PiSwBusRelationAdd

INT64 __fastcall PiSwBusRelationAdd(const WCHAR *a1, INT64 a2){
  int PWSTR; 
  PVOID v4; 
  signed int v5; 
  __int64 v6; 
  _WORD *v7; 
  __int64 v8; 
  _QWORD *inserted; 
  char *v10; 
  char **v11; 
  char *v12; 
  __int128 Buffer[2]; 
  unsigned __int8 NewElement; 
  PVOID P; 
  P = 0i64;
  NewElement = 0;
  memset(Buffer, 0, sizeof(Buffer));
  PWSTR = PnpAllocatePWSTR((WCHAR *)a1, 0xC8ui64, 0x57706E50ui64, (WCHAR **)&P);
  v4 = P;
  v5 = PWSTR;
  if( PWSTR >= 0 )
  {
    v5 = 0;
    if( P )
    {
      v6 = 0x7FFFi64;
      v7 = P;
      do
      {
        if( !*v7 )
          break;
        ++v7;
        --v6;
      }
      while( v6 );
      v8 = (0x7FFF - v6) & -(__int64)(v6 != 0);
      v5 = v6 == 0 ? 0xC000000D : 0;
      if( v6 )
      {
        *((_QWORD *)&Buffer[0] + 1) = P;
        LOWORD(Buffer[0]) = 2 * v8;
        WORD1(Buffer[0]) = 2 * v8 + 2;
      }
    }
    if( v5 >= 0 )
    {
      inserted = RtlInsertElementGenericTableAvl(&PiSwBusRelationsTable, Buffer, 0x20ui64, &NewElement);
      if( inserted )
      {
        if( NewElement )
        {
          v4 = 0i64;
          inserted[3] = inserted + 2;
          inserted[2] = inserted + 2;
          P = 0i64;
        }
      }
      else
      {
        v5 = -1073741670;
      }
      if( v5 >= 0 )
      {
        *(_QWORD *)(a2 + 112) = inserted;
        v10 = (char *)(a2 + 96);
        v11 = (char **)inserted[3];
        v12 = (char *)(inserted + 2);
        if( *v11 != v12 )
          __fastfail(3u);
        *(_QWORD *)v10 = v12;
        *(_QWORD *)(a2 + 104) = v11;
        *v11 = v10;
        *((_QWORD *)v12 + 1) = v10;
        _InterlockedIncrement((volatile signed __int32 *)a2);
        v4 = P;
      }
    }
  }
  if( v4 )
    ExFreePoolWithTag(v4, 0x57706E50u);
  return(unsigned int)v5;
}

Referenced by:

PiSwIrpStartCreateWorker
PiSwProcessRemove