#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_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ remoteaddr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int INET_ADDRSTRLEN;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
char *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int listen(int, int);
int make_socket(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
int main(void) {
  fd_set master;
  fd_set readfds;
  int fdmax;
  int listener;
  int newfd;
  struct sockaddr_storage remoteaddr;
  socklen_t addrlen;
  char remoteIP[INET_ADDRSTRLEN];
  int i, j;
  char data[512];
  char reply[512];
  int nbytes;
  FD_ZERO(&master);
  FD_ZERO(&readfds);
  listener = make_socket(30303);
  if (listen(listener, 10) == -1) {
    perror("listen");
    return 1;
  }
  FD_SET(listener, &master);
  fdmax = listener;
  for (;;) {
    readfds = master;
    if (select(fdmax + 1, &readfds, NULL, NULL, NULL) == -1) {
      perror("select");
      return 2;
    }
    for (i = 0; i <= fdmax; i++) {
      if (FD_ISSET(i, &readfds)) {
        if (i == listener) {
          addrlen = sizeof(remoteaddr);
          newfd = accept(listener, (struct sockaddr *)&remoteaddr, &addrlen);
          if (newfd == -1) {
            perror("accept");
            return 3;
          } else {
            FD_SET(newfd, &master);
            if (newfd > fdmax) {
              fdmax = newfd;
            }
            printf("New connection from %s on socket %d.\n",
                   inet_ntop(remoteaddr.ss_family,
                             get_in_addr((struct sockaddr *)&remoteaddr),
                             remoteIP, INET_ADDRSTRLEN),
                   newfd);
          }
        } else {
          bzero(data, 512);
          if ((nbytes = recv(i, data, sizeof(data), 0)) <= 0) {
            if (nbytes == 0) {
              printf("Socket %d hung up.\n", i);
            } else {
              perror("recv");
            }
            close(i);
            FD_CLR(i, &master);
          } else {
            strtok(data, "\n");
            strtok(data, "\r");
            strcpy(reply, "Default");
            if (!strcmp(data, "close") || !strcmp(data, "Close")) {
              strcpy(reply, "___CLS___");
            } else if (!strcmp(data, "shutdown") || !strcmp(data, "Shutdown")) {
              strcpy(reply, "Server shutting down.\n___CLS___\n");
              for (j = 4; j <= fdmax; j++) {
                if (send(j, reply, strlen(reply), 0) == -1) {
                  perror("send");
                  exit(1);
                }
              }
              close(listener);
              return 0;
            }
            if ((nbytes = send(i, reply, strlen(reply), 0)) == -1) {
              perror("send");
              exit(1);
            }
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x450(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x8(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
lea    -0xc(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    $0x765f,%edi
call   1100 <make_socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10f0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12e8 <main+0x98>
lea    0xd33(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x448(%rbp)
jmp    169e <main+0x44e>
mov    -0x14(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10e0 <select@plt>
cmp    $0xffffffff,%eax
jne    1345 <main+0xf5>
lea    0xcdd(%rip),%rdi
call   1110 <perror@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x448(%rbp)
jmp    169e <main+0x44e>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1699 <main+0x449>
mov    -0x3c(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1686 <main+0x436>
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1426 <main+0x1d6>
movl   $0x4,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13c0 <main+0x170>
lea    0xc69(%rip),%rdi
call   1110 <perror@plt>
movl   $0x3,-0x4(%rbp)
movl   $0x1,-0x448(%rbp)
jmp    169e <main+0x44e>
mov    -0x18(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    13de <main+0x18e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x454(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <get_in_addr@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rdx
mov    %eax,%esi
mov    0x2bda(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1681 <main+0x431>
lea    -0x240(%rbp),%rdi
mov    $0x200,%esi
call   1130 <bzero@plt>
mov    -0x3c(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x444(%rbp)
cmp    $0x0,%eax
jg     14a4 <main+0x254>
cmpl   $0x0,-0x444(%rbp)
jne    147f <main+0x22f>
mov    -0x3c(%rbp),%esi
lea    0xbc8(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    148b <main+0x23b>
lea    0xbc9(%rip),%rdi
call   1110 <perror@plt>
mov    -0x3c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x3c(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1150 <FD_CLR@plt>
jmp    167c <main+0x42c>
lea    -0x240(%rbp),%rdi
lea    0xb87(%rip),%rsi
call   1120 <strtok@plt>
lea    -0x240(%rbp),%rdi
lea    0xb8f(%rip),%rsi
call   1120 <strtok@plt>
lea    -0x440(%rbp),%rdi
lea    0xb7e(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x240(%rbp),%rdi
lea    0xb73(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
je     1515 <main+0x2c5>
lea    -0x240(%rbp),%rdi
lea    0xb5d(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
jne    152d <main+0x2dd>
lea    -0x440(%rbp),%rdi
lea    0xb47(%rip),%rsi
call   1060 <strcpy@plt>
jmp    1619 <main+0x3c9>
lea    -0x240(%rbp),%rdi
lea    0xb39(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
je     1565 <main+0x315>
lea    -0x240(%rbp),%rdi
lea    0xb26(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%eax
jne    1614 <main+0x3c4>
lea    -0x440(%rbp),%rdi
lea    0xb13(%rip),%rsi
call   1060 <strcpy@plt>
movl   $0x4,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     15f6 <main+0x3a6>
mov    -0x40(%rbp),%eax
mov    %eax,-0x464(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x460(%rbp)
lea    -0x440(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x464(%rbp),%edi
mov    -0x460(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
jne    15e3 <main+0x393>
lea    0xad3(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    15e8 <main+0x398>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    157f <main+0x32f>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x448(%rbp)
jmp    169e <main+0x44e>
jmp    1619 <main+0x3c9>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x474(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x470(%rbp)
lea    -0x440(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x474(%rbp),%edi
mov    -0x470(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,-0x444(%rbp)
cmp    $0xffffffff,%eax
jne    1677 <main+0x427>
lea    0xa3f(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    167c <main+0x42c>
jmp    1681 <main+0x431>
jmp    1686 <main+0x436>
jmp    168b <main+0x43b>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    134c <main+0xfc>
jmp    12fa <main+0xaa>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsp,%rbx
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
lea    -0x2c(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
lea    -0x30(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    $0x765f,%edi
call   10f0 <make_socket@plt>
mov    %rax,-0x38(%rbp)
mov    %eax,%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
je     15c8 <main+0x388>
mov    %rbx,-0x40(%rbp)
lea    -0x2c(%rbp),%rsi
mov    -0x38(%rbp),%rbx
mov    %ebx,%edi
call   1160 <FD_SET@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    0x1(%rbx),%edi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
je     15b5 <main+0x375>
lea    -0x30(%rbp),%r15
lea    -0x260(%rbp),%rbx
mov    -0x38(%rbp),%r13
jmp    1312 <main+0xd2>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    0x1(%r13),%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
je     15b5 <main+0x375>
test   %r13d,%r13d
js     12f0 <main+0xb0>
xor    %r12d,%r12d
jmp    136d <main+0x12d>
lea    -0x460(%rbp),%rdi
lea    0xd40(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x460(%rbp),%r14
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     15db <main+0x39b>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r12),%eax
cmp    %r13d,%r12d
mov    %eax,%r12d
jge    12f0 <main+0xb0>
mov    %r12d,%edi
mov    %r15,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     1360 <main+0x120>
cmp    %r12d,-0x38(%rbp)
jne    1410 <main+0x1d0>
movl   $0x4,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rbx
mov    %rbx,%rsi
lea    -0x4c(%rbp),%rdx
call   1130 <accept@plt>
cmp    $0xffffffff,%eax
je     15a2 <main+0x362>
mov    %eax,%r14d
mov    %eax,%edi
lea    -0x2c(%rbp),%rsi
call   1160 <FD_SET@plt>
cmp    %r13d,%r14d
cmovg  %r14d,%r13d
mov    %r13,-0x60(%rbp)
mov    -0x48(%rbp),%r13d
mov    %rbx,%rdi
call   1050 <get_in_addr@plt>
mov    0x2c09(%rip),%rcx
mov    (%rcx),%ecx
mov    %r13d,%edi
mov    -0x60(%rbp),%r13
mov    %eax,%esi
mov    -0x58(%rbp),%rdx
call   1030 <inet_ntop@plt>
lea    0xc23(%rip),%rdi
mov    %rax,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    -0x260(%rbp),%rbx
jmp    1360 <main+0x120>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    14ed <main+0x2ad>
mov    %rbx,%rdi
lea    0xbf8(%rip),%rsi
call   1110 <strtok@plt>
mov    %rbx,%rdi
lea    0xc04(%rip),%rsi
call   1110 <strtok@plt>
lea    -0x460(%rbp),%rdi
lea    0xbf3(%rip),%rsi
call   1060 <strcpy@plt>
mov    -0x260(%rbp),%eax
mov    $0x736f6c63,%ecx
xor    %ecx,%eax
movzwl -0x25c(%rbp),%ecx
xor    $0x65,%ecx
or     %eax,%ecx
je     131c <main+0xdc>
mov    -0x260(%rbp),%eax
mov    $0x736f6c43,%ecx
xor    %ecx,%eax
movzwl -0x25c(%rbp),%ecx
xor    $0x65,%ecx
or     %eax,%ecx
je     131c <main+0xdc>
movabs $0x6e776f6474756853,%rax
6f 77 6e
add    $0x20,%rax
xor    -0x260(%rbp),%rax
movzbl -0x258(%rbp),%ecx
or     %rax,%rcx
je     1527 <main+0x2e7>
mov    -0x260(%rbp),%rax
movabs $0x6e776f6474756853,%rcx
6f 77 6e
xor    %rcx,%rax
movzbl -0x258(%rbp),%ecx
or     %rax,%rcx
jne    132f <main+0xef>
jmp    1527 <main+0x2e7>
jne    1519 <main+0x2d9>
lea    0xb45(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
mov    %r12d,%edi
lea    -0x2c(%rbp),%rsi
call   1140 <FD_CLR@plt>
jmp    1360 <main+0x120>
lea    0xb2f(%rip),%rdi
call   1100 <perror@plt>
jmp    1500 <main+0x2c0>
lea    0xb58(%rip),%rsi
lea    -0x460(%rbp),%rdi
call   1060 <strcpy@plt>
cmp    $0x4,%r13d
jl     1581 <main+0x341>
neg    %r13d
mov    $0x4,%r15d
lea    -0x460(%rbp),%r14
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     15db <main+0x39b>
lea    (%r15,%r13,1),%eax
add    $0x1,%eax
mov    %r15d,%ecx
add    $0x1,%ecx
mov    %ecx,%r15d
cmp    $0x1,%eax
jne    1550 <main+0x310>
mov    -0x38(%rbp),%rdi
call   10b0 <close@plt>
xor    %eax,%eax
mov    -0x40(%rbp),%rbx
mov    %rbx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xa65(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%eax
jmp    158c <main+0x34c>
lea    0xa4b(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%eax
jmp    158c <main+0x34c>
lea    0xa31(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%eax
jmp    1590 <main+0x350>
lea    0xac5(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@.str = [7 x i8] c"listen\00"
@.str.1 = [7 x i8] c"select\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [38 x i8] c"New connection from %s on socket %d.\0A\00"
@.str.4 = [20 x i8] c"Socket %d hung up.\0A\00"
@.str.5 = [5 x i8] c"recv\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [2 x i8] c"\0D\00"
@.str.8 = [8 x i8] c"Default\00"
@.str.9 = [6 x i8] c"close\00"
@.str.10 = [6 x i8] c"Close\00"
@.str.11 = [10 x i8] c"___CLS___\00"
@.str.12 = [9 x i8] c"shutdown\00"
@.str.13 = [9 x i8] c"Shutdown\00"
@.str.14 = [33 x i8] c"Server shutting down.\0A___CLS___\0A\00"
@.str.15 = [5 x i8] c"send\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast %struct.sockaddr_storage* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = load i32, i32* @INET_ADDRSTRLEN
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = call i32 @FD_ZERO(i32* %1)
%18 = call i32 @FD_ZERO(i32* %2)
%19 = call i32 @make_socket(i32 30303)
%20 = call i32 @listen(i32 %19, i32 10)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %122
24: ; preds = %0
%25 = call i32 @FD_SET(i32 %19, i32* %1)
%26 = load i32, i32* %1
store i32 %26, i32* %2
%27 = add nsw i32 %19, 1
%28 = call i32 @select(i32 %27, i32* %2, i32* null, i32* null, i32* null)
%29 = icmp eq i32 %28, -1
br i1 %29, label %42, label %30
30: ; preds = %24
%31 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%32 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
br label %39
33: ; preds = %118, %39
%34 = phi i32 [ %40, %39 ], [ %119, %118 ]
%35 = load i32, i32* %1
store i32 %35, i32* %2
%36 = add nsw i32 %34, 1
%37 = call i32 @select(i32 %36, i32* %2, i32* null, i32* null, i32* null)
%38 = icmp eq i32 %37, -1
br i1 %38, label %42, label %39
39: ; preds = %30, %33
%40 = phi i32 [ %19, %30 ], [ %34, %33 ]
%41 = icmp slt i32 %40, 0
br i1 %41, label %33, label %44
42: ; preds = %33, %24
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %122
44: ; preds = %39, %118
%45 = phi i32 [ %120, %118 ], [ 0, %39 ]
%46 = phi i32 [ %119, %118 ], [ %40, %39 ]
%47 = call i64 @FD_ISSET(i32 %45, i32* %2)
%48 = icmp eq i64 %47, 0
br i1 %48, label %118, label %49
49: ; preds = %44
%50 = icmp eq i32 %45, %19
br i1 %50, label %51, label %65
51: ; preds = %49
store i32 4, i32* %4
%52 = call i32 @accept(i32 %19, %struct.sockaddr* %31, i32* %4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %122
56: ; preds = %51
%57 = call i32 @FD_SET(i32 %52, i32* %1)
%58 = icmp sgt i32 %52, %46
%59 = select i1 %58, i32 %52, i32 %46
%60 = load i32, i32* %32
%61 = call i32 @get_in_addr(%struct.sockaddr* %31)
%62 = load i32, i32* @INET_ADDRSTRLEN
%63 = call i8* @inet_ntop(i32 %60, i32 %61, i8* %14, i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %63, i32 %52)
br label %118
65: ; preds = %49
%66 = call i32 @bzero(i8* %15, i32 512)
%67 = call i32 @recv(i32 %45, i8* %15, i32 512, i32 0)
%68 = icmp slt i32 %67, 1
br i1 %68, label %69, label %78
69: ; preds = %65
%70 = icmp eq i32 %67, 0
br i1 %70, label %71, label %73
71: ; preds = %69
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %75
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %71
%76 = call i32 @close(i32 %45)
%77 = call i32 @FD_CLR(i32 %45, i32* %1)
br label %118
78: ; preds = %65
%79 = call i32 @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%80 = call i32 @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%81 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%82 = call i32 @bcmp(i8* dereferenceable(6) %15, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i64 6)
%83 = icmp eq i32 %82, 0
br i1 %83, label %87, label %84
84: ; preds = %78
%85 = call i32 @bcmp(i8* dereferenceable(6) %15, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i64 6)
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84, %78
%88 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
br label %111
89: ; preds = %84
%90 = call i32 @bcmp(i8* dereferenceable(9) %15, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i64 9)
%91 = icmp eq i32 %90, 0
br i1 %91, label %95, label %92
92: ; preds = %89
%93 = call i32 @bcmp(i8* dereferenceable(9) %15, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i64 9)
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %111
95: ; preds = %92, %89
%96 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0))
%97 = icmp slt i32 %46, 4
br i1 %97, label %109, label %101
98: ; preds = %101
%99 = add nuw i32 %102, 1
%100 = icmp eq i32 %102, %46
br i1 %100, label %109, label %101
101: ; preds = %95, %98
%102 = phi i32 [ %99, %98 ], [ 4, %95 ]
%103 = call i32 @strlen(i8* %16)
%104 = call i32 @send(i32 %102, i8* %16, i32 %103, i32 0)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %98
106: ; preds = %101
%107 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %98, %95
%110 = call i32 @close(i32 %19)
br label %122
111: ; preds = %92, %87
%112 = call i32 @strlen(i8* %16)
%113 = call i32 @send(i32 %45, i8* %16, i32 %112, i32 0)
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %118
115: ; preds = %111
%116 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %44, %75, %111, %56
%119 = phi i32 [ %59, %56 ], [ %46, %75 ], [ %46, %111 ], [ %46, %44 ]
%120 = add nuw nsw i32 %45, 1
%121 = icmp slt i32 %45, %119
br i1 %121, label %44, label %33
122: ; preds = %109, %54, %42, %22
%123 = phi i32 [ 1, %22 ], [ 2, %42 ], [ 3, %54 ], [ 0, %109 ]
ret i32 %123
}