RtlFindLongestRunClearCapped

UINT64 __stdcall RtlFindLongestRunClearCapped(
        _RTL_BITMAP *BitMapHeader,
        UINT64 MaximumRunAllowed,
        UINT64 *StartingIndex){
  unsigned int SizeOfBitMap; 
  unsigned int v4; 
  unsigned int v6; 
  unsigned int v8; 
  int v9; 
  int v10; 
  unsigned int v11; 
  unsigned int v12; 
  unsigned int v13; 
  unsigned int v14; 
  __int64 v15; 
  unsigned int v16; 
  _BYTE *v17; 
  unsigned __int8 v18; 
  unsigned int *Buffer; 
  unsigned int v20; 
  __int64 v21; 
  unsigned int v22; 
  unsigned __int8 i; 
  __int64 v24; 
  char v25; 
  int v26; 
  unsigned int v27; 
  bool v28; 
  unsigned int v29; 
  unsigned int v30; 
  unsigned int v31; 
  bool v32; 
  UINT64 result; 
  unsigned int v34; 
  unsigned int v36; 
  unsigned int v37; 

  SizeOfBitMap = BitMapHeader->SizeOfBitMap;
  v4 = MaximumRunAllowed;
  v6 = BitMapHeader->SizeOfBitMap & 7;
  v34 = v6;
  v8 = (SizeOfBitMap >> 3) + (v6 != 0);
  v9 = *(_DWORD *)StartingIndex;
  v10 = -(*(_DWORD *)StartingIndex < SizeOfBitMap);
  v11 = 0;
  v36 = 0;
  v12 = v9 & v10 & 0xFFFFFFF8;
  v13 = 0;
  v14 = v12 >> 3;
  LODWORD(v15) = 0;
  v16 = v12;
  v17 = (char *)BitMapHeader->Buffer + (v12 >> 3);
  v18 = *v17;
  Buffer = (unsigned int *)(v17 + 1);
  if( v12 >> 3 == v8 - 1 && v6 )
    v18 |= byte_14001A768[SizeOfBitMap & 7];
  v20 = 0;
  v37 = 0;
  if( v8 )
  {
    while( !v18 )
    {
      LODWORD(v15) = v15 + 8;
      if( (unsigned int)v15 >= v4 )
        goto LABEL_49;
LABEL_22:
      ++v14;
      v27 = v15;
      if( v14 >= v8 )
      {
        if( (_DWORD)v15 )
        {
          v28 = (unsigned int)v15 <= v11;
          v29 = v16;
          if( (unsigned int)v15 <= v11 )
            LODWORD(v15) = v11;
          if( v28 )
            v29 = v13;
          v11 = v15;
          v13 = v29;
          LODWORD(v15) = 0;
          if( v16 != v12 )
            v27 = v36;
          v36 = v27;
        }
        v14 = 0;
        Buffer = BitMapHeader->Buffer;
      }
      v18 = *(_BYTE *)Buffer;
      Buffer = (unsigned int *)((char *)Buffer + 1);
      if( v14 == v8 - 1 && v34 )
        v18 |= byte_14001A768[SizeOfBitMap & 7];
      v37 = ++v20;
      if( v20 >= v8 )
        goto LABEL_36;
    }
    v21 = *((unsigned __int8 *)RtlpBitsClearLow + v18);
    v22 = v21 + v15;
    if( (_DWORD)v21 + (_DWORD)v15 )
    {
      if( v22 >= v4 )
      {
LABEL_49:
        *(_DWORD *)StartingIndex = v16;
        return v4;
      }
      if( v22 > v11 )
      {
        v11 = v21 + v15;
        v13 = v16;
      }
    }
    if( v16 != v12 )
      v22 = v36;
    v36 = v22;
    v15 = *((unsigned __int8 *)RtlpBitsClearHigh + v18);
    v16 = 8 * v14 - v15 + 8;
    for( i = *((_BYTE *)qword_14001A770 - v15) | byte_14001DA00[v21] | v18; ; i |= v25 )
    {
      if( i == 0xFF || (v24 = *((unsigned __int8 *)RtlpBitsClearAnywhere + i), v11 >= (unsigned int)v24) )
      {
        v20 = v37;
        goto LABEL_22;
      }
      v25 = byte_14001DA00[v24];
      v26 = 0;
      while( ((unsigned __int8)v25 & i) != 0 )
      {
        v25 *= 2;
        ++v26;
      }
      v13 = v26 + 8 * v14;
      if( (unsigned int)v24 >= v4 )
        break;
      v11 = *((unsigned __int8 *)RtlpBitsClearAnywhere + i);
    }
    result = v4;
    goto LABEL_47;
  }
LABEL_36:
  v30 = v13;
  if( (_DWORD)v15 )
  {
    v31 = v15 + v36;
    v13 = v16;
    if( v16 + (_DWORD)v15 != v12 )
      v31 = v15;
    v32 = v31 <= v11;
    if( v31 <= v11 )
      v31 = v11;
    if( v32 )
      v13 = v30;
    v11 = v31;
    goto LABEL_44;
  }
  if( v11 )
  {
LABEL_44:
    if( v11 > v4 )
      v11 = v4;
    result = v11;
LABEL_47:
    *(_DWORD *)StartingIndex = v13;
    return result;
  }
  *(_DWORD *)StartingIndex = 0;
  return 0i64;
}

Referenced by:

MiFindPageFileWriteCluster