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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sscanf(char *, char *, float *);
scalar_t__ strncmp(char *, char *, int);
unsigned long long get_hz(void) {
  FILE *fp;
  char buf[1024];
  unsigned long long ret = 0;
  float f = 0;
  if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) {
    perror("fopen");
    goto err;
  }
  while (fgets(buf, sizeof(buf), fp)) {
    if (strncmp(buf, "cpu MHz", 7)) {
      continue;
    }
    sscanf(buf, "cpu MHz%*[ \t]: %f\n", &f);
    break;
  }
  ret = (unsigned long long)(f * 1000000.0);
out:
  if (fp)
    fclose(fp);
  return (ret);
err:
  ret = 0;
  goto out;
}


x86 assembly (clang, -O0):
<get_hz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movq   $0x0,-0x418(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x41c(%rbp)
ff
lea    0xe88(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11b3 <get_hz+0x53>
lea    0xe77(%rip),%rdi
call   1080 <perror@plt>
jmp    1281 <get_hz+0x121>
jmp    11b8 <get_hz+0x58>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1218 <get_hz+0xb8>
lea    -0x410(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11fe <get_hz+0x9e>
jmp    11b8 <get_hz+0x58>
lea    -0x410(%rbp),%rdi
lea    0xe22(%rip),%rsi
lea    -0x41c(%rbp),%rdx
call   1060 <sscanf@plt>
movss  -0x41c(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xdd4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xdc1(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1271 <get_hz+0x111>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x418(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret
movq   $0x0,-0x418(%rbp)
jmp    125d <get_hz+0xfd>

x86 assembly (clang, -O2):
<get_hz>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe93(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123b <get_hz+0xdb>
mov    %rax,%r15
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
lea    0xe82(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1221 <get_hz+0xc1>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <get_hz+0x50>
lea    0xe4d(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xdfe(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xdf2(%rip),%xmm0
cvttsd2si %xmm0,%r14
and    %rcx,%r14
or     %rax,%r14
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdde(%rip),%rdi
call   1080 <perror@plt>
xor    %r14d,%r14d
jmp    1229 <get_hz+0xc9>

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

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