MmAllocateVirtualMemory

NTSTATUS __stdcall MmAllocateVirtualMemory(
        PVOID *BaseAddress,
        UINT64 ZeroBits,
        UINT64 *RegionSize,
        UINT64 AllocationType){
  unsigned __int64 v6; 
  UINT64 v7; 
  __int64 v8; 
  __int64 v9; 
  unsigned __int64 v10; 
  NTSTATUS MapExtendedParameters; 
  UINT64 *v12; 
  INT8 *AllocationTypea; 
  UINT64 AllocationTypeb; 
  UINT64 Protect; 
  INT8 PreviousMode; 
  UINT64 InternalFlags; 
  _MMVAD_SHORT **OutVad; 
  _MMVAD_SHORT **OutVada; 
  unsigned __int64 v21; 
  UINT64 ZeroBitsa; 
  UINT64 v23; 
  UINT64 v24; 
  PVOID Object; 
  __int64 v26; 
  __int64 ProcessHandle[16]; 
  INT8 v28[80]; 
  int v30; 
  int v31; 
  VOID *Address; 
  unsigned int ullMultiplicand; 
  unsigned __int8 v34; 
  int v35; 
  int v36; 
  __int64 v37; 

  v30 = AllocationType;
  memset(v28, 0i64, 0x48u);
  v6 = 0i64;
  v23 = 0i64;
  v24 = 0i64;
  if( v34 )
  {
    v7 = ZeroBits;
    if( ZeroBits >= 0x7FFFFFFF0000i64 )
      v7 = 0x7FFFFFFF0000i64;
    *(_QWORD *)v7 = *(_QWORD *)v7;
    v8 = (__int64)RegionSize;
    if( (unsigned __int64)RegionSize >= 0x7FFFFFFF0000i64 )
      v8 = 0x7FFFFFFF0000i64;
    *(_QWORD *)v8 = *(_QWORD *)v8;
  }
  v9 = *(_QWORD *)ZeroBits;
  v23 = *(_QWORD *)ZeroBits;
  v10 = *RegionSize;
  v24 = *RegionSize;
  AllocationTypea = v28;
  MapExtendedParameters = MiCaptureAllocateMapExtendedParameters(Address, ullMultiplicand, (VOID *)v34);
  if( MapExtendedParameters >= 0 )
  {
    memset(ProcessHandle, 0i64, sizeof(ProcessHandle));
    ZeroBitsa = 0i64;
    Object = 0i64;
    v21 = 0i64;
    LODWORD(OutVad) = v35;
    LODWORD(AllocationTypea) = v30;
    MapExtendedParameters = MiAllocateVirtualMemoryPrepare(
                              BaseAddress,
                              v9,
                              0i64,
                              v10,
                              (INT64)AllocationTypea,
                              v31,
                              (__int64)v28,
                              v34,
                              (INT64)OutVad,
                              v36,
                              v37,
                              (__int64)ProcessHandle,
                              (__int64)&Object);
    if( MapExtendedParameters < 0 )
      goto LABEL_15;
    if( *(_QWORD *)&v28[24] )
    {
      if( *(_QWORD *)&v28[24] == -3i64 )
      {
        v6 = 1i64;
      }
      else
      {
        MapExtendedParameters = PsReferencePartitionByHandle(*(VOID **)&v28[24], 2ui64, v34, 0x61566D4Du, &v21);
        v6 = v21;
        if( MapExtendedParameters < 0 )
          goto LABEL_15;
      }
    }
    if( v28[48] == 1 && (v30 & 0x20400000) != 0x400000 )
    {
      MapExtendedParameters = -1073741811;
      goto LABEL_29;
    }
    if( v35 < 0 )
    {
      v26 = 0i64;
      if( (ProcessHandle[7] & 0x4000000000000000i64) != 0 )
      {
        ProcessHandle[10] = (__int64)&v26;
        HIDWORD(ProcessHandle[9]) = 536870913;
      }
      MapExtendedParameters = MiAllocateVirtualMemory(
                                ProcessHandle,
                                0i64,
                                (UINT64)&ZeroBitsa,
                                v12,
                                AllocationTypeb,
                                Protect,
                                PreviousMode,
                                InternalFlags,
                                OutVada);
      ProcessHandle[10] = 0i64;
      HIDWORD(ProcessHandle[9]) = 0;
      if( MapExtendedParameters >= 0 )
        MapExtendedParameters = 0;
    }
    else
    {
      MapExtendedParameters = MiAllocateVirtualMemory(
                                ProcessHandle,
                                (PVOID *)v6,
                                (UINT64)&ZeroBitsa,
                                v12,
                                AllocationTypeb,
                                Protect,
                                PreviousMode,
                                InternalFlags,
                                OutVada);
    }
    if( MapExtendedParameters < 0 )
      goto LABEL_29;
    v9 = ZeroBitsa;
    v23 = ZeroBitsa;
    v10 = ProcessHandle[3];
    v24 = ProcessHandle[3];
LABEL_15:
    if( MapExtendedParameters >= 0 )
    {
LABEL_16:
      if( v6 >= 2 )
        PsDereferencePartition(v6);
      if( Object )
        ObfDereferenceObjectWithTag(Object, 0x6D566D4Dui64);
      LODWORD(v21) = MapExtendedParameters;
      if( MapExtendedParameters >= 0 )
      {
        *(_QWORD *)ZeroBits = v9;
        *RegionSize = v10;
      }
      return MapExtendedParameters;
    }
LABEL_29:
    if( ProcessHandle[0] )
      ++*(&stru_140C4DB30 + 639);
    else
      ++*(&stru_140C4DB30 + 638);
    goto LABEL_16;
  }
  return MapExtendedParameters;
}

Referenced by:

NtAllocateVirtualMemoryEx
PsDispatchIumService
WbAllocateMemoryBlock