#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*/ errExit(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void setGPIOPin(char *pin, char *dir, char *drive, char *val) {
  char buf[256];
  int fd;
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd == -1)
    errExit("GPIO Export");
  write(fd, pin, strlen(pin));
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%s/direction", pin);
  fd = open(buf, O_WRONLY);
  if (fd == -1)
    errExit("Gpio Direction");
  write(fd, dir, strlen(dir));
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%s/drive", pin);
  fd = open(buf, O_WRONLY);
  if (fd == -1)
    errExit("Gpio Drive");
  write(fd, drive, strlen(drive));
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%s/value", pin);
  fd = open(buf, O_WRONLY);
  if (fd == -1)
    errExit("Gpio Value");
  write(fd, val, strlen(val));
  close(fd);
}


x86 assembly (clang, -O0):
<setGPIOPin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    11af <setGPIOPin+0x4f>
lea    0xe6d(%rip),%rdi
call   1040 <errExit@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x134(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x124(%rbp),%edi
call   1060 <close@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    1239 <setGPIOPin+0xd9>
lea    0xe10(%rip),%rdi
call   1040 <errExit@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x144(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x144(%rbp),%edi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x124(%rbp),%edi
call   1060 <close@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdc9(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    12c3 <setGPIOPin+0x163>
lea    0xdb2(%rip),%rdi
call   1040 <errExit@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x154(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x124(%rbp),%edi
call   1060 <close@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd67(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    134d <setGPIOPin+0x1ed>
lea    0xd50(%rip),%rdi
call   1040 <errExit@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x164(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x124(%rbp),%edi
call   1060 <close@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setGPIOPin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e54(%rip),%r13
mov    0x0(%r13),%esi
lea    0xe71(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11a7 <setGPIOPin+0x47>
lea    0xe75(%rip),%rdi
call   1040 <errExit@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe5a(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11f6 <setGPIOPin+0x96>
lea    0xe53(%rip),%rdi
call   1040 <errExit@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe3b(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1245 <setGPIOPin+0xe5>
lea    0xe30(%rip),%rdi
call   1040 <errExit@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe14(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1294 <setGPIOPin+0x134>
lea    0xe09(%rip),%rdi
call   1040 <errExit@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <close@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"GPIO Export\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%s/direction\00"
@.str.3 = [15 x i8] c"Gpio Direction\00"
@.str.4 = [29 x i8] c"/sys/class/gpio/gpio%s/drive\00"
@.str.5 = [11 x i8] c"Gpio Drive\00"
@.str.6 = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@.str.7 = [11 x i8] c"Gpio Value\00"
define void @setGPIOPin(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @errExit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
%18 = load i32, i32* %10
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
%23 = load i32, i32* %10
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* @O_WRONLY
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %17
%34 = call i32 @errExit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %17
%36 = load i32, i32* %10
%37 = load i8*, i8** %6
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @write(i32 %36, i8* %37, i32 %39)
%41 = load i32, i32* %10
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%44 = load i8*, i8** %5
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* @O_WRONLY
%48 = call i32 @open(i8* %46, i32 %47)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %35
%52 = call i32 @errExit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %35
%54 = load i32, i32* %10
%55 = load i8*, i8** %7
%56 = load i8*, i8** %7
%57 = call i32 @strlen(i8* %56)
%58 = call i32 @write(i32 %54, i8* %55, i32 %57)
%59 = load i32, i32* %10
%60 = call i32 @close(i32 %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%62 = load i8*, i8** %5
%63 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %62)
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%65 = load i32, i32* @O_WRONLY
%66 = call i32 @open(i8* %64, i32 %65)
store i32 %66, i32* %10
%67 = load i32, i32* %10
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %53
%70 = call i32 @errExit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %71
71: ; preds = %69, %53
%72 = load i32, i32* %10
%73 = load i8*, i8** %8
%74 = load i8*, i8** %8
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @write(i32 %72, i8* %73, i32 %75)
%77 = load i32, i32* %10
%78 = call i32 @close(i32 %77)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"GPIO Export\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%s/direction\00"
@.str.3 = [15 x i8] c"Gpio Direction\00"
@.str.4 = [29 x i8] c"/sys/class/gpio/gpio%s/drive\00"
@.str.5 = [11 x i8] c"Gpio Drive\00"
@.str.6 = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@.str.7 = [11 x i8] c"Gpio Value\00"
define void @setGPIOPin(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @errExit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @write(i32 %8, i8* %0, i32 %13)
%15 = tail call i32 @close(i32 %8)
%16 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* %6, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = tail call i32 @errExit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = tail call i32 @strlen(i8* %1)
%24 = tail call i32 @write(i32 %18, i8* %1, i32 %23)
%25 = tail call i32 @close(i32 %18)
%26 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%27 = load i32, i32* @O_WRONLY
%28 = call i32 @open(i8* %6, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = tail call i32 @errExit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %22
%33 = tail call i32 @strlen(i8* %2)
%34 = tail call i32 @write(i32 %28, i8* %2, i32 %33)
%35 = tail call i32 @close(i32 %28)
%36 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%37 = load i32, i32* @O_WRONLY
%38 = call i32 @open(i8* %6, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = tail call i32 @errExit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %42
42: ; preds = %40, %32
%43 = tail call i32 @strlen(i8* %3)
%44 = tail call i32 @write(i32 %38, i8* %3, i32 %43)
%45 = tail call i32 @close(i32 %38)
ret void
}