#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct pollfd {
  int fd;
  int events;
  int revents;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ srvaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int Accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ Bind(int, struct sockaddr *, int);
int /*<<< orphan*/ Close(int);
scalar_t__ ECONNRESET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ Listen(int, int);
int POLLERR;
int POLLRDNORM;
int Poll(struct pollfd *, int, int);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ Writen(int, char *, scalar_t__);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ err_sys(char *);
scalar_t__ errno;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ read(int, char *, int);
int main(void) {
  int i, maxi, listenfd, connfd, sockfd;
  int nready;
  ssize_t n;
  char buf[1024];
  struct pollfd client[1024];
  struct sockaddr_in srvaddr;
  listenfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&srvaddr, 0, sizeof(srvaddr));
  srvaddr.sin_family = AF_INET;
  srvaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  srvaddr.sin_port = htons(9877);
  Bind(listenfd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
  Listen(listenfd, 1024);
  client[0].fd = listenfd;
  client[0].events = POLLRDNORM;
  for (i = 1; i < 1024; ++i)
    client[i].fd = -1;
  maxi = 0;
  for (;;) {
    nready = Poll(client, maxi + 1, -1);
    if (client[0].revents & POLLRDNORM) {
      connfd = Accept(listenfd, NULL, NULL);
      for (i = 1; i < 1024; ++i) {
        if (client[i].fd < 0) {
          client[i].fd = connfd;
          break;
        }
      }
      if (i == 1024)
        err_quit("too many clients");
      client[i].events = POLLRDNORM;
      if (i > maxi)
        maxi = i;
      if (--nready <= 0)
        continue;
    }
    for (i = 1; i <= maxi; ++i) {
      if ((sockfd = client[i].fd) < 0)
        continue;
      if (client[i].revents & (POLLRDNORM | POLLERR)) {
        if ((n = read(sockfd, buf, 1024)) < 0) {
          if (errno == ECONNRESET) {
            Close(sockfd);
            client[i].fd = -1;
          } else
            err_sys("read error");
        } else if (n == 0) {
          Close(sockfd);
          client[i].fd = -1;
        } else
          Writen(sockfd, buf, n);
        if (--nready <= 0)
          continue;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3440,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <Socket@plt>
mov    %eax,-0x10(%rbp)
lea    -0x3440(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3438(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x343c(%rbp)
mov    $0x2695,%edi
call   1050 <htons@plt>
mov    %eax,-0x3440(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x3440(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <Bind@plt>
mov    -0x10(%rbp),%edi
mov    $0x400,%esi
call   10a0 <Listen@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x3430(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x342c(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    12b7 <main+0xe7>
movslq -0x8(%rbp),%rcx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1284 <main+0xb4>
movl   $0x0,-0xc(%rbp)
lea    -0x3430(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    $0xffffffff,%edx
call   10c0 <Poll@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x3428(%rbp),%eax
mov    0x2cfb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13c5 <main+0x1f5>
mov    -0x10(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1040 <Accept@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    1360 <main+0x190>
movslq -0x8(%rbp),%rcx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    134d <main+0x17d>
mov    -0x14(%rbp),%ecx
movslq -0x8(%rbp),%rdx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
jmp    1360 <main+0x190>
jmp    1352 <main+0x182>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1309 <main+0x139>
cmpl   $0x400,-0x8(%rbp)
jne    1379 <main+0x1a9>
lea    0xc8c(%rip),%rdi
call   1080 <err_quit@plt>
mov    0x2c60(%rip),%rax
mov    (%rax),%ecx
movslq -0x8(%rbp),%rdx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    13a9 <main+0x1d9>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jg     13c0 <main+0x1f0>
jmp    12be <main+0xee>
jmp    13c5 <main+0x1f5>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1518 <main+0x348>
movslq -0x8(%rbp),%rcx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    13fd <main+0x22d>
jmp    150a <main+0x33a>
movslq -0x8(%rbp),%rcx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    0x2bc7(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bb6(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1505 <main+0x335>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    14a1 <main+0x2d1>
mov    0x2b58(%rip),%rax
mov    (%rax),%rax
mov    0x2b5e(%rip),%rcx
cmp    (%rcx),%rax
jne    1490 <main+0x2c0>
mov    -0x18(%rbp),%edi
call   10d0 <Close@plt>
movslq -0x8(%rbp),%rcx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
jmp    149c <main+0x2cc>
lea    0xb7a(%rip),%rdi
call   1030 <err_sys@plt>
jmp    14e9 <main+0x319>
cmpq   $0x0,-0x28(%rbp)
jne    14d1 <main+0x301>
mov    -0x18(%rbp),%edi
call   10d0 <Close@plt>
movslq -0x8(%rbp),%rcx
lea    -0x3430(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
jmp    14e4 <main+0x314>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   10f0 <Writen@plt>
jmp    14e9 <main+0x319>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jg     1500 <main+0x330>
jmp    150a <main+0x33a>
jmp    1505 <main+0x335>
jmp    150a <main+0x33a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    13cc <main+0x1fc>
jmp    12be <main+0xee>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3428,%rsp
mov    0x2e00(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <Socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x2695,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10b0 <Bind@plt>
mov    %ebx,%edi
mov    $0x400,%esi
call   10a0 <Listen@plt>
mov    %ebx,0xc(%rsp)
mov    %ebx,0x420(%rsp)
mov    0x2d7b(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x424(%rsp)
mov    $0x24,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0xffffffff,0x408(%rsp,%rax,1)
ff ff ff ff
movl   $0xffffffff,0x414(%rsp,%rax,1)
ff ff ff ff
movl   $0xffffffff,0x420(%rsp,%rax,1)
ff ff ff ff
add    $0x24,%rax
cmp    $0x3018,%rax
jne    1280 <main+0xb0>
xor    %r14d,%r14d
lea    0x420(%rsp),%rbp
mov    0x2d19(%rip),%r15
jmp    12d8 <main+0x108>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x420(%rsp),%rbp
lea    0x1(%r14),%esi
mov    %rbp,%rdi
mov    $0xffffffff,%edx
call   10c0 <Poll@plt>
mov    %eax,%ebx
mov    (%r12),%eax
test   %eax,0x428(%rsp)
je     13b2 <main+0x1e2>
mov    0xc(%rsp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <Accept@plt>
mov    $0x1,%ecx
mov    $0x3,%esi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
cmpl   $0x0,0x42c(%rsp,%rdx,1)
js     1366 <main+0x196>
cmpl   $0x0,0x438(%rsp,%rdx,1)
js     1372 <main+0x1a2>
cmpl   $0x0,0x444(%rsp,%rdx,1)
js     1382 <main+0x1b2>
add    $0x3,%rcx
add    $0x24,%rdx
add    $0x3,%rsi
cmp    $0x2ff4,%rdx
jne    1320 <main+0x150>
lea    0xca6(%rip),%rdi
call   1080 <err_quit@plt>
mov    $0x400,%ecx
jmp    1391 <main+0x1c1>
add    %rsp,%rdx
add    $0x42c,%rdx
jmp    138f <main+0x1bf>
add    $0x1,%rcx
add    %rsp,%rdx
add    $0x438,%rdx
jmp    138f <main+0x1bf>
add    %rsp,%rdx
add    $0x444,%rdx
mov    %rsi,%rcx
mov    %eax,(%rdx)
mov    (%r12),%eax
mov    %ecx,%edx
lea    (%rdx,%rdx,2),%rdx
mov    %eax,0x424(%rsp,%rdx,4)
cmp    %r14d,%ecx
cmovg  %ecx,%r14d
cmp    $0x2,%ebx
jl     12d8 <main+0x108>
test   %r14d,%r14d
jle    12d8 <main+0x108>
mov    %r14d,%eax
shl    $0x2,%rax
lea    (%rax,%rax,2),%r13
add    $0xc,%r13
mov    $0xc,%ebp
jmp    13fd <main+0x22d>
mov    %ebx,%edi
call   10d0 <Close@plt>
movl   $0xffffffff,0x420(%rsp,%rbp,1)
ff ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xc,%rbp
cmp    %rbp,%r13
je     12d0 <main+0x100>
mov    0x420(%rsp,%rbp,1),%ebx
test   %ebx,%ebx
js     13f0 <main+0x220>
mov    (%r15),%eax
or     (%r12),%eax
test   %eax,0x428(%rsp,%rbp,1)
je     13f0 <main+0x220>
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %rax,%rax
js     1441 <main+0x271>
je     13d1 <main+0x201>
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
mov    %rax,%rdx
call   10f0 <Writen@plt>
jmp    13f0 <main+0x220>
mov    0x2b68(%rip),%rax
mov    (%rax),%rax
mov    0x2b6e(%rip),%rcx
cmp    (%rcx),%rax
je     13d1 <main+0x201>
lea    0xbaf(%rip),%rdi
call   1030 <err_sys@plt>
jmp    13f0 <main+0x220>

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@POLLRDNORM = global i32 0
@.str = [17 x i8] c"too many clients\00"
@POLLERR = global i32 0
@errno = global i64 0
@ECONNRESET = global i64 0
@.str.1 = [11 x i8] c"read error\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x %struct.pollfd]
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = bitcast [1024 x %struct.pollfd]* %2 to i8*
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @Socket(i32 %7, i32 %8, i32 0)
%10 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = call i32 @htons(i32 9877)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @Bind(i32 %9, %struct.sockaddr* %18, i32 12)
%20 = call i32 @Listen(i32 %9, i32 1024)
%21 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
store i32 %9, i32* %21
%22 = load i32, i32* @POLLRDNORM
%23 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
store i32 %22, i32* %23
br label %27
24: ; preds = %27
%25 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 0
%26 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 0, i32 2
br label %36
27: ; preds = %27, %0
%28 = phi i64 [ 1, %0 ], [ %34, %27 ]
%29 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %28, i32 0
store i32 -1, i32* %29
%30 = add nuw nsw i64 %28, 1
%31 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %30, i32 0
store i32 -1, i32* %31
%32 = add nuw nsw i64 %28, 2
%33 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %32, i32 0
store i32 -1, i32* %33
%34 = add nuw nsw i64 %28, 3
%35 = icmp eq i64 %34, 1024
br i1 %35, label %24, label %27
36: ; preds = %81, %24
%37 = phi i32 [ 0, %24 ], [ %82, %81 ]
%38 = add nsw i32 %37, 1
%39 = call i32 @Poll(%struct.pollfd* %25, i32 %38, i32 -1)
%40 = load i32, i32* %26
%41 = load i32, i32* @POLLRDNORM
%42 = and i32 %41, %40
%43 = icmp eq i32 %42, 0
br i1 %43, label %78, label %44
44: ; preds = %36
%45 = call i32 @Accept(i32 %9, i32* null, i32* null)
br label %46
46: ; preds = %65, %44
%47 = phi i64 [ 1, %44 ], [ %66, %65 ]
%48 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %47, i32 0
%49 = load i32, i32* %48
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %60, %55, %46
%52 = phi i64 [ %47, %46 ], [ %56, %55 ], [ %61, %60 ]
%53 = phi i32* [ %48, %46 ], [ %57, %55 ], [ %62, %60 ]
%54 = trunc i64 %52 to i32
store i32 %45, i32* %53
br label %70
55: ; preds = %46
%56 = add nuw nsw i64 %47, 1
%57 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %56, i32 0
%58 = load i32, i32* %57
%59 = icmp slt i32 %58, 0
br i1 %59, label %51, label %60
60: ; preds = %55
%61 = add nuw nsw i64 %47, 2
%62 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %61, i32 0
%63 = load i32, i32* %62
%64 = icmp slt i32 %63, 0
br i1 %64, label %51, label %65
65: ; preds = %60
%66 = add nuw nsw i64 %47, 3
%67 = icmp eq i64 %66, 1024
br i1 %67, label %68, label %46
68: ; preds = %65
%69 = call i32 @err_quit(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %70
70: ; preds = %51, %68
%71 = phi i32 [ %54, %51 ], [ 1024, %68 ]
%72 = load i32, i32* @POLLRDNORM
%73 = zext i32 %71 to i64
%74 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %73, i32 1
store i32 %72, i32* %74
%75 = icmp sgt i32 %71, %37
%76 = select i1 %75, i32 %71, i32 %37
%77 = icmp slt i32 %39, 2
br i1 %77, label %81, label %78
78: ; preds = %70, %36
%79 = phi i32 [ %76, %70 ], [ %37, %36 ]
%80 = icmp slt i32 %79, 1
br i1 %80, label %81, label %83
81: ; preds = %116, %78, %70
%82 = phi i32 [ %76, %70 ], [ %79, %78 ], [ %79, %116 ]
br label %36
83: ; preds = %78
%84 = add nuw i32 %79, 1
%85 = zext i32 %84 to i64
br label %86
86: ; preds = %83, %116
%87 = phi i64 [ 1, %83 ], [ %117, %116 ]
%88 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %87, i32 0
%89 = load i32, i32* %88
%90 = icmp slt i32 %89, 0
br i1 %90, label %116, label %91
91: ; preds = %86
%92 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %2, i64 0, i64 %87, i32 2
%93 = load i32, i32* %92
%94 = load i32, i32* @POLLRDNORM
%95 = load i32, i32* @POLLERR
%96 = or i32 %95, %94
%97 = and i32 %96, %93
%98 = icmp eq i32 %97, 0
br i1 %98, label %116, label %99
99: ; preds = %91
%100 = call i64 @read(i32 %89, i8* %4, i32 1024)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %110
102: ; preds = %99
%103 = load i64, i64* @errno
%104 = load i64, i64* @ECONNRESET
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 @Close(i32 %89)
store i32 -1, i32* %88
br label %116
108: ; preds = %102
%109 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %116
110: ; preds = %99
%111 = icmp eq i64 %100, 0
br i1 %111, label %112, label %114
112: ; preds = %110
%113 = call i32 @Close(i32 %89)
store i32 -1, i32* %88
br label %116
114: ; preds = %110
%115 = call i32 @Writen(i32 %89, i8* %4, i64 %100)
br label %116
116: ; preds = %108, %106, %114, %112, %91, %86
%117 = add nuw nsw i64 %87, 1
%118 = icmp eq i64 %117, %85
br i1 %118, label %81, label %86
}