#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__ {
  void *s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ TCP_NODELAY;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
void *htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memmove(int *, int *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stampa(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int srv_fd, cfd;
  int fd_list[50];
  int fd_count;
  struct sockaddr_in servaddr;
  srv_fd = socket(AF_INET, SOCK_STREAM, 0);
  int yep = 1;
  setsockopt(srv_fd, SOL_SOCKET, SO_REUSEADDR, &yep, sizeof(int));
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htons(INADDR_ANY);
  servaddr.sin_port = htons(11124);
  bind(srv_fd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(srv_fd, 10);
  fd_count = 0;
  while (1) {
    fd_set read_fds;
    int nfds;
    FD_ZERO(&read_fds);
    FD_SET(srv_fd, &read_fds);
    nfds = srv_fd + 1;
    for (int i = 0; i < fd_count; ++i) {
      FD_SET(fd_list[i], &read_fds);
      nfds = ((fd_list[i] + 1) > (nfds) ? (fd_list[i] + 1) : (nfds));
    }
    printf("WAIT ON SELECT %d\n", nfds);
    if (select(nfds, &read_fds, NULL, NULL, NULL) < 0) {
      perror("select()");
      continue;
    }
    if (FD_ISSET(srv_fd, &read_fds)) {
      int cfd = accept(srv_fd, (struct sockaddr *)NULL, NULL);
      setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, &yep, sizeof(int));
      printf("Accettato il client %d\n", cfd);
      fd_list[fd_count++] = cfd;
    } else {
      char buffer[128];
      ssize_t rd;
      printf("SCAN FOR READ max_fd=%d\n", nfds);
      for (int i = 0; i < fd_count; ++i) {
        int cfd = fd_list[i];
        if (!FD_ISSET(cfd, &read_fds))
          continue;
        rd = read(cfd, buffer, sizeof(buffer));
        if (rd <= 0) {
          memmove(fd_list + i, fd_list + i + 1, (fd_count - i) * sizeof(int));
          fd_count--;
          continue;
        }
        printf(" - letto dal client %d: ", cfd);
        stampa(buffer, rd);
        for (int j = 0; j < fd_count; ++j) {
          write(fd_list[j], buffer, rd);
        }
      }
    }
  }
  close(srv_fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x104(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    0x2d4e(%rip),%rax
mov    (%rax),%edx
lea    -0x104(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x100(%rbp),%rdi
mov    $0x18,%esi
call   1100 <bzero@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,-0xf8(%rbp)
mov    $0x2b74,%edi
call   1060 <htons@plt>
mov    %rax,-0x100(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x18,%edx
call   10d0 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
movl   $0x0,-0xe4(%rbp)
lea    -0x108(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x108(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
movl   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%eax
cmp    -0xe4(%rbp),%eax
jge    13a9 <main+0x199>
movslq -0x110(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%edi
lea    -0x108(%rbp),%rsi
call   1120 <FD_SET@plt>
movslq -0x110(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%eax
add    $0x1,%eax
cmp    -0x10c(%rbp),%eax
jle    137d <main+0x16d>
movslq -0x110(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1389 <main+0x179>
mov    -0x10c(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
mov    %eax,-0x10c(%rbp)
mov    -0x110(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x110(%rbp)
jmp    1318 <main+0x108>
mov    -0x10c(%rbp),%esi
lea    0xc4a(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10c(%rbp),%edi
lea    -0x108(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10b0 <select@plt>
cmp    $0x0,%rax
jge    13f3 <main+0x1e3>
lea    0xc2a(%rip),%rdi
call   10f0 <perror@plt>
jmp    12e7 <main+0xd7>
mov    -0x14(%rbp),%edi
lea    -0x108(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1482 <main+0x272>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1110 <accept@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%edi
mov    0x2b9a(%rip),%rax
mov    (%rax),%esi
mov    0x2ba9(%rip),%rax
mov    (%rax),%edx
lea    -0x104(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x114(%rbp),%esi
lea    0xbc4(%rip),%rdi
call   1070 <printf@plt>
mov    -0x114(%rbp),%ecx
mov    -0xe4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xe4(%rbp)
cltq
mov    %ecx,-0xe0(%rbp,%rax,4)
jmp    15fc <main+0x3ec>
mov    -0x10c(%rbp),%esi
lea    0xba5(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0xe4(%rbp),%eax
jge    15f7 <main+0x3e7>
movslq -0x1a8(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%edi
lea    -0x108(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
jne    14e5 <main+0x2d5>
jmp    15e3 <main+0x3d3>
mov    -0x1ac(%rbp),%edi
lea    -0x1a0(%rbp),%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    %eax,-0x1a4(%rbp)
cmpl   $0x0,-0x1a4(%rbp)
jg     156a <main+0x35a>
lea    -0xe0(%rbp),%rdi
movslq -0x1a8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0xe0(%rbp),%rsi
movslq -0x1a8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
add    $0x4,%rsi
mov    -0xe4(%rbp),%eax
sub    -0x1a8(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
call   10e0 <memmove@plt>
mov    -0xe4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xe4(%rbp)
jmp    15e3 <main+0x3d3>
mov    -0x1ac(%rbp),%esi
lea    0xad6(%rip),%rdi
call   1070 <printf@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
call   1080 <stampa@plt>
movl   $0x0,-0x1b0(%rbp)
mov    -0x1b0(%rbp),%eax
cmp    -0xe4(%rbp),%eax
jge    15de <main+0x3ce>
movslq -0x1b0(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%edi
lea    -0x1a0(%rbp),%rsi
mov    -0x1a4(%rbp),%edx
call   1040 <write@plt>
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    1598 <main+0x388>
jmp    15e3 <main+0x3d3>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    149e <main+0x28e>
jmp    15fc <main+0x3ec>
jmp    12e7 <main+0xd7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x188,%rsp
mov    0x2db0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r13d
movl   $0x1,0xc(%rsp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r13d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   1100 <bzero@plt>
mov    0x0(%rbp),%eax
xor    %ebp,%ebp
mov    %eax,0x28(%rsp)
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %rax,0x20(%rsp)
mov    $0x2b74,%edi
call   1060 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   10d0 <bind@plt>
mov    %r13d,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
mov    %r13d,%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
lea    0x8(%rsp),%rbx
lea    0x100(%rsp),%r12
mov    %r13d,(%rsp)
jmp    1344 <main+0x134>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1110 <accept@plt>
mov    %eax,%ebx
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
mov    0x2cd2(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0xcf3(%rip),%rdi
mov    %ebx,%esi
call   1070 <printf@plt>
mov    0x10(%rsp),%rbp
movslq %ebp,%rax
add    $0x1,%ebp
mov    %ebx,0x30(%rsp,%rax,4)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1120 <FD_SET@plt>
mov    0x4(%rsp),%r14d
mov    %rbp,0x10(%rsp)
test   %ebp,%ebp
mov    %rbx,%r15
jle    13a7 <main+0x197>
mov    0x10(%rsp),%ebx
xor    %ebp,%ebp
mov    0x4(%rsp),%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x30(%rsp,%rbp,4),%edi
mov    %r15,%rsi
call   1120 <FD_SET@plt>
mov    0x30(%rsp,%rbp,4),%eax
lea    0x1(%rax),%r14d
cmp    %r13d,%eax
cmovl  %r13d,%r14d
add    $0x1,%rbp
mov    %r14d,%r13d
cmp    %rbp,%rbx
jne    1380 <main+0x170>
lea    0xc52(%rip),%rdi
mov    %r14d,%esi
call   1070 <printf@plt>
mov    %r14d,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
test   %rax,%rax
mov    %r15,%rbx
js     14c9 <main+0x2b9>
mov    (%rsp),%r13d
mov    %r13d,%edi
mov    %rbx,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
jne    12f0 <main+0xe0>
lea    0xc41(%rip),%rdi
mov    %r14d,%esi
call   1070 <printf@plt>
mov    0x10(%rsp),%rbp
test   %ebp,%ebp
jle    14c0 <main+0x2b0>
xor    %r13d,%r13d
jmp    1439 <main+0x229>
nopl   (%rax)
lea    (%rsp,%r13,4),%rdi
add    $0x30,%rdi
lea    0x4(%rdi),%rsi
mov    %ebp,%edx
sub    %r13d,%edx
shl    $0x2,%edx
call   10e0 <memmove@plt>
add    $0xffffffff,%ebp
add    $0x1,%r13
cmp    %r13d,%ebp
jle    14c0 <main+0x2b0>
mov    0x30(%rsp,%r13,4),%r14d
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     142c <main+0x21c>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x80,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1410 <main+0x200>
mov    %eax,%r15d
lea    0xbe1(%rip),%rdi
mov    %r14d,%esi
call   1070 <printf@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1080 <stampa@plt>
test   %ebp,%ebp
jle    142c <main+0x21c>
mov    %rbp,%r14
mov    %ebp,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x30(%rsp,%rbp,4),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <write@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1490 <main+0x280>
mov    %r14,%rbp
lea    0x8(%rsp),%rbx
jmp    142c <main+0x21c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%r13d
jmp    1344 <main+0x134>
lea    0xb43(%rip),%rdi
call   10f0 <perror@plt>
mov    0x10(%rsp),%rbp
mov    (%rsp),%r13d
jmp    1344 <main+0x134>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str = [19 x i8] c"WAIT ON SELECT %d\0A\00"
@.str.1 = [9 x i8] c"select()\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.2 = [24 x i8] c"Accettato il client %d\0A\00"
@.str.3 = [25 x i8] c"SCAN FOR READ max_fd=%d\0A\00"
@.str.4 = [25 x i8] c" - letto dal client %d: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i32]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = bitcast [50 x i32]* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_REUSEADDR
%16 = call i32 @setsockopt(i32 %12, i32 %14, i32 %15, i32* %5, i32 4)
%17 = call i32 @bzero(%struct.sockaddr_in* %4, i32 24)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = call i8* @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i8* %21, i8** %22
%23 = call i8* @htons(i32 11124)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %23, i8** %24
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i32 @bind(i32 %12, %struct.sockaddr* %25, i32 24)
%27 = call i32 @listen(i32 %12, i32 10)
%28 = bitcast i32* %6 to i8*
%29 = add nsw i32 %12, 1
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
br label %31
31: ; preds = %108, %2
%32 = phi i32 [ 0, %2 ], [ %109, %108 ]
%33 = call i32 @FD_ZERO(i32* %6)
%34 = call i32 @FD_SET(i32 %12, i32* %6)
%35 = icmp sgt i32 %32, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = zext i32 %32 to i64
br label %43
38: ; preds = %43, %31
%39 = phi i32 [ %29, %31 ], [ %52, %43 ]
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = call i64 @select(i32 %39, i32* %6, i32* null, i32* null, i32* null)
%42 = icmp slt i64 %41, 0
br i1 %42, label %55, label %57
43: ; preds = %36, %43
%44 = phi i64 [ 0, %36 ], [ %53, %43 ]
%45 = phi i32 [ %29, %36 ], [ %52, %43 ]
%46 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %44
%47 = load i32, i32* %46
%48 = call i32 @FD_SET(i32 %47, i32* %6)
%49 = load i32, i32* %46
%50 = icmp slt i32 %49, %45
%51 = add nsw i32 %49, 1
%52 = select i1 %50, i32 %45, i32 %51
%53 = add nuw nsw i64 %44, 1
%54 = icmp eq i64 %53, %37
br i1 %54, label %38, label %43
55: ; preds = %38
%56 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %108
57: ; preds = %38
%58 = call i64 @FD_ISSET(i32 %12, i32* %6)
%59 = icmp eq i64 %58, 0
br i1 %59, label %69, label %60
60: ; preds = %57
%61 = call i32 @accept(i32 %12, %struct.sockaddr* null, i32* null)
%62 = load i32, i32* @IPPROTO_TCP
%63 = load i32, i32* @TCP_NODELAY
%64 = call i32 @setsockopt(i32 %61, i32 %62, i32 %63, i32* %5, i32 4)
%65 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%66 = add nsw i32 %32, 1
%67 = sext i32 %32 to i64
%68 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %67
store i32 %61, i32* %68
br label %108
69: ; preds = %57
%70 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br i1 %35, label %73, label %71
71: ; preds = %103, %69
%72 = phi i32 [ %32, %69 ], [ %104, %103 ]
br label %108
73: ; preds = %69, %103
%74 = phi i64 [ %105, %103 ], [ 0, %69 ]
%75 = phi i32 [ %104, %103 ], [ %32, %69 ]
%76 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %74
%77 = load i32, i32* %76
%78 = call i64 @FD_ISSET(i32 %77, i32* %6)
%79 = icmp eq i64 %78, 0
br i1 %79, label %103, label %80
80: ; preds = %73
%81 = call i32 @read(i32 %77, i8* %30, i32 128)
%82 = icmp slt i32 %81, 1
br i1 %82, label %83, label %90
83: ; preds = %80
%84 = getelementptr inbounds i32, i32* %76, i64 1
%85 = trunc i64 %74 to i32
%86 = sub nsw i32 %75, %85
%87 = shl i32 %86, 2
%88 = call i32 @memmove(i32* %76, i32* %84, i32 %87)
%89 = add nsw i32 %75, -1
br label %103
90: ; preds = %80
%91 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %77)
%92 = call i32 @stampa(i8* %30, i32 %81)
%93 = icmp sgt i32 %75, 0
br i1 %93, label %94, label %103
94: ; preds = %90
%95 = zext i32 %75 to i64
br label %96
96: ; preds = %94, %96
%97 = phi i64 [ 0, %94 ], [ %101, %96 ]
%98 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %97
%99 = load i32, i32* %98
%100 = call i32 @write(i32 %99, i8* %30, i32 %81)
%101 = add nuw nsw i64 %97, 1
%102 = icmp eq i64 %101, %95
br i1 %102, label %103, label %96
103: ; preds = %96, %90, %73, %83
%104 = phi i32 [ %89, %83 ], [ %75, %73 ], [ %75, %90 ], [ %75, %96 ]
%105 = add nuw i64 %74, 1
%106 = trunc i64 %105 to i32
%107 = icmp sgt i32 %104, %106
br i1 %107, label %73, label %71
108: ; preds = %60, %71, %55
%109 = phi i32 [ %32, %55 ], [ %66, %60 ], [ %72, %71 ]
br label %31
}