RtlpHpHeapCreate

VOID __fastcall RtlpHpHeapCreate(INT64 a1, INT64 a2, CHAR r8_0){
  __int128 *v3; 
  unsigned int v4; 
  __int128 *v5; 
  unsigned int MaximumProcessorCount; 
  __int64 v7; 
  UINT64 v8; 
  __int128 v9; 
  char a8; 
  __int128 v11; 
  union _RTL_RUN_ONCE *HeapManager; 
  unsigned __int8 v13; 
  __int64 v14; 
  __int64 v15; 
  __int64 v16; 
  unsigned __int16 v17; 
  unsigned __int16 v18; 
  __int128 a3; 
  INT64 a5[2]; 
  INT64(__fastcall *v21)(INT64, UINT64, UINT64); 
  UINT64(__fastcall *v22)(INT64, UINT64, UINT64); 
  INT64(__fastcall *v23)(INT64, INT64); 
  v4 = a1;
  v5 = v3;
  if( (int)RtlpHpRegisterEnvironment(v3) >= 0 )
  {
    MaximumProcessorCount = HalQueryMaximumProcessorCount();
    if( !MaximumProcessorCount )
      MaximumProcessorCount = 1;
    a3 = *v5;
    v7 = RtlpHpHeapAllocate(v4, MaximumProcessorCount, &a3);
    v8 = v7;
    if( v7 )
    {
      v9 = *v5;
      *(_DWORD *)(v7 + 20) = v4;
      *(_DWORD *)(v7 + 16) = -571548178;
      *(_OWORD *)v7 = v9;
      a8 = (BYTE1(*(_QWORD *)v5) >= 2u ? 0x10 : 0) | 4;
      if( (v4 & 0x4000000) == 0 )
        a8 = BYTE1(*(_QWORD *)v5) >= 2u ? 0x10 : 0;
      a3 = *v5;
      RtlpHpSegContextInitialize((__int64 *)(v7 + 256), 0x100000u, v7, v7 + 832, v7 + 640, v7 + 128, &a3, a8);
      a3 = *v5;
      RtlpHpSegContextInitialize((__int64 *)(v8 + 448), 0x1000000u, v8, 0i64, 0i64, v8 + 128, &a3, a8);
      *(_QWORD *)(v8 + 64) = 0i64;
      *(_QWORD *)(v8 + 72) = 0i64;
      *(_QWORD *)(v8 + 80) = 0i64;
      *(_QWORD *)(v8 + 224) = 0i64;
      if( (*(_DWORD *)(v8 + 20) & 0x20000000) != 0 )
      {
        v17 = 0;
        while( 1 )
        {
          v18 = v17 + 1;
          if( *((INT64(__stdcall **)())&RtlpInterceptorRoutines + v17) == HalSystemVectorDispatchEntry )
            break;
          ++v17;
          if( v18 )
          {
            v18 = 0;
            break;
          }
        }
        *(_DWORD *)(v8 + 24) = v18;
      }
      v11 = *v5;
      v23 = 0i64;
      a5[0] = (INT64)RtlpHpSegVsAllocate;
      a5[1] = (INT64)RtlpHpSegLfhVsFree;
      v21 = RtlpHpSegLfhVsCommit;
      v22 = RtlpHpSegLfhVsDecommit;
      a3 = v11;
      HeapManager = RtlpHpEnvGetHeapManager(&a3);
      RtlpHpVsContextInitialize(
        v8 + 640,
        v8 + 256,
        (__int128 *)a5,
        v13 & (unsigned __int8)*(_DWORD *)v5,
        0,
        (_DWORD *)&HeapManager[1817].2 + 1);
      a5[0] = (INT64)RtlpHpSegLfhAllocate;
      a5[1] = (INT64)RtlpHpSegLfhVsFree;
      v21 = RtlpHpSegLfhVsCommit;
      v22 = RtlpHpSegLfhVsDecommit;
      v23 = RtlpHpSegLfhExtendContext;
      RtlpHpLfhContextInitialize(
        v8 + 832,
        v8 + 256,
        MaximumProcessorCount,
        *(_BYTE *)v5 & 1,
        (INT64)a5,
        v8 + 128,
        &HeapManager[1817]);
      CmSiRWLockInitialize((PRTL_RUN_ONCE)(v8 + 104));
      if( (int)RtlpHpSegContextReserve(v8 + 256, 0i64, 0i64) >= 0 )
        v8 = 0i64;
      if( v8 )
        RtlpHpHeapDestroy(v8, v14, v15, v16);
    }
    else
    {
      RtlpHpRegisterEnvironment(v5);
    }
  }
}

Referenced by:

ExCreateHeap
RtlpHpMetadataHeapCreate