RtlpHpHeapCreate

VOID __stdcall RtlpHpHeapCreate(INT64 a1, INT64 a2, CHAR a3){
  INT128 *v3; 
  unsigned int v4; 
  INT128 *v5; 
  unsigned int MaximumProcessorCount; 
  __int64 v7; 
  __int64 v8; 
  __int128 v9; 
  char v10; 
  __int128 v11; 
  _RTL_RUN_ONCE *HeapManager; 
  unsigned __int8 v13; 
  INT64 v14; 
  UINT64 v15; 
  unsigned __int16 v16; 
  unsigned __int16 v17; 
  __int128 v18; 
  __int128 v19; 
  NTSTATUS(__stdcall *v20)(INT64, UINT64, UINT64); 
  UINT64(__stdcall *v21)(INT64, UINT64, UINT64); 
  NTSTATUS(__stdcall *v22)(INT64, INT64); 

  v4 = a1;
  v5 = v3;
  if( RtlpHpRegisterEnvironment(v3) >= 0 )
  {
    MaximumProcessorCount = HalQueryMaximumProcessorCount();
    if( !MaximumProcessorCount )
      MaximumProcessorCount = 1;
    v18 = *(_OWORD *)v5;
    v7 = RtlpHpHeapAllocate(v4, MaximumProcessorCount, &v18);
    v8 = v7;
    if( v7 )
    {
      v9 = *(_OWORD *)v5;
      *(_DWORD *)(v7 + 20) = v4;
      *(_DWORD *)(v7 + 16) = -571548178;
      *(_OWORD *)v7 = v9;
      v10 = (BYTE1(*(_QWORD *)v5) >= 2u ? 0x10 : 0) | 4;
      if( (v4 & 0x4000000) == 0 )
        v10 = BYTE1(*(_QWORD *)v5) >= 2u ? 0x10 : 0;
      v18 = *(_OWORD *)v5;
      RtlpHpSegContextInitialize((__int64 *)(v7 + 256), 0x100000u, v7, v7 + 832, v7 + 640, v7 + 128, &v18, v10);
      v18 = *(_OWORD *)v5;
      RtlpHpSegContextInitialize((__int64 *)(v8 + 448), 0x1000000u, v8, 0i64, 0i64, v8 + 128, &v18, v10);
      *(_QWORD *)(v8 + 64) = 0i64;
      *(_QWORD *)(v8 + 72) = 0i64;
      *(_QWORD *)(v8 + 80) = 0i64;
      *(_QWORD *)(v8 + 224) = 0i64;
      if( (*(_DWORD *)(v8 + 20) & 0x20000000) != 0 )
      {
        v16 = 0;
        while( 1 )
        {
          v17 = v16 + 1;
          if( *((UINT32(__stdcall **)(UINT32, PKINTERRUPT_ROUTINE **, PKINTERRUPT_ROUTINE *))&RtlpInterceptorRoutines.QuadPart
               + v16) == HalSystemVectorDispatchEntry )
            break;
          ++v16;
          if( v17 )
          {
            v17 = 0;
            break;
          }
        }
        *(_DWORD *)(v8 + 24) = v17;
      }
      v11 = *(_OWORD *)v5;
      v22 = 0i64;
      *(_QWORD *)&v19 = RtlpHpSegVsAllocate;
      *((_QWORD *)&v19 + 1) = RtlpHpSegLfhVsFree;
      v20 = RtlpHpSegLfhVsCommit;
      v21 = RtlpHpSegLfhVsDecommit;
      v18 = v11;
      HeapManager = RtlpHpEnvGetHeapManager(&v18);
      RtlpHpVsContextInitialize(
        v8 + 640,
        v8 + 256,
        &v19,
        v13 & (unsigned __int8)*v5,
        0,
        (_DWORD *)&HeapManager[1817] + 1);
      *(_QWORD *)&v19 = RtlpHpSegLfhAllocate;
      *((_QWORD *)&v19 + 1) = RtlpHpSegLfhVsFree;
      v20 = RtlpHpSegLfhVsCommit;
      v21 = RtlpHpSegLfhVsDecommit;
      v22 = RtlpHpSegLfhExtendContext;
      RtlpHpLfhContextInitialize(
        v8 + 832,
        v8 + 256,
        MaximumProcessorCount,
        *(_BYTE *)v5 & 1,
        (__int64)&v19,
        v8 + 128,
        &HeapManager[1817]);
      CmSiRWLockInitialize((PRTL_RUN_ONCE)(v8 + 104));
      if( RtlpHpSegContextReserve(v8 + 256, 0i64, 0i64) >= 0 )
        v8 = 0i64;
      if( v8 )
        RtlpHpHeapDestroy(v8, v14, v15);
    }
    else
    {
      RtlpHpRegisterEnvironment(v5);
    }
  }
}

Referenced by:

ExCreateHeap
RtlpHpMetadataHeapCreate