PopCaptureSleepStudyStatistics

INT64 __fastcall PopCaptureSleepStudyStatistics(_QWORD *a1, INT64 a2, INT64 a3){
  unsigned int v3; 
  bool IsHibernateSupported; 
  CHAR IsLockConsoleTimeoutActive; 
  UINT64 *v9; 
  _OBJECT_ATTRIBUTES *v10; 
  __int64 v11; 
  UINT64 v12; 
  UINT8 v13; 
  INT64 v14; 
  INT64 v15; 
  WCHAR v16; 
  __int64 v17; 
  __int64 v18; 
  __int64 v19; 
  __int64 v20; 
  int v21; 
  __int64 v22; 
  POWER_MONITOR_REQUEST_REASON ModernStandbyTransitionReason; 
  UINT8 v24; 
  INT64 v25; 
  INT64 v26; 
  INT64 v27; 
  INT64 v28; 
  INT64 v29; 
  UINT8 v30; 
  INT64 v31; 
  UINT64 v32; 
  BOOL v33; 
  INT64 v34; 
  UINT64 v35; 
  UINT8 v36; 
  UINT64 v37; 
  UINT64 v38; 
  UINT8 v39; 
  __int64 v41; 
  __int64 v42; 
  __int64 v43; 
  __int64 v44; 
  __int64 v45; 
  __int64 v46; 
  int v47; 
  int v48; 
  int v49; 
  int v50; 
  int v51; 
  int v52; 
  int v53; 
  int a1a; 
  INT64 v55; 
  UINT64 PreVetoCount; 
  UINT64 VetoCount; 
  INT64 v58[2]; 
  __int128 v59; 
  SYSTEM_BATTERY_STATE PowerState; 
  _SYSTEM_POWER_CAPABILITIES result; 
  unsigned int v62; 
  v3 = 0;
  PreVetoCount = 0i64;
  v47 = 0;
  v62 = 0;
  VetoCount = 0i64;
  memset(&PowerState, 0, sizeof(PowerState));
  *(_OWORD *)v58 = 0i64;
  v59 = 0i64;
  memset((INT64)&result, 0i64);
  v48 = 0;
  v53 = 0;
  v52 = 0;
  IsHibernateSupported = 0;
  IsLockConsoleTimeoutActive = 0;
  v50 = 0;
  v51 = 0;
  v49 = 0;
  PopCurrentPowerStatePrecise(&PowerState);
  if( *(_OWORD *)a1 == *(_OWORD *)&GUID_SPM_LOW_POWER_CS )
    IsLockConsoleTimeoutActive = PopIsLockConsoleTimeoutActive();
  PopAcquirePolicyLock();
  v11 = *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart;
  if( *a1 == *(_QWORD *)&GUID_SPM_LOW_POWER_CS.Data1 && a1[1] == *(_QWORD *)GUID_SPM_LOW_POWER_CS.Data4 )
  {
    PopWnfCsEnterScenarioId = a2;
    PopCalculateIdleInformation((INT64)v58, v9);
    PpmGetPlatformSelectionVetoCounts((unsigned int)PlatformIdleStateIndex, &PreVetoCount, &VetoCount);
    LODWORD(PopCsConsumption) = PowerState.RemainingCapacity;
    qword_140C4FC50 = v58[1];
    dword_140C4FC60 = DWORD2(v59);
    qword_140C4FC58 = v58[0];
    InitialHwDripsResidency = v59;
    qword_140C4FCE0 = PreVetoCount;
    qword_140C4FCE8 = VetoCount;
    dword_140C4FD10 = PowerState.MaxCapacity;
    qword_140C4FC48 = v11;
    SourceTime = 0i64;
    qword_140C4FC68 = 0i64;
    qword_140C4FC70 = 0i64;
    qword_140C4FC90 = 0i64;
    qword_140C4FCC8 = 0i64;
    qword_140C4FCD0 = 0i64;
    qword_140C4FCA0 = 0i64;
    qword_140C4FCB0 = 0i64;
    CpuBusyTime = 0i64;
    qword_140C4FD20 = 0i64;
    qword_140C4FD28 = 0i64;
    qword_140C4FD30 = 0i64;
    byte_140C4FD0C = 0;
    PopNetIsDisconnectStandbyActive(&v47);
    KeAcquireSpinLockRaiseToDpc(&qword_140C22E38, v12);
    qword_140C22E28 = 0i64;
    qword_140C22E30 = 0i64;
    PopDisplayOnPerformance = 0i64;
    dword_140C22E40 = 1;
    KeReleaseSpinLock(&qword_140C22E38, v13);
    PopGetEnergyCounter(&CsSessionEnergyCounter);
    byte_140C4FD00 = (dword_140C23D0C == 0) | byte_140C4FD00 & 0xFE;
    byte_140C4FD01 ^= (byte_140C4FD01 ^ PopNetIsCompliantNicPresent()) & 1;
    if( (((v47 - 1) & 0xFFFFFFFC) != 0 || v47 == 2)
      && PopNetCheckUserConnectivityPolicy()
      && !PopNetCheckOpportunisticDs(v15, v14, v16) )
    {
      byte_140C4FD01 &= ~2u;
    }
    else
    {
      byte_140C4FD01 |= 2u;
    }
    if( PopDiagCachedAggregatorIntent )
    {
      dword_140C4FD3C = PopDiagCachedAggregatorIntent;
      dword_140C4FD40 = 6;
      PopDiagCachedAggregatorAction = 6;
      PopDiagCachedAggregatorIntent = 0;
    }
    PopGetPowerSettingValue(&GUID_ENERGY_SAVER_POLICY, v14, 3, &v48, v41, &v62);
    byte_140C4FD01 ^= (byte_140C4FD01 ^ (4 * v48)) & 4;
    PopGetPowerSettingValue(&GUID_VIDEO_POWERDOWN_TIMEOUT, v17, 3, &v49, v42, &v62);
    dword_140C4FCF0 = v49;
    PopGetPowerSettingValue(&GUID_VIDEO_CONSOLE_LOCK_TIMEOUT, v18, 3, &v50, v43, &v62);
    dword_140C4FCF4 = v50;
    byte_140C4FCF8 = IsLockConsoleTimeoutActive;
    PopGetPowerSettingValue(&GUID_STANDBY_TIMEOUT, v19, 3, &v51, v44, &v62);
    dword_140C4FCFC = v51;
    byte_140C4FD15 = (char)KdDebuggerEnabled;
    PopFilterCapabilities((_SYSTEM_POWER_CAPABILITIES *)&PopCapabilities, &result);
    v3 = v21;
    if( v21 >= 0 )
      IsHibernateSupported = PopIsHibernateSupported(&result.PowerButtonPresent);
    byte_140C4FD14 = IsHibernateSupported;
    PopGetPowerSettingValue(&GUID_HIBERNATE_TIMEOUT, v20, 3, &v52, v45, &v62);
    dword_140C4FD18 = v52;
    PopGetPowerSettingValue(&GUID_STANDBY_BUDGET_PERCENT, v22, 3, &v53, v46, &v62);
    dword_140C4FD1C = v53;
    _InterlockedExchange64(&qword_140C4FD80, 0i64);
    if( PopFxLookupSocSubsystemsByPlatformIdleState((unsigned int)PlatformIdleStateIndex) )
      v3 = PopFxResetSocSubsystemAccounting((unsigned int)PlatformIdleStateIndex);
    PopFxStartDeviceAccounting();
    PpmIdleStartCsVetoAccounting();
    dword_140C4FD04 = PopAggressiveStandbyEnabledActions;
    dword_140C4FD08 = PopAggressiveStandbyAppliedActions;
    ExStartRecordingIRTimerExpiries();
    PpmResetDripsAccountingSnapshot();
    ModernStandbyTransitionReason = (unsigned int)PopGetModernStandbyTransitionReason(1, 0i64);
    PopDiagTraceCsEnterReason(ModernStandbyTransitionReason);
    PopSetConnectedStandbyMarker(v24);
    PopStatsNotifyPowerRequestCsState(v25, 1);
    v55 = PopWdiCurrentScenarioInstanceId;
    PopDirectedDripsNotify(0i64, &v55, v26, v27);
    PopIdleWakeNotifyModernStandbyEnter();
    a1a = 0;
    PopQueryInputSuppressionCount(&a1a);
    dword_140C4FD38 = a1a;
  }
  else
  {
    PopIdleWakeNotifyModernStandbyExit(v10, (UINT64)v9);
    PopCalculateCsSummary(a3, (UINT64 *)(unsigned int)PopSleepstudyStopReason);
    v55 = a3;
    PopDirectedDripsNotify(1i64, &v55, v28, v29);
    PpmIdleCaptureCsVetoAccounting(v30, (unsigned int)PlatformIdleStateIndex, v31);
    ExStopRecordingIRTimerExpiries();
    PopFxStopDeviceAccounting();
    PpmSnapDripsAccountingSnapshot(v32, 10i64 * *(_QWORD *)(a3 + 32));
    PopDiagTraceCsConsumption((int *)a3);
    PopDiagTraceCsExitReason((PANSI_STRING)a3, (PCUNICODE_STRING)a2, v33);
    if( PopFxLookupSocSubsystemsByPlatformIdleState((unsigned int)PlatformIdleStateIndex) )
    {
      PopFxLogSocSubsystemBlockingTimes(v34, (unsigned int)PlatformIdleStateIndex, v35);
      v3 = PopFxLogSocSubsystemMetadata(v36, (unsigned int)PlatformIdleStateIndex, v37);
    }
    PopStatsNotifyPowerRequestCsState(v34, 0);
    PopGetModernStandbyTransitionReason(0, 0i64);
    PopClearConnectedStandbyMarker();
    qword_140C4FC48 = 0i64;
    KeAcquireSpinLockRaiseToDpc(&qword_140C22E38, v38);
    dword_140C22E40 = 0;
    KeReleaseSpinLock(&qword_140C22E38, v39);
  }
  PopReleasePolicyLock();
  return v3;
}

Referenced by:

PopSleepstudyCaptureSessionStatistics