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

/* 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;
  socklen_t 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', sizeof myaddr.sin_zero);
  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)
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    -0x38(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1343 <main+0x113>
lea    0xcde(%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    136f <main+0x13f>
lea    0xcb7(%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    13c0 <main+0x190>
lea    0xc6d(%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     15c0 <main+0x390>
mov    -0x150(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15a7 <main+0x377>
mov    -0x150(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    147a <main+0x24a>
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    143b <main+0x20b>
lea    0xbf4(%rip),%rdi
call   1100 <perror@plt>
jmp    1475 <main+0x245>
mov    -0x3c(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    1459 <main+0x229>
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    0xbbe(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    15a2 <main+0x372>
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     14f3 <main+0x2c3>
cmpl   $0x0,-0x144(%rbp)
jne    14c8 <main+0x298>
mov    -0x150(%rbp),%esi
lea    0xba3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    14d4 <main+0x2a4>
lea    0xbb1(%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    159d <main+0x36d>
movl   $0x0,-0x154(%rbp)
mov    -0x154(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     1598 <main+0x368>
mov    -0x154(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     157f <main+0x34f>
mov    -0x154(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     157a <main+0x34a>
mov    -0x154(%rbp),%eax
cmp    -0x150(%rbp),%eax
je     157a <main+0x34a>
mov    -0x154(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    -0x144(%rbp),%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    1575 <main+0x345>
lea    0xb15(%rip),%rdi
call   1100 <perror@plt>
jmp    157a <main+0x34a>
jmp    157f <main+0x34f>
jmp    1584 <main+0x354>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    14fd <main+0x2cd>
jmp    159d <main+0x36d>
jmp    15a2 <main+0x372>
jmp    15a7 <main+0x377>
jmp    15ac <main+0x37c>
mov    -0x150(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x150(%rbp)
jmp    13ca <main+0x19a>
jmp    1381 <main+0x151>

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    1355 <main+0x125>
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    1355 <main+0x125>
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)
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    130a <main+0xda>
lea    0xd0a(%rip),%rdi
jmp    1355 <main+0x125>
mov    %ebx,%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1324 <main+0xf4>
lea    0xcf5(%rip),%rdi
jmp    1355 <main+0x125>
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    1364 <main+0x134>
lea    0xcc9(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0x4(%rsp),%r14
mov    %ebx,%r13d
jmp    138f <main+0x15f>
xchg   %ax,%ax
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     134e <main+0x11e>
test   %r13d,%r13d
js     1370 <main+0x140>
xor    %r15d,%r15d
jmp    13ac <main+0x17c>
lea    0x4(%rsp),%r14
xchg   %ax,%ax
lea    0x1(%r15),%eax
cmp    %r13d,%r15d
mov    %eax,%r15d
jge    1370 <main+0x140>
mov    %r15d,%edi
mov    %r14,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13a0 <main+0x170>
cmp    %ebx,%r15d
jne    1420 <main+0x1f0>
movl   $0x10,0x8(%rsp)
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     14c7 <main+0x297>
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    0xc26(%rip),%rdi
mov    %rax,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <printf@plt>
jmp    13a0 <main+0x170>
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    149c <main+0x26c>
test   %r13d,%r13d
js     13a0 <main+0x170>
mov    %eax,%r12d
lea    0x1(%r13),%ebp
xor    %r14d,%r14d
jmp    145d <main+0x22d>
nopl   (%rax)
add    $0x1,%r14d
cmp    %r14d,%ebp
je     1399 <main+0x169>
mov    %r14d,%edi
mov    %rsp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1450 <main+0x220>
cmp    %r14d,%ebx
je     1450 <main+0x220>
cmp    %r14d,%r15d
je     1450 <main+0x220>
mov    %r14d,%edi
lea    0x30(%rsp),%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    1450 <main+0x220>
lea    0xbf0(%rip),%rdi
call   1100 <perror@plt>
jmp    1450 <main+0x220>
jne    14d8 <main+0x2a8>
lea    0xbba(%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    13a0 <main+0x170>
lea    0xb57(%rip),%rdi
call   1100 <perror@plt>
jmp    13a0 <main+0x170>
lea    0xba1(%rip),%rdi
call   1100 <perror@plt>
jmp    14af <main+0x27f>

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 = load i32, i32* %41
%43 = call i32 @memset(i32 %42, i8 signext 0, i32 4)
%44 = load i32, i32* %7
%45 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%46 = call i32 @bind(i32 %44, %struct.sockaddr* %45, i32 16)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %33
%49 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %33
%52 = load i32, i32* %7
%53 = call i32 @listen(i32 %52, i32 10)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %51
%59 = load i32, i32* %7
%60 = call i32 @FD_SET(i32 %59, i32* %2)
%61 = load i32, i32* %7
store i32 %61, i32* %6
br label %62
62: ; preds = %163, %58
%63 = load i32, i32* %2
store i32 %63, i32* %3
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
%66 = call i32 @select(i32 %65, i32* %3, i32* null, i32* null, i32* null)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %62
store i32 0, i32* %13
br label %72
72: ; preds = %160, %71
%73 = load i32, i32* %13
%74 = load i32, i32* %6
%75 = icmp sle i32 %73, %74
br i1 %75, label %76, label %163
76: ; preds = %72
%77 = load i32, i32* %13
%78 = call i64 @FD_ISSET(i32 %77, i32* %3)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %159
80: ; preds = %76
%81 = load i32, i32* %13
%82 = load i32, i32* %7
%83 = icmp eq i32 %81, %82
br i1 %83, label %84, label %107
84: ; preds = %80
store i32 16, i32* %12
%85 = load i32, i32* %7
%86 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%87 = call i32 @accept(i32 %85, %struct.sockaddr* %86, i32* %12)
store i32 %87, i32* %8
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %106
91: ; preds = %84
%92 = load i32, i32* %8
%93 = call i32 @FD_SET(i32 %92, i32* %2)
%94 = load i32, i32* %8
%95 = load i32, i32* %6
%96 = icmp sgt i32 %94, %95
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = load i32, i32* %8
store i32 %98, i32* %6
br label %99
99: ; preds = %97, %91
%100 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%101 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %100, i32 0, i32 0
%102 = load i32, i32* %101
%103 = call i8* @inet_ntoa(i32 %102)
%104 = load i32, i32* %8
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %103, i32 %104)
br label %106
106: ; preds = %99, %89
br label %158
107: ; preds = %80
%108 = load i32, i32* %13
%109 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%110 = call i32 @recv(i32 %108, i8* %109, i32 256, i32 0)
store i32 %110, i32* %10
%111 = icmp sle i32 %110, 0
br i1 %111, label %112, label %125
112: ; preds = %107
%113 = load i32, i32* %10
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %112
%116 = load i32, i32* %13
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %116)
br label %120
118: ; preds = %112
%119 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %120
120: ; preds = %118, %115
%121 = load i32, i32* %13
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* %13
%124 = call i32 @FD_CLR(i32 %123, i32* %2)
br label %157
125: ; preds = %107
store i32 0, i32* %14
br label %126
126: ; preds = %153, %125
%127 = load i32, i32* %14
%128 = load i32, i32* %6
%129 = icmp sle i32 %127, %128
br i1 %129, label %130, label %156
130: ; preds = %126
%131 = load i32, i32* %14
%132 = call i64 @FD_ISSET(i32 %131, i32* %2)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %152
134: ; preds = %130
%135 = load i32, i32* %14
%136 = load i32, i32* %7
%137 = icmp ne i32 %135, %136
br i1 %137, label %138, label %151
138: ; preds = %134
%139 = load i32, i32* %14
%140 = load i32, i32* %13
%141 = icmp ne i32 %139, %140
br i1 %141, label %142, label %151
142: ; preds = %138
%143 = load i32, i32* %14
%144 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%145 = load i32, i32* %10
%146 = call i32 @send(i32 %143, i8* %144, i32 %145, i32 0)
%147 = icmp eq i32 %146, -1
br i1 %147, label %148, label %150
148: ; preds = %142
%149 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %150
150: ; preds = %148, %142
br label %151
151: ; preds = %150, %138, %134
br label %152
152: ; preds = %151, %130
br label %153
153: ; preds = %152
%154 = load i32, i32* %14
%155 = add nsw i32 %154, 1
store i32 %155, i32* %14
br label %126
156: ; preds = %126
br label %157
157: ; preds = %156, %120
br label %158
158: ; preds = %157, %106
br label %159
159: ; preds = %158, %76
br label %160
160: ; preds = %159
%161 = load i32, i32* %13
%162 = add nsw i32 %161, 1
store i32 %162, i32* %13
br label %72
163: ; preds = %72
br label %62
}

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 = call i32 @memset(i32 undef, i8 signext 0, i32 4)
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @bind(i32 %19, %struct.sockaddr* %40, i32 16)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %32
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %32
%47 = call i32 @listen(i32 %19, i32 10)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %46
%53 = call i32 @FD_SET(i32 %19, i32* %1)
%54 = load i32, i32* %1
store i32 %54, i32* %2
%55 = add nuw nsw i32 %19, 1
%56 = call i32 @select(i32 %55, i32* %2, i32* null, i32* null, i32* null)
%57 = icmp eq i32 %56, -1
br i1 %57, label %70, label %58
58: ; preds = %52
%59 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %67
61: ; preds = %122, %67
%62 = phi i32 [ %68, %67 ], [ %123, %122 ]
%63 = load i32, i32* %1
store i32 %63, i32* %2
%64 = add nsw i32 %62, 1
%65 = call i32 @select(i32 %64, i32* %2, i32* null, i32* null, i32* null)
%66 = icmp eq i32 %65, -1
br i1 %66, label %70, label %67
67: ; preds = %58, %61
%68 = phi i32 [ %19, %58 ], [ %62, %61 ]
%69 = icmp slt i32 %68, 0
br i1 %69, label %61, label %73
70: ; preds = %61, %52
%71 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %67, %122
%74 = phi i32 [ %124, %122 ], [ 0, %67 ]
%75 = phi i32 [ %123, %122 ], [ %68, %67 ]
%76 = call i64 @FD_ISSET(i32 %74, i32* %2)
%77 = icmp eq i64 %76, 0
br i1 %77, label %122, label %78
78: ; preds = %73
%79 = icmp eq i32 %74, %19
br i1 %79, label %80, label %92
80: ; preds = %78
store i32 16, i32* %7
%81 = call i32 @accept(i32 %19, %struct.sockaddr* %59, i32* %7)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %122
85: ; preds = %80
%86 = call i32 @FD_SET(i32 %81, i32* %1)
%87 = icmp sgt i32 %81, %75
%88 = select i1 %87, i32 %81, i32 %75
%89 = load i32, i32* %60
%90 = call i8* @inet_ntoa(i32 %89)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %90, i32 %81)
br label %122
92: ; preds = %78
%93 = call i32 @recv(i32 %74, i8* %12, i32 256, i32 0)
%94 = icmp slt i32 %93, 1
br i1 %94, label %97, label %95
95: ; preds = %92
%96 = icmp slt i32 %75, 0
br i1 %96, label %122, label %106
97: ; preds = %92
%98 = icmp eq i32 %93, 0
br i1 %98, label %99, label %101
99: ; preds = %97
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %74)
br label %103
101: ; preds = %97
%102 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %103
103: ; preds = %101, %99
%104 = call i32 @close(i32 %74)
%105 = call i32 @FD_CLR(i32 %74, i32* %1)
br label %122
106: ; preds = %95, %119
%107 = phi i32 [ %120, %119 ], [ 0, %95 ]
%108 = call i64 @FD_ISSET(i32 %107, i32* %1)
%109 = icmp eq i64 %108, 0
%110 = icmp eq i32 %107, %19
%111 = select i1 %109, i1 true, i1 %110
%112 = icmp eq i32 %107, %74
%113 = or i1 %111, %112
br i1 %113, label %119, label %114
114: ; preds = %106
%115 = call i32 @send(i32 %107, i8* %12, i32 %93, i32 0)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %119
117: ; preds = %114
%118 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %119
119: ; preds = %106, %114, %117
%120 = add nuw i32 %107, 1
%121 = icmp eq i32 %107, %75
br i1 %121, label %122, label %106
122: ; preds = %119, %95, %73, %103, %83, %85
%123 = phi i32 [ %75, %83 ], [ %88, %85 ], [ %75, %103 ], [ %75, %73 ], [ %75, %95 ], [ %75, %119 ]
%124 = add nuw nsw i32 %74, 1
%125 = icmp slt i32 %74, %123
br i1 %125, label %73, label %61
}