MiAttemptCoalesce

VOID __stdcall MiAttemptCoalesce(_MI_SYSTEM_PTE_TYPE *SystemPteInfo, UINT64 StartBit, UINT64 NumberOfBits){
  UINT64 v3; 
  UINT64 v5; 
  UINT64 v6; 
  __int64 v7; 
  UINT64 v8; 
  UINT64 v9; 
  UINT64 v10; 
  unsigned __int64 *Buffer; 
  unsigned __int64 v12; 
  unsigned __int64 *v13; 
  unsigned __int64 *v14; 
  bool v15; 
  unsigned __int64 *v16; 

  v3 = 32i64;
  if( (SystemPteInfo->Flags & 4) == 0 )
    v3 = 512i64;
  v5 = 0i64;
  v6 = v3 - 1;
  v7 = ~(v3 - 1);
  v8 = StartBit & v7;
  v9 = (v7 & (v3 + StartBit + NumberOfBits - 1)) - (StartBit & v7);
  if( v9 )
  {
    do
    {
      v10 = v8 + v5;
      if( v8 + v5 < SystemPteInfo->Bitmap.SizeOfBitMap && SystemPteInfo->Bitmap.SizeOfBitMap - v10 >= v3 )
      {
        Buffer = SystemPteInfo->Bitmap.Buffer;
        v12 = Buffer[v10 >> 6];
        v13 = &Buffer[v10 >> 6];
        v14 = &Buffer[(v10 + v6) >> 6];
        if( v13 == v14 )
        {
          v15 = (v12 & (0xFFFFFFFFFFFFFFFFui64 >> (64 - (unsigned __int8)v3) << v10)) == 0;
LABEL_5:
          if( v15 && RtlInterlockedSetClearRunEx(&SystemPteInfo->Bitmap, v8 + v5, v3) == 1 )
            MiReturnSystemPtes(SystemPteInfo, v8 + v5, v3, 0i64);
          goto LABEL_6;
        }
        if( (v12 & (-1i64 << v10)) == 0 )
        {
          v16 = v13 + 1;
          if( v16 != v14 )
          {
            while( !*v16 )
            {
              if( ++v16 == v14 )
                goto LABEL_18;
            }
            goto LABEL_6;
          }
LABEL_18:
          v15 = ((0xFFFFFFFFFFFFFFFFui64 >> ~((unsigned __int8)v10 + (unsigned __int8)v6)) & *v16) == 0;
          goto LABEL_5;
        }
      }
LABEL_6:
      v5 += v3;
    }
    while( v5 < v9 );
  }
}

Referenced by:

MiAdjustPteBins
MiDeleteSessionAddressSpace
MiReleasePtes
MiReplenishBitMap