RtlFindNextClearRunUlong

UINT64 __stdcall RtlFindNextClearRunUlong(
        RTL_BITMAP *BitMapHeader,
        UINT64 StartingIndex,
        UINT64 MaxRunLength,
        UINT64 *StartingRunIndex){
  unsigned int v4; 
  unsigned int SizeOfBitMap; 
  unsigned int *Buffer; 
  unsigned __int64 v7; 
  unsigned int *v8; 
  unsigned __int64 v9; 
  unsigned int v10; 
  int v11; 
  unsigned int v12; 
  char v13; 
  bool v14; 
  __int64 v15; 
  __int64 v16; 
  unsigned int v17; 
  int v18; 
  char v19; 
  unsigned int *v20; 
  char v21; 
  __int64 v22; 
  UINT64 result; 
  _DWORD *v24; 
  v4 = (unsigned int)StartingRunIndex;
  if( (unsigned int)StartingRunIndex < 0x20 )
    return 0i64;
  SizeOfBitMap = BitMapHeader->SizeOfBitMap;
  if( BitMapHeader->SizeOfBitMap < 0x20 || (unsigned int)StartingIndex > SizeOfBitMap - 32 )
    return 0i64;
  Buffer = BitMapHeader->Buffer;
  v7 = (unsigned __int64)(SizeOfBitMap - 1) >> 5;
  v8 = &Buffer[(unsigned __int64)(unsigned int)StartingIndex >> 5];
  v9 = (unsigned __int64)&Buffer[v7 - 1];
  if( (SizeOfBitMap & 0x1F) == 0 )
    v9 = (unsigned __int64)&Buffer[v7];
  v10 = *v8 | *((_DWORD *)qword_140011CE0 + (StartingIndex & 0x1F));
  v11 = 0;
  do
  {
    while( 1 )
    {
      if( v10 == -1 )
        goto LABEL_8;
      v11 = 32 * (v8 - Buffer);
      if( !v10 )
        break;
      v13 = -1;
      v14 = !_BitScanReverse64((unsigned __int64 *)&v15, v10);
      if( !v14 )
        v13 = v15;
      if( v13 != 31 )
      {
        v11 += v13 + 1;
        break;
      }
LABEL_8:
      v12 = 0;
      if( (unsigned __int64)v8 >= v9 )
        goto LABEL_33;
      v10 = *++v8;
    }
    v16 = v11 & 0x1F;
    v17 = 0;
    v18 = v10 & ~*((_DWORD *)qword_140011CE0 + v16);
    v10 = v18;
    if( (unsigned __int64)v8 > v9 )
    {
LABEL_21:
      v19 = 1;
      if( (SizeOfBitMap & 0x1F) == 0 )
        goto LABEL_30;
      v20 = v8 + 1;
      if( v17 )
        v10 = *v20;
      if( !v17 )
        v20 = v8;
      v8 = v20;
      v10 |= ~*((_DWORD *)qword_140011CE0 + (SizeOfBitMap & 0x1F));
LABEL_27:
      v21 = -1;
      v14 = !_BitScanForward64((unsigned __int64 *)&v22, v10);
      if( !v14 )
        v21 = v22;
      v17 += v21;
      goto LABEL_30;
    }
    v19 = 0;
    if( v18 )
      goto LABEL_27;
    while( 1 )
    {
      v17 += 32;
      if( v17 >= v4 && v17 - (unsigned int)v16 >= v4 )
        break;
      if( v8 == (unsigned int *)v9 )
        goto LABEL_21;
      v10 = *++v8;
      if( *v8 )
        goto LABEL_27;
    }
LABEL_30:
    v12 = v17 - v16;
    if( v12 > v4 )
      v12 = v4;
    if( v12 >= 0x20 )
      break;
    v12 = 0;
  }
  while( !v19 );
LABEL_33:
  if( v12 > v4 )
    v12 = v4;
  result = v12;
  *v24 = v11;
  return result;
}

Referenced by:

MiFindFreePageFileSpaceForward
MiRescanPageFileBitmapPortion
MiRescanPagefileBitmaps