#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ opt;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ bufsize;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINTR;
int /*<<< orphan*/ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ SO_SNDBUF;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char const *,
                             int /*<<< orphan*/ *);
int listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: %s port\n", argv[0]);
    exit(0);
  }
  struct sockaddr_in addr;
  const char *ip = "0.0.0.0";
  int opt = 1;
  int bufsize;
  socklen_t optlen;
  int connections = 0;
  int base_port = 7000;
  if (argc >= 2) {
    base_port = atoi(argv[1]);
  }
  int server_socks[100];
  for (int i = 0; i < 100; i++) {
    int port = base_port + i;
    bzero(&addr, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons((short)port);
    inet_pton(AF_INET, ip, &addr.sin_addr);
    int serv_sock;
    if ((serv_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      goto sock_err;
    }
    if (setsockopt(serv_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) ==
        -1) {
      goto sock_err;
    }
    if (bind(serv_sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
      goto sock_err;
    }
    if (listen(serv_sock, 1024) == -1) {
      goto sock_err;
    }
    server_socks[i] = serv_sock;
    printf("server listen on port: %d\n", port);
  }
  while (1) {
    fd_set readset;
    FD_ZERO(&readset);
    int maxfd = 0;
    for (int i = 0; i < 100; i++) {
      FD_SET(server_socks[i], &readset);
      if (server_socks[i] > maxfd) {
        maxfd = server_socks[i];
      }
    }
    int ret = select(maxfd + 1, &readset, NULL, NULL, NULL);
    if (ret < 0) {
      if (errno == EINTR) {
        continue;
      } else {
        printf("select error! %s\n", strerror(errno));
        exit(0);
      }
    }
    if (ret == 0) {
      continue;
    }
    for (int i = 0; i < 100; i++) {
      if (!FD_ISSET(server_socks[i], &readset)) {
        continue;
      }
      socklen_t addrlen = sizeof(addr);
      int sock = accept(server_socks[i], (struct sockaddr *)&addr, &addrlen);
      if (sock == -1) {
        goto sock_err;
      }
      connections++;
      if (connections % 1000 == 999) {
        printf("connections: %d, fd: %d\n", connections, sock);
      }
      bufsize = 5000;
      setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize));
      setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
    }
  }
  return 0;
sock_err:
  printf("connections: %d\n", connections);
  printf("error: %s\n", strerror(errno));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    123f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xdca(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x1b58,-0x3c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1279 <main+0x79>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x1d4(%rbp)
cmpl   $0x64,-0x1d4(%rbp)
jge    13be <main+0x1be>
mov    -0x3c(%rbp),%eax
add    -0x1d4(%rbp),%eax
mov    %eax,-0x1d8(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1d8(%rbp),%eax
movswl %ax,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <inet_pton@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x1dc(%rbp)
cmp    $0xffffffff,%eax
jne    130d <main+0x10d>
jmp    1600 <main+0x400>
mov    -0x1dc(%rbp),%edi
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
mov    0x2c85(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1342 <main+0x142>
jmp    1600 <main+0x400>
mov    -0x1dc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1364 <main+0x164>
jmp    1600 <main+0x400>
mov    -0x1dc(%rbp),%edi
mov    $0x400,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1382 <main+0x182>
jmp    1600 <main+0x400>
mov    -0x1dc(%rbp),%ecx
movslq -0x1d4(%rbp),%rax
mov    %ecx,-0x1d0(%rbp,%rax,4)
mov    -0x1d8(%rbp),%esi
lea    0xc75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4(%rbp)
jmp    1283 <main+0x83>
jmp    13c3 <main+0x1c3>
lea    -0x1e0(%rbp),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x0,-0x1e4(%rbp)
movl   $0x0,-0x1e8(%rbp)
cmpl   $0x64,-0x1e8(%rbp)
jge    1451 <main+0x251>
movslq -0x1e8(%rbp),%rax
mov    -0x1d0(%rbp,%rax,4),%edi
lea    -0x1e0(%rbp),%rsi
call   1110 <FD_SET@plt>
movslq -0x1e8(%rbp),%rax
mov    -0x1d0(%rbp,%rax,4),%eax
cmp    -0x1e4(%rbp),%eax
jle    1438 <main+0x238>
movslq -0x1e8(%rbp),%rax
mov    -0x1d0(%rbp,%rax,4),%eax
mov    %eax,-0x1e4(%rbp)
jmp    143d <main+0x23d>
mov    -0x1e8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1e8(%rbp)
jmp    13e3 <main+0x1e3>
mov    -0x1e4(%rbp),%edi
add    $0x1,%edi
lea    -0x1e0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1090 <select@plt>
mov    %eax,-0x1ec(%rbp)
cmpl   $0x0,-0x1ec(%rbp)
jge    14ca <main+0x2ca>
mov    0x2b2d(%rip),%rax
mov    (%rax),%rax
mov    0x2b1b(%rip),%rcx
cmp    (%rcx),%rax
jne    14a3 <main+0x2a3>
jmp    13c3 <main+0x1c3>
mov    0x2b0e(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xb77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x1ec(%rbp)
jne    14dc <main+0x2dc>
jmp    13c3 <main+0x1c3>
movl   $0x0,-0x1f0(%rbp)
cmpl   $0x64,-0x1f0(%rbp)
jge    15fb <main+0x3fb>
movslq -0x1f0(%rbp),%rax
mov    -0x1d0(%rbp,%rax,4),%edi
lea    -0x1e0(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%eax
jne    151b <main+0x31b>
jmp    15e7 <main+0x3e7>
movl   $0xc,-0x1f4(%rbp)
movslq -0x1f0(%rbp),%rax
mov    -0x1d0(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rsi
lea    -0x1f4(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x1f8(%rbp)
cmpl   $0xffffffff,-0x1f8(%rbp)
jne    155b <main+0x35b>
jmp    1600 <main+0x400>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cmp    $0x3e7,%edx
jne    1592 <main+0x392>
mov    -0x38(%rbp),%esi
mov    -0x1f8(%rbp),%edx
lea    0xaba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1388,-0x30(%rbp)
mov    -0x1f8(%rbp),%edi
mov    0x2a42(%rip),%rax
mov    (%rax),%esi
mov    0x2a29(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x1f8(%rbp),%edi
mov    0x2a1b(%rip),%rax
mov    (%rax),%esi
mov    0x29f2(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x1f0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f0(%rbp)
jmp    14e6 <main+0x2e6>
jmp    13c3 <main+0x1c3>
mov    -0x38(%rbp),%esi
lea    0xa54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x29a0(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xa45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
cmp    $0x1,%edi
jle    14bb <main+0x2bb>
movl   $0x1,0xc(%rsp)
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebx
xor    %r14d,%r14d
lea    0x10(%rsp),%rbp
mov    0x2da4(%rip),%r12
xor    %r15d,%r15d
nop
mov    %rbp,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
movswl %bx,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r12),%edi
lea    0xda4(%rip),%rsi
mov    %rbp,%rdx
call   1070 <inet_pton@plt>
mov    (%r12),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1476 <main+0x276>
mov    %eax,%r13d
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d04(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1476 <main+0x276>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     1476 <main+0x276>
mov    %r13d,%edi
mov    $0x400,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     1476 <main+0x276>
mov    %r13d,0x20(%rsp,%r15,4)
lea    0xd1b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r15
add    $0x1,%ebx
cmp    $0x64,%r15
jne    1240 <main+0x40>
lea    0x1c(%rsp),%r12
xor    %r14d,%r14d
jmp    134a <main+0x14a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2c81(%rip),%rax
mov    (%rax),%rdi
mov    0x2c6f(%rip),%rax
cmp    (%rax),%rdi
jne    14c7 <main+0x2c7>
mov    %r12,%rdi
call   1080 <FD_ZERO@plt>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0x20(%rsp,%rbx,4),%r15d
mov    %r15d,%edi
mov    %r12,%rsi
call   1110 <FD_SET@plt>
cmp    %ebp,%r15d
cmovg  %r15d,%ebp
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1360 <main+0x160>
add    $0x1,%ebp
mov    %ebp,%edi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <select@plt>
test   %eax,%eax
js     1330 <main+0x130>
je     134a <main+0x14a>
xor    %ebx,%ebx
jmp    13fc <main+0x1fc>
nop
movl   $0x1388,0x8(%rsp)
mov    0x2c39(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2c1f(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
lea    0x8(%rsp),%r15
mov    %r15,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x0(%rbp),%esi
mov    0x2bed(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
je     134a <main+0x14a>
mov    0x20(%rsp,%rbx,4),%ebp
mov    %ebp,%edi
mov    %r12,%rsi
call   1040 <FD_ISSET@plt>
test   %eax,%eax
je     13ee <main+0x1ee>
movl   $0xc,0x4(%rsp)
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   10d0 <accept@plt>
cmp    $0xffffffff,%eax
je     1476 <main+0x276>
mov    %eax,%r13d
add    $0x1,%r14d
movslq %r14d,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x3e7,%eax
jne    13a0 <main+0x1a0>
lea    0xbe1(%rip),%rdi
mov    %r14d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    13a0 <main+0x1a0>
lea    0xbe1(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2b2a(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xbd2(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xb3b(%rip),%rdi
jmp    14d6 <main+0x2d6>
call   1100 <strerror@plt>
lea    0xb60(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"Usage: %s port\0A\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [27 x i8] c"server listen on port: %d\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.3 = [18 x i8] c"select error! %s\0A\00"
@.str.4 = [25 x i8] c"connections: %d, fd: %d\0A\00"
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
@.str.5 = [17 x i8] c"connections: %d\0A\00"
@.str.6 = [11 x i8] c"error: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [100 x i32]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 1, i32* %8
store i32 0, i32* %11
store i32 7000, i32* %12
%33 = load i32, i32* %4
%34 = icmp sge i32 %33, 2
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %12
br label %40
40: ; preds = %35, %32
store i32 0, i32* %14
br label %41
41: ; preds = %89, %40
%42 = load i32, i32* %14
%43 = icmp slt i32 %42, 100
br i1 %43, label %44, label %92
44: ; preds = %41
%45 = load i32, i32* %12
%46 = load i32, i32* %14
%47 = add nsw i32 %45, %46
store i32 %47, i32* %15
%48 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %49, i32* %50
%51 = load i32, i32* %15
%52 = trunc i32 %51 to i16
%53 = call i32 @htons(i16 signext %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %53, i32* %54
%55 = load i32, i32* @AF_INET
%56 = load i8*, i8** %7
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%58 = call i32 @inet_pton(i32 %55, i8* %56, i32* %57)
%59 = load i32, i32* @AF_INET
%60 = load i32, i32* @SOCK_STREAM
%61 = call i32 @socket(i32 %59, i32 %60, i32 0)
store i32 %61, i32* %16
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %64
63: ; preds = %44
br label %184
64: ; preds = %44
%65 = load i32, i32* %16
%66 = load i32, i32* @SOL_SOCKET
%67 = load i32, i32* @SO_REUSEADDR
%68 = call i32 @setsockopt(i32 %65, i32 %66, i32 %67, i32* %8, i32 4)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %71
70: ; preds = %64
br label %184
71: ; preds = %64
%72 = load i32, i32* %16
%73 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%74 = call i32 @bind(i32 %72, %struct.sockaddr* %73, i32 12)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %77
76: ; preds = %71
br label %184
77: ; preds = %71
%78 = load i32, i32* %16
%79 = call i32 @listen(i32 %78, i32 1024)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %82
81: ; preds = %77
br label %184
82: ; preds = %77
%83 = load i32, i32* %16
%84 = load i32, i32* %14
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [100 x i32], [100 x i32]* %13, i64 0, i64 %85
store i32 %83, i32* %86
%87 = load i32, i32* %15
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %82
%90 = load i32, i32* %14
%91 = add nsw i32 %90, 1
store i32 %91, i32* %14
br label %41
92: ; preds = %41
br label %93
93: ; preds = %92, %129, %138, %183
%94 = call i32 @FD_ZERO(i32* %17)
store i32 0, i32* %18
store i32 0, i32* %19
br label %95
95: ; preds = %116, %93
%96 = load i32, i32* %19
%97 = icmp slt i32 %96, 100
br i1 %97, label %98, label %119
98: ; preds = %95
%99 = load i32, i32* %19
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [100 x i32], [100 x i32]* %13, i64 0, i64 %100
%102 = load i32, i32* %101
%103 = call i32 @FD_SET(i32 %102, i32* %17)
%104 = load i32, i32* %19
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [100 x i32], [100 x i32]* %13, i64 0, i64 %105
%107 = load i32, i32* %106
%108 = load i32, i32* %18
%109 = icmp sgt i32 %107, %108
br i1 %109, label %110, label %115
110: ; preds = %98
%111 = load i32, i32* %19
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [100 x i32], [100 x i32]* %13, i64 0, i64 %112
%114 = load i32, i32* %113
store i32 %114, i32* %18
br label %115
115: ; preds = %110, %98
br label %116
116: ; preds = %115
%117 = load i32, i32* %19
%118 = add nsw i32 %117, 1
store i32 %118, i32* %19
br label %95
119: ; preds = %95
%120 = load i32, i32* %18
%121 = add nsw i32 %120, 1
%122 = call i32 @select(i32 %121, i32* %17, i32* null, i32* null, i32* null)
store i32 %122, i32* %20
%123 = load i32, i32* %20
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %135
125: ; preds = %119
%126 = load i64, i64* @errno
%127 = load i64, i64* @EINTR
%128 = icmp eq i64 %126, %127
br i1 %128, label %129, label %130
129: ; preds = %125
br label %93
130: ; preds = %125
%131 = load i64, i64* @errno
%132 = call i8* @strerror(i64 %131)
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %132)
%134 = call i32 @exit(i32 0)
unreachable
135: ; preds = %119
%136 = load i32, i32* %20
%137 = icmp eq i32 %136, 0
br i1 %137, label %138, label %139
138: ; preds = %135
br label %93
139: ; preds = %135
store i32 0, i32* %21
br label %140
140: ; preds = %180, %139
%141 = load i32, i32* %21
%142 = icmp slt i32 %141, 100
br i1 %142, label %143, label %183
143: ; preds = %140
%144 = load i32, i32* %21
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [100 x i32], [100 x i32]* %13, i64 0, i64 %145
%147 = load i32, i32* %146
%148 = call i32 @FD_ISSET(i32 %147, i32* %17)
%149 = icmp ne i32 %148, 0
br i1 %149, label %151, label %150
150: ; preds = %143
br label %180
151: ; preds = %143
store i32 12, i32* %22
%152 = load i32, i32* %21
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [100 x i32], [100 x i32]* %13, i64 0, i64 %153
%155 = load i32, i32* %154
%156 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%157 = call i32 @accept(i32 %155, %struct.sockaddr* %156, i32* %22)
store i32 %157, i32* %23
%158 = load i32, i32* %23
%159 = icmp eq i32 %158, -1
br i1 %159, label %160, label %161
160: ; preds = %151
br label %184
161: ; preds = %151
%162 = load i32, i32* %11
%163 = add nsw i32 %162, 1
store i32 %163, i32* %11
%164 = load i32, i32* %11
%165 = srem i32 %164, 1000
%166 = icmp eq i32 %165, 999
br i1 %166, label %167, label %171
167: ; preds = %161
%168 = load i32, i32* %11
%169 = load i32, i32* %23
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %168, i32 %169)
br label %171
171: ; preds = %167, %161
store i32 5000, i32* %9
%172 = load i32, i32* %23
%173 = load i32, i32* @SOL_SOCKET
%174 = load i32, i32* @SO_SNDBUF
%175 = call i32 @setsockopt(i32 %172, i32 %173, i32 %174, i32* %9, i32 4)
%176 = load i32, i32* %23
%177 = load i32, i32* @SOL_SOCKET
%178 = load i32, i32* @SO_RCVBUF
%179 = call i32 @setsockopt(i32 %176, i32 %177, i32 %178, i32* %9, i32 4)
br label %180
180: ; preds = %171, %150
%181 = load i32, i32* %21
%182 = add nsw i32 %181, 1
store i32 %182, i32* %21
br label %140
183: ; preds = %140
br label %93
184: ; preds = %160, %81, %76, %70, %63
%185 = load i32, i32* %11
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %185)
%187 = load i64, i64* @errno
%188 = call i8* @strerror(i64 %187)
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %188)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"Usage: %s port\0A\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [27 x i8] c"server listen on port: %d\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.3 = [18 x i8] c"select error! %s\0A\00"
@.str.4 = [25 x i8] c"connections: %d, fd: %d\0A\00"
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
@.str.5 = [17 x i8] c"connections: %d\0A\00"
@.str.6 = [11 x i8] c"error: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = bitcast %struct.sockaddr_in* %3 to i8*
%16 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%17 = bitcast i32* %5 to i8*
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = bitcast [100 x i32]* %6 to i8*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %29
26: ; preds = %54
%27 = bitcast i32* %7 to i8*
%28 = bitcast i32* %8 to i8*
br label %59
29: ; preds = %14, %54
%30 = phi i64 [ 0, %14 ], [ %57, %54 ]
%31 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%32 = load i32, i32* @AF_INET
store i32 %32, i32* %22
%33 = trunc i64 %30 to i32
%34 = add i32 %20, %33
%35 = trunc i32 %34 to i16
%36 = call i32 @htons(i16 signext %35)
store i32 %36, i32* %23
%37 = load i32, i32* @AF_INET
%38 = call i32 @inet_pton(i32 %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
%42 = icmp eq i32 %41, -1
br i1 %42, label %116, label %43
43: ; preds = %29
%44 = load i32, i32* @SOL_SOCKET
%45 = load i32, i32* @SO_REUSEADDR
%46 = call i32 @setsockopt(i32 %41, i32 %44, i32 %45, i32* %4, i32 4)
%47 = icmp eq i32 %46, -1
br i1 %47, label %116, label %48
48: ; preds = %43
%49 = call i32 @bind(i32 %41, %struct.sockaddr* %25, i32 12)
%50 = icmp eq i32 %49, -1
br i1 %50, label %116, label %51
51: ; preds = %48
%52 = call i32 @listen(i32 %41, i32 1024)
%53 = icmp eq i32 %52, -1
br i1 %53, label %116, label %54
54: ; preds = %51
%55 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %30
store i32 %41, i32* %55
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%57 = add nuw nsw i64 %30, 1
%58 = icmp eq i64 %57, 100
br i1 %58, label %26, label %29
59: ; preds = %26, %114
%60 = phi i32 [ %115, %114 ], [ 0, %26 ]
%61 = call i32 @FD_ZERO(i32* %7)
br label %66
62: ; preds = %66
%63 = add nsw i32 %73, 1
%64 = call i32 @select(i32 %63, i32* %7, i32* null, i32* null, i32* null)
%65 = icmp slt i32 %64, 0
br i1 %65, label %76, label %84
66: ; preds = %59, %66
%67 = phi i64 [ 0, %59 ], [ %74, %66 ]
%68 = phi i32 [ 0, %59 ], [ %73, %66 ]
%69 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %67
%70 = load i32, i32* %69
%71 = call i32 @FD_SET(i32 %70, i32* %7)
%72 = icmp sgt i32 %70, %68
%73 = select i1 %72, i32 %70, i32 %68
%74 = add nuw nsw i64 %67, 1
%75 = icmp eq i64 %74, 100
br i1 %75, label %62, label %66
76: ; preds = %62
%77 = load i64, i64* @errno
%78 = load i64, i64* @EINTR
%79 = icmp eq i64 %77, %78
br i1 %79, label %114, label %80
80: ; preds = %76
%81 = call i8* @strerror(i64 %77)
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 0)
unreachable
84: ; preds = %62
%85 = icmp eq i32 %64, 0
br i1 %85, label %114, label %86
86: ; preds = %84, %109
%87 = phi i64 [ %111, %109 ], [ 0, %84 ]
%88 = phi i32 [ %110, %109 ], [ %60, %84 ]
%89 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %87
%90 = load i32, i32* %89
%91 = call i32 @FD_ISSET(i32 %90, i32* %7)
%92 = icmp eq i32 %91, 0
br i1 %92, label %109, label %93
93: ; preds = %86
store i32 12, i32* %8
%94 = call i32 @accept(i32 %90, %struct.sockaddr* %25, i32* %8)
%95 = icmp eq i32 %94, -1
br i1 %95, label %113, label %96
96: ; preds = %93
%97 = add nsw i32 %88, 1
%98 = srem i32 %97, 1000
%99 = icmp eq i32 %98, 999
br i1 %99, label %100, label %102
100: ; preds = %96
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %97, i32 %94)
br label %102
102: ; preds = %96, %100
store i32 5000, i32* %5
%103 = load i32, i32* @SOL_SOCKET
%104 = load i32, i32* @SO_SNDBUF
%105 = call i32 @setsockopt(i32 %94, i32 %103, i32 %104, i32* %5, i32 4)
%106 = load i32, i32* @SOL_SOCKET
%107 = load i32, i32* @SO_RCVBUF
%108 = call i32 @setsockopt(i32 %94, i32 %106, i32 %107, i32* %5, i32 4)
br label %109
109: ; preds = %102, %86
%110 = phi i32 [ %97, %102 ], [ %88, %86 ]
%111 = add nuw nsw i64 %87, 1
%112 = icmp eq i64 %111, 100
br i1 %112, label %114, label %86
113: ; preds = %93
br label %116
114: ; preds = %109, %84, %76
%115 = phi i32 [ %60, %76 ], [ %60, %84 ], [ %110, %109 ]
br label %59
116: ; preds = %29, %43, %48, %51, %113
%117 = phi i32 [ %88, %113 ], [ 0, %51 ], [ 0, %48 ], [ 0, %43 ], [ 0, %29 ]
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %117)
%119 = load i64, i64* @errno
%120 = call i8* @strerror(i64 %119)
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %120)
ret i32 0
}