#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*/ sscanf(char *, char *, float *);
char *strstr(char *, char *);
float get_cpu_clock_speed() {
  FILE *fp;
  char buffer[2048];
  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) {
    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    $0x830,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %rax,-0x818(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x818(%rbp)
je     11bb <get_cpu_clock_speed+0x6b>
cmpq   $0x800,-0x818(%rbp)
jne    11c8 <get_cpu_clock_speed+0x78>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1233 <get_cpu_clock_speed+0xe3>
mov    -0x818(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
jne    120c <get_cpu_clock_speed+0xbc>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1233 <get_cpu_clock_speed+0xe3>
mov    -0x820(%rbp),%rdi
lea    0xdfe(%rip),%rsi
lea    -0x824(%rbp),%rdx
call   1050 <sscanf@plt>
movss  -0x824(%rbp),%xmm0
ff
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_clock_speed>:
push   %r14
push   %rbx
sub    $0x818,%rsp
lea    0xe9f(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
xorps  %xmm0,%xmm0
test   $0xfffffffffffff7ff,%r14
je     11d7 <get_cpu_clock_speed+0x87>
movb   $0x0,0x10(%rsp,%r14,1)
lea    0xe65(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <strstr@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
je     11d7 <get_cpu_clock_speed+0x87>
lea    0xe54(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <sscanf@plt>
movss  0xc(%rsp),%xmm0
add    $0x818,%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 = [13 x i8] c"cpu MHz : %f\00"
define float @get_cpu_clock_speed() {
%1 = alloca float
%2 = alloca i32*
%3 = alloca [2048 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 [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i64 @fread(i8* %8, i32 1, i32 2048, 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, 2048
br i1 %17, label %18, label %19
18: ; preds = %15, %0
store float 0.000000e+00, float* %1
br label %31
19: ; preds = %15
%20 = load i64, i64* %4
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %19
store float 0.000000e+00, float* %1
br label %31
27: ; preds = %19
%28 = load i8*, i8** %5
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), float* %6)
%30 = load float, float* %6
store float %30, float* %1
br label %31
31: ; preds = %27, %26, %18
%32 = load float, float* %1
ret float %32
}

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