#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 Get_Fan_Status();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
int toshiba_get_fan_status(int use_toshiba_hardware) {
  if (use_toshiba_hardware != 2) {
    FILE *fp = fopen("/proc/acpi/toshiba/fan", "r");
    if (fp) {
      int result;
      if (fscanf(fp, "%*s%d", &result) == 1) {
        fclose(fp);
        return result;
      }
      fclose(fp);
    }
    if (!use_toshiba_hardware)
      return -1;
  }
  if (Get_Fan_Status() < 0x00) {
    fprintf(stderr, "direct access to toshiba hardware failed:\n");
    fprintf(stderr, "cannot get fan status!\n");
    return -1;
  }
  if (Get_Fan_Status() == 0x00)
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<toshiba_get_fan_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11dc <toshiba_get_fan_status+0x8c>
lea    0xe94(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c1 <toshiba_get_fan_status+0x71>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b8 <toshiba_get_fan_status+0x68>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <toshiba_get_fan_status+0xf5>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11d7 <toshiba_get_fan_status+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <toshiba_get_fan_status+0xf5>
jmp    11dc <toshiba_get_fan_status+0x8c>
mov    $0x0,%al
call   1070 <Get_Fan_Status@plt>
cmp    $0x0,%eax
jge    1222 <toshiba_get_fan_status+0xd2>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <toshiba_get_fan_status+0xf5>
mov    $0x0,%al
call   1070 <Get_Fan_Status@plt>
cmp    $0x0,%eax
jne    123e <toshiba_get_fan_status+0xee>
movl   $0x0,-0x4(%rbp)
jmp    1245 <toshiba_get_fan_status+0xf5>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toshiba_get_fan_status>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
je     11a9 <toshiba_get_fan_status+0x59>
mov    %edi,%ebp
lea    0xe9a(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a5 <toshiba_get_fan_status+0x55>
mov    %rax,%rbx
lea    0xe98(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%r14d
jne    11a5 <toshiba_get_fan_status+0x55>
mov    0xc(%rsp),%eax
jmp    11ee <toshiba_get_fan_status+0x9e>
test   %ebp,%ebp
je     11e9 <toshiba_get_fan_status+0x99>
xor    %eax,%eax
call   1070 <Get_Fan_Status@plt>
test   %eax,%eax
js     11c6 <toshiba_get_fan_status+0x76>
xor    %eax,%eax
call   1070 <Get_Fan_Status@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
jmp    11ee <toshiba_get_fan_status+0x9e>
mov    0x2e13(%rip),%rbx
mov    (%rbx),%edi
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/proc/acpi/toshiba/fan\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%*s%d\00"
@stderr = global i32 0
@.str.3 = [43 x i8] c"direct access to toshiba hardware failed:\0A\00"
@.str.4 = [24 x i8] c"cannot get fan status!\0A\00"
define i32 @toshiba_get_fan_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 2
br i1 %7, label %8, label %28
8: ; preds = %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32*, i32** %4
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %41
20: ; preds = %12
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %20, %8
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %23
store i32 -1, i32* %2
br label %41
27: ; preds = %23
br label %28
28: ; preds = %27, %1
%29 = call i32 (...) @Get_Fan_Status()
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
36: ; preds = %28
%37 = call i32 (...) @Get_Fan_Status()
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 0, i32* %2
br label %41
40: ; preds = %36
store i32 1, i32* %2
br label %41
41: ; preds = %40, %39, %31, %26, %16
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [23 x i8] c"/proc/acpi/toshiba/fan\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%*s%d\00"
@stderr = global i32 0
@.str.3 = [43 x i8] c"direct access to toshiba hardware failed:\0A\00"
@.str.4 = [24 x i8] c"cannot get fan status!\0A\00"
define i32 @toshiba_get_fan_status(i32 %0) {
%2 = alloca i32
%3 = icmp eq i32 %0, 2
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 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 %15, label %7
7: ; preds = %4
%8 = bitcast i32* %2 to i8*
%9 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = icmp eq i32 %9, 1
%11 = call i32 @fclose(i32* %5)
br i1 %10, label %12, label %14
12: ; preds = %7
%13 = load i32, i32* %2
br label %29
14: ; preds = %7
br label %15
15: ; preds = %4, %14
%16 = icmp eq i32 %0, 0
br i1 %16, label %29, label %17
17: ; preds = %15, %1
%18 = call i32 (...) @Get_Fan_Status()
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %29
25: ; preds = %17
%26 = call i32 (...) @Get_Fan_Status()
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %12, %25, %15, %20
%30 = phi i32 [ -1, %15 ], [ -1, %20 ], [ %28, %25 ], [ %13, %12 ]
ret i32 %30
}