KeTransitionProcessorParkState

unsigned __int8 __fastcall KeTransitionProcessorParkState(__int64 a1, int a2){
  char v3; 
  char v4; 
  __int64 v5; 
  unsigned __int64 v6; 
  bool v7; 
  __int64 v8; 
  __int64 v9; 
  unsigned __int64 v10; 
  char v11; 
  unsigned __int64 v12; 
  __int64 v13; 
  __int64 v14; 
  __int64 v15; 
  int v16; 
  int v17; 
  UINT8 v18; 
  unsigned __int8 result; 
  int v20; 
  char v21; 
  INT64 v22; 
  char v23; 
  __int64 v24; 
  char v25; 
  bool v26; 
  UINT64 v27; 
  char v28; 
  char v29; 
  INT64 v30; 
  UINT64 v31; 
  __int64 v32; 
  bool v33; 
  UINT64 SpinCount; 
  UINT64 v35; 
  SINGLE_LIST_ENTRY DeferredList; 
  char v37; 
  char v38; 
  DeferredList.Next = 0i64;
  v3 = 0;
  v38 = 0;
  v4 = 0;
  v37 = 0;
  v5 = *(_QWORD *)(a1 + 192);
  v6 = *(_QWORD *)(a1 + 200);
  if( !a2 )
  {
    v37 = 1;
    v7 = (v6 & *(_QWORD *)(v5 + 88)) != 0;
    goto LABEL_10;
  }
  _m_prefetchw((const void *)(v5 + 80));
  if( (v6 & *(_QWORD *)(v5 + 80)) != 0 )
  {
    v3 = 1;
    v4 = 1;
    if( a2 == 2 )
    {
      v7 = 1;
      goto LABEL_10;
    }
    v7 = 0;
  }
  else
  {
    v7 = 1;
  }
  v4 = v3;
  if( a2 == 1 )
    v3 = 1;
LABEL_10:
  ExAcquireSpinLockExclusiveAtDpcLevel((INT64 *)(v5 + 104));
  LODWORD(SpinCount) = 0;
  while( _interlockedbittestandset64((volatile signed __int32 *)(a1 + 48), 0i64) )
  {
    do
      KeYieldProcessorEx(&SpinCount);
    while( *(_QWORD *)(a1 + 48) );
  }
  if( v4 || v37 )
  {
    _InterlockedXor64((volatile signed __int64 *)(v5 + 80), v6);
    v8 = *(_QWORD *)(a1 + 33856);
    if( v8 )
    {
      v9 = *(_QWORD *)(a1 + 33864);
      v10 = v8 & *(_QWORD *)(v5 + 80);
      if( !v10 )
      {
        v38 = 1;
        goto LABEL_25;
      }
      if( v10 == v6 )
      {
        *((_DWORD *)*(&KiProcessorBlock
                    + (unsigned int)KiProcessorNumberToIndexMappingTable[64
                                                                       * (unsigned __int64)*(unsigned __int8 *)(a1 + 208)
                                                                       + *(unsigned __int8 *)(v9 + 596)])
        + 8468) = 0;
        v11 = *(_BYTE *)(a1 + 209);
        *(_DWORD *)(a1 + 33872) = 1;
LABEL_24:
        *(_BYTE *)(v9 + 596) = v11;
        goto LABEL_25;
      }
      if( *(_DWORD *)(a1 + 33872) && v4 )
      {
        _BitScanReverse64(&v12, v10);
        v13 = (unsigned int)v12 + (*(unsigned __int8 *)(a1 + 208) << 6);
        HIDWORD(SpinCount) = v12;
        v14 = (__int64)*(&KiProcessorBlock + (unsigned int)KiProcessorNumberToIndexMappingTable[v13]);
        *(_DWORD *)(a1 + 33872) = 0;
        *(_DWORD *)(v14 + 33872) = 1;
        v11 = *(_BYTE *)(v14 + 209);
        goto LABEL_24;
      }
    }
  }
LABEL_25:
  if( v7 )
    _InterlockedXor64((volatile signed __int64 *)(v5 + 88), v6);
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v5 + 104));
  v15 = *(_QWORD *)(a1 + 24);
  if( v37 )
  {
    v16 = *(unsigned __int8 *)(a1 + 35);
    if( (v16 & 2) != 0 )
    {
      v17 = v16 - 2;
      if( v7 )
        v17 = *(unsigned __int8 *)(a1 + 35) - 6;
      *(_BYTE *)(a1 + 35) = v17;
      if( !v17 )
        _InterlockedXor64((volatile signed __int64 *)v5, v6);
      v18 = 0;
      if( !v17 )
      {
        *(_BYTE *)(a1 + 12587) = 1;
        v18 = 1;
      }
      KiUpdateThreadPriority((_KPRCB *)a1, (_KTHREAD *)v15, 0i64, v18);
      _InterlockedAnd64((volatile signed __int64 *)(a1 + 48), 0i64);
      if( v18 && KeHeteroSystem && !KeHeteroSystemVirtual )
        KiSendHeteroRescheduleIntRequest((_QWORD *)a1);
      result = 106;
      _InterlockedAdd16((volatile signed __int16 *)&KUSER_SHARED_DATA.UnparkedProcessorCount, 1u);
      return result;
    }
LABEL_53:
    __fastfail(0x21u);
  }
  if( !v4 && !v3 )
  {
    result = *(_BYTE *)(a1 + 35) & 6;
    if( result == 2 )
    {
      *(_BYTE *)(a1 + 35) += 4;
      _InterlockedAnd64((volatile signed __int64 *)(a1 + 48), 0i64);
      return result;
    }
    goto LABEL_53;
  }
  v20 = *(unsigned __int8 *)(a1 + 35);
  if( v4 )
  {
    if( (v20 & 6) != 0 )
      goto LABEL_53;
    v20 += 2;
    if( v20 == 2 )
      _InterlockedXor64((volatile signed __int64 *)v5, v6);
  }
  v21 = v20 ^ 4;
  if( !v7 )
    v21 = v20;
  v22 = *(_QWORD *)(a1 + 16);
  *(_BYTE *)(a1 + 35) = v21;
  if( !v22 || v22 == v15 )
  {
    v23 = 0;
  }
  else
  {
    *(_QWORD *)(a1 + 16) = 0i64;
    _interlockedbittestandreset((volatile signed __int32 *)(v22 + 120), 0xCu);
    KiInsertDeferredReadyList((INT64)&DeferredList, v22);
    v22 = 0i64;
    v23 = 1;
  }
  v24 = *(_QWORD *)(a1 + 8);
  v25 = 1;
  if( v24 == v15 )
  {
    if( v23 )
    {
      KiSetProcessorIdle((_KPRCB *)a1, 1ui64, 0i64);
      v26 = v33;
      goto LABEL_61;
    }
    goto LABEL_60;
  }
  if( v22 )
  {
LABEL_60:
    v26 = 0;
    goto LABEL_61;
  }
  if( (*((_DWORD *)KeGetCurrentPrcb() + 3147) & 0x10000) != 0 )
  {
    v25 = 0;
    goto LABEL_60;
  }
  *(_BYTE *)(v24 + 565) = 1;
  _interlockedbittestandset((volatile signed __int32 *)(v24 + 120), 0xCu);
  *(_QWORD *)(a1 + 16) = v15;
  KiSetProcessorIdle((_KPRCB *)a1, 1ui64, 0i64);
  v26 = (*(_BYTE *)(a1 + 12588) & 1) == 0;
LABEL_61:
  if( v4 )
  {
    KiUpdateThreadPriority((_KPRCB *)a1, (_KTHREAD *)v15, 127i64, 0);
    if( v25 )
    {
      if( (*(_BYTE *)(v15 + 2) & 4) == 0 || (KiIsThreadRankNonZero((_ETHREAD *)v15, (_KPRCB *)a1), v28 = 1, !v29) )
        v28 = *(_BYTE *)(v15 + 195);
      **(_BYTE **)(a1 + 56) = v28;
      if( *(_QWORD *)(a1 + 33976) )
      {
        v30 = (unsigned int)KiVpThreadSystemWorkPriority;
        if( v15 != *(_QWORD *)(a1 + 24) )
          v30 = (unsigned int)v28;
        KiSetSchedulerAssistPriority(*(volatile INT32 **)(a1 + 33976), v30, 0);
      }
    }
    if( KiGroupSchedulingEnabled )
      KiGroupSchedulingGenerationEnd((_KPRCB *)a1, KUSER_SHARED_DATA.TickCountQuad, 1u);
    KiFlushReadyLists((LIST_ENTRY *)(a1 + 31872), (UINT64 *)(a1 + 31768), &DeferredList, v27);
    if( v38 )
    {
      v32 = *(_QWORD *)(a1 + 33864);
      LODWORD(v35) = 0;
      while( _interlockedbittestandset64((volatile signed __int32 *)v32, 0i64) )
      {
        do
          KeYieldProcessorEx(&v35);
        while( *(_QWORD *)v32 );
      }
      KiFlushReadyLists((LIST_ENTRY *)(v32 + 16), (UINT64 *)(v32 + 8), &DeferredList, v31);
      _InterlockedAnd64((volatile signed __int64 *)v32, 0i64);
    }
  }
  _InterlockedAnd64((volatile signed __int64 *)(a1 + 48), 0i64);
  result = (unsigned __int8)KiReadyDeferredReadyList((struct _KPRCB *)a1, &DeferredList);
  if( *(_QWORD *)(a1 + 16) )
  {
    result = *(_BYTE *)(a1 + 12586);
    if( !result )
      result = KiRequestSoftwareInterrupt((struct _KPRCB *)a1, 2);
  }
  if( v4 )
  {
    result = 106;
    _InterlockedDecrement16((volatile signed __int16 *)&KUSER_SHARED_DATA.UnparkedProcessorCount);
  }
  if( v26 )
    return KiRequestSoftwareInterrupt((struct _KPRCB *)a1, 2);
  return result;
}

Referenced by:

KiForceIdleParkUnparkProcessor
PpmParkReportParkedCore
PpmParkReportSoftParkChange
PpmParkReportUnparkedCore