RtlpHpSegSegmentFree

CHAR __stdcall RtlpHpSegSegmentFree(INT64 a1, INT64 a2, INT64 a3, INT64 a4){
  unsigned int v4; 
  _RTL_RUN_ONCE *HeapManager; 
  unsigned __int64 v8; 
  __int64 v9; 
  unsigned __int64 i; 
  __int128 v12; 

  v4 = a3;
  if( (_DWORD)a4 )
  {
    v12 = *(_OWORD *)(a1 + 40);
    HeapManager = RtlpHpEnvGetHeapManager(&v12);
    RtlCSparseBitmapBitsClear((INT64)&HeapManager[2], 2 * ((v9 - HeapManager[1].Value) >> 20), 2 * (v8 >> 20));
  }
  if( (*(_BYTE *)(a1 + 13) & 7) != 0 && v4 == 0x7FFFFFFF )
  {
    v4 = 2;
    for( i = 32i64 * *(unsigned __int8 *)(a1 + 10) + a2; i < a2 + 0x2000; i += 32i64 * *(unsigned __int8 *)(i + 31) )
      v4 += (unsigned __int16)~*(_WORD *)(i + 28);
  }
  return RtlpHpSegMgrRelease(a1, a2, v4);
}

Referenced by:

RtlpHpSegContextCleanup
RtlpHpSegContextCompact
RtlpHpSegPageRangeShrink
RtlpHpSegSegmentAllocate