#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 timeval {
  int tv_sec;
  int tv_usec;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ cli_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int create_socket();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void *update_data(void *arg) {
  int i, maxi, maxfd, nready;
  fd_set global_rfds, global_wfds, current_rfds, current_wfds;
  int client[FD_SETSIZE];
  char buf[1024];
  ssize_t num_bytes;
  struct timeval timeout;
  struct sockaddr_in cli_addr;
  socklen_t socklen;
  int socket_fd, connect_fd, fd;
  socket_fd = create_socket();
  if (socket_fd == -1) {
    fprintf(stderr, "create_socket() failed.\n");
    exit(EXIT_FAILURE);
  }
  maxfd = socket_fd;
  maxi = -1;
  for (i = 0; i < FD_SETSIZE; i++)
    client[i] = -1;
  FD_ZERO(&global_rfds);
  FD_ZERO(&global_wfds);
  FD_SET(socket_fd, &global_rfds);
  FD_SET(socket_fd, &global_wfds);
  printf("FD_SETSIZE = %d\n", FD_SETSIZE);
  while (1) {
    timeout.tv_sec = 5;
    timeout.tv_usec = 500 * 1000;
    current_rfds = global_rfds;
    current_wfds = global_wfds;
    nready = select(maxfd + 1, &current_rfds, &current_wfds, NULL, &timeout);
    if (FD_ISSET(socket_fd, &current_rfds)) {
      socklen = sizeof(cli_addr);
      connect_fd = accept(socket_fd, (struct sockaddr *)&cli_addr, &socklen);
      for (i = 0; i < FD_SETSIZE; ++i) {
        if (client[i] < 0) {
          printf("Client connected, i = %d\n", i);
          client[i] = connect_fd;
          break;
        }
      }
      if (i == FD_SETSIZE) {
        fprintf(stderr, "Too many clients\n");
        close(connect_fd);
        continue;
      }
      FD_SET(connect_fd, &global_rfds);
      FD_SET(connect_fd, &global_wfds);
      if (connect_fd > maxfd)
        maxfd = connect_fd;
      if (i > maxi)
        maxi = i;
    }
    if (FD_ISSET(socket_fd, &current_wfds)) {
      printf("writefds have ready\n");
      sleep(10);
    }
    for (i = 0; i <= maxi; ++i) {
      if ((fd = client[i]) < 0)
        continue;
      memset(buf, 0, sizeof(buf));
      num_bytes = 0;
      if (FD_ISSET(fd, &current_rfds)) {
        num_bytes = read(fd, buf, sizeof(buf));
        if (num_bytes <= 0) {
          close(fd);
          printf("client[%d] close\n", i);
          FD_CLR(fd, &global_rfds);
          FD_CLR(fd, &global_wfds);
          client[i] = -1;
          fd = -1;
        } else
          printf("recv [%d bytes]: %s\n", (int)num_bytes, buf);
      }
      if (FD_ISSET(fd, &current_wfds)) {
        printf("fd have ready\n");
        sleep(10);
      }
    }
  }
  close(socket_fd);
}


x86 assembly (clang, -O0):
<update_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x470(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <create_socket@plt>
mov    %eax,-0x460(%rbp)
cmpl   $0xffffffff,-0x460(%rbp)
jne    125c <update_data+0x7c>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x460(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d5b(%rip),%rcx
cmp    (%rcx),%eax
jge    12a5 <update_data+0xc5>
mov    -0x470(%rbp),%rax
movslq -0xc(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1273 <update_data+0x93>
lea    -0x1c(%rbp),%rdi
call   1090 <FD_ZERO@plt>
lea    -0x20(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x460(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10f0 <FD_SET@plt>
mov    -0x460(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10f0 <FD_SET@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f1 <update_data+0x111>
movl   $0x5,-0x450(%rbp)
movl   $0x7a120,-0x44c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x450(%rbp),%r8
call   10a0 <select@plt>
mov    %eax,-0x18(%rbp)
mov    -0x460(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1463 <update_data+0x283>
movl   $0x4,-0x45c(%rbp)
mov    -0x460(%rbp),%edi
lea    -0x458(%rbp),%rsi
lea    -0x45c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x464(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2c53(%rip),%rcx
cmp    (%rcx),%eax
jge    13df <update_data+0x1ff>
mov    -0x470(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    13cc <update_data+0x1ec>
mov    -0xc(%rbp),%esi
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x470(%rbp),%rax
mov    -0x464(%rbp),%edx
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    13df <update_data+0x1ff>
jmp    13d1 <update_data+0x1f1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    137b <update_data+0x19b>
mov    -0xc(%rbp),%eax
mov    0x2bef(%rip),%rcx
cmp    (%rcx),%eax
jne    1416 <update_data+0x236>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
lea    0xc43(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x464(%rbp),%edi
call   1060 <close@plt>
jmp    12ec <update_data+0x10c>
mov    -0x464(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10f0 <FD_SET@plt>
mov    -0x464(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10f0 <FD_SET@plt>
mov    -0x464(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    144c <update_data+0x26c>
mov    -0x464(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    145e <update_data+0x27e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1463 <update_data+0x283>
mov    -0x460(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1494 <update_data+0x2b4>
lea    0xbd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1100 <sleep@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     15ee <update_data+0x40e>
mov    -0x470(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x468(%rbp)
cmp    $0x0,%eax
jge    14c9 <update_data+0x2e9>
jmp    15e0 <update_data+0x400>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movq   $0x0,-0x448(%rbp)
mov    -0x468(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15aa <update_data+0x3ca>
mov    -0x468(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jg     1587 <update_data+0x3a7>
mov    -0x468(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%esi
lea    0xb2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x468(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10d0 <FD_CLR@plt>
mov    -0x468(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10d0 <FD_CLR@plt>
mov    -0x470(%rbp),%rax
movslq -0xc(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
movl   $0xffffffff,-0x468(%rbp)
ff ff ff
jmp    15a5 <update_data+0x3c5>
mov    -0x448(%rbp),%rax
mov    %eax,%esi
lea    -0x440(%rbp),%rdx
lea    0xadf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15aa <update_data+0x3ca>
mov    -0x468(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15db <update_data+0x3fb>
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1100 <sleep@plt>
jmp    15e0 <update_data+0x400>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    149b <update_data+0x2bb>
jmp    12ec <update_data+0x10c>

x86 assembly (clang, -O2):
<update_data>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2dcd(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %eax,%eax
call   10c0 <create_socket@plt>
cmp    $0xffffffff,%eax
je     152f <update_data+0x33f>
mov    %eax,-0x2c(%rbp)
mov    (%r15),%edx
test   %edx,%edx
jle    124e <update_data+0x5e>
shl    $0x2,%rdx
mov    %r14,%rdi
mov    $0xff,%esi
call   1060 <memset@plt>
lea    -0x38(%rbp),%r12
mov    %r12,%rdi
call   10a0 <FD_ZERO@plt>
lea    -0x34(%rbp),%r13
mov    %r13,%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x2c(%rbp),%ebx
mov    %ebx,%edi
mov    %r12,%rsi
call   1100 <FD_SET@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %ebx,%r13d
call   1100 <FD_SET@plt>
mov    (%r15),%esi
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
mov    %rax,-0x48(%rbp)
mov    %ebx,%eax
mov    %rax,-0x50(%rbp)
jmp    12b4 <update_data+0xc4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x2c(%rbp),%r13d
mov    -0x50(%rbp),%rax
lea    0x1(%rax),%r12d
jmp    12e0 <update_data+0xf0>
xchg   %ax,%ax
xor    %r13d,%r13d
cmp    %eax,%r13d
je     13a3 <update_data+0x1b3>
jmp    13e0 <update_data+0x1f0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movabs $0x7a12000000005,%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    %r12d,%edi
lea    -0x3c(%rbp),%rbx
mov    %rbx,%rsi
lea    -0x30(%rbp),%rdx
xor    %ecx,%ecx
lea    -0x60(%rbp),%r8
call   10b0 <select@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     13d0 <update_data+0x1e0>
movl   $0x4,-0x54(%rbp)
mov    %r13d,%edi
lea    -0x58(%rbp),%rsi
lea    -0x54(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,%r15d
mov    0x2c90(%rip),%rax
mov    (%rax),%eax
test   %eax,%eax
lea    -0x460(%rbp),%rbx
jle    12c0 <update_data+0xd0>
xor    %r13d,%r13d
nopl   0x0(%rax)
cmpl   $0x0,(%r14,%r13,4)
js     1380 <update_data+0x190>
add    $0x1,%r13
cmp    %r13,%rax
jne    1360 <update_data+0x170>
jmp    13a3 <update_data+0x1b3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xca3(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,(%r14,%r13,4)
mov    0x2c3c(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%r13d
jne    13e0 <update_data+0x1f0>
mov    0x2c36(%rip),%rax
mov    (%rax),%edi
lea    0xc91(%rip),%rsi
call   1090 <fprintf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    -0x2c(%rbp),%r13d
jmp    12e0 <update_data+0xf0>
nopl   0x0(%rax)
lea    -0x460(%rbp),%rbx
jmp    141a <update_data+0x22a>
nopl   0x0(%rax)
mov    %r15d,%edi
lea    -0x38(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    %r15d,%edi
lea    -0x34(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x50(%rbp),%rax
cmp    %eax,%r15d
cmovg  %r15d,%eax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
cmp    %eax,%r13d
cmovg  %r13d,%eax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%r13d
mov    %r13d,%edi
lea    -0x30(%rbp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1441 <update_data+0x251>
lea    0xc59(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1110 <sleep@plt>
cmpl   $0x0,-0x48(%rbp)
js     12b4 <update_data+0xc4>
mov    -0x48(%rbp),%rax
lea    0x1(%rax),%r13d
xor    %r12d,%r12d
jmp    146d <update_data+0x27d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%r13
je     12b0 <update_data+0xc0>
mov    (%r14,%r12,4),%r15d
test   %r15d,%r15d
js     1460 <update_data+0x270>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %r15d,%edi
lea    -0x3c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     14ff <update_data+0x30f>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %rax,%rax
jle    14c0 <update_data+0x2d0>
lea    0xbb6(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    14ff <update_data+0x30f>
mov    %r15d,%edi
call   1070 <close@plt>
lea    0xb87(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
lea    -0x38(%rbp),%rsi
call   10e0 <FD_CLR@plt>
mov    %r15d,%edi
lea    -0x34(%rbp),%rsi
call   10e0 <FD_CLR@plt>
movl   $0xffffffff,(%r14,%r12,4)
ff
mov    $0xffffffff,%r15d
mov    %r15d,%edi
lea    -0x30(%rbp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1460 <update_data+0x270>
lea    0xb62(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1110 <sleep@plt>
jmp    1460 <update_data+0x270>
mov    0x2aaa(%rip),%rax
mov    (%rax),%edi
lea    0xac1(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2a85(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@FD_SETSIZE = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"create_socket() failed.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"FD_SETSIZE = %d\0A\00"
@.str.2 = [26 x i8] c"Client connected, i = %d\0A\00"
@.str.3 = [18 x i8] c"Too many clients\0A\00"
@.str.5 = [18 x i8] c"client[%d] close\0A\00"
@.str.6 = [21 x i8] c"recv [%d bytes]: %s\0A\00"
@str = [14 x i8] c"fd have ready\00"
@str.8 = [20 x i8] c"writefds have ready\00"
define noalias i8* @update_data(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca %struct.timeval
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = load i32, i32* @FD_SETSIZE
%15 = zext i32 %14 to i64
%16 = alloca i32, i64 %15
%17 = bitcast i32* %16 to i8*
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = bitcast %struct.timeval* %7 to i8*
%20 = bitcast %struct.sockaddr_in* %8 to i8*
%21 = bitcast i32* %9 to i8*
%22 = tail call i32 (...) @create_socket()
%23 = icmp eq i32 %22, -1
br i1 %23, label %30, label %24
24: ; preds = %1
%25 = load i32, i32* @FD_SETSIZE
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = zext i32 %25 to i64
%29 = shl nuw nsw i64 %28, 2
br label %35
30: ; preds = %1
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %27, %24
%36 = call i32 @FD_ZERO(i32* %2)
%37 = call i32 @FD_ZERO(i32* %3)
%38 = call i32 @FD_SET(i32 %22, i32* %2)
%39 = call i32 @FD_SET(i32 %22, i32* %3)
%40 = load i32, i32* @FD_SETSIZE
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%44 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
br label %45
45: ; preds = %100, %35
%46 = phi i32 [ %22, %35 ], [ %91, %100 ]
%47 = phi i32 [ -1, %35 ], [ %92, %100 ]
%48 = add nsw i32 %46, 1
br label %49
49: ; preds = %45, %79
store i32 5, i32* %42
store i32 500000, i32* %43
%50 = load i32, i32* %2
store i32 %50, i32* %4
%51 = load i32, i32* %3
store i32 %51, i32* %5
%52 = call i32 @select(i32 %48, i32* %4, i32* %5, i32* null, %struct.timeval* %7)
%53 = call i64 @FD_ISSET(i32 %22, i32* %4)
%54 = icmp eq i64 %53, 0
br i1 %54, label %90, label %55
55: ; preds = %49
store i32 4, i32* %9
%56 = call i32 @accept(i32 %22, %struct.sockaddr* %44, i32* %9)
%57 = load i32, i32* @FD_SETSIZE
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %75
59: ; preds = %55
%60 = zext i32 %57 to i64
br label %61
61: ; preds = %59, %72
%62 = phi i64 [ 0, %59 ], [ %73, %72 ]
%63 = getelementptr inbounds i32, i32* %16, i64 %62
%64 = load i32, i32* %63
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %61
%67 = trunc i64 %62 to i32
%68 = and i64 %62, 4294967295
%69 = getelementptr inbounds i32, i32* %16, i64 %68
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %67)
store i32 %56, i32* %69
%71 = load i32, i32* @FD_SETSIZE
br label %75
72: ; preds = %61
%73 = add nuw nsw i64 %62, 1
%74 = icmp eq i64 %73, %60
br i1 %74, label %79, label %61
75: ; preds = %55, %66
%76 = phi i32 [ %71, %66 ], [ %57, %55 ]
%77 = phi i32 [ %67, %66 ], [ 0, %55 ]
%78 = icmp eq i32 %77, %76
br i1 %78, label %79, label %83
79: ; preds = %72, %75
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 @close(i32 %56)
br label %49
83: ; preds = %75
%84 = call i32 @FD_SET(i32 %56, i32* %2)
%85 = call i32 @FD_SET(i32 %56, i32* %3)
%86 = icmp sgt i32 %56, %46
%87 = select i1 %86, i32 %56, i32 %46
%88 = icmp sgt i32 %77, %47
%89 = select i1 %88, i32 %77, i32 %47
br label %90
90: ; preds = %49, %83
%91 = phi i32 [ %87, %83 ], [ %46, %49 ]
%92 = phi i32 [ %89, %83 ], [ %47, %49 ]
%93 = call i64 @FD_ISSET(i32 %22, i32* %5)
%94 = icmp eq i64 %93, 0
br i1 %94, label %98, label %95
95: ; preds = %90
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%97 = call i32 @sleep(i32 10)
br label %98
98: ; preds = %95, %90
%99 = icmp slt i32 %92, 0
br i1 %99, label %100, label %101
100: ; preds = %132, %98
br label %45
101: ; preds = %98
%102 = add nuw i32 %92, 1
%103 = zext i32 %102 to i64
br label %104
104: ; preds = %101, %132
%105 = phi i64 [ 0, %101 ], [ %133, %132 ]
%106 = getelementptr inbounds i32, i32* %16, i64 %105
%107 = load i32, i32* %106
%108 = icmp slt i32 %107, 0
br i1 %108, label %132, label %109
109: ; preds = %104
%110 = call i32 @memset(i8* %18, i32 0, i32 1024)
%111 = call i64 @FD_ISSET(i32 %107, i32* %4)
%112 = icmp eq i64 %111, 0
br i1 %112, label %125, label %113
113: ; preds = %109
%114 = call i64 @read(i32 %107, i8* %18, i32 1024)
%115 = icmp slt i64 %114, 1
br i1 %115, label %116, label %122
116: ; preds = %113
%117 = call i32 @close(i32 %107)
%118 = trunc i64 %105 to i32
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %118)
%120 = call i32 @FD_CLR(i32 %107, i32* %2)
%121 = call i32 @FD_CLR(i32 %107, i32* %3)
store i32 -1, i32* %106
br label %125
122: ; preds = %113
%123 = trunc i64 %114 to i32
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %123, i8* %18)
br label %125
125: ; preds = %116, %122, %109
%126 = phi i32 [ -1, %116 ], [ %107, %122 ], [ %107, %109 ]
%127 = call i64 @FD_ISSET(i32 %126, i32* %5)
%128 = icmp eq i64 %127, 0
br i1 %128, label %132, label %129
129: ; preds = %125
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%131 = call i32 @sleep(i32 10)
br label %132
132: ; preds = %125, %129, %104
%133 = add nuw nsw i64 %105, 1
%134 = icmp eq i64 %133, %103
br i1 %134, label %100, label %104
}