MiRemoveUnmappedIoNode

_RTL_BALANCED_NODE *__stdcall 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((UINT64 *)a1, (INT64 *)i);
  v5 = i + 1;
  if( (_RTL_BALANCED_NODE *)*(&stru_140C4DB30 + 462) == &i[1]
    && v5->Children[0] != (_RTL_BALANCED_NODE *)((char *)&stru_140C4DB30 + 3696) )
  {
    *(&stru_140C4DB30 + 928) = 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((_MI_IO_PFN_NODE *)i);
  }
  i[2].Children[1] = 0i64;
  result = i;
  --*(&stru_140C4DB30 + 465);
  return result;
}

Referenced by:

MiMakeIoRangePermanent
MiReferenceIoPages