RtlInsertElementGenericTableFullAvl

UINT64 __stdcall RtlInsertElementGenericTableFullAvl(RTL_BITMAP *BitMapHeader, UINT64 NumberToFind, UINT64 HINTIndex){
  bool *v3; 
  bool *v4; 
  UINT64 v5; 
  _RTL_BALANCED_LINKS *v8; 
  RTL_BALANCED_LINKS *v9; 
  RTL_BALANCED_LINKS *v10; 
  RTL_BALANCED_LINKS *v11; 
  _RTL_BALANCED_LINKS *i; 
  bool v13; 
  char v14; 
  char Balance; 
  RTL_BALANCED_LINKS *NodeOrParent; 
  TABLE_SEARCH_RESULT SearchResult; 
  v4 = v3;
  v5 = (unsigned int)HINTIndex;
  if( SearchResult == TableFoundNode )
  {
    v9 = NodeOrParent;
LABEL_16:
    if( v4 )
      *v4 = SearchResult != TableFoundNode;
    LODWORD(BitMapHeader[2].Buffer) = 0;
    *(_QWORD *)&BitMapHeader[2].SizeOfBitMap = 0i64;
    return(UINT64)&v9[1];
  }
  if( (int)HINTIndex + 32 >= (unsigned int)HINTIndex )
  {
    v8 = (_RTL_BALANCED_LINKS *)(*(__int64(**)(void))&BitMapHeader[5].SizeOfBitMap)();
    v9 = v8;
    if( v8 )
    {
      *(_OWORD *)&v8->Parent = 0i64;
      *(_OWORD *)&v8->RightChild = 0i64;
      ++HIDWORD(BitMapHeader[2].Buffer);
      if( SearchResult )
      {
        v10 = NodeOrParent;
        v11 = v8;
        if( SearchResult == TableInsertAsLeft )
          NodeOrParent->LeftChild = v8;
        else
          NodeOrParent->RightChild = v8;
        v8->Parent = NodeOrParent;
        LOBYTE(BitMapHeader[1].Buffer) = -1;
        for( i = v8->Parent; ; v10 = i )
        {
          v13 = i->LeftChild == v11;
          v14 = -1;
          Balance = v10->Balance;
          if( !v13 )
            v14 = 1;
          if( Balance )
            break;
          i = v10->Parent;
          v11 = v10;
          v10->Balance = v14;
        }
        if( Balance == v14 )
        {
          RebalanceNode(v10);
        }
        else
        {
          v10->Balance = 0;
          if( !LOBYTE(BitMapHeader[1].Buffer) )
            ++BitMapHeader[3].SizeOfBitMap;
        }
      }
      else
      {
        *(_QWORD *)&BitMapHeader[1].SizeOfBitMap = v8;
        v8->Parent = (_RTL_BALANCED_LINKS *)BitMapHeader;
        BitMapHeader[3].SizeOfBitMap = 1;
      }
      memmove((UINT8 *)&v9[1], (UINT8 *)NumberToFind, v5);
      goto LABEL_16;
    }
  }
  if( v4 )
    *v4 = 0;
  return 0i64;
}

Referenced by:

PiDmAddCacheReferenceForObject
PiPnpRtlObjectEventCreate
RtlInsertElementGenericTableAvl