#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);
      if (newsockfd < 0)
        error("ERROR on accept");
      FD_SET(newsockfd, &master);
      printf("accept\n");
    }
    for (int i = 0; i < FD_SETSIZE; ++i) {
      if (FD_ISSET(i, &rfds) && (i != sockfd)) {
        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", 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    $0x160,%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     1413 <main+0x203>
movl   $0xc,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x150(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    13f9 <main+0x1e9>
lea    0xc94(%rip),%rdi
call   10d0 <error@plt>
mov    -0x20(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1120 <FD_SET@plt>
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x15c(%rbp)
mov    -0x15c(%rbp),%eax
mov    0x2b8e(%rip),%rcx
cmp    (%rcx),%eax
jge    1518 <main+0x308>
mov    -0x15c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14ff <main+0x2ef>
mov    -0x15c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     14ff <main+0x2ef>
cmpl   $0x0,-0x154(%rbp)
jge    1478 <main+0x268>
lea    0xc32(%rip),%rdi
call   10d0 <error@plt>
jmp    14fa <main+0x2ea>
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    0xc04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x15c(%rbp),%edi
lea    0xc09(%rip),%rsi
mov    $0x12,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jge    14f5 <main+0x2e5>
lea    0xbf6(%rip),%rdi
call   10d0 <error@plt>
jmp    14fa <main+0x2ea>
jmp    14ff <main+0x2ef>
jmp    1504 <main+0x2f4>
mov    -0x15c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15c(%rbp)
jmp    141d <main+0x20d>
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    1479 <main+0x259>
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>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10a0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
lea    0x4(%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    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2ca3(%rip),%r12
lea    0x4(%rsp),%r15
lea    0x30(%rsp),%r13
xor    %ebp,%ebp
jmp    1337 <main+0x117>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%ebp
add    $0x1,%ebp
imul   $0x26e978d5,%ebp,%eax
ror    $0x3,%eax
cmp    $0x418937,%eax
ja     1357 <main+0x137>
lea    0xcf1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,0x8(%rsp)
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
mov    (%r12),%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
mov    %eax,%ebp
lea    0xcf5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13d9 <main+0x1b9>
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1100 <accept@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    13c2 <main+0x1a2>
lea    0xcc3(%rip),%rdi
call   10e0 <error@plt>
mov    %r14d,%edi
mov    %rsp,%rsi
call   1130 <FD_SET@plt>
lea    0xcb5(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,(%r12)
jle    1330 <main+0x110>
xor    %r14d,%r14d
jmp    1403 <main+0x1e3>
nopl   0x0(%rax)
call   10e0 <error@plt>
add    $0x1,%r14d
cmp    (%r12),%r14d
jge    1330 <main+0x110>
mov    %r14d,%edi
mov    %r15,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13f5 <main+0x1d5>
cmp    %r14d,%ebx
je     13f5 <main+0x1d5>
lea    0xc71(%rip),%rdi
test   %ebp,%ebp
js     13f0 <main+0x1d0>
mov    %r13,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xc61(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14d,%edi
lea    0xc66(%rip),%rsi
mov    $0x12,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0xc66(%rip),%rdi
test   %eax,%eax
jns    13f5 <main+0x1d5>
jmp    13f0 <main+0x1d0>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    0xb77(%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"ERROR on accept\00"
@.str.7 = [8 x i8] c"accept\0A\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 = [19 x i8] c"I got your message\00"
@.str.11 = [24 x i8] c"ERROR writing to socket\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = load i32, i32* @IPPROTO_TCP
%29 = call i32 @socket(i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %25
%35 = call i32 @FD_ZERO(i32* %7)
%36 = load i32, i32* %8
%37 = call i32 @FD_SET(i32 %36, i32* %7)
%38 = call i32 @FD_ZERO(i32* %6)
%39 = load i32, i32* %8
%40 = call i32 @FD_SET(i32 %39, i32* %6)
%41 = bitcast %struct.sockaddr_in* %14 to i8*
%42 = call i32 @bzero(i8* %41, i32 12)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %10
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i32, i32* @INADDR_ANY
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
store i32 %49, i32* %51
%52 = load i32, i32* %10
%53 = call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* %8
%56 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%57 = call i64 @bind(i32 %55, %struct.sockaddr* %56, i32 12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %34
%60 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %34
%62 = load i32, i32* %8
%63 = call i32 @listen(i32 %62, i32 5)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %61, %131
%66 = load i32, i32* %11
%67 = srem i32 %66, 1000
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %65
%70 = load i32, i32* %11
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %69, %65
%73 = load i32, i32* %7
store i32 %73, i32* %6
%74 = load i32, i32* @FD_SETSIZE
%75 = call i32 @select(i32 %74, i32* %6, i32* null, i32* null, i32* null)
store i32 %75, i32* %16
%76 = load i32, i32* %16
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %76)
%78 = load i32, i32* %8
%79 = call i64 @FD_ISSET(i32 %78, i32* %6)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %93
81: ; preds = %72
store i32 12, i32* %12
%82 = load i32, i32* %8
%83 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%84 = call i32 @accept(i32 %82, %struct.sockaddr* %83, i32* %12)
store i32 %84, i32* %9
%85 = load i32, i32* %9
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %81
%88 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %89
89: ; preds = %87, %81
%90 = load i32, i32* %9
%91 = call i32 @FD_SET(i32 %90, i32* %7)
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %93
93: ; preds = %89, %72
store i32 0, i32* %18
br label %94
94: ; preds = %128, %93
%95 = load i32, i32* %18
%96 = load i32, i32* @FD_SETSIZE
%97 = icmp slt i32 %95, %96
br i1 %97, label %98, label %131
98: ; preds = %94
%99 = load i32, i32* %18
%100 = call i64 @FD_ISSET(i32 %99, i32* %6)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %127
102: ; preds = %98
%103 = load i32, i32* %18
%104 = load i32, i32* %8
%105 = icmp ne i32 %103, %104
br i1 %105, label %106, label %127
106: ; preds = %102
%107 = load i32, i32* %16
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %106
%110 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %126
111: ; preds = %106
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%113 = call i32 @bzero(i8* %112, i32 256)
%114 = load i32, i32* %18
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%116 = call i32 @recv(i32 %114, i8* %115, i32 255, i32 0)
store i32 %116, i32* %17
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %18
%120 = call i32 @send(i32 %119, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 18, i32 0)
store i32 %120, i32* %17
%121 = load i32, i32* %17
%122 = icmp slt i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %111
%124 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
br label %125
125: ; preds = %123, %111
br label %126
126: ; preds = %125, %109
br label %127
127: ; preds = %126, %102, %98
br label %128
128: ; preds = %127
%129 = load i32, i32* %18
%130 = add nsw i32 %129, 1
store i32 %130, i32* %18
br label %94
131: ; preds = %94
%132 = load i32, i32* %11
%133 = add nsw i32 %132, 1
store i32 %133, i32* %11
br label %65
}

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"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 = [19 x i8] c"I got your message\00"
@.str.11 = [24 x i8] c"ERROR writing to socket\00"
@str = [7 x i8] c"listen\00"
@str.12 = [7 x i8] c"accept\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 = icmp slt i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
%71 = call i32 @FD_SET(i32 %66, i32* %4)
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
br label %73
73: ; preds = %70, %58
%74 = load i32, i32* @FD_SETSIZE
%75 = icmp sgt i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = icmp slt i32 %61, 0
br label %80
78: ; preds = %96, %73
%79 = add nuw nsw i32 %53, 1
br label %52
80: ; preds = %76, %96
%81 = phi i32 [ 0, %76 ], [ %97, %96 ]
%82 = call i64 @FD_ISSET(i32 %81, i32* %3)
%83 = icmp eq i64 %82, 0
%84 = icmp eq i32 %81, %24
%85 = select i1 %83, i1 true, i1 %84
br i1 %85, label %96, label %86
86: ; preds = %80
br i1 %77, label %93, label %87
87: ; preds = %86
%88 = call i32 @bzero(i8* %12, i32 256)
%89 = call i32 @recv(i32 %81, i8* %12, i32 255, i32 0)
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %12)
%91 = call i32 @send(i32 %81, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 18, i32 0)
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %87, %86
%94 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), %86 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), %87 ]
%95 = call i32 @error(i8* %94)
br label %96
96: ; preds = %93, %80, %87
%97 = add nuw nsw i32 %81, 1
%98 = load i32, i32* @FD_SETSIZE
%99 = icmp slt i32 %97, %98
br i1 %99, label %80, label %78
}