RtlLengthCurrentClearRunForward

UINT64 __stdcall RtlLengthCurrentClearRunForward(_RTL_BITMAP *BitMapHeader, UINT64 StartingIndex, UINT64 MaxRunLength){
  unsigned int *Buffer; 
  unsigned int v4; 
  unsigned int v5; 
  unsigned int *v6; 
  unsigned int *v7; 
  unsigned int *v8; 
  UINT64 v9; 
  unsigned int v10; 
  unsigned int v11; 
  unsigned __int64 v12; 
  char v13; 
  bool v14; 
  __int64 v15; 
  unsigned int v16; 
  unsigned __int64 v18; 
  char v19; 

  Buffer = BitMapHeader->Buffer;
  v4 = MaxRunLength;
  v5 = BitMapHeader->SizeOfBitMap & 0x1F;
  v6 = &Buffer[(unsigned __int64)(unsigned int)StartingIndex >> 5];
  v7 = &Buffer[(unsigned __int64)(BitMapHeader->SizeOfBitMap - 1) >> 5];
  v8 = v7 - 1;
  if( !v5 )
    v8 = v7;
  v9 = StartingIndex & 0x1F;
  v10 = 0;
  v11 = ~*((_DWORD *)qword_140011CE0 + v9) & *v6;
  if( v6 > v8 )
  {
LABEL_18:
    if( v5 )
    {
      if( v10 )
        v11 = v6[1];
      v18 = v11 | ~*((_DWORD *)qword_140011CE0 + (BitMapHeader->SizeOfBitMap & 0x1F));
      v19 = -1;
      v14 = !_BitScanForward64((unsigned __int64 *)&BitMapHeader, v18);
      if( !v14 )
        v19 = (char)BitMapHeader;
      v10 += v19;
    }
  }
  else if( v11 )
  {
LABEL_5:
    v12 = v11;
    v13 = -1;
    v14 = !_BitScanForward64((unsigned __int64 *)&v15, v12);
    if( !v14 )
      v13 = v15;
    v10 += v13;
  }
  else
  {
    v11 = 0;
    while( 1 )
    {
      v10 += 32;
      if( v10 >= v4 && v10 - (unsigned int)v9 >= v4 )
        break;
      if( v6 == v8 )
        goto LABEL_18;
      v11 = *++v6;
      if( *v6 )
        goto LABEL_5;
    }
  }
  v16 = v10 - v9;
  if( v16 > v4 )
    return v4;
  return v16;
}

Referenced by:

MiFindFreePageFileSpace