PfSnBeginScenario

__int64 __fastcall PfSnBeginScenario(void *a1, _OWORD *a2, int a3, unsigned int a4, VOID **a5){
  _ETHREAD *CurrentThread; 
  int v6; 
  _OWORD *v8; 
  __int16 v9; 
  __int64 v10; 
  int v11; 
  int v12; 
  _BYTE *v13; 
  INT64 v14; 
  unsigned int started; 
  int v17; 
  UINT64 v18; 
  NTSTATUS v19; 
  char PreviousMode; 
  int v21; 
  int v22; 
  int v23; 
  PVOID P; 
  INT64 v25; 

  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v6 = a3;
  v23 = -1;
  v21 = 0;
  v8 = a2;
  v22 = 0;
  v9 = 0;
  PreviousMode = CurrentThread->Tcb.PreviousMode;
  v10 = -1i64;
  P = 0i64;
  v25 = 0i64;
  CurrentThread->Tcb.PreviousMode = 0;
  if( PsGetIoPriorityThread(CurrentThread) < IoPriorityNormal )
  {
    started = 1075380276;
    goto LABEL_19;
  }
  v12 = v11 + 1;
  if( v11 + 1 + _InterlockedExchangeAdd(dword_140C501F0, v11 + 1) < (unsigned int)dword_140C4FE88 )
  {
    v9 = PfSnCheckActionsNeeded((__int64)v8, v6, CurrentThread, &v21, &v22);
    if( (a4 & 2) != 0 )
    {
      v9 &= ~2u;
      v22 = 9;
    }
    if( (v9 & 2) != 0 )
    {
      if( (int)PfSnGetPrefetchInstructions((__int64)v8, v6, &P) >= 0 )
      {
        v13 = P;
        v10 = *(_QWORD *)&KUSER_SHARED_DATA.SystemTime.LowPart - *((_QWORD *)P + 16);
        if( v10 < *((_QWORD *)P + 24) && v21 != 22 )
        {
          v9 &= ~1u;
          v21 = 11;
        }
        v23 = *((_DWORD *)P + 50);
LABEL_7:
        if( (a4 & 4) != 0 )
        {
          v9 &= ~1u;
          v21 = 8;
        }
        if( ((unsigned __int8)v9 & (unsigned __int8)v12) != 0 )
        {
          v17 = PfSnBeginTrace(
                  a2,
                  v6,
                  a1,
                  (_ETHREAD *)((unsigned __int64)CurrentThread & -(__int64)(((unsigned __int8)v12 & (unsigned __int8)a4) != 0)),
                  v12 & (a4 >> 3),
                  &v25);
          if( v17 < 0 )
          {
            switch( v17 )
            {
              case -1073741618:
                v21 = 16;
                break;
              case -1073741670:
                v21 = 17;
                break;
              case -1072037882:
                v21 = 18;
                break;
              case -1073741791:
                v21 = 19;
                break;
              default:
                v21 = (v17 != -1073741661) + 20;
                break;
            }
          }
          v14 = v25;
          if( v25 && a5 )
            PfSnLogIdentifier(v25, (const VOID **)a5);
        }
        else
        {
          v14 = v25;
        }
        if( (v9 & 2) != 0 )
        {
          v18 = a4 | 0x10;
          if( (v13[208] & 3) == 0 )
            v18 = a4;
          v19 = PfSnPrefetchScenario(v13, v18);
          P = 0i64;
          v13 = 0i64;
          if( v19 >= 0 )
            LOBYTE(v12) = 0;
        }
        started = 0;
        if( !(_BYTE)v12 )
          goto LABEL_14;
        goto LABEL_13;
      }
      v9 &= ~2u;
      v22 = 10;
    }
    v13 = P;
    goto LABEL_7;
  }
  v21 = v11 + 1;
  started = -1073741631;
  v22 = v11 + 1;
LABEL_13:
  _InterlockedDecrement(dword_140C501F0);
  v13 = P;
  v14 = v25;
LABEL_14:
  if( v13 )
    ExFreePoolWithTag(v13, 0);
  if( v14 )
  {
    started = PfSnStartTraceTimer((PFSN_TRACE_HEADER *)v14);
    ExReleaseRundownProtection((_EX_RUNDOWN_REF *)(v14 + 360));
  }
  v8 = a2;
  v6 = a3;
LABEL_19:
  PfSnLogScenarioDecision((__int64)v8, v6, v9, v21, v22, v23, v10);
  CurrentThread->Tcb.PreviousMode = PreviousMode;
  return started;
}

Referenced by:

PfSnBeginAppLaunch
PfSnOperationProcess