KiFindNextTimerDueTime

UINT64 __stdcall KiFindNextTimerDueTime(_KPRCB *Prcb, UINT64 InterruptTime, UINT8 ClockOwner){
  unsigned __int64 *v3; 
  UINT8 v4; 
  UINT64 v5; 
  unsigned int v6; 
  UINT64 v7; 
  unsigned int v8; 
  unsigned __int64 *v9; 
  _KPRCB *v10; 
  unsigned int v11; 
  unsigned int v12; 
  unsigned __int64 v13; 
  unsigned int v14; 
  unsigned int v15; 
  __int64 v17; 
  __int64 v18; 
  __int64 v19; 
  __int64 *v20; 
  unsigned __int64 v21; 
  unsigned __int64 v22; 
  unsigned __int64 v23; 
  __int64 v24; 
  unsigned __int64 v25; 
  _QWORD *v26; 
  __int64 v27; 
  unsigned __int64 v28; 
  unsigned int v29; 
  __int64 v30; 
  __int64 v31; 
  unsigned int v32; 
  __int64 v33; 
  char *v34; 
  unsigned __int64 v35; 
  unsigned __int64 v36; 
  unsigned __int64 v37; 
  unsigned __int64 v38; 
  _QWORD *v39; 
  __int64 v40; 
  unsigned __int64 v41; 
  unsigned __int64 v42; 
  int v43; 
  __int64 v44; 
  unsigned __int64 v45; 
  unsigned __int16 v46; 
  unsigned __int64 v47; 
  unsigned __int64 v48; 
  __int64 v49; 
  unsigned __int64 v50; 
  _QWORD *v51; 
  __int64 v52; 
  unsigned __int64 v53; 
  __int64 v54; 
  unsigned int v55; 
  __int64 v56; 
  unsigned int v57; 
  unsigned __int64 v58; 
  int v59; 
  unsigned int v60; 
  unsigned __int64 *v64; 
  v64 = v3;
  v4 = ClockOwner;
  v5 = InterruptTime;
  v6 = -1;
  v7 = -1i64;
  v56 = -1i64;
  v8 = -1;
  v55 = -1;
  v9 = v3;
  v10 = Prcb;
  if( (KiVelocityFlags & 0x2000) != 0 && KePseudoHrTimeIncrement == KeMaximumIncrement )
  {
    v11 = 1;
    v59 = -1;
  }
  else
  {
    v11 = 0;
    v59 = 1;
  }
  v57 = v11;
  v12 = (unsigned __int8)(v5 >> 18);
  v60 = v12;
  while( 1 )
  {
    v13 = -1i64;
    v58 = -1i64;
    v14 = v12;
    if( !KiSerializeTimerExpiration )
      break;
    if( !v4 )
      goto LABEL_7;
    v31 = v11;
    v32 = (unsigned __int8)(v12 - *((_BYTE *)KiProcessorBlock + 4 * v11 + 31568));
    if( v32 > 1 )
      return 0i64;
    v8 = 0;
    v33 = (unsigned __int8)*((_DWORD *)KiProcessorBlock + v31 + 7892);
    v34 = (char *)KiProcessorBlock + 0x2000 * v31;
    v35 = (v5 & 0xFFFFFFFFFFFC0000ui64) - (v32 << 18) + 0x4000000;
    while( 2 )
    {
      v36 = v13;
      v37 = (unsigned int)v33;
      v38 = KiPendingTimerBitmaps[0] - 1;
      if( (unsigned __int64)(unsigned int)v33 >= KiPendingTimerBitmaps[0] )
        v37 = 0i64;
      while( 1 )
      {
        if( v38 - v37 == -1i64 )
        {
          LODWORD(v41) = -1;
        }
        else
        {
          v39 = (_QWORD *)(qword_140CFC7A8[0] + 8 * (v37 >> 6));
          v40 = ((1i64 << (v37 & 0x3F)) - 1) | ~*v39;
          if( v40 == -1 )
          {
            while( (unsigned __int64)++v39 <= qword_140CFC7A8[0] + 8 * (v38 >> 6) )
            {
              v40 = ~*v39;
              if( *v39 )
                goto LABEL_48;
            }
LABEL_64:
            LODWORD(v41) = -1;
            goto LABEL_65;
          }
LABEL_48:
          _BitScanForward64((unsigned __int64 *)&v40, ~v40);
          v41 = v40 + (((__int64)v39 - qword_140CFC7A8[0]) >> 3 << 6);
          if( v41 > v38 )
            goto LABEL_64;
          if( v41 != -1i64 )
            break;
        }
LABEL_65:
        if( !v37 )
          break;
        v44 = v33 + 1;
        if( (unsigned __int64)(v33 + 1) > KiPendingTimerBitmaps[0] )
          v44 = KiPendingTimerBitmaps[0];
        v38 = v44 - 1;
        v37 = 0i64;
      }
      v6 = v55;
      v13 = v58;
      if( (_DWORD)v41 != -1 )
      {
        v8 += (unsigned __int8)(v41 - v33 + 1);
        if( v8 <= v55 && v8 <= 0x100 )
        {
          v42 = *(_QWORD *)&v34[32 * (unsigned int)v41 + 15192];
          if( v42 >= v58 || HIDWORD(v42) == -1 )
            goto LABEL_54;
          if( v42 >= v35 )
          {
            v13 = *(_QWORD *)&v34[32 * (unsigned int)v41 + 15192];
            v58 = v13;
LABEL_54:
            v33 = (unsigned __int8)(v41 + 1);
            continue;
          }
          v43 = (unsigned __int8)(v42 >> 18);
          if( v43 != (_DWORD)v41 )
          {
            v33 = (unsigned __int8)(v41 + 1);
            v13 = (v42 & 0xFFFFFFFFFFFC0000ui64) + ((((_DWORD)v41 - v43) << 18) & 0x3FC0000);
            if( v13 >= v36 )
              v13 = v36;
            v58 = v13;
            continue;
          }
          v13 = *(_QWORD *)&v34[32 * (unsigned int)v41 + 15192];
          v6 = v55;
        }
      }
      break;
    }
    v5 = InterruptTime;
LABEL_34:
    v7 = v56;
    v10 = Prcb;
    v4 = ClockOwner;
    v9 = v64;
LABEL_7:
    if( v57 )
    {
      *v9 = v13;
    }
    else
    {
      v7 = v13;
      v56 = v13;
    }
    if( v13 != -1i64 && v6 >= v8 + 1 )
    {
      v6 = v8 + 1;
      v55 = v8 + 1;
    }
    v15 = v59 + v57;
    v57 = v15;
    if( v15 >= 2 )
      return v7;
    v12 = v60;
    v11 = v15;
  }
  if( v12 == (unsigned __int8)*((_DWORD *)v10 + v11 + 7892) )
  {
    if( !v4 )
    {
      v8 = 0;
      v17 = *((_QWORD *)v10 + 25);
      v18 = 2i64 * *((unsigned __int8 *)v10 + 208);
      v19 = KiPendingTimerBitmaps[v18 + 1];
      v20 = &KiPendingTimerBitmaps[v18];
      while( 1 )
      {
        v21 = *v20;
        v22 = (unsigned __int64)v14 << 9;
        if( v22 >= *v20 )
          v23 = 0i64;
        else
          v23 = (unsigned __int64)v14 << 9;
        v24 = v20[1];
        v25 = v21 - 1;
        while( 1 )
        {
          if( v25 - v23 == -1i64 )
            goto LABEL_37;
          v26 = (_QWORD *)(v24 + 8 * (v23 >> 6));
          v27 = ~*v26;
          if( !*v26 )
          {
            while( (unsigned __int64)++v26 <= v24 + 8 * (v25 >> 6) )
            {
              v27 = ~*v26;
              if( *v26 )
                goto LABEL_20;
            }
LABEL_37:
            LODWORD(v28) = -1;
            goto LABEL_38;
          }
LABEL_20:
          _BitScanForward64((unsigned __int64 *)&v27, ~v27);
          v28 = v27 + (((__int64)v26 - v24) >> 3 << 6);
          if( v28 > v25 )
          {
            LODWORD(v28) = -1;
          }
          else if( v28 != -1i64 )
          {
            break;
          }
LABEL_38:
          if( !v23 )
            break;
          v30 = v22 + 1;
          if( v22 + 1 > v21 )
            v30 = *v20;
          v25 = v30 - 1;
          v23 = 0i64;
        }
        if( (_DWORD)v28 == -1 || (v29 = (unsigned int)v28 >> 9, v8 += (unsigned __int8)(v29 - v14) + 1, v8 > 0x100) )
        {
          v13 = -1i64;
          v6 = v55;
          goto LABEL_34;
        }
        if( (*(_QWORD *)(((unsigned __int64)v29 << 6) + v19) & v17) != 0 )
        {
          v6 = v55;
          v13 = v5 + (v8 << 18);
          goto LABEL_34;
        }
        v14 = (unsigned __int8)(v29 + 1);
      }
    }
    v45 = v12 << 9;
    v8 = -1;
    v46 = 0;
LABEL_72:
    v47 = KiPendingTimerBitmaps[2 * v46];
    if( v45 >= v47 )
      v48 = 0i64;
    else
      v48 = v14 << 9;
    v49 = KiPendingTimerBitmaps[2 * v46 + 1];
    v50 = v47 - 1;
    while( 1 )
    {
      if( v50 - v48 == -1i64 )
        goto LABEL_91;
      v51 = (_QWORD *)(v49 + 8 * (v48 >> 6));
      v52 = ~*v51;
      if( !*v51 )
        break;
LABEL_77:
      _BitScanForward64((unsigned __int64 *)&v52, ~v52);
      v53 = v52 + (((__int64)v51 - v49) >> 3 << 6);
      if( v53 > v50 )
      {
        LODWORD(v53) = -1;
      }
      else if( v53 != -1i64 )
      {
        goto LABEL_79;
      }
LABEL_92:
      if( !v48 )
      {
LABEL_79:
        if( (_DWORD)v53 != -1 && (unsigned __int8)(((unsigned int)v53 >> 9) - v14) < v8 )
          v8 = (unsigned __int8)(((unsigned int)v53 >> 9) - v14);
        if( ++v46 >= (unsigned __int16)KiActiveGroups )
        {
          v6 = v55;
          v7 = v56;
          v10 = Prcb;
          v4 = ClockOwner;
          v9 = v64;
          if( v8 == -1 )
            v13 = -1i64;
          else
            v13 = (unsigned int)KeTimeIncrement + (v5 & 0xFFFFFFFFFFFC0000ui64) + (v8 << 18);
          goto LABEL_7;
        }
        goto LABEL_72;
      }
      v54 = v45 + 1;
      if( v45 + 1 > v47 )
        v54 = KiPendingTimerBitmaps[2 * v46];
      v50 = v54 - 1;
      v48 = 0i64;
    }
    while( (unsigned __int64)++v51 <= v49 + 8 * (v50 >> 6) )
    {
      v52 = ~*v51;
      if( *v51 )
        goto LABEL_77;
    }
LABEL_91:
    LODWORD(v53) = -1;
    goto LABEL_92;
  }
  return 0i64;
}

Referenced by:

KiGetNextTimerExpirationDueTime