#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, double *);
int /*<<< orphan*/ stderr;
double proc_get_cpu_mhz(int no_cpu_freq_fail) {
  FILE *f;
  char buf[256];
  double mhz = 0.0;
  f = fopen("/proc/cpuinfo", "r");
  if (!f)
    return 0.0;
  while (fgets(buf, sizeof(buf), f)) {
    double m;
    int rc;
    rc = sscanf(buf, "cpu MHz : %lf", &m);
    if (rc != 1)
      continue;
    if (mhz == 0.0) {
      mhz = m;
      continue;
    }
    if (mhz != m) {
      fprintf(stderr,
              "Conflicting CPU frequency values"
              " detected: %lf != %lf\n",
              mhz, m);
      if (no_cpu_freq_fail) {
        fprintf(stderr, "Test integrity may be harmed !\n");
      } else {
        return 0.0;
      }
      continue;
    }
  }
  fclose(f);
  return mhz;
}


x86 assembly (clang, -O0):
<proc_get_cpu_mhz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x128(%rbp)
ff
lea    0xe90(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1198 <proc_get_cpu_mhz+0x48>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b9 <proc_get_cpu_mhz+0x169>
jmp    119d <proc_get_cpu_mhz+0x4d>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12a3 <proc_get_cpu_mhz+0x153>
lea    -0x120(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x130(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x1,-0x134(%rbp)
je     11ee <proc_get_cpu_mhz+0x9e>
jmp    119d <proc_get_cpu_mhz+0x4d>
movsd  -0x128(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    121e <proc_get_cpu_mhz+0xce>
jp     121e <proc_get_cpu_mhz+0xce>
movsd  -0x130(%rbp),%xmm0
ff
movsd  %xmm0,-0x128(%rbp)
ff
jmp    119d <proc_get_cpu_mhz+0x4d>
movsd  -0x128(%rbp),%xmm0
ff
ucomisd -0x130(%rbp),%xmm0
ff
jne    123f <proc_get_cpu_mhz+0xef>
jp     123f <proc_get_cpu_mhz+0xef>
jmp    129e <proc_get_cpu_mhz+0x14e>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
movsd  -0x128(%rbp),%xmm0
ff
movsd  -0x130(%rbp),%xmm1
ff
lea    0xdbf(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0xc(%rbp)
je     128c <proc_get_cpu_mhz+0x13c>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1299 <proc_get_cpu_mhz+0x149>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b9 <proc_get_cpu_mhz+0x169>
jmp    119d <proc_get_cpu_mhz+0x4d>
jmp    119d <proc_get_cpu_mhz+0x4d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movsd  -0x128(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_get_cpu_mhz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %edi,%r14d
lea    0xe9d(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1247 <proc_get_cpu_mhz+0xf7>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     124d <proc_get_cpu_mhz+0xfd>
lea    0xe73(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%r12
mov    0x2e2a(%rip),%r13
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
jmp    11ea <proc_get_cpu_mhz+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1256 <proc_get_cpu_mhz+0x106>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11d5 <proc_get_cpu_mhz+0x85>
movsd  (%rsp),%xmm0
ucomisd 0xdf6(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
jne    1214 <proc_get_cpu_mhz+0xc4>
jnp    11d0 <proc_get_cpu_mhz+0x80>
ucomisd %xmm1,%xmm0
jne    121c <proc_get_cpu_mhz+0xcc>
jnp    11d5 <proc_get_cpu_mhz+0x85>
mov    0x0(%r13),%edi
lea    0xdff(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
test   %r14d,%r14d
je     1247 <proc_get_cpu_mhz+0xf7>
mov    0x0(%r13),%edi
lea    0xe1f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11d5 <proc_get_cpu_mhz+0x85>
xorpd  %xmm0,%xmm0
jmp    1263 <proc_get_cpu_mhz+0x113>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
movsd  (%rsp),%xmm0
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"cpu MHz : %lf\00"
@stderr = global i32 0
@.str.3 = [55 x i8] c"Conflicting CPU frequency values detected: %lf != %lf\0A\00"
@.str.4 = [32 x i8] c"Test integrity may be harmed !\0A\00"
define double @proc_get_cpu_mhz(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 %0, i32* %3
store double 0.000000e+00, double* %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store double 0.000000e+00, double* %2
br label %51
13: ; preds = %1
br label %14
14: ; preds = %46, %45, %28, %24, %13
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* %15, i32 256, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %47
19: ; preds = %14
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %7)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %19
br label %14
25: ; preds = %19
%26 = load double, double* %6
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load double, double* %7
store double %29, double* %6
br label %14
30: ; preds = %25
%31 = load double, double* %6
%32 = load double, double* %7
%33 = fcmp une double %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load double, double* %6
%37 = load double, double* %7
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), double %36, double %37)
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %45
44: ; preds = %34
store double 0.000000e+00, double* %2
br label %51
45: ; preds = %41
br label %14
46: ; preds = %30
br label %14
47: ; preds = %14
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = load double, double* %6
store double %50, double* %2
br label %51
51: ; preds = %47, %44, %12
%52 = load double, double* %2
ret double %52
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"cpu MHz : %lf\00"
@stderr = global i32 0
@.str.3 = [55 x i8] c"Conflicting CPU frequency values detected: %lf != %lf\0A\00"
@.str.4 = [32 x i8] c"Test integrity may be harmed !\0A\00"
define double @proc_get_cpu_mhz(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca double
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %36, label %7
7: ; preds = %1
%8 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %33, label %10
10: ; preds = %7
%11 = bitcast double* %3 to i8*
%12 = icmp eq i32 %0, 0
br label %13
13: ; preds = %10, %29
%14 = phi double [ 0.000000e+00, %10 ], [ %30, %29 ]
%15 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = fcmp oeq double %14, 0.000000e+00
%19 = load double, double* %3
br i1 %18, label %29, label %20
20: ; preds = %17
%21 = fcmp une double %14, %19
br i1 %21, label %22, label %29
22: ; preds = %20
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), double %14, double %19)
br i1 %12, label %25, label %26
25: ; preds = %22
br label %36
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %17, %20, %13, %26
%30 = phi double [ %14, %26 ], [ %14, %13 ], [ %14, %20 ], [ %19, %17 ]
%31 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %13
33: ; preds = %29, %7
%34 = phi double [ 0.000000e+00, %7 ], [ %30, %29 ]
%35 = call i32 @fclose(i32* %5)
br label %36
36: ; preds = %25, %1, %33
%37 = phi double [ %34, %33 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %25 ]
ret double %37
}