#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ op_close_file(int /*<<< orphan*/ *);
char *op_get_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ *op_try_open_file(char *, char *);
int sscanf(char *, char *, ...);
double op_cpu_frequency(void) {
  double fval = 0.0;
  unsigned long uval;
  char *line = NULL;
  FILE *fp = op_try_open_file("/proc/cpuinfo", "r");
  if (!fp)
    return 0.0;
  while (1) {
    line = op_get_line(fp);
    if (!line)
      break;
    if (line[0] == '\0') {
      free(line);
      continue;
    }
    if (sscanf(line, "cpu MHz : %lf", &fval) == 1)
      break;
    if (sscanf(line, "clock : %lfMHz", &fval) == 1)
      break;
    if (sscanf(line, "cycle frequency [Hz] : %lu", &uval) == 1) {
      fval = uval / 1E6;
      break;
    }
    if (sscanf(line, "Cpu0ClkTck : %lx", &uval) == 1) {
      fval = uval / 1E6;
      break;
    }
    if (sscanf(line, "BogoMIPS		: %lu", &uval) == 1) {
      fval = uval * 3 / 2;
      break;
    }
    free(line);
  }
  if (line)
    free(line);
  op_close_file(fp);
  return fval;
}


x86 assembly (clang, -O0):
<op_cpu_frequency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xec1(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1070 <op_try_open_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <op_cpu_frequency+0x47>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1345 <op_cpu_frequency+0x1f5>
jmp    119c <op_cpu_frequency+0x4c>
mov    -0x28(%rbp),%rdi
call   1060 <op_get_line@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <op_cpu_frequency+0x69>
jmp    131e <op_cpu_frequency+0x1ce>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d7 <op_cpu_frequency+0x87>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    119c <op_cpu_frequency+0x4c>
mov    -0x20(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11fb <op_cpu_frequency+0xab>
jmp    131e <op_cpu_frequency+0x1ce>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    121f <op_cpu_frequency+0xcf>
jmp    131e <op_cpu_frequency+0x1ce>
mov    -0x20(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    127b <op_cpu_frequency+0x12b>
movaps 0xdcb(%rip),%xmm1
movq   -0x18(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdca(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd93(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    131e <op_cpu_frequency+0x1ce>
mov    -0x20(%rbp),%rdi
lea    0xdf2(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    12d7 <op_cpu_frequency+0x187>
movaps 0xd6f(%rip),%xmm1
movq   -0x18(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd6e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd37(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    131e <op_cpu_frequency+0x1ce>
mov    -0x20(%rbp),%rdi
lea    0xda7(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1310 <op_cpu_frequency+0x1c0>
mov    -0x18(%rbp),%rax
lea    (%rax,%rax,2),%rax
shr    %rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    131e <op_cpu_frequency+0x1ce>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    119c <op_cpu_frequency+0x4c>
cmpq   $0x0,-0x20(%rbp)
je     1332 <op_cpu_frequency+0x1e2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <op_close_file@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<op_cpu_frequency>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xeba(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1070 <op_try_open_file@plt>
test   %rax,%rax
je     127b <op_cpu_frequency+0x12b>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <op_get_line@plt>
test   %rax,%rax
je     12b7 <op_cpu_frequency+0x167>
mov    %rax,%rbx
lea    0xe97(%rip),%r15
lea    0x8(%rsp),%r12
lea    0xe99(%rip),%r13
lea    0x10(%rsp),%rbp
jmp    11dc <op_cpu_frequency+0x8c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <op_get_line@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12b7 <op_cpu_frequency+0x167>
cmpb   $0x0,(%rbx)
je     11c0 <op_cpu_frequency+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12af <op_cpu_frequency+0x15f>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12af <op_cpu_frequency+0x15f>
mov    %rbx,%rdi
lea    0xe38(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1280 <op_cpu_frequency+0x130>
mov    %rbx,%rdi
lea    0xe3a(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1280 <op_cpu_frequency+0x130>
mov    %rbx,%rdi
lea    0xe32(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11c0 <op_cpu_frequency+0x70>
mov    0x10(%rsp),%rax
lea    (%rax,%rax,2),%rax
shr    %rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    12af <op_cpu_frequency+0x15f>
xorps  %xmm0,%xmm0
jmp    12c5 <op_cpu_frequency+0x175>
movsd  0x10(%rsp),%xmm0
unpcklps 0xd73(%rip),%xmm0
subpd  0xd7b(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xd77(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <op_close_file@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%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"
@.str.3 = [15 x i8] c"clock : %lfMHz\00"
@.str.4 = [27 x i8] c"cycle frequency [Hz] : %lu\00"
@.str.5 = [17 x i8] c"Cpu0ClkTck : %lx\00"
@.str.6 = [16 x i8] c"BogoMIPS\09\09: %lu\00"
define double @op_cpu_frequency() {
%1 = alloca double
%2 = alloca double
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32*
store double 0.000000e+00, double* %2
store i8* null, i8** %4
%6 = call i32* @op_try_open_file(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* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
store double 0.000000e+00, double* %1
br label %74
10: ; preds = %0
br label %11
11: ; preds = %10, %23, %61
%12 = load i32*, i32** %5
%13 = call i8* @op_get_line(i32* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
br label %64
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
br label %11
26: ; preds = %17
%27 = load i8*, i8** %4
%28 = call i32 (i8*, i8*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %2)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %26
br label %64
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = call i32 (i8*, i8*, ...) @sscanf(i8* %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double* %2)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %31
br label %64
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = call i32 (i8*, i8*, ...) @sscanf(i8* %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i64* %3)
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i64, i64* %3
%42 = uitofp i64 %41 to double
%43 = fdiv double %42, 1.000000e+06
store double %43, double* %2
br label %64
44: ; preds = %36
%45 = load i8*, i8** %4
%46 = call i32 (i8*, i8*, ...) @sscanf(i8* %45, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64* %3)
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i64, i64* %3
%50 = uitofp i64 %49 to double
%51 = fdiv double %50, 1.000000e+06
store double %51, double* %2
br label %64
52: ; preds = %44
%53 = load i8*, i8** %4
%54 = call i32 (i8*, i8*, ...) @sscanf(i8* %53, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64* %3)
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i64, i64* %3
%58 = mul i64 %57, 3
%59 = udiv i64 %58, 2
%60 = uitofp i64 %59 to double
store double %60, double* %2
br label %64
61: ; preds = %52
%62 = load i8*, i8** %4
%63 = call i32 @free(i8* %62)
br label %11
64: ; preds = %56, %48, %40, %35, %30, %16
%65 = load i8*, i8** %4
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i8*, i8** %4
%69 = call i32 @free(i8* %68)
br label %70
70: ; preds = %67, %64
%71 = load i32*, i32** %5
%72 = call i32 @op_close_file(i32* %71)
%73 = load double, double* %2
store double %73, double* %1
br label %74
74: ; preds = %70, %9
%75 = load double, double* %1
ret double %75
}

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 = [15 x i8] c"clock : %lfMHz\00"
@.str.4 = [27 x i8] c"cycle frequency [Hz] : %lu\00"
@.str.5 = [17 x i8] c"Cpu0ClkTck : %lx\00"
@.str.6 = [16 x i8] c"BogoMIPS\09\09: %lu\00"
define double @op_cpu_frequency() {
%1 = alloca double
%2 = alloca i64
%3 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%4 = bitcast i64* %2 to i8*
%5 = tail call i32* @op_try_open_file(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 %51, label %7
7: ; preds = %0
%8 = call i8* @op_get_line(i32* %5)
%9 = icmp eq i8* %8, null
br i1 %9, label %48, label %10
10: ; preds = %7, %14
%11 = phi i8* [ %16, %14 ], [ %8, %7 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10, %38
%15 = call i32 @free(i8* %11)
%16 = call i8* @op_get_line(i32* %5)
%17 = icmp eq i8* %16, null
br i1 %17, label %48, label %10
18: ; preds = %10
%19 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %46, label %21
21: ; preds = %18
%22 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double* %1)
%23 = icmp eq i32 %22, 1
br i1 %23, label %46, label %24
24: ; preds = %21
%25 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i64* %2)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i64, i64* %2
%29 = uitofp i64 %28 to double
%30 = fdiv double %29, 1.000000e+06
store double %30, double* %1
br label %46
31: ; preds = %24
%32 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64* %2)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i64, i64* %2
%36 = uitofp i64 %35 to double
%37 = fdiv double %36, 1.000000e+06
store double %37, double* %1
br label %46
38: ; preds = %31
%39 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64* %2)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %14
41: ; preds = %38
%42 = load i64, i64* %2
%43 = mul i64 %42, 3
%44 = lshr i64 %43, 1
%45 = uitofp i64 %44 to double
store double %45, double* %1
br label %46
46: ; preds = %18, %21, %27, %34, %41
%47 = call i32 @free(i8* %11)
br label %48
48: ; preds = %14, %7, %46
%49 = call i32 @op_close_file(i32* %5)
%50 = load double, double* %1
br label %51
51: ; preds = %0, %48
%52 = phi double [ %50, %48 ], [ 0.000000e+00, %0 ]
ret double %52
}