#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, float *);
char *strstr(char *, char *);
float get_cpu_clock_speed() {
  FILE *fp;
  char buffer[10240];
  size_t bytes_read;
  char *match;
  float clock_speed;
  fp = fopen("/proc/cpuinfo", "r");
  bytes_read = fread(buffer, 1, sizeof(buffer), fp);
  fclose(fp);
  if (bytes_read == 0 || bytes_read == sizeof(buffer)) {
    return 0;
  }
  buffer[bytes_read] == '\0';
  match = strstr(buffer, "cpu MHz");
  if (match == NULL) {
    printf("2\n");
    return 0;
  }
  sscanf(match, "cpu MHz : %f", &clock_speed);
  return clock_speed;
}


x86 assembly (clang, -O0):
<get_cpu_clock_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x2810(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2800,%edx
call   1030 <fread@plt>
mov    %rax,-0x2818(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x2818(%rbp)
je     11cb <get_cpu_clock_speed+0x6b>
cmpq   $0x2800,-0x2818(%rbp)
jne    11d8 <get_cpu_clock_speed+0x78>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1240 <get_cpu_clock_speed+0xe0>
lea    -0x2810(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x2820(%rbp)
cmpq   $0x0,-0x2820(%rbp)
jne    1219 <get_cpu_clock_speed+0xb9>
lea    0xe11(%rip),%rdi
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1240 <get_cpu_clock_speed+0xe0>
mov    -0x2820(%rbp),%rdi
lea    0xdf4(%rip),%rsi
lea    -0x2824(%rbp),%rdx
call   1060 <sscanf@plt>
movss  -0x2824(%rbp),%xmm0
ff
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_clock_speed>:
push   %r14
push   %rbx
sub    $0x2818,%rsp
lea    0xe8f(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2800,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
xorps  %xmm0,%xmm0
test   %r14,%r14
je     11f4 <get_cpu_clock_speed+0x94>
cmp    $0x2800,%r14
je     11f4 <get_cpu_clock_speed+0x94>
lea    0xe56(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     11e5 <get_cpu_clock_speed+0x85>
lea    0xe48(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <sscanf@plt>
movss  0xc(%rsp),%xmm0
jmp    11f4 <get_cpu_clock_speed+0x94>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
add    $0x2818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"cpu MHz\00"
@.str.3 = [3 x i8] c"2\0A\00"
@.str.4 = [13 x i8] c"cpu MHz : %f\00"
define float @get_cpu_clock_speed() {
%1 = alloca float
%2 = alloca i32*
%3 = alloca [10240 x i8]
%4 = alloca i64
%5 = alloca i8*
%6 = alloca float
%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 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i64 @fread(i8* %8, i32 1, i32 10240, i32* %9)
store i64 %10, i64* %4
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
%13 = load i64, i64* %4
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %0
%16 = load i64, i64* %4
%17 = icmp eq i64 %16, 10240
br i1 %17, label %18, label %19
18: ; preds = %15, %0
store float 0.000000e+00, float* %1
br label %36
19: ; preds = %15
%20 = load i64, i64* %4
%21 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
%26 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store float 0.000000e+00, float* %1
br label %36
32: ; preds = %19
%33 = load i8*, i8** %5
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), float* %6)
%35 = load float, float* %6
store float %35, float* %1
br label %36
36: ; preds = %32, %30, %18
%37 = load float, float* %1
ret float %37
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"cpu MHz\00"
@.str.4 = [13 x i8] c"cpu MHz : %f\00"
@str = [2 x i8] c"2\00"
define float @get_cpu_clock_speed() {
%1 = alloca [10240 x i8]
%2 = alloca float
%3 = getelementptr inbounds [10240 x i8], [10240 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.1, i64 0, i64 0))
%6 = call i64 @fread(i8* %3, i32 1, i32 10240, i32* %5)
%7 = tail call i32 @fclose(i32* %5)
switch i64 %6, label %8 [
i64 10240, label %16
i64 0, label %16
]
8: ; preds = %0
%9 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %16
13: ; preds = %8
%14 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), float* %2)
%15 = load float, float* %2
br label %16
16: ; preds = %0, %0, %13, %11
%17 = phi float [ 0.000000e+00, %11 ], [ %15, %13 ], [ 0.000000e+00, %0 ], [ 0.000000e+00, %0 ]
ret float %17
}