#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 pollfd {
  int fd;
  int events;
  int revents;
};
typedef int /*<<< orphan*/ fdset;

/* Variables and functions */
int POLLPRI;
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ gpio_export(int);
int /*<<< orphan*/ gpio_fd_close(int);
int gpio_fd_open(int, char *);
int /*<<< orphan*/ gpio_get_value(int, char *, int *);
int /*<<< orphan*/ gpio_set_dir(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ gpio_set_edge(int, char *, char *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char **, int);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv, char **envp) {
  struct pollfd fdset[2];
  int nfds = 2;
  int gpio_fd11, gpio_fd10, timeout, rc;
  char *buf[64];
  unsigned int gpio;
  int gpio_value;
  int len;
  unsigned short count;
  if (argc < 2) {
    printf("Usage: gpio-int <gpio-pin>\n\n");
    printf(
        "Waits for a change in the GPIO pin voltage level or input on stdin\n");
    exit(-1);
  }
  gpio = atoi(argv[1]);
  gpio_export(11);
  gpio_export(10);
  gpio_set_dir(11, "ph15", 0);
  gpio_set_dir(10, "ph14", 0);
  gpio_set_edge(11, "ph15", "rising");
  gpio_set_edge(10, "ph14", "falling");
  gpio_fd11 = gpio_fd_open(11, "ph15");
  gpio_fd10 = gpio_fd_open(10, "ph14");
  gpio_value = 0;
  count = 0;
  timeout = (3 * 1000);
  while (1) {
    memset((void *)fdset, 0, sizeof(fdset));
    fdset[0].fd = gpio_fd10;
    fdset[0].events = POLLPRI;
    fdset[1].fd = gpio_fd11;
    fdset[1].events = POLLPRI;
    rc = poll(fdset, nfds, timeout);
    if (rc < 0) {
      printf("\npoll() failed!\n");
      return -1;
    }
    if (rc == 0) {
    }
    if (fdset[1].revents & POLLPRI) {
      len = read(fdset[1].fd, buf, 64);
      gpio_get_value(11, "ph15", &gpio_value);
      if (gpio_value == 1) {
        count++;
      }
      printf("\npoll() GPIO %d interrupt occurred with value %i\n", 11,
             gpio_value);
    }
    if (fdset[0].revents & POLLPRI) {
      len = read(fdset[0].fd, buf, 64);
      gpio_get_value(10, "ph14", &gpio_value);
      printf("\npoll() GPIO %d interrupt occurred with value %i\n", 10,
             gpio_value);
      if (gpio_value == 0 && count != 0) {
        printf("Count: %d\n", count);
        count = 0;
      }
    }
    fflush(stdout);
  }
  gpio_fd_close(gpio_fd11);
  gpio_fd_close(gpio_fd10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x2,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1214 <main+0x54>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x254(%rbp)
mov    $0xb,%edi
call   1050 <gpio_export@plt>
mov    $0xa,%edi
call   1050 <gpio_export@plt>
mov    $0xb,%edi
lea    0xe1a(%rip),%rsi
xor    %edx,%edx
call   1030 <gpio_set_dir@plt>
mov    $0xa,%edi
lea    0xe0c(%rip),%rsi
xor    %edx,%edx
call   1030 <gpio_set_dir@plt>
mov    $0xb,%edi
lea    0xdf4(%rip),%rsi
lea    0xdf7(%rip),%rdx
call   1090 <gpio_set_edge@plt>
mov    $0xa,%edi
lea    0xde1(%rip),%rsi
lea    0xde6(%rip),%rdx
call   1090 <gpio_set_edge@plt>
mov    $0xb,%edi
lea    0xdc4(%rip),%rsi
call   1080 <gpio_fd_open@plt>
mov    %eax,-0x38(%rbp)
mov    $0xa,%edi
lea    0xdb5(%rip),%rsi
call   1080 <gpio_fd_open@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x258(%rbp)
movw   $0x0,-0x25e(%rbp)
movl   $0xbb8,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%edx
call   10c0 <poll@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    133f <main+0x17f>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x260,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x44(%rbp)
jne    134e <main+0x18e>
jmp    134e <main+0x18e>
mov    -0x1c(%rbp),%eax
mov    0x2c98(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13cd <main+0x20d>
mov    -0x24(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0x40,%edx
call   10a0 <read@plt>
mov    %eax,-0x25c(%rbp)
mov    $0xb,%edi
lea    0xcd8(%rip),%rsi
lea    -0x258(%rbp),%rdx
call   1070 <gpio_get_value@plt>
cmpl   $0x1,-0x258(%rbp)
jne    13b4 <main+0x1f4>
mov    -0x25e(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x25e(%rbp)
mov    -0x258(%rbp),%edx
lea    0xcca(%rip),%rdi
mov    $0xb,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
mov    0x2c19(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     146d <main+0x2ad>
mov    -0x30(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0x40,%edx
call   10a0 <read@plt>
mov    %eax,-0x25c(%rbp)
mov    $0xa,%edi
lea    0xc5e(%rip),%rsi
lea    -0x258(%rbp),%rdx
call   1070 <gpio_get_value@plt>
mov    -0x258(%rbp),%edx
lea    0xc6a(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x258(%rbp)
jne    1468 <main+0x2a8>
movzwl -0x25e(%rbp),%eax
cmp    $0x0,%eax
je     1468 <main+0x2a8>
movzwl -0x25e(%rbp),%esi
lea    0xc65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movw   $0x0,-0x25e(%rbp)
jmp    146d <main+0x2ad>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
jmp    12d3 <main+0x113>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
cmp    $0x1,%edi
jle    1406 <main+0x246>
mov    $0xb,%edi
call   1060 <gpio_export@plt>
mov    $0xa,%edi
call   1060 <gpio_export@plt>
lea    0xe0b(%rip),%rbx
mov    $0xb,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <gpio_set_dir@plt>
lea    0xdfa(%rip),%rbp
mov    $0xa,%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1040 <gpio_set_dir@plt>
lea    0xde9(%rip),%rdx
mov    $0xb,%edi
mov    %rbx,%rsi
call   10a0 <gpio_set_edge@plt>
lea    0xddc(%rip),%rdx
mov    $0xa,%edi
mov    %rbp,%rsi
call   10a0 <gpio_set_edge@plt>
mov    $0xb,%edi
mov    %rbx,%rsi
call   1090 <gpio_fd_open@plt>
mov    %eax,%r14d
mov    $0xa,%edi
mov    %rbp,%rsi
call   1090 <gpio_fd_open@plt>
mov    %eax,%ebp
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    %ebp,0x10(%rsp)
mov    0x2d68(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    %r14d,0x1c(%rsp)
mov    %eax,0x20(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xbb8,%edx
call   10d0 <poll@plt>
test   %eax,%eax
js     13e3 <main+0x223>
lea    0x10(%rsp),%rbx
lea    0xd5b(%rip),%r12
xor    %r13d,%r13d
jmp    131b <main+0x15b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    %ebp,0x10(%rsp)
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    %r14d,0x1c(%rsp)
mov    %eax,0x20(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xbb8,%edx
call   10d0 <poll@plt>
test   %eax,%eax
js     13e3 <main+0x223>
mov    (%r15),%eax
test   %eax,0x24(%rsp)
je     136e <main+0x1ae>
mov    0x1c(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x40,%edx
call   10b0 <read@plt>
mov    $0xb,%edi
lea    0xcbd(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <gpio_get_value@plt>
mov    0xc(%rsp),%edx
xor    %eax,%eax
cmp    $0x1,%edx
sete   %al
add    %eax,%r13d
mov    %r12,%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%eax
test   %eax,0x18(%rsp)
je     12d0 <main+0x110>
mov    0x10(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x40,%edx
call   10b0 <read@plt>
mov    $0xa,%edi
lea    0xc6e(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <gpio_get_value@plt>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jne    12d0 <main+0x110>
test   %r13w,%r13w
je     12d0 <main+0x110>
movzwl %r13w,%esi
xor    %r13d,%r13d
lea    0xc74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12d0 <main+0x110>
lea    0xc6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc59(%rip),%rdi
call   1030 <puts@plt>
lea    0xc69(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [29 x i8] c"Usage: gpio-int <gpio-pin>\0A\0A\00"
@.str.1 = [68 x i8] c"Waits for a change in the GPIO pin voltage level or input on stdin\0A\00"
@.str.2 = [5 x i8] c"ph15\00"
@.str.3 = [5 x i8] c"ph14\00"
@.str.4 = [7 x i8] c"rising\00"
@.str.5 = [8 x i8] c"falling\00"
@POLLPRI = global i32 0
@.str.6 = [17 x i8] c"\0Apoll() failed!\0A\00"
@.str.7 = [50 x i8] c"\0Apoll() GPIO %d interrupt occurred with value %i\0A\00"
@.str.8 = [11 x i8] c"Count: %d\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [2 x %struct.pollfd]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [64 x i8*]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i16
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 2, i32* %9
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %3
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %15
%30 = call i32 @gpio_export(i32 11)
%31 = call i32 @gpio_export(i32 10)
%32 = call i32 @gpio_set_dir(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0)
%33 = call i32 @gpio_set_dir(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
%34 = call i32 @gpio_set_edge(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @gpio_set_edge(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @gpio_fd_open(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 %36, i32* %10
%37 = call i32 @gpio_fd_open(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 %37, i32* %11
store i32 0, i32* %16
store i16 0, i16* %18
store i32 3000, i32* %12
br label %38
38: ; preds = %25, %115
%39 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%40 = bitcast %struct.pollfd* %39 to i8*
%41 = call i32 @memset(i8* %40, i32 0, i32 24)
%42 = load i32, i32* %11
%43 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%44 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %43, i32 0, i32 0
store i32 %42, i32* %44
%45 = load i32, i32* @POLLPRI
%46 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%47 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %46, i32 0, i32 1
store i32 %45, i32* %47
%48 = load i32, i32* %10
%49 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1
%50 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %49, i32 0, i32 0
store i32 %48, i32* %50
%51 = load i32, i32* @POLLPRI
%52 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1
%53 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %52, i32 0, i32 1
store i32 %51, i32* %53
%54 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%55 = load i32, i32* %9
%56 = load i32, i32* %12
%57 = call i32 @poll(%struct.pollfd* %54, i32 %55, i32 %56)
store i32 %57, i32* %13
%58 = load i32, i32* %13
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %38
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
ret i32 -1
62: ; preds = %38
%63 = load i32, i32* %13
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %62
br label %66
66: ; preds = %65, %62
%67 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1
%68 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %67, i32 0, i32 2
%69 = load i32, i32* %68
%70 = load i32, i32* @POLLPRI
%71 = and i32 %69, %70
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %88
73: ; preds = %66
%74 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1
%75 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds [64 x i8*], [64 x i8*]* %14, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8** %77, i32 64)
store i32 %78, i32* %17
%79 = call i32 @gpio_get_value(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %16)
%80 = load i32, i32* %16
%81 = icmp eq i32 %80, 1
br i1 %81, label %82, label %85
82: ; preds = %73
%83 = load i16, i16* %18
%84 = add i16 %83, 1
store i16 %84, i16* %18
br label %85
85: ; preds = %82, %73
%86 = load i32, i32* %16
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 11, i32 %86)
br label %88
88: ; preds = %85, %66
%89 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%90 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %89, i32 0, i32 2
%91 = load i32, i32* %90
%92 = load i32, i32* @POLLPRI
%93 = and i32 %91, %92
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %115
95: ; preds = %88
%96 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%97 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %96, i32 0, i32 0
%98 = load i32, i32* %97
%99 = getelementptr inbounds [64 x i8*], [64 x i8*]* %14, i64 0, i64 0
%100 = call i32 @read(i32 %98, i8** %99, i32 64)
store i32 %100, i32* %17
%101 = call i32 @gpio_get_value(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%102 = load i32, i32* %16
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 10, i32 %102)
%104 = load i32, i32* %16
%105 = icmp eq i32 %104, 0
br i1 %105, label %106, label %114
106: ; preds = %95
%107 = load i16, i16* %18
%108 = zext i16 %107 to i32
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %106
%111 = load i16, i16* %18
%112 = zext i16 %111 to i32
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %112)
store i16 0, i16* %18
br label %114
114: ; preds = %110, %106, %95
br label %115
115: ; preds = %114, %88
%116 = load i32, i32* @stdout
%117 = call i32 @fflush(i32 %116)
br label %38
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str.2 = [5 x i8] c"ph15\00"
@.str.3 = [5 x i8] c"ph14\00"
@.str.4 = [7 x i8] c"rising\00"
@.str.5 = [8 x i8] c"falling\00"
@POLLPRI = global i32 0
@.str.7 = [50 x i8] c"\0Apoll() GPIO %d interrupt occurred with value %i\0A\00"
@.str.8 = [11 x i8] c"Count: %d\0A\00"
@stdout = global i32 0
@str = [16 x i8] c"\0Apoll() failed!\00"
@str.9 = [28 x i8] c"Usage: gpio-int <gpio-pin>\0A\00"
@str.10 = [67 x i8] c"Waits for a change in the GPIO pin voltage level or input on stdin\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [2 x %struct.pollfd]
%5 = alloca [64 x i8*]
%6 = alloca i32
%7 = bitcast [2 x %struct.pollfd]* %4 to i8*
%8 = bitcast [64 x i8*]* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = icmp slt i32 %0, 2
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.10, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %3
%16 = tail call i32 @gpio_export(i32 11)
%17 = tail call i32 @gpio_export(i32 10)
%18 = tail call i32 @gpio_set_dir(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0)
%19 = tail call i32 @gpio_set_dir(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
%20 = tail call i32 @gpio_set_edge(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @gpio_set_edge(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%22 = tail call i32 @gpio_fd_open(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @gpio_fd_open(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
%24 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%25 = call i32 @memset(i8* %7, i32 0, i32 24)
%26 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 %23, i32* %26
%27 = load i32, i32* @POLLPRI
%28 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 0
store i32 %22, i32* %29
%30 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 1
store i32 %27, i32* %30
%31 = call i32 @poll(%struct.pollfd* %24, i32 2, i32 3000)
%32 = icmp slt i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %15
%34 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 2
%35 = getelementptr inbounds [64 x i8*], [64 x i8*]* %5, i64 0, i64 0
%36 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 2
br label %39
37: ; preds = %74, %15
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
ret i32 -1
39: ; preds = %33, %74
%40 = phi i16 [ 0, %33 ], [ %75, %74 ]
%41 = load i32, i32* %34
%42 = load i32, i32* @POLLPRI
%43 = and i32 %42, %41
%44 = icmp eq i32 %43, 0
br i1 %44, label %55, label %45
45: ; preds = %39
%46 = load i32, i32* %29
%47 = call i32 @read(i32 %46, i8** %35, i32 64)
%48 = call i32 @gpio_get_value(i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, 1
%51 = zext i1 %50 to i16
%52 = add i16 %40, %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 11, i32 %49)
%54 = load i32, i32* @POLLPRI
br label %55
55: ; preds = %45, %39
%56 = phi i32 [ %54, %45 ], [ %42, %39 ]
%57 = phi i16 [ %52, %45 ], [ %40, %39 ]
%58 = load i32, i32* %36
%59 = and i32 %56, %58
%60 = icmp eq i32 %59, 0
br i1 %60, label %74, label %61
61: ; preds = %55
%62 = load i32, i32* %26
%63 = call i32 @read(i32 %62, i8** %35, i32 64)
%64 = call i32 @gpio_get_value(i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%65 = load i32, i32* %6
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 10, i32 %65)
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 0
%69 = icmp ne i16 %57, 0
%70 = select i1 %68, i1 %69, i1 false
br i1 %70, label %71, label %74
71: ; preds = %61
%72 = zext i16 %57 to i32
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %61, %71, %55
%75 = phi i16 [ 0, %71 ], [ %57, %61 ], [ %57, %55 ]
%76 = load i32, i32* @stdout
%77 = call i32 @fflush(i32 %76)
%78 = call i32 @memset(i8* %7, i32 0, i32 24)
store i32 %23, i32* %26
%79 = load i32, i32* @POLLPRI
store i32 %79, i32* %28
store i32 %22, i32* %29
store i32 %79, i32* %30
%80 = call i32 @poll(%struct.pollfd* %24, i32 2, i32 3000)
%81 = icmp slt i32 %80, 0
br i1 %81, label %37, label %39
}