PiSwBusRelationAdd

NTSTATUS __stdcall PiSwBusRelationAdd(WCHAR *ParentDeviceInstance, PI_SWD_OBJECT *SwDeviceObject){
  int v3; 
  PVOID v4; 
  NTSTATUS v5; 
  __int64 v6; 
  _WORD *v7; 
  __int64 v8; 
  _QWORD *inserted; 
  PI_SWD_OBJECT *v10; 
  PI_SWD_OBJECT **v11; 
  PI_SWD_OBJECT *v12; 
  __int128 Buffer[2]; 
  UINT8 NewElement; 
  PVOID P; 

  P = 0i64;
  NewElement = 0;
  memset(Buffer, 0, sizeof(Buffer));
  v3 = PnpAllocatePWSTR(ParentDeviceInstance, 0xC8ui64, 0x57706E50u, &P);
  v4 = P;
  v5 = v3;
  if( v3 >= 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 *)SwDeviceObject + 14) = inserted;
        v10 = SwDeviceObject + 24;
        v11 = (PI_SWD_OBJECT **)inserted[3];
        v12 = (PI_SWD_OBJECT *)(inserted + 2);
        if( *v11 != v12 )
          __fastfail(3u);
        *(_QWORD *)v10 = v12;
        *((_QWORD *)SwDeviceObject + 13) = v11;
        *v11 = v10;
        *((_QWORD *)v12 + 1) = v10;
        _InterlockedIncrement(SwDeviceObject);
        v4 = P;
      }
    }
  }
  if( v4 )
    ExFreePoolWithTag(v4, 0x57706E50u);
  return v5;
}

Referenced by:

PiSwIrpStartCreateWorker
PiSwProcessRemove