#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int gpio_check(void) {
  int fd;
  fd = open("/sys/class/gpio/gpio115/value", O_RDONLY);
  if (fd != 0) {
    int len;
    unsigned char pin_val;
    len = read(fd, &pin_val, 1);
    close(fd);
    if (len == 1) {
      if (pin_val == 48) {
        return 1;
      } else {
        return 0;
      }
    }
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<gpio_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11aa <gpio_check+0x7a>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11a5 <gpio_check+0x75>
movzbl -0xd(%rbp),%eax
cmp    $0x30,%eax
jne    1199 <gpio_check+0x69>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <gpio_check+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <gpio_check+0x81>
jmp    11b1 <gpio_check+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_check>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
je     1174 <gpio_check+0x44>
mov    %eax,%ebx
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
cmpb   $0x30,0xf(%rsp)
sete   %al
jmp    1176 <gpio_check+0x46>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/class/gpio/gpio115/value\00"
@O_RDONLY = global i32 0
define i32 @gpio_check() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @read(i32 %10, i8* %4, i32 1)
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %9
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 48
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %1
br label %24
21: ; preds = %16
store i32 0, i32* %1
br label %24
22: ; preds = %9
br label %24
23: ; preds = %0
store i32 0, i32* %1
br label %24
24: ; preds = %20, %21, %23, %22
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/class/gpio/gpio115/value\00"
@O_RDONLY = global i32 0
define i32 @gpio_check() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = call i32 @read(i32 %3, i8* %1, i32 1)
%7 = tail call i32 @close(i32 %3)
%8 = icmp eq i32 %6, 1
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 48
%11 = zext i1 %10 to i32
%12 = select i1 %8, i32 %11, i32 undef
br label %13
13: ; preds = %0, %5
%14 = phi i32 [ %12, %5 ], [ 0, %0 ]
ret i32 %14
}