PoFxPrepareDevice

LONG __fastcall PoFxPrepareDevice(__int64 a1, char a2){
  LONG result; 
  signed __int32 v5; 
  signed __int32 v6; 
  _ETHREAD *CurrentThread; 
  ULONG_PTR *v8; 
  ULONG_PTR *v9; 
  _POP_FX_DEVICE *v10; 
  INT64 v11; 
  _POP_FX_DEVICE *FoundFxDevice; 
  FoundFxDevice = 0i64;
  _m_prefetchw((const void *)(a1 + 296));
  result = _InterlockedOr((volatile signed __int32 *)(a1 + 296), 0);
  if( (result & 1) != 0 )
    return result;
  _m_prefetchw((const void *)(a1 + 296));
  v5 = *(_DWORD *)(a1 + 296);
  do
  {
    v6 = v5;
    v5 = _InterlockedCompareExchange((volatile signed __int32 *)(a1 + 296), v5, v5);
  }
  while( v6 != v5 );
  if( (v5 & 2) != 0 )
    goto LABEL_7;
  result = PopFxFindDeviceAndAllocateUniqueId((_DEVICE_NODE *)a1, &FoundFxDevice);
  if( result != -1073741738 )
  {
    _InterlockedOr((volatile signed __int32 *)(a1 + 296), 2u);
LABEL_7:
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 242);
    ExAcquirePushLockSharedEx((UINT64)&PopFxPluginLock, 0i64);
    v8 = (ULONG_PTR *)PopFxPluginList;
    v9 = 0i64;
    while( v8 != &PopFxPluginList )
    {
      if( PopPluginPrepareDevice((ULONG_PTR)v8, a1) )
      {
        PopDiagTraceFxDevicePreparation((PVOID)a1, v8, (UNICODE_STRING *)(a1 + 128), 1u, v11);
        v9 = v8;
        if( v8 )
          goto LABEL_14;
        break;
      }
      v8 = (ULONG_PTR *)*v8;
    }
    if( !a2 )
      goto LABEL_15;
LABEL_14:
    *(_QWORD *)(a1 + 144) = v9;
    _InterlockedOr((volatile signed __int32 *)(a1 + 296), 1u);
    *(_WORD *)(a1 + 96) = 0;
    *(_QWORD *)(a1 + 112) = a1 + 104;
    *(_QWORD *)(a1 + 104) = a1 + 104;
    *(_BYTE *)(a1 + 98) = 6;
    *(_DWORD *)(a1 + 100) = 0;
LABEL_15:
    if( _InterlockedCompareExchange64((volatile signed __int64 *)&PopFxPluginLock, 0i64, 17i64) != 17 )
      ExfReleasePushLockShared((INT64 *)&PopFxPluginLock);
    KeAbPostRelease(&PopFxPluginLock);
    result = (unsigned int)KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
  }
  v10 = FoundFxDevice;
  if( FoundFxDevice )
  {
    result = _InterlockedDecrement((volatile signed __int32 *)FoundFxDevice + 69);
    if( !result )
      return KeSetEvent((PRKEVENT)((char *)v10 + 280), 0);
  }
  return result;
}

Referenced by:

PiProcessAddBootDevices
PipProcessDevNodeTree
PnpStartDevice