#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__ 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 /*<<< orphan*/ SHUT_RDWR;
int accept(int, struct sockaddr *, int *);
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int);
int create_tcp_server(int /*<<< orphan*/ *, char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getdtablesize();
int getpid();
scalar_t__ nonblock(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ process_connection(int);
scalar_t__ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
scalar_t__ setsid();
scalar_t__ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void *run_server(void *args) {
  int status, i, sockserver, sock;
  int client[16];
  int clientc = 0;
  struct sockaddr_in address;
  socklen_t length = sizeof(struct sockaddr_in);
  if ((sockserver = create_tcp_server(NULL, (char *)args)) < 0) {
    fprintf(stderr, "create_tcp_server failed\n");
    exit(1);
  }
  if (nonblock(sockserver) < 0) {
    exit(1);
  }
  printf("Listen on TCP port %s\n", "13756");
  if (chdir("/") < 0) {
    perror("chdir");
    exit(1);
  }
  if (fork() != 0) {
    exit(0);
  }
  if (setsid() < 0) {
    perror("setsid");
    exit(1);
  }
  if (fork() != 0) {
    exit(0);
  }
  printf("PID: %d\n", getpid());
  for (i = 0; i < getdtablesize(); i++) {
    if (i != sockserver) {
      close(i);
    }
  }
  fd_set lfdset;
  int run = 1;
  while (run) {
    FD_ZERO(&lfdset);
    FD_SET(sockserver, &lfdset);
    for (i = 0; i < clientc; i++) {
      FD_SET(client[i], &lfdset);
    }
    if (select(FD_SETSIZE, &lfdset, NULL, NULL, NULL) < 0) {
      if (errno != EINTR) {
        perror("select");
        exit(1);
      } else {
        continue;
      }
    }
    if (FD_ISSET(sockserver, &lfdset)) {
      if ((sock = accept(sockserver, (struct sockaddr *)(&address), &length)) <
          0) {
        perror("accept");
        continue;
      }
      if (nonblock(sock) < 0) {
        close(sock);
        continue;
      }
      if (clientc == 16) {
        char *toomanyco = "Sorry, no slot available, retry later\n";
        write(sock, toomanyco, strlen(toomanyco));
        close(sock);
      } else {
        client[clientc++] = sock;
        char *motd = "Welcom to TCP Hub monitor.\nType 'help' for help.\n> ";
        write(sock, motd, strlen(motd));
      }
    }
    for (i = 0; i < clientc; i++) {
      if (FD_ISSET(client[i], &lfdset)) {
        if (process_connection(client[i]) < 0) {
          if (shutdown(client[i], SHUT_RDWR) < 0) {
            perror("shutdown");
          }
          close(client[i]);
          client[i] = client[--clientc];
          continue;
        }
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<run_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x4,-0x6c(%rbp)
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <create_tcp_server@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12a5 <run_server+0x55>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x14(%rbp),%edi
call   1030 <nonblock@plt>
cmp    $0x0,%rax
jge    12c1 <run_server+0x71>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xd52(%rip),%rdi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   10b0 <printf@plt>
lea    0xd5a(%rip),%rdi
call   10a0 <chdir@plt>
cmp    $0x0,%rax
jge    1302 <run_server+0xb2>
lea    0xd46(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    $0x0,%al
call   1150 <fork@plt>
cmp    $0x0,%rax
je     131a <run_server+0xca>
xor    %edi,%edi
call   1130 <exit@plt>
mov    $0x0,%al
call   10d0 <setsid@plt>
cmp    $0x0,%rax
jge    1341 <run_server+0xf1>
lea    0xd0d(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    $0x0,%al
call   1150 <fork@plt>
cmp    $0x0,%rax
je     1359 <run_server+0x109>
xor    %edi,%edi
call   1130 <exit@plt>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,%esi
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    $0x0,%al
call   1160 <getdtablesize@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
cmp    %ecx,%eax
jge    13be <run_server+0x16e>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     13ab <run_server+0x15b>
mov    -0x10(%rbp),%edi
call   10c0 <close@plt>
jmp    13b0 <run_server+0x160>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1377 <run_server+0x127>
movl   $0x1,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     163c <run_server+0x3ec>
lea    -0x70(%rbp),%rdi
call   10f0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1140 <FD_SET@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1416 <run_server+0x1c6>
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
lea    -0x70(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    13eb <run_server+0x19b>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1100 <select@plt>
cmp    $0x0,%rax
jge    1472 <run_server+0x222>
mov    0x2b84(%rip),%rax
mov    (%rax),%rax
mov    0x2b72(%rip),%rcx
cmp    (%rcx),%rax
je     146d <run_server+0x21d>
lea    0xbf1(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    13c5 <run_server+0x175>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1585 <run_server+0x335>
mov    -0x14(%rbp),%edi
lea    -0x68(%rbp),%rsi
lea    -0x6c(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    14b5 <run_server+0x265>
lea    0xbab(%rip),%rdi
call   1110 <perror@plt>
jmp    13c5 <run_server+0x175>
mov    -0x18(%rbp),%edi
call   1030 <nonblock@plt>
cmp    $0x0,%rax
jge    14d4 <run_server+0x284>
mov    -0x18(%rbp),%edi
call   10c0 <close@plt>
jmp    13c5 <run_server+0x175>
cmpl   $0x10,-0x64(%rbp)
jne    1527 <run_server+0x2d7>
lea    0xb78(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x80(%rbp),%rdi
call   1090 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x18(%rbp),%edi
call   10c0 <close@plt>
jmp    1580 <run_server+0x330>
mov    -0x18(%rbp),%ecx
mov    -0x64(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x64(%rbp)
cltq
mov    %ecx,-0x60(%rbp,%rax,4)
lea    0xb42(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x88(%rbp),%rdi
call   1090 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    1585 <run_server+0x335>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1637 <run_server+0x3e7>
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
lea    -0x70(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1624 <run_server+0x3d4>
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
call   1170 <process_connection@plt>
cmp    $0x0,%rax
jge    161f <run_server+0x3cf>
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
mov    0x2a17(%rip),%rax
mov    (%rax),%esi
call   1080 <shutdown@plt>
cmp    $0x0,%rax
jge    15f6 <run_server+0x3a6>
lea    0xac7(%rip),%rdi
call   1110 <perror@plt>
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
call   10c0 <close@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
cltq
mov    -0x60(%rbp,%rax,4),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
jmp    1629 <run_server+0x3d9>
jmp    1624 <run_server+0x3d4>
jmp    1629 <run_server+0x3d9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    158c <run_server+0x33c>
jmp    13c5 <run_server+0x175>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_server>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rsi
movl   $0x4,0x4(%rsp)
xor    %edi,%edi
call   1040 <create_tcp_server@plt>
test   %eax,%eax
jns    128b <run_server+0x3b>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   10e0 <fprintf@plt>
jmp    129a <run_server+0x4a>
mov    %eax,%r13d
mov    %eax,%edi
call   1030 <nonblock@plt>
test   %rax,%rax
jns    12a4 <run_server+0x54>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xd6f(%rip),%rdi
lea    0xd7f(%rip),%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0xd77(%rip),%rdi
call   10a0 <chdir@plt>
test   %rax,%rax
jns    12e0 <run_server+0x90>
lea    0xd68(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
xor    %eax,%eax
call   1150 <fork@plt>
test   %rax,%rax
jne    135c <run_server+0x10c>
xor    %eax,%eax
call   10d0 <setsid@plt>
test   %rax,%rax
jns    1301 <run_server+0xb1>
lea    0xd40(%rip),%rdi
jmp    12d1 <run_server+0x81>
xor    %eax,%eax
call   1150 <fork@plt>
test   %rax,%rax
jne    135c <run_server+0x10c>
xor    %r15d,%r15d
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xd28(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10b0 <printf@plt>
xor    %eax,%eax
call   1160 <getdtablesize@plt>
test   %eax,%eax
jle    1363 <run_server+0x113>
xor    %ebx,%ebx
jmp    134e <run_server+0xfe>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %eax,%eax
call   1160 <getdtablesize@plt>
cmp    %eax,%ebx
jge    1363 <run_server+0x113>
cmp    %ebx,%r13d
je     1340 <run_server+0xf0>
mov    %ebx,%edi
call   10c0 <close@plt>
jmp    1340 <run_server+0xf0>
xor    %edi,%edi
call   1130 <exit@plt>
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15d,%ebp
jmp    139a <run_server+0x14a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2c41(%rip),%rax
mov    (%rax),%rax
mov    0x2c2f(%rip),%rcx
cmp    (%rcx),%rax
jne    1536 <run_server+0x2e6>
mov    %r12,%rdi
call   10f0 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %r12,%rsi
call   1140 <FD_SET@plt>
test   %r15d,%r15d
jle    13d5 <run_server+0x185>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp,%rbx,4),%edi
mov    %r12,%rsi
call   1140 <FD_SET@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    13c0 <run_server+0x170>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1100 <select@plt>
test   %rax,%rax
js     1380 <run_server+0x130>
mov    %r13d,%edi
mov    %r12,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     14b8 <run_server+0x268>
mov    %r13d,%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1120 <accept@plt>
test   %eax,%eax
js     1438 <run_server+0x1e8>
mov    %eax,%r14d
mov    %eax,%edi
call   1030 <nonblock@plt>
test   %rax,%rax
jns    1450 <run_server+0x200>
mov    %r14d,%edi
call   10c0 <close@plt>
jmp    139a <run_server+0x14a>
lea    0xc17(%rip),%rdi
call   1110 <perror@plt>
jmp    139a <run_server+0x14a>
nopl   0x0(%rax)
cmp    $0x10,%r15d
jne    1490 <run_server+0x240>
lea    0xc00(%rip),%rbx
mov    %rbx,%rdi
call   1090 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
mov    $0x10,%r15d
mov    0x2b69(%rip),%rbx
jmp    14c8 <run_server+0x278>
nopl   0x0(%rax)
movslq %r15d,%rax
add    $0x1,%r15d
mov    %r14d,0x10(%rsp,%rax,4)
lea    0xbe1(%rip),%rbx
mov    %rbx,%rdi
call   1090 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    0x2b31(%rip),%rbx
test   %r15d,%r15d
jle    1370 <run_server+0x120>
xor    %ebp,%ebp
jmp    14f7 <run_server+0x2a7>
nopl   0x0(%rax)
mov    %r14d,%edi
call   10c0 <close@plt>
movslq %r15d,%rax
add    $0xffffffff,%r15d
mov    0xc(%rsp,%rax,4),%eax
mov    %eax,0x10(%rsp,%rbp,4)
add    $0x1,%rbp
movslq %r15d,%rax
cmp    %rax,%rbp
jge    1370 <run_server+0x120>
mov    0x10(%rsp,%rbp,4),%r14d
mov    %r14d,%edi
mov    %r12,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     14e7 <run_server+0x297>
mov    %r14d,%edi
call   1170 <process_connection@plt>
test   %rax,%rax
jns    14e7 <run_server+0x297>
mov    (%rbx),%esi
mov    %r14d,%edi
call   1080 <shutdown@plt>
test   %rax,%rax
jns    14d0 <run_server+0x280>
lea    0xb89(%rip),%rdi
call   1110 <perror@plt>
jmp    14d0 <run_server+0x280>
lea    0xb12(%rip),%rdi
jmp    12d1 <run_server+0x81>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"create_tcp_server failed\0A\00"
@.str.1 = [23 x i8] c"Listen on TCP port %s\0A\00"
@.str.2 = [6 x i8] c"13756\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [6 x i8] c"chdir\00"
@.str.5 = [7 x i8] c"setsid\00"
@.str.6 = [9 x i8] c"PID: %d\0A\00"
@FD_SETSIZE = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [7 x i8] c"select\00"
@.str.8 = [7 x i8] c"accept\00"
@.str.9 = [39 x i8] c"Sorry, no slot available, retry later\0A\00"
@.str.10 = [52 x i8] c"Welcom to TCP Hub monitor.\0AType 'help' for help.\0A> \00"
@SHUT_RDWR = global i32 0
@.str.11 = [9 x i8] c"shutdown\00"
define i8* @run_server(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [16 x i32]
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %8
store i32 4, i32* %10
%15 = load i8*, i8** %2
%16 = call i32 @create_tcp_server(i32* null, i8* %15)
store i32 %16, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %1
%23 = load i32, i32* %5
%24 = call i64 @nonblock(i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = call i64 (...) @fork()
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %35
%41 = call i64 (...) @setsid()
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = call i64 (...) @fork()
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %46
%52 = call i32 (...) @getpid()
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %52)
store i32 0, i32* %4
br label %54
54: ; preds = %66, %51
%55 = load i32, i32* %4
%56 = call i32 (...) @getdtablesize()
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %69
58: ; preds = %54
%59 = load i32, i32* %4
%60 = load i32, i32* %5
%61 = icmp ne i32 %59, %60
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i32, i32* %4
%64 = call i32 @close(i32 %63)
br label %65
65: ; preds = %62, %58
br label %66
66: ; preds = %65
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %54
69: ; preds = %54
store i32 1, i32* %12
br label %70
70: ; preds = %191, %117, %111, %101, %69
%71 = load i32, i32* %12
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %192
73: ; preds = %70
%74 = call i32 @FD_ZERO(i32* %11)
%75 = load i32, i32* %5
%76 = call i32 @FD_SET(i32 %75, i32* %11)
store i32 0, i32* %4
br label %77
77: ; preds = %87, %73
%78 = load i32, i32* %4
%79 = load i32, i32* %8
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %90
81: ; preds = %77
%82 = load i32, i32* %4
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %83
%85 = load i32, i32* %84
%86 = call i32 @FD_SET(i32 %85, i32* %11)
br label %87
87: ; preds = %81
%88 = load i32, i32* %4
%89 = add nsw i32 %88, 1
store i32 %89, i32* %4
br label %77
90: ; preds = %77
%91 = load i32, i32* @FD_SETSIZE
%92 = call i64 @select(i32 %91, i32* %11, i32* null, i32* null, i32* null)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %102
94: ; preds = %90
%95 = load i64, i64* @errno
%96 = load i64, i64* @EINTR
%97 = icmp ne i64 %95, %96
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %94
br label %70
102: ; preds = %90
%103 = load i32, i32* %5
%104 = call i64 @FD_ISSET(i32 %103, i32* %11)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %143
106: ; preds = %102
%107 = load i32, i32* %5
%108 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%109 = call i32 @accept(i32 %107, %struct.sockaddr* %108, i32* %10)
store i32 %109, i32* %6
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %106
%112 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %70
113: ; preds = %106
%114 = load i32, i32* %6
%115 = call i64 @nonblock(i32 %114)
%116 = icmp slt i64 %115, 0
br i1 %116, label %117, label %120
117: ; preds = %113
%118 = load i32, i32* %6
%119 = call i32 @close(i32 %118)
br label %70
120: ; preds = %113
%121 = load i32, i32* %8
%122 = icmp eq i32 %121, 16
br i1 %122, label %123, label %131
123: ; preds = %120
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i8** %13
%124 = load i32, i32* %6
%125 = load i8*, i8** %13
%126 = load i8*, i8** %13
%127 = call i32 @strlen(i8* %126)
%128 = call i32 @write(i32 %124, i8* %125, i32 %127)
%129 = load i32, i32* %6
%130 = call i32 @close(i32 %129)
br label %142
131: ; preds = %120
%132 = load i32, i32* %6
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
%135 = sext i32 %133 to i64
%136 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %135
store i32 %132, i32* %136
store i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0), i8** %14
%137 = load i32, i32* %6
%138 = load i8*, i8** %14
%139 = load i8*, i8** %14
%140 = call i32 @strlen(i8* %139)
%141 = call i32 @write(i32 %137, i8* %138, i32 %140)
br label %142
142: ; preds = %131, %123
br label %143
143: ; preds = %142, %102
store i32 0, i32* %4
br label %144
144: ; preds = %188, %143
%145 = load i32, i32* %4
%146 = load i32, i32* %8
%147 = icmp slt i32 %145, %146
br i1 %147, label %148, label %191
148: ; preds = %144
%149 = load i32, i32* %4
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %150
%152 = load i32, i32* %151
%153 = call i64 @FD_ISSET(i32 %152, i32* %11)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %187
155: ; preds = %148
%156 = load i32, i32* %4
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %157
%159 = load i32, i32* %158
%160 = call i64 @process_connection(i32 %159)
%161 = icmp slt i64 %160, 0
br i1 %161, label %162, label %186
162: ; preds = %155
%163 = load i32, i32* %4
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %164
%166 = load i32, i32* %165
%167 = load i32, i32* @SHUT_RDWR
%168 = call i64 @shutdown(i32 %166, i32 %167)
%169 = icmp slt i64 %168, 0
br i1 %169, label %170, label %172
170: ; preds = %162
%171 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %172
172: ; preds = %170, %162
%173 = load i32, i32* %4
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %174
%176 = load i32, i32* %175
%177 = call i32 @close(i32 %176)
%178 = load i32, i32* %8
%179 = add nsw i32 %178, -1
store i32 %179, i32* %8
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %180
%182 = load i32, i32* %181
%183 = load i32, i32* %4
%184 = sext i32 %183 to i64
%185 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %184
store i32 %182, i32* %185
br label %188
186: ; preds = %155
br label %187
187: ; preds = %186, %148
br label %188
188: ; preds = %187, %172
%189 = load i32, i32* %4
%190 = add nsw i32 %189, 1
store i32 %190, i32* %4
br label %144
191: ; preds = %144
br label %70
192: ; preds = %70
ret i8* null
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"create_tcp_server failed\0A\00"
@.str.1 = [23 x i8] c"Listen on TCP port %s\0A\00"
@.str.2 = [6 x i8] c"13756\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [6 x i8] c"chdir\00"
@.str.5 = [7 x i8] c"setsid\00"
@.str.6 = [9 x i8] c"PID: %d\0A\00"
@FD_SETSIZE = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [7 x i8] c"select\00"
@.str.8 = [7 x i8] c"accept\00"
@.str.9 = [39 x i8] c"Sorry, no slot available, retry later\0A\00"
@.str.10 = [52 x i8] c"Welcom to TCP Hub monitor.\0AType 'help' for help.\0A> \00"
@SHUT_RDWR = global i32 0
@.str.11 = [9 x i8] c"shutdown\00"
define noalias i8* @run_server(i8* %0) {
%2 = alloca [16 x i32]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [16 x i32]* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%9 = tail call i32 @create_tcp_server(i32* null, i8* %0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = tail call i64 @nonblock(i32 %9)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %15
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = tail call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @exit(i32 0)
unreachable
32: ; preds = %27
%33 = tail call i64 (...) @setsid()
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = tail call i64 (...) @fork()
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = tail call i32 @exit(i32 0)
unreachable
43: ; preds = %38
%44 = tail call i32 (...) @getpid()
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = tail call i32 (...) @getdtablesize()
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %43, %53
%49 = phi i32 [ %54, %53 ], [ 0, %43 ]
%50 = icmp eq i32 %49, %9
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = tail call i32 @close(i32 %49)
br label %53
53: ; preds = %48, %51
%54 = add nuw nsw i32 %49, 1
%55 = tail call i32 (...) @getdtablesize()
%56 = icmp slt i32 %54, %55
br i1 %56, label %48, label %57
57: ; preds = %53, %43
%58 = bitcast i32* %5 to i8*
%59 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %60
60: ; preds = %114, %57
%61 = phi i32 [ 0, %57 ], [ %115, %114 ]
%62 = icmp sgt i32 %61, 0
%63 = zext i32 %61 to i64
br label %64
64: ; preds = %93, %60
%65 = call i32 @FD_ZERO(i32* %5)
%66 = call i32 @FD_SET(i32 %9, i32* %5)
br i1 %62, label %67, label %74
67: ; preds = %64, %67
%68 = phi i64 [ %72, %67 ], [ 0, %64 ]
%69 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %68
%70 = load i32, i32* %69
%71 = call i32 @FD_SET(i32 %70, i32* %5)
%72 = add nuw nsw i64 %68, 1
%73 = icmp eq i64 %72, %63
br i1 %73, label %74, label %67
74: ; preds = %67, %64
%75 = load i32, i32* @FD_SETSIZE
%76 = call i64 @select(i32 %75, i32* %5, i32* null, i32* null, i32* null)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %74
%79 = load i64, i64* @errno
%80 = load i64, i64* @EINTR
%81 = icmp eq i64 %79, %80
br i1 %81, label %93, label %82
82: ; preds = %78
%83 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %74
%86 = call i64 @FD_ISSET(i32 %9, i32* %5)
%87 = icmp eq i64 %86, 0
br i1 %87, label %111, label %88
88: ; preds = %85
%89 = call i32 @accept(i32 %9, %struct.sockaddr* %59, i32* %4)
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %93
93: ; preds = %91, %97, %78
br label %64
94: ; preds = %88
%95 = call i64 @nonblock(i32 %89)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 @close(i32 %89)
br label %93
99: ; preds = %94
%100 = icmp eq i32 %61, 16
br i1 %100, label %101, label %105
101: ; preds = %99
%102 = call i32 @strlen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%103 = call i32 @write(i32 %89, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %102)
%104 = call i32 @close(i32 %89)
br label %116
105: ; preds = %99
%106 = add nsw i32 %61, 1
%107 = sext i32 %61 to i64
%108 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %107
store i32 %89, i32* %108
%109 = call i32 @strlen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0))
%110 = call i32 @write(i32 %89, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0), i32 %109)
br label %111
111: ; preds = %85, %105
%112 = phi i32 [ %106, %105 ], [ %61, %85 ]
%113 = icmp sgt i32 %112, 0
br i1 %113, label %116, label %114
114: ; preds = %140, %111
%115 = phi i32 [ %112, %111 ], [ %141, %140 ]
br label %60
116: ; preds = %101, %111
%117 = phi i32 [ %112, %111 ], [ 16, %101 ]
br label %118
118: ; preds = %116, %140
%119 = phi i64 [ %142, %140 ], [ 0, %116 ]
%120 = phi i32 [ %141, %140 ], [ %117, %116 ]
%121 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %119
%122 = load i32, i32* %121
%123 = call i64 @FD_ISSET(i32 %122, i32* %5)
%124 = icmp eq i64 %123, 0
br i1 %124, label %140, label %125
125: ; preds = %118
%126 = call i64 @process_connection(i32 %122)
%127 = icmp slt i64 %126, 0
br i1 %127, label %128, label %140
128: ; preds = %125
%129 = load i32, i32* @SHUT_RDWR
%130 = call i64 @shutdown(i32 %122, i32 %129)
%131 = icmp slt i64 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %128
%133 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %134
134: ; preds = %132, %128
%135 = call i32 @close(i32 %122)
%136 = add nsw i32 %120, -1
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %137
%139 = load i32, i32* %138
store i32 %139, i32* %121
br label %140
140: ; preds = %118, %125, %134
%141 = phi i32 [ %136, %134 ], [ %120, %125 ], [ %120, %118 ]
%142 = add nuw nsw i64 %119, 1
%143 = sext i32 %141 to i64
%144 = icmp slt i64 %142, %143
br i1 %144, label %118, label %114
}