HalpTimerMeasureFrequencies

LARGE_INTEGER __fastcall HalpTimerMeasureFrequencies(__int64 a1, void *a2, void *a3, void *a4){
  LARGE_INTEGER result; 
  ULONG_PTR *v5; 
  int v6; 
  __int64 v8; 
  void *v9; 
  void *v10; 
  void *v11; 
  ULONG_PTR *v12; 
  __int64 v13; 
  void *v14; 
  void *v15; 
  void *v16; 
  ULONG_PTR *v17; 
  LARGE_INTEGER *v18; 
  __int64 v19; 
  void *v20; 
  void *v21; 
  void *v22; 
  UINT64 v23; 
  void *v24; 
  void *v25; 
  void *v26; 
  ULONG_PTR *v27; 
  LARGE_INTEGER *v28; 
  __int64 v29; 
  ULONG_PTR *v30; 
  ULONG_PTR *v31; 
  int v32; 
  ULONG_PTR v33; 
  ULONG_PTR v34; 
  void *v35; 
  char *v36; 
  unsigned int v37; 
  void *v38; 
  __int64 v39; 
  __int64(__fastcall *v40)(__int64); 
  __int64 v41; 
  __int64 v42; 
  __int64 v43; 
  __int64 v44; 
  __int64 v45; 
  __int64 v46; 
  __int64 v47; 
  void *retaddr; 
  result.QuadPart = (LONGLONG)&retaddr;
  v5 = (ULONG_PTR *)HalpRegisteredTimers;
  v6 = *(_DWORD *)(a1 + 224) & 2;
  LOBYTE(a2) = 0;
  if( (ULONG_PTR *)HalpRegisteredTimers != &HalpRegisteredTimers )
  {
    do
    {
      v8 = (__int64)v5;
      v5 = (ULONG_PTR *)*v5;
      if( *(_QWORD *)(v8 + 192) )
      {
        result.QuadPart = *(unsigned int *)(v8 + 184);
        if( (result.LowPart & 8) == 0 )
          continue;
      }
      result.QuadPart = *(unsigned int *)(v8 + 224);
      if( (result.LowPart & 2) != 0 )
      {
        result.QuadPart = HalpTimerInitialize(v8, a2, a3, a4);
        LOBYTE(a2) = 1;
      }
    }
    while( v5 != &HalpRegisteredTimers );
    if( (_BYTE)a2 )
    {
      KeStallExecutionProcessor(0x5DCu);
      v12 = (ULONG_PTR *)HalpRegisteredTimers;
      while( v12 != &HalpRegisteredTimers )
      {
        v13 = (__int64)v12;
        v12 = (ULONG_PTR *)*v12;
        if( (!*(_QWORD *)(v13 + 192) || (*(_DWORD *)(v13 + 184) & 8) != 0)
          && (*(_DWORD *)(v13 + 224) & 2) != 0
          && (*(_DWORD *)(v13 + 184) & 2) != 0 )
        {
          if( v6 )
          {
            *(_DWORD *)(v13 + 48) = HalpTimerDetermineValidTimerPairReadLatency(v13, a1);
          }
          else
          {
            HalpTimerGetInternalData((KDPC *)v13, v9, v10, v11);
            *(_QWORD *)(v13 + 16) = (*(__int64(__fastcall **)(__int64))(v13 + 112))(v41);
          }
        }
      }
      HalpProcessorFence();
      if( (*(_DWORD *)(a1 + 224) & 2) == 0 )
      {
        HalpTimerGetInternalData((KDPC *)a1, v14, v15, v16);
        (*(void(__fastcall **)(__int64, _QWORD))(a1 + 176))(v42, 0i64);
      }
      v17 = (ULONG_PTR *)HalpRegisteredTimers;
      while( v17 != &HalpRegisteredTimers )
      {
        v18 = (LARGE_INTEGER *)v17;
        v19 = (__int64)v17;
        v17 = (ULONG_PTR *)*v17;
        if( (!v18[24].QuadPart || (v18[23].LowPart & 8) != 0)
          && (*(_DWORD *)(v19 + 224) & 2) != 0
          && (*(_DWORD *)(v19 + 184) & 2) != 0 )
        {
          if( v6 )
          {
            HalpTimerReadTimerPairWithLatencyLimit(*(_DWORD *)(v19 + 48), v19, a1, v18 + 2, (LARGE_INTEGER *)(v19 + 24));
          }
          else
          {
            HalpTimerGetInternalData((KDPC *)v19, v14, v15, v16);
            v18[2].QuadPart = (*(__int64(__fastcall **)(__int64))(v43 + 112))(v44);
          }
        }
      }
      HalpProcessorFence();
      if( (*(_DWORD *)(a1 + 224) & 2) != 0 )
      {
        v23 = 1250000i64;
        HalpTimerStallExecutionProcessor(a1, 1250000i64, 0i64, v22);
      }
      else
      {
        HalpTimerGetInternalData((KDPC *)a1, v20, v21, v22);
        v23 = (*(__int64(__fastcall **)(__int64, __int64))(a1 + 176))(v45, 1250000i64);
      }
      result.QuadPart = HalpProcessorFence();
      v27 = (ULONG_PTR *)HalpRegisteredTimers;
      while( v27 != &HalpRegisteredTimers )
      {
        v28 = (LARGE_INTEGER *)v27;
        v29 = (__int64)v27;
        v27 = (ULONG_PTR *)*v27;
        if( v28[24].QuadPart )
        {
          result.QuadPart = v28[23].LowPart;
          if( (result.LowPart & 8) == 0 )
            continue;
        }
        result.QuadPart = *(unsigned int *)(v29 + 224);
        if( (result.LowPart & 2) != 0 )
        {
          result.QuadPart = *(unsigned int *)(v29 + 184);
          if( (result.LowPart & 2) != 0 )
          {
            if( v6 )
            {
              result.QuadPart = HalpTimerReadTimerPairWithLatencyLimit(
                                  *(_DWORD *)(v29 + 48),
                                  v29,
                                  a1,
                                  v28 + 4,
                                  (LARGE_INTEGER *)(v29 + 40));
            }
            else
            {
              HalpTimerGetInternalData((KDPC *)v29, v24, v25, v26);
              result.QuadPart = (*(__int64(__fastcall **)(__int64))(v46 + 112))(v47);
              v28[4] = result;
            }
          }
        }
      }
      v30 = (ULONG_PTR *)HalpRegisteredTimers;
      while( v30 != &HalpRegisteredTimers )
      {
        v31 = v30;
        v30 = (ULONG_PTR *)*v30;
        if( v31[24] )
        {
          result.QuadPart = *((unsigned int *)v31 + 46);
          if( (result.LowPart & 8) == 0 )
            continue;
        }
        result.QuadPart = *((unsigned int *)v31 + 56);
        if( (result.LowPart & 2) != 0 )
        {
          v32 = *((_DWORD *)v31 + 46);
          if( (v32 & 2) != 0 )
          {
            v33 = v31[2];
            v34 = v31[4] - v33;
            v35 = (void *)v31[3];
            v36 = (char *)(v31[5] - (_QWORD)v35);
            if( v31[4] < v33 )
              v34 += 1i64 << *((_DWORD *)v31 + 55);
            if( v31[5] < (unsigned __int64)v35 )
              v36 += 1i64 << *(_DWORD *)(a1 + 220);
            if( v6 )
              v23 = HalpTimerScaleCounter((UINT64)v36, *(_QWORD *)(a1 + 192), 0x989680ui64);
            v37 = v32 & 0xFFFFFFF7;
            result.QuadPart = 10000000 * v34 / v23;
            *((_DWORD *)v31 + 46) = v37;
            v31[24] = result.QuadPart;
            if( v31 != (ULONG_PTR *)a1 && (v37 & 4) == 0 )
            {
              v38 = (void *)v31[17];
              if( v38 )
              {
                HalpTimerGetInternalData((KDPC *)v31, v38, v35, v36);
                result.QuadPart = v40(v39);
              }
            }
          }
        }
      }
    }
  }
  return result;
}

Referenced by:

HalpTimerSelectRoles