#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*/ closeConnections();
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int configurePinAsOutput(int aPin) {
  int fd;
  char buf[100];
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd < 1) {
    printf("Unable to export IO Pin: %d", aPin);
    closeConnections();
    exit(1);
  }
  sprintf(buf, "%d", aPin);
  write(fd, buf, strlen(buf));
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%d/direction", aPin);
  fd = open(buf, O_WRONLY);
  if (fd < 1) {
    printf("Unable to initialize IO Pin direction: %d", aPin);
    closeConnections();
    exit(1);
  }
  write(fd, "out", 3);
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%d/value", aPin);
  fd = open(buf, O_WRONLY);
  if (fd < 1) {
    printf("Unable to Initialize IO Pin Output to LOW: %d", aPin);
    closeConnections();
    exit(1);
  }
  write(fd, "0", 1);
  return fd;
}


x86 assembly (clang, -O0):
<configurePinAsOutput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11d0 <configurePinAsOutput+0x50>
mov    -0x4(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <closeConnections@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeec(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe15(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1262 <configurePinAsOutput+0xe2>
mov    -0x4(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <closeConnections@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xe12(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdf6(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2d3c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    12d0 <configurePinAsOutput+0x150>
mov    -0x4(%rbp),%esi
lea    0xde5(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <closeConnections@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xdf3(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configurePinAsOutput>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edi,%r14d
mov    0x2e44(%rip),%r15
mov    (%r15),%esi
lea    0xe62(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
jle    1260 <configurePinAsOutput+0xe0>
mov    %eax,%ebp
lea    0xf16(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
call   1090 <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   1070 <close@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1090 <sprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
jle    1269 <configurePinAsOutput+0xe9>
mov    %eax,%ebp
lea    0xe77(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe61(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
call   1090 <sprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
jle    1272 <configurePinAsOutput+0xf2>
mov    %eax,%ebp
lea    0xe86(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb0(%rip),%rdi
jmp    1279 <configurePinAsOutput+0xf9>
lea    0xde4(%rip),%rdi
jmp    1279 <configurePinAsOutput+0xf9>
lea    0xe26(%rip),%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <closeConnections@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [28 x i8] c"Unable to export IO Pin: %d\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.4 = [42 x i8] c"Unable to initialize IO Pin direction: %d\00"
@.str.5 = [4 x i8] c"out\00"
@.str.6 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@.str.7 = [46 x i8] c"Unable to Initialize IO Pin Output to LOW: %d\00"
@.str.8 = [2 x i8] c"0\00"
define i32 @configurePinAsOutput(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 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 = load i32, i32* %3
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @closeConnections()
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* %2
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %3
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* %2
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%29 = load i32, i32* @O_WRONLY
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %38
33: ; preds = %14
%34 = load i32, i32* %2
%35 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = call i32 (...) @closeConnections()
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %14
%39 = load i32, i32* %3
%40 = call i32 @write(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%41 = load i32, i32* %3
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%44 = load i32, i32* %2
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%47 = load i32, i32* @O_WRONLY
%48 = call i32 @open(i8* %46, i32 %47)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp slt i32 %49, 1
br i1 %50, label %51, label %56
51: ; preds = %38
%52 = load i32, i32* %2
%53 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = call i32 (...) @closeConnections()
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %38
%57 = load i32, i32* %3
%58 = call i32 @write(i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [28 x i8] c"Unable to export IO Pin: %d\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.4 = [42 x i8] c"Unable to initialize IO Pin direction: %d\00"
@.str.5 = [4 x i8] c"out\00"
@.str.6 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@.str.7 = [46 x i8] c"Unable to Initialize IO Pin Output to LOW: %d\00"
@.str.8 = [2 x i8] c"0\00"
define i32 @configurePinAsOutput(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 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 = icmp slt i32 %5, 1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%9 = tail call i32 (...) @closeConnections()
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%13 = call i32 @strlen(i8* %3)
%14 = call i32 @write(i32 %5, i8* %3, i32 %13)
%15 = call i32 @close(i32 %5)
%16 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* %3, i32 %17)
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%22 = call i32 (...) @closeConnections()
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %11
%25 = call i32 @write(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%26 = call i32 @close(i32 %18)
%27 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %0)
%28 = load i32, i32* @O_WRONLY
%29 = call i32 @open(i8* %3, i32 %28)
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %0)
%33 = call i32 (...) @closeConnections()
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %24
%36 = call i32 @write(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
ret i32 %29
}