#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 *, double, double);
int sscanf(char *, char *, double *);
int /*<<< orphan*/ stderr;
double proc_get_cpu_mhz(void) {
  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) {
      rc = sscanf(buf, "clock : %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);
      return 0.0;
    }
  }
  fclose(f);
  return mhz;
}


x86 assembly (clang, -O0):
<proc_get_cpu_mhz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x118(%rbp)
ff
lea    0xe93(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <proc_get_cpu_mhz+0x45>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bb <proc_get_cpu_mhz+0x16b>
jmp    119a <proc_get_cpu_mhz+0x4a>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12a5 <proc_get_cpu_mhz+0x155>
lea    -0x110(%rbp),%rdi
lea    0xe49(%rip),%rsi
lea    -0x120(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
je     121d <proc_get_cpu_mhz+0xcd>
lea    -0x110(%rbp),%rdi
lea    0xe2a(%rip),%rsi
lea    -0x120(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
je     1218 <proc_get_cpu_mhz+0xc8>
jmp    119a <proc_get_cpu_mhz+0x4a>
jmp    121d <proc_get_cpu_mhz+0xcd>
movsd  -0x118(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    124d <proc_get_cpu_mhz+0xfd>
jp     124d <proc_get_cpu_mhz+0xfd>
movsd  -0x120(%rbp),%xmm0
ff
movsd  %xmm0,-0x118(%rbp)
ff
jmp    119a <proc_get_cpu_mhz+0x4a>
movsd  -0x118(%rbp),%xmm0
ff
ucomisd -0x120(%rbp),%xmm0
ff
jne    126e <proc_get_cpu_mhz+0x11e>
jp     126e <proc_get_cpu_mhz+0x11e>
jmp    12a0 <proc_get_cpu_mhz+0x150>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
movsd  -0x118(%rbp),%xmm0
ff
movsd  -0x120(%rbp),%xmm1
ff
lea    0xd9c(%rip),%rsi
call   1050 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bb <proc_get_cpu_mhz+0x16b>
jmp    119a <proc_get_cpu_mhz+0x4a>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movsd  -0x118(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_get_cpu_mhz>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
lea    0xea1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123d <proc_get_cpu_mhz+0xed>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1243 <proc_get_cpu_mhz+0xf3>
lea    0xe77(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r12
lea    0xe74(%rip),%r13
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
jmp    11f1 <proc_get_cpu_mhz+0xa1>
nopl   (%rax)
movsd  (%rsp),%xmm0
ucomisd 0xe33(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
jne    1220 <proc_get_cpu_mhz+0xd0>
jp     1220 <proc_get_cpu_mhz+0xd0>
movsd  %xmm1,(%rsp)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     124c <proc_get_cpu_mhz+0xfc>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11c0 <proc_get_cpu_mhz+0x70>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11c0 <proc_get_cpu_mhz+0x70>
jmp    11dc <proc_get_cpu_mhz+0x8c>
nopl   0x0(%rax)
ucomisd %xmm1,%xmm0
jne    1228 <proc_get_cpu_mhz+0xd8>
jnp    11dc <proc_get_cpu_mhz+0x8c>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1050 <fprintf@plt>
xorpd  %xmm0,%xmm0
jmp    1259 <proc_get_cpu_mhz+0x109>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
call   1030 <fclose@plt>
movsd  (%rsp),%xmm0
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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"
@.str.3 = [12 x i8] c"clock : %lf\00"
@stderr = global i32 0
@.str.4 = [55 x i8] c"Conflicting CPU frequency values detected: %lf != %lf\0A\00"
define double @proc_get_cpu_mhz() {
%1 = alloca double
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double 0.000000e+00, double* %4
%7 = 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* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %0
store double 0.000000e+00, double* %1
br label %48
11: ; preds = %0
br label %12
12: ; preds = %43, %32, %27, %11
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i64 @fgets(i8* %13, i32 256, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %12
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %5)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double* %5)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %22
br label %12
28: ; preds = %22
br label %29
29: ; preds = %28, %17
%30 = load double, double* %4
%31 = fcmp oeq double %30, 0.000000e+00
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load double, double* %5
store double %33, double* %4
br label %12
34: ; preds = %29
%35 = load double, double* %4
%36 = load double, double* %5
%37 = fcmp une double %35, %36
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load double, double* %4
%41 = load double, double* %5
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), double %40, double %41)
store double 0.000000e+00, double* %1
br label %48
43: ; preds = %34
br label %12
44: ; preds = %12
%45 = load i32*, i32** %2
%46 = call i32 @fclose(i32* %45)
%47 = load double, double* %4
store double %47, double* %1
br label %48
48: ; preds = %44, %38, %10
%49 = load double, double* %1
ret double %49
}

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"
@.str.3 = [12 x i8] c"clock : %lf\00"
@stderr = global i32 0
@.str.4 = [55 x i8] c"Conflicting CPU frequency values detected: %lf != %lf\0A\00"
define double @proc_get_cpu_mhz() {
%1 = alloca [256 x i8]
%2 = alloca double
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %33, label %6
6: ; preds = %0
%7 = call i64 @fgets(i8* %3, i32 256, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %30, label %9
9: ; preds = %6
%10 = bitcast double* %2 to i8*
br label %11
11: ; preds = %9, %26
%12 = phi double [ 0.000000e+00, %9 ], [ %27, %26 ]
%13 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %2)
%14 = icmp eq i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double* %2)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %26
18: ; preds = %15, %11
%19 = fcmp oeq double %12, 0.000000e+00
%20 = load double, double* %2
br i1 %19, label %26, label %21
21: ; preds = %18
%22 = fcmp une double %12, %20
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), double %12, double %20)
br label %33
26: ; preds = %18, %21, %15
%27 = phi double [ %12, %15 ], [ %12, %21 ], [ %20, %18 ]
%28 = call i64 @fgets(i8* %3, i32 256, i32* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %11
30: ; preds = %26, %6
%31 = phi double [ 0.000000e+00, %6 ], [ %27, %26 ]
%32 = call i32 @fclose(i32* %4)
br label %33
33: ; preds = %23, %0, %30
%34 = phi double [ %31, %30 ], [ 0.000000e+00, %0 ], [ 0.000000e+00, %23 ]
ret double %34
}