#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_WRONLY;
int close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
void set_pic_gpio_direction(void) {
  int fd;
  fd = open("/sys/class/gpio/gpio15/direction", O_WRONLY);
  if (fd == -1) {
    perror("open: /sys/class/gpio/gpio15/direction");
    exit(76);
  }
  if (write(fd, "out", 3) != 3) {
    perror("write: /sys/class/gpio/gpio15/direction");
    exit(81);
  }
  if (close(fd) == -1) {
    perror("close: /sys/class/gpio/gpio15/direction");
    exit(86);
  }
}


x86 assembly (clang, -O0):
<set_pic_gpio_direction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xef2(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1190 <set_pic_gpio_direction+0x40>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x4c,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
lea    0xe8d(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
je     11c3 <set_pic_gpio_direction+0x73>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    $0x51,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11ea <set_pic_gpio_direction+0x9a>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
mov    $0x56,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pic_gpio_direction>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xef9(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1193 <set_pic_gpio_direction+0x43>
mov    %eax,%ebx
lea    0xeb3(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
jne    11a9 <set_pic_gpio_direction+0x59>
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     11bf <set_pic_gpio_direction+0x6f>
pop    %rbx
ret
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
mov    $0x4c,%edi
call   1070 <exit@plt>
lea    0xe7b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x51,%edi
call   1070 <exit@plt>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x56,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"/sys/class/gpio/gpio15/direction\00"
@O_WRONLY = global i32 0
@.str.1 = [39 x i8] c"open: /sys/class/gpio/gpio15/direction\00"
@.str.2 = [4 x i8] c"out\00"
@.str.3 = [40 x i8] c"write: /sys/class/gpio/gpio15/direction\00"
@.str.4 = [40 x i8] c"close: /sys/class/gpio/gpio15/direction\00"
define void @set_pic_gpio_direction() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @exit(i32 76)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 81)
unreachable
16: ; preds = %9
%17 = load i32, i32* %1
%18 = call i32 @close(i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @exit(i32 86)
unreachable
23: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"/sys/class/gpio/gpio15/direction\00"
@O_WRONLY = global i32 0
@.str.1 = [39 x i8] c"open: /sys/class/gpio/gpio15/direction\00"
@.str.2 = [4 x i8] c"out\00"
@.str.3 = [40 x i8] c"write: /sys/class/gpio/gpio15/direction\00"
@.str.4 = [40 x i8] c"close: /sys/class/gpio/gpio15/direction\00"
define void @set_pic_gpio_direction() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 76)
unreachable
7: ; preds = %0
%8 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%9 = icmp eq i32 %8, 3
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 81)
unreachable
13: ; preds = %7
%14 = tail call i32 @close(i32 %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @exit(i32 86)
unreachable
19: ; preds = %13
ret void
}