#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*/ 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_REUSEADDR;
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 /*<<< orphan*/ setlimit(int);
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) {
  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]);
  }
  setlimit(100000);
  int server_socks[10];
  for (int i = 0; i < 10; 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 < 10; 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) {
      for (int i = 0; i < 10; 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++;
        printf("connections: %d, fd: %d\n", connections, sock);
      }
    }
  }
  return 0;
sock_err:
  printf("error: %s\n", strerror(errno));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd0(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x1b58,-0x3c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1263 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x186a0,%edi
call   10b0 <setlimit@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0xa,-0x74(%rbp)
jge    1385 <main+0x175>
mov    -0x3c(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x78(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x78(%rbp),%eax
movswl %ax,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <inet_pton@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
mov    0x2cfb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x7c(%rbp)
cmp    $0xffffffff,%eax
jne    12ef <main+0xdf>
jmp    1540 <main+0x330>
mov    -0x7c(%rbp),%edi
mov    0x2cef(%rip),%rax
mov    (%rax),%esi
mov    0x2cb6(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1321 <main+0x111>
jmp    1540 <main+0x330>
mov    -0x7c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1340 <main+0x130>
jmp    1540 <main+0x330>
mov    -0x7c(%rbp),%edi
mov    $0x400,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    135b <main+0x14b>
jmp    1540 <main+0x330>
mov    -0x7c(%rbp),%ecx
movslq -0x74(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x78(%rbp),%esi
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1274 <main+0x64>
jmp    138a <main+0x17a>
lea    -0x80(%rbp),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x88(%rbp)
cmpl   $0xa,-0x88(%rbp)
jge    1409 <main+0x1f9>
movslq -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edi
lea    -0x80(%rbp),%rsi
call   1120 <FD_SET@plt>
movslq -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
cmp    -0x84(%rbp),%eax
jle    13f0 <main+0x1e0>
movslq -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
mov    %eax,-0x84(%rbp)
jmp    13f5 <main+0x1e5>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    13a7 <main+0x197>
mov    -0x84(%rbp),%edi
add    $0x1,%edi
lea    -0x80(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1090 <select@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    147f <main+0x26f>
mov    0x2b88(%rip),%rax
mov    (%rax),%rax
mov    0x2b76(%rip),%rcx
cmp    (%rcx),%rax
jne    1458 <main+0x248>
jmp    138a <main+0x17a>
mov    0x2b69(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xbb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x8c(%rbp)
jle    153b <main+0x32b>
movl   $0x0,-0x90(%rbp)
cmpl   $0xa,-0x90(%rbp)
jge    1536 <main+0x326>
movslq -0x90(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edi
lea    -0x80(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%eax
jne    14c5 <main+0x2b5>
jmp    1522 <main+0x312>
movl   $0xc,-0x94(%rbp)
movslq -0x90(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rsi
lea    -0x94(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0xffffffff,-0x98(%rbp)
jne    1502 <main+0x2f2>
jmp    1540 <main+0x330>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x98(%rbp),%edx
lea    0xb1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    1496 <main+0x286>
jmp    153b <main+0x32b>
jmp    138a <main+0x17a>
mov    0x2a81(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xaf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movl   $0x1,0x2c(%rsp)
mov    $0x1b58,%ebx
cmp    $0x3,%edi
jl     123b <main+0x2b>
mov    0x8(%rsi),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebx
mov    $0x186a0,%edi
call   10b0 <setlimit@plt>
lea    0x30(%rsp),%r13
mov    0x2d8f(%rip),%r12
lea    0x2c(%rsp),%r15
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x38(%rsp)
movswl %bx,%edi
call   1050 <htons@plt>
mov    %eax,0x34(%rsp)
mov    (%r12),%edi
lea    0xd74(%rip),%rsi
mov    %r13,%rdx
call   1070 <inet_pton@plt>
mov    (%r12),%edi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     14e4 <main+0x2d4>
mov    %eax,%ebp
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    0x2cf5(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     14e4 <main+0x2d4>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     14e4 <main+0x2d4>
mov    %ebp,%edi
mov    $0x400,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     14e4 <main+0x2d4>
mov    %ebp,0x40(%rsp,%r14,4)
lea    0xcf1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r14
add    $0x1,%ebx
cmp    $0xa,%r14
jne    1260 <main+0x50>
mov    0x40(%rsp),%eax
test   %eax,%eax
mov    $0x0,%ebp
mov    %eax,0x24(%rsp)
cmovns %eax,%ebp
mov    0x44(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x20(%rsp)
cmovg  %eax,%ebp
mov    0x48(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x1c(%rsp)
cmovg  %eax,%ebp
mov    0x4c(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x18(%rsp)
cmovg  %eax,%ebp
mov    0x50(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x14(%rsp)
cmovg  %eax,%ebp
mov    0x54(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x10(%rsp)
cmovg  %eax,%ebp
mov    0x58(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0xc(%rsp)
cmovg  %eax,%ebp
mov    0x5c(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x8(%rsp)
cmovg  %eax,%ebp
mov    0x60(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,0x4(%rsp)
cmovg  %eax,%ebp
mov    0x64(%rsp),%eax
cmp    %ebp,%eax
mov    %eax,(%rsp)
cmovg  %eax,%ebp
add    $0x1,%ebp
lea    0x74(%rsp),%r14
lea    0x28(%rsp),%r12
xor    %ebx,%ebx
jmp    13ea <main+0x1da>
nopl   0x0(%rax,%rax,1)
mov    0x2bf1(%rip),%rax
mov    (%rax),%rdi
mov    0x2bdf(%rip),%rax
cmp    (%rax),%rdi
jne    1515 <main+0x305>
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    0x24(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x20(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x1c(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x18(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x14(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x10(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    (%rsp),%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <select@plt>
test   %eax,%eax
js     13d0 <main+0x1c0>
je     13ea <main+0x1da>
xor    %r15d,%r15d
jmp    14b3 <main+0x2a3>
nopl   (%rax)
add    $0x1,%ebx
lea    0xb9b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r15
cmp    $0xa,%r15
je     13ea <main+0x1da>
mov    0x40(%rsp,%r15,4),%r13d
mov    %r13d,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %eax,%eax
je     14a5 <main+0x295>
movl   $0xc,0x28(%rsp)
mov    %r13d,%edi
lea    0x30(%rsp),%rsi
mov    %r12,%rdx
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
jne    1490 <main+0x280>
mov    0x2add(%rip),%rax
mov    (%rax),%rdi
call   1110 <strerror@plt>
lea    0xb54(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
call   1110 <strerror@plt>
lea    0xb02(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

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

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