#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 */
float atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ memcmp(char *, char *, int);
unsigned long cpu_speed(void) {
  FILE *f;
  char line[160];
  f = fopen("/proc/cpuinfo", "r");
  if (f == NULL) {
    return 0;
  }
  while (!feof(f)) {
    char *res;
    res = fgets(line, 160, f);
    if (res != NULL) {
      if (memcmp(line, "cpu MHz\t\t: ", 11) == 0) {
        float s;
        s = atof(line + 10);
        fclose(f);
        return s * 1000.0;
      }
    }
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<cpu_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <cpu_speed+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1288 <cpu_speed+0x128>
jmp    119f <cpu_speed+0x3f>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bd <cpu_speed+0x5d>
jmp    1277 <cpu_speed+0x117>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa0,%esi
call   1060 <fgets@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
je     1272 <cpu_speed+0x112>
lea    -0xb0(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0xb,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    126d <cpu_speed+0x10d>
lea    -0xa6(%rbp),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0xbc(%rbp)
ff
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movss  -0xbc(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xdc6(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xdb3(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1288 <cpu_speed+0x128>
jmp    1272 <cpu_speed+0x112>
jmp    119f <cpu_speed+0x3f>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_speed>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     119b <cpu_speed+0x3b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11aa <cpu_speed+0x4a>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x10(%rsp),%r14
lea    0xe6a(%rip),%r15
jmp    11cc <cpu_speed+0x6c>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1193 <cpu_speed+0x33>
mov    %r14,%rdi
mov    $0xa0,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c0 <cpu_speed+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    11c0 <cpu_speed+0x60>
lea    0x1a(%rsp),%rdi
call   1030 <atof@plt>
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
call   1040 <fclose@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xde0(%rip),%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xdd4(%rip),%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rcx,%rax
jmp    119d <cpu_speed+0x3d>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"cpu MHz\09\09: \00"
define i64 @cpu_speed() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca [160 x i8]
%4 = alloca i8*
%5 = alloca float
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i64 0, i64* %1
br label %41
10: ; preds = %0
br label %11
11: ; preds = %37, %10
%12 = load i32*, i32** %2
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %38
16: ; preds = %11
%17 = getelementptr inbounds [160 x i8], [160 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %2
%19 = call i8* @fgets(i8* %17, i32 160, i32* %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %37
22: ; preds = %16
%23 = getelementptr inbounds [160 x i8], [160 x i8]* %3, i64 0, i64 0
%24 = call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = getelementptr inbounds [160 x i8], [160 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 10
%29 = call float @atof(i8* %28)
store float %29, float* %5
%30 = load i32*, i32** %2
%31 = call i32 @fclose(i32* %30)
%32 = load float, float* %5
%33 = fpext float %32 to double
%34 = fmul double %33, 1.000000e+03
%35 = fptoui double %34 to i64
store i64 %35, i64* %1
br label %41
36: ; preds = %22
br label %37
37: ; preds = %36, %16
br label %11
38: ; preds = %11
%39 = load i32*, i32** %2
%40 = call i32 @fclose(i32* %39)
store i64 0, i64* %1
br label %41
41: ; preds = %38, %26, %9
%42 = load i64, i64* %1
ret i64 %42
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"cpu MHz\09\09: \00"
define i64 @cpu_speed() {
%1 = alloca [160 x i8]
%2 = getelementptr inbounds [160 x i8], [160 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %0
%6 = call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %5, %21
%9 = call i8* @fgets(i8* %2, i32 160, i32* %3)
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = call i64 @memcmp(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = getelementptr inbounds [160 x i8], [160 x i8]* %1, i64 0, i64 10
%16 = call float @atof(i8* %15)
%17 = call i32 @fclose(i32* %3)
%18 = fpext float %16 to double
%19 = fmul double %18, 1.000000e+03
%20 = fptoui double %19 to i64
br label %26
21: ; preds = %8, %11
%22 = call i32 @feof(i32* %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %8, label %24
24: ; preds = %21, %5
%25 = call i32 @fclose(i32* %3)
br label %26
26: ; preds = %14, %0, %24
%27 = phi i64 [ 0, %24 ], [ 0, %0 ], [ %20, %14 ]
ret i64 %27
}