#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int rc_print_cpu_freq() {
  int freq;
  FILE *freq_fd =
      fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
  if (freq_fd == NULL) {
    fprintf(stderr, "ERROR in rc_print_cpu_freq, cpu governor driver not "
                    "available in this kernel\n");
    return -1;
  }
  if (fscanf(freq_fd, "%d", &freq) < 0) {
    fprintf(stderr,
            "ERROR in rc_print_cpu_freq, failed to read frequency path\n");
    return -1;
  }
  fclose(freq_fd);
  printf("%dmhz", freq / 1000);
  return 0;
}


x86 assembly (clang, -O0):
<rc_print_cpu_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xed0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <rc_print_cpu_freq+0x4b>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <rc_print_cpu_freq+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xee0(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x0,%rax
jge    11da <rc_print_cpu_freq+0x8a>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <rc_print_cpu_freq+0xb3>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xecd(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_print_cpu_freq>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xed3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ba <rc_print_cpu_freq+0x6a>
mov    %rax,%rbx
lea    0xf0f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
test   %rax,%rax
js     11cc <rc_print_cpu_freq+0x7c>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movslq 0xc(%rsp),%rax
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
lea    0xf13(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11e6 <rc_print_cpu_freq+0x96>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
jmp    11dc <rc_print_cpu_freq+0x8c>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [54 x i8] c"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [78 x i8] c"ERROR in rc_print_cpu_freq, cpu governor driver not available in this kernel\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [59 x i8] c"ERROR in rc_print_cpu_freq, failed to read frequency path\0A\00"
@.str.5 = [6 x i8] c"%dmhz\00"
define i32 @rc_print_cpu_freq() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
10: ; preds = %0
%11 = load i32*, i32** %3
%12 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
17: ; preds = %10
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %2
%21 = sdiv i32 %20, 1000
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %21)
store i32 0, i32* %1
br label %23
23: ; preds = %17, %14, %7
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [54 x i8] c"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [78 x i8] c"ERROR in rc_print_cpu_freq, cpu governor driver not available in this kernel\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [59 x i8] c"ERROR in rc_print_cpu_freq, failed to read frequency path\0A\00"
@.str.5 = [6 x i8] c"%dmhz\00"
define i32 @rc_print_cpu_freq() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([54 x i8], [54 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 %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
br label %19
8: ; preds = %0
%9 = call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %19
14: ; preds = %8
%15 = call i32 @fclose(i32* %3)
%16 = load i32, i32* %1
%17 = sdiv i32 %16, 1000
%18 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %14, %11, %5
%20 = phi i32 [ -1, %5 ], [ -1, %11 ], [ 0, %14 ]
ret i32 %20
}