#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
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 socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEPORT;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int send(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i = 0;
  int server_socket;
  if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket()");
    exit(1);
  }
  int yes = 1;
  if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(int)) ==
      -1) {
    perror("setsockopt()");
    exit(1);
  }
  struct sockaddr_in server_addr;
  memset((void *)&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5555);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(server_socket, (struct sockaddr *)&server_addr,
           sizeof(server_addr)) < 0) {
    perror("bind()");
    exit(1);
  }
  if (listen(server_socket, 5) < 0) {
    perror("listen()");
    exit(1);
  }
  int accept_socket;
  struct sockaddr_in client_addr;
  socklen_t client_addr_len = sizeof(client_addr);
  char buffer[1024];
  int iDataNum;
  int client_socket[4] = {0};
  int timeout_ctr = 0;
  while (1) {
    fd_set read_fds;
    FD_ZERO(&read_fds);
    FD_SET(server_socket, &read_fds);
    int maxsock = server_socket;
    for (i = 0; i < 4; i++) {
      if (client_socket[i] != 0) {
        FD_SET(client_socket[i], &read_fds);
        if (client_socket[i] > maxsock) {
          maxsock = client_socket[i];
        }
      }
    }
    int ret;
    struct timeval tv;
    tv.tv_sec = 3;
    tv.tv_usec = 0;
    printf("select() ... start\n");
    ret = select(maxsock + 1, &read_fds, NULL, NULL, &tv);
    if (ret < 0) {
      perror("select()");
      exit(1);
    } else if (ret == 0) {
      printf("select() waitting timeout ... (R)(%d) maxsock = %d\n",
             timeout_ctr, maxsock);
      ++timeout_ctr;
      continue;
    }
    printf("select() ... end\n");
    if (FD_ISSET(server_socket, &read_fds)) {
      accept_socket = accept(server_socket, (struct sockaddr *)&client_addr,
                             &client_addr_len);
      if (accept_socket < 0) {
        perror("accept()");
        break;
      }
      printf("accept() ... done\n");
      printf("Server socket fd = %d\n", server_socket);
      printf("Accept socket fd = %d\n", accept_socket);
      for (i = 0; i < 4; i++) {
        if (client_socket[i] == 0) {
          client_socket[i] = accept_socket;
          printf("new client[%d] %s:%d\n", i, inet_ntoa(client_addr.sin_addr),
                 ntohs(client_addr.sin_port));
          break;
        }
      }
      if (i == 4) {
        send(accept_socket, "sorry overload!", sizeof("sorry overload!"), 0);
        close(accept_socket);
        break;
      }
    }
    for (i = 0; i < 4; i++) {
      if (client_socket[i] != 0 && FD_ISSET(client_socket[i], &read_fds)) {
        ret = recv(client_socket[i], buffer, sizeof(buffer), 0);
        if (ret <= 0) {
          printf("client[%d] close\n", i);
          close(client_socket[i]);
          FD_CLR(client_socket[i], &read_fds);
          client_socket[i] = 0;
        } else {
          printf("client[%d] msg:%s\n", i, buffer);
          fd_set write_fds = read_fds;
          ret = select(maxsock + 1, NULL, &write_fds, NULL, &tv);
          if (ret < 0) {
            perror("select()");
            exit(1);
          } else if (ret == 0) {
            printf("select() waitting timeout ... (W)(%d)\n", timeout_ctr);
            ++timeout_ctr;
            continue;
          }
          int j = 0;
          for (j = 0; j < 4; j++) {
            if (client_socket[i] != 0 &&
                FD_ISSET(client_socket[i], &write_fds)) {
              if (send(client_socket[j], buffer, sizeof(buffer), 0) == -1) {
                perror("send()");
              }
            }
          }
        }
      }
    }
  }
  printf("close server socket ... start\n");
  close(server_socket);
  printf("close server socket ... done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12ab <main+0x5b>
lea    0xd64(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
mov    0x2d13(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12f5 <main+0xa5>
lea    0xd23(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x15b3,%edi
call   1070 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1110 <bind@plt>
cmp    $0x0,%rax
jge    1360 <main+0x110>
lea    0xcc5(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x5,%esi
call   10f0 <listen@plt>
cmp    $0x0,%rax
jge    138d <main+0x13d>
lea    0xc9f(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movl   $0xc,-0x3c(%rbp)
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <memset@plt>
movl   $0x0,-0x464(%rbp)
lea    -0x468(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0x18(%rbp),%edi
lea    -0x468(%rbp),%rsi
call   1160 <FD_SET@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x46c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    144f <main+0x1ff>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x460(%rbp,%rax,4)
je     143c <main+0x1ec>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
lea    -0x468(%rbp),%rsi
call   1160 <FD_SET@plt>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%eax
cmp    -0x46c(%rbp),%eax
jle    1437 <main+0x1e7>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%eax
mov    %eax,-0x46c(%rbp)
jmp    143c <main+0x1ec>
jmp    1441 <main+0x1f1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13dc <main+0x18c>
movl   $0x3,-0x480(%rbp)
movq   $0x0,-0x478(%rbp)
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x46c(%rbp),%edi
add    $0x1,%edi
lea    -0x468(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x480(%rbp),%r8
mov    %rcx,%rdx
call   10e0 <select@plt>
mov    %eax,-0x470(%rbp)
cmpl   $0x0,-0x470(%rbp)
jge    14be <main+0x26e>
lea    0xb8b(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
cmpl   $0x0,-0x470(%rbp)
jne    14f9 <main+0x2a9>
mov    -0x464(%rbp),%esi
mov    -0x46c(%rbp),%edx
lea    0xb65(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x464(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x464(%rbp)
jmp    13b1 <main+0x161>
jmp    14fe <main+0x2ae>
lea    0xb72(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x468(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     163b <main+0x3eb>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1130 <accept@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1553 <main+0x303>
lea    0xb40(%rip),%rdi
call   1120 <perror@plt>
jmp    1870 <main+0x620>
lea    0xb38(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xb3a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xb40(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1609 <main+0x3b9>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x460(%rbp,%rax,4)
jne    15f6 <main+0x3a6>
mov    -0x2c(%rbp),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x460(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
mov    %eax,-0x494(%rbp)
mov    -0x34(%rbp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,-0x490(%rbp)
mov    -0x38(%rbp),%edi
call   1100 <ntohs@plt>
mov    -0x494(%rbp),%esi
mov    -0x490(%rbp),%rdx
mov    %eax,%ecx
lea    0xae9(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1609 <main+0x3b9>
jmp    15fb <main+0x3ab>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    158a <main+0x33a>
cmpl   $0x4,-0x14(%rbp)
jne    1636 <main+0x3e6>
mov    -0x2c(%rbp),%edi
lea    0xacc(%rip),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    -0x2c(%rbp),%edi
call   10c0 <close@plt>
jmp    1870 <main+0x620>
jmp    163b <main+0x3eb>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    186b <main+0x61b>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x460(%rbp,%rax,4)
je     1858 <main+0x608>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
lea    -0x468(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1858 <main+0x608>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x470(%rbp)
cmpl   $0x0,-0x470(%rbp)
jg     16fc <main+0x4ac>
mov    -0x14(%rbp),%esi
lea    0xa3f(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
call   10c0 <close@plt>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
lea    -0x468(%rbp),%rsi
call   1140 <FD_CLR@plt>
movslq -0x14(%rbp),%rax
movl   $0x0,-0x460(%rbp,%rax,4)
jmp    1853 <main+0x603>
mov    -0x14(%rbp),%esi
lea    -0x440(%rbp),%rdx
lea    0x9fe(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x468(%rbp),%eax
mov    %eax,-0x484(%rbp)
mov    -0x46c(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x484(%rbp),%rdx
lea    -0x480(%rbp),%r8
mov    %rcx,%rsi
call   10e0 <select@plt>
mov    %eax,-0x470(%rbp)
cmpl   $0x0,-0x470(%rbp)
jge    176c <main+0x51c>
lea    0x8dd(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
cmpl   $0x0,-0x470(%rbp)
jne    17a1 <main+0x551>
mov    -0x464(%rbp),%esi
lea    0x998(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x464(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x464(%rbp)
jmp    185d <main+0x60d>
jmp    17a6 <main+0x556>
movl   $0x0,-0x488(%rbp)
movl   $0x0,-0x488(%rbp)
cmpl   $0x4,-0x488(%rbp)
jge    184e <main+0x5fe>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x460(%rbp,%rax,4)
je     1835 <main+0x5e5>
movslq -0x14(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
lea    -0x484(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1835 <main+0x5e5>
movslq -0x488(%rbp),%rax
mov    -0x460(%rbp,%rax,4),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    1830 <main+0x5e0>
lea    0x91a(%rip),%rdi
call   1120 <perror@plt>
jmp    1835 <main+0x5e5>
jmp    183a <main+0x5ea>
mov    -0x488(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x488(%rbp)
jmp    17ba <main+0x56a>
jmp    1853 <main+0x603>
jmp    1858 <main+0x608>
jmp    185d <main+0x60d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1642 <main+0x3f2>
jmp    13b1 <main+0x161>
lea    0x8d5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%edi
call   10c0 <close@plt>
lea    0x8de(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %eax,%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
mov    0x2d68(%rip),%r14
mov    (%r14),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
test   %eax,%eax
js     1794 <main+0x534>
mov    %eax,%ebx
movl   $0x1,0x3c(%rsp)
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
lea    0x3c(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     179d <main+0x53d>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10c0 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x48(%rsp)
mov    $0x15b3,%edi
call   1080 <htons@plt>
mov    %eax,0x40(%rsp)
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,0x44(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1120 <bind@plt>
test   %rax,%rax
js     17a6 <main+0x546>
mov    %ebx,%edi
mov    $0x5,%esi
call   1100 <listen@plt>
test   %rax,%rax
js     17af <main+0x54f>
movl   $0xc,0x38(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x34(%rsp),%r15
xor    %ebp,%ebp
movl   $0x0,0xc(%rsp)
mov    %ebx,0x28(%rsp)
jmp    1368 <main+0x108>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%ebp
mov    0x28(%rsp),%ebx
mov    %r15,%rdi
call   10e0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1170 <FD_SET@plt>
mov    %ebx,%r12d
test   %ebp,%ebp
je     1394 <main+0x134>
mov    %ebp,%edi
mov    %r15,%rsi
call   1170 <FD_SET@plt>
cmp    %ebx,%ebp
mov    %ebx,%r12d
cmovg  %ebp,%r12d
mov    0x14(%rsp),%r13d
test   %r13d,%r13d
je     13b0 <main+0x150>
mov    %r13d,%edi
mov    %r15,%rsi
call   1170 <FD_SET@plt>
cmp    %r12d,%r13d
cmovg  %r13d,%r12d
mov    0x18(%rsp),%r14d
test   %r14d,%r14d
mov    %ebp,0x2c(%rsp)
je     13d0 <main+0x170>
mov    %r14d,%edi
mov    %r15,%rsi
call   1170 <FD_SET@plt>
cmp    %r12d,%r14d
cmovg  %r14d,%r12d
mov    0x1c(%rsp),%ebp
test   %ebp,%ebp
je     13e9 <main+0x189>
mov    %ebp,%edi
mov    %r15,%rsi
call   1170 <FD_SET@plt>
cmp    %r12d,%ebp
cmovg  %ebp,%r12d
movl   $0x3,0x50(%rsp)
movq   $0x0,0x58(%rsp)
lea    0xd12(%rip),%rdi
call   1040 <puts@plt>
lea    0x1(%r12),%edi
mov    %edi,0x30(%rsp)
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x50(%rsp),%r8
call   10f0 <select@plt>
test   %eax,%eax
js     177e <main+0x51e>
je     16f0 <main+0x490>
lea    0xcf1(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1515 <main+0x2b5>
mov    %ebx,%edi
lea    0x60(%rsp),%rsi
lea    0x38(%rsp),%rdx
call   1140 <accept@plt>
test   %eax,%eax
js     1770 <main+0x510>
mov    %eax,%r12d
test   %r14d,%r14d
sete   %r14b
test   %r13d,%r13d
sete   0x7(%rsp)
mov    %ebx,%r15d
xor    %ebx,%ebx
cmpl   $0x0,0x2c(%rsp)
setne  %bl
sete   %r13b
lea    0xce2(%rip),%rdi
call   1040 <puts@plt>
lea    0xbd0(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xbd6(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
or     0x7(%rsp),%r13b
or     %r13b,%r14b
test   %r13b,%r13b
mov    $0x2,%eax
cmove  %eax,%ebx
test   %r14b,%r14b
mov    $0x3,%eax
cmove  %eax,%ebx
jne    14df <main+0x27f>
test   %ebp,%ebp
jne    171b <main+0x4bb>
mov    %ebx,%eax
mov    %r12d,0x10(%rsp,%rax,4)
mov    0x64(%rsp),%edi
call   1070 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x60(%rsp),%edi
call   1110 <ntohs@plt>
lea    0xb98(%rip),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x34(%rsp),%r15
xor    %ebp,%ebp
lea    0x70(%rsp),%r12
lea    0xb9d(%rip),%r13
mov    0x30(%rsp),%ebx
jmp    155e <main+0x2fe>
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,%edi
call   10d0 <close@plt>
mov    %r14d,%edi
mov    %r15,%rsi
call   1150 <FD_CLR@plt>
movl   $0x0,0x10(%rsp,%rbp,4)
add    $0x1,%rbp
cmp    $0x4,%rbp
je     1360 <main+0x100>
mov    0x10(%rsp,%rbp,4),%r14d
test   %r14d,%r14d
je     1550 <main+0x2f0>
mov    %r14d,%edi
mov    %r15,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1550 <main+0x2f0>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1529 <main+0x2c9>
lea    0xb3d(%rip),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x34(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
xor    %esi,%esi
lea    0x8(%rsp),%rdx
xor    %ecx,%ecx
lea    0x50(%rsp),%r8
call   10f0 <select@plt>
test   %eax,%eax
js     177e <main+0x51e>
je     1699 <main+0x439>
mov    %r14d,%edi
lea    0x8(%rsp),%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     15fa <main+0x39a>
mov    0x10(%rsp),%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     16bd <main+0x45d>
mov    %r14d,%edi
lea    0x8(%rsp),%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1628 <main+0x3c8>
mov    0x14(%rsp),%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     16ce <main+0x46e>
mov    %r14d,%edi
lea    0x8(%rsp),%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1656 <main+0x3f6>
mov    0x18(%rsp),%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     16df <main+0x47f>
mov    %r14d,%edi
lea    0x8(%rsp),%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1550 <main+0x2f0>
mov    0x1c(%rsp),%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
jne    1550 <main+0x2f0>
lea    0xa7d(%rip),%rdi
call   1130 <perror@plt>
jmp    1550 <main+0x2f0>
lea    0xa45(%rip),%rdi
mov    0xc(%rsp),%ebx
mov    %ebx,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
add    $0x1,%ebx
mov    %ebx,0xc(%rsp)
mov    0x30(%rsp),%ebx
jmp    1550 <main+0x2f0>
lea    0xa48(%rip),%rdi
call   1130 <perror@plt>
jmp    15fa <main+0x39a>
lea    0xa37(%rip),%rdi
call   1130 <perror@plt>
jmp    1628 <main+0x3c8>
lea    0xa26(%rip),%rdi
call   1130 <perror@plt>
jmp    1656 <main+0x3f6>
lea    0x938(%rip),%rdi
mov    %ebx,%ebp
mov    0xc(%rsp),%ebx
mov    %ebx,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
add    $0x1,%ebx
mov    %ebx,0xc(%rsp)
mov    %ebp,%ebx
mov    0x2c(%rsp),%ebp
jmp    1368 <main+0x108>
lea    0x98e(%rip),%rsi
mov    %r12d,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %r12d,%edi
call   10d0 <close@plt>
mov    0x28(%rsp),%ebx
lea    0x9f3(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   10d0 <close@plt>
lea    0x9fe(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x478,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8ec(%rip),%rdi
call   1130 <perror@plt>
jmp    173d <main+0x4dd>
lea    0x8a1(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0x865(%rip),%rdi
jmp    1785 <main+0x525>
lea    0x865(%rip),%rdi
jmp    1785 <main+0x525>
lea    0x869(%rip),%rdi
jmp    1785 <main+0x525>
lea    0x867(%rip),%rdi
jmp    1785 <main+0x525>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [13 x i8] c"setsockopt()\00"
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"bind()\00"
@.str.3 = [9 x i8] c"listen()\00"
@.str.4 = [20 x i8] c"select() ... start\0A\00"
@.str.5 = [9 x i8] c"select()\00"
@.str.6 = [52 x i8] c"select() waitting timeout ... (R)(%d) maxsock = %d\0A\00"
@.str.7 = [18 x i8] c"select() ... end\0A\00"
@.str.8 = [9 x i8] c"accept()\00"
@.str.9 = [19 x i8] c"accept() ... done\0A\00"
@.str.10 = [23 x i8] c"Server socket fd = %d\0A\00"
@.str.11 = [23 x i8] c"Accept socket fd = %d\0A\00"
@.str.12 = [22 x i8] c"new client[%d] %s:%d\0A\00"
@.str.13 = [16 x i8] c"sorry overload!\00"
@.str.14 = [18 x i8] c"client[%d] close\0A\00"
@.str.15 = [19 x i8] c"client[%d] msg:%s\0A\00"
@.str.16 = [39 x i8] c"select() waitting timeout ... (W)(%d)\0A\00"
@.str.17 = [7 x i8] c"send()\00"
@.str.18 = [31 x i8] c"close server socket ... start\0A\00"
@.str.19 = [30 x i8] c"close server socket ... done\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 %struct.sockaddr_in
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca i32
%15 = alloca [4 x i32]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca %struct.timeval
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
store i32 1, i32* %8
%31 = load i32, i32* %7
%32 = load i32, i32* @SOL_SOCKET
%33 = load i32, i32* @SO_REUSEPORT
%34 = call i32 @setsockopt(i32 %31, i32 %32, i32 %33, i32* %8, i32 4)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = bitcast %struct.sockaddr_in* %9 to i8*
%41 = call i32 @memset(i8* %40, i32 0, i32 12)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %42, i32* %43
%44 = call i32 @htons(i32 5555)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %44, i32* %45
%46 = load i32, i32* @INADDR_ANY
%47 = call i32 @htonl(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = load i32, i32* %7
%51 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%52 = call i64 @bind(i32 %50, %struct.sockaddr* %51, i32 12)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %39
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %39
%58 = load i32, i32* %7
%59 = call i64 @listen(i32 %58, i32 5)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %57
store i32 12, i32* %12
%65 = bitcast [4 x i32]* %15 to i8*
store i32 0, i32* %16
br label %66
66: ; preds = %64, %117, %281
%67 = call i32 @FD_ZERO(i32* %17)
%68 = load i32, i32* %7
%69 = call i32 @FD_SET(i32 %68, i32* %17)
%70 = load i32, i32* %7
store i32 %70, i32* %18
store i32 0, i32* %6
br label %71
71: ; preds = %99, %66
%72 = load i32, i32* %6
%73 = icmp slt i32 %72, 4
br i1 %73, label %74, label %102
74: ; preds = %71
%75 = load i32, i32* %6
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %76
%78 = load i32, i32* %77
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %98
80: ; preds = %74
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %82
%84 = load i32, i32* %83
%85 = call i32 @FD_SET(i32 %84, i32* %17)
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %87
%89 = load i32, i32* %88
%90 = load i32, i32* %18
%91 = icmp sgt i32 %89, %90
br i1 %91, label %92, label %97
92: ; preds = %80
%93 = load i32, i32* %6
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %94
%96 = load i32, i32* %95
store i32 %96, i32* %18
br label %97
97: ; preds = %92, %80
br label %98
98: ; preds = %97, %74
br label %99
99: ; preds = %98
%100 = load i32, i32* %6
%101 = add nsw i32 %100, 1
store i32 %101, i32* %6
br label %71
102: ; preds = %71
%103 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
store i32 3, i32* %103
%104 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
store i64 0, i64* %104
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%106 = load i32, i32* %18
%107 = add nsw i32 %106, 1
%108 = call i32 @select(i32 %107, i32* %17, i32* null, i32* null, %struct.timeval* %20)
store i32 %108, i32* %19
%109 = load i32, i32* %19
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %102
%112 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %102
%115 = load i32, i32* %19
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %123
117: ; preds = %114
%118 = load i32, i32* %16
%119 = load i32, i32* %18
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i32 %118, i32 %119)
%121 = load i32, i32* %16
%122 = add nsw i32 %121, 1
store i32 %122, i32* %16
br label %66
123: ; preds = %114
br label %124
124: ; preds = %123
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%126 = load i32, i32* %7
%127 = call i64 @FD_ISSET(i32 %126, i32* %17)
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %179
129: ; preds = %124
%130 = load i32, i32* %7
%131 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%132 = call i32 @accept(i32 %130, %struct.sockaddr* %131, i32* %12)
store i32 %132, i32* %10
%133 = load i32, i32* %10
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %129
%136 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %282
137: ; preds = %129
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%139 = load i32, i32* %7
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %139)
%141 = load i32, i32* %10
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i32 %141)
store i32 0, i32* %6
br label %143
143: ; preds = %167, %137
%144 = load i32, i32* %6
%145 = icmp slt i32 %144, 4
br i1 %145, label %146, label %170
146: ; preds = %143
%147 = load i32, i32* %6
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %148
%150 = load i32, i32* %149
%151 = icmp eq i32 %150, 0
br i1 %151, label %152, label %166
152: ; preds = %146
%153 = load i32, i32* %10
%154 = load i32, i32* %6
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %155
store i32 %153, i32* %156
%157 = load i32, i32* %6
%158 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%159 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %158, i32 0, i32 0
%160 = load i32, i32* %159
%161 = call i8* @inet_ntoa(i32 %160)
%162 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%163 = load i32, i32* %162
%164 = call i32 @ntohs(i32 %163)
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %157, i8* %161, i32 %164)
br label %170
166: ; preds = %146
br label %167
167: ; preds = %166
%168 = load i32, i32* %6
%169 = add nsw i32 %168, 1
store i32 %169, i32* %6
br label %143
170: ; preds = %152, %143
%171 = load i32, i32* %6
%172 = icmp eq i32 %171, 4
br i1 %172, label %173, label %178
173: ; preds = %170
%174 = load i32, i32* %10
%175 = call i32 @send(i32 %174, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 16, i32 0)
%176 = load i32, i32* %10
%177 = call i32 @close(i32 %176)
br label %282
178: ; preds = %170
br label %179
179: ; preds = %178, %124
store i32 0, i32* %6
br label %180
180: ; preds = %278, %179
%181 = load i32, i32* %6
%182 = icmp slt i32 %181, 4
br i1 %182, label %183, label %281
183: ; preds = %180
%184 = load i32, i32* %6
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %185
%187 = load i32, i32* %186
%188 = icmp ne i32 %187, 0
br i1 %188, label %189, label %277
189: ; preds = %183
%190 = load i32, i32* %6
%191 = sext i32 %190 to i64
%192 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %191
%193 = load i32, i32* %192
%194 = call i64 @FD_ISSET(i32 %193, i32* %17)
%195 = icmp ne i64 %194, 0
br i1 %195, label %196, label %277
196: ; preds = %189
%197 = load i32, i32* %6
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %198
%200 = load i32, i32* %199
%201 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%202 = call i32 @recv(i32 %200, i8* %201, i32 1024, i32 0)
store i32 %202, i32* %19
%203 = load i32, i32* %19
%204 = icmp sle i32 %203, 0
br i1 %204, label %205, label %221
205: ; preds = %196
%206 = load i32, i32* %6
%207 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %206)
%208 = load i32, i32* %6
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %209
%211 = load i32, i32* %210
%212 = call i32 @close(i32 %211)
%213 = load i32, i32* %6
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %214
%216 = load i32, i32* %215
%217 = call i32 @FD_CLR(i32 %216, i32* %17)
%218 = load i32, i32* %6
%219 = sext i32 %218 to i64
%220 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %219
store i32 0, i32* %220
br label %276
221: ; preds = %196
%222 = load i32, i32* %6
%223 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%224 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0), i32 %222, i8* %223)
%225 = load i32, i32* %17
store i32 %225, i32* %21
%226 = load i32, i32* %18
%227 = add nsw i32 %226, 1
%228 = call i32 @select(i32 %227, i32* null, i32* %21, i32* null, %struct.timeval* %20)
store i32 %228, i32* %19
%229 = load i32, i32* %19
%230 = icmp slt i32 %229, 0
br i1 %230, label %231, label %234
231: ; preds = %221
%232 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%233 = call i32 @exit(i32 1)
unreachable
234: ; preds = %221
%235 = load i32, i32* %19
%236 = icmp eq i32 %235, 0
br i1 %236, label %237, label %242
237: ; preds = %234
%238 = load i32, i32* %16
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.16, i64 0, i64 0), i32 %238)
%240 = load i32, i32* %16
%241 = add nsw i32 %240, 1
store i32 %241, i32* %16
br label %278
242: ; preds = %234
br label %243
243: ; preds = %242
store i32 0, i32* %22
store i32 0, i32* %22
br label %244
244: ; preds = %272, %243
%245 = load i32, i32* %22
%246 = icmp slt i32 %245, 4
br i1 %246, label %247, label %275
247: ; preds = %244
%248 = load i32, i32* %6
%249 = sext i32 %248 to i64
%250 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %249
%251 = load i32, i32* %250
%252 = icmp ne i32 %251, 0
br i1 %252, label %253, label %271
253: ; preds = %247
%254 = load i32, i32* %6
%255 = sext i32 %254 to i64
%256 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %255
%257 = load i32, i32* %256
%258 = call i64 @FD_ISSET(i32 %257, i32* %21)
%259 = icmp ne i64 %258, 0
br i1 %259, label %260, label %271
260: ; preds = %253
%261 = load i32, i32* %22
%262 = sext i32 %261 to i64
%263 = getelementptr inbounds [4 x i32], [4 x i32]* %15, i64 0, i64 %262
%264 = load i32, i32* %263
%265 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%266 = call i32 @send(i32 %264, i8* %265, i32 1024, i32 0)
%267 = icmp eq i32 %266, -1
br i1 %267, label %268, label %270
268: ; preds = %260
%269 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %270
270: ; preds = %268, %260
br label %271
271: ; preds = %270, %253, %247
br label %272
272: ; preds = %271
%273 = load i32, i32* %22
%274 = add nsw i32 %273, 1
store i32 %274, i32* %22
br label %244
275: ; preds = %244
br label %276
276: ; preds = %275, %205
br label %277
277: ; preds = %276, %189, %183
br label %278
278: ; preds = %277, %237
%279 = load i32, i32* %6
%280 = add nsw i32 %279, 1
store i32 %280, i32* %6
br label %180
281: ; preds = %180
br label %66
282: ; preds = %173, %135
%283 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.18, i64 0, i64 0))
%284 = load i32, i32* %7
%285 = call i32 @close(i32 %284)
%286 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.19, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [13 x i8] c"setsockopt()\00"
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"bind()\00"
@.str.3 = [9 x i8] c"listen()\00"
@.str.5 = [9 x i8] c"select()\00"
@.str.6 = [52 x i8] c"select() waitting timeout ... (R)(%d) maxsock = %d\0A\00"
@.str.8 = [9 x i8] c"accept()\00"
@.str.10 = [23 x i8] c"Server socket fd = %d\0A\00"
@.str.11 = [23 x i8] c"Accept socket fd = %d\0A\00"
@.str.12 = [22 x i8] c"new client[%d] %s:%d\0A\00"
@.str.13 = [16 x i8] c"sorry overload!\00"
@.str.14 = [18 x i8] c"client[%d] close\0A\00"
@.str.15 = [19 x i8] c"client[%d] msg:%s\0A\00"
@.str.16 = [39 x i8] c"select() waitting timeout ... (W)(%d)\0A\00"
@.str.17 = [7 x i8] c"send()\00"
@str = [19 x i8] c"select() ... start\00"
@str.20 = [17 x i8] c"select() ... end\00"
@str.21 = [30 x i8] c"close server socket ... start\00"
@str.22 = [29 x i8] c"close server socket ... done\00"
@str.23 = [18 x i8] c"accept() ... done\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 i32
%7 = alloca [1024 x i8]
%8 = alloca [4 x i32]
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = alloca i32
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_REUSEPORT
%23 = call i32 @setsockopt(i32 %14, i32 %21, i32 %22, i32* %3, i32 4)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = bitcast %struct.sockaddr_in* %4 to i8*
%30 = call i32 @memset(i8* %29, 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 = call i32 @htons(i32 5555)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %36, i32* %37
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%39 = call i64 @bind(i32 %14, %struct.sockaddr* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %28
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %28
%45 = call i64 @listen(i32 %14, i32 5)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %44
%51 = bitcast %struct.sockaddr_in* %5 to i8*
%52 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%54 = bitcast [4 x i32]* %8 to i8*
%55 = bitcast i32* %9 to i8*
%56 = bitcast %struct.timeval* %10 to i8*
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
%58 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
%59 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%62 = bitcast i32* %11 to i8*
%63 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%64 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%65 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%66 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
br label %67
67: ; preds = %221, %50
%68 = phi i32 [ 0, %50 ], [ %222, %221 ]
%69 = phi i32 [ 0, %50 ], [ %223, %221 ]
%70 = call i32 @FD_ZERO(i32* %9)
%71 = call i32 @FD_SET(i32 %14, i32* %9)
%72 = icmp eq i32 %68, 0
br i1 %72, label %77, label %73
73: ; preds = %67
%74 = call i32 @FD_SET(i32 %68, i32* %9)
%75 = icmp sgt i32 %68, %14
%76 = select i1 %75, i32 %68, i32 %14
br label %77
77: ; preds = %73, %67
%78 = phi i32 [ %14, %67 ], [ %76, %73 ]
%79 = load i32, i32* %64
%80 = icmp eq i32 %79, 0
br i1 %80, label %85, label %81
81: ; preds = %77
%82 = call i32 @FD_SET(i32 %79, i32* %9)
%83 = icmp sgt i32 %79, %78
%84 = select i1 %83, i32 %79, i32 %78
br label %85
85: ; preds = %81, %77
%86 = phi i32 [ %78, %77 ], [ %84, %81 ]
%87 = load i32, i32* %65
%88 = icmp eq i32 %87, 0
br i1 %88, label %93, label %89
89: ; preds = %85
%90 = call i32 @FD_SET(i32 %87, i32* %9)
%91 = icmp sgt i32 %87, %86
%92 = select i1 %91, i32 %87, i32 %86
br label %93
93: ; preds = %89, %85
%94 = phi i32 [ %86, %85 ], [ %92, %89 ]
%95 = load i32, i32* %66
%96 = icmp eq i32 %95, 0
br i1 %96, label %101, label %97
97: ; preds = %93
%98 = call i32 @FD_SET(i32 %95, i32* %9)
%99 = icmp sgt i32 %95, %94
%100 = select i1 %99, i32 %95, i32 %94
br label %101
101: ; preds = %97, %93
%102 = phi i32 [ %94, %93 ], [ %100, %97 ]
store i32 3, i32* %57
store i64 0, i64* %58
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%104 = add nsw i32 %102, 1
%105 = call i32 @select(i32 %104, i32* %9, i32* null, i32* null, %struct.timeval* %10)
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %101
%108 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %101
%111 = icmp eq i32 %105, 0
br i1 %111, label %112, label %115
112: ; preds = %110
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i32 %69, i32 %102)
%114 = add nsw i32 %69, 1
br label %221
115: ; preds = %110
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.20, i64 0, i64 0))
%117 = call i64 @FD_ISSET(i32 %14, i32* %9)
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %120
119: ; preds = %136, %115
br label %147
120: ; preds = %115
%121 = call i32 @accept(i32 %14, %struct.sockaddr* %59, i32* %6)
%122 = icmp slt i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %120
%124 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %224
125: ; preds = %120
%126 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.23, i64 0, i64 0))
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %14)
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i32 %121)
%129 = select i1 %72, i1 true, i1 %80
%130 = xor i1 %72, true
%131 = zext i1 %130 to i32
%132 = select i1 %129, i1 true, i1 %88
%133 = select i1 %129, i32 %131, i32 2
%134 = select i1 %132, i1 true, i1 %96
%135 = select i1 %132, i32 %133, i32 3
br i1 %134, label %136, label %144
136: ; preds = %125
%137 = zext i32 %135 to i64
%138 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %137
store i32 %121, i32* %138
%139 = load i32, i32* %60
%140 = call i8* @inet_ntoa(i32 %139)
%141 = load i32, i32* %61
%142 = call i32 @ntohs(i32 %141)
%143 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %135, i8* %140, i32 %142)
br label %119
144: ; preds = %125
%145 = call i32 @send(i32 %121, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 16, i32 0)
%146 = call i32 @close(i32 %121)
br label %224
147: ; preds = %119, %215
%148 = phi i64 [ %217, %215 ], [ 0, %119 ]
%149 = phi i32 [ %216, %215 ], [ %69, %119 ]
%150 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %148
%151 = load i32, i32* %150
%152 = icmp eq i32 %151, 0
br i1 %152, label %215, label %153
153: ; preds = %147
%154 = call i64 @FD_ISSET(i32 %151, i32* %9)
%155 = icmp eq i64 %154, 0
br i1 %155, label %215, label %156
156: ; preds = %153
%157 = call i32 @recv(i32 %151, i8* %53, i32 1024, i32 0)
%158 = icmp slt i32 %157, 1
%159 = trunc i64 %148 to i32
br i1 %158, label %160, label %164
160: ; preds = %156
%161 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %159)
%162 = call i32 @close(i32 %151)
%163 = call i32 @FD_CLR(i32 %151, i32* %9)
store i32 0, i32* %150
br label %215
164: ; preds = %156
%165 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0), i32 %159, i8* %53)
%166 = load i32, i32* %9
store i32 %166, i32* %11
%167 = call i32 @select(i32 %104, i32* null, i32* %11, i32* null, %struct.timeval* %10)
%168 = icmp slt i32 %167, 0
br i1 %168, label %169, label %172
169: ; preds = %164
%170 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%171 = call i32 @exit(i32 1)
unreachable
172: ; preds = %164
%173 = icmp eq i32 %167, 0
br i1 %173, label %177, label %174
174: ; preds = %172
%175 = call i64 @FD_ISSET(i32 %151, i32* %11)
%176 = icmp eq i64 %175, 0
br i1 %176, label %186, label %180
177: ; preds = %172
%178 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.16, i64 0, i64 0), i32 %149)
%179 = add nsw i32 %149, 1
br label %213
180: ; preds = %174
%181 = load i32, i32* %63
%182 = call i32 @send(i32 %181, i8* %53, i32 1024, i32 0)
%183 = icmp eq i32 %182, -1
br i1 %183, label %184, label %186
184: ; preds = %180
%185 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %186
186: ; preds = %174, %184, %180
%187 = call i64 @FD_ISSET(i32 %151, i32* %11)
%188 = icmp eq i64 %187, 0
br i1 %188, label %195, label %189
189: ; preds = %186
%190 = load i32, i32* %64
%191 = call i32 @send(i32 %190, i8* %53, i32 1024, i32 0)
%192 = icmp eq i32 %191, -1
br i1 %192, label %193, label %195
193: ; preds = %189
%194 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %195
195: ; preds = %193, %189, %186
%196 = call i64 @FD_ISSET(i32 %151, i32* %11)
%197 = icmp eq i64 %196, 0
br i1 %197, label %204, label %198
198: ; preds = %195
%199 = load i32, i32* %65
%200 = call i32 @send(i32 %199, i8* %53, i32 1024, i32 0)
%201 = icmp eq i32 %200, -1
br i1 %201, label %202, label %204
202: ; preds = %198
%203 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %204
204: ; preds = %202, %198, %195
%205 = call i64 @FD_ISSET(i32 %151, i32* %11)
%206 = icmp eq i64 %205, 0
br i1 %206, label %213, label %207
207: ; preds = %204
%208 = load i32, i32* %66
%209 = call i32 @send(i32 %208, i8* %53, i32 1024, i32 0)
%210 = icmp eq i32 %209, -1
br i1 %210, label %211, label %213
211: ; preds = %207
%212 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %213
213: ; preds = %204, %207, %211, %177
%214 = phi i32 [ %179, %177 ], [ %149, %211 ], [ %149, %207 ], [ %149, %204 ]
br label %215
215: ; preds = %213, %147, %153, %160
%216 = phi i32 [ %149, %160 ], [ %214, %213 ], [ %149, %153 ], [ %149, %147 ]
%217 = add nuw nsw i64 %148, 1
%218 = icmp eq i64 %217, 4
br i1 %218, label %219, label %147
219: ; preds = %215
%220 = load i32, i32* %63
br label %221
221: ; preds = %219, %112
%222 = phi i32 [ %68, %112 ], [ %220, %219 ]
%223 = phi i32 [ %114, %112 ], [ %216, %219 ]
br label %67
224: ; preds = %123, %144
%225 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.21, i64 0, i64 0))
%226 = call i32 @close(i32 %14)
%227 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.22, i64 0, i64 0))
ret i32 0
}