#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int getVal() {
  FILE *file = fopen("/sys/class/gpio/gpio68/value", "r");
  if (file == NULL) {
    perror("Couldn't open GPIO value file!");
    return -1;
  }
  char buffer[256];
  fgets(buffer, 256, file);
  fclose(file);
  if (buffer[0] == '0')
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<getVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xeae(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1185 <getVal+0x45>
lea    0xeab(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <getVal+0x86>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movsbl -0x110(%rbp),%eax
cmp    $0x30,%eax
jne    11bf <getVal+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <getVal+0x86>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVal>:
push   %rbx
sub    $0x100,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118d <getVal+0x4d>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmpb   $0x30,(%rsp)
setne  %al
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    1184 <getVal+0x44>

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/gpio/gpio68/value\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Couldn't open GPIO value file!\00"
define i32 @getVal() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 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 eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32 @fgets(i8* %10, i32 256, i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 48
br i1 %18, label %19, label %20
19: ; preds = %9
store i32 0, i32* %1
br label %21
20: ; preds = %9
store i32 1, i32* %1
br label %21
21: ; preds = %20, %19, %7
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio68/value\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Couldn't open GPIO value file!\00"
define i32 @getVal() {
%1 = alloca [256 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %13
6: ; preds = %0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%8 = call i32 @fgets(i8* %7, i32 256, i32* %2)
%9 = call i32 @fclose(i32* %2)
%10 = load i8, i8* %7
%11 = icmp ne i8 %10, 48
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %6, %4
%14 = phi i32 [ -1, %4 ], [ %12, %6 ]
ret i32 %14
}