#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;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int POLLERR;
int POLLIN;
int _POSIX_OPEN_MAX;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ stderr;
scalar_t__ tcp_main(int);
int tcp_server_socket(int);
int main(int argc, char *argv[]) {
  int listen_fd, client_fd;
  struct pollfd client[_POSIX_OPEN_MAX];
  int i, max_i, nready;
  listen_fd = tcp_server_socket(1234);
  client[0].fd = listen_fd;
  client[0].events = POLLIN;
  for (i = 1; i < _POSIX_OPEN_MAX; i++) {
    client[i].fd = -1;
  }
  max_i = 0;
  for (;;) {
    if ((nready = poll(client, max_i + 1, -1)) < 0) {
      perror("poll error");
      exit(EXIT_FAILURE);
    }
    if (client[0].revents & POLLIN) {
      if ((client_fd = accept(listen_fd, NULL, NULL)) < 0) {
        perror("accept error");
        exit(EXIT_FAILURE);
      }
      for (i = 1; i < _POSIX_OPEN_MAX; i++) {
        if (client[i].fd < 0) {
          client[i].fd = client_fd;
          break;
        }
      }
      if (i == _POSIX_OPEN_MAX) {
        fprintf(stderr, "too many clients\n");
        exit(EXIT_FAILURE);
      }
      client[i].events = POLLIN;
      if (i > max_i)
        max_i = i;
      if (--nready <= 0)
        continue;
    }
    for (i = 1; i <= max_i; i++) {
      if (client[i].fd < 0)
        continue;
      if (client[i].revents & (POLLIN | POLLERR)) {
        if (tcp_main(client[i].fd) == 0) {
          close(client[i].fd);
          if (max_i == i)
            --max_i;
          client[i].fd = -1;
        }
        if (--nready <= 0)
          break;
      }
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    (%rax,%rax,2),%rcx
lea    0xf(,%rcx,4),%rdx
movabs $0x1ffffffff0,%rcx
and    %rcx,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    $0x4d2,%edi
call   1030 <tcp_server_socket@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    %ecx,(%rax)
mov    0x2de9(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rax)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%eax
jge    1230 <main+0xb0>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fb <main+0x7b>
movl   $0x0,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%esi
add    $0x1,%esi
mov    $0xffffffff,%edx
call   1070 <poll@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1271 <main+0xf1>
lea    0xda2(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2d59(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     139a <main+0x21a>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1090 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12bf <main+0x13f>
lea    0xd5f(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%eax
jge    131c <main+0x19c>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    1309 <main+0x189>
mov    -0x40(%rbp),%rax
mov    -0x18(%rbp),%ecx
movslq -0x2c(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
jmp    131c <main+0x19c>
jmp    130e <main+0x18e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12c6 <main+0x146>
mov    -0x2c(%rbp),%eax
mov    0x2cba(%rip),%rcx
cmp    (%rcx),%eax
jne    1351 <main+0x1d1>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xcda(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x2c7c(%rip),%rcx
mov    (%rcx),%ecx
movslq -0x2c(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    137e <main+0x1fe>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jg     1395 <main+0x215>
jmp    1237 <main+0xb7>
jmp    139a <main+0x21a>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     1488 <main+0x308>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    13ca <main+0x24a>
jmp    147a <main+0x2fa>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    0x2bf5(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bfc(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1475 <main+0x2f5>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   1040 <tcp_main@plt>
cmp    $0x0,%rax
jne    1459 <main+0x2d9>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    1444 <main+0x2c4>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jg     1470 <main+0x2f0>
jmp    1488 <main+0x308>
jmp    1475 <main+0x2f5>
jmp    147a <main+0x2fa>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    13a1 <main+0x221>
jmp    1237 <main+0xb7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e48(%rip),%r15
mov    (%r15),%eax
lea    (%rax,%rax,2),%rax
lea    0xf(,%rax,4),%rax
movabs $0x1ffffffff0,%rbx
and    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%r13
sub    %rbx,%r13
mov    %r13,%rsp
mov    $0x4d2,%edi
call   1030 <tcp_server_socket@plt>
mov    %eax,-0x2c(%rbp)
mov    %eax,0x0(%r13)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
neg    %rbx
mov    %eax,0x4(%r14,%rbx,1)
mov    (%r15),%esi
cmp    $0x2,%esi
jl     1280 <main+0x100>
lea    -0x1(%rsi),%rcx
add    $0xfffffffffffffffe,%rsi
mov    %ecx,%eax
and    $0x3,%eax
mov    $0x1,%edx
cmp    $0x3,%rsi
jb     1251 <main+0xd1>
lea    0x30(%r13),%rsi
and    $0xfffffffffffffffc,%rcx
neg    %rcx
mov    $0x1,%edx
cs nopw 0x0(%rax,%rax,1)
movl   $0xffffffff,-0x24(%rsi)
movl   $0xffffffff,-0x18(%rsi)
movl   $0xffffffff,-0xc(%rsi)
movl   $0xffffffff,(%rsi)
add    $0x30,%rsi
lea    (%rcx,%rdx,1),%rdi
add    $0x4,%rdi
add    $0x4,%rdx
cmp    $0x1,%rdi
jne    1220 <main+0xa0>
test   %rax,%rax
je     1280 <main+0x100>
lea    (%rdx,%rdx,2),%rcx
lea    0x0(,%rcx,4),%rcx
add    %r13,%rcx
shl    $0x2,%rax
lea    (%rax,%rax,2),%rax
xor    %edx,%edx
nop
movl   $0xffffffff,(%rcx,%rdx,1)
add    $0xc,%rdx
cmp    %rdx,%rax
jne    1270 <main+0xf0>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1070 <poll@plt>
test   %eax,%eax
jns    12a7 <main+0x127>
lea    0xd63(%rip),%rdi
call   1080 <perror@plt>
jmp    1418 <main+0x298>
mov    %eax,%ebx
lea    0xc(%r13),%rax
mov    %rax,-0x38(%rbp)
xor    %r14d,%r14d
mov    0x2d2d(%rip),%r12
mov    %r13,-0x40(%rbp)
jmp    12eb <main+0x16b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%r14),%esi
mov    -0x40(%rbp),%r13
mov    %r13,%rdi
mov    $0xffffffff,%edx
call   1070 <poll@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1296 <main+0x116>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
test   %eax,0x8(%r13)
je     1381 <main+0x201>
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
test   %eax,%eax
js     1426 <main+0x2a6>
mov    0x2cc7(%rip),%rcx
mov    (%rcx),%edx
mov    $0x1,%ecx
cmp    $0x2,%edx
jl     1352 <main+0x1d2>
mov    $0x1,%ecx
mov    -0x38(%rbp),%rsi
xchg   %ax,%ax
cmpl   $0x0,(%rsi)
js     1350 <main+0x1d0>
add    $0x1,%rcx
add    $0xc,%rsi
cmp    %rcx,%rdx
jne    1330 <main+0x1b0>
jmp    1403 <main+0x283>
nopw   0x0(%rax,%rax,1)
mov    %eax,(%rsi)
cmp    %edx,%ecx
je     1403 <main+0x283>
mov    0x2c77(%rip),%rax
mov    (%rax),%eax
mov    %ecx,%edx
lea    (%rdx,%rdx,2),%rdx
mov    %eax,0x4(%r13,%rdx,4)
cmp    %r14d,%ecx
cmovg  %ecx,%r14d
cmp    $0x2,%ebx
jl     12d0 <main+0x150>
add    $0xffffffff,%ebx
test   %r14d,%r14d
jle    12d0 <main+0x150>
mov    -0x38(%rbp),%r15
xor    %r13d,%r13d
jmp    13b0 <main+0x230>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %r14d,%rax
add    $0xc,%r15
cmp    %rax,%r13
jge    12d0 <main+0x150>
add    $0x1,%r13
mov    (%r15),%edi
test   %edi,%edi
js     13a0 <main+0x220>
mov    (%r12),%eax
mov    0x2c12(%rip),%rcx
or     (%rcx),%eax
test   %eax,0x8(%r15)
je     13a0 <main+0x220>
call   1040 <tcp_main@plt>
test   %rax,%rax
jne    13f5 <main+0x275>
mov    (%r15),%edi
call   1050 <close@plt>
mov    %r14d,%eax
xor    %ecx,%ecx
cmp    %rax,%r13
sete   %cl
sub    %ecx,%r14d
movl   $0xffffffff,(%r15)
cmp    $0x2,%ebx
jl     12d0 <main+0x150>
add    $0xffffffff,%ebx
jmp    13a0 <main+0x220>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xc05(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xbde(%rip),%rdi
jmp    129d <main+0x11d>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@_POSIX_OPEN_MAX = global i32 0
@POLLIN = global i32 0
@.str = [11 x i8] c"poll error\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"accept error\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"too many clients\0A\00"
@POLLERR = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @_POSIX_OPEN_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca %struct.pollfd, i64 %14
store i64 %14, i64* %9
%17 = call i32 @tcp_server_socket(i32 1234)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 0
%20 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* @POLLIN
%22 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 0
%23 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %22, i32 0, i32 1
store i32 %21, i32* %23
store i32 1, i32* %10
br label %24
24: ; preds = %33, %2
%25 = load i32, i32* %10
%26 = load i32, i32* @_POSIX_OPEN_MAX
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %30
%32 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %31, i32 0, i32 0
store i32 -1, i32* %32
br label %33
33: ; preds = %28
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %24
36: ; preds = %24
store i32 0, i32* %11
br label %37
37: ; preds = %169, %107, %36
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
%40 = call i32 @poll(%struct.pollfd* %16, i32 %39, i32 -1)
store i32 %40, i32* %12
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %37
%47 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 0
%48 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %47, i32 0, i32 2
%49 = load i32, i32* %48
%50 = load i32, i32* @POLLIN
%51 = and i32 %49, %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %109
53: ; preds = %46
%54 = load i32, i32* %6
%55 = call i32 @accept(i32 %54, i32* null, i32* null)
store i32 %55, i32* %7
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %53
store i32 1, i32* %10
br label %62
62: ; preds = %80, %61
%63 = load i32, i32* %10
%64 = load i32, i32* @_POSIX_OPEN_MAX
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %83
66: ; preds = %62
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %68
%70 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %66
%74 = load i32, i32* %7
%75 = load i32, i32* %10
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %76
%78 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %77, i32 0, i32 0
store i32 %74, i32* %78
br label %83
79: ; preds = %66
br label %80
80: ; preds = %79
%81 = load i32, i32* %10
%82 = add nsw i32 %81, 1
store i32 %82, i32* %10
br label %62
83: ; preds = %73, %62
%84 = load i32, i32* %10
%85 = load i32, i32* @_POSIX_OPEN_MAX
%86 = icmp eq i32 %84, %85
br i1 %86, label %87, label %92
87: ; preds = %83
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %83
%93 = load i32, i32* @POLLIN
%94 = load i32, i32* %10
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %95
%97 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %96, i32 0, i32 1
store i32 %93, i32* %97
%98 = load i32, i32* %10
%99 = load i32, i32* %11
%100 = icmp sgt i32 %98, %99
br i1 %100, label %101, label %103
101: ; preds = %92
%102 = load i32, i32* %10
store i32 %102, i32* %11
br label %103
103: ; preds = %101, %92
%104 = load i32, i32* %12
%105 = add nsw i32 %104, -1
store i32 %105, i32* %12
%106 = icmp sle i32 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %103
br label %37
108: ; preds = %103
br label %109
109: ; preds = %108, %46
store i32 1, i32* %10
br label %110
110: ; preds = %166, %109
%111 = load i32, i32* %10
%112 = load i32, i32* %11
%113 = icmp sle i32 %111, %112
br i1 %113, label %114, label %169
114: ; preds = %110
%115 = load i32, i32* %10
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %116
%118 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %117, i32 0, i32 0
%119 = load i32, i32* %118
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %122
121: ; preds = %114
br label %166
122: ; preds = %114
%123 = load i32, i32* %10
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %124
%126 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %125, i32 0, i32 2
%127 = load i32, i32* %126
%128 = load i32, i32* @POLLIN
%129 = load i32, i32* @POLLERR
%130 = or i32 %128, %129
%131 = and i32 %127, %130
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %165
133: ; preds = %122
%134 = load i32, i32* %10
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %135
%137 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %136, i32 0, i32 0
%138 = load i32, i32* %137
%139 = call i64 @tcp_main(i32 %138)
%140 = icmp eq i64 %139, 0
br i1 %140, label %141, label %159
141: ; preds = %133
%142 = load i32, i32* %10
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %143
%145 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %144, i32 0, i32 0
%146 = load i32, i32* %145
%147 = call i32 @close(i32 %146)
%148 = load i32, i32* %11
%149 = load i32, i32* %10
%150 = icmp eq i32 %148, %149
br i1 %150, label %151, label %154
151: ; preds = %141
%152 = load i32, i32* %11
%153 = add nsw i32 %152, -1
store i32 %153, i32* %11
br label %154
154: ; preds = %151, %141
%155 = load i32, i32* %10
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i64 %156
%158 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %157, i32 0, i32 0
store i32 -1, i32* %158
br label %159
159: ; preds = %154, %133
%160 = load i32, i32* %12
%161 = add nsw i32 %160, -1
store i32 %161, i32* %12
%162 = icmp sle i32 %161, 0
br i1 %162, label %163, label %164
163: ; preds = %159
br label %169
164: ; preds = %159
br label %165
165: ; preds = %164, %122
br label %166
166: ; preds = %165, %121
%167 = load i32, i32* %10
%168 = add nsw i32 %167, 1
store i32 %168, i32* %10
br label %110
169: ; preds = %163, %110
br label %37
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@_POSIX_OPEN_MAX = global i32 0
@POLLIN = global i32 0
@.str = [11 x i8] c"poll error\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"accept error\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"too many clients\0A\00"
@POLLERR = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @_POSIX_OPEN_MAX
%4 = zext i32 %3 to i64
%5 = alloca %struct.pollfd, i64 %4
%6 = tail call i32 @tcp_server_socket(i32 1234)
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @POLLIN
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @_POSIX_OPEN_MAX
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %30
12: ; preds = %2
%13 = zext i32 %10 to i64
%14 = add nsw i64 %13, -1
%15 = add nsw i64 %13, -2
%16 = and i64 %14, 3
%17 = icmp ult i64 %15, 3
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = and i64 %14, -4
br label %35
20: ; preds = %35, %12
%21 = phi i64 [ 1, %12 ], [ %45, %35 ]
%22 = icmp eq i64 %16, 0
br i1 %22, label %30, label %23
23: ; preds = %20, %23
%24 = phi i64 [ %27, %23 ], [ %21, %20 ]
%25 = phi i64 [ %28, %23 ], [ 0, %20 ]
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %24, i32 0
store i32 -1, i32* %26
%27 = add nuw nsw i64 %24, 1
%28 = add i64 %25, 1
%29 = icmp eq i64 %28, %16
br i1 %29, label %30, label %23
30: ; preds = %20, %23, %2
%31 = call i32 @poll(%struct.pollfd* %5, i32 1, i32 -1)
%32 = icmp slt i32 %31, 0
br i1 %32, label %48, label %33
33: ; preds = %30
%34 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 2
br label %52
35: ; preds = %35, %18
%36 = phi i64 [ 1, %18 ], [ %45, %35 ]
%37 = phi i64 [ 0, %18 ], [ %46, %35 ]
%38 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %36, i32 0
store i32 -1, i32* %38
%39 = add nuw nsw i64 %36, 1
%40 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %39, i32 0
store i32 -1, i32* %40
%41 = add nuw nsw i64 %36, 2
%42 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %41, i32 0
store i32 -1, i32* %42
%43 = add nuw nsw i64 %36, 3
%44 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %43, i32 0
store i32 -1, i32* %44
%45 = add nuw nsw i64 %36, 4
%46 = add i64 %37, 4
%47 = icmp eq i64 %46, %19
br i1 %47, label %20, label %35
48: ; preds = %136, %30
%49 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %33, %136
%53 = phi i32 [ %31, %33 ], [ %139, %136 ]
%54 = phi i32 [ 0, %33 ], [ %137, %136 ]
%55 = load i32, i32* %34
%56 = load i32, i32* @POLLIN
%57 = and i32 %56, %55
%58 = icmp eq i32 %57, 0
br i1 %58, label %97, label %59
59: ; preds = %52
%60 = call i32 @accept(i32 %6, i32* null, i32* null)
%61 = icmp slt i32 %60, 0
br i1 %61, label %67, label %62
62: ; preds = %59
%63 = load i32, i32* @_POSIX_OPEN_MAX
%64 = icmp sgt i32 %63, 1
br i1 %64, label %65, label %81
65: ; preds = %62
%66 = zext i32 %63 to i64
br label %71
67: ; preds = %59
%68 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %65, %78
%72 = phi i64 [ 1, %65 ], [ %79, %78 ]
%73 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %72, i32 0
%74 = load i32, i32* %73
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = trunc i64 %72 to i32
store i32 %60, i32* %73
br label %81
78: ; preds = %71
%79 = add nuw nsw i64 %72, 1
%80 = icmp eq i64 %79, %66
br i1 %80, label %84, label %71
81: ; preds = %62, %76
%82 = phi i32 [ %77, %76 ], [ 1, %62 ]
%83 = icmp eq i32 %82, %63
br i1 %83, label %84, label %89
84: ; preds = %81, %78
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %81
%90 = load i32, i32* @POLLIN
%91 = zext i32 %82 to i64
%92 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %91, i32 1
store i32 %90, i32* %92
%93 = icmp sgt i32 %82, %54
%94 = select i1 %93, i32 %82, i32 %54
%95 = add nsw i32 %53, -1
%96 = icmp slt i32 %53, 2
br i1 %96, label %136, label %97
97: ; preds = %89, %52
%98 = phi i32 [ %94, %89 ], [ %54, %52 ]
%99 = phi i32 [ %95, %89 ], [ %53, %52 ]
%100 = icmp slt i32 %98, 1
br i1 %100, label %136, label %101
101: ; preds = %97, %130
%102 = phi i64 [ %133, %130 ], [ 1, %97 ]
%103 = phi i32 [ %132, %130 ], [ %99, %97 ]
%104 = phi i32 [ %131, %130 ], [ %98, %97 ]
%105 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %102, i32 0
%106 = load i32, i32* %105
%107 = icmp slt i32 %106, 0
br i1 %107, label %130, label %108
108: ; preds = %101
%109 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 %102, i32 2
%110 = load i32, i32* %109
%111 = load i32, i32* @POLLIN
%112 = load i32, i32* @POLLERR
%113 = or i32 %112, %111
%114 = and i32 %113, %110
%115 = icmp eq i32 %114, 0
br i1 %115, label %130, label %116
116: ; preds = %108
%117 = call i64 @tcp_main(i32 %106)
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %126
119: ; preds = %116
%120 = load i32, i32* %105
%121 = call i32 @close(i32 %120)
%122 = zext i32 %104 to i64
%123 = icmp eq i64 %102, %122
%124 = sext i1 %123 to i32
%125 = add nsw i32 %104, %124
store i32 -1, i32* %105
br label %126
126: ; preds = %119, %116
%127 = phi i32 [ %125, %119 ], [ %104, %116 ]
%128 = add nsw i32 %103, -1
%129 = icmp slt i32 %103, 2
br i1 %129, label %136, label %130
130: ; preds = %108, %126, %101
%131 = phi i32 [ %104, %101 ], [ %127, %126 ], [ %104, %108 ]
%132 = phi i32 [ %103, %101 ], [ %128, %126 ], [ %103, %108 ]
%133 = add nuw nsw i64 %102, 1
%134 = sext i32 %131 to i64
%135 = icmp slt i64 %102, %134
br i1 %135, label %101, label %136
136: ; preds = %126, %130, %97, %89
%137 = phi i32 [ %94, %89 ], [ %98, %97 ], [ %127, %126 ], [ %131, %130 ]
%138 = add nsw i32 %137, 1
%139 = call i32 @poll(%struct.pollfd* %5, i32 %138, i32 -1)
%140 = icmp slt i32 %139, 0
br i1 %140, label %48, label %52
}