#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int get_mhz(void) {
  FILE *f = fopen("/proc/cpuinfo", "r");
  if (f == 0) {
    perror("can't open /proc/cpuinfo\n");
    exit(1);
  }
  for (;;) {
    int mhz;
    int ret;
    char buf[1000];
    if (fgets(buf, sizeof(buf), f) == NULL) {
      fprintf(stderr, "cannot locate cpu MHz in /proc/cpuinfo\n");
      exit(1);
    }
    ret = sscanf(buf, "cpu MHz         : %d", &mhz);
    if (ret == 1) {
      fclose(f);
      return mhz;
    }
  }
}


x86 assembly (clang, -O0):
<get_mhz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
lea    0xe7e(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b3 <get_mhz+0x43>
lea    0xe6c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11b8 <get_mhz+0x48>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11f6 <get_mhz+0x86>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x400(%rbp),%rdi
lea    0xe4e(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    122f <get_mhz+0xbf>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret
jmp    11b8 <get_mhz+0x48>

x86 assembly (clang, -O2):
<get_mhz>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f8,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1232 <get_mhz+0xc2>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f8 <get_mhz+0x88>
lea    0xe97(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1217 <get_mhz+0xa7>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11d0 <get_mhz+0x60>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdd7(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"can't open /proc/cpuinfo\0A\00"
@stderr = global i32 0
@.str.3 = [40 x i8] c"cannot locate cpu MHz in /proc/cpuinfo\0A\00"
@.str.4 = [21 x i8] c"cpu MHz : %d\00"
define i32 @get_mhz() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%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 = load i32*, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %30, %11
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %1
%15 = call i32* @fgets(i8* %13, i32 1000, i32* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32* %2)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32*, i32** %1
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %2
ret i32 %29
30: ; preds = %21
br label %12
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"can't open /proc/cpuinfo\0A\00"
@stderr = global i32 0
@.str.3 = [40 x i8] c"cannot locate cpu MHz in /proc/cpuinfo\0A\00"
@.str.4 = [21 x i8] c"cpu MHz : %d\00"
define i32 @get_mhz() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%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 %10, label %5
5: ; preds = %0
%6 = bitcast i32* %1 to i8*
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%8 = call i32* @fgets(i8* %7, i32 1000, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %17
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %20, %5
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %5, %20
%18 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%19 = icmp eq i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i32* @fgets(i8* %7, i32 1000, i32* %3)
%22 = icmp eq i32* %21, null
br i1 %22, label %13, label %17
23: ; preds = %17
%24 = call i32 @fclose(i32* %3)
%25 = load i32, i32* %1
ret i32 %25
}