#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*/ line;
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*/ perror(char *);
int sscanf(char *, char *, float *);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
float cpu_MHz(void) {
  char *path = "/proc/cpuinfo", *s, line[1024];
  float freq;
  char *cpu_line = "cpu MHz";
  FILE *f = fopen(path, "r");
  if (!f) {
    perror(path);
    return -1.0;
  }
  while (fgets(line, sizeof(line), f)) {
    if (!strncmp(line, cpu_line, strlen(cpu_line))) {
      s = strchr(line, ':');
      if (s && 1 == sscanf(s, ":%g", &freq)) {
        fclose(f);
        return freq;
      }
    }
  }
  fclose(f);
  return -1.0;
}


x86 assembly (clang, -O0):
<cpu_MHz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
lea    0xe72(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe75(%rip),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    11e4 <cpu_MHz+0x64>
mov    -0x10(%rbp),%rdi
call   10a0 <perror@plt>
movss  0xe26(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12d8 <cpu_MHz+0x158>
jmp    11e9 <cpu_MHz+0x69>
lea    -0x420(%rbp),%rdi
mov    -0x438(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12bf <cpu_MHz+0x13f>
lea    -0x420(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x430(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x448(%rbp),%rdi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12ba <cpu_MHz+0x13a>
lea    -0x420(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b5 <cpu_MHz+0x135>
mov    -0x18(%rbp),%rdi
lea    0xda0(%rip),%rsi
lea    -0x424(%rbp),%rdx
call   1080 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    12b5 <cpu_MHz+0x135>
mov    -0x438(%rbp),%rdi
call   1040 <fclose@plt>
movss  -0x424(%rbp),%xmm0
ff
movss  %xmm0,-0x4(%rbp)
jmp    12d8 <cpu_MHz+0x158>
jmp    12ba <cpu_MHz+0x13a>
jmp    11e9 <cpu_MHz+0x69>
mov    -0x438(%rbp),%rdi
call   1040 <fclose@plt>
movss  0xd2d(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_MHz>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xe6d(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1274 <cpu_MHz+0xf4>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1253 <cpu_MHz+0xd3>
lea    0xe41(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xe3f(%rip),%r12
lea    0xc(%rsp),%r13
jmp    1205 <cpu_MHz+0x85>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1253 <cpu_MHz+0xd3>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11f0 <cpu_MHz+0x70>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11f0 <cpu_MHz+0x70>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11f0 <cpu_MHz+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
movss  0xc(%rsp),%xmm0
jmp    1263 <cpu_MHz+0xe3>
mov    %r14,%rdi
call   1040 <fclose@plt>
movss  0xd9d(%rip),%xmm0
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd89(%rip),%rdi
call   10a0 <perror@plt>
jmp    125b <cpu_MHz+0xdb>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [8 x i8] c"cpu MHz\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c":%g\00"
define float @cpu_MHz() {
%1 = alloca float
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca float
%6 = alloca i8*
%7 = alloca i32*
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i8*, i8** %2
%14 = call i32 @perror(i8* %13)
store float -1.000000e+00, float* %1
br label %46
15: ; preds = %0
br label %16
16: ; preds = %42, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = load i32*, i32** %7
%19 = call i64 @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @strncmp(i8* %22, i8* %23, i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %42, label %28
28: ; preds = %21
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = call i8* @strchr(i8* %29, i8 signext 58)
store i8* %30, i8** %3
%31 = load i8*, i8** %3
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %28
%34 = load i8*, i8** %3
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), float* %5)
%36 = icmp eq i32 1, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
%40 = load float, float* %5
store float %40, float* %1
br label %46
41: ; preds = %33, %28
br label %42
42: ; preds = %41, %21
br label %16
43: ; preds = %16
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
store float -1.000000e+00, float* %1
br label %46
46: ; preds = %43, %37, %12
%47 = load float, float* %1
ret float %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [8 x i8] c"cpu MHz\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c":%g\00"
define float @cpu_MHz() {
%1 = alloca [1024 x i8]
%2 = alloca float
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast float* %2 to i8*
%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.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i64 @fgets(i8* %3, i32 1024, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %28, label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %30
12: ; preds = %7, %25
%13 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = call i8* @strchr(i8* %3, i8 signext 58)
%18 = icmp eq i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), float* %2)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @fclose(i32* %5)
%24 = load float, float* %2
br label %30
25: ; preds = %16, %19, %12
%26 = call i64 @fgets(i8* %3, i32 1024, i32* %5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %12
28: ; preds = %25, %7
%29 = call i32 @fclose(i32* %5)
br label %30
30: ; preds = %28, %22, %10
%31 = phi float [ %24, %22 ], [ -1.000000e+00, %28 ], [ -1.000000e+00, %10 ]
ret float %31
}