#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 /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, char *, int);
int setup_gpio() {
  int fd;
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd == -1) {
    perror("open");
    return -1;
  }
  write(fd, "44", 2);
  close(fd);
  fd = open("/sys/class/gpio/gpio44/direction", O_WRONLY);
  if (fd == -1) {
    perror("open");
    return -1;
  }
  write(fd, "in", 2);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<setup_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1182 <setup_gpio+0x42>
lea    0xea6(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <setup_gpio+0xbb>
mov    -0x8(%rbp),%edi
lea    0xe90(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11d8 <setup_gpio+0x98>
lea    0xe50(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <setup_gpio+0xbb>
mov    -0x8(%rbp),%edi
lea    0xe5e(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_gpio>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%r14
mov    (%r14),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11b5 <setup_gpio+0x75>
mov    %eax,%ebx
lea    0xeb4(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%r14),%esi
lea    0xe9a(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11b5 <setup_gpio+0x75>
mov    %eax,%ebx
lea    0xea8(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5b(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    11ad <setup_gpio+0x6d>

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"44\00"
@.str.3 = [33 x i8] c"/sys/class/gpio/gpio44/direction\00"
@.str.4 = [3 x i8] c"in\00"
define i32 @setup_gpio() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_WRONLY
%4 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %25
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %25
20: ; preds = %9
%21 = load i32, i32* %2
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
store i32 0, i32* %1
br label %25
25: ; preds = %20, %18, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"44\00"
@.str.3 = [33 x i8] c"/sys/class/gpio/gpio44/direction\00"
@.str.4 = [3 x i8] c"in\00"
define i32 @setup_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 %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %17
6: ; preds = %0
%7 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%8 = tail call i32 @close(i32 %2)
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %17
14: ; preds = %6
%15 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%16 = tail call i32 @close(i32 %10)
br label %17
17: ; preds = %14, %12, %4
%18 = phi i32 [ -1, %4 ], [ -1, %12 ], [ 0, %14 ]
ret i32 %18
}