MiClearRangeInPartitionTree

INT64 __fastcall MiClearRangeInPartitionTree(RTL_BALANCED_NODE **a1, INT64 a2, UINT64 a3){
  UINT64 v3; 
  INT64 v4; 
  INT64 v5; 
  INT64 result; 
  UINT64 v8; 
  RTL_BALANCED_NODE *v9; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  unsigned __int64 *v12; 
  UINT64 v13; 
  unsigned __int64 v14; 
  __int64 *ParentValue; 
  __int64 v16; 
  __int64 *v17; 
  bool v18; 
  bool i; 
  v3 = a3;
  v4 = a2 & 0x7FFFFFFFFFFC0000i64;
  v5 = a2;
  result = a2 - (a2 & 0x7FFFFFFFFFFC0000i64);
  v8 = (result + a3 + 0x3FFFF) >> 18;
  if( v8 )
  {
    while( 1 )
    {
      v9 = *a1;
      if( *a1 )
      {
        v10 = v4 & 0x7FFFFFFFFFFFFFFFi64;
        do
        {
          v11 = (__int64)v9[1].Children[0] & 0x7FFFFFFFFFFFFFFFi64;
          if( v10 < v11 )
          {
            v9 = v9->Children[0];
          }
          else
          {
            if( v10 <= v11 )
              break;
            v9 = v9->Children[1];
          }
        }
        while( v9 );
      }
      v12 = (unsigned __int64 *)&v9[1].Children[1];
      v13 = v3;
      if( ((unsigned __int64)v9[1].Children[0] & 0x7FFFFFFFFFFFFFFFi64) - v5 + 0x40000 <= v3 )
        v13 = ((__int64)v9[1].Children[0] & 0x7FFFFFFFFFFFFFFFi64) - v5 + 0x40000;
      RtlClearBitsEx((INT64)&v9[1].Children[1], v5 - ((__int64)v9[1].Children[0] & 0x7FFFFFFFFFFFFFFFi64), v13);
      v14 = *v12;
      if( !*v12 )
        goto LABEL_24;
      if( v14 <= 1 )
        break;
      ParentValue = (__int64 *)v9[1].ParentValue;
      v16 = *ParentValue;
      v17 = &ParentValue[(v14 - 1) >> 6];
      if( ParentValue != v17 )
      {
        for( i = v16 == 0; i; i = *ParentValue == 0 )
        {
          if( ++ParentValue == v17 )
          {
            v18 = ((0xFFFFFFFFFFFFFFFFui64 >> ~((unsigned __int8)v14 - 1)) & *ParentValue) == 0;
            goto LABEL_22;
          }
        }
        goto LABEL_24;
      }
      v18 = (v16 & (0xFFFFFFFFFFFFFFFFui64 >> (64 - (unsigned __int8)v14))) == 0;
LABEL_22:
      if( v18 )
        goto LABEL_23;
LABEL_24:
      v5 += v13;
      result = (v4 ^ (v4 + 0x40000)) & 0x7FFFFFFFFFFFFFFFi64;
      v3 -= v13;
      v4 ^= result;
      if( !--v8 )
        return result;
    }
    if( _bittest64((const signed __int64 *)v9[1].ParentValue, 0) )
      goto LABEL_24;
LABEL_23:
    RtlAvlRemoveNode((unsigned __int64 *)a1, (__int64 *)v9);
    ExFreePoolWithTag((PVOID)v9[1].ParentValue, 0);
    ExFreePoolWithTag(v9, 0);
    goto LABEL_24;
  }
  return result;
}

Referenced by:

MiAddMdlToPartitionTree