#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ remoteaddr;
typedef int /*<<< orphan*/ myaddr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buf;

/* 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 /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, 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, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  fd_set master;
  fd_set read_fds;
  struct sockaddr_in myaddr;
  struct sockaddr_in remoteaddr;
  int fdmax;
  int listener;
  int newfd;
  char buf[256];
  int nbytes;
  int yes = 1;
  int addrlen;
  int i, j;
  FD_ZERO(&master);
  FD_ZERO(&read_fds);
  if ((listener = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
    perror("setsockopt");
    exit(1);
  }
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = INADDR_ANY;
  myaddr.sin_port = htons(9034);
  memset(&(myaddr.sin_zero), '\0', 8);
  if (bind(listener, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1) {
    perror("bind");
    exit(1);
  }
  if (listen(listener, 10) == -1) {
    perror("listen");
    exit(1);
  }
  FD_SET(listener, &master);
  fdmax = listener;
  for (;;) {
    read_fds = master;
    if (select(fdmax + 1, &read_fds, NULL, NULL, NULL) == -1) {
      perror("select");
      exit(1);
    }
    for (i = 0; i <= fdmax; i++) {
      if (FD_ISSET(i, &read_fds)) {
        if (i == listener) {
          addrlen = sizeof(remoteaddr);
          if ((newfd = accept(listener, (struct sockaddr *)&remoteaddr,
                              &addrlen)) == -1) {
            perror("accept");
          } else {
            FD_SET(newfd, &master);
            if (newfd > fdmax) {
              fdmax = newfd;
            }
            printf("selectserver: new connection from %s on "
                   "socket %d\n",
                   inet_ntoa(remoteaddr.sin_addr), newfd);
          }
        } else {
          if ((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) {
            if (nbytes == 0) {
              printf("selectserver: socket %d hung up\n", i);
            } else {
              perror("recv");
            }
            close(i);
            FD_CLR(i, &master);
          } else {
            for (j = 0; j <= fdmax; j++) {
              if (FD_ISSET(j, &master)) {
                if (j != listener && j != i) {
                  if (send(j, buf, nbytes, 0) == -1) {
                    perror("send");
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x148(%rbp)
lea    -0x8(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
lea    -0xc(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    1299 <main+0x69>
lea    0xd76(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x38(%rbp),%edi
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
lea    -0x148(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12df <main+0xaf>
lea    0xd37(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x234a,%edi
call   1070 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    -0x38(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1348 <main+0x118>
lea    0xcd9(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x38(%rbp),%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1374 <main+0x144>
lea    0xcb2(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x38(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
jne    13c5 <main+0x195>
lea    0xc68(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
movl   $0x0,-0x150(%rbp)
mov    -0x150(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     15c5 <main+0x395>
mov    -0x150(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15ac <main+0x37c>
mov    -0x150(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    147f <main+0x24f>
movl   $0x10,-0x14c(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x14c(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    1440 <main+0x210>
lea    0xbef(%rip),%rdi
call   1100 <perror@plt>
jmp    147a <main+0x24a>
mov    -0x3c(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    145e <main+0x22e>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x3c(%rbp),%edx
lea    0xbb9(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    15a7 <main+0x377>
mov    -0x150(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x144(%rbp)
cmp    $0x0,%eax
jg     14f8 <main+0x2c8>
cmpl   $0x0,-0x144(%rbp)
jne    14cd <main+0x29d>
mov    -0x150(%rbp),%esi
lea    0xb9e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    14d9 <main+0x2a9>
lea    0xbac(%rip),%rdi
call   1100 <perror@plt>
mov    -0x150(%rbp),%edi
call   10b0 <close@plt>
mov    -0x150(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1120 <FD_CLR@plt>
jmp    15a2 <main+0x372>
movl   $0x0,-0x154(%rbp)
mov    -0x154(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     159d <main+0x36d>
mov    -0x154(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1584 <main+0x354>
mov    -0x154(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     157f <main+0x34f>
mov    -0x154(%rbp),%eax
cmp    -0x150(%rbp),%eax
je     157f <main+0x34f>
mov    -0x154(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    -0x144(%rbp),%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    157a <main+0x34a>
lea    0xb10(%rip),%rdi
call   1100 <perror@plt>
jmp    157f <main+0x34f>
jmp    1584 <main+0x354>
jmp    1589 <main+0x359>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    1502 <main+0x2d2>
jmp    15a2 <main+0x372>
jmp    15a7 <main+0x377>
jmp    15ac <main+0x37c>
jmp    15b1 <main+0x381>
mov    -0x150(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x150(%rbp)
jmp    13cf <main+0x19f>
jmp    1386 <main+0x156>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
movl   $0x1,0xc(%rsp)
mov    %rsp,%rdi
call   10c0 <FD_ZERO@plt>
lea    0x4(%rsp),%rdi
call   10c0 <FD_ZERO@plt>
mov    0x2d7e(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
jne    1286 <main+0x56>
lea    0xd7f(%rip),%rdi
jmp    135a <main+0x12a>
mov    %eax,%ebx
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
mov    0x2d28(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12bd <main+0x8d>
lea    0xd4f(%rip),%rdi
jmp    135a <main+0x12a>
mov    0x0(%rbp),%eax
mov    %eax,0x1c(%rsp)
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x234a,%edi
call   1070 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x14(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    130f <main+0xdf>
lea    0xd05(%rip),%rdi
jmp    135a <main+0x12a>
mov    %ebx,%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1329 <main+0xf9>
lea    0xcf0(%rip),%rdi
jmp    135a <main+0x12a>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1140 <FD_SET@plt>
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
lea    0x1(%rbx),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
jne    1369 <main+0x139>
lea    0xcc4(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0x4(%rsp),%r14
mov    %ebx,%r13d
jmp    139f <main+0x16f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
lea    0x1(%r13),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
je     1353 <main+0x123>
test   %r13d,%r13d
js     1380 <main+0x150>
xor    %r15d,%r15d
jmp    13bc <main+0x18c>
lea    0x4(%rsp),%r14
xchg   %ax,%ax
lea    0x1(%r15),%eax
cmp    %r13d,%r15d
mov    %eax,%r15d
jge    1380 <main+0x150>
mov    %r15d,%edi
mov    %r14,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13b0 <main+0x180>
cmp    %ebx,%r15d
jne    1430 <main+0x200>
movl   $0x10,0x8(%rsp)
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     14d7 <main+0x2a7>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rsp,%rsi
call   1140 <FD_SET@plt>
cmp    %r13d,%ebp
cmovg  %ebp,%r13d
mov    0x20(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xc16(%rip),%rdi
mov    %rax,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <printf@plt>
jmp    13b0 <main+0x180>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
lea    0x30(%rsp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    14ac <main+0x27c>
test   %r13d,%r13d
js     13b0 <main+0x180>
mov    %eax,%r12d
lea    0x1(%r13),%ebp
xor    %r14d,%r14d
jmp    146d <main+0x23d>
nopl   (%rax)
add    $0x1,%r14d
cmp    %r14d,%ebp
je     13a9 <main+0x179>
mov    %r14d,%edi
mov    %rsp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1460 <main+0x230>
cmp    %r14d,%ebx
je     1460 <main+0x230>
cmp    %r14d,%r15d
je     1460 <main+0x230>
mov    %r14d,%edi
lea    0x30(%rsp),%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    1460 <main+0x230>
lea    0xbe0(%rip),%rdi
call   1100 <perror@plt>
jmp    1460 <main+0x230>
jne    14e8 <main+0x2b8>
lea    0xbaa(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
mov    %r15d,%edi
mov    %rsp,%rsi
call   1120 <FD_CLR@plt>
jmp    13b0 <main+0x180>
lea    0xb47(%rip),%rdi
call   1100 <perror@plt>
jmp    13b0 <main+0x180>
lea    0xb91(%rip),%rdi
call   1100 <perror@plt>
jmp    14bf <main+0x28f>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"select\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [51 x i8] c"selectserver: new connection from %s on socket %d\0A\00"
@.str.7 = [33 x i8] c"selectserver: socket %d hung up\0A\00"
@.str.8 = [5 x i8] c"recv\00"
@.str.9 = [5 x i8] c"send\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%13 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%14 = bitcast i32* %7 to i8*
%15 = call i32 @FD_ZERO(i32* %1)
%16 = call i32 @FD_ZERO(i32* %2)
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %0
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = call i32 @setsockopt(i32 %19, i32 %25, i32 %26, i32* %6, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %35, i32* %36
%37 = call i32 @htons(i32 9034)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%40 = call i32 @memset(i32* %39, i8 signext 0, i32 8)
%41 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%42 = call i32 @bind(i32 %19, %struct.sockaddr* %41, i32 16)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %32
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %32
%48 = call i32 @listen(i32 %19, i32 10)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %47
%54 = call i32 @FD_SET(i32 %19, i32* %1)
%55 = load i32, i32* %1
store i32 %55, i32* %2
%56 = add nuw nsw i32 %19, 1
%57 = call i32 @select(i32 %56, i32* %2, i32* null, i32* null, i32* null)
%58 = icmp eq i32 %57, -1
br i1 %58, label %71, label %59
59: ; preds = %53
%60 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %68
62: ; preds = %123, %68
%63 = phi i32 [ %69, %68 ], [ %124, %123 ]
%64 = load i32, i32* %1
store i32 %64, i32* %2
%65 = add nsw i32 %63, 1
%66 = call i32 @select(i32 %65, i32* %2, i32* null, i32* null, i32* null)
%67 = icmp eq i32 %66, -1
br i1 %67, label %71, label %68
68: ; preds = %59, %62
%69 = phi i32 [ %19, %59 ], [ %63, %62 ]
%70 = icmp slt i32 %69, 0
br i1 %70, label %62, label %74
71: ; preds = %62, %53
%72 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %68, %123
%75 = phi i32 [ %125, %123 ], [ 0, %68 ]
%76 = phi i32 [ %124, %123 ], [ %69, %68 ]
%77 = call i64 @FD_ISSET(i32 %75, i32* %2)
%78 = icmp eq i64 %77, 0
br i1 %78, label %123, label %79
79: ; preds = %74
%80 = icmp eq i32 %75, %19
br i1 %80, label %81, label %93
81: ; preds = %79
store i32 16, i32* %7
%82 = call i32 @accept(i32 %19, %struct.sockaddr* %60, i32* %7)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %123
86: ; preds = %81
%87 = call i32 @FD_SET(i32 %82, i32* %1)
%88 = icmp sgt i32 %82, %76
%89 = select i1 %88, i32 %82, i32 %76
%90 = load i32, i32* %61
%91 = call i8* @inet_ntoa(i32 %90)
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %91, i32 %82)
br label %123
93: ; preds = %79
%94 = call i32 @recv(i32 %75, i8* %12, i32 256, i32 0)
%95 = icmp slt i32 %94, 1
br i1 %95, label %98, label %96
96: ; preds = %93
%97 = icmp slt i32 %76, 0
br i1 %97, label %123, label %107
98: ; preds = %93
%99 = icmp eq i32 %94, 0
br i1 %99, label %100, label %102
100: ; preds = %98
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %75)
br label %104
102: ; preds = %98
%103 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %104
104: ; preds = %102, %100
%105 = call i32 @close(i32 %75)
%106 = call i32 @FD_CLR(i32 %75, i32* %1)
br label %123
107: ; preds = %96, %120
%108 = phi i32 [ %121, %120 ], [ 0, %96 ]
%109 = call i64 @FD_ISSET(i32 %108, i32* %1)
%110 = icmp eq i64 %109, 0
%111 = icmp eq i32 %108, %19
%112 = select i1 %110, i1 true, i1 %111
%113 = icmp eq i32 %108, %75
%114 = or i1 %112, %113
br i1 %114, label %120, label %115
115: ; preds = %107
%116 = call i32 @send(i32 %108, i8* %12, i32 %94, i32 0)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %120
118: ; preds = %115
%119 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %120
120: ; preds = %107, %115, %118
%121 = add nuw i32 %108, 1
%122 = icmp eq i32 %108, %76
br i1 %122, label %123, label %107
123: ; preds = %120, %96, %74, %104, %84, %86
%124 = phi i32 [ %76, %84 ], [ %89, %86 ], [ %76, %104 ], [ %76, %74 ], [ %76, %96 ], [ %76, %120 ]
%125 = add nuw nsw i32 %75, 1
%126 = icmp slt i32 %75, %124
br i1 %126, label %74, label %62
}