#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*/ val_str;
struct pollfd {
  int fd;
  int events;
};
typedef int nfds_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int POLLERR;
int POLLPRI;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(struct pollfd *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
struct pollfd *malloc(int);
int open(char *, int /*<<< orphan*/);
char *optarg;
scalar_t__ poll(struct pollfd *, int, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strtoul(char *, char **, int /*<<< orphan*/);
int poll_gpio_value(int gpio_base, int nchannel) {
  char gpio_val_file[128];
  int val_fd = 0;
  int gpio_max;
  char val_str[2];
  char *cptr;
  int value = 0;
  int c;
  struct pollfd *fds;
  nfds_t nfds, fds_index;
  nfds = nchannel;
  fds = malloc(sizeof(struct pollfd) * nfds);
  if (fds == NULL) {
    fprintf(stderr, "Memory allocation in poll_gpio_value failed.\n");
    return -1;
  }
  gpio_max = gpio_base + nchannel;
  for (c = gpio_base, fds_index = 0; c < gpio_max; c++, fds_index++) {
    sprintf(gpio_val_file, "/sys/class/gpio/gpio%d/value", c);
    val_fd = open(gpio_val_file, O_RDWR);
    if (val_fd < 0) {
      free(fds);
      fprintf(stderr, "Cannot open GPIO to export %d\n", c);
      return -1;
    }
    read(val_fd, val_str, sizeof(val_str));
    fds[fds_index].fd = val_fd;
    fds[fds_index].events = POLLPRI | POLLERR;
  }
  if (poll(fds, nfds, -1) < 0) {
    free(fds);
    fprintf(stderr, "poll(2) failed.\n");
    return -1;
  }
  for (fds_index = 0; fds_index < nfds; fds_index++) {
    nfds_t fds_rindex = nfds - 1 - fds_index;
    lseek(fds[fds_rindex].fd, 0, SEEK_SET);
    read(fds[fds_rindex].fd, val_str, sizeof(val_str));
    value <<= 1;
    value += (int)strtoul(val_str, &cptr, 0);
    if (cptr == optarg) {
      fprintf(stderr, "Failed to change %s into integer", val_str);
    }
    close(fds[fds_rindex].fd);
  }
  free(fds);
  return value;
}


x86 assembly (clang, -O0):
<poll_gpio_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0xac(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0xbc(%rbp)
movslq -0xbc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    1218 <poll_gpio_value+0x78>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    149c <poll_gpio_value+0x2fc>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x98(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xb0(%rbp)
movl   $0x0,-0xc0(%rbp)
mov    -0xb0(%rbp),%eax
cmp    -0x98(%rbp),%eax
jge    1334 <poll_gpio_value+0x194>
lea    -0x90(%rbp),%rdi
mov    -0xb0(%rbp),%edx
lea    0xdd1(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jge    12bf <poll_gpio_value+0x11f>
mov    -0xb8(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    -0xb0(%rbp),%edx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    149c <poll_gpio_value+0x2fc>
mov    -0x94(%rbp),%edi
lea    -0x9a(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    -0x94(%rbp),%edx
mov    -0xb8(%rbp),%rax
movslq -0xc0(%rbp),%rcx
mov    %edx,(%rax,%rcx,8)
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
mov    0x2cd3(%rip),%rax
or     (%rax),%edx
mov    -0xb8(%rbp),%rax
movslq -0xc0(%rbp),%rcx
mov    %edx,0x4(%rax,%rcx,8)
mov    -0xb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb0(%rbp)
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    1237 <poll_gpio_value+0x97>
mov    -0xb8(%rbp),%rdi
mov    -0xbc(%rbp),%esi
mov    $0xffffffff,%edx
call   1090 <poll@plt>
cmp    $0x0,%rax
jge    1384 <poll_gpio_value+0x1e4>
mov    -0xb8(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    149c <poll_gpio_value+0x2fc>
movl   $0x0,-0xc0(%rbp)
mov    -0xc0(%rbp),%eax
cmp    -0xbc(%rbp),%eax
jge    1487 <poll_gpio_value+0x2e7>
mov    -0xbc(%rbp),%eax
sub    $0x1,%eax
sub    -0xc0(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xb8(%rbp),%rax
movslq -0xc4(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
mov    0x2beb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0xb8(%rbp),%rax
movslq -0xc4(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
lea    -0x9a(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    -0xac(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xac(%rbp)
lea    -0x9a(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
xor    %edx,%edx
call   10b0 <strtoul@plt>
add    -0xac(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0xa8(%rbp),%rax
mov    0x2bc2(%rip),%rcx
cmp    (%rcx),%rax
jne    145d <poll_gpio_value+0x2bd>
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
lea    -0x9a(%rbp),%rdx
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0xb8(%rbp),%rax
movslq -0xc4(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
call   1050 <close@plt>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    138e <poll_gpio_value+0x1ee>
mov    -0xb8(%rbp),%rdi
call   1030 <free@plt>
mov    -0xac(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll_gpio_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x0(,%rbx,8),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1315 <poll_gpio_value+0x175>
mov    %rax,%r12
test   %ebx,%ebx
jle    1327 <poll_gpio_value+0x187>
mov    %rbx,0x8(%rsp)
lea    (%rbx,%rbp,1),%r13d
mov    %rbp,0x10(%rsp)
mov    %ebp,%ebp
xor    %r14d,%r14d
lea    0x20(%rsp),%rbx
nopl   (%rax)
lea    (%r14,%rbp,1),%edx
mov    %rbx,%rdi
lea    0xe30(%rip),%rsi
call   10c0 <sprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1363 <poll_gpio_value+0x1c3>
mov    %eax,%r15d
mov    %eax,%edi
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %r15d,(%r12,%r14,8)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    0x2da4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x4(%r12,%r14,8)
add    $0x1,%r14
lea    (%r14,%rbp,1),%eax
cmp    %r13d,%eax
jl     11f0 <poll_gpio_value+0x50>
mov    %r12,%rdi
mov    0x8(%rsp),%rbx
mov    %ebx,%esi
mov    $0xffffffff,%edx
call   1090 <poll@plt>
test   %rax,%rax
js     133d <poll_gpio_value+0x19d>
test   %ebx,%ebx
jle    1391 <poll_gpio_value+0x1f1>
mov    %ebx,%r13d
lea    0x6(%rsp),%r14
xor    %ebx,%ebx
jmp    12a7 <poll_gpio_value+0x107>
nopl   0x0(%rax)
lea    0x0(%rbp,%rbx,2),%ebx
mov    (%r12,%r15,8),%edi
call   1050 <close@plt>
add    $0xffffffffffffffff,%r13
je     1393 <poll_gpio_value+0x1f3>
lea    -0x1(%r13),%eax
movslq %eax,%r15
mov    (%r12,%r15,8),%edi
mov    0x2cff(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    (%r12,%r15,8),%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %r14,%rdi
lea    0x18(%rsp),%rsi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,%rbp
mov    0x18(%rsp),%rax
mov    0x2d07(%rip),%rcx
cmp    (%rcx),%rax
jne    1290 <poll_gpio_value+0xf0>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1290 <poll_gpio_value+0xf0>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
jmp    1355 <poll_gpio_value+0x1b5>
mov    %r12,%rdi
mov    %ebx,%esi
mov    $0xffffffff,%edx
call   1090 <poll@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    1393 <poll_gpio_value+0x1f3>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    139b <poll_gpio_value+0x1fb>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
add    %r14d,%edx
lea    0xcc8(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    139b <poll_gpio_value+0x1fb>
xor    %ebx,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@stderr = global i32 0
@.str = [46 x i8] c"Memory allocation in poll_gpio_value failed.\0A\00"
@.str.1 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"Cannot open GPIO to export %d\0A\00"
@POLLPRI = global i32 0
@POLLERR = global i32 0
@.str.3 = [17 x i8] c"poll(2) failed.\0A\00"
@SEEK_SET = global i32 0
@optarg = global i8* null
@.str.4 = [33 x i8] c"Failed to change %s into integer\00"
define i32 @poll_gpio_value(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.pollfd*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
store i32 0, i32* %11
%17 = load i32, i32* %5
store i32 %17, i32* %14
%18 = load i32, i32* %14
%19 = sext i32 %18 to i64
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call %struct.pollfd* @malloc(i32 %21)
store %struct.pollfd* %22, %struct.pollfd** %13
%23 = load %struct.pollfd*, %struct.pollfd** %13
%24 = icmp eq %struct.pollfd* %23, null
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %140
28: ; preds = %2
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = add nsw i32 %29, %30
store i32 %31, i32* %8
%32 = load i32, i32* %4
store i32 %32, i32* %12
store i32 0, i32* %15
br label %33
33: ; preds = %70, %28
%34 = load i32, i32* %12
%35 = load i32, i32* %8
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %75
37: ; preds = %33
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %12
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* @O_RDWR
%43 = call i32 @open(i8* %41, i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %37
%47 = load %struct.pollfd*, %struct.pollfd** %13
%48 = call i32 @free(%struct.pollfd* %47)
%49 = load i32, i32* @stderr
%50 = load i32, i32* %12
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %50)
store i32 -1, i32* %3
br label %140
52: ; preds = %37
%53 = load i32, i32* %7
%54 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%55 = call i32 @read(i32 %53, i8* %54, i32 2)
%56 = load i32, i32* %7
%57 = load %struct.pollfd*, %struct.pollfd** %13
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %57, i64 %59
%61 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %60, i32 0, i32 0
store i32 %56, i32* %61
%62 = load i32, i32* @POLLPRI
%63 = load i32, i32* @POLLERR
%64 = or i32 %62, %63
%65 = load %struct.pollfd*, %struct.pollfd** %13
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %65, i64 %67
%69 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %68, i32 0, i32 1
store i32 %64, i32* %69
br label %70
70: ; preds = %52
%71 = load i32, i32* %12
%72 = add nsw i32 %71, 1
store i32 %72, i32* %12
%73 = load i32, i32* %15
%74 = add nsw i32 %73, 1
store i32 %74, i32* %15
br label %33
75: ; preds = %33
%76 = load %struct.pollfd*, %struct.pollfd** %13
%77 = load i32, i32* %14
%78 = call i64 @poll(%struct.pollfd* %76, i32 %77, i32 -1)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %75
%81 = load %struct.pollfd*, %struct.pollfd** %13
%82 = call i32 @free(%struct.pollfd* %81)
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %140
85: ; preds = %75
store i32 0, i32* %15
br label %86
86: ; preds = %133, %85
%87 = load i32, i32* %15
%88 = load i32, i32* %14
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %136
90: ; preds = %86
%91 = load i32, i32* %14
%92 = sub nsw i32 %91, 1
%93 = load i32, i32* %15
%94 = sub nsw i32 %92, %93
store i32 %94, i32* %16
%95 = load %struct.pollfd*, %struct.pollfd** %13
%96 = load i32, i32* %16
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %95, i64 %97
%99 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %98, i32 0, i32 0
%100 = load i32, i32* %99
%101 = load i32, i32* @SEEK_SET
%102 = call i32 @lseek(i32 %100, i32 0, i32 %101)
%103 = load %struct.pollfd*, %struct.pollfd** %13
%104 = load i32, i32* %16
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %103, i64 %105
%107 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %106, i32 0, i32 0
%108 = load i32, i32* %107
%109 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%110 = call i32 @read(i32 %108, i8* %109, i32 2)
%111 = load i32, i32* %11
%112 = shl i32 %111, 1
store i32 %112, i32* %11
%113 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%114 = call i64 @strtoul(i8* %113, i8** %10, i32 0)
%115 = trunc i64 %114 to i32
%116 = load i32, i32* %11
%117 = add nsw i32 %116, %115
store i32 %117, i32* %11
%118 = load i8*, i8** %10
%119 = load i8*, i8** @optarg
%120 = icmp eq i8* %118, %119
br i1 %120, label %121, label %125
121: ; preds = %90
%122 = load i32, i32* @stderr
%123 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %123)
br label %125
125: ; preds = %121, %90
%126 = load %struct.pollfd*, %struct.pollfd** %13
%127 = load i32, i32* %16
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %126, i64 %128
%130 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %129, i32 0, i32 0
%131 = load i32, i32* %130
%132 = call i32 @close(i32 %131)
br label %133
133: ; preds = %125
%134 = load i32, i32* %15
%135 = add nsw i32 %134, 1
store i32 %135, i32* %15
br label %86
136: ; preds = %86
%137 = load %struct.pollfd*, %struct.pollfd** %13
%138 = call i32 @free(%struct.pollfd* %137)
%139 = load i32, i32* %11
store i32 %139, i32* %3
br label %140
140: ; preds = %136, %80, %46, %25
%141 = load i32, i32* %3
ret i32 %141
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@stderr = global i32 0
@.str = [46 x i8] c"Memory allocation in poll_gpio_value failed.\0A\00"
@.str.1 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"Cannot open GPIO to export %d\0A\00"
@POLLPRI = global i32 0
@POLLERR = global i32 0
@.str.3 = [17 x i8] c"poll(2) failed.\0A\00"
@SEEK_SET = global i32 0
@optarg = global i8* null
@.str.4 = [33 x i8] c"Failed to change %s into integer\00"
define i32 @poll_gpio_value(i32 %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = alloca [2 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
%9 = shl i32 %1, 3
%10 = tail call %struct.pollfd* @malloc(i32 %9)
%11 = icmp eq %struct.pollfd* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %83
15: ; preds = %2
%16 = add nsw i32 %1, %0
%17 = icmp sgt i32 %1, 0
br i1 %17, label %18, label %42
18: ; preds = %15, %29
%19 = phi i64 [ %37, %29 ], [ 0, %15 ]
%20 = phi i32 [ %36, %29 ], [ %0, %15 ]
%21 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* %6, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = tail call i32 @free(%struct.pollfd* %10)
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %83
29: ; preds = %18
%30 = call i32 @read(i32 %23, i8* %7, i32 2)
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %19, i32 0
store i32 %23, i32* %31
%32 = load i32, i32* @POLLPRI
%33 = load i32, i32* @POLLERR
%34 = or i32 %33, %32
%35 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %19, i32 1
store i32 %34, i32* %35
%36 = add nsw i32 %20, 1
%37 = add nuw nsw i64 %19, 1
%38 = icmp slt i32 %36, %16
br i1 %38, label %18, label %39
39: ; preds = %29
%40 = tail call i64 @poll(%struct.pollfd* %10, i32 %1, i32 -1)
%41 = icmp slt i64 %40, 0
br i1 %41, label %48, label %45
42: ; preds = %15
%43 = tail call i64 @poll(%struct.pollfd* %10, i32 %1, i32 -1)
%44 = icmp slt i64 %43, 0
br i1 %44, label %48, label %80
45: ; preds = %39
br i1 %17, label %46, label %80
46: ; preds = %45
%47 = zext i32 %1 to i64
br label %52
48: ; preds = %42, %39
%49 = tail call i32 @free(%struct.pollfd* %10)
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %83
52: ; preds = %46, %75
%53 = phi i64 [ 0, %46 ], [ %78, %75 ]
%54 = phi i32 [ 0, %46 ], [ %68, %75 ]
%55 = trunc i64 %53 to i32
%56 = xor i32 %55, -1
%57 = add i32 %56, %1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %58, i32 0
%60 = load i32, i32* %59
%61 = load i32, i32* @SEEK_SET
%62 = call i32 @lseek(i32 %60, i32 0, i32 %61)
%63 = load i32, i32* %59
%64 = call i32 @read(i32 %63, i8* %7, i32 2)
%65 = shl i32 %54, 1
%66 = call i64 @strtoul(i8* %7, i8** %5, i32 0)
%67 = trunc i64 %66 to i32
%68 = add nsw i32 %65, %67
%69 = load i8*, i8** %5
%70 = load i8*, i8** @optarg
%71 = icmp eq i8* %69, %70
br i1 %71, label %72, label %75
72: ; preds = %52
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %7)
br label %75
75: ; preds = %72, %52
%76 = load i32, i32* %59
%77 = call i32 @close(i32 %76)
%78 = add nuw nsw i64 %53, 1
%79 = icmp eq i64 %78, %47
br i1 %79, label %80, label %52
80: ; preds = %75, %42, %45
%81 = phi i32 [ 0, %45 ], [ 0, %42 ], [ %68, %75 ]
%82 = call i32 @free(%struct.pollfd* %10)
br label %83
83: ; preds = %80, %48, %25, %12
%84 = phi i32 [ -1, %12 ], [ -1, %25 ], [ -1, %48 ], [ %81, %80 ]
ret i32 %84
}