MiRemoveUnmappedIoNode

RTL_BALANCED_NODE *__fastcall MiRemoveUnmappedIoNode(RTL_BALANCED_NODE **a1, UINT64 a2){
  RTL_BALANCED_NODE *i; 
  UINT64 ParentValue; 
  RTL_BALANCED_NODE *result; 
  RTL_BALANCED_NODE *v5; 
  _RTL_BALANCED_NODE *v6; 
  _RTL_BALANCED_NODE *v7; 
  int Right; 
  int v9[10]; 
  for( i = *a1; ; i = i->Children[1] )
  {
    while( 1 )
    {
      if( !i )
        return 0i64;
      ParentValue = i[1].ParentValue;
      if( a2 >= ParentValue )
        break;
      i = i->Children[0];
    }
    if( a2 < ParentValue + 512 )
      break;
  }
  RtlAvlRemoveNode((unsigned __int64 *)a1, (__int64 *)i);
  v5 = i + 1;
  if( (RTL_BALANCED_NODE *)qword_140C4E9A0 == &i[1] && (__int64 *)v5->Children[0] != &qword_140C4E9A0 )
    dword_140C4E9B0 = (int)v5->Children[0][1].Right;
  v6 = v5->Children[0];
  if( v5->Children[0]->Children[1] != v5 || (v7 = i[1].Children[1], v7->Children[0] != v5) )
    __fastfail(3u);
  v7->Children[0] = v6;
  v6->Children[1] = v7;
  _InterlockedOr(v9, 0);
  Right = (int)i[2].Right;
  if( (unsigned int)(KiCacheFlushTimeStamp - Right) > 2
    || (Right & 1) == 0 && (unsigned int)(KiCacheFlushTimeStamp - Right) >= 2 )
  {
    MiInitializeIoPageNodeArray((INT64)i);
  }
  i[2].Children[1] = 0i64;
  result = i;
  --qword_140C4E9B8;
  return result;
}

Referenced by:

MiMakeIoRangePermanent
MiReferenceIoPages