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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ POLLIN;
int check_and_parse(int, char **, char *, int *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dumphex(char **, char *, int, int, char *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ print_err(char *, int);
int /*<<< orphan*/ print_err_prefix(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ tt_open(char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fds, res, mode, copy = 0;
  struct pollfd pfd[16] = {{0}};
  char devnams[16][16] = {{0}};
  fds = check_and_parse(argc, argv, devnams[0], &mode, &copy);
  if (fds < 0)
    return -1 - fds;
  for (int i = 0; i < fds; i++) {
    pfd[i].events = POLLIN;
    printf("Opening %s...\n", devnams[i]);
    pfd[i].fd = tt_open(devnams[i], mode | (1 << 12) | (1 << 15));
    if (pfd[i].fd < 0) {
      print_err("tt_open", pfd[i].fd);
      return 4;
    }
    printf("%s opened.\n", devnams[i]);
  }
  puts("");
  char framebuf[(9126 + 14)];
  char *hexbuf = NULL;
  for (int i = 0;;) {
    res = poll(pfd, fds, -1);
    if (res < 0) {
      print_err("poll", res);
      break;
    }
    for (i = 0; i < fds; i++) {
      if (!pfd[i].revents)
        continue;
      res = read(pfd[i].fd, framebuf, sizeof(framebuf));
      if (res == -1) {
        if (errno == EINTR)
          continue;
        print_err_prefix(devnams[i], "read", res);
        i = -1;
        break;
      }
      if (res == 0) {
        fprintf(stderr, "%s read() returned 0.\n", devnams[i]);
        i = -1;
        break;
      }
      dumphex(&hexbuf, framebuf, res, (1 << 0) | (1 << 1) | (1 << 2),
              devnams[i]);
      puts(hexbuf);
      if (copy) {
        res = write(pfd[(i + 1) % fds].fd, framebuf, res);
        if (res == -1 && errno != EINTR) {
          print_err_prefix(devnams[(i + 1) % fds], "write", res);
          i = -1;
          break;
        }
        printf("%s sent %d bytes.\n\n", devnams[(i + 1) % fds], res);
      }
    }
    if (i < 0)
      break;
  }
  while (--fds >= 0)
    close(pfd[fds].fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2670,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1080 <memset@plt>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x2a0(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   10b0 <check_and_parse@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    124e <main+0x7e>
mov    $0xffffffff,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1650 <main+0x480>
movl   $0x0,-0x2a4(%rbp)
mov    -0x2a4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1377 <main+0x1a7>
mov    0x2d7a(%rip),%rax
mov    (%rax),%ecx
movslq -0x2a4(%rbp),%rdx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0xc(%rax)
movslq -0x2a4(%rbp),%rax
lea    -0x2a0(%rbp),%rsi
shl    $0x4,%rax
add    %rax,%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x2a4(%rbp),%rax
lea    -0x2a0(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%esi
or     $0x1000,%esi
or     $0x8000,%esi
call   10f0 <tt_open@plt>
mov    %rax,%rcx
movslq -0x2a4(%rbp),%rdx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
movslq -0x2a4(%rbp),%rcx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
jge    1340 <main+0x170>
movslq -0x2a4(%rbp),%rcx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0xce0(%rip),%rdi
call   1030 <print_err@plt>
movl   $0x4,-0x4(%rbp)
jmp    1650 <main+0x480>
movslq -0x2a4(%rbp),%rax
lea    -0x2a0(%rbp),%rsi
shl    $0x4,%rax
add    %rax,%rsi
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2a4(%rbp)
jmp    1258 <main+0x88>
lea    0xcdf(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,-0x2668(%rbp)
movl   $0x0,-0x266c(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0xffffffff,%edx
call   10e0 <poll@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13cd <main+0x1fd>
mov    -0x18(%rbp),%esi
lea    0xc60(%rip),%rdi
call   1030 <print_err@plt>
jmp    1611 <main+0x441>
movl   $0x0,-0x266c(%rbp)
mov    -0x266c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    15fa <main+0x42a>
movslq -0x266c(%rbp),%rcx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0x8(%rax)
jne    140a <main+0x23a>
jmp    15e6 <main+0x416>
movslq -0x266c(%rbp),%rcx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %eax,%edi
lea    -0x2660(%rbp),%rsi
mov    $0x23b4,%edx
call   10c0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1494 <main+0x2c4>
mov    0x2b87(%rip),%rax
mov    (%rax),%rax
mov    0x2b75(%rip),%rcx
cmp    (%rcx),%rax
jne    1461 <main+0x291>
jmp    15e6 <main+0x416>
movslq -0x266c(%rbp),%rax
lea    -0x2a0(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%edx
lea    0xba8(%rip),%rsi
call   1060 <print_err_prefix@plt>
movl   $0xffffffff,-0x266c(%rbp)
ff ff ff
jmp    15fa <main+0x42a>
cmpl   $0x0,-0x18(%rbp)
jne    14d7 <main+0x307>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
movslq -0x266c(%rbp),%rax
lea    -0x2a0(%rbp),%rdx
shl    $0x4,%rax
add    %rax,%rdx
lea    0xb6a(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0xffffffff,-0x266c(%rbp)
ff ff ff
jmp    15fa <main+0x42a>
lea    -0x2660(%rbp),%rsi
mov    -0x18(%rbp),%edx
movslq -0x266c(%rbp),%rax
lea    -0x2a0(%rbp),%r8
shl    $0x4,%rax
add    %rax,%r8
lea    -0x2668(%rbp),%rdi
mov    $0x7,%ecx
call   1090 <dumphex@plt>
mov    -0x2668(%rbp),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x20(%rbp)
je     15e1 <main+0x411>
mov    -0x266c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
movslq %edx,%rcx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %eax,%edi
lea    -0x2660(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    15b2 <main+0x3e2>
mov    0x2a6d(%rip),%rax
mov    (%rax),%rax
mov    0x2a5b(%rip),%rcx
cmp    (%rcx),%rax
je     15b2 <main+0x3e2>
mov    -0x266c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
movslq %edx,%rax
lea    -0x2a0(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%edx
lea    0xaa6(%rip),%rsi
call   1060 <print_err_prefix@plt>
movl   $0xffffffff,-0x266c(%rbp)
ff ff ff
jmp    15fa <main+0x42a>
mov    -0x266c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
movslq %edx,%rax
lea    -0x2a0(%rbp),%rsi
shl    $0x4,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
lea    0xa70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15e6 <main+0x416>
mov    -0x266c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x266c(%rbp)
jmp    13d7 <main+0x207>
cmpl   $0x0,-0x266c(%rbp)
jge    160c <main+0x43c>
jmp    1611 <main+0x441>
jmp    1398 <main+0x1c8>
jmp    1616 <main+0x446>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1649 <main+0x479>
movslq -0x14(%rbp),%rcx
lea    -0x1a0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %eax,%edi
call   10a0 <close@plt>
jmp    1616 <main+0x446>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2670,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2658,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movl   $0x0,0x8(%rsp)
lea    0x120(%rsp),%rdi
mov    $0x180,%edx
xor    %esi,%esi
call   1090 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rbx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10c0 <check_and_parse@plt>
test   %eax,%eax
js     14aa <main+0x2ca>
mov    %eax,0x4(%rsp)
mov    %eax,%r15d
je     132c <main+0x14c>
lea    0x0(,%r15,8),%rax
lea    (%rax,%rax,2),%rbp
lea    0xd3d(%rip),%r12
mov    $0x9000,%r13d
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x12c(%rsp,%r14,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0xc(%rsp),%esi
or     %r13d,%esi
mov    %rbx,%rdi
call   1100 <tt_open@plt>
mov    %rax,0x120(%rsp,%r14,1)
test   %rax,%rax
js     14b1 <main+0x2d1>
lea    0xd02(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x18,%r14
add    $0x10,%rbx
cmp    %r14,%rbp
jne    12d0 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
movq   $0x0,0x10(%rsp)
lea    0x120(%rsp),%rdi
mov    0x4(%rsp),%ebx
mov    %ebx,%esi
mov    $0xffffffff,%edx
call   10f0 <poll@plt>
test   %eax,%eax
js     14c9 <main+0x2e9>
mov    %r15,%r14
neg    %r14
mov    %r14,0x18(%rsp)
jmp    1390 <main+0x1b0>
nopl   0x0(%rax)
lea    0x120(%rsp),%rdi
mov    0x4(%rsp),%ebx
mov    %ebx,%esi
mov    $0xffffffff,%edx
call   10f0 <poll@plt>
test   %eax,%eax
js     14c9 <main+0x2e9>
test   %ebx,%ebx
jle    1370 <main+0x190>
mov    $0x1,%r13d
lea    0x128(%rsp),%rbx
lea    0x20(%rsp),%rbp
jmp    13e4 <main+0x204>
nopl   0x0(%rax)
mov    0x2c19(%rip),%rax
mov    (%rax),%rax
mov    0x2c07(%rip),%rcx
cmp    (%rcx),%rax
jne    14f7 <main+0x317>
add    $0x10,%rbp
add    $0x18,%rbx
lea    (%r14,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%r13
cmp    $0x1,%rax
je     1370 <main+0x190>
cmpl   $0x0,(%rbx)
je     13ca <main+0x1ea>
mov    -0x8(%rbx),%edi
lea    0x2a0(%rsp),%rsi
mov    $0x23b4,%edx
call   10d0 <read@plt>
cmp    $0xffffffff,%eax
je     13b0 <main+0x1d0>
mov    %eax,%r12d
test   %eax,%eax
je     14dd <main+0x2fd>
lea    0x10(%rsp),%rdi
lea    0x2a0(%rsp),%rsi
mov    %r12d,%edx
mov    $0x7,%ecx
mov    %rbp,%r8
call   10a0 <dumphex@plt>
mov    0x10(%rsp),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0x8(%rsp)
je     13ca <main+0x1ea>
mov    %r14,%rax
add    %r13,%rax
mov    %r13,%r14
mov    $0x0,%eax
cmove  %rax,%r14
lea    (%r14,%r14,2),%rax
mov    0x120(%rsp,%rax,8),%edi
lea    0x2a0(%rsp),%rsi
mov    %r12d,%edx
call   1060 <write@plt>
cmp    $0xffffffff,%eax
jne    1484 <main+0x2a4>
mov    0x2b5b(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2b49(%rip),%rdx
cmp    (%rdx),%rcx
jne    1503 <main+0x323>
shl    $0x4,%r14
lea    (%rsp,%r14,1),%rsi
add    $0x20,%rsi
lea    0xbb3(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x18(%rsp),%r14
jmp    13ca <main+0x1ea>
not    %eax
jmp    1550 <main+0x370>
lea    0xb57(%rip),%rdi
mov    %eax,%esi
call   1040 <print_err@plt>
mov    $0x4,%eax
jmp    1550 <main+0x370>
lea    0xb53(%rip),%rdi
mov    %eax,%esi
call   1040 <print_err@plt>
test   %ebx,%ebx
jg     1528 <main+0x348>
jmp    154e <main+0x36e>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
lea    0xb40(%rip),%rsi
mov    %rbp,%rdx
call   10e0 <fprintf@plt>
jmp    1520 <main+0x340>
lea    0xb2a(%rip),%rsi
mov    %rbp,%rdi
jmp    1516 <main+0x336>
shl    $0x4,%r14
lea    (%rsp,%r14,1),%rdi
add    $0x20,%rdi
lea    0xb2e(%rip),%rsi
mov    $0xffffffff,%edx
call   1070 <print_err_prefix@plt>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jle    154e <main+0x36e>
add    $0x1,%r15
nopl   0x0(%rax)
lea    -0x2(%r15),%eax
lea    (%rax,%rax,2),%rax
mov    0x120(%rsp,%rax,8),%edi
call   10b0 <close@plt>
add    $0xffffffffffffffff,%r15
cmp    $0x1,%r15
ja     1530 <main+0x350>
xor    %eax,%eax
add    $0x2658,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i64, i32, i32, i32 }
@POLLIN = global i32 0
@.str = [15 x i8] c"Opening %s...\0A\00"
@.str.1 = [8 x i8] c"tt_open\00"
@.str.2 = [12 x i8] c"%s opened.\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [5 x i8] c"poll\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.6 = [23 x i8] c"%s read() returned 0.\0A\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [20 x i8] c"%s sent %d bytes.\0A\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 i32
%9 = alloca i32
%10 = alloca [16 x %struct.pollfd]
%11 = alloca [16 x [16 x i8]]
%12 = alloca i32
%13 = alloca [9140 x i8]
%14 = alloca i8*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%16 = bitcast [16 x %struct.pollfd]* %10 to i8*
%17 = bitcast [16 x [16 x i8]]* %11 to i8*
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 0
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%22 = call i32 @check_and_parse(i32 %18, i8** %19, i8* %21, i32* %8, i32* %9)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* %6
%27 = sub nsw i32 -1, %26
store i32 %27, i32* %3
br label %210
28: ; preds = %2
store i32 0, i32* %12
br label %29
29: ; preds = %76, %28
%30 = load i32, i32* %12
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %79
33: ; preds = %29
%34 = load i32, i32* @POLLIN
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %36
%38 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %37, i32 0, i32 2
store i32 %34, i32* %38
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %40
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %41, i64 0, i64 0
%43 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %45
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %46, i64 0, i64 0
%48 = load i32, i32* %8
%49 = or i32 %48, 4096
%50 = or i32 %49, 32768
%51 = call i64 @tt_open(i8* %47, i32 %50)
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %53
%55 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %54, i32 0, i32 0
store i64 %51, i64* %55
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %57
%59 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %58, i32 0, i32 0
%60 = load i64, i64* %59
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %33
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %64
%66 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = trunc i64 %67 to i32
%69 = call i32 @print_err(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %68)
store i32 4, i32* %3
br label %210
70: ; preds = %33
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %72
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %73, i64 0, i64 0
%75 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %70
%77 = load i32, i32* %12
%78 = add nsw i32 %77, 1
store i32 %78, i32* %12
br label %29
79: ; preds = %29
%80 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %14
store i32 0, i32* %15
br label %81
81: ; preds = %195, %79
%82 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 0
%83 = load i32, i32* %6
%84 = call i32 @poll(%struct.pollfd* %82, i32 %83, i32 -1)
store i32 %84, i32* %7
%85 = load i32, i32* %7
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %81
%88 = load i32, i32* %7
%89 = call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %88)
br label %196
90: ; preds = %81
store i32 0, i32* %15
br label %91
91: ; preds = %188, %90
%92 = load i32, i32* %15
%93 = load i32, i32* %6
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %191
95: ; preds = %91
%96 = load i32, i32* %15
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %97
%99 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %98, i32 0, i32 1
%100 = load i32, i32* %99
%101 = icmp ne i32 %100, 0
br i1 %101, label %103, label %102
102: ; preds = %95
br label %188
103: ; preds = %95
%104 = load i32, i32* %15
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %105
%107 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %106, i32 0, i32 0
%108 = load i64, i64* %107
%109 = trunc i64 %108 to i32
%110 = getelementptr inbounds [9140 x i8], [9140 x i8]* %13, i64 0, i64 0
%111 = call i32 @read(i32 %109, i8* %110, i32 9140)
store i32 %111, i32* %7
%112 = load i32, i32* %7
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %126
114: ; preds = %103
%115 = load i64, i64* @errno
%116 = load i64, i64* @EINTR
%117 = icmp eq i64 %115, %116
br i1 %117, label %118, label %119
118: ; preds = %114
br label %188
119: ; preds = %114
%120 = load i32, i32* %15
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %121
%123 = getelementptr inbounds [16 x i8], [16 x i8]* %122, i64 0, i64 0
%124 = load i32, i32* %7
%125 = call i32 @print_err_prefix(i8* %123, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %124)
store i32 -1, i32* %15
br label %191
126: ; preds = %103
%127 = load i32, i32* %7
%128 = icmp eq i32 %127, 0
br i1 %128, label %129, label %136
129: ; preds = %126
%130 = load i32, i32* @stderr
%131 = load i32, i32* %15
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %132
%134 = getelementptr inbounds [16 x i8], [16 x i8]* %133, i64 0, i64 0
%135 = call i32 @fprintf(i32 %130, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %134)
store i32 -1, i32* %15
br label %191
136: ; preds = %126
%137 = getelementptr inbounds [9140 x i8], [9140 x i8]* %13, i64 0, i64 0
%138 = load i32, i32* %7
%139 = load i32, i32* %15
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %140
%142 = getelementptr inbounds [16 x i8], [16 x i8]* %141, i64 0, i64 0
%143 = call i32 @dumphex(i8** %14, i8* %137, i32 %138, i32 7, i8* %142)
%144 = load i8*, i8** %14
%145 = call i32 @puts(i8* %144)
%146 = load i32, i32* %9
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %187
148: ; preds = %136
%149 = load i32, i32* %15
%150 = add nsw i32 %149, 1
%151 = load i32, i32* %6
%152 = srem i32 %150, %151
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %153
%155 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %154, i32 0, i32 0
%156 = load i64, i64* %155
%157 = trunc i64 %156 to i32
%158 = getelementptr inbounds [9140 x i8], [9140 x i8]* %13, i64 0, i64 0
%159 = load i32, i32* %7
%160 = call i32 @write(i32 %157, i8* %158, i32 %159)
store i32 %160, i32* %7
%161 = load i32, i32* %7
%162 = icmp eq i32 %161, -1
br i1 %162, label %163, label %177
163: ; preds = %148
%164 = load i64, i64* @errno
%165 = load i64, i64* @EINTR
%166 = icmp ne i64 %164, %165
br i1 %166, label %167, label %177
167: ; preds = %163
%168 = load i32, i32* %15
%169 = add nsw i32 %168, 1
%170 = load i32, i32* %6
%171 = srem i32 %169, %170
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %172
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %173, i64 0, i64 0
%175 = load i32, i32* %7
%176 = call i32 @print_err_prefix(i8* %174, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %175)
store i32 -1, i32* %15
br label %191
177: ; preds = %163, %148
%178 = load i32, i32* %15
%179 = add nsw i32 %178, 1
%180 = load i32, i32* %6
%181 = srem i32 %179, %180
%182 = sext i32 %181 to i64
%183 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %11, i64 0, i64 %182
%184 = getelementptr inbounds [16 x i8], [16 x i8]* %183, i64 0, i64 0
%185 = load i32, i32* %7
%186 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %184, i32 %185)
br label %187
187: ; preds = %177, %136
br label %188
188: ; preds = %187, %118, %102
%189 = load i32, i32* %15
%190 = add nsw i32 %189, 1
store i32 %190, i32* %15
br label %91
191: ; preds = %167, %129, %119, %91
%192 = load i32, i32* %15
%193 = icmp slt i32 %192, 0
br i1 %193, label %194, label %195
194: ; preds = %191
br label %196
195: ; preds = %191
br label %81
196: ; preds = %194, %87
br label %197
197: ; preds = %201, %196
%198 = load i32, i32* %6
%199 = add nsw i32 %198, -1
store i32 %199, i32* %6
%200 = icmp sge i32 %199, 0
br i1 %200, label %201, label %209
201: ; preds = %197
%202 = load i32, i32* %6
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %10, i64 0, i64 %203
%205 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %204, i32 0, i32 0
%206 = load i64, i64* %205
%207 = trunc i64 %206 to i32
%208 = call i32 @close(i32 %207)
br label %197
209: ; preds = %197
store i32 0, i32* %3
br label %210
210: ; preds = %209, %62, %25
%211 = load i32, i32* %3
ret i32 %211
}

LLVM IR (-O2):
%struct.pollfd = type { i64, i32, i32, i32 }
@POLLIN = global i32 0
@.str = [15 x i8] c"Opening %s...\0A\00"
@.str.1 = [8 x i8] c"tt_open\00"
@.str.2 = [12 x i8] c"%s opened.\0A\00"
@.str.4 = [5 x i8] c"poll\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.6 = [23 x i8] c"%s read() returned 0.\0A\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [20 x i8] c"%s sent %d bytes.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x %struct.pollfd]
%6 = alloca [16 x [16 x i8]]
%7 = alloca [9140 x i8]
%8 = alloca i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast [16 x %struct.pollfd]* %5 to i8*
%12 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 0, i64 0
%13 = call i32 @check_and_parse(i32 %0, i8** %1, i8* %12, i32* %3, i32* %4)
%14 = icmp slt i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = icmp eq i32 %13, 0
br i1 %16, label %39, label %17
17: ; preds = %15
%18 = zext i32 %13 to i64
br label %21
19: ; preds = %2
%20 = xor i32 %13, -1
br label %123
21: ; preds = %17, %35
%22 = phi i64 [ 0, %17 ], [ %37, %35 ]
%23 = load i32, i32* @POLLIN
%24 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 %22, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 %22, i64 0
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %3
%28 = or i32 %27, 36864
%29 = call i64 @tt_open(i8* %25, i32 %28)
%30 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 %22, i32 0
store i64 %29, i64* %30
%31 = icmp slt i64 %29, 0
br i1 %31, label %32, label %35
32: ; preds = %21
%33 = trunc i64 %29 to i32
%34 = call i32 @print_err(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %123
35: ; preds = %21
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%37 = add nuw nsw i64 %22, 1
%38 = icmp eq i64 %37, %18
br i1 %38, label %39, label %21
39: ; preds = %35, %15
%40 = call i32 @putchar(i32 10)
%41 = getelementptr inbounds [9140 x i8], [9140 x i8]* %7, i64 0, i64 0
%42 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%43 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 0
%44 = call i32 @poll(%struct.pollfd* %43, i32 %13, i32 -1)
%45 = icmp slt i32 %44, 0
br i1 %45, label %53, label %46
46: ; preds = %39
%47 = icmp sgt i32 %13, 0
%48 = zext i32 %13 to i64
br label %52
49: ; preds = %106, %52
%50 = call i32 @poll(%struct.pollfd* %43, i32 %13, i32 -1)
%51 = icmp slt i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %46, %49
br i1 %47, label %56, label %49
53: ; preds = %49, %39
%54 = phi i32 [ %44, %39 ], [ %50, %49 ]
%55 = call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br label %109
56: ; preds = %52, %106
%57 = phi i64 [ %107, %106 ], [ 0, %52 ]
%58 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 %57, i32 1
%59 = load i32, i32* %58
%60 = icmp eq i32 %59, 0
br i1 %60, label %106, label %61
61: ; preds = %56
%62 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 %57, i32 0
%63 = load i64, i64* %62
%64 = trunc i64 %63 to i32
%65 = call i32 @read(i32 %64, i8* %41, i32 9140)
switch i32 %65, label %79 [
i32 -1, label %66
i32 0, label %74
]
66: ; preds = %61
%67 = load i64, i64* @errno
%68 = load i64, i64* @EINTR
%69 = icmp eq i64 %67, %68
br i1 %69, label %106, label %70
70: ; preds = %66
%71 = and i64 %57, 4294967295
%72 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 %71, i64 0
%73 = call i32 @print_err_prefix(i8* %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %109
74: ; preds = %61
%75 = and i64 %57, 4294967295
%76 = load i32, i32* @stderr
%77 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 %75, i64 0
%78 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %77)
br label %109
79: ; preds = %61
%80 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 %57, i64 0
%81 = call i32 @dumphex(i8** %8, i8* %41, i32 %65, i32 7, i8* %80)
%82 = load i8*, i8** %8
%83 = call i32 @puts(i8* dereferenceable(1) %82)
%84 = load i32, i32* %4
%85 = icmp eq i32 %84, 0
br i1 %85, label %106, label %86
86: ; preds = %79
%87 = add nuw nsw i64 %57, 1
%88 = icmp eq i64 %87, %48
%89 = and i64 %87, 4294967295
%90 = select i1 %88, i64 0, i64 %89
%91 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 %90, i32 0
%92 = load i64, i64* %91
%93 = trunc i64 %92 to i32
%94 = call i32 @write(i32 %93, i8* %41, i32 %65)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %103
96: ; preds = %86
%97 = load i64, i64* @errno
%98 = load i64, i64* @EINTR
%99 = icmp eq i64 %97, %98
br i1 %99, label %103, label %100
100: ; preds = %96
%101 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 %90, i64 0
%102 = call i32 @print_err_prefix(i8* %101, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 -1)
br label %109
103: ; preds = %96, %86
%104 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %6, i64 0, i64 %90, i64 0
%105 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %104, i32 %94)
br label %106
106: ; preds = %79, %103, %66, %56
%107 = add nuw nsw i64 %57, 1
%108 = icmp eq i64 %107, %48
br i1 %108, label %49, label %56
109: ; preds = %100, %74, %70, %53
%110 = icmp sgt i32 %13, 0
br i1 %110, label %111, label %122
111: ; preds = %109
%112 = zext i32 %13 to i64
br label %113
113: ; preds = %111, %113
%114 = phi i64 [ %112, %111 ], [ %115, %113 ]
%115 = add nsw i64 %114, -1
%116 = and i64 %115, 4294967295
%117 = getelementptr inbounds [16 x %struct.pollfd], [16 x %struct.pollfd]* %5, i64 0, i64 %116, i32 0
%118 = load i64, i64* %117
%119 = trunc i64 %118 to i32
%120 = call i32 @close(i32 %119)
%121 = icmp ugt i64 %114, 1
br i1 %121, label %113, label %122
122: ; preds = %113, %109
br label %123
123: ; preds = %32, %122, %19
%124 = phi i32 [ %20, %19 ], [ 0, %122 ], [ 4, %32 ]
ret i32 %124
}