RtlAddAtomToAtomTableEx

NTSTATUS __stdcall RtlAddAtomToAtomTableEx(VOID *AtomTableHandle, WCHAR *AtomName, UINT16 *Atom, UINT64 Flags){
  unsigned int v4; 
  int v8; 
  __int64 v9; 
  _RTL_ATOM_TABLE_ENTRY **v10; 
  _RTL_ATOM_TABLE_ENTRY *v11; 
  _RTL_ATOM_TABLE_ENTRY *v12; 
  unsigned __int64 v13; 
  __int64 v14; 
  UINT16 v15; 
  __int16 Atoma[2]; 
  int v18; 
  UINT64 NameLength; 
  _RTL_ATOM_TABLE_REFERENCE *LowBox; 
  _RTL_ATOM_TABLE_ENTRY *AtomEntry; 
  _RTL_ATOM_TABLE_ENTRY **PreviousAtom; 

  v4 = Flags;
  AtomEntry = 0i64;
  PreviousAtom = 0i64;
  LODWORD(NameLength) = 0;
  Atoma[0] = 0;
  LowBox = 0i64;
  if( RtlpLockAtomTable((_RTL_ATOM_TABLE *)AtomTableHandle) )
  {
    if( RtlGetIntegerAtom((UINT64)AtomName, (WORD *)Atoma) )
    {
      v15 = Atoma[0];
      if( Atoma[0] >= 0xC000u )
      {
        v15 = 0;
        Atoma[0] = 0;
        v8 = -1073741811;
        v18 = -1073741811;
      }
      else
      {
        v8 = 0;
        v18 = 0;
      }
      if( Atom )
        *Atom = v15;
      goto LABEL_27;
    }
    if( *AtomName )
    {
      v8 = RtlpHashStringToAtom(
             (_RTL_ATOM_TABLE *)AtomTableHandle,
             AtomName,
             0,
             &PreviousAtom,
             &NameLength,
             &LowBox,
             &AtomEntry);
      v18 = v8;
      if( v8 < 0 )
      {
LABEL_27:
        RtlpUnlockAtomTable((_RTL_ATOM_TABLE *)AtomTableHandle);
        return v8;
      }
      if( AtomEntry )
      {
        RtlpReferenceAtom(AtomEntry, LowBox);
        if( Atom )
          *Atom = *(_WORD *)(v9 + 10);
        v8 = 0;
        v18 = 0;
        goto LABEL_27;
      }
      v10 = PreviousAtom;
      if( PreviousAtom )
      {
        v8 = -1073741801;
        v18 = -1073741801;
        v11 = RtlpAllocateAtomTableEntry((unsigned int)NameLength, &LowBox, v4);
        v12 = v11;
        AtomEntry = v11;
        if( v11 )
        {
          v13 = (unsigned int)NameLength;
          memmove(v11->Name, AtomName, NameLength);
          v14 = (unsigned __int8)(v13 >> 1);
          v12->NameLength = v14;
          v12->Name[v14] = 0;
          if( RtlpInsertStringAtom((_RTL_ATOM_TABLE *)AtomTableHandle, v12) )
          {
            v12->Atom = v12->HandleIndex | 0xC000;
            *v10 = v12;
            if( Atom )
              *Atom = v12->Atom;
            v8 = 0;
            v18 = 0;
          }
          else
          {
            if( LowBox && LowBox != &v12->Reference )
              RtlpFreeAtom(LowBox);
            RtlpFreeAtom(v12);
          }
        }
        goto LABEL_27;
      }
      v8 = -1073741811;
    }
    else
    {
      v8 = -1073741773;
    }
    v18 = v8;
    goto LABEL_27;
  }
  return -1073741811;
}

Referenced by:

NtAddAtomEx
RtlAddAtomToAtomTable