#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double);
double get_core_freq();
double proc_get_cpu_mhz(int);
double sample_get_cpu_mhz();
int /*<<< orphan*/ stderr;
double get_cpu_mhz(int no_cpu_freq_fail) {
  double freq, sample, proc, delta;
  freq = get_core_freq();
  if (freq)
    return freq;
  sample = sample_get_cpu_mhz();
  proc = proc_get_cpu_mhz(no_cpu_freq_fail);
  if (!proc || !sample)
    return 0;
  delta = proc > sample ? proc - sample : sample - proc;
  if (delta / proc > 0.01) {
    fprintf(stderr,
            "Warning: measured timestamp"
            " frequency %g differs from nominal %g MHz\n",
            sample, proc);
    return sample;
  }
  return proc;
}


x86 assembly (clang, -O0):
<get_cpu_mhz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x0,%al
call   1060 <get_core_freq@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1174 <get_cpu_mhz+0x34>
jp     1174 <get_cpu_mhz+0x34>
jmp    1183 <get_cpu_mhz+0x43>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126f <get_cpu_mhz+0x12f>
mov    $0x0,%al
call   1050 <sample_get_cpu_mhz@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <proc_get_cpu_mhz@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b9 <get_cpu_mhz+0x79>
jp     11b9 <get_cpu_mhz+0x79>
jmp    11d1 <get_cpu_mhz+0x91>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11de <get_cpu_mhz+0x9e>
jp     11de <get_cpu_mhz+0x9e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126f <get_cpu_mhz+0x12f>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1202 <get_cpu_mhz+0xc2>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1211 <get_cpu_mhz+0xd1>
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  0xdd3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1265 <get_cpu_mhz+0x125>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xdb7(%rip),%rsi
call   1040 <fprintf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126f <get_cpu_mhz+0x12f>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_mhz>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <get_core_freq@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115a <get_cpu_mhz+0x1a>
jnp    1160 <get_cpu_mhz+0x20>
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1050 <sample_get_cpu_mhz@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1030 <proc_get_cpu_mhz@plt>
ucomisd 0xe8c(%rip),%xmm0
jne    1180 <get_cpu_mhz+0x40>
jnp    11f1 <get_cpu_mhz+0xb1>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm4
ucomisd %xmm0,%xmm4
xorpd  %xmm0,%xmm0
jne    119a <get_cpu_mhz+0x5a>
jnp    115a <get_cpu_mhz+0x1a>
movapd %xmm1,%xmm0
subsd  %xmm4,%xmm0
movapd %xmm4,%xmm2
subsd  %xmm1,%xmm2
movapd %xmm4,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm2,%xmm3
orpd   %xmm0,%xmm3
divsd  %xmm1,%xmm3
ucomisd 0xe35(%rip),%xmm3
jbe    11fa <get_cpu_mhz+0xba>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
movapd %xmm4,%xmm0
call   1040 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
jmp    115a <get_cpu_mhz+0x1a>
xorpd  %xmm0,%xmm0
jmp    115a <get_cpu_mhz+0x1a>
movapd %xmm1,%xmm0
jmp    115a <get_cpu_mhz+0x1a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [70 x i8] c"Warning: measured timestamp frequency %g differs from nominal %g MHz\0A\00"
define double @get_cpu_mhz(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %3
%8 = call double (...) @get_core_freq()
store double %8, double* %4
%9 = load double, double* %4
%10 = fcmp une double %9, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load double, double* %4
store double %12, double* %2
br label %49
13: ; preds = %1
%14 = call double (...) @sample_get_cpu_mhz()
store double %14, double* %5
%15 = load i32, i32* %3
%16 = call double @proc_get_cpu_mhz(i32 %15)
store double %16, double* %6
%17 = load double, double* %6
%18 = fcmp une double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load double, double* %5
%21 = fcmp une double %20, 0.000000e+00
br i1 %21, label %23, label %22
22: ; preds = %19, %13
store double 0.000000e+00, double* %2
br label %49
23: ; preds = %19
%24 = load double, double* %6
%25 = load double, double* %5
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load double, double* %6
%29 = load double, double* %5
%30 = fsub double %28, %29
br label %35
31: ; preds = %23
%32 = load double, double* %5
%33 = load double, double* %6
%34 = fsub double %32, %33
br label %35
35: ; preds = %31, %27
%36 = phi double [ %30, %27 ], [ %34, %31 ]
store double %36, double* %7
%37 = load double, double* %7
%38 = load double, double* %6
%39 = fdiv double %37, %38
%40 = fcmp ogt double %39, 1.000000e-02
br i1 %40, label %41, label %47
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = load double, double* %5
%44 = load double, double* %6
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), double %43, double %44)
%46 = load double, double* %5
store double %46, double* %2
br label %49
47: ; preds = %35
%48 = load double, double* %6
store double %48, double* %2
br label %49
49: ; preds = %47, %41, %22, %11
%50 = load double, double* %2
ret double %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [70 x i8] c"Warning: measured timestamp frequency %g differs from nominal %g MHz\0A\00"
define double @get_cpu_mhz(i32 %0) {
%2 = tail call double (...) @get_core_freq()
%3 = fcmp une double %2, 0.000000e+00
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call double (...) @sample_get_cpu_mhz()
%6 = tail call double @proc_get_cpu_mhz(i32 %0)
%7 = fcmp une double %6, 0.000000e+00
%8 = fcmp une double %5, 0.000000e+00
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %20
10: ; preds = %4
%11 = fcmp ogt double %6, %5
%12 = fsub double %6, %5
%13 = fsub double %5, %6
%14 = select i1 %11, double %12, double %13
%15 = fdiv double %14, %6
%16 = fcmp ogt double %15, 1.000000e-02
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), double %5, double %6)
br label %20
20: ; preds = %10, %4, %1, %17
%21 = phi double [ %5, %17 ], [ %2, %1 ], [ 0.000000e+00, %4 ], [ %6, %10 ]
ret double %21
}