#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*/ LOG_ERR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
int read_cpu_temp(const char *cpu_path) {
  int temp;
  FILE *file;
  if ((file = fopen(cpu_path, "r")) != NULL) {
    fscanf(file, "%d", &temp);
    fclose(file);
    return temp;
  } else {
    syslog(LOG_ERR, "Failed to read %s", cpu_path);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<read_cpu_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a0 <read_cpu_temp+0x50>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe51(%rip),%rsi
call   1050 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<read_cpu_temp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1193 <read_cpu_temp+0x43>
mov    %rax,%rbx
lea    0xe90(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    %r14,%rdx
call   1050 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@LOG_ERR = global i32 0
@.str.2 = [18 x i8] c"Failed to read %s\00"
define i32 @read_cpu_temp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32*, i32** %4
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = load i32*, i32** %4
%12 = call i32 @fclose(i32* %11)
%13 = load i32, i32* %3
ret i32 %13
14: ; preds = %1
%15 = load i32, i32* @LOG_ERR
%16 = load i8*, i8** %2
%17 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@LOG_ERR = global i32 0
@.str.2 = [18 x i8] c"Failed to read %s\00"
define i32 @read_cpu_temp(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 @fclose(i32* %4)
%9 = load i32, i32* %2
ret i32 %9
10: ; preds = %1
%11 = load i32, i32* @LOG_ERR
%12 = tail call i32 @syslog(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
}