#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*/ sprintf(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void export_gpio(int gpio) {
  int fd;
  char buf[255];
  fd = open("/sys/class/gpio/export", O_WRONLY);
  sprintf(buf, "%d", gpio);
  write(fd, buf, strlen(buf));
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%d/direction", gpio);
  fd = open(buf, O_WRONLY);
  write(fd, "out", 3);
  close(fd);
}


x86 assembly (clang, -O0):
<export_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe90(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x11c(%rbp),%edi
mov    -0x118(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe3e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe38(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_gpio>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%r14d
mov    0x2e71(%rip),%r15
mov    (%r15),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xe98(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1070 <sprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe6d(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.3 = [4 x i8] c"out\00"
define void @export_gpio(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [255 x i8]
store i32 %0, i32* %2
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %3
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @write(i32 %10, i8* %11, i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %2
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* @O_WRONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.3 = [4 x i8] c"out\00"
define void @export_gpio(i32 %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%7 = call i32 @strlen(i8* %3)
%8 = call i32 @write(i32 %5, i8* %3, i32 %7)
%9 = call i32 @close(i32 %5)
%10 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %3, i32 %11)
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%14 = call i32 @close(i32 %12)
ret void
}