#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 */
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int atoi(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, int *, int /*<<< orphan*/);
int /*<<< orphan*/ gpioCleanup();
int gpioGet(int);
int /*<<< orphan*/ gpioInit();
int /*<<< orphan*/ gpioSet(int, int);
int /*<<< orphan*/ gpioSetDir(int, int);
int /*<<< orphan*/ printf(char *, ...);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char **argv) {
  int i, j;
  int gpio[128];
  int oldstate[128], state[128];
  int ngpios;
  struct timeval tv;
  fd_set read_fd;
  char *str = NULL;
  int lenStr = 0;
  ngpios = argc - 1;
  for (i = 0; i < 128; i++)
    gpio[i] = -1;
  for (i = 0; i < ngpios; i++) {
    j = atoi(argv[i + 1]);
    gpio[i] = j;
    oldstate[i] = -1;
  }
  gpioInit();
  do {
    tv.tv_sec = 0;
    tv.tv_usec = 1000;
    FD_ZERO(&read_fd);
    FD_SET(0, &read_fd);
    if (select(1, &read_fd, NULL, NULL, &tv) == -1)
      return 0;
    if (FD_ISSET(0, &read_fd)) {
      getline(&str, &lenStr, stdin);
      i = strlen(str);
      if (str[i - 1] == '\n')
        str[i - 1] = 0x00;
      if (str == NULL)
        break;
      if (str[0] == 'q')
        break;
      else if (str[0] == 'o') {
        printf("GPIO #:");
        getline(&str, &lenStr, stdin);
        i = atoi(str);
        if (i >= 0 && i < 128)
          gpioSetDir(i, 1);
        printf("%i --> output\n", i);
      } else if (str[0] == 'i') {
        printf("GPIO #:");
        getline(&str, &lenStr, stdin);
        i = atoi(str);
        if (i >= 0 && i < 128)
          gpioSetDir(i, 0);
        printf("%i --> input\n", i);
      } else if (str[0] >= '0' && str[0] <= '9') {
        i = atoi(str);
        if (i >= 0 && i < 128) {
          j = gpioGet(i);
          printf("%i: %i --> %i\n", i, j, !j);
          gpioSet(i, !j);
        }
      }
    }
    for (i = 0; i < ngpios; i++) {
      state[i] = gpioGet(gpio[i]);
      if (state[i] != oldstate[i])
        printf("%i: %i --> %i\n", gpio[i], oldstate[i], state[i]);
      oldstate[i] = state[i];
    }
  } while (1);
  gpioCleanup();
  if (str != NULL)
    free(str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x648(%rbp)
movl   $0x0,-0x64c(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x624(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    124b <main+0x6b>
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0x220(%rbp,%rax,4)
ff ff ff ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1221 <main+0x41>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x624(%rbp),%eax
jge    12a5 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x220(%rbp,%rax,4)
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0x420(%rbp,%rax,4)
ff ff ff ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1252 <main+0x72>
mov    $0x0,%al
call   1080 <gpioInit@plt>
movq   $0x0,-0x630(%rbp)
movl   $0x3e8,-0x638(%rbp)
lea    -0x63c(%rbp),%rdi
call   1090 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x63c(%rbp),%rsi
call   10f0 <FD_SET@plt>
mov    $0x1,%edi
lea    -0x63c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x638(%rbp),%r8
mov    %rcx,%rdx
call   10a0 <select@plt>
cmp    $0xffffffff,%eax
jne    130f <main+0x12f>
movl   $0x0,-0x4(%rbp)
jmp    163d <main+0x45d>
xor    %edi,%edi
lea    -0x63c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     155f <main+0x37f>
mov    0x2cba(%rip),%rax
mov    (%rax),%edx
lea    -0x648(%rbp),%rdi
lea    -0x64c(%rbp),%rsi
call   10e0 <getline@plt>
mov    -0x648(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x648(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1383 <main+0x1a3>
mov    -0x648(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x648(%rbp)
jne    1396 <main+0x1b6>
jmp    1615 <main+0x435>
mov    -0x648(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
jne    13ae <main+0x1ce>
jmp    1615 <main+0x435>
mov    -0x648(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6f,%eax
jne    1434 <main+0x254>
lea    0xc38(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c12(%rip),%rax
mov    (%rax),%edx
lea    -0x648(%rbp),%rdi
lea    -0x64c(%rbp),%rsi
call   10e0 <getline@plt>
mov    -0x648(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     141e <main+0x23e>
cmpl   $0x80,-0x14(%rbp)
jge    141e <main+0x23e>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1100 <gpioSetDir@plt>
mov    -0x14(%rbp),%esi
lea    0xbe0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1555 <main+0x375>
mov    -0x648(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x69,%eax
jne    14b7 <main+0x2d7>
lea    0xbb2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edx
lea    -0x648(%rbp),%rdi
lea    -0x64c(%rbp),%rsi
call   10e0 <getline@plt>
mov    -0x648(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     14a1 <main+0x2c1>
cmpl   $0x80,-0x14(%rbp)
jge    14a1 <main+0x2c1>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1100 <gpioSetDir@plt>
mov    -0x14(%rbp),%esi
lea    0xb6c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1550 <main+0x370>
mov    -0x648(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     154b <main+0x36b>
mov    -0x648(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     154b <main+0x36b>
mov    -0x648(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1546 <main+0x366>
cmpl   $0x80,-0x14(%rbp)
jge    1546 <main+0x366>
mov    -0x14(%rbp),%edi
call   10c0 <gpioGet@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
lea    0xafc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
call   1050 <gpioSet@plt>
jmp    154b <main+0x36b>
jmp    1550 <main+0x370>
jmp    1555 <main+0x375>
jmp    155a <main+0x37a>
jmp    155f <main+0x37f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x624(%rbp),%eax
jge    1601 <main+0x421>
movslq -0x14(%rbp),%rax
mov    -0x220(%rbp,%rax,4),%edi
call   10c0 <gpioGet@plt>
mov    %eax,%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x620(%rbp,%rax,4)
movslq -0x14(%rbp),%rax
mov    -0x620(%rbp,%rax,4),%eax
movslq -0x14(%rbp),%rcx
cmp    -0x420(%rbp,%rcx,4),%eax
je     15dd <main+0x3fd>
movslq -0x14(%rbp),%rax
mov    -0x220(%rbp,%rax,4),%esi
movslq -0x14(%rbp),%rax
mov    -0x420(%rbp,%rax,4),%edx
movslq -0x14(%rbp),%rax
mov    -0x620(%rbp,%rax,4),%ecx
lea    0xa4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x14(%rbp),%rax
mov    -0x620(%rbp,%rax,4),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x420(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1566 <main+0x386>
jmp    1606 <main+0x426>
mov    $0x1,%al
test   $0x1,%al
jne    12ac <main+0xcc>
jmp    1615 <main+0x435>
mov    $0x0,%al
call   10b0 <gpioCleanup@plt>
cmpq   $0x0,-0x648(%rbp)
je     1636 <main+0x456>
mov    -0x648(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
movq   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
lea    0x230(%rsp),%rdi
mov    $0x200,%edx
mov    $0xff,%esi
call   1080 <memset@plt>
lea    -0x1(%rbx),%eax
mov    %eax,%r14d
mov    %rbx,0x28(%rsp)
cmp    $0x2,%ebx
jl     127d <main+0x8d>
lea    0x0(,%r14,4),%rdx
lea    0x30(%rsp),%rdi
mov    $0xff,%esi
call   1080 <memset@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbp),%rbx
mov    0x8(%r15,%rbp,8),%rdi
call   10e0 <atoi@plt>
mov    %eax,0x230(%rsp,%rbp,4)
mov    %rbx,%rbp
cmp    %rbx,%r14
jne    1260 <main+0x70>
xor    %eax,%eax
call   1090 <gpioInit@plt>
movq   $0x0,0x20(%rsp)
movl   $0x3e8,0x18(%rsp)
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1100 <FD_SET@plt>
lea    0x18(%rsp),%r8
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10b0 <select@plt>
cmp    $0xffffffff,%eax
je     14f2 <main+0x302>
lea    0x14(%rsp),%r15
lea    0xd4e(%rip),%r13
jmp    1322 <main+0x132>
nopl   0x0(%rax)
movq   $0x0,0x20(%rsp)
movl   $0x3e8,0x18(%rsp)
mov    %r15,%rdi
call   10a0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1100 <FD_SET@plt>
mov    $0x1,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x18(%rsp),%r8
call   10b0 <select@plt>
cmp    $0xffffffff,%eax
je     14f2 <main+0x302>
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1483 <main+0x293>
mov    0x2cac(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10f0 <getline@plt>
mov    0x8(%rsp),%rdi
call   1060 <strlen@plt>
mov    0x8(%rsp),%rdi
cltq
cmpb   $0xa,-0x1(%rax,%rdi,1)
jne    1378 <main+0x188>
movb   $0x0,-0x1(%rdi,%rax,1)
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     14dc <main+0x2ec>
mov    (%rdi),%al
cmp    $0x69,%al
je     13e0 <main+0x1f0>
cmp    $0x6f,%al
je     1430 <main+0x240>
cmp    $0x71,%al
je     14dc <main+0x2ec>
add    $0xd0,%al
cmp    $0x9,%al
ja     1483 <main+0x293>
call   10e0 <atoi@plt>
cmp    $0x7f,%eax
ja     1483 <main+0x293>
mov    %eax,%r12d
mov    %eax,%edi
call   10d0 <gpioGet@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %r13,%rdi
mov    %r12d,%esi
mov    %eax,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
mov    %ebx,%esi
call   1050 <gpioSet@plt>
jmp    1483 <main+0x293>
nopw   0x0(%rax,%rax,1)
lea    0xc19(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10f0 <getline@plt>
mov    0x8(%rsp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
cmp    $0x7f,%eax
ja     1420 <main+0x230>
mov    %ebp,%edi
xor    %esi,%esi
call   1110 <gpioSetDir@plt>
lea    0xbf0(%rip),%rdi
jmp    147a <main+0x28a>
nopl   0x0(%rax)
lea    0xbc9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ba3(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10f0 <getline@plt>
mov    0x8(%rsp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
cmp    $0x7f,%eax
ja     1473 <main+0x283>
mov    %ebp,%edi
mov    $0x1,%esi
call   1110 <gpioSetDir@plt>
lea    0xb8e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x2,0x28(%rsp)
jl     12e0 <main+0xf0>
xor    %ebx,%ebx
jmp    14b1 <main+0x2c1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,0x30(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
je     12e0 <main+0xf0>
mov    0x230(%rsp,%rbx,4),%r12d
mov    %r12d,%edi
call   10d0 <gpioGet@plt>
mov    %eax,%ebp
mov    0x30(%rsp,%rbx,4),%edx
cmp    %edx,%eax
je     14a0 <main+0x2b0>
mov    %r13,%rdi
mov    %r12d,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    14a0 <main+0x2b0>
xor    %eax,%eax
call   10c0 <gpioCleanup@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     14f2 <main+0x302>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@stdin = global i32 0
@.str = [8 x i8] c"GPIO #:\00"
@.str.1 = [15 x i8] c"%i --> output\0A\00"
@.str.2 = [14 x i8] c"%i --> input\0A\00"
@.str.3 = [15 x i8] c"%i: %i --> %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i32]
%9 = alloca [128 x i32]
%10 = alloca [128 x i32]
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %14
store i32 0, i32* %15
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %11
store i32 0, i32* %6
br label %18
18: ; preds = %25, %2
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 128
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [128 x i32], [128 x i32]* %8, i64 0, i64 %23
store i32 -1, i32* %24
br label %25
25: ; preds = %21
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %18
28: ; preds = %18
store i32 0, i32* %6
br label %29
29: ; preds = %48, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %11
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %51
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [128 x i32], [128 x i32]* %8, i64 0, i64 %43
store i32 %41, i32* %44
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [128 x i32], [128 x i32]* %9, i64 0, i64 %46
store i32 -1, i32* %47
br label %48
48: ; preds = %33
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %29
51: ; preds = %29
%52 = call i32 (...) @gpioInit()
br label %53
53: ; preds = %230, %51
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %54
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 1000, i32* %55
%56 = call i32 @FD_ZERO(i32* %13)
%57 = call i32 @FD_SET(i32 0, i32* %13)
%58 = call i32 @select(i32 1, i32* %13, i32* null, i32* null, %struct.timeval* %12)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %61
60: ; preds = %53
store i32 0, i32* %3
br label %239
61: ; preds = %53
%62 = call i64 @FD_ISSET(i32 0, i32* %13)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %181
64: ; preds = %61
%65 = load i32, i32* @stdin
%66 = call i32 @getline(i8** %14, i32* %15, i32 %65)
%67 = load i8*, i8** %14
%68 = call i32 @strlen(i8* %67)
store i32 %68, i32* %6
%69 = load i8*, i8** %14
%70 = load i32, i32* %6
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 10
br i1 %76, label %77, label %83
77: ; preds = %64
%78 = load i8*, i8** %14
%79 = load i32, i32* %6
%80 = sub nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %78, i64 %81
store i8 0, i8* %82
br label %83
83: ; preds = %77, %64
%84 = load i8*, i8** %14
%85 = icmp eq i8* %84, null
br i1 %85, label %86, label %87
86: ; preds = %83
br label %231
87: ; preds = %83
%88 = load i8*, i8** %14
%89 = getelementptr inbounds i8, i8* %88, i64 0
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 113
br i1 %92, label %93, label %94
93: ; preds = %87
br label %231
94: ; preds = %87
%95 = load i8*, i8** %14
%96 = getelementptr inbounds i8, i8* %95, i64 0
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp eq i32 %98, 111
br i1 %99, label %100, label %117
100: ; preds = %94
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%102 = load i32, i32* @stdin
%103 = call i32 @getline(i8** %14, i32* %15, i32 %102)
%104 = load i8*, i8** %14
%105 = call i32 @atoi(i8* %104)
store i32 %105, i32* %6
%106 = load i32, i32* %6
%107 = icmp sge i32 %106, 0
br i1 %107, label %108, label %114
108: ; preds = %100
%109 = load i32, i32* %6
%110 = icmp slt i32 %109, 128
br i1 %110, label %111, label %114
111: ; preds = %108
%112 = load i32, i32* %6
%113 = call i32 @gpioSetDir(i32 %112, i32 1)
br label %114
114: ; preds = %111, %108, %100
%115 = load i32, i32* %6
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %115)
br label %179
117: ; preds = %94
%118 = load i8*, i8** %14
%119 = getelementptr inbounds i8, i8* %118, i64 0
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp eq i32 %121, 105
br i1 %122, label %123, label %140
123: ; preds = %117
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%125 = load i32, i32* @stdin
%126 = call i32 @getline(i8** %14, i32* %15, i32 %125)
%127 = load i8*, i8** %14
%128 = call i32 @atoi(i8* %127)
store i32 %128, i32* %6
%129 = load i32, i32* %6
%130 = icmp sge i32 %129, 0
br i1 %130, label %131, label %137
131: ; preds = %123
%132 = load i32, i32* %6
%133 = icmp slt i32 %132, 128
br i1 %133, label %134, label %137
134: ; preds = %131
%135 = load i32, i32* %6
%136 = call i32 @gpioSetDir(i32 %135, i32 0)
br label %137
137: ; preds = %134, %131, %123
%138 = load i32, i32* %6
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %138)
br label %178
140: ; preds = %117
%141 = load i8*, i8** %14
%142 = getelementptr inbounds i8, i8* %141, i64 0
%143 = load i8, i8* %142
%144 = sext i8 %143 to i32
%145 = icmp sge i32 %144, 48
br i1 %145, label %146, label %177
146: ; preds = %140
%147 = load i8*, i8** %14
%148 = getelementptr inbounds i8, i8* %147, i64 0
%149 = load i8, i8* %148
%150 = sext i8 %149 to i32
%151 = icmp sle i32 %150, 57
br i1 %151, label %152, label %177
152: ; preds = %146
%153 = load i8*, i8** %14
%154 = call i32 @atoi(i8* %153)
store i32 %154, i32* %6
%155 = load i32, i32* %6
%156 = icmp sge i32 %155, 0
br i1 %156, label %157, label %176
157: ; preds = %152
%158 = load i32, i32* %6
%159 = icmp slt i32 %158, 128
br i1 %159, label %160, label %176
160: ; preds = %157
%161 = load i32, i32* %6
%162 = call i32 @gpioGet(i32 %161)
store i32 %162, i32* %7
%163 = load i32, i32* %6
%164 = load i32, i32* %7
%165 = load i32, i32* %7
%166 = icmp ne i32 %165, 0
%167 = xor i1 %166, true
%168 = zext i1 %167 to i32
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %163, i32 %164, i32 %168)
%170 = load i32, i32* %6
%171 = load i32, i32* %7
%172 = icmp ne i32 %171, 0
%173 = xor i1 %172, true
%174 = zext i1 %173 to i32
%175 = call i32 @gpioSet(i32 %170, i32 %174)
br label %176
176: ; preds = %160, %157, %152
br label %177
177: ; preds = %176, %146, %140
br label %178
178: ; preds = %177, %137
br label %179
179: ; preds = %178, %114
br label %180
180: ; preds = %179
br label %181
181: ; preds = %180, %61
store i32 0, i32* %6
br label %182
182: ; preds = %226, %181
%183 = load i32, i32* %6
%184 = load i32, i32* %11
%185 = icmp slt i32 %183, %184
br i1 %185, label %186, label %229
186: ; preds = %182
%187 = load i32, i32* %6
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds [128 x i32], [128 x i32]* %8, i64 0, i64 %188
%190 = load i32, i32* %189
%191 = call i32 @gpioGet(i32 %190)
%192 = load i32, i32* %6
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [128 x i32], [128 x i32]* %10, i64 0, i64 %193
store i32 %191, i32* %194
%195 = load i32, i32* %6
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds [128 x i32], [128 x i32]* %10, i64 0, i64 %196
%198 = load i32, i32* %197
%199 = load i32, i32* %6
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds [128 x i32], [128 x i32]* %9, i64 0, i64 %200
%202 = load i32, i32* %201
%203 = icmp ne i32 %198, %202
br i1 %203, label %204, label %218
204: ; preds = %186
%205 = load i32, i32* %6
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds [128 x i32], [128 x i32]* %8, i64 0, i64 %206
%208 = load i32, i32* %207
%209 = load i32, i32* %6
%210 = sext i32 %209 to i64
%211 = getelementptr inbounds [128 x i32], [128 x i32]* %9, i64 0, i64 %210
%212 = load i32, i32* %211
%213 = load i32, i32* %6
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds [128 x i32], [128 x i32]* %10, i64 0, i64 %214
%216 = load i32, i32* %215
%217 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %208, i32 %212, i32 %216)
br label %218
218: ; preds = %204, %186
%219 = load i32, i32* %6
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds [128 x i32], [128 x i32]* %10, i64 0, i64 %220
%222 = load i32, i32* %221
%223 = load i32, i32* %6
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds [128 x i32], [128 x i32]* %9, i64 0, i64 %224
store i32 %222, i32* %225
br label %226
226: ; preds = %218
%227 = load i32, i32* %6
%228 = add nsw i32 %227, 1
store i32 %228, i32* %6
br label %182
229: ; preds = %182
br label %230
230: ; preds = %229
br i1 true, label %53, label %231
231: ; preds = %230, %93, %86
%232 = call i32 (...) @gpioCleanup()
%233 = load i8*, i8** %14
%234 = icmp ne i8* %233, null
br i1 %234, label %235, label %238
235: ; preds = %231
%236 = load i8*, i8** %14
%237 = call i32 @free(i8* %236)
br label %238
238: ; preds = %235, %231
store i32 0, i32* %3
br label %239
239: ; preds = %238, %60
%240 = load i32, i32* %3
ret i32 %240
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@stdin = global i32 0
@.str = [8 x i8] c"GPIO #:\00"
@.str.1 = [15 x i8] c"%i --> output\0A\00"
@.str.2 = [14 x i8] c"%i --> input\0A\00"
@.str.3 = [15 x i8] c"%i: %i --> %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i32]
%4 = bitcast [128 x i32]* %3 to i8*
%5 = alloca [128 x i32]
%6 = bitcast [128 x i32]* %5 to i8*
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = bitcast %struct.timeval* %7 to i8*
%12 = bitcast i32* %8 to i8*
%13 = bitcast i8** %9 to i8*
store i8* null, i8** %9
%14 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%15 = add i32 %0, -1
%16 = icmp sgt i32 %0, 1
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = zext i32 %15 to i64
%19 = shl nuw nsw i64 %18, 2
br label %20
20: ; preds = %17, %20
%21 = phi i64 [ 0, %17 ], [ %22, %20 ]
%22 = add nuw nsw i64 %21, 1
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = getelementptr inbounds [128 x i32], [128 x i32]* %3, i64 0, i64 %21
store i32 %25, i32* %26
%27 = icmp eq i64 %22, %18
br i1 %27, label %28, label %20
28: ; preds = %20, %2
%29 = tail call i32 (...) @gpioInit()
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i64 0, i64* %30
store i32 1000, i32* %31
%32 = call i32 @FD_ZERO(i32* %8)
%33 = call i32 @FD_SET(i32 0, i32* %8)
%34 = call i32 @select(i32 1, i32* %8, i32* null, i32* null, %struct.timeval* %7)
%35 = icmp eq i32 %34, -1
br i1 %35, label %117, label %36
36: ; preds = %28
%37 = zext i32 %15 to i64
br label %43
38: ; preds = %108, %97
store i64 0, i64* %30
store i32 1000, i32* %31
%39 = call i32 @FD_ZERO(i32* %8)
%40 = call i32 @FD_SET(i32 0, i32* %8)
%41 = call i32 @select(i32 1, i32* %8, i32* null, i32* null, %struct.timeval* %7)
%42 = icmp eq i32 %41, -1
br i1 %42, label %117, label %43
43: ; preds = %36, %38
%44 = call i64 @FD_ISSET(i32 0, i32* %8)
%45 = icmp eq i64 %44, 0
br i1 %45, label %97, label %46
46: ; preds = %43
%47 = load i32, i32* @stdin
%48 = call i32 @getline(i8** %9, i32* %10, i32 %47)
%49 = load i8*, i8** %9
%50 = call i32 @strlen(i8* %49)
%51 = load i8*, i8** %9
%52 = add nsw i32 %50, -1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 10
br i1 %56, label %57, label %60
57: ; preds = %46
store i8 0, i8* %54
%58 = load i8*, i8** %9
%59 = icmp eq i8* %58, null
br i1 %59, label %111, label %60
60: ; preds = %46, %57
%61 = phi i8* [ %58, %57 ], [ %51, %46 ]
%62 = load i8, i8* %61
switch i8 %62, label %85 [
i8 113, label %111
i8 111, label %63
i8 105, label %74
]
63: ; preds = %60
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%65 = load i32, i32* @stdin
%66 = call i32 @getline(i8** %9, i32* %10, i32 %65)
%67 = load i8*, i8** %9
%68 = call i32 @atoi(i8* %67)
%69 = icmp ult i32 %68, 128
br i1 %69, label %70, label %72
70: ; preds = %63
%71 = call i32 @gpioSetDir(i32 %68, i32 1)
br label %72
72: ; preds = %70, %63
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %68)
br label %97
74: ; preds = %60
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%76 = load i32, i32* @stdin
%77 = call i32 @getline(i8** %9, i32* %10, i32 %76)
%78 = load i8*, i8** %9
%79 = call i32 @atoi(i8* %78)
%80 = icmp ult i32 %79, 128
br i1 %80, label %81, label %83
81: ; preds = %74
%82 = call i32 @gpioSetDir(i32 %79, i32 0)
br label %83
83: ; preds = %81, %74
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %79)
br label %97
85: ; preds = %60
%86 = add i8 %62, -48
%87 = icmp ult i8 %86, 10
br i1 %87, label %88, label %97
88: ; preds = %85
%89 = call i32 @atoi(i8* %61)
%90 = icmp ult i32 %89, 128
br i1 %90, label %91, label %97
91: ; preds = %88
%92 = call i32 @gpioGet(i32 %89)
%93 = icmp eq i32 %92, 0
%94 = zext i1 %93 to i32
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %89, i32 %92, i32 %94)
%96 = call i32 @gpioSet(i32 %89, i32 %94)
br label %97
97: ; preds = %83, %88, %91, %85, %72, %43
br i1 %16, label %98, label %38
98: ; preds = %97, %108
%99 = phi i64 [ %109, %108 ], [ 0, %97 ]
%100 = getelementptr inbounds [128 x i32], [128 x i32]* %3, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = call i32 @gpioGet(i32 %101)
%103 = getelementptr inbounds [128 x i32], [128 x i32]* %5, i64 0, i64 %99
%104 = load i32, i32* %103
%105 = icmp eq i32 %102, %104
br i1 %105, label %108, label %106
106: ; preds = %98
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %101, i32 %104, i32 %102)
br label %108
108: ; preds = %106, %98
store i32 %102, i32* %103
%109 = add nuw nsw i64 %99, 1
%110 = icmp eq i64 %109, %37
br i1 %110, label %38, label %98
111: ; preds = %60, %57
%112 = call i32 (...) @gpioCleanup()
%113 = load i8*, i8** %9
%114 = icmp eq i8* %113, null
br i1 %114, label %117, label %115
115: ; preds = %111
%116 = call i32 @free(i8* %113)
br label %117
117: ; preds = %38, %28, %111, %115
ret i32 0
}