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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
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 /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
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 socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  fd_set rfds;
  fd_set master;
  int sockfd, newsockfd, portno;
  int count = 0;
  socklen_t clilen;
  char buffer[256];
  struct sockaddr_in serv_addr, cli_addr;
  int ret, text;
  if (argc < 2) {
    fprintf(stderr, "ERROR, no port provided\n");
    exit(1);
  }
  sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sockfd < 0) {
    error("ERROR opening socket");
  }
  FD_ZERO(&master);
  FD_SET(sockfd, &master);
  FD_ZERO(&rfds);
  FD_SET(sockfd, &rfds);
  bzero((char *)&serv_addr, sizeof(serv_addr));
  portno = atoi(argv[1]);
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR on binding");
  listen(sockfd, 5);
  printf("listen\n");
  while (1) {
    if (count % 1000 == 0) {
      printf("======================= %d =======================\n", count);
    }
    rfds = master;
    ret = select(FD_SETSIZE, &rfds, NULL, NULL, NULL);
    printf("Events = %d\n", ret);
    if (FD_ISSET(sockfd, &rfds)) {
      clilen = sizeof(cli_addr);
      newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
      printf("Newsockfd = %d\n", newsockfd);
      if (newsockfd < 0) {
        error("ERROR on accept");
      }
      FD_SET(newsockfd, &master);
    }
    for (int i = 0; i < FD_SETSIZE && ret > 0; ++i) {
      if (FD_ISSET(i, &rfds) && (i != sockfd)) {
        ret--;
        if (ret < 0) {
          error("ERROR reading from socket");
        } else {
          bzero(buffer, 256);
          text = recv(i, buffer, 255, 0);
          printf("Here is the message: %s\n", buffer);
          text = send(i, "I got your message\n", 18, 0);
          if (text < 0) {
            error("ERROR writing to socket");
          }
          for (int x = 0; x < FD_SETSIZE; ++x) {
            if (x != i && FD_ISSET(x, &master) && (x != sockfd)) {
              printf("send to monitor\n");
              text = send(x, buffer, 18, 0);
              if (text < 0) {
                error("ERROR writing to socket");
              }
            }
          }
        }
      }
    }
    count++;
  }
  close(newsockfd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1259 <main+0x49>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    0x2d66(%rip),%rax
mov    (%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1292 <main+0x82>
lea    0xd8c(%rip),%rdi
call   10d0 <error@plt>
lea    -0x18(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1120 <FD_SET@plt>
lea    -0x14(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1120 <FD_SET@plt>
lea    -0x140(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x138(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x140(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1333 <main+0x123>
lea    0xd00(%rip),%rdi
call   10d0 <error@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1373 <main+0x163>
mov    -0x28(%rbp),%esi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10a0 <select@plt>
mov    %eax,-0x154(%rbp)
mov    -0x154(%rbp),%esi
lea    0xcd2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1416 <main+0x206>
movl   $0xc,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x150(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jge    140a <main+0x1fa>
lea    0xc93(%rip),%rdi
call   10d0 <error@plt>
mov    -0x20(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1120 <FD_SET@plt>
movl   $0x0,-0x15c(%rbp)
mov    -0x15c(%rbp),%ecx
xor    %eax,%eax
mov    0x2b89(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x161(%rbp)
jge    144d <main+0x23d>
cmpl   $0x0,-0x154(%rbp)
setg   %al
mov    %al,-0x161(%rbp)
mov    -0x161(%rbp),%al
test   $0x1,%al
jne    1460 <main+0x250>
jmp    1612 <main+0x402>
mov    -0x15c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15f9 <main+0x3e9>
mov    -0x15c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     15f9 <main+0x3e9>
mov    -0x154(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jge    14b5 <main+0x2a5>
lea    0xbfd(%rip),%rdi
call   10d0 <error@plt>
jmp    15f4 <main+0x3e4>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    -0x15c(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x158(%rbp)
lea    -0x130(%rbp),%rsi
lea    0xbcf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x15c(%rbp),%edi
lea    0xbd4(%rip),%rsi
mov    $0x12,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jge    1532 <main+0x322>
lea    0xbc2(%rip),%rdi
call   10d0 <error@plt>
movl   $0x0,-0x160(%rbp)
mov    -0x160(%rbp),%eax
mov    0x2a6f(%rip),%rcx
cmp    (%rcx),%eax
jge    15ef <main+0x3df>
mov    -0x160(%rbp),%eax
cmp    -0x15c(%rbp),%eax
je     15d6 <main+0x3c6>
mov    -0x160(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15d6 <main+0x3c6>
mov    -0x160(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     15d6 <main+0x3c6>
lea    0xb75(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x160(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x12,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jge    15d1 <main+0x3c1>
lea    0xb23(%rip),%rdi
call   10d0 <error@plt>
jmp    15d6 <main+0x3c6>
jmp    15db <main+0x3cb>
mov    -0x160(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x160(%rbp)
jmp    153c <main+0x32c>
jmp    15f4 <main+0x3e4>
jmp    15f9 <main+0x3e9>
jmp    15fe <main+0x3ee>
mov    -0x15c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15c(%rbp)
jmp    1420 <main+0x210>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    134e <main+0x13e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
cmp    $0x1,%edi
jle    153b <main+0x31b>
mov    %rsi,%r14
mov    0x2da4(%rip),%r15
mov    (%r15),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1270 <main+0x50>
lea    0xdae(%rip),%rdi
call   10e0 <error@plt>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   10a0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10a0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x8(%r14),%rdi
call   1110 <atoi@plt>
mov    (%r15),%ecx
mov    %ecx,0x18(%rsp)
mov    0x2d1b(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rsp)
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jns    12f6 <main+0xd6>
lea    0xd3d(%rip),%rdi
call   10e0 <error@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
mov    0x2ca3(%rip),%r13
mov    %rsp,%rbp
xor    %r14d,%r14d
jmp    132c <main+0x10c>
nopl   (%rax)
mov    %r14,%rbp
mov    0x8(%rsp),%r14d
add    $0x1,%r14d
imul   $0x26e978d5,%r14d,%eax
ror    $0x3,%eax
cmp    $0x418937,%eax
ja     134e <main+0x12e>
lea    0xcfb(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14d,0x8(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,(%rsp)
mov    0x0(%r13),%edi
mov    %rbp,%r14
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
mov    %eax,%r15d
lea    0xcf9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
lea    0x4(%rsp),%rbp
je     13e2 <main+0x1c2>
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1100 <accept@plt>
mov    %eax,%r14d
lea    0xcc6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %r14d,%r14d
jns    13d4 <main+0x1b4>
lea    0xcc1(%rip),%rdi
call   10e0 <error@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
mov    %rsp,%r14
cmpl   $0x0,0x0(%r13)
jle    1320 <main+0x100>
test   %r15d,%r15d
jle    1320 <main+0x100>
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r14,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1500 <main+0x2e0>
cmp    %ebx,%r12d
je     1500 <main+0x2e0>
mov    %r14,%rbp
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xc55(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,%edi
lea    0xc5a(%rip),%rsi
mov    $0x12,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jns    147b <main+0x25b>
lea    0xc57(%rip),%rdi
call   10e0 <error@plt>
add    $0xffffffff,%r15d
mov    0x0(%r13),%eax
test   %eax,%eax
jle    1515 <main+0x2f5>
xor    %r14d,%r14d
lea    0x4(%rsp),%rbp
jmp    14ad <main+0x28d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14d
mov    0x0(%r13),%eax
cmp    %eax,%r14d
jge    1510 <main+0x2f0>
cmp    %r14d,%r12d
je     14a0 <main+0x280>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     14a0 <main+0x280>
cmp    %r14d,%ebx
je     14a0 <main+0x280>
lea    0xc1e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
lea    0x30(%rsp),%rsi
mov    $0x12,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jns    14a0 <main+0x280>
lea    0xbdb(%rip),%rdi
call   10e0 <error@plt>
jmp    14a0 <main+0x280>
nopl   0x0(%rax)
mov    0x0(%r13),%eax
jmp    1520 <main+0x300>
cs nopw 0x0(%rax,%rax,1)
mov    %rsp,%r14
jmp    1520 <main+0x300>
mov    %rbp,%r14
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    %eax,%r12d
jge    1320 <main+0x100>
test   %r15d,%r15d
jg     1400 <main+0x1e0>
jmp    1320 <main+0x100>
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
lea    0xab5(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERROR, no port provided\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"ERROR on binding\00"
@.str.3 = [8 x i8] c"listen\0A\00"
@.str.4 = [52 x i8] c"======================= %d =======================\0A\00"
@FD_SETSIZE = global i32 0
@.str.5 = [13 x i8] c"Events = %d\0A\00"
@.str.6 = [16 x i8] c"Newsockfd = %d\0A\00"
@.str.7 = [16 x i8] c"ERROR on accept\00"
@.str.8 = [26 x i8] c"ERROR reading from socket\00"
@.str.9 = [25 x i8] c"Here is the message: %s\0A\00"
@.str.10 = [20 x i8] c"I got your message\0A\00"
@.str.11 = [24 x i8] c"ERROR writing to socket\00"
@.str.12 = [17 x i8] c"send to monitor\0A\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca %struct.sockaddr_in
%15 = alloca %struct.sockaddr_in
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = load i32, i32* @IPPROTO_TCP
%30 = call i32 @socket(i32 %27, i32 %28, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = call i32 @FD_ZERO(i32* %7)
%37 = load i32, i32* %8
%38 = call i32 @FD_SET(i32 %37, i32* %7)
%39 = call i32 @FD_ZERO(i32* %6)
%40 = load i32, i32* %8
%41 = call i32 @FD_SET(i32 %40, i32* %6)
%42 = bitcast %struct.sockaddr_in* %14 to i8*
%43 = call i32 @bzero(i8* %42, i32 12)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %10
%48 = load i32, i32* @AF_INET
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %48, i32* %49
%50 = load i32, i32* @INADDR_ANY
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
store i32 %50, i32* %52
%53 = load i32, i32* %10
%54 = call i32 @htons(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
store i32 %54, i32* %55
%56 = load i32, i32* %8
%57 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%58 = call i64 @bind(i32 %56, %struct.sockaddr* %57, i32 12)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %35
%61 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60, %35
%63 = load i32, i32* %8
%64 = call i32 @listen(i32 %63, i32 5)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %66
66: ; preds = %62, %171
%67 = load i32, i32* %11
%68 = srem i32 %67, 1000
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = load i32, i32* %11
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70, %66
%74 = load i32, i32* %7
store i32 %74, i32* %6
%75 = load i32, i32* @FD_SETSIZE
%76 = call i32 @select(i32 %75, i32* %6, i32* null, i32* null, i32* null)
store i32 %76, i32* %16
%77 = load i32, i32* %16
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %8
%80 = call i64 @FD_ISSET(i32 %79, i32* %6)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %95
82: ; preds = %73
store i32 12, i32* %12
%83 = load i32, i32* %8
%84 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%85 = call i32 @accept(i32 %83, %struct.sockaddr* %84, i32* %12)
store i32 %85, i32* %9
%86 = load i32, i32* %9
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %86)
%88 = load i32, i32* %9
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %82
%91 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %92
92: ; preds = %90, %82
%93 = load i32, i32* %9
%94 = call i32 @FD_SET(i32 %93, i32* %7)
br label %95
95: ; preds = %92, %73
store i32 0, i32* %18
br label %96
96: ; preds = %168, %95
%97 = load i32, i32* %18
%98 = load i32, i32* @FD_SETSIZE
%99 = icmp slt i32 %97, %98
br i1 %99, label %100, label %103
100: ; preds = %96
%101 = load i32, i32* %16
%102 = icmp sgt i32 %101, 0
br label %103
103: ; preds = %100, %96
%104 = phi i1 [ false, %96 ], [ %102, %100 ]
br i1 %104, label %105, label %171
105: ; preds = %103
%106 = load i32, i32* %18
%107 = call i64 @FD_ISSET(i32 %106, i32* %6)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %167
109: ; preds = %105
%110 = load i32, i32* %18
%111 = load i32, i32* %8
%112 = icmp ne i32 %110, %111
br i1 %112, label %113, label %167
113: ; preds = %109
%114 = load i32, i32* %16
%115 = add nsw i32 %114, -1
store i32 %115, i32* %16
%116 = load i32, i32* %16
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %113
%119 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %166
120: ; preds = %113
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%122 = call i32 @bzero(i8* %121, i32 256)
%123 = load i32, i32* %18
%124 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%125 = call i32 @recv(i32 %123, i8* %124, i32 255, i32 0)
store i32 %125, i32* %17
%126 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %126)
%128 = load i32, i32* %18
%129 = call i32 @send(i32 %128, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 18, i32 0)
store i32 %129, i32* %17
%130 = load i32, i32* %17
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %120
%133 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
br label %134
134: ; preds = %132, %120
store i32 0, i32* %19
br label %135
135: ; preds = %162, %134
%136 = load i32, i32* %19
%137 = load i32, i32* @FD_SETSIZE
%138 = icmp slt i32 %136, %137
br i1 %138, label %139, label %165
139: ; preds = %135
%140 = load i32, i32* %19
%141 = load i32, i32* %18
%142 = icmp ne i32 %140, %141
br i1 %142, label %143, label %161
143: ; preds = %139
%144 = load i32, i32* %19
%145 = call i64 @FD_ISSET(i32 %144, i32* %7)
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %161
147: ; preds = %143
%148 = load i32, i32* %19
%149 = load i32, i32* %8
%150 = icmp ne i32 %148, %149
br i1 %150, label %151, label %161
151: ; preds = %147
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
%153 = load i32, i32* %19
%154 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%155 = call i32 @send(i32 %153, i8* %154, i32 18, i32 0)
store i32 %155, i32* %17
%156 = load i32, i32* %17
%157 = icmp slt i32 %156, 0
br i1 %157, label %158, label %160
158: ; preds = %151
%159 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
br label %160
160: ; preds = %158, %151
br label %161
161: ; preds = %160, %147, %143, %139
br label %162
162: ; preds = %161
%163 = load i32, i32* %19
%164 = add nsw i32 %163, 1
store i32 %164, i32* %19
br label %135
165: ; preds = %135
br label %166
166: ; preds = %165, %118
br label %167
167: ; preds = %166, %109, %105
br label %168
168: ; preds = %167
%169 = load i32, i32* %18
%170 = add nsw i32 %169, 1
store i32 %170, i32* %18
br label %96
171: ; preds = %103
%172 = load i32, i32* %11
%173 = add nsw i32 %172, 1
store i32 %173, i32* %11
br label %66
}

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