RtlpHpLfhSubsegmentFree

INT64 __fastcall RtlpHpLfhSubsegmentFree(INT64 a1, INT64 a2, INT64 r8_0, CHAR a4){
  unsigned int v7; 
  unsigned int v8; 
  int v9; 
  int EmptyUnits; 
  int a3; 
  _InterlockedDecrement64((volatile signed __int64 *)(r8_0 + 64));
  _InterlockedExchangeAdd64((volatile signed __int64 *)(r8_0 + 56), -*(__int16 *)(a2 + 34));
  a3 = 0;
  v7 = 0;
  v8 = *(unsigned __int8 *)(a2 + 45);
  v9 = 0;
  if( *(_BYTE *)(a2 + 45) )
  {
    do
    {
      EmptyUnits = RtlpHpLfhSubsegmentFindEmptyUnits(a2, v7, &a3);
      if( EmptyUnits == -1 )
        break;
      v9 += a3;
      v7 = a3 + EmptyUnits;
    }
    while( v7 < v8 );
    if( v9 && (RtlpHpLfhPerfFlags & 0x20) != 0 )
      _InterlockedExchangeAdd64(
        (volatile signed __int64 *)(*(__int16 *)(a1 + 58) + a1 + 24),
        -(__int64)((unsigned __int64)(unsigned int)(v9 << *(_BYTE *)(a2 + 44)) >> 12));
  }
  return((__int64(__fastcall *)(_QWORD, INT64, _QWORD, _QWORD))(a1 ^ RtlpHpHeapGlobals ^ *(_QWORD *)(a1 + 16)))(
           *(_QWORD *)a1,
           a2,
           *(unsigned __int8 *)(a2 + 45) << *(_BYTE *)(a2 + 44),
           a4 & 1);
}

Referenced by:

RtlpHpLfhBucketAddSubsegment
RtlpHpLfhOwnerCleanup