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

/* 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 FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ print(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char buf[10];
  int listenfd = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in cliaddr, servaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(8888);
  bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(listenfd, 1024);
  printf("listenfd: %d\n", listenfd);
  int client[FD_SETSIZE];
  int maxfd = listenfd;
  int maxi = -1;
  for (int i = 0; i < FD_SETSIZE; ++i) {
    client[i] = -1;
  }
  fd_set rset, allset;
  FD_ZERO(&allset);
  FD_SET(listenfd, &allset);
  for (;;) {
    rset = allset;
    int ready = select(maxfd + 1, &rset, NULL, NULL, NULL);
    printf("select [%d]\n", ready);
    if (FD_ISSET(listenfd, &rset)) {
      socklen_t children = sizeof(cliaddr);
      int connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &children);
      printf("accept [%d]\n", connfd);
      int i = 0;
      for (; i < FD_SETSIZE; ++i) {
        if (client[i] < 0) {
          client[i] = connfd;
          break;
        }
      }
      FD_SET(connfd, &allset);
      if (connfd > maxfd)
        maxfd = connfd;
      if (i > maxi)
        maxi = i;
      if (--ready <= 0)
        continue;
    }
    for (int i = 0; i <= maxi; ++i) {
      int sockfd = client[i];
      if (sockfd < 0)
        continue;
      if (FD_ISSET(sockfd, &rset)) {
        int n = read(sockfd, buf, 10);
        printf("read [%d] from %d\n", n, sockfd);
        if (n == 0) {
          printf("client closed\n");
          close(sockfd);
          FD_CLR(sockfd, &allset);
          client[i] = -1;
        } else {
          print(buf, n);
          write(sockfd, buf, n);
        }
        if (--ready <= 0)
          break;
      }
    }
  }
}


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)
mov    0x2db8(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    (%rax),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,-0x8c(%rbp)
call   1130 <socket@plt>
mov    %eax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    %rdi,-0x98(%rbp)
mov    $0xc,%esi
mov    %esi,-0x90(%rbp)
call   10f0 <bzero@plt>
mov    -0xa0(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    -0x98(%rbp),%rsi
mov    -0x90(%rbp),%edx
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%edi
call   10e0 <bind@plt>
mov    -0x20(%rbp),%edi
mov    $0x400,%esi
call   10d0 <listen@plt>
mov    -0x8c(%rbp),%eax
mov    -0x20(%rbp),%esi
lea    0xd37(%rip),%rdi
call   1060 <printf@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x54(%rbp)
movl   $0xffffffff,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2cac(%rip),%rcx
cmp    (%rcx),%eax
jge    1344 <main+0x134>
mov    -0x88(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1312 <main+0x102>
lea    -0x64(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0x20(%rbp),%edi
lea    -0x64(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x54(%rbp),%edi
add    $0x1,%edi
lea    -0x60(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10c0 <select@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%esi
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1471 <main+0x261>
movl   $0xc,-0x6c(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x6c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%esi
lea    0xc54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2be9(%rip),%rcx
cmp    (%rcx),%eax
jge    1425 <main+0x215>
mov    -0x88(%rbp),%rax
movslq -0x74(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    1412 <main+0x202>
mov    -0x88(%rbp),%rax
mov    -0x70(%rbp),%edx
movslq -0x74(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1425 <main+0x215>
jmp    1417 <main+0x207>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    13d5 <main+0x1c5>
mov    -0x70(%rbp),%edi
lea    -0x64(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x70(%rbp),%eax
cmp    -0x54(%rbp),%eax
jle    1443 <main+0x233>
mov    -0x70(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x58(%rbp),%eax
jle    1455 <main+0x245>
mov    -0x74(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x68(%rbp)
cmp    $0x0,%eax
jg     146c <main+0x25c>
jmp    1359 <main+0x149>
jmp    1471 <main+0x261>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x58(%rbp),%eax
jg     156f <main+0x35f>
mov    -0x88(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jge    14a4 <main+0x294>
jmp    1561 <main+0x351>
mov    -0x7c(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     155c <main+0x34c>
mov    -0x7c(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%esi
mov    -0x7c(%rbp),%edx
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x80(%rbp)
jne    1525 <main+0x315>
lea    0xb48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x7c(%rbp),%edi
call   1080 <close@plt>
mov    -0x7c(%rbp),%edi
lea    -0x64(%rbp),%rsi
call   1110 <FD_CLR@plt>
mov    -0x88(%rbp),%rax
movslq -0x78(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    1540 <main+0x330>
lea    -0x1a(%rbp),%rdi
mov    -0x80(%rbp),%esi
call   1090 <print@plt>
mov    -0x7c(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    -0x80(%rbp),%edx
call   1030 <write@plt>
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x68(%rbp)
cmp    $0x0,%eax
jg     1557 <main+0x347>
jmp    156f <main+0x35f>
jmp    155c <main+0x34c>
jmp    1561 <main+0x351>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1478 <main+0x268>
jmp    1359 <main+0x149>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2da0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%r12d
lea    -0x70(%rbp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x6c(%rbp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,-0x70(%rbp)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
mov    %r12d,%edi
mov    $0x400,%esi
call   10f0 <listen@plt>
lea    0xd4b(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
lea    0xf(,%rdx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %edx,%edx
jle    12f2 <main+0xc2>
shl    $0x2,%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1090 <memset@plt>
lea    -0x2c(%rbp),%r14
mov    %r14,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1140 <FD_SET@plt>
mov    $0xffffffff,%r13d
mov    %r12d,%eax
mov    %rax,-0x48(%rbp)
mov    %rbx,%rcx
mov    %r12d,-0x3c(%rbp)
mov    %rbx,-0x38(%rbp)
jmp    1338 <main+0x108>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x3c(%rbp),%r12d
mov    -0x58(%rbp),%r13
mov    -0x2c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
lea    0x1(%rax),%edi
lea    -0x40(%rbp),%rbx
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10e0 <select@plt>
mov    %eax,%r14d
lea    0xcac(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13e0 <main+0x1b0>
movl   $0xc,-0x4c(%rbp)
mov    %r12d,%edi
lea    -0x88(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,%r15d
xor    %ebx,%ebx
lea    0xc7a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%eax
test   %eax,%eax
jle    13f2 <main+0x1c2>
xor    %ebx,%ebx
mov    -0x38(%rbp),%rcx
nopl   (%rax)
cmpl   $0x0,(%rcx,%rbx,4)
js     13ee <main+0x1be>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    13c0 <main+0x190>
mov    %eax,%ebx
jmp    13f2 <main+0x1c2>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x38(%rbp),%rcx
test   %r13d,%r13d
jns    142f <main+0x1ff>
jmp    1338 <main+0x108>
mov    %r15d,(%rcx,%rbx,4)
mov    %r15d,%edi
lea    -0x2c(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x48(%rbp),%rax
cmp    %eax,%r15d
cmovg  %r15d,%eax
mov    %rax,-0x48(%rbp)
cmp    %r13d,%ebx
cmovg  %ebx,%r13d
cmp    $0x2,%r14d
mov    -0x38(%rbp),%rcx
jl     1338 <main+0x108>
add    $0xffffffff,%r14d
test   %r13d,%r13d
js     1338 <main+0x108>
mov    %r14,-0x60(%rbp)
mov    %r13,-0x58(%rbp)
lea    0x1(%r13),%r14d
xor    %ebx,%ebx
lea    -0x7a(%rbp),%r13
jmp    1461 <main+0x231>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x38(%rbp),%rcx
add    $0x1,%rbx
cmp    %rbx,%r14
je     1330 <main+0x100>
mov    (%rcx,%rbx,4),%r15d
test   %r15d,%r15d
js     1454 <main+0x224>
mov    %r15d,%edi
lea    -0x40(%rbp),%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1450 <main+0x220>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0xa,%edx
call   10c0 <read@plt>
mov    %eax,%r12d
lea    0xb93(%rip),%rdi
mov    %eax,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
test   %r12d,%r12d
je     14c5 <main+0x295>
mov    %r13,%rdi
mov    %r12d,%esi
call   10b0 <print@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r12d,%edx
call   1040 <write@plt>
mov    -0x38(%rbp),%rcx
jmp    14f0 <main+0x2c0>
lea    0xb6f(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r15d,%edi
lea    -0x2c(%rbp),%rsi
call   1130 <FD_CLR@plt>
mov    -0x38(%rbp),%rcx
movl   $0xffffffff,(%rcx,%rbx,4)
mov    -0x60(%rbp),%rdx
lea    -0x1(%rdx),%eax
cmp    $0x2,%edx
mov    %rax,-0x60(%rbp)
jge    1454 <main+0x224>
jmp    1330 <main+0x100>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [14 x i8] c"listenfd: %d\0A\00"
@FD_SETSIZE = global i32 0
@.str.1 = [13 x i8] c"select [%d]\0A\00"
@.str.2 = [13 x i8] c"accept [%d]\0A\00"
@.str.3 = [19 x i8] c"read [%d] from %d\0A\00"
@str = [14 x i8] c"client closed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = bitcast %struct.sockaddr_in* %4 to i8*
%14 = bitcast %struct.sockaddr_in* %5 to i8*
%15 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = tail call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 8888)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%24 = call i32 @bind(i32 %12, %struct.sockaddr* %23, i32 12)
%25 = call i32 @listen(i32 %12, i32 1024)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %12)
%27 = load i32, i32* @FD_SETSIZE
%28 = zext i32 %27 to i64
%29 = alloca i32, i64 %28
%30 = icmp sgt i32 %27, 0
br i1 %30, label %31, label %34
31: ; preds = %2
%32 = bitcast i32* %29 to i8*
%33 = shl nuw nsw i64 %28, 2
br label %34
34: ; preds = %31, %2
%35 = bitcast i32* %6 to i8*
%36 = bitcast i32* %7 to i8*
%37 = call i32 @FD_ZERO(i32* %7)
%38 = call i32 @FD_SET(i32 %12, i32* %7)
%39 = bitcast i32* %8 to i8*
%40 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %41
41: ; preds = %83, %34
%42 = phi i32 [ -1, %34 ], [ %84, %83 ]
%43 = phi i32 [ %12, %34 ], [ %85, %83 ]
%44 = load i32, i32* %7
store i32 %44, i32* %6
%45 = add nsw i32 %43, 1
%46 = call i32 @select(i32 %45, i32* %6, i32* null, i32* null, i32* null)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = call i64 @FD_ISSET(i32 %12, i32* %6)
%49 = icmp eq i64 %48, 0
br i1 %49, label %78, label %50
50: ; preds = %41
store i32 12, i32* %8
%51 = call i32 @accept(i32 %12, %struct.sockaddr* %40, i32* %8)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = load i32, i32* @FD_SETSIZE
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %69
55: ; preds = %50
%56 = zext i32 %53 to i64
br label %57
57: ; preds = %55, %66
%58 = phi i64 [ 0, %55 ], [ %67, %66 ]
%59 = getelementptr inbounds i32, i32* %29, i64 %58
%60 = load i32, i32* %59
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = trunc i64 %58 to i32
%64 = and i64 %58, 4294967295
%65 = getelementptr inbounds i32, i32* %29, i64 %64
store i32 %51, i32* %65
br label %69
66: ; preds = %57
%67 = add nuw nsw i64 %58, 1
%68 = icmp eq i64 %67, %56
br i1 %68, label %69, label %57
69: ; preds = %66, %50, %62
%70 = phi i32 [ %63, %62 ], [ 0, %50 ], [ %53, %66 ]
%71 = call i32 @FD_SET(i32 %51, i32* %7)
%72 = icmp sgt i32 %51, %43
%73 = select i1 %72, i32 %51, i32 %43
%74 = icmp sgt i32 %70, %42
%75 = select i1 %74, i32 %70, i32 %42
%76 = add nsw i32 %46, -1
%77 = icmp slt i32 %46, 2
br i1 %77, label %83, label %78
78: ; preds = %69, %41
%79 = phi i32 [ %76, %69 ], [ %46, %41 ]
%80 = phi i32 [ %75, %69 ], [ %42, %41 ]
%81 = phi i32 [ %73, %69 ], [ %43, %41 ]
%82 = icmp slt i32 %80, 0
br i1 %82, label %83, label %86
83: ; preds = %109, %112, %78, %69
%84 = phi i32 [ %75, %69 ], [ %80, %78 ], [ %80, %112 ], [ %80, %109 ]
%85 = phi i32 [ %73, %69 ], [ %81, %78 ], [ %81, %112 ], [ %81, %109 ]
br label %41
86: ; preds = %78
%87 = add nuw i32 %80, 1
%88 = zext i32 %87 to i64
br label %89
89: ; preds = %86, %112
%90 = phi i64 [ 0, %86 ], [ %114, %112 ]
%91 = phi i32 [ %79, %86 ], [ %113, %112 ]
%92 = getelementptr inbounds i32, i32* %29, i64 %90
%93 = load i32, i32* %92
%94 = icmp slt i32 %93, 0
br i1 %94, label %112, label %95
95: ; preds = %89
%96 = call i64 @FD_ISSET(i32 %93, i32* %6)
%97 = icmp eq i64 %96, 0
br i1 %97, label %112, label %98
98: ; preds = %95
%99 = call i32 @read(i32 %93, i8* %9, i32 10)
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %99, i32 %93)
%101 = icmp eq i32 %99, 0
br i1 %101, label %102, label %106
102: ; preds = %98
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%104 = call i32 @close(i32 %93)
%105 = call i32 @FD_CLR(i32 %93, i32* %7)
store i32 -1, i32* %92
br label %109
106: ; preds = %98
%107 = call i32 @print(i8* %9, i32 %99)
%108 = call i32 @write(i32 %93, i8* %9, i32 %99)
br label %109
109: ; preds = %106, %102
%110 = add nsw i32 %91, -1
%111 = icmp slt i32 %91, 2
br i1 %111, label %83, label %112
112: ; preds = %95, %109, %89
%113 = phi i32 [ %91, %89 ], [ %110, %109 ], [ %91, %95 ]
%114 = add nuw nsw i64 %90, 1
%115 = icmp eq i64 %114, %88
br i1 %115, label %83, label %89
}