#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 sample_get_cpu_mhz();
int /*<<< orphan*/ stderr;
double get_cpu_mhz(int no_cpu_freq_fail) {
  double sample, proc, delta;
  sample = sample_get_cpu_mhz();
  proc = 1704.0;
  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    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <sample_get_cpu_mhz@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1161 <get_cpu_mhz+0x41>
jp     1161 <get_cpu_mhz+0x41>
jmp    1179 <get_cpu_mhz+0x59>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1186 <get_cpu_mhz+0x66>
jp     1186 <get_cpu_mhz+0x66>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1217 <get_cpu_mhz+0xf7>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11aa <get_cpu_mhz+0x8a>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11b9 <get_cpu_mhz+0x99>
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xe33(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    120d <get_cpu_mhz+0xed>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe17(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1217 <get_cpu_mhz+0xf7>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_mhz>:
push   %rax
xor    %eax,%eax
call   1040 <sample_get_cpu_mhz@plt>
movapd %xmm0,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm4
jne    1138 <get_cpu_mhz+0x18>
jnp    11a2 <get_cpu_mhz+0x82>
movsd  0xec0(%rip),%xmm0
movapd %xmm0,%xmm1
subsd  %xmm4,%xmm1
movsd  0xeb8(%rip),%xmm2
addsd  %xmm4,%xmm2
movapd %xmm4,%xmm3
cmpltsd %xmm0,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm3
orpd   %xmm1,%xmm3
divsd  %xmm0,%xmm3
ucomisd 0xe9b(%rip),%xmm3
jbe    11a2 <get_cpu_mhz+0x82>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
movsd  0xe71(%rip),%xmm1
movapd %xmm4,%xmm0
movsd  %xmm4,(%rsp)
call   1030 <fprintf@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret

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
store i32 %0, i32* %3
%7 = call double (...) @sample_get_cpu_mhz()
store double %7, double* %4
store double 1.704000e+03, double* %5
%8 = load double, double* %5
%9 = fcmp une double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load double, double* %4
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %14, label %13
13: ; preds = %10, %1
store double 0.000000e+00, double* %2
br label %40
14: ; preds = %10
%15 = load double, double* %5
%16 = load double, double* %4
%17 = fcmp ogt double %15, %16
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load double, double* %5
%20 = load double, double* %4
%21 = fsub double %19, %20
br label %26
22: ; preds = %14
%23 = load double, double* %4
%24 = load double, double* %5
%25 = fsub double %23, %24
br label %26
26: ; preds = %22, %18
%27 = phi double [ %21, %18 ], [ %25, %22 ]
store double %27, double* %6
%28 = load double, double* %6
%29 = load double, double* %5
%30 = fdiv double %28, %29
%31 = fcmp ogt double %30, 1.000000e-02
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load double, double* %4
%35 = load double, double* %5
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), double %34, double %35)
%37 = load double, double* %4
store double %37, double* %2
br label %40
38: ; preds = %26
%39 = load double, double* %5
store double %39, double* %2
br label %40
40: ; preds = %38, %32, %13
%41 = load double, double* %2
ret double %41
}

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 (...) @sample_get_cpu_mhz()
%3 = fcmp une double %2, 0.000000e+00
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = fcmp olt double %2, 1.704000e+03
%6 = fsub double 1.704000e+03, %2
%7 = fadd double %2, -1.704000e+03
%8 = select i1 %5, double %6, double %7
%9 = fdiv double %8, 1.704000e+03
%10 = fcmp ogt double %9, 1.000000e-02
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), double %2, double 1.704000e+03)
br label %14
14: ; preds = %4, %1, %11
%15 = phi double [ %2, %11 ], [ 0.000000e+00, %1 ], [ 1.704000e+03, %4 ]
ret double %15
}