#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 export_pic_gpio(void) {
  int fd;
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd == -1) {
    perror("open: /sys/class/gpio/export");
    exit(55);
  }
  if (write(fd, "15", 2) != 2) {
    perror("write: /sys/class/gpio/export");
    exit(60);
  }
  if (close(fd) == -1) {
    perror("close: /sys/class/gpio/export");
    exit(65);
  }
}


x86 assembly (clang, -O0):
<export_pic_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xedd(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1190 <export_pic_gpio+0x40>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x37,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
lea    0xe83(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     11c3 <export_pic_gpio+0x73>
lea    0xe6c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x3c,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11ea <export_pic_gpio+0x9a>
lea    0xe63(%rip),%rdi
call   1060 <perror@plt>
mov    $0x41,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_pic_gpio>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xee4(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1193 <export_pic_gpio+0x43>
mov    %eax,%ebx
lea    0xea9(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jne    11a9 <export_pic_gpio+0x59>
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     11bf <export_pic_gpio+0x6f>
pop    %rbx
ret
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
mov    $0x37,%edi
call   1070 <exit@plt>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    $0x3c,%edi
call   1070 <exit@plt>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
mov    $0x41,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [29 x i8] c"open: /sys/class/gpio/export\00"
@.str.2 = [3 x i8] c"15\00"
@.str.3 = [30 x i8] c"write: /sys/class/gpio/export\00"
@.str.4 = [30 x i8] c"close: /sys/class/gpio/export\00"
define void @export_pic_gpio() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 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 ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @exit(i32 55)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 60)
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 ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @exit(i32 65)
unreachable
23: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [29 x i8] c"open: /sys/class/gpio/export\00"
@.str.2 = [3 x i8] c"15\00"
@.str.3 = [30 x i8] c"write: /sys/class/gpio/export\00"
@.str.4 = [30 x i8] c"close: /sys/class/gpio/export\00"
define void @export_pic_gpio() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 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 ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 55)
unreachable
7: ; preds = %0
%8 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%9 = icmp eq i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 60)
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 ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @exit(i32 65)
unreachable
19: ; preds = %13
ret void
}