#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*/ *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[1024 * 4];
  size_t bytes_read;
  char *match;
  float clock_speed;
  fp = fopen("/proc/cpuinfo", "r");
  bytes_read = fread(buffer, 1, sizeof(buffer), 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    $0x1030,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
je     11a2 <get_cpu_clock_speed+0x62>
cmpq   $0x1000,-0x1018(%rbp)
jne    11af <get_cpu_clock_speed+0x6f>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    121a <get_cpu_clock_speed+0xda>
mov    -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
jne    11f3 <get_cpu_clock_speed+0xb3>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    121a <get_cpu_clock_speed+0xda>
mov    -0x1020(%rbp),%rdi
lea    0xe17(%rip),%rsi
lea    -0x1024(%rbp),%rdx
call   1040 <sscanf@plt>
movss  -0x1024(%rbp),%xmm0
ff
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_clock_speed>:
sub    $0x1018,%rsp
lea    0xeb2(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
xorps  %xmm0,%xmm0
test   $0xffffffffffffefff,%rax
je     11b4 <get_cpu_clock_speed+0x74>
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe88(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <strstr@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
je     11b4 <get_cpu_clock_speed+0x74>
lea    0xe77(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <sscanf@plt>
movss  0xc(%rsp),%xmm0
add    $0x1018,%rsp
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 [4096 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 [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i64 @fread(i8* %8, i32 1, i32 4096, i32* %9)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 4096
br i1 %15, label %16, label %17
16: ; preds = %13, %0
store float 0.000000e+00, float* %1
br label %29
17: ; preds = %13
%18 = load i64, i64* %4
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %17
store float 0.000000e+00, float* %1
br label %29
25: ; preds = %17
%26 = load i8*, i8** %5
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), float* %6)
%28 = load float, float* %6
store float %28, float* %1
br label %29
29: ; preds = %25, %24, %16
%30 = load float, float* %1
ret float %30
}

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