PopPepWork

char __fastcall PopPepWork(__int64 a1){
  _ETHREAD *CurrentThread; 
  unsigned int v2; 
  int v3; 
  EVENT_DESCRIPTOR *v4; 
  INT64 v5; 
  __int64 v6; 
  UINT64 v7; 
  unsigned __int8 CurrentIrql; 
  unsigned int v9; 
  INT64 v10; 
  INT64 *v11; 
  __int64 v12; 
  int v13; 
  unsigned int v14; 
  INT64 v15; 
  unsigned int ReadyActivityType; 
  char started; 
  unsigned int v18; 
  unsigned int v19; 
  int v21; 
  unsigned int v22; 
  INT64 v23; 
  LPCGUID ActivityId; 
  UINT64 UserDataCount; 
  int a5; 
  __int64 v28; 
  INT64 a1a; 
  EVENT_DATA_DESCRIPTOR UserData; 
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v2 = 0;
  a5 = 0;
  v3 = 0;
  --*((_WORD *)CurrentThread + 242);
  ExAcquirePushLockSharedEx((UINT64)&PopPepDeviceListLock, 0i64);
  v5 = PopPepLastCheckedDevice;
  if( (INT64 *)PopPepLastCheckedDevice == &PopPepDeviceList )
  {
    _InterlockedCompareExchange64(&PopPepLastCheckedDevice, *(_QWORD *)PopPepLastCheckedDevice, PopPepLastCheckedDevice);
    v5 = PopPepLastCheckedDevice;
  }
  v6 = *(_QWORD *)(v5 + 32);
  v28 = 0i64;
  if( PopDiagHandleRegistered )
  {
    v7 = PopDiagHandle;
    if( EtwEventEnabled(PopDiagHandle, (EVENT_DESCRIPTOR *)&POP_ETW_EVENT_DEFAULT_PEP_WORKER_START, v4) )
    {
      if( v6 )
        v28 = *(_QWORD *)(v6 + 48);
      *(_QWORD *)&UserData.Size = 8i64;
      UserData.Ptr = (unsigned __int64)&v28;
      LODWORD(UserDataCount) = 1;
      EtwWriteEx(
        v7,
        (EVENT_DESCRIPTOR *)&POP_ETW_EVENT_DEFAULT_PEP_WORKER_START,
        0i64,
        1ui64,
        0i64,
        0i64,
        UserDataCount,
        &UserData);
    }
    v3 = 0;
  }
  CurrentIrql = KeGetCurrentIrql();
  __writecr8(2ui64);
  v9 = 0;
  while( 2 )
  {
    v10 = v5;
    do
    {
      a1a = 0i64;
      v11 = (INT64 *)(v10 + 64);
      if( v9 )
      {
        ExAcquireSpinLockExclusiveAtDpcLevel(v11);
        v21 = v3 + 1;
        if( v9 != 2 )
          v21 = v3;
        a5 = v21;
      }
      else if( !(unsigned int)ExTryAcquireSpinLockExclusiveAtDpcLevel(v11) )
      {
        goto LABEL_19;
      }
      v12 = *(_QWORD *)(v10 + 32);
      if( v12 )
        a1a = *(_QWORD *)(v12 + 48);
      v13 = *(_DWORD *)(v10 + 120);
      if( v13 )
      {
        ReadyActivityType = PopPepGetReadyActivityType(v10 + 72, 0i64, 0i64);
        if( ReadyActivityType != 6 )
        {
          started = PopPepStartActivity(v10, 0i64, v10 + 72, ReadyActivityType, (volatile INT32 *)(v10 + 120), a1);
          ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v10 + 64));
          v18 = 1;
          goto LABEL_27;
        }
      }
      v14 = *(_DWORD *)(v10 + 180);
      v2 = 0;
      if( v14 )
      {
        v15 = v10 + 184;
        while( !*(_DWORD *)(v15 + 104) )
        {
          ++v2;
          v15 += 200i64;
          if( v2 >= v14 )
            goto LABEL_17;
        }
        v22 = PopPepGetReadyActivityType(v15 + 56, 1ui64, 3i64);
        started = PopPepStartActivity(v10, v23, v23 + 56, v22, (volatile INT32 *)(v23 + 104), a1);
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v10 + 64));
        v18 = 2;
        goto LABEL_27;
      }
LABEL_17:
      if( v13 )
      {
        v19 = PopPepGetReadyActivityType(v10 + 72, 4ui64, 5i64);
        started = PopPepStartActivity(v10, 0i64, v10 + 72, v19, (volatile INT32 *)(v10 + 120), a1);
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v10 + 64));
        v18 = 3;
        goto LABEL_27;
      }
      ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v10 + 64));
LABEL_19:
      v10 = *(_QWORD *)v10;
      if( (INT64 *)v10 == &PopPepDeviceList )
        v10 = *(_QWORD *)v10;
      v3 = a5;
    }
    while( v10 != v5 );
    if( ++v9 < 3 )
      continue;
    break;
  }
  started = 0;
  v18 = 0;
LABEL_27:
  __writecr8(CurrentIrql);
  if( v10 != v5 )
    _InterlockedExchange64(&PopPepLastCheckedDevice, v10);
  if( _InterlockedCompareExchange64((volatile signed __int64 *)&PopPepDeviceListLock, 0i64, 17i64) != 17 )
    ExfReleasePushLockShared((INT64 *)&PopPepDeviceListLock);
  KeAbPostRelease(&PopPepDeviceListLock);
  KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
  LODWORD(ActivityId) = a5;
  PopDiagTraceFxDefaultPepWorkerEnd(a1a, v18, (EVENT_DESCRIPTOR *)v2, v9, (INT64)ActivityId);
  return started;
}

Referenced by:

PopFxDispatchPluginWorkOnce