KiCheckWaitNext

__int64 __fastcall KiCheckWaitNext(__int64 a1, __int64 a2, char a3, _QWORD *a4, _DWORD *a5){
  unsigned __int8 v6; 
  unsigned __int8 v7; 
  unsigned __int8 CurrentIrql; 
  __int64 v11; 
  UINT64 UnbiasedInterruptTime; 
  _DWORD *v13; 
  INT64 CurrentQpc; 
  v6 = _bittestandreset((signed __int32 *)(a1 + 116), 2u);
  CurrentQpc = 0i64;
  v7 = v6;
  if( !v6 )
  {
    CurrentIrql = KeGetCurrentIrql();
    __writecr8(2ui64);
    *(_BYTE *)(a1 + 390) = CurrentIrql;
  }
  if( a2 )
  {
    if( *(int *)(a2 + 4) >= 0 )
    {
      *a4 = *(_QWORD *)a2;
      *a5 = 1;
    }
    else
    {
      if( a3 )
      {
        LODWORD(v11) = RtlGetInterruptTimePrecise(&CurrentQpc);
        UnbiasedInterruptTime = v11 - KUSER_SHARED_DATA.InterruptTimeBias;
      }
      else
      {
        UnbiasedInterruptTime = KiQueryUnbiasedInterruptTime(0);
      }
      v13 = a5;
      *a4 = UnbiasedInterruptTime - *(_QWORD *)(a1 + 248) - *(_QWORD *)a2;
      *v13 = 2;
    }
  }
  else
  {
    *a5 = 0;
  }
  return v7;
}

Referenced by:

KeDelayExecutionThread
KeWaitForAlertByThreadId
KiWaitForAllObjects