#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 *, int *, int *);
int dell_get_fan_status(void) {
  FILE *fp = fopen("/proc/i8k", "r");
  int fan_status = 0;
  int fan_2_status = 0;
  if (!fp)
    return -1;
  if (fscanf(fp, "%*s%*s%*s%*s%d%d", &fan_status, &fan_2_status) == 2) {
    fclose(fp);
    return (fan_status + fan_2_status);
  }
  fclose(fp);
  return -1;
}


x86 assembly (clang, -O0):
<dell_get_fan_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <dell_get_fan_status+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <dell_get_fan_status+0x8c>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    11ac <dell_get_fan_status+0x7c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <dell_get_fan_status+0x8c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dell_get_fan_status>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0xffffffff,%ebp
test   %rax,%rax
je     119a <dell_get_fan_status+0x6a>
mov    %rax,%rbx
lea    0xe9d(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x2,%r14d
jne    119a <dell_get_fan_status+0x6a>
mov    0x8(%rsp),%ebp
add    0xc(%rsp),%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"/proc/i8k\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"%*s%*s%*s%*s%d%d\00"
define i32 @dell_get_fan_status() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = icmp eq i32* %3, null
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%9 = icmp eq i32 %8, 2
%10 = call i32 @fclose(i32* %3)
br i1 %9, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = add nsw i32 %13, %12
br label %15
15: ; preds = %7, %0, %11
%16 = phi i32 [ %14, %11 ], [ -1, %0 ], [ -1, %7 ]
ret i32 %16
}