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

/* Variables and functions */
int /*<<< orphan*/ getSysFileValue(char *, int, char *);
int /*<<< orphan*/ output(char *, ...);
scalar_t__ sscanf(char const *, char *, int *);
void printSysFanState(const char *cmd) {
  int fan = 0;
  if (sscanf(cmd, "acpi/Cooling_Device/%d", &fan) <= 0) {
    output("-1\n");
    return;
  }
  output("%d\n", getSysFileValue("cooling_device", fan, "cur_state"));
}


x86 assembly (clang, -O0):
<printSysFanState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x0,%rax
jg     1174 <printSysFanState+0x44>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
jmp    119a <printSysFanState+0x6a>
mov    -0xc(%rbp),%esi
lea    0xea1(%rip),%rdi
lea    0xea9(%rip),%rdx
call   1040 <getSysFileValue@plt>
mov    %eax,%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printSysFanState>:
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xec0(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
test   %rax,%rax
jle    1178 <printSysFanState+0x48>
mov    0x4(%rsp),%esi
lea    0xec5(%rip),%rdi
lea    0xecd(%rip),%rdx
call   1040 <getSysFileValue@plt>
lea    0xeae(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <output@plt>
pop    %rax
ret
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [23 x i8] c"acpi/Cooling_Device/%d\00"
@.str.1 = [4 x i8] c"-1\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [15 x i8] c"cooling_device\00"
@.str.4 = [10 x i8] c"cur_state\00"
define void @printSysFanState(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = call i64 @sscanf(i8* %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp sle i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %13
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @getSysFileValue(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %9, %7
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"acpi/Cooling_Device/%d\00"
@.str.1 = [4 x i8] c"-1\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [15 x i8] c"cooling_device\00"
@.str.4 = [10 x i8] c"cur_state\00"
define void @printSysFanState(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = icmp slt i64 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %12
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @getSysFileValue(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %6
ret void
}