#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;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ 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 /*<<< orphan*/ read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int listenfd, connfd, sockfd;
  socklen_t socklen;
  struct sockaddr_in svaddr, cliaddr;
  int ret, i;
  ssize_t n;
  int maxi, maxfd, nready, client[FD_SETSIZE];
  fd_set rset, allset;
  char buf[100];
  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;
  }
  maxfd = listenfd;
  maxi = -1;
  for (i = 0; i < FD_SETSIZE; ++i)
    client[i] = -1;
  FD_ZERO(&allset);
  FD_SET(listenfd, &allset);
  socklen = sizeof(cliaddr);
  while (1) {
    rset = allset;
    nready = select(maxfd + 1, &rset, NULL, NULL, NULL);
    if (FD_ISSET(listenfd, &rset)) {
      connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &socklen);
      for (i = 0; i < FD_SETSIZE; ++i) {
        if (client[i] < 0) {
          client[i] = connfd;
          break;
        }
      }
      if (i == FD_SETSIZE) {
        fprintf(stderr, "Too many clients\n");
        exit(EXIT_FAILURE);
      }
      FD_SET(connfd, &allset);
      if (connfd > maxfd)
        maxfd = connfd;
      if (i > maxi)
        maxi = i;
      if (--nready <= 0)
        continue;
    }
    for (i = 0; i <= maxi; ++i) {
      if ((sockfd = client[i]) < 0)
        continue;
      if (FD_ISSET(sockfd, &rset)) {
        if ((n = read(sockfd, buf, 100)) == 0) {
          close(sockfd);
          FD_CLR(sockfd, &allset);
          client[i] = -1;
        } else {
          write(sockfd, buf, n);
        }
        if (--nready <= 0)
          break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xf0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12d9 <main+0xb9>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf4(%rbp)
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xf4(%rbp),%edi
mov    %rax,%rdx
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xe4(%rbp)
jmp    1655 <main+0x435>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x2710,%edi
call   1050 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1383 <main+0x163>
mov    0x2c98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf8(%rbp)
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xf8(%rbp),%edi
mov    %rax,%rdx
lea    0xcb7(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xe4(%rbp)
jmp    1655 <main+0x435>
mov    -0x14(%rbp),%edi
mov    $0x80,%esi
call   10d0 <listen@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    13ef <main+0x1cf>
mov    0x2c2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xfc(%rbp)
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xfc(%rbp),%edi
mov    %rax,%rdx
lea    0xc5e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xe4(%rbp)
jmp    1655 <main+0x435>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
movl   $0xffffffff,-0x50(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2bb3(%rip),%rcx
cmp    (%rcx),%eax
jge    1435 <main+0x215>
mov    -0xf0(%rbp),%rax
movslq -0x48(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1403 <main+0x1e3>
lea    -0x70(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1130 <FD_SET@plt>
movl   $0xc,-0x20(%rbp)
jmp    1456 <main+0x236>
mov    -0x70(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x54(%rbp),%edi
add    $0x1,%edi
lea    -0x6c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10c0 <select@plt>
mov    %eax,-0x58(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x6c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     157c <main+0x35c>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2b0d(%rip),%rcx
cmp    (%rcx),%eax
jge    14f9 <main+0x2d9>
mov    -0xf0(%rbp),%rax
movslq -0x48(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    14e6 <main+0x2c6>
mov    -0xf0(%rbp),%rax
mov    -0x18(%rbp),%edx
movslq -0x48(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    14f9 <main+0x2d9>
jmp    14eb <main+0x2cb>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    14a9 <main+0x289>
mov    -0x48(%rbp),%eax
mov    0x2abd(%rip),%rcx
cmp    (%rcx),%eax
jne    1530 <main+0x310>
mov    0x2abe(%rip),%rax
mov    (%rax),%edi
lea    0xb22(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2a87(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x18(%rbp),%eax
cmp    -0x54(%rbp),%eax
jle    154e <main+0x32e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x50(%rbp),%eax
jle    1560 <main+0x340>
mov    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x58(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
jg     1577 <main+0x357>
jmp    1451 <main+0x231>
jmp    157c <main+0x35c>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x50(%rbp),%eax
jg     1650 <main+0x430>
mov    -0xf0(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    15ae <main+0x38e>
jmp    1642 <main+0x422>
mov    -0x1c(%rbp),%edi
lea    -0x6c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     163d <main+0x41d>
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x64,%edx
call   1090 <read@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jne    160f <main+0x3ef>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x1c(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1100 <FD_CLR@plt>
mov    -0xf0(%rbp),%rax
movslq -0x48(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    1621 <main+0x401>
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1030 <write@plt>
mov    -0x58(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
jg     1638 <main+0x418>
jmp    1650 <main+0x430>
jmp    163d <main+0x41d>
jmp    1642 <main+0x422>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1583 <main+0x363>
jmp    1451 <main+0x231>
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rsp,%r15
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2d8c(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
je     12fb <main+0xdb>
mov    %eax,%r14d
lea    -0x50(%rbp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%rbx),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x2710,%edi
call   1050 <htons@plt>
mov    %eax,-0x50(%rbp)
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
je     1327 <main+0x107>
mov    %r14d,%edi
mov    $0x80,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1370 <main+0x150>
mov    0x2cee(%rip),%rax
mov    (%rax),%ebx
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xd2f(%rip),%rsi
jmp    1345 <main+0x125>
mov    0x2cce(%rip),%rax
mov    (%rax),%ebx
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xce7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1359 <main+0x139>
mov    0x2ca2(%rip),%rax
mov    (%rax),%ebx
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xcd0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    %r15,%rsp
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c49(%rip),%rax
mov    (%rax),%edx
test   %edx,%edx
jle    138e <main+0x16e>
shl    $0x2,%rdx
mov    %r12,%rdi
mov    $0xff,%esi
call   1070 <memset@plt>
lea    -0x2c(%rbp),%rbx
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1130 <FD_SET@plt>
movl   $0xc,-0x44(%rbp)
mov    $0xffffffff,%r13d
mov    %r14d,%eax
mov    %rax,-0x40(%rbp)
jmp    13bf <main+0x19f>
mov    -0x38(%rbp),%r13
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
lea    0x1(%rax),%edi
lea    -0x30(%rbp),%rbx
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10c0 <select@plt>
mov    %eax,%r15d
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1475 <main+0x255>
mov    %r13,-0x38(%rbp)
mov    %r14d,%edi
lea    -0x70(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,%r13d
mov    0x2bac(%rip),%rax
mov    (%rax),%eax
xor    %ebx,%ebx
test   %eax,%eax
jle    1439 <main+0x219>
nopl   0x0(%rax)
cmpl   $0x0,(%r12,%rbx,4)
js     1435 <main+0x215>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1420 <main+0x200>
jmp    1513 <main+0x2f3>
mov    %r13d,(%r12,%rbx,4)
cmp    %eax,%ebx
je     1513 <main+0x2f3>
mov    %r13d,%edi
lea    -0x2c(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x40(%rbp),%rax
cmp    %eax,%r13d
cmovg  %r13d,%eax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%r13
cmp    %r13d,%ebx
cmovg  %ebx,%r13d
cmp    $0x2,%r15d
jl     13bf <main+0x19f>
add    $0xffffffff,%r15d
test   %r13d,%r13d
js     13bf <main+0x19f>
mov    %r13,-0x38(%rbp)
lea    0x1(%r13),%eax
mov    %rax,-0x60(%rbp)
xor    %r13d,%r13d
jmp    14b8 <main+0x298>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x58(%rbp),%rcx
lea    -0x1(%rcx),%eax
cmp    $0x2,%ecx
mov    %eax,%r15d
jl     150a <main+0x2ea>
add    $0x1,%r13
cmp    %r13,-0x60(%rbp)
je     13bb <main+0x19b>
mov    (%r12,%r13,4),%ebx
test   %ebx,%ebx
js     14aa <main+0x28a>
mov    %ebx,%edi
lea    -0x30(%rbp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     14aa <main+0x28a>
mov    %r15,-0x58(%rbp)
mov    %ebx,%edi
lea    -0xe0(%rbp),%r15
mov    %r15,%rsi
mov    $0x64,%edx
call   1090 <read@plt>
test   %eax,%eax
jne    148f <main+0x26f>
mov    %ebx,%edi
call   1080 <close@plt>
mov    %ebx,%edi
lea    -0x2c(%rbp),%rsi
call   1100 <FD_CLR@plt>
movl   $0xffffffff,(%r12,%r13,4)
ff
jmp    149b <main+0x27b>
mov    -0x38(%rbp),%r13
jmp    13bf <main+0x19f>
mov    0x2ab6(%rip),%rax
mov    (%rax),%edi
lea    0xb1a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2a7f(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

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

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