#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ str;
typedef int ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int Accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ Bind(int, struct sockaddr *, int);
int /*<<< orphan*/ Close(int);
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ Listen(int, int);
int Read(int, char *, int);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ Write(int, char *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perr_exit(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char toupper(char);
int main(int argc, char **argv) {
  int i, maxi, maxfd, listenfd, connfd, sockfd;
  int nready, client[FD_SETSIZE];
  ssize_t n;
  fd_set rset, allset;
  char buf[80];
  char str[INET_ADDRSTRLEN];
  socklen_t cliaddr_len;
  struct sockaddr_in cliaddr, servaddr;
  listenfd = Socket(AF_INET, SOCK_STREAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(8000);
  Bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  Listen(listenfd, 20);
  maxfd = listenfd;
  maxi = -1;
  for (i = 0; i < FD_SETSIZE; i++)
    client[i] = -1;
  FD_ZERO(&allset);
  FD_SET(listenfd, &allset);
  for (;;) {
    rset = allset;
    nready = select(maxfd + 1, &rset, NULL, NULL, NULL);
    if (nready < 0)
      perr_exit("select error");
    if (FD_ISSET(listenfd, &rset)) {
      cliaddr_len = sizeof(cliaddr);
      connfd = Accept(listenfd, (struct sockaddr *)&cliaddr, &cliaddr_len);
      printf("received from %s at PORT %d\n",
             inet_ntop(AF_INET, &cliaddr.sin_addr, str, sizeof(str)),
             ntohs(cliaddr.sin_port));
      for (i = 0; i < FD_SETSIZE; i++)
        if (client[i] < 0) {
          client[i] = connfd;
          break;
        }
      if (i == FD_SETSIZE) {
        fputs("too many clients\n", stderr);
        exit(1);
      }
      FD_SET(connfd, &allset);
      if (connfd > maxfd)
        maxfd = connfd;
      if (i > maxi)
        maxi = i;
      if (--nready == 0)
        continue;
    }
    for (i = 0; i <= maxi; i++) {
      if ((sockfd = client[i]) < 0)
        continue;
      if (FD_ISSET(sockfd, &rset)) {
        if ((n = Read(sockfd, buf, 80)) == 0) {
          Close(sockfd);
          FD_CLR(sockfd, &allset);
          client[i] = -1;
        } else {
          int j;
          for (j = 0; j < n; j++)
            buf[j] = toupper(buf[j]);
          Write(sockfd, buf, n);
        }
        if (--nready == 0)
          break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xe8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xe0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xa8(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <Socket@plt>
mov    %eax,-0x20(%rbp)
lea    -0xc8(%rbp),%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc0(%rbp)
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,-0xc4(%rbp)
mov    $0x1f40,%edi
call   1080 <htons@plt>
mov    %eax,-0xc8(%rbp)
mov    -0x20(%rbp),%edi
lea    -0xc8(%rbp),%rsi
mov    $0xc,%edx
call   1110 <Bind@plt>
mov    -0x20(%rbp),%edi
mov    $0x14,%esi
call   10f0 <Listen@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2c46(%rip),%rcx
cmp    (%rcx),%eax
jge    13a2 <main+0x142>
mov    -0xe8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1370 <main+0x110>
lea    -0x4c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0x20(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
lea    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10e0 <select@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    13f0 <main+0x190>
lea    0xc15(%rip),%rdi
call   1180 <perr_exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     154f <main+0x2ef>
movl   $0xc,-0xac(%rbp)
mov    -0x20(%rbp),%edi
lea    -0xb8(%rbp),%rsi
lea    -0xac(%rbp),%rdx
call   1070 <Accept@plt>
mov    -0xd8(%rbp),%rdx
mov    %eax,%ecx
mov    -0xe0(%rbp),%rax
mov    %ecx,-0x24(%rbp)
mov    0x2ba8(%rip),%rcx
mov    (%rcx),%edi
lea    -0xb8(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0xf0(%rbp)
mov    -0xb8(%rbp),%edi
call   1100 <ntohs@plt>
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
lea    0xb97(%rip),%rdi
call   1090 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2b34(%rip),%rcx
cmp    (%rcx),%eax
jge    14d2 <main+0x272>
mov    -0xe8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    14bf <main+0x25f>
mov    -0xe8(%rbp),%rax
mov    -0x24(%rbp),%edx
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    14d2 <main+0x272>
jmp    14c4 <main+0x264>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1482 <main+0x222>
mov    -0x14(%rbp),%eax
mov    0x2ae4(%rip),%rcx
cmp    (%rcx),%eax
jne    1503 <main+0x2a3>
mov    0x2ae5(%rip),%rax
mov    (%rax),%esi
lea    0xb36(%rip),%rdi
call   10a0 <fputs@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1521 <main+0x2c1>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1533 <main+0x2d3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    154a <main+0x2ea>
jmp    13b7 <main+0x157>
jmp    154f <main+0x2ef>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1674 <main+0x414>
mov    -0xe8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1581 <main+0x321>
jmp    1666 <main+0x406>
mov    -0x28(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1661 <main+0x401>
mov    -0x28(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x50,%edx
call   1050 <Read@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jne    15e2 <main+0x382>
mov    -0x28(%rbp),%edi
call   1120 <Close@plt>
mov    -0x28(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1150 <FD_CLR@plt>
mov    -0xe8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    1645 <main+0x3e5>
movl   $0x0,-0xcc(%rbp)
mov    -0xcc(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1633 <main+0x3d3>
movslq -0xcc(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%edi
ff
call   1040 <toupper@plt>
mov    %al,%cl
movslq -0xcc(%rbp),%rax
mov    %cl,-0xa0(%rbp,%rax,1)
mov    -0xcc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xcc(%rbp)
jmp    15ec <main+0x38c>
mov    -0x28(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   10c0 <Write@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    165c <main+0x3fc>
jmp    1674 <main+0x414>
jmp    1661 <main+0x401>
jmp    1666 <main+0x406>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1556 <main+0x2f6>
jmp    13b7 <main+0x157>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    0x2d35(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x68(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    0x2d1c(%rip),%r12
mov    (%r12),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <Socket@plt>
mov    %eax,%ebx
lea    -0x58(%rbp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1140 <bzero@plt>
mov    (%r12),%eax
mov    %eax,-0x50(%rbp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,-0x54(%rbp)
mov    $0x1f40,%edi
call   1080 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1120 <Bind@plt>
mov    %ebx,%r15d
mov    %ebx,%edi
mov    $0x14,%esi
call   1100 <Listen@plt>
mov    (%r14),%edx
test   %edx,%edx
jle    134e <main+0xde>
shl    $0x2,%rdx
mov    %r13,%rdi
mov    $0xff,%esi
call   10c0 <memset@plt>
lea    -0x30(%rbp),%rbx
mov    %rbx,%rdi
call   10e0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r15d,%ebx
call   1180 <FD_SET@plt>
mov    $0xffffffff,%eax
mov    %rax,-0x40(%rbp)
lea    -0x38(%rbp),%r14
mov    %r15d,%eax
mov    %rax,-0x48(%rbp)
mov    %r13,-0x70(%rbp)
mov    %r15d,-0x2c(%rbp)
jmp    1393 <main+0x123>
cs nopw 0x0(%rax,%rax,1)
mov    -0x2c(%rbp),%ebx
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
lea    0x1(%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10f0 <select@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    13c2 <main+0x152>
lea    0xc43(%rip),%rdi
call   1190 <perr_exit@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     14a5 <main+0x235>
mov    %r12d,%r15d
movl   $0xc,-0x4c(%rbp)
mov    %ebx,%edi
lea    -0x88(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1070 <Accept@plt>
mov    %eax,%r12d
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
lea    -0x84(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    %rax,%rbx
mov    -0x88(%rbp),%edi
call   1110 <ntohs@plt>
lea    0xbe7(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1090 <printf@plt>
mov    0x2b89(%rip),%rax
mov    (%rax),%eax
xor    %ebx,%ebx
test   %eax,%eax
jle    1465 <main+0x1f5>
nop
cmpl   $0x0,0x0(%r13,%rbx,4)
js     1460 <main+0x1f0>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1440 <main+0x1d0>
jmp    1585 <main+0x315>
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,0x0(%r13,%rbx,4)
cmp    %eax,%ebx
je     1585 <main+0x315>
mov    %r12d,%edi
lea    -0x30(%rbp),%rsi
call   1180 <FD_SET@plt>
mov    -0x48(%rbp),%rax
cmp    %eax,%r12d
cmovg  %r12d,%eax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
cmp    %eax,%ebx
cmovg  %ebx,%eax
mov    %rax,-0x40(%rbp)
mov    %r15d,%r12d
add    $0xffffffff,%r12d
mov    -0x2c(%rbp),%ebx
je     1393 <main+0x123>
cmpl   $0x0,-0x40(%rbp)
js     1393 <main+0x123>
mov    -0x40(%rbp),%rax
add    $0x1,%eax
mov    %rax,-0x78(%rbp)
xor    %r15d,%r15d
jmp    14f6 <main+0x286>
mov    %ebx,%edi
call   1130 <Close@plt>
mov    %ebx,%edi
lea    -0x30(%rbp),%rsi
call   1160 <FD_CLR@plt>
movl   $0xffffffff,0x0(%r13,%r15,4)
ff ff
mov    -0x34(%rbp),%r12d
add    $0xffffffff,%r12d
je     157d <main+0x30d>
add    $0x1,%r15
cmp    -0x78(%rbp),%r15
je     1390 <main+0x120>
mov    0x0(%r13,%r15,4),%ebx
test   %ebx,%ebx
js     14e8 <main+0x278>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     14e8 <main+0x278>
mov    %r12d,-0x34(%rbp)
mov    %ebx,%edi
lea    -0xe0(%rbp),%rsi
mov    $0x50,%edx
call   1050 <Read@plt>
test   %eax,%eax
je     14bf <main+0x24f>
mov    %eax,%r12d
jle    155f <main+0x2ef>
mov    %r12d,%r14d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl -0xe0(%rbp,%r13,1),%edi
ff ff
call   1040 <toupper@plt>
mov    %al,-0xe0(%rbp,%r13,1)
ff
add    $0x1,%r13
cmp    %r13,%r14
jne    1540 <main+0x2d0>
mov    %ebx,%edi
lea    -0xe0(%rbp),%rsi
mov    %r12d,%edx
call   10d0 <Write@plt>
mov    -0x70(%rbp),%r13
lea    -0x38(%rbp),%r14
jmp    14da <main+0x26a>
mov    -0x2c(%rbp),%ebx
jmp    1393 <main+0x123>
mov    0x2a44(%rip),%rax
mov    (%rax),%esi
lea    0xa95(%rip),%rdi
call   10a0 <fputs@plt>
mov    $0x1,%edi
call   1170 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@FD_SETSIZE = global i32 0
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [13 x i8] c"select error\00"
@.str.1 = [29 x i8] c"received from %s at PORT %d\0A\00"
@.str.2 = [18 x i8] c"too many clients\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = load i32, i32* @FD_SETSIZE
%10 = zext i32 %9 to i64
%11 = alloca i32, i64 %10
%12 = bitcast i32* %3 to i8*
%13 = bitcast i32* %4 to i8*
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* @INET_ADDRSTRLEN
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
%18 = bitcast i32* %6 to i8*
%19 = bitcast %struct.sockaddr_in* %7 to i8*
%20 = bitcast %struct.sockaddr_in* %8 to i8*
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @Socket(i32 %21, i32 %22, i32 0)
%24 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = tail call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1, i32 0
store i32 %28, i32* %29
%30 = tail call i32 @htons(i32 8000)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%33 = call i32 @Bind(i32 %23, %struct.sockaddr* %32, i32 12)
%34 = call i32 @Listen(i32 %23, i32 20)
%35 = load i32, i32* @FD_SETSIZE
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %2
%38 = bitcast i32* %11 to i8*
%39 = zext i32 %35 to i64
%40 = shl nuw nsw i64 %39, 2
br label %41
41: ; preds = %37, %2
%42 = call i32 @FD_ZERO(i32* %4)
%43 = call i32 @FD_SET(i32 %23, i32* %4)
%44 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
br label %47
47: ; preds = %102, %41
%48 = phi i32 [ %23, %41 ], [ %103, %102 ]
%49 = phi i32 [ -1, %41 ], [ %104, %102 ]
%50 = load i32, i32* %4
store i32 %50, i32* %3
%51 = add nsw i32 %48, 1
%52 = call i32 @select(i32 %51, i32* %3, i32* null, i32* null, i32* null)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 @perr_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %56
56: ; preds = %54, %47
%57 = call i64 @FD_ISSET(i32 %23, i32* %3)
%58 = icmp eq i64 %57, 0
br i1 %58, label %97, label %59
59: ; preds = %56
store i32 12, i32* %6
%60 = call i32 @Accept(i32 %23, %struct.sockaddr* %44, i32* %6)
%61 = load i32, i32* @AF_INET
%62 = call i8* @inet_ntop(i32 %61, %struct.TYPE_2__* %45, i8* %17, i32 %15)
%63 = load i32, i32* %46
%64 = call i32 @ntohs(i32 %63)
%65 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %62, i32 %64)
%66 = load i32, i32* @FD_SETSIZE
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %82
68: ; preds = %59
%69 = zext i32 %66 to i64
br label %70
70: ; preds = %68, %79
%71 = phi i64 [ 0, %68 ], [ %80, %79 ]
%72 = getelementptr inbounds i32, i32* %11, i64 %71
%73 = load i32, i32* %72
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = trunc i64 %71 to i32
%77 = and i64 %71, 4294967295
%78 = getelementptr inbounds i32, i32* %11, i64 %77
store i32 %60, i32* %78
br label %82
79: ; preds = %70
%80 = add nuw nsw i64 %71, 1
%81 = icmp eq i64 %80, %69
br i1 %81, label %85, label %70
82: ; preds = %59, %75
%83 = phi i32 [ %76, %75 ], [ 0, %59 ]
%84 = icmp eq i32 %83, %66
br i1 %84, label %85, label %89
85: ; preds = %82, %79
%86 = load i32, i32* @stderr
%87 = call i32 @fputs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %86)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %82
%90 = call i32 @FD_SET(i32 %60, i32* %4)
%91 = icmp sgt i32 %60, %48
%92 = select i1 %91, i32 %60, i32 %48
%93 = icmp sgt i32 %83, %49
%94 = select i1 %93, i32 %83, i32 %49
%95 = add nsw i32 %52, -1
%96 = icmp eq i32 %95, 0
br i1 %96, label %102, label %97
97: ; preds = %89, %56
%98 = phi i32 [ %95, %89 ], [ %52, %56 ]
%99 = phi i32 [ %92, %89 ], [ %48, %56 ]
%100 = phi i32 [ %94, %89 ], [ %49, %56 ]
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %139, %136, %97, %89
%103 = phi i32 [ %92, %89 ], [ %99, %97 ], [ %99, %136 ], [ %99, %139 ]
%104 = phi i32 [ %94, %89 ], [ %100, %97 ], [ %100, %136 ], [ %100, %139 ]
br label %47
105: ; preds = %97
%106 = add nuw i32 %100, 1
%107 = zext i32 %106 to i64
br label %108
108: ; preds = %105, %139
%109 = phi i64 [ 0, %105 ], [ %141, %139 ]
%110 = phi i32 [ %98, %105 ], [ %140, %139 ]
%111 = getelementptr inbounds i32, i32* %11, i64 %109
%112 = load i32, i32* %111
%113 = icmp slt i32 %112, 0
br i1 %113, label %139, label %114
114: ; preds = %108
%115 = call i64 @FD_ISSET(i32 %112, i32* %3)
%116 = icmp eq i64 %115, 0
br i1 %116, label %139, label %117
117: ; preds = %114
%118 = call i32 @Read(i32 %112, i8* %14, i32 80)
%119 = icmp eq i32 %118, 0
br i1 %119, label %124, label %120
120: ; preds = %117
%121 = icmp sgt i32 %118, 0
br i1 %121, label %122, label %134
122: ; preds = %120
%123 = zext i32 %118 to i64
br label %127
124: ; preds = %117
%125 = call i32 @Close(i32 %112)
%126 = call i32 @FD_CLR(i32 %112, i32* %4)
store i32 -1, i32* %111
br label %136
127: ; preds = %122, %127
%128 = phi i64 [ 0, %122 ], [ %132, %127 ]
%129 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %128
%130 = load i8, i8* %129
%131 = call signext i8 @toupper(i8 signext %130)
store i8 %131, i8* %129
%132 = add nuw nsw i64 %128, 1
%133 = icmp eq i64 %132, %123
br i1 %133, label %134, label %127
134: ; preds = %127, %120
%135 = call i32 @Write(i32 %112, i8* %14, i32 %118)
br label %136
136: ; preds = %134, %124
%137 = add nsw i32 %110, -1
%138 = icmp eq i32 %137, 0
br i1 %138, label %102, label %139
139: ; preds = %114, %136, %108
%140 = phi i32 [ %110, %108 ], [ %137, %136 ], [ %110, %114 ]
%141 = add nuw nsw i64 %109, 1
%142 = icmp eq i64 %141, %107
br i1 %142, label %102, label %108
}