KiRemoveEntryTimer

VOID __stdcall KiRemoveEntryTimer(_KTIMER_TABLE *TimerTable, _KTIMER *Timer, UINT64 Hand){
  volatile signed __int64 **v3; 
  __int64 v4; 
  unsigned int v6; 
  __int64 v7; 
  char *v8; 
  unsigned __int64 v9; 
  char **v10; 
  __int64 v11; 
  volatile signed __int32 *v12; 
  struct _KPRCB *CurrentPrcb; 
  unsigned __int64 v14; 
  unsigned __int64 v15; 
  struct _KPRCB *v16; 
  __int64 v17; 
  struct _KPRCB *v18; 
  struct _KPRCB *v19; 
  volatile signed __int32 *v20; 
  __int64 v21; 
  int v22; 
  __int64 v23; 
  int v24; 
  UINT64 v25; 
  UINT64 v26; 
  UINT64 SpinCount; 
  volatile signed __int64 **v28; 
  v28 = v3;
  v4 = (unsigned int)Hand;
  v6 = *((unsigned __int16 *)Timer + 29);
  v7 = *((_QWORD *)Timer + 4);
  v8 = (char *)Timer + 32;
  v9 = 32 * (((unsigned __int64)v6 << 8) + v4 + 16);
  v10 = (char **)*((_QWORD *)v8 + 1);
  v11 = 32 * (((v6 ^ 1i64) << 8) + v4 + 16);
  if( *(char **)(v7 + 8) != v8 || *v10 != v8 )
    __fastfail(3u);
  *v10 = (char *)v7;
  *(_QWORD *)(v7 + 8) = v10;
  if( v10 == (char **)v7 )
  {
    *(_DWORD *)((char *)TimerTable + v9 + 28) = -1;
    if( (_WORD)v6 )
    {
      v12 = (volatile signed __int32 *)((char *)TimerTable + 32 * v4 + 512);
      CurrentPrcb = KeGetCurrentPrcb();
      if( *((_QWORD *)CurrentPrcb + 4247) && *((_BYTE *)CurrentPrcb + 32) <= 1u && *((_BYTE *)CurrentPrcb + 32) == 1 )
        v3 = v28;
      if( _interlockedbittestandset64((volatile signed __int32 *)TimerTable + 8 * v4 + 128, 0i64) )
      {
        if( *((_QWORD *)CurrentPrcb + 4247) && *((_BYTE *)CurrentPrcb + 32) <= 1u && !(_DWORD)v10 )
          v3 = v28;
        _mm_pause();
        v12 = 0i64;
      }
      if( !v12 )
      {
        _InterlockedAnd64(*v3, 0i64);
        v12 = (volatile signed __int32 *)((char *)TimerTable + 32 * v4 + 512);
        v18 = KeGetCurrentPrcb();
        LODWORD(v25) = 0;
        while( _interlockedbittestandset64(v12, 0i64) )
        {
          do
            KeYieldProcessorEx(&v25);
          while( *(_QWORD *)v12 );
          v21 = *((_QWORD *)v18 + 4247);
          if( v21 && *((_BYTE *)v18 + 32) <= 1u )
          {
            v22 = *(_DWORD *)(v21 + 24) + 1;
            *(_DWORD *)(v21 + 24) = v22;
          }
        }
        v19 = KeGetCurrentPrcb();
        v20 = (volatile signed __int32 *)((char *)TimerTable + 32 * v4 + 8704);
        LODWORD(v26) = 0;
        while( _interlockedbittestandset64(v20, 0i64) )
        {
          do
            KeYieldProcessorEx(&v26);
          while( *(_QWORD *)v20 );
          v23 = *((_QWORD *)v19 + 4247);
          if( v23 && *((_BYTE *)v19 + 32) <= 1u )
          {
            v24 = *(_DWORD *)(v23 + 24) + 1;
            *(_DWORD *)(v23 + 24) = v24;
          }
        }
        *v28 = (volatile signed __int64 *)v20;
      }
    }
    else
    {
      v16 = KeGetCurrentPrcb();
      v12 = (volatile signed __int32 *)((char *)TimerTable + 32 * v4 + 8704);
      LODWORD(SpinCount) = 0;
      while( _interlockedbittestandset64(v12, 0i64) )
      {
        do
          KeYieldProcessorEx(&SpinCount);
        while( *(_QWORD *)v12 );
        v17 = *((_QWORD *)v16 + 4247);
        if( v17 && *((_BYTE *)v16 + 32) <= 1u )
          ++*(_DWORD *)(v17 + 24);
      }
    }
    if( *(_DWORD *)((char *)TimerTable + v9 + 28) == -1 && *(_DWORD *)((char *)TimerTable + v11 + 28) == -1 )
    {
      if( KiSerializeTimerExpiration )
      {
        v14 = v4 & 0x3F;
        v15 = 8i64 * ((unsigned int)v4 >> 6);
      }
      else
      {
        v14 = *((unsigned __int8 *)TimerTable - 14447);
        v15 = (unsigned __int64)(unsigned int)v4 << 6;
      }
      _interlockedbittestandreset64(
        (volatile signed __int32 *)(qword_140CFC7A8[2 * *((unsigned __int8 *)TimerTable - 14448)] + v15),
        v14);
    }
    _InterlockedAnd64((volatile signed __int64 *)v12, 0i64);
  }
}

Referenced by:

ExpSetTimerObject
KiAdjustTimerDueTimes
KiExpireTimerTable
KiInsertTimerTable
KiRetireDpcList