#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int gpio_export(char *gp) {
  int fd = 0;
  int er = 0;
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd == -1) {
    fprintf(stderr, "%s\n", strerror(errno));
    return 1;
  };
  er = write(fd, gp, 2);
  close(fd);
  if (er == -1) {
    fprintf(stderr, "%s\n", strerror(errno));
    return 1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<gpio_export>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c4 <gpio_export+0x74>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <gpio_export+0xd9>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1222 <gpio_export+0xd2>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe06(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <gpio_export+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_export>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1191 <gpio_export+0x41>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
jne    11be <gpio_export+0x6e>
mov    0x2e48(%rip),%rax
mov    (%rax),%ebx
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe68(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @gpio_export(i8* nocapture %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = tail call i32 @write(i32 %3, i8* %0, i32 2)
%7 = tail call i32 @close(i32 %3)
%8 = icmp eq i32 %6, -1
br i1 %8, label %9, label %14
9: ; preds = %5, %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %9, %5
%15 = phi i32 [ 0, %5 ], [ 1, %9 ]
ret i32 %15
}