#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 fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int compal_get_fan_status(void) {
  FILE *fp = fopen("/proc/omnibook/fan", "r");
  char fan_status[3];
  if (!fp)
    return -1;
  if (fscanf(fp, "%*s%*s%2s", fan_status) != 1) {
    fclose(fp);
    return -1;
  }
  fclose(fp);
  if (!strcmp(fan_status, "on"))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<compal_get_fan_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <compal_get_fan_status+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <compal_get_fan_status+0x9d>
mov    -0x10(%rbp),%rdi
lea    -0x13(%rbp),%rdx
lea    0xe90(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11a8 <compal_get_fan_status+0x68>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <compal_get_fan_status+0x9d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x13(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <compal_get_fan_status+0x96>
movl   $0x1,-0x4(%rbp)
jmp    11dd <compal_get_fan_status+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compal_get_fan_status>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1050 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1195 <compal_get_fan_status+0x65>
mov    %rax,%rbx
lea    0xeb6(%rip),%rsi
lea    0xd(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%r14d
jne    1195 <compal_get_fan_status+0x65>
movzwl 0xd(%rsp),%eax
xor    $0x6e6f,%eax
movzbl 0xf(%rsp),%ecx
xor    %ebp,%ebp
or     %ax,%cx
sete   %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/proc/omnibook/fan\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"%*s%*s%2s\00"
@.str.3 = [3 x i8] c"on\00"
define i32 @compal_get_fan_status() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [3 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 -1, i32* %1
br label %24
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%11 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
store i32 -1, i32* %1
br label %24
16: ; preds = %8
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
store i32 1, i32* %1
br label %24
23: ; preds = %16
store i32 0, i32* %1
br label %24
24: ; preds = %23, %22, %13, %7
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [19 x i8] c"/proc/omnibook/fan\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"%*s%*s%2s\00"
@.str.3 = [3 x i8] c"on\00"
define i32 @compal_get_fan_status() {
%1 = alloca [3 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%4 = icmp eq i32* %2, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%7 = icmp eq i32 %6, 1
%8 = call i32 @fclose(i32* %2)
br i1 %7, label %9, label %13
9: ; preds = %5
%10 = call i32 @bcmp(i8* dereferenceable(3) %3, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %5, %9, %0
%14 = phi i32 [ -1, %0 ], [ %12, %9 ], [ -1, %5 ]
ret i32 %14
}