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

/* Forward declarations */

/* Type definitions */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ ECONNRESET;
scalar_t__ EINTR;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int create_tcp_server(int /*<<< orphan*/ *, char const *);
scalar_t__ dispatches(int, int *, int, int, char *);
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ nonblock(int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
scalar_t__ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int hub(const char *service) {
  int sockserver;
  struct sockaddr_in address;
  socklen_t length = sizeof(struct sockaddr_in);
  if ((sockserver = create_tcp_server(NULL, service)) < 0) {
    return -1;
  }
  if (nonblock(sockserver) < 0) {
    return -1;
  }
  char buffer[1024];
  int sockclient[64];
  int sockclientc = 0;
  int i, j, r, sock, run, dataread;
  fd_set listenfdset;
  run = 1;
  while (run) {
    FD_ZERO(&listenfdset);
    FD_SET(sockserver, &listenfdset);
    for (i = 0; i < sockclientc; i++) {
      FD_SET(sockclient[i], &listenfdset);
    }
    if (select(FD_SETSIZE, &listenfdset, NULL, NULL, NULL) < 0) {
      if (errno != EINTR) {
        perror("select");
        return -1;
      } else {
        continue;
      }
    }
    if (FD_ISSET(sockserver, &listenfdset)) {
      if ((sock = accept(sockserver, (struct sockaddr *)(&address), &length)) <
          0) {
        perror("accept");
        return -1;
      }
      if (nonblock(sock) < 0) {
        return -1;
      }
      if (sockclientc == 64) {
        char *toomanyco = "Sorry, no slot available, retry later\n";
        write(sock, toomanyco, strlen(toomanyco));
        close(sock);
      } else {
        sockclient[sockclientc++] = sock;
        fprintf(stdout, "%i connections [+1]\n", sockclientc);
        fflush(stdout);
      }
    }
    for (i = 0; i < sockclientc; i++) {
      if (FD_ISSET(sockclient[i], &listenfdset)) {
        r = read(sockclient[i], buffer, 1024);
        if (r <= 0) {
          close(sockclient[i]);
          sockclient[i] = sockclient[--sockclientc];
          fprintf(stdout, "%i connections [-1]\n", sockclientc);
          fflush(stdout);
          if (r < 0 && errno != ECONNRESET) {
            perror("read");
          }
        } else {
          if (dispatches(sockclientc, sockclient, i, r, buffer) < 0) {
            return -1;
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<hub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x560,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <create_tcp_server@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    122b <hub+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c3 <hub+0x3d3>
mov    -0x14(%rbp),%edi
call   1030 <nonblock@plt>
cmp    $0x0,%rax
jge    1249 <hub+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c3 <hub+0x3d3>
movl   $0x0,-0x524(%rbp)
movl   $0x1,-0x538(%rbp)
cmpl   $0x0,-0x538(%rbp)
je     15c3 <hub+0x3d3>
lea    -0x540(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x540(%rbp),%rsi
call   1110 <FD_SET@plt>
movl   $0x0,-0x528(%rbp)
mov    -0x528(%rbp),%eax
cmp    -0x524(%rbp),%eax
jge    12cf <hub+0xdf>
movslq -0x528(%rbp),%rax
mov    -0x520(%rbp,%rax,4),%edi
lea    -0x540(%rbp),%rsi
call   1110 <FD_SET@plt>
mov    -0x528(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x528(%rbp)
jmp    128f <hub+0x9f>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    -0x540(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10d0 <select@plt>
cmp    $0x0,%rax
jge    1330 <hub+0x140>
mov    0x2cd0(%rip),%rax
mov    (%rax),%rax
mov    0x2cbe(%rip),%rcx
cmp    (%rcx),%rax
je     132b <hub+0x13b>
lea    0xce6(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c3 <hub+0x3d3>
jmp    125d <hub+0x6d>
mov    -0x14(%rbp),%edi
lea    -0x540(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1454 <hub+0x264>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x534(%rbp)
cmp    $0x0,%eax
jge    1380 <hub+0x190>
lea    0xc98(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c3 <hub+0x3d3>
mov    -0x534(%rbp),%edi
call   1030 <nonblock@plt>
cmp    $0x0,%rax
jge    13a1 <hub+0x1b1>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c3 <hub+0x3d3>
cmpl   $0x40,-0x524(%rbp)
jne    1406 <hub+0x216>
lea    0xc59(%rip),%rax
mov    %rax,-0x548(%rbp)
mov    -0x534(%rbp),%eax
mov    %eax,-0x554(%rbp)
mov    -0x548(%rbp),%rax
mov    %rax,-0x550(%rbp)
mov    -0x548(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x554(%rbp),%edi
mov    -0x550(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x534(%rbp),%edi
call   1090 <close@plt>
jmp    144f <hub+0x25f>
mov    -0x534(%rbp),%ecx
mov    -0x524(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x524(%rbp)
cltq
mov    %ecx,-0x520(%rbp,%rax,4)
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
mov    -0x524(%rbp),%edx
lea    0xbf9(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
jmp    1454 <hub+0x264>
movl   $0x0,-0x528(%rbp)
mov    -0x528(%rbp),%eax
cmp    -0x524(%rbp),%eax
jge    15be <hub+0x3ce>
movslq -0x528(%rbp),%rax
mov    -0x520(%rbp,%rax,4),%edi
lea    -0x540(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15a5 <hub+0x3b5>
movslq -0x528(%rbp),%rax
mov    -0x520(%rbp,%rax,4),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x530(%rbp)
cmpl   $0x0,-0x530(%rbp)
jg     1560 <hub+0x370>
movslq -0x528(%rbp),%rax
mov    -0x520(%rbp,%rax,4),%edi
call   1090 <close@plt>
mov    -0x524(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x524(%rbp)
cltq
mov    -0x520(%rbp,%rax,4),%ecx
movslq -0x528(%rbp),%rax
mov    %ecx,-0x520(%rbp,%rax,4)
mov    0x2aba(%rip),%rax
mov    (%rax),%edi
mov    -0x524(%rbp),%edx
lea    0xb35(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2a9f(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
cmpl   $0x0,-0x530(%rbp)
jge    155b <hub+0x36b>
mov    0x2a94(%rip),%rax
mov    (%rax),%rax
mov    0x2a9a(%rip),%rcx
cmp    (%rcx),%rax
je     155b <hub+0x36b>
lea    0xb09(%rip),%rdi
call   10f0 <perror@plt>
jmp    15a0 <hub+0x3b0>
mov    -0x524(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    -0x528(%rbp),%edx
mov    -0x530(%rbp),%ecx
lea    -0x420(%rbp),%r8
call   1070 <dispatches@plt>
cmp    $0x0,%rax
jge    159b <hub+0x3ab>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c3 <hub+0x3d3>
jmp    15a0 <hub+0x3b0>
jmp    15a5 <hub+0x3b5>
jmp    15aa <hub+0x3ba>
mov    -0x528(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x528(%rbp)
jmp    145e <hub+0x26e>
jmp    125d <hub+0x6d>
mov    -0x4(%rbp),%eax
add    $0x560,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hub>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %rdi,%rsi
movl   $0x4,0x4(%rsp)
xor    %edi,%edi
call   1040 <create_tcp_server@plt>
test   %eax,%eax
js     149b <hub+0x2ab>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <nonblock@plt>
test   %rax,%rax
js     149b <hub+0x2ab>
mov    %ebx,(%rsp)
xor    %r15d,%r15d
lea    0xc(%rsp),%r14
mov    0x2d99(%rip),%r13
mov    %r15d,%ebp
mov    (%rsp),%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1110 <FD_SET@plt>
test   %r15d,%r15d
jle    1285 <hub+0x95>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%edi
mov    %r14,%rsi
call   1110 <FD_SET@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <hub+0x80>
mov    0x0(%r13),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %rax,%rax
jns    12c0 <hub+0xd0>
mov    0x2d2c(%rip),%rax
mov    (%rax),%rax
mov    0x2d1a(%rip),%rcx
cmp    (%rcx),%rax
je     1250 <hub+0x60>
jmp    148f <hub+0x29f>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1340 <hub+0x150>
mov    %r12d,%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1100 <accept@plt>
test   %eax,%eax
lea    0x110(%rsp),%rbp
js     14b2 <hub+0x2c2>
mov    %eax,%r12d
mov    %eax,%edi
call   1030 <nonblock@plt>
test   %rax,%rax
js     149b <hub+0x2ab>
cmp    $0x40,%r15d
jne    1360 <hub+0x170>
lea    0xcfc(%rip),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    $0x40,%r15d
jmp    1394 <hub+0x1a4>
nopw   0x0(%rax,%rax,1)
lea    0x110(%rsp),%rbp
test   %r15d,%r15d
jg     1394 <hub+0x1a4>
jmp    123f <hub+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r15d,%rax
add    $0x1,%r15d
mov    %r12d,0x10(%rsp,%rax,4)
mov    0x2c4d(%rip),%rbx
mov    (%rbx),%edi
lea    0xcb9(%rip),%rsi
mov    %r15d,%edx
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
call   10e0 <fflush@plt>
test   %r15d,%r15d
jle    123f <hub+0x4f>
xor    %r12d,%r12d
jmp    13d2 <hub+0x1e2>
nopl   0x0(%rax)
mov    %r15d,%edi
lea    0x10(%rsp),%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %rbp,%r8
call   1070 <dispatches@plt>
test   %rax,%rax
mov    %rbx,%r13
js     149b <hub+0x2ab>
add    $0x1,%r12
movslq %r15d,%rax
cmp    %rax,%r12
jge    123f <hub+0x4f>
mov    0x10(%rsp,%r12,4),%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     13c2 <hub+0x1d2>
mov    %r13,%rbx
mov    0x10(%rsp,%r12,4),%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,%r13d
test   %eax,%eax
jg     13a0 <hub+0x1b0>
mov    0x10(%rsp,%r12,4),%edi
call   1090 <close@plt>
movslq %r15d,%rax
add    $0xffffffff,%r15d
mov    0xc(%rsp,%rax,4),%eax
mov    %eax,0x10(%rsp,%r12,4)
mov    0x2b9f(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xc1f(%rip),%rsi
mov    %r15d,%edx
call   10b0 <fprintf@plt>
mov    0x0(%rbp),%edi
call   10e0 <fflush@plt>
test   %r13d,%r13d
js     1450 <hub+0x260>
mov    %rbx,%r13
lea    0x110(%rsp),%rbp
jmp    13c2 <hub+0x1d2>
mov    0x2b79(%rip),%rax
mov    (%rax),%rax
mov    0x2b7f(%rip),%rcx
cmp    (%rcx),%rax
mov    %rbx,%r13
jne    1476 <hub+0x286>
lea    0x110(%rsp),%rbp
jmp    13c2 <hub+0x1d2>
lea    0xbe2(%rip),%rdi
call   10f0 <perror@plt>
lea    0x110(%rsp),%rbp
jmp    13c2 <hub+0x1d2>
lea    0xb6a(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb4e(%rip),%rdi
jmp    1496 <hub+0x2a6>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@FD_SETSIZE = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
@.str.1 = [7 x i8] c"accept\00"
@.str.2 = [39 x i8] c"Sorry, no slot available, retry later\0A\00"
@stdout = global i32 0
@.str.3 = [21 x i8] c"%i connections [+1]\0A\00"
@.str.4 = [21 x i8] c"%i connections [-1]\0A\00"
@ECONNRESET = global i64 0
@.str.5 = [5 x i8] c"read\00"
define i32 @hub(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [64 x i32]
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%9 = tail call i32 @create_tcp_server(i32* null, i8* %0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %114, label %11
11: ; preds = %1
%12 = tail call i64 @nonblock(i32 %9)
%13 = icmp slt i64 %12, 0
br i1 %13, label %114, label %14
14: ; preds = %11
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = bitcast [64 x i32]* %5 to i8*
%17 = bitcast i32* %6 to i8*
%18 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%19 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 0
br label %20
20: ; preds = %68, %14
%21 = phi i32 [ 0, %14 ], [ %69, %68 ]
%22 = icmp sgt i32 %21, 0
%23 = zext i32 %21 to i64
br label %24
24: ; preds = %20, %38
%25 = call i32 @FD_ZERO(i32* %6)
%26 = call i32 @FD_SET(i32 %9, i32* %6)
br i1 %22, label %27, label %34
27: ; preds = %24, %27
%28 = phi i64 [ %32, %27 ], [ 0, %24 ]
%29 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @FD_SET(i32 %30, i32* %6)
%32 = add nuw nsw i64 %28, 1
%33 = icmp eq i64 %32, %23
br i1 %33, label %34, label %27
34: ; preds = %27, %24
%35 = load i32, i32* @FD_SETSIZE
%36 = call i64 @select(i32 %35, i32* %6, i32* null, i32* null, i32* null)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINTR
%41 = icmp eq i64 %39, %40
br i1 %41, label %24, label %110
42: ; preds = %34
%43 = call i64 @FD_ISSET(i32 %9, i32* %6)
%44 = icmp eq i64 %43, 0
br i1 %44, label %65, label %45
45: ; preds = %42
%46 = call i32 @accept(i32 %9, %struct.sockaddr* %18, i32* %3)
%47 = icmp slt i32 %46, 0
br i1 %47, label %110, label %48
48: ; preds = %45
%49 = call i64 @nonblock(i32 %46)
%50 = icmp slt i64 %49, 0
br i1 %50, label %113, label %51
51: ; preds = %48
%52 = icmp eq i32 %21, 64
br i1 %52, label %53, label %57
53: ; preds = %51
%54 = call i32 @strlen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%55 = call i32 @write(i32 %46, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = call i32 @close(i32 %46)
br label %70
57: ; preds = %51
%58 = add nsw i32 %21, 1
%59 = sext i32 %21 to i64
%60 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %59
store i32 %46, i32* %60
%61 = load i32, i32* @stdout
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%63 = load i32, i32* @stdout
%64 = call i32 @fflush(i32 %63)
br label %65
65: ; preds = %57, %42
%66 = phi i32 [ %58, %57 ], [ %21, %42 ]
%67 = icmp sgt i32 %66, 0
br i1 %67, label %70, label %68
68: ; preds = %105, %65
%69 = phi i32 [ %66, %65 ], [ %106, %105 ]
br label %20
70: ; preds = %53, %65
%71 = phi i32 [ %66, %65 ], [ 64, %53 ]
br label %72
72: ; preds = %70, %105
%73 = phi i64 [ %107, %105 ], [ 0, %70 ]
%74 = phi i32 [ %106, %105 ], [ %71, %70 ]
%75 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %73
%76 = load i32, i32* %75
%77 = call i64 @FD_ISSET(i32 %76, i32* %6)
%78 = icmp eq i64 %77, 0
br i1 %78, label %105, label %79
79: ; preds = %72
%80 = load i32, i32* %75
%81 = call i32 @read(i32 %80, i8* %15, i32 1024)
%82 = icmp slt i32 %81, 1
br i1 %82, label %83, label %101
83: ; preds = %79
%84 = load i32, i32* %75
%85 = call i32 @close(i32 %84)
%86 = add nsw i32 %74, -1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %87
%89 = load i32, i32* %88
store i32 %89, i32* %75
%90 = load i32, i32* @stdout
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %86)
%92 = load i32, i32* @stdout
%93 = call i32 @fflush(i32 %92)
%94 = icmp slt i32 %81, 0
br i1 %94, label %95, label %105
95: ; preds = %83
%96 = load i64, i64* @errno
%97 = load i64, i64* @ECONNRESET
%98 = icmp eq i64 %96, %97
br i1 %98, label %105, label %99
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %105
101: ; preds = %79
%102 = trunc i64 %73 to i32
%103 = call i64 @dispatches(i32 %74, i32* %19, i32 %102, i32 %81, i8* %15)
%104 = icmp slt i64 %103, 0
br i1 %104, label %113, label %105
105: ; preds = %72, %101, %83, %95, %99
%106 = phi i32 [ %86, %99 ], [ %86, %95 ], [ %86, %83 ], [ %74, %101 ], [ %74, %72 ]
%107 = add nuw nsw i64 %73, 1
%108 = sext i32 %106 to i64
%109 = icmp slt i64 %107, %108
br i1 %109, label %72, label %68
110: ; preds = %45, %38
%111 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %38 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %45 ]
%112 = call i32 @perror(i8* %111)
br label %113
113: ; preds = %48, %101, %110
br label %114
114: ; preds = %11, %1, %113
ret i32 -1
}