#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*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ memcmp(char *, char *, int);
unsigned int 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);
        return s * 1000.0;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cpu_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xea6(%rip),%rdi
lea    0xead(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <cpu_speed+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1242 <cpu_speed+0xf2>
jmp    118e <cpu_speed+0x3e>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ac <cpu_speed+0x5c>
jmp    123b <cpu_speed+0xeb>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa0,%esi
call   1050 <fgets@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
je     1236 <cpu_speed+0xe6>
lea    -0xb0(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0xb,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    1231 <cpu_speed+0xe1>
lea    -0xa6(%rbp),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0xbc(%rbp)
ff
movss  -0xbc(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xde0(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x4(%rbp)
jmp    1242 <cpu_speed+0xf2>
jmp    1236 <cpu_speed+0xe6>
jmp    118e <cpu_speed+0x3e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_speed>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xea3(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1070 <fopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1188 <cpu_speed+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     119a <cpu_speed+0x4a>
mov    %r14d,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rsp,%r15
lea    0xe74(%rip),%r12
jmp    11bc <cpu_speed+0x6c>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1188 <cpu_speed+0x38>
mov    %r15,%rdi
mov    $0xa0,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b0 <cpu_speed+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xb,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11b0 <cpu_speed+0x60>
lea    0xa(%rsp),%rdi
call   1030 <atof@plt>
cvtss2sd %xmm0,%xmm0
mulsd  0xe04(%rip),%xmm0
cvttsd2si %xmm0,%r14
jmp    1188 <cpu_speed+0x38>

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 i32 @cpu_speed() {
%1 = alloca i32
%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 i32 0, i32* %1
br label %37
10: ; preds = %0
br label %11
11: ; preds = %35, %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 %36
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 %35
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 %34
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 float, float* %5
%31 = fpext float %30 to double
%32 = fmul double %31, 1.000000e+03
%33 = fptoui double %32 to i32
store i32 %33, i32* %1
br label %37
34: ; preds = %22
br label %35
35: ; preds = %34, %16
br label %11
36: ; preds = %11
store i32 0, i32* %1
br label %37
37: ; preds = %36, %26, %9
%38 = load i32, i32* %1
ret i32 %38
}

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 i32 @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 %23, label %5
5: ; preds = %0
%6 = call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %5, %20
%9 = call i8* @fgets(i8* %2, i32 160, i32* %3)
%10 = icmp eq i8* %9, null
br i1 %10, label %20, 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 %20
14: ; preds = %11
%15 = getelementptr inbounds [160 x i8], [160 x i8]* %1, i64 0, i64 10
%16 = call float @atof(i8* %15)
%17 = fpext float %16 to double
%18 = fmul double %17, 1.000000e+03
%19 = fptoui double %18 to i32
br label %23
20: ; preds = %8, %11
%21 = call i32 @feof(i32* %3)
%22 = icmp eq i32 %21, 0
br i1 %22, label %8, label %23
23: ; preds = %20, %5, %14, %0
%24 = phi i32 [ 0, %0 ], [ %19, %14 ], [ 0, %5 ], [ 0, %20 ]
ret i32 %24
}