#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 /*<<< orphan*/ write(int, char *, int);
void gpioInit(int gpio) {
  int fd;
  char buf[255];
  fd = open("/sys/class/gpio/export", O_WRONLY);
  sprintf(buf, "%d", gpio);
  write(fd, buf, 3);
  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):
<gpioInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xea2(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea0(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe71(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe6b(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpioInit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
mov    0x2e82(%rip),%r15
mov    (%r15),%esi
lea    0xea0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
lea    0xea9(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0xe85(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebx,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>

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 @gpioInit(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 = call i32 @write(i32 %10, i8* %11, i32 3)
%13 = load i32, i32* %3
%14 = call i32 @close(i32 %13)
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* %2
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
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 @gpioInit(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 @write(i32 %5, i8* %3, i32 3)
%8 = tail call i32 @close(i32 %5)
%9 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* %3, i32 %10)
%12 = tail call i32 @write(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%13 = tail call i32 @close(i32 %11)
ret void
}