HalpTimerClockPowerChange

NTSTATUS __fastcall HalpTimerClockPowerChange(PVOID BugCheckParameter3, CHAR a2){
  struct _KPRCB *CurrentPrcb; 
  char v3; 
  _KDPC *v4; 
  NTSTATUS result; 
  CHAR v6; 
  INT64 v7; 
  void *v8; 
  void *v9; 
  void *v10; 
  void *v11; 
  signed __int64 v12; 
  unsigned __int64 v13; 
  __int64 v14; 
  int v15; 
  INT64 v16; 
  unsigned __int64 BugCheckParameter4; 
  INT64 a4; 

  CurrentPrcb = KeGetCurrentPrcb();
  v3 = *((_BYTE *)BugCheckParameter3 + 224) & 1;
  if( a2 )
  {
    result = HalpTimerClockInitialize();
    if( !v3 )
      ++KiClockStats;
  }
  else
  {
    v4 = (_KDPC *)HalpAlwaysOnTimer;
    if( !HalpAlwaysOnTimer )
      KeBugCheckEx(
        (_DWORD)HalpAlwaysOnTimer + 92,
        (PVOID)0x113,
        (PVOID)(unsigned int)((_DWORD)HalpAlwaysOnTimer + 33),
        BugCheckParameter3,
        (PVOID)((unsigned __int64)HalpAlwaysOnTimer & BugCheckParameter4));
    if( v3 )
    {
      result = KiClockTimerOwner;
      if( KeGetCurrentPrcb()->Number != (_DWORD)KiClockTimerOwner )
        return result;
    }
    else
    {
      ++KiClockStats;
    }
    HalpTimerClockStop();
    KeGetNextClockTickDuration(v7, v6);
    v11 = v10;
    v12 = 0x989680ui64 / *(_QWORD *)&v4[3].TargetInfoAsUlong;
    v13 = 0x989680ui64 % *(_QWORD *)&v4[3].TargetInfoAsUlong;
    if( v12 < 5000 )
      v12 = 5000i64;
    if( (__int64)v11 < v12 )
    {
      ++HalpTimerClockSwapViolationCount;
      v11 = (void *)v12;
    }
    if( (unsigned __int64)v11 > qword_140C50728 )
      KeBugCheckEx(0x5Cu, (PVOID)0x113, (PVOID)0x25, v11, 0i64);
    HalpTimerGetInternalData(v4, (PVOID)v13, v8, v9);
    v15 = ((__int64(__fastcall *)(__int64))v4[1].SystemArgument1)(v14);
    if( v15 < 0 )
      KeBugCheckEx(0x5Cu, (PVOID)0x113, (PVOID)0xF, v4, (PVOID)v15);
    result = HalpSetTimerAnyMode(v4, (unsigned int)v11, v16, (INT64)&a4);
    if( result < 0 )
      KeBugCheckEx(0x5Cu, (PVOID)0x113, (PVOID)0x23, v4, (PVOID)result);
    CurrentPrcb->PendingTickFlags |= 2u;
  }
  return result;
}

Referenced by:

HalpTimerPowerChange