#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 */
typedef int /*<<< orphan*/ svaddr;
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 socklen_t;
typedef int nfds_t;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ ECONNRESET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int POLLERR;
int POLLRDNORM;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int poll(struct pollfd *, int, int);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int listenfd, connfd, sockfd;
  socklen_t socklen;
  struct sockaddr_in svaddr, cliaddr;
  int ret, i, nready;
  ssize_t n;
  char buf[100];
  nfds_t maxi;
  struct pollfd client[1024];
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  if (listenfd == -1) {
    fprintf(stderr, "socket() failed: %s\n", strerror(errno));
    return -1;
  }
  memset(&svaddr, 0, sizeof(svaddr));
  svaddr.sin_family = AF_INET;
  svaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  svaddr.sin_port = htons(10000);
  ret = bind(listenfd, (struct sockaddr *)&svaddr, sizeof(svaddr));
  if (ret == -1) {
    fprintf(stderr, "bind() failed: %s\n", strerror(errno));
    close(listenfd);
    return -1;
  }
  ret = listen(listenfd, 128);
  if (ret == -1) {
    fprintf(stderr, "listen() failed: %s\n", strerror(errno));
    close(listenfd);
    return -1;
  }
  client[0].fd = listenfd;
  client[0].events = POLLRDNORM;
  for (i = 1; i < 1024; ++i)
    client[i].fd = -1;
  maxi = 0;
  while (1) {
    nready = poll(client, maxi + 1, -1);
    if (client[0].revents & POLLRDNORM) {
      socklen = sizeof(cliaddr);
      connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &socklen);
      for (i = 1; i < 1024; ++i) {
        if (client[i].fd < 0) {
          client[i].fd = connfd;
          break;
        }
      }
      if (i == 1024) {
        fprintf(stderr, "Too many clients\n");
        exit(EXIT_FAILURE);
      }
      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, 100)) < 0) {
          if (errno == ECONNRESET) {
            close(sockfd);
            client[i].fd = -1;
          } else {
            fprintf(stderr, "read() failed: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
          }
        } else if (n == 0) {
          close(sockfd);
          client[i].fd = -1;
        } else {
          write(sockfd, buf, n);
        }
        if (--nready <= 0)
          break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1260 <main+0x80>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30d4(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x30d4(%rbp),%edi
mov    %rax,%rdx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1683 <main+0x4a3>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x2710,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1301 <main+0x121>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30d8(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x30d8(%rbp),%edi
mov    %rax,%rdx
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1683 <main+0x4a3>
mov    -0x14(%rbp),%edi
mov    $0x80,%esi
call   10a0 <listen@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1364 <main+0x184>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30dc(%rbp)
mov    0x2c77(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x30dc(%rbp),%edi
mov    %rax,%rdx
lea    0xcdf(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1683 <main+0x4a3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30d0(%rbp)
mov    0x2c6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30cc(%rbp)
movl   $0x1,-0x48(%rbp)
cmpl   $0x400,-0x48(%rbp)
jge    13b6 <main+0x1d6>
movslq -0x48(%rbp),%rcx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1383 <main+0x1a3>
movl   $0x0,-0xc4(%rbp)
lea    -0x30d0(%rbp),%rdi
mov    -0xc4(%rbp),%esi
add    $0x1,%esi
mov    $0xffffffff,%edx
call   10b0 <poll@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x30c8(%rbp),%eax
mov    0x2bf6(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14f1 <main+0x311>
movl   $0xc,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x48(%rbp)
cmpl   $0x400,-0x48(%rbp)
jge    146d <main+0x28d>
movslq -0x48(%rbp),%rcx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    145a <main+0x27a>
mov    -0x18(%rbp),%ecx
movslq -0x48(%rbp),%rdx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
jmp    146d <main+0x28d>
jmp    145f <main+0x27f>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1416 <main+0x236>
cmpl   $0x400,-0x48(%rbp)
jne    149f <main+0x2bf>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
lea    0xbb3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2b3a(%rip),%rax
mov    (%rax),%ecx
movslq -0x48(%rbp),%rdx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x48(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jle    14d5 <main+0x2f5>
mov    -0x48(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jg     14ec <main+0x30c>
jmp    13c0 <main+0x1e0>
jmp    14f1 <main+0x311>
movl   $0x1,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jg     167e <main+0x49e>
movslq -0x48(%rbp),%rcx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    152c <main+0x34c>
jmp    1670 <main+0x490>
movslq -0x48(%rbp),%rcx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    0x2a98(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2a87(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     166b <main+0x48b>
mov    -0x1c(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jge    1607 <main+0x427>
mov    0x2a21(%rip),%rax
mov    (%rax),%rax
mov    0x2a2f(%rip),%rcx
cmp    (%rcx),%rax
jne    15bf <main+0x3df>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movslq -0x48(%rbp),%rcx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
jmp    1602 <main+0x422>
mov    0x29f2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30e0(%rbp)
mov    0x29d3(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x30e0(%rbp),%edi
mov    %rax,%rdx
lea    0xa62(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x29a5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    164f <main+0x46f>
cmpq   $0x0,-0x58(%rbp)
jne    1637 <main+0x457>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movslq -0x48(%rbp),%rcx
lea    -0x30d0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
jmp    164a <main+0x46a>
mov    -0x1c(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1030 <write@plt>
jmp    164f <main+0x46f>
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jg     1666 <main+0x486>
jmp    167e <main+0x49e>
jmp    166b <main+0x48b>
jmp    1670 <main+0x490>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    14f8 <main+0x318>
jmp    13c0 <main+0x1e0>
mov    -0x4(%rbp),%eax
add    $0x30e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30a8,%rsp
mov    0x2df0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     148f <main+0x2af>
mov    %eax,%r15d
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x2710,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     14bc <main+0x2dc>
mov    %r15d,%edi
mov    $0x80,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     14f6 <main+0x316>
mov    %r15d,0xa0(%rsp)
mov    0x2d52(%rip),%r12
mov    (%r12),%eax
mov    %eax,0xa4(%rsp)
mov    $0x24,%eax
xchg   %ax,%ax
movl   $0xffffffff,0x88(%rsp,%rax,1)
ff ff ff ff
movl   $0xffffffff,0x94(%rsp,%rax,1)
ff ff ff ff
movl   $0xffffffff,0xa0(%rsp,%rax,1)
ff ff ff ff
add    $0x24,%rax
cmp    $0x3018,%rax
jne    12a0 <main+0xc0>
xor    %r14d,%r14d
lea    0xa0(%rsp),%rbp
mov    %r15d,0x8(%rsp)
jmp    12ed <main+0x10d>
nop
mov    0x8(%rsp),%r15d
lea    0xa0(%rsp),%rbp
lea    0x1(%r14),%esi
mov    %rbp,%rdi
mov    $0xffffffff,%edx
call   10b0 <poll@plt>
mov    %eax,%ebx
mov    (%r12),%eax
test   %eax,0xa8(%rsp)
je     13d3 <main+0x1f3>
movl   $0xc,0xc(%rsp)
mov    %r15d,%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10d0 <accept@plt>
mov    $0x1,%ecx
mov    $0x3,%edx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,0xac(%rsp,%rsi,1)
js     1380 <main+0x1a0>
cmpl   $0x0,0xb8(%rsp,%rsi,1)
js     1390 <main+0x1b0>
cmpl   $0x0,0xc4(%rsp,%rsi,1)
js     13a0 <main+0x1c0>
add    $0x3,%rcx
add    $0x24,%rsi
add    $0x3,%rdx
cmp    $0x2ff4,%rsi
jne    1340 <main+0x160>
jmp    14dd <main+0x2fd>
nopl   0x0(%rax,%rax,1)
add    %rsp,%rsi
add    $0xac,%rsi
jmp    13ad <main+0x1cd>
nopl   0x0(%rax)
add    $0x1,%rcx
add    %rsp,%rsi
add    $0xb8,%rsi
jmp    13ad <main+0x1cd>
add    %rsp,%rsi
add    $0xc4,%rsi
mov    %rdx,%rcx
mov    %eax,(%rsi)
mov    (%r12),%eax
mov    %ecx,%edx
lea    (%rdx,%rdx,2),%rdx
mov    %eax,0xa4(%rsp,%rdx,4)
cmp    %ecx,%r14d
cmovl  %ecx,%r14d
cmp    $0x2,%ebx
jl     12ed <main+0x10d>
add    $0xffffffff,%ebx
test   %r14d,%r14d
jle    12ed <main+0x10d>
mov    %r14d,%eax
shl    $0x2,%rax
lea    (%rax,%rax,2),%rbp
add    $0xc,%rbp
mov    $0xc,%r13d
jmp    143c <main+0x25c>
mov    0x2bae(%rip),%rax
mov    (%rax),%rdi
mov    0x2bbc(%rip),%rax
cmp    (%rax),%rdi
jne    1540 <main+0x360>
mov    %r15d,%edi
call   1070 <close@plt>
movl   $0xffffffff,0xa0(%rsp,%r13,1)
lea    -0x1(%rbx),%eax
cmp    $0x2,%ebx
mov    %eax,%ebx
jl     12e0 <main+0x100>
add    $0xc,%r13
cmp    %r13,%rbp
je     12e0 <main+0x100>
mov    0xa0(%rsp,%r13,1),%r15d
test   %r15d,%r15d
js     142f <main+0x24f>
mov    0x2b88(%rip),%rax
mov    (%rax),%eax
or     (%r12),%eax
test   %eax,0xa8(%rsp,%r13,1)
je     142f <main+0x24f>
mov    %r15d,%edi
lea    0x30(%rsp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
test   %rax,%rax
js     13f3 <main+0x213>
je     140d <main+0x22d>
mov    %r15d,%edi
lea    0x30(%rsp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
jmp    1421 <main+0x241>
mov    0x2b22(%rip),%rax
mov    (%rax),%ebx
mov    0x2b09(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
lea    0xb52(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1529 <main+0x349>
mov    0x2af5(%rip),%rax
mov    (%rax),%ebx
mov    0x2adc(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
lea    0xb3a(%rip),%rsi
jmp    1515 <main+0x335>
mov    0x2ad4(%rip),%rax
mov    (%rax),%edi
lea    0xb50(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1561 <main+0x381>
mov    0x2abb(%rip),%rax
mov    (%rax),%ebx
mov    0x2aa2(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
lea    0xb13(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
add    $0x30a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a71(%rip),%rax
mov    (%rax),%ebx
call   10f0 <strerror@plt>
lea    0xafa(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2a38(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"socket() failed: %s\0A\00"
@errno = global i64 0
@INADDR_ANY = global i32 0
@.str.1 = [19 x i8] c"bind() failed: %s\0A\00"
@.str.2 = [21 x i8] c"listen() failed: %s\0A\00"
@POLLRDNORM = global i32 0
@.str.3 = [18 x i8] c"Too many clients\0A\00"
@EXIT_FAILURE = global i32 0
@POLLERR = global i32 0
@ECONNRESET = global i64 0
@.str.4 = [19 x i8] c"read() failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [100 x i8]
%7 = alloca [1024 x %struct.pollfd]
%8 = bitcast i32* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = bitcast [1024 x %struct.pollfd]* %7 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i64, i64* @errno
%20 = tail call i8* @strerror(i64 %19)
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %161
22: ; preds = %2
%23 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = call i32 @htons(i32 10000)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %29, i32* %30
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i32 @bind(i32 %15, %struct.sockaddr* %31, i32 12)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %40
34: ; preds = %22
%35 = load i32, i32* @stderr
%36 = load i64, i64* @errno
%37 = call i8* @strerror(i64 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @close(i32 %15)
br label %161
40: ; preds = %22
%41 = call i32 @listen(i32 %15, i32 128)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = call i32 @close(i32 %15)
br label %161
49: ; preds = %40
%50 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 0, i32 0
store i32 %15, i32* %50
%51 = load i32, i32* @POLLRDNORM
%52 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 0, i32 1
store i32 %51, i32* %52
br label %57
53: ; preds = %57
%54 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 0
%55 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 0, i32 2
%56 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %66
57: ; preds = %57, %49
%58 = phi i64 [ 1, %49 ], [ %64, %57 ]
%59 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %58, i32 0
store i32 -1, i32* %59
%60 = add nuw nsw i64 %58, 1
%61 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %60, i32 0
store i32 -1, i32* %61
%62 = add nuw nsw i64 %58, 2
%63 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %62, i32 0
store i32 -1, i32* %63
%64 = add nuw nsw i64 %58, 3
%65 = icmp eq i64 %64, 1024
br i1 %65, label %53, label %57
66: ; preds = %114, %53
%67 = phi i32 [ 0, %53 ], [ %115, %114 ]
%68 = add nsw i32 %67, 1
%69 = call i32 @poll(%struct.pollfd* %54, i32 %68, i32 -1)
%70 = load i32, i32* %55
%71 = load i32, i32* @POLLRDNORM
%72 = and i32 %71, %70
%73 = icmp eq i32 %72, 0
br i1 %73, label %110, label %74
74: ; preds = %66
store i32 12, i32* %3
%75 = call i32 @accept(i32 %15, %struct.sockaddr* %56, i32* %3)
br label %76
76: ; preds = %91, %74
%77 = phi i64 [ 1, %74 ], [ %92, %91 ]
%78 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %77, i32 0
%79 = load i32, i32* %78
%80 = icmp slt i32 %79, 0
br i1 %80, label %99, label %81
81: ; preds = %76
%82 = add nuw nsw i64 %77, 1
%83 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %82, i32 0
%84 = load i32, i32* %83
%85 = icmp slt i32 %84, 0
br i1 %85, label %99, label %86
86: ; preds = %81
%87 = add nuw nsw i64 %77, 2
%88 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %87, i32 0
%89 = load i32, i32* %88
%90 = icmp slt i32 %89, 0
br i1 %90, label %99, label %91
91: ; preds = %86
%92 = add nuw nsw i64 %77, 3
%93 = icmp eq i64 %92, 1024
br i1 %93, label %94, label %76
94: ; preds = %91
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %86, %81, %76
%100 = phi i64 [ %77, %76 ], [ %82, %81 ], [ %87, %86 ]
%101 = phi i32* [ %78, %76 ], [ %83, %81 ], [ %88, %86 ]
%102 = trunc i64 %100 to i32
store i32 %75, i32* %101
%103 = load i32, i32* @POLLRDNORM
%104 = and i64 %100, 4294967295
%105 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %104, i32 1
store i32 %103, i32* %105
%106 = icmp slt i32 %67, %102
%107 = select i1 %106, i32 %102, i32 %67
%108 = add nsw i32 %69, -1
%109 = icmp slt i32 %69, 2
br i1 %109, label %114, label %110
110: ; preds = %99, %66
%111 = phi i32 [ %108, %99 ], [ %69, %66 ]
%112 = phi i32 [ %107, %99 ], [ %67, %66 ]
%113 = icmp slt i32 %112, 1
br i1 %113, label %114, label %116
114: ; preds = %157, %154, %110, %99
%115 = phi i32 [ %107, %99 ], [ %112, %110 ], [ %112, %154 ], [ %112, %157 ]
br label %66
116: ; preds = %110
%117 = add nuw i32 %112, 1
%118 = zext i32 %117 to i64
br label %119
119: ; preds = %116, %157
%120 = phi i64 [ 1, %116 ], [ %159, %157 ]
%121 = phi i32 [ %111, %116 ], [ %158, %157 ]
%122 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %120, i32 0
%123 = load i32, i32* %122
%124 = icmp slt i32 %123, 0
br i1 %124, label %157, label %125
125: ; preds = %119
%126 = getelementptr inbounds [1024 x %struct.pollfd], [1024 x %struct.pollfd]* %7, i64 0, i64 %120, i32 2
%127 = load i32, i32* %126
%128 = load i32, i32* @POLLRDNORM
%129 = load i32, i32* @POLLERR
%130 = or i32 %129, %128
%131 = and i32 %130, %127
%132 = icmp eq i32 %131, 0
br i1 %132, label %157, label %133
133: ; preds = %125
%134 = call i64 @read(i32 %123, i8* %11, i32 100)
%135 = icmp slt i64 %134, 0
br i1 %135, label %136, label %148
136: ; preds = %133
%137 = load i64, i64* @errno
%138 = load i64, i64* @ECONNRESET
%139 = icmp eq i64 %137, %138
br i1 %139, label %140, label %142
140: ; preds = %136
%141 = call i32 @close(i32 %123)
store i32 -1, i32* %122
br label %154
142: ; preds = %136
%143 = load i32, i32* @stderr
%144 = call i8* @strerror(i64 %137)
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %144)
%146 = load i32, i32* @EXIT_FAILURE
%147 = call i32 @exit(i32 %146)
unreachable
148: ; preds = %133
%149 = icmp eq i64 %134, 0
br i1 %149, label %150, label %152
150: ; preds = %148
%151 = call i32 @close(i32 %123)
store i32 -1, i32* %122
br label %154
152: ; preds = %148
%153 = call i32 @write(i32 %123, i8* %11, i64 %134)
br label %154
154: ; preds = %150, %152, %140
%155 = add nsw i32 %121, -1
%156 = icmp slt i32 %121, 2
br i1 %156, label %114, label %157
157: ; preds = %125, %154, %119
%158 = phi i32 [ %121, %119 ], [ %155, %154 ], [ %121, %125 ]
%159 = add nuw nsw i64 %120, 1
%160 = icmp eq i64 %159, %118
br i1 %160, label %114, label %119
161: ; preds = %43, %34, %17
ret i32 -1
}