MiClaimPhysicalRun

__int64 __fastcall MiClaimPhysicalRun(
        __int64 a1,
        unsigned __int64 a2,
        __int64 a3,
        __int64 a4,
        __int64 a5,
        int a6,
        int a7,
        __int64 a8,
        int a9,
        _QWORD *a10){
  unsigned __int64 v10; 
  __int64 v14; 
  _MMPFN *v15; 
  INT64 v16; 
  unsigned __int64 v17; 
  __int64 v19; 
  INT64 v20[2]; 
  __int64 v21; 
  int v22; 
  int v23; 
  int v24; 
  int v25; 
  __int64 v26; 
  unsigned __int64 v27; 
  __int64 v28; 
  __int64 v29; 
  int v30; 
  _MMPFN *v31; 
  unsigned __int64 v32; 
  v25 = 0;
  v10 = a2;
  v27 = 0i64;
  if( a10 )
    *a10 = -1i64;
  v14 = a3;
  v20[1] = a5;
  v23 = a7;
  v24 = a9;
  v20[0] = a1;
  v30 = 0;
  v29 = a8;
  v22 = a6;
  v21 = a3;
  v28 = a4;
  v26 = -1i64;
  v15 = (_MMPFN *)((char *)MmGetPfnDb() + 48 * a2);
  v31 = (_MMPFN *)((char *)v15 + 48 * a3);
  v32 = a2 + a3;
  while( 1 )
  {
    v16 = MiTradePage((INT64)v20, v10);
    v17 = v16;
    if( !v16 )
    {
      v17 = 1i64;
      if( v27 > 1 )
      {
        if( v10 == (v10 & ~(v27 - 1)) )
          v17 = v27;
        else
          v17 = (~(v27 - 1) & (v10 + v27 - 1)) - v10;
      }
      if( !v30 )
      {
        if( v27 )
          v14 = v32 - (v10 & ~(v27 - 1));
        v30 = 1;
      }
      if( (a6 & 0x2000) == 0 )
        goto LABEL_20;
      if( v17 >= v32 - v10 )
        goto LABEL_10;
      goto LABEL_9;
    }
    v21 -= v16;
    if( !v21 )
      break;
LABEL_9:
    v10 += v17;
    v15 = (_MMPFN *)((char *)v15 + 48 * v17);
    if( v15 >= v31 )
    {
LABEL_10:
      if( (a6 & 0x2000) == 0 )
      {
LABEL_20:
        v19 = a3 - v21;
        if( a8 )
          *(_DWORD *)(a8 + 40) += -4096 * v19;
        for( ; v19; --v19 )
        {
          v15 = (_MMPFN *)((char *)v15 - 48);
          MiReleaseFreshPage(v15);
        }
      }
      return v14;
    }
  }
  if( (a6 & 0x400000) != 0 && a10 )
    *a10 = v26;
  return 0i64;
}

Referenced by:

MiFindContiguousPages
MiScrubNode
MmRelocatePfnList