#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 dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ recvdata;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
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*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, 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 /*<<< orphan*/ stderr;
int main(void) {
  struct addrinfo hints, *p, *res;
  int sd, nsd;
  int gais;
  int yes;
  struct sockaddr_storage clientAddr;
  socklen_t clientAddrLen;
  fd_set mS, mS_cp;
  int fdmax, i, j;
  int recvbytes;
  char recvdata[256];
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  clientAddrLen = sizeof(struct sockaddr_storage);
  FD_ZERO(&mS);
  FD_ZERO(&mS_cp);
  if ((gais = getaddrinfo(NULL, "3199", &hints, &res)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(gais));
    exit(1);
  }
  for (p = res; p != NULL; p = p->ai_next) {
    if ((sd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("server: socket");
      continue;
    }
    if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
      perror("setsockopt");
      exit(2);
    }
    if (bind(sd, p->ai_addr, p->ai_addrlen) == -1) {
      perror("server: bind");
      close(sd);
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "server: failed to bind()\n");
    exit(3);
  }
  freeaddrinfo(res);
  if (listen(sd, 5) == -1) {
    perror("listen: ");
    exit(4);
  }
  FD_SET(sd, &mS);
  fdmax = sd;
  while (1) {
    mS_cp = mS;
    if (select(fdmax + 1, &mS_cp, NULL, NULL, NULL) == -1) {
      perror("select: ");
      exit(5);
    }
    for (i = 0; i <= fdmax; i++) {
      if (FD_ISSET(i, &mS_cp)) {
        if (i == sd) {
          nsd = accept(sd, (struct sockaddr *)&clientAddr, &clientAddrLen);
          if (nsd == -1) {
            perror("accept: ");
          } else {
            FD_SET(nsd, &mS);
            if (nsd > fdmax) {
              fdmax = nsd;
            }
          }
        } else {
          if ((recvbytes = recv(i, recvdata, sizeof(recvdata), 0)) <= 0) {
            if (recvbytes == 0) {
              printf("clients gone!!\n");
            } else {
              perror("recv");
            }
            close(i);
            FD_CLR(i, &mS);
          } else {
            for (j = 0; j <= fdmax; j++) {
              if (FD_ISSET(j, &mS)) {
                if (j == i || j == sd) {
                  continue;
                } else {
                  if ((send(j, recvdata, recvbytes, 0) == -1)) {
                    perror("send");
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x4,-0x5c(%rbp)
lea    -0x60(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
lea    -0x64(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd46(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1140 <getaddrinfo@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     130b <main+0xbb>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x184(%rbp)
mov    -0x4c(%rbp),%edi
call   1080 <gai_strerror@plt>
mov    -0x184(%rbp),%edi
mov    %rax,%rdx
lea    0xd0b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     13e5 <main+0x195>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   1170 <socket@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    1355 <main+0x105>
lea    0xccb(%rip),%rdi
call   1100 <perror@plt>
jmp    13d4 <main+0x184>
mov    -0x44(%rbp),%edi
mov    0x2c89(%rip),%rax
mov    (%rax),%esi
mov    0x2c50(%rip),%rax
mov    (%rax),%edx
lea    -0x50(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1398 <main+0x148>
lea    0xc9c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1130 <exit@plt>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13cf <main+0x17f>
lea    0xc73(%rip),%rdi
call   1100 <perror@plt>
mov    -0x44(%rbp),%edi
call   10a0 <close@plt>
jmp    13d4 <main+0x184>
jmp    13e5 <main+0x195>
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1313 <main+0xc3>
cmpq   $0x0,-0x38(%rbp)
jne    1411 <main+0x1c1>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xc3d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x3,%edi
call   1130 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1160 <freeaddrinfo@plt>
mov    -0x44(%rbp),%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1446 <main+0x1f6>
lea    0xc20(%rip),%rdi
call   1100 <perror@plt>
mov    $0x4,%edi
call   1130 <exit@plt>
mov    -0x44(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1150 <FD_SET@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x68(%rbp),%edi
add    $0x1,%edi
lea    -0x64(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
jne    1497 <main+0x247>
lea    0xbd8(%rip),%rdi
call   1100 <perror@plt>
mov    $0x5,%edi
call   1130 <exit@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x68(%rbp),%eax
jg     1632 <main+0x3e2>
mov    -0x6c(%rbp),%edi
lea    -0x64(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     161f <main+0x3cf>
mov    -0x6c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jne    1522 <main+0x2d2>
mov    -0x44(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x5c(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    14fa <main+0x2aa>
lea    0xb79(%rip),%rdi
call   1100 <perror@plt>
jmp    151d <main+0x2cd>
mov    -0x48(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1150 <FD_SET@plt>
mov    -0x48(%rbp),%eax
cmp    -0x68(%rbp),%eax
jle    1518 <main+0x2c8>
mov    -0x48(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    151d <main+0x2cd>
jmp    161a <main+0x3ca>
mov    -0x6c(%rbp),%edi
lea    -0x180(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jg     1584 <main+0x334>
cmpl   $0x0,-0x74(%rbp)
jne    155f <main+0x30f>
lea    0xb1d(%rip),%rdi
call   1070 <printf@plt>
jmp    156b <main+0x31b>
lea    0xb1c(%rip),%rdi
call   1100 <perror@plt>
mov    -0x6c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x6c(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1120 <FD_CLR@plt>
jmp    1615 <main+0x3c5>
movl   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x68(%rbp),%eax
jg     1610 <main+0x3c0>
mov    -0x70(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15fd <main+0x3ad>
mov    -0x70(%rbp),%eax
cmp    -0x6c(%rbp),%eax
je     15c5 <main+0x375>
mov    -0x70(%rbp),%eax
cmp    -0x44(%rbp),%eax
jne    15ca <main+0x37a>
jmp    1602 <main+0x3b2>
mov    -0x70(%rbp),%edi
lea    -0x180(%rbp),%rsi
mov    -0x74(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    15f3 <main+0x3a3>
lea    0xa99(%rip),%rdi
call   1100 <perror@plt>
jmp    15f8 <main+0x3a8>
jmp    15fd <main+0x3ad>
jmp    1602 <main+0x3b2>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    158b <main+0x33b>
jmp    1615 <main+0x3c5>
jmp    161a <main+0x3ca>
jmp    161f <main+0x3cf>
jmp    1624 <main+0x3d4>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    149e <main+0x24e>
jmp    1458 <main+0x208>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
movl   $0x4,0x14(%rsp)
lea    0xc(%rsp),%rdi
call   10c0 <FD_ZERO@plt>
lea    0x10(%rsp),%rdi
call   10c0 <FD_ZERO@plt>
lea    0xd41(%rip),%rsi
lea    0x18(%rsp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1140 <getaddrinfo@plt>
test   %eax,%eax
jne    12fd <main+0xad>
mov    0x18(%rsp),%rbp
test   %rbp,%rbp
jne    132a <main+0xda>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x3,%edi
call   1130 <exit@plt>
mov    0x2cc4(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <gai_strerror@plt>
lea    0xcf1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    0x2cb7(%rip),%r13
mov    0x2c80(%rip),%r14
lea    0x24(%rsp),%r15
lea    0xcec(%rip),%r12
jmp    136d <main+0x11d>
lea    0xcc9(%rip),%rdi
call   1100 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x18(%rbp),%rbp
test   %rbp,%rbp
je     12dc <main+0x8c>
mov    0x10(%rbp),%edi
mov    0x8(%rbp),%edx
mov    0xc(%rbp),%esi
call   1170 <socket@plt>
cmp    $0xffffffff,%eax
je     1346 <main+0xf6>
mov    %eax,%ebx
mov    0x0(%r13),%esi
mov    (%r14),%edx
mov    %eax,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     15a5 <main+0x355>
mov    0x0(%rbp),%edx
mov    0x4(%rbp),%esi
mov    %ebx,%edi
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13c5 <main+0x175>
mov    %r12,%rdi
call   1100 <perror@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
jmp    1360 <main+0x110>
mov    0x18(%rsp),%rdi
call   1160 <freeaddrinfo@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13f6 <main+0x1a6>
lea    0xc70(%rip),%rdi
call   1100 <perror@plt>
mov    $0x4,%edi
call   1130 <exit@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1150 <FD_SET@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp)
lea    0x1(%rbx),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
jne    1439 <main+0x1e9>
lea    0xc36(%rip),%rdi
call   1100 <perror@plt>
mov    $0x5,%edi
call   1130 <exit@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%r13d
jmp    1470 <main+0x220>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%eax
mov    %eax,0x10(%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     1423 <main+0x1d3>
test   %r13d,%r13d
js     1450 <main+0x200>
xor    %r15d,%r15d
jmp    148c <main+0x23c>
lea    0x10(%rsp),%r14
nop
lea    0x1(%r15),%eax
cmp    %r13d,%r15d
mov    %eax,%r15d
jge    1450 <main+0x200>
mov    %r15d,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1480 <main+0x230>
cmp    %ebx,%r15d
jne    14e0 <main+0x290>
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     1586 <main+0x336>
mov    %eax,%ebp
mov    %eax,%edi
lea    0xc(%rsp),%rsi
call   1150 <FD_SET@plt>
cmp    %r13d,%ebp
cmovg  %ebp,%r13d
jmp    1480 <main+0x230>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
lea    0x50(%rsp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    155e <main+0x30e>
test   %r13d,%r13d
js     1480 <main+0x230>
mov    %eax,%r12d
lea    0x1(%r13),%ebp
xor    %r14d,%r14d
jmp    151d <main+0x2cd>
nopl   0x0(%rax)
add    $0x1,%r14d
cmp    %r14d,%ebp
je     147a <main+0x22a>
mov    %r14d,%edi
lea    0xc(%rsp),%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1510 <main+0x2c0>
cmp    %r14d,%r15d
je     1510 <main+0x2c0>
cmp    %r14d,%ebx
je     1510 <main+0x2c0>
mov    %r14d,%edi
lea    0x50(%rsp),%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    1510 <main+0x2c0>
lea    0xb20(%rip),%rdi
call   1100 <perror@plt>
jmp    1510 <main+0x2c0>
jne    1597 <main+0x347>
lea    0xb15(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r15d,%edi
lea    0xc(%rsp),%rsi
call   1120 <FD_CLR@plt>
jmp    1480 <main+0x230>
lea    0xadc(%rip),%rdi
call   1100 <perror@plt>
jmp    1480 <main+0x230>
lea    0xad4(%rip),%rdi
call   1100 <perror@plt>
jmp    156c <main+0x31c>
lea    0xa79(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [5 x i8] c"3199\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [15 x i8] c"server: socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@.str.4 = [13 x i8] c"server: bind\00"
@.str.5 = [26 x i8] c"server: failed to bind()\0A\00"
@.str.6 = [9 x i8] c"listen: \00"
@.str.7 = [9 x i8] c"select: \00"
@.str.8 = [9 x i8] c"accept: \00"
@.str.9 = [16 x i8] c"clients gone!!\0A\00"
@.str.10 = [5 x i8] c"recv\00"
@.str.11 = [5 x i8] c"send\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_storage
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [256 x i8]
store i32 0, i32* %1
%18 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 40)
%19 = load i32, i32* @AI_PASSIVE
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 6
store i32 %19, i32* %20
%21 = load i32, i32* @AF_UNSPEC
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 4
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 3
store i32 %23, i32* %24
store i32 4, i32* %10
%25 = call i32 @FD_ZERO(i32* %11)
%26 = call i32 @FD_ZERO(i32* %12)
%27 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %4)
store i32 %27, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %0
%30 = load i32, i32* @stderr
%31 = load i32, i32* %7
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %0
%36 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %36, %struct.addrinfo** %3
br label %37
37: ; preds = %78, %35
%38 = load %struct.addrinfo*, %struct.addrinfo** %3
%39 = icmp ne %struct.addrinfo* %38, null
br i1 %39, label %40, label %82
40: ; preds = %37
%41 = load %struct.addrinfo*, %struct.addrinfo** %3
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 4
%43 = load i32, i32* %42
%44 = load %struct.addrinfo*, %struct.addrinfo** %3
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 3
%46 = load i32, i32* %45
%47 = load %struct.addrinfo*, %struct.addrinfo** %3
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 2
%49 = load i32, i32* %48
%50 = call i32 @socket(i32 %43, i32 %46, i32 %49)
store i32 %50, i32* %5
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %40
%53 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %78
54: ; preds = %40
%55 = load i32, i32* %5
%56 = load i32, i32* @SOL_SOCKET
%57 = load i32, i32* @SO_REUSEADDR
%58 = call i32 @setsockopt(i32 %55, i32 %56, i32 %57, i32* %8, i32 4)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%62 = call i32 @exit(i32 2)
unreachable
63: ; preds = %54
%64 = load i32, i32* %5
%65 = load %struct.addrinfo*, %struct.addrinfo** %3
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 1
%67 = load i32, i32* %66
%68 = load %struct.addrinfo*, %struct.addrinfo** %3
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @bind(i32 %64, i32 %67, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %77
73: ; preds = %63
%74 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* %5
%76 = call i32 @close(i32 %75)
br label %78
77: ; preds = %63
br label %82
78: ; preds = %73, %52
%79 = load %struct.addrinfo*, %struct.addrinfo** %3
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 5
%81 = load %struct.addrinfo*, %struct.addrinfo** %80
store %struct.addrinfo* %81, %struct.addrinfo** %3
br label %37
82: ; preds = %77, %37
%83 = load %struct.addrinfo*, %struct.addrinfo** %3
%84 = icmp eq %struct.addrinfo* %83, null
br i1 %84, label %85, label %89
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%88 = call i32 @exit(i32 3)
unreachable
89: ; preds = %82
%90 = load %struct.addrinfo*, %struct.addrinfo** %4
%91 = call i32 @freeaddrinfo(%struct.addrinfo* %90)
%92 = load i32, i32* %5
%93 = call i32 @listen(i32 %92, i32 5)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %98
95: ; preds = %89
%96 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%97 = call i32 @exit(i32 4)
unreachable
98: ; preds = %89
%99 = load i32, i32* %5
%100 = call i32 @FD_SET(i32 %99, i32* %11)
%101 = load i32, i32* %5
store i32 %101, i32* %13
br label %102
102: ; preds = %98, %198
%103 = load i32, i32* %11
store i32 %103, i32* %12
%104 = load i32, i32* %13
%105 = add nsw i32 %104, 1
%106 = call i32 @select(i32 %105, i32* %12, i32* null, i32* null, i32* null)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %111
108: ; preds = %102
%109 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%110 = call i32 @exit(i32 5)
unreachable
111: ; preds = %102
store i32 0, i32* %14
br label %112
112: ; preds = %195, %111
%113 = load i32, i32* %14
%114 = load i32, i32* %13
%115 = icmp sle i32 %113, %114
br i1 %115, label %116, label %198
116: ; preds = %112
%117 = load i32, i32* %14
%118 = call i64 @FD_ISSET(i32 %117, i32* %12)
%119 = icmp ne i64 %118, 0
br i1 %119, label %120, label %194
120: ; preds = %116
%121 = load i32, i32* %14
%122 = load i32, i32* %5
%123 = icmp eq i32 %121, %122
br i1 %123, label %124, label %142
124: ; preds = %120
%125 = load i32, i32* %5
%126 = bitcast %struct.sockaddr_storage* %9 to %struct.sockaddr*
%127 = call i32 @accept(i32 %125, %struct.sockaddr* %126, i32* %10)
store i32 %127, i32* %6
%128 = load i32, i32* %6
%129 = icmp eq i32 %128, -1
br i1 %129, label %130, label %132
130: ; preds = %124
%131 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %141
132: ; preds = %124
%133 = load i32, i32* %6
%134 = call i32 @FD_SET(i32 %133, i32* %11)
%135 = load i32, i32* %6
%136 = load i32, i32* %13
%137 = icmp sgt i32 %135, %136
br i1 %137, label %138, label %140
138: ; preds = %132
%139 = load i32, i32* %6
store i32 %139, i32* %13
br label %140
140: ; preds = %138, %132
br label %141
141: ; preds = %140, %130
br label %193
142: ; preds = %120
%143 = load i32, i32* %14
%144 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%145 = call i32 @recv(i32 %143, i8* %144, i32 256, i32 0)
store i32 %145, i32* %16
%146 = icmp sle i32 %145, 0
br i1 %146, label %147, label %159
147: ; preds = %142
%148 = load i32, i32* %16
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %152
150: ; preds = %147
%151 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %154
152: ; preds = %147
%153 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %154
154: ; preds = %152, %150
%155 = load i32, i32* %14
%156 = call i32 @close(i32 %155)
%157 = load i32, i32* %14
%158 = call i32 @FD_CLR(i32 %157, i32* %11)
br label %192
159: ; preds = %142
store i32 0, i32* %15
br label %160
160: ; preds = %188, %159
%161 = load i32, i32* %15
%162 = load i32, i32* %13
%163 = icmp sle i32 %161, %162
br i1 %163, label %164, label %191
164: ; preds = %160
%165 = load i32, i32* %15
%166 = call i64 @FD_ISSET(i32 %165, i32* %11)
%167 = icmp ne i64 %166, 0
br i1 %167, label %168, label %187
168: ; preds = %164
%169 = load i32, i32* %15
%170 = load i32, i32* %14
%171 = icmp eq i32 %169, %170
br i1 %171, label %176, label %172
172: ; preds = %168
%173 = load i32, i32* %15
%174 = load i32, i32* %5
%175 = icmp eq i32 %173, %174
br i1 %175, label %176, label %177
176: ; preds = %172, %168
br label %188
177: ; preds = %172
%178 = load i32, i32* %15
%179 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%180 = load i32, i32* %16
%181 = call i32 @send(i32 %178, i8* %179, i32 %180, i32 0)
%182 = icmp eq i32 %181, -1
br i1 %182, label %183, label %185
183: ; preds = %177
%184 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %185
185: ; preds = %183, %177
br label %186
186: ; preds = %185
br label %187
187: ; preds = %186, %164
br label %188
188: ; preds = %187, %176
%189 = load i32, i32* %15
%190 = add nsw i32 %189, 1
store i32 %190, i32* %15
br label %160
191: ; preds = %160
br label %192
192: ; preds = %191, %154
br label %193
193: ; preds = %192, %141
br label %194
194: ; preds = %193, %116
br label %195
195: ; preds = %194
%196 = load i32, i32* %14
%197 = add nsw i32 %196, 1
store i32 %197, i32* %14
br label %112
198: ; preds = %112
br label %102
}

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