#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int stat(char *, struct stat *);
int pic_gpio_is_exported(void) {
  struct stat st;
  int ret;
  ret = stat("/sys/class/gpio/gpio15", &st);
  if (ret == -1) {
    if (errno == ENOENT) {
      return 0;
    } else {
      perror("stat: /sys/class/gpio/gpio15");
      exit(41);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<pic_gpio_is_exported>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1191 <pic_gpio_is_exported+0x61>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    117b <pic_gpio_is_exported+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    1198 <pic_gpio_is_exported+0x68>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x29,%edi
call   1050 <exit@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pic_gpio_is_exported>:
push   %rax
lea    0xece(%rip),%rdi
mov    %rsp,%rsi
call   1030 <stat@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
jne    1164 <pic_gpio_is_exported+0x34>
mov    0x2e8d(%rip),%rax
mov    (%rax),%rcx
mov    0x2e73(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
jne    1166 <pic_gpio_is_exported+0x36>
pop    %rcx
ret
lea    0xe93(%rip),%rdi
call   1040 <perror@plt>
mov    $0x29,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [23 x i8] c"/sys/class/gpio/gpio15\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [29 x i8] c"stat: /sys/class/gpio/gpio15\00"
define i32 @pic_gpio_is_exported() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
%4 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 0, i32* %1
br label %16
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 41)
unreachable
15: ; preds = %0
store i32 1, i32* %1
br label %16
16: ; preds = %15, %11
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [23 x i8] c"/sys/class/gpio/gpio15\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [29 x i8] c"stat: /sys/class/gpio/gpio15\00"
define i32 @pic_gpio_is_exported() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 41)
unreachable
12: ; preds = %0, %5
%13 = phi i32 [ 0, %5 ], [ 1, %0 ]
ret i32 %13
}