RtlpHpHeapDestroy

NTSTATUS __stdcall RtlpHpHeapDestroy(INT64 a1, INT64 a2, UINT64 a3){
  __int64 v3; 
  INT64 v4; 
  bool v5; 
  __int64 v7; 
  char v8; 
  int v9; 
  _QWORD *v10; 
  __int64 v11; 
  __int64 v12; 
  unsigned __int64 v13; 
  __int64 v14; 
  __int64 v15; 
  INT64 v16; 
  __int128 v17; 
  INT128 v19[4]; 
  __int128 v20; 
  __int64 v21; 
  __int64 v22; 

  v21 = a1;
  v22 = 0i64;
  v4 = a1 + 72;
  v5 = (*(_BYTE *)(a1 + 80) & 1) == 0;
  v7 = *(_QWORD *)(a1 + 72);
  if( !v5 && v7 )
    v7 ^= v4;
  v8 = *(_BYTE *)(v4 + 8);
  v9 = v8 & 1;
  if( v7 )
  {
    while( 1 )
    {
      while( 1 )
      {
        while( *(_QWORD *)v7 )
        {
          v10 = (_QWORD *)v7;
          if( v9 )
            v7 ^= *(_QWORD *)v7;
          else
            v7 = *(_QWORD *)v7;
          *v10 = 0i64;
        }
        v11 = *(_QWORD *)(v7 + 8);
        if( !v11 )
          break;
        v12 = v7;
        if( v9 )
          v7 ^= v11;
        else
          v7 = *(_QWORD *)(v7 + 8);
        *(_QWORD *)(v12 + 8) = 0i64;
      }
      v13 = *(_QWORD *)(v7 + 16) & 0xFFFFFFFFFFFFFFFCui64;
      if( v9 && v13 )
        v13 ^= v7;
      RtlpHpLargeAllocationDestroy(v7, (__int128 *)a1);
      if( !v13 )
        break;
      v7 = v13;
    }
    v8 = *(_BYTE *)(v4 + 8);
  }
  *(_QWORD *)v4 = 0i64;
  *(_QWORD *)(v4 + 8) = 0i64;
  if( (v8 & 1) != 0 )
    *(_BYTE *)(v4 + 8) = 1;
  v14 = v21;
  v15 = v21 + 672;
  while( *(_QWORD *)v15 )
  {
    v16 = v15 ^ *(_QWORD *)v15;
    RtlpHpVsSubsegmentCleanup(v14 + 640, v16, a3, v3);
    RtlpHpVsSubsegmentFree(v14 + 640, v16, 1ui64);
  }
  RtlpHpLfhContextCleanup(v21 + 832);
  RtlpHpSegContextCleanup(v21 + 256);
  RtlpHpSegContextCleanup(v21 + 448);
  v17 = *(_OWORD *)v21;
  v22 = *(_QWORD *)(v21 + 248) - v21;
  v5 = (*(_BYTE *)(v21 + 30) & 1) == 0;
  *(_OWORD *)v19 = v17;
  v20 = *(_OWORD *)v21;
  if( v5 )
    RtlpHpFreeVA((UINT64 *)&v21, (UINT64 *)&v22, BYTE1(v19[0]) < 2u ? 16809984 : 0x8000, &v20);
  else
    RtlpHpMetadataFree(v21, &v20);
  return RtlpHpRegisterEnvironment(v19);
}

Referenced by:

ExCleanupSessionHeapManager
RtlpHpHeapCreate