MiMirrorVerify

NTSTATUS __stdcall MiMirrorVerify(INT64 a1){
  NTSTATUS v1; 
  unsigned __int64 v4; 
  unsigned __int64 v5; 
  unsigned __int64 v6; 
  _QWORD *v7; 
  __int64 i; 
  unsigned __int64 v9; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  unsigned __int64 v12; 
  unsigned __int64 v13; 
  unsigned __int64 v14; 
  _DWORD *v15; 
  unsigned __int64 v16; 
  _DWORD *v17; 
  unsigned __int64 j; 
  unsigned __int64 v19; 

  v1 = 0;
  if( !*(_QWORD *)(a1 + 24) )
    return 0;
  v4 = 0i64;
  while( 1 )
  {
    v5 = v4 & -(__int64)(v4 < *(&stru_140C4DB30 + 292));
    v6 = *(&stru_140C4DB30 + 292) - 1i64;
    while( 1 )
    {
      if( v6 - v5 == -1i64 )
        goto LABEL_7;
      v7 = (_QWORD *)(*(&stru_140C4DB30 + 293) + 8 * (v5 >> 6));
      for( i = ~*v7 | ((1i64 << (v5 & 0x3F)) - 1); i == -1; i = ~*v7 )
      {
        if( (unsigned __int64)++v7 > *(&stru_140C4DB30 + 293) + 8 * (v6 >> 6) )
          goto LABEL_7;
      }
      _BitScanForward64(&v10, ~i);
      v9 = v10 + (((__int64)v7 - *(&stru_140C4DB30 + 293)) >> 3 << 6);
      if( v9 > v6 )
      {
LABEL_7:
        v9 = -1i64;
      }
      else if( v9 != -1i64 )
      {
        break;
      }
      if( !v5 )
        break;
      v11 = v4 + 1;
      if( v4 + 1 > *(&stru_140C4DB30 + 292) )
        v11 = *(&stru_140C4DB30 + 292);
      v6 = v11 - 1;
      v5 = 0i64;
    }
    if( v9 < v4 || v9 == -1i64 )
      return v1;
    if( *(&stru_140C4DB30 + 292) > v9 )
    {
      v13 = v9;
      v14 = *(&stru_140C4DB30 + 293) + 4 * ((unsigned __int64)(*(&stru_140C4DB30 + 292) - 1i64) >> 5);
      v15 = (_DWORD *)(*(&stru_140C4DB30 + 293) + 4 * (v9 >> 5));
      if( v15 != (_DWORD *)v14 && (*v15 | *((_DWORD *)qword_140011CE0 + (v9 & 0x1F))) == -1 )
      {
        v13 = (v9 & 0xFFFFFFFFFFFFFFE0ui64) + 32;
        for( ++v15; (unsigned __int64)v15 < v14 && *v15 == -1; ++v15 )
          v13 += 32i64;
      }
      while( v13 < *(&stru_140C4DB30 + 292) && _bittest64(*(&stru_140C4DB30 + 293), v13) )
        ++v13;
      v12 = 0i64;
      if( v15 == (_DWORD *)v14 )
        goto LABEL_38;
      v16 = v13 & 0x1F;
      if( (~*((_DWORD *)qword_140011CE0 + v16) & *v15) != 0 )
        goto LABEL_38;
      v12 = 32 - v16;
      if( v16 != 33 )
      {
        v17 = v15 + 1;
        while( (unsigned __int64)v17 < v14 && !*v17 )
        {
          ++v17;
          v12 += 32i64;
          if( v12 == -1i64 )
            goto LABEL_43;
        }
LABEL_38:
        for( j = v12 + v13; j < *(&stru_140C4DB30 + 292) && !_bittest64(*(&stru_140C4DB30 + 293), j) && v12 != -1i64; ++j )
          ++v12;
      }
LABEL_43:
      if( v12 )
        goto LABEL_45;
      goto LABEL_44;
    }
    v12 = 0i64;
LABEL_44:
    v13 = *(&stru_140C4DB30 + 292);
LABEL_45:
    v19 = v13 - v9;
    v1 = (*(__int64(__fastcall **)(unsigned __int64, unsigned __int64))(a1 + 24))(v9 << 12, v19 << 12);
    if( v1 >= 0 )
    {
      v4 = v19 + v12 + v9;
      if( v4 < *(&stru_140C4DB30 + 292) )
        continue;
    }
    return v1;
  }
}

Referenced by:

MmDuplicateMemory