#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 */
typedef int /*<<< orphan*/ b;

/* Variables and functions */
int LOG_DAEMON;
int LOG_ERR;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ pwrite(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ syslog(int, char *, ...);
int init_pin(int pin, int *value_fd) {
  int fd;
  char b[64];
  if (pin == 0) {
    value_fd = 0;
    return 0;
  }
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd < 0) {
    perror("/sys/class/gpio/export");
    return 1;
  }
  snprintf(b, sizeof(b), "%d", pin);
  if (pwrite(fd, b, strlen(b), 0) < 0) {
    syslog(LOG_DAEMON | LOG_ERR,
           "Unable to export pin=%d (already in use?): %s\n", pin,
           strerror(errno));
    return 2;
  }
  close(fd);
  snprintf(b, sizeof(b), "%s%d/edge", "/sys/class/gpio/gpio", pin);
  fd = open(b, O_RDWR);
  if (fd < 0) {
    syslog(LOG_DAEMON | LOG_ERR, "Open %s: %s\n", b, strerror(errno));
    return 3;
  }
  if (pwrite(fd, "both", 4, 0) < 0) {
    syslog(LOG_DAEMON | LOG_ERR, "Unable to write 'both' to %s: %s\n", b,
           strerror(errno));
    return 4;
  }
  close(fd);
  snprintf(b, sizeof(b), "%s%d/direction", "/sys/class/gpio/gpio", pin);
  fd = open(b, O_RDWR);
  if (fd < 0) {
    syslog(LOG_DAEMON | LOG_ERR, "Open %s: %s\n", b, strerror(errno));
    return 5;
  }
  if (pwrite(fd, "in", 2, 0) < 0) {
    syslog(LOG_DAEMON | LOG_ERR, "Unable to write 'in' to %s: %s\n", b,
           strerror(errno));
    return 6;
  }
  close(fd);
  snprintf(b, sizeof(b), "%s%d/value", "/sys/class/gpio/gpio", pin);
  fd = open(b, O_RDWR);
  if (fd < 0) {
    syslog(LOG_DAEMON | LOG_ERR, "Open %s: %s\n", b, strerror(errno));
    return 7;
  }
  *value_fd = fd;
  return 0;
}


x86 assembly (clang, -O0):
<init_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11b0 <init_pin+0x30>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    0xe40(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ea <init_pin+0x6a>
lea    0xe27(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x40,%esi
lea    0xe1a(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <pwrite@plt>
cmp    $0x0,%rax
jge    1280 <init_pin+0x100>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    0x2d73(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%edx
mov    %eax,%ecx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x2,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%r8d
mov    $0x40,%esi
lea    0xdad(%rip),%rdx
lea    0xdb0(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    131d <init_pin+0x19d>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    0x2cdf(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x84(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %eax,%ecx
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x3,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    -0x14(%rbp),%edi
lea    0xd4e(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <pwrite@plt>
cmp    $0x0,%rax
jge    1397 <init_pin+0x217>
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    0x2c6b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x94(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rdx
mov    %eax,%ecx
lea    0xcf6(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x4,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%r8d
mov    $0x40,%esi
lea    0xce9(%rip),%rdx
lea    0xc99(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2c1c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    143a <init_pin+0x2ba>
mov    0x2bf9(%rip),%rax
mov    (%rax),%eax
mov    0x2bc8(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xa4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rdx
mov    %eax,%ecx
lea    0xc41(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x5,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    -0x14(%rbp),%edi
lea    0xc67(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1070 <pwrite@plt>
cmp    $0x0,%rax
jge    14b4 <init_pin+0x334>
mov    0x2b7f(%rip),%rax
mov    (%rax),%eax
mov    0x2b4e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xb4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rdx
mov    %eax,%ecx
lea    0xc0d(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x6,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%r8d
mov    $0x40,%esi
lea    0xbfe(%rip),%rdx
lea    0xb7c(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2aff(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1557 <init_pin+0x3d7>
mov    0x2adc(%rip),%rax
mov    (%rax),%eax
mov    0x2aab(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2aa9(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rdx
mov    %eax,%ecx
lea    0xb24(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x7,-0x4(%rbp)
jmp    1567 <init_pin+0x3e7>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_pin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
test   %edi,%edi
je     1304 <init_pin+0x184>
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1402 <init_pin+0x282>
mov    %eax,%ebp
lea    0xe57(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <pwrite@plt>
test   %rax,%rax
js     130b <init_pin+0x18b>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe47(%rip),%rdx
lea    0xe4a(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    0x2dc3(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     134a <init_pin+0x1ca>
mov    %eax,%ebx
lea    0xe33(%rip),%rsi
mov    $0x4,%ebp
mov    %eax,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <pwrite@plt>
test   %rax,%rax
js     1389 <init_pin+0x209>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe30(%rip),%rdx
lea    0xde0(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     13c3 <init_pin+0x243>
mov    %eax,%ebx
lea    0xe06(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1070 <pwrite@plt>
test   %rax,%rax
js     1415 <init_pin+0x295>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe04(%rip),%rdx
lea    0xd82(%rip),%rcx
xor    %ebp,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1451 <init_pin+0x2d1>
mov    %eax,(%r14)
jmp    148b <init_pin+0x30b>
xor    %ebp,%ebp
jmp    148b <init_pin+0x30b>
mov    0x2cce(%rip),%rax
mov    0x2c9f(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xce8(%rip),%rsi
mov    %ebx,%edi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x2,%ebp
jmp    148b <init_pin+0x30b>
mov    0x2c8f(%rip),%rax
mov    0x2c60(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcf7(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x3,%ebp
jmp    148b <init_pin+0x30b>
mov    0x2c50(%rip),%rax
mov    0x2c21(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcca(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
jmp    148b <init_pin+0x30b>
mov    0x2c16(%rip),%rax
mov    0x2be7(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc7e(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x5,%ebp
jmp    148b <init_pin+0x30b>
lea    0xbf7(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebp
jmp    148b <init_pin+0x30b>
mov    0x2bc4(%rip),%rax
mov    0x2b95(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc72(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x6,%ebp
jmp    148b <init_pin+0x30b>
mov    0x2b88(%rip),%rax
mov    0x2b59(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xbf0(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x7,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
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"
@LOG_DAEMON = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [47 x i8] c"Unable to export pin=%d (already in use?): %s\0A\00"
@errno = global i32 0
@.str.3 = [10 x i8] c"%s%d/edge\00"
@.str.4 = [21 x i8] c"/sys/class/gpio/gpio\00"
@O_RDWR = global i32 0
@.str.5 = [13 x i8] c"Open %s: %s\0A\00"
@.str.6 = [5 x i8] c"both\00"
@.str.7 = [34 x i8] c"Unable to write 'both' to %s: %s\0A\00"
@.str.8 = [15 x i8] c"%s%d/direction\00"
@.str.9 = [3 x i8] c"in\00"
@.str.10 = [32 x i8] c"Unable to write 'in' to %s: %s\0A\00"
@.str.11 = [11 x i8] c"%s%d/value\00"
define i32 @init_pin(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [64 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32* null, i32** %5
store i32 0, i32* %3
br label %120
11: ; preds = %2
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %120
18: ; preds = %11
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %4
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %19, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %6
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i64 @pwrite(i32 %22, i8* %23, i32 %25, i32 0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %18
%29 = load i32, i32* @LOG_DAEMON
%30 = load i32, i32* @LOG_ERR
%31 = or i32 %29, %30
%32 = load i32, i32* %4
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 (i32, i8*, ...) @syslog(i32 %31, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %34)
store i32 2, i32* %3
br label %120
36: ; preds = %18
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%40 = load i32, i32* %4
%41 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %39, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%43 = load i32, i32* @O_RDWR
%44 = call i32 @open(i8* %42, i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %36
%48 = load i32, i32* @LOG_DAEMON
%49 = load i32, i32* @LOG_ERR
%50 = or i32 %48, %49
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%52 = load i32, i32* @errno
%53 = call i32 @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @syslog(i32 %50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %51, i32 %53)
store i32 3, i32* %3
br label %120
55: ; preds = %36
%56 = load i32, i32* %6
%57 = call i64 @pwrite(i32 %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4, i32 0)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %55
%60 = load i32, i32* @LOG_DAEMON
%61 = load i32, i32* @LOG_ERR
%62 = or i32 %60, %61
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%64 = load i32, i32* @errno
%65 = call i32 @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @syslog(i32 %62, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %63, i32 %65)
store i32 4, i32* %3
br label %120
67: ; preds = %55
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
%70 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%71 = load i32, i32* %4
%72 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %70, i32 64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%74 = load i32, i32* @O_RDWR
%75 = call i32 @open(i8* %73, i32 %74)
store i32 %75, i32* %6
%76 = load i32, i32* %6
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %86
78: ; preds = %67
%79 = load i32, i32* @LOG_DAEMON
%80 = load i32, i32* @LOG_ERR
%81 = or i32 %79, %80
%82 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%83 = load i32, i32* @errno
%84 = call i32 @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @syslog(i32 %81, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %82, i32 %84)
store i32 5, i32* %3
br label %120
86: ; preds = %67
%87 = load i32, i32* %6
%88 = call i64 @pwrite(i32 %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2, i32 0)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %98
90: ; preds = %86
%91 = load i32, i32* @LOG_DAEMON
%92 = load i32, i32* @LOG_ERR
%93 = or i32 %91, %92
%94 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%95 = load i32, i32* @errno
%96 = call i32 @strerror(i32 %95)
%97 = call i32 (i32, i8*, ...) @syslog(i32 %93, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %94, i32 %96)
store i32 6, i32* %3
br label %120
98: ; preds = %86
%99 = load i32, i32* %6
%100 = call i32 @close(i32 %99)
%101 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%102 = load i32, i32* %4
%103 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %101, i32 64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %102)
%104 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%105 = load i32, i32* @O_RDWR
%106 = call i32 @open(i8* %104, i32 %105)
store i32 %106, i32* %6
%107 = load i32, i32* %6
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %117
109: ; preds = %98
%110 = load i32, i32* @LOG_DAEMON
%111 = load i32, i32* @LOG_ERR
%112 = or i32 %110, %111
%113 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%114 = load i32, i32* @errno
%115 = call i32 @strerror(i32 %114)
%116 = call i32 (i32, i8*, ...) @syslog(i32 %112, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %113, i32 %115)
store i32 7, i32* %3
br label %120
117: ; preds = %98
%118 = load i32, i32* %6
%119 = load i32*, i32** %5
store i32 %118, i32* %119
store i32 0, i32* %3
br label %120
120: ; preds = %117, %109, %90, %78, %59, %47, %28, %16, %10
%121 = load i32, i32* %3
ret i32 %121
}

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"
@LOG_DAEMON = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [47 x i8] c"Unable to export pin=%d (already in use?): %s\0A\00"
@errno = global i32 0
@.str.3 = [10 x i8] c"%s%d/edge\00"
@.str.4 = [21 x i8] c"/sys/class/gpio/gpio\00"
@O_RDWR = global i32 0
@.str.5 = [13 x i8] c"Open %s: %s\0A\00"
@.str.6 = [5 x i8] c"both\00"
@.str.7 = [34 x i8] c"Unable to write 'both' to %s: %s\0A\00"
@.str.8 = [15 x i8] c"%s%d/direction\00"
@.str.9 = [3 x i8] c"in\00"
@.str.10 = [32 x i8] c"Unable to write 'in' to %s: %s\0A\00"
@.str.11 = [11 x i8] c"%s%d/value\00"
define i32 @init_pin(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 0
br i1 %5, label %84, label %6
6: ; preds = %2
%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 slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %84
12: ; preds = %6
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%14 = call i32 @strlen(i8* %4)
%15 = call i64 @pwrite(i32 %8, i8* %4, i32 %14, i32 0)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* @LOG_DAEMON
%19 = load i32, i32* @LOG_ERR
%20 = or i32 %19, %18
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @syslog(i32 %20, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %22)
br label %84
24: ; preds = %12
%25 = call i32 @close(i32 %8)
%26 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* %4, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load i32, i32* @LOG_DAEMON
%32 = load i32, i32* @LOG_ERR
%33 = or i32 %32, %31
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @syslog(i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %4, i32 %35)
br label %84
37: ; preds = %24
%38 = call i64 @pwrite(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* @LOG_DAEMON
%42 = load i32, i32* @LOG_ERR
%43 = or i32 %42, %41
%44 = load i32, i32* @errno
%45 = call i32 @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @syslog(i32 %43, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %4, i32 %45)
br label %84
47: ; preds = %37
%48 = call i32 @close(i32 %28)
%49 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%50 = load i32, i32* @O_RDWR
%51 = call i32 @open(i8* %4, i32 %50)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %47
%54 = load i32, i32* @LOG_DAEMON
%55 = load i32, i32* @LOG_ERR
%56 = or i32 %55, %54
%57 = load i32, i32* @errno
%58 = call i32 @strerror(i32 %57)
%59 = call i32 (i32, i8*, ...) @syslog(i32 %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %4, i32 %58)
br label %84
60: ; preds = %47
%61 = call i64 @pwrite(i32 %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2, i32 0)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %60
%64 = load i32, i32* @LOG_DAEMON
%65 = load i32, i32* @LOG_ERR
%66 = or i32 %65, %64
%67 = load i32, i32* @errno
%68 = call i32 @strerror(i32 %67)
%69 = call i32 (i32, i8*, ...) @syslog(i32 %66, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %4, i32 %68)
br label %84
70: ; preds = %60
%71 = call i32 @close(i32 %51)
%72 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%73 = load i32, i32* @O_RDWR
%74 = call i32 @open(i8* %4, i32 %73)
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %83
76: ; preds = %70
%77 = load i32, i32* @LOG_DAEMON
%78 = load i32, i32* @LOG_ERR
%79 = or i32 %78, %77
%80 = load i32, i32* @errno
%81 = call i32 @strerror(i32 %80)
%82 = call i32 (i32, i8*, ...) @syslog(i32 %79, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %4, i32 %81)
br label %84
83: ; preds = %70
store i32 %74, i32* %1
br label %84
84: ; preds = %2, %83, %76, %63, %53, %40, %30, %17, %10
%85 = phi i32 [ 1, %10 ], [ 2, %17 ], [ 3, %30 ], [ 4, %40 ], [ 5, %53 ], [ 6, %63 ], [ 7, %76 ], [ 0, %83 ], [ 0, %2 ]
ret i32 %85
}