#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 proc_get_cpu_mhz();
double sample_get_cpu_mhz();
int /*<<< orphan*/ stderr;
double get_cpu_mhz(void) {
  double sample, proc, delta;
  sample = sample_get_cpu_mhz();
  proc = proc_get_cpu_mhz();
  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    $0x0,%al
call   1050 <sample_get_cpu_mhz@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <proc_get_cpu_mhz@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116d <get_cpu_mhz+0x3d>
jp     116d <get_cpu_mhz+0x3d>
jmp    1185 <get_cpu_mhz+0x55>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1192 <get_cpu_mhz+0x62>
jp     1192 <get_cpu_mhz+0x62>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1223 <get_cpu_mhz+0xf3>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b6 <get_cpu_mhz+0x86>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c5 <get_cpu_mhz+0x95>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe1f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1219 <get_cpu_mhz+0xe9>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe03(%rip),%rsi
call   1040 <fprintf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1223 <get_cpu_mhz+0xf3>
movsd  -0x18(%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   1050 <sample_get_cpu_mhz@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <proc_get_cpu_mhz@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1154 <get_cpu_mhz+0x24>
jnp    11b6 <get_cpu_mhz+0x86>
xorpd  %xmm2,%xmm2
movsd  (%rsp),%xmm4
ucomisd %xmm2,%xmm4
jne    1165 <get_cpu_mhz+0x35>
jnp    11b6 <get_cpu_mhz+0x86>
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 0xe6a(%rip),%xmm3
jbe    11b8 <get_cpu_mhz+0x88>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
movapd %xmm4,%xmm0
call   1040 <fprintf@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret
movapd %xmm1,%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() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = call double (...) @sample_get_cpu_mhz()
store double %5, double* %2
%6 = call double (...) @proc_get_cpu_mhz()
store double %6, double* %3
%7 = load double, double* %3
%8 = fcmp une double %7, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load double, double* %2
%11 = fcmp une double %10, 0.000000e+00
br i1 %11, label %13, label %12
12: ; preds = %9, %0
store double 0.000000e+00, double* %1
br label %39
13: ; preds = %9
%14 = load double, double* %3
%15 = load double, double* %2
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load double, double* %3
%19 = load double, double* %2
%20 = fsub double %18, %19
br label %25
21: ; preds = %13
%22 = load double, double* %2
%23 = load double, double* %3
%24 = fsub double %22, %23
br label %25
25: ; preds = %21, %17
%26 = phi double [ %20, %17 ], [ %24, %21 ]
store double %26, double* %4
%27 = load double, double* %4
%28 = load double, double* %3
%29 = fdiv double %27, %28
%30 = fcmp ogt double %29, 1.000000e-02
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load double, double* %2
%34 = load double, double* %3
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), double %33, double %34)
%36 = load double, double* %2
store double %36, double* %1
br label %39
37: ; preds = %25
%38 = load double, double* %3
store double %38, double* %1
br label %39
39: ; preds = %37, %31, %12
%40 = load double, double* %1
ret double %40
}

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