#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*/ remoteAddr;
typedef int /*<<< orphan*/ in_port_t;
typedef int /*<<< orphan*/ fd_set;

/* 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 /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ dieWithMessage(char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  int i, err, numBytes, peerCount, maxFd;
  in_port_t remotePort;
  struct sockaddr_in remoteAddr;
  char *strIp, *strPort;
  int *peerFds = NULL;
  fd_set rfds;
  char buffer[1024];
  if (argc < 2)
    dieWithMessage("Usage: %s <server1:port1> [<server2:port2> ... ]");
  peerCount = argc - 1;
  peerFds = (int *)malloc(peerCount * sizeof(int));
  if (peerFds == NULL)
    dieWithMessage("memory too low");
  FD_ZERO(&rfds);
  maxFd = 0;
  for (i = 1; i <= peerCount; i++) {
    strIp = strtok(argv[i], ":");
    strPort = strtok(NULL, ":");
    remotePort = atoi(strPort);
    memset(&remoteAddr, 0, sizeof(remoteAddr));
    remoteAddr.sin_family = AF_INET;
    err = inet_pton(AF_INET, strIp, &remoteAddr.sin_addr.s_addr);
    if (err == 0)
      dieWithMessage("inet_pton() failed - Invalid address string");
    else if (err < 0)
      dieWithMessage("inet_pton() failed");
    remoteAddr.sin_port = htons(remotePort);
    peerFds[i - 1] = socket(AF_INET, SOCK_STREAM, 0);
    if (connect(peerFds[i - 1], (struct sockaddr *)&remoteAddr,
                sizeof(remoteAddr)) < 0)
      dieWithMessage("connect() failed");
    FD_SET(peerFds[i - 1], &rfds);
    maxFd = (peerFds[i - 1] > maxFd) ? peerFds[i - 1] : maxFd;
  }
  while (1) {
    FD_ZERO(&rfds);
    for (i = 0; i < peerCount; i++) {
      FD_SET(peerFds[i], &rfds);
    }
    err = select(maxFd + 1, &rfds, NULL, NULL, NULL);
    if (err == -1) {
      dieWithMessage("select() failed");
    } else if (err) {
      for (i = 0; i < peerCount; i++) {
        if (FD_ISSET(peerFds[i], &rfds)) {
          numBytes = recv(peerFds[i], buffer, 1024 - 1, 0);
          if (numBytes < 0)
            dieWithMessage("recv() failed");
          else if (numBytes == 0)
            dieWithMessage("recv() Connection closed prematurely");
          buffer[numBytes] = '\0';
          printf("%s\n", buffer);
        }
      }
    } else {
      dieWithMessage("Select timedout!");
    }
  }
  free(peerFds);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x50(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1227 <main+0x37>
lea    0xdde(%rip),%rdi
call   1070 <dieWithMessage@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    125a <main+0x6a>
lea    0xddc(%rip),%rdi
call   1070 <dieWithMessage@plt>
lea    -0x54(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     13ff <main+0x20f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdb0(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9c(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
add    $0x4,%rdx
call   1090 <inet_pton@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    130d <main+0x11d>
lea    0xd3f(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    1328 <main+0x138>
cmpl   $0x0,-0x18(%rbp)
jge    1323 <main+0x133>
lea    0xd50(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    1328 <main+0x138>
mov    -0x28(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    0x2c95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%edx
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    1392 <main+0x1a2>
lea    0xcf4(%rip),%rdi
call   1070 <dieWithMessage@plt>
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x54(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
jle    13df <main+0x1ef>
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x464(%rbp)
jmp    13e8 <main+0x1f8>
mov    -0x24(%rbp),%eax
mov    %eax,-0x464(%rbp)
mov    -0x464(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1271 <main+0x81>
jmp    1404 <main+0x214>
lea    -0x54(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1442 <main+0x252>
mov    -0x50(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x54(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1414 <main+0x224>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
lea    -0x54(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10b0 <select@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    147a <main+0x28a>
lea    0xc22(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    1554 <main+0x364>
cmpl   $0x0,-0x18(%rbp)
je     1543 <main+0x353>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    153e <main+0x34e>
mov    -0x50(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x54(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     152b <main+0x33b>
mov    -0x50(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x460(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14f1 <main+0x301>
lea    0xbbb(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    150c <main+0x31c>
cmpl   $0x0,-0x1c(%rbp)
jne    1507 <main+0x317>
lea    0xbae(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    150c <main+0x31c>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x460(%rbp,%rax,1)
lea    -0x460(%rbp),%rsi
lea    0xbaf(%rip),%rdi
call   1060 <printf@plt>
jmp    1530 <main+0x340>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    148b <main+0x29b>
jmp    154f <main+0x35f>
lea    0xb8f(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    1554 <main+0x364>
jmp    1404 <main+0x214>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
cmp    $0x1,%edi
jg     1217 <main+0x27>
lea    0xdee(%rip),%rdi
call   1070 <dieWithMessage@plt>
lea    -0x4(,%rbx,4),%edi
call   10c0 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1237 <main+0x47>
lea    0xdff(%rip),%rdi
call   1070 <dieWithMessage@plt>
lea    -0x1(%rbx),%r14d
lea    0x4(%rsp),%rdi
call   10a0 <FD_ZERO@plt>
movl   $0x1,(%rsp)
cmp    $0x2,%ebx
mov    %rbp,0x8(%rsp)
mov    %rbx,0x28(%rsp)
jl     137b <main+0x18b>
mov    %r14d,0x14(%rsp)
mov    %ebx,%r14d
add    $0xffffffffffffffff,%r14
xor    %r13d,%r13d
lea    0xdcb(%rip),%r12
movl   $0x0,(%rsp)
jmp    12aa <main+0xba>
xchg   %ax,%ax
mov    (%rbx,%r13,4),%edi
lea    0x4(%rsp),%rsi
call   1100 <FD_SET@plt>
mov    (%rbx,%r13,4),%eax
mov    (%rsp),%ecx
cmp    %ecx,%eax
cmovg  %eax,%ecx
mov    %ecx,(%rsp)
add    $0x1,%r13
cmp    %r13,%r14
je     136d <main+0x17d>
mov    0x8(%r15,%r13,8),%rdi
mov    %r12,%rbx
mov    %r12,%rsi
call   10d0 <strtok@plt>
mov    %rax,%rbp
xor    %edi,%edi
mov    %r12,%rsi
call   10d0 <strtok@plt>
mov    %rax,%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebx
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x20(%rsp)
mov    %rbp,%rsi
lea    0x1c(%rsp),%rdx
call   1090 <inet_pton@plt>
lea    0xd3f(%rip),%rdi
test   %eax,%eax
je     1310 <main+0x120>
lea    0xd60(%rip),%rdi
jns    1315 <main+0x125>
call   1070 <dieWithMessage@plt>
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    0x2ca8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    0x8(%rsp),%rbx
mov    %eax,(%rbx,%r13,4)
mov    %eax,%edi
lea    0x18(%rsp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
jns    1280 <main+0x90>
lea    0xd1e(%rip),%rdi
call   1070 <dieWithMessage@plt>
jmp    1280 <main+0x90>
addl   $0x1,(%rsp)
mov    0x8(%rsp),%rbp
mov    0x14(%rsp),%r14d
mov    %r14d,%r14d
lea    0x4(%rsp),%r15
lea    0x30(%rsp),%rbx
jmp    139f <main+0x1af>
nopw   0x0(%rax,%rax,1)
lea    0xd42(%rip),%rdi
mov    %r13,%rbx
call   1070 <dieWithMessage@plt>
mov    %rbx,%r13
mov    %r15,%rdi
call   10a0 <FD_ZERO@plt>
mov    0x28(%rsp),%r12
cmp    $0x2,%r12d
jl     13e0 <main+0x1f0>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,4),%edi
mov    %r15,%rsi
call   1100 <FD_SET@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    13c0 <main+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
cmp    $0xffffffff,%eax
je     1410 <main+0x220>
test   %eax,%eax
je     1390 <main+0x1a0>
cmp    $0x2,%r12d
jge    1420 <main+0x230>
mov    %r15,%rdi
call   10a0 <FD_ZERO@plt>
jmp    13e0 <main+0x1f0>
nopl   0x0(%rax,%rax,1)
lea    0xc7b(%rip),%rdi
jmp    1397 <main+0x1a7>
nopl   0x0(%rax)
xor    %r12d,%r12d
mov    %r13,%rbx
jmp    145e <main+0x26e>
nopl   0x0(%rax,%rax,1)
call   1070 <dieWithMessage@plt>
movslq %r13d,%rax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xc91(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x8(%rsp),%rbp
add    $0x1,%r12
cmp    %r12,%r14
je     139f <main+0x1af>
mov    0x0(%rbp,%r12,4),%edi
mov    %r15,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1451 <main+0x261>
mov    0x0(%rbp,%r12,4),%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r13d
lea    0xc14(%rip),%rdi
test   %eax,%eax
js     1430 <main+0x240>
lea    0xc17(%rip),%rdi
jne    1435 <main+0x245>
jmp    1430 <main+0x240>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [49 x i8] c"Usage: %s <server1:port1> [<server2:port2> ... ]\00"
@.str.1 = [15 x i8] c"memory too low\00"
@.str.2 = [2 x i8] c":\00"
@AF_INET = global i32 0
@.str.3 = [44 x i8] c"inet_pton() failed - Invalid address string\00"
@.str.4 = [19 x i8] c"inet_pton() failed\00"
@SOCK_STREAM = global i32 0
@.str.5 = [17 x i8] c"connect() failed\00"
@.str.6 = [16 x i8] c"select() failed\00"
@.str.7 = [14 x i8] c"recv() failed\00"
@.str.8 = [37 x i8] c"recv() Connection closed prematurely\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@.str.10 = [17 x i8] c"Select timedout!\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 %struct.sockaddr_in
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %15
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @dieWithMessage(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %15
%31 = load i32*, i32** %15
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = call i32 @dieWithMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %22
%36 = call i32 @FD_ZERO(i32* %16)
store i32 0, i32* %10
store i32 1, i32* %6
br label %37
37: ; preds = %119, %35
%38 = load i32, i32* %6
%39 = load i32, i32* %9
%40 = icmp sle i32 %38, %39
br i1 %40, label %41, label %122
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i8* @strtok(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %47, i8** %13
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %48, i8** %14
%49 = load i8*, i8** %14
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %11
%51 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%52 = load i32, i32* @AF_INET
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %52, i32* %53
%54 = load i32, i32* @AF_INET
%55 = load i8*, i8** %13
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
%58 = call i32 @inet_pton(i32 %54, i8* %55, i32* %57)
store i32 %58, i32* %7
%59 = load i32, i32* %7
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %41
%62 = call i32 @dieWithMessage(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %69
63: ; preds = %41
%64 = load i32, i32* %7
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 @dieWithMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
br label %69
69: ; preds = %68, %61
%70 = load i32, i32* %11
%71 = call i32 @htons(i32 %70)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %71, i32* %72
%73 = load i32, i32* @AF_INET
%74 = load i32, i32* @SOCK_STREAM
%75 = call i32 @socket(i32 %73, i32 %74, i32 0)
%76 = load i32*, i32** %15
%77 = load i32, i32* %6
%78 = sub nsw i32 %77, 1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %76, i64 %79
store i32 %75, i32* %80
%81 = load i32*, i32** %15
%82 = load i32, i32* %6
%83 = sub nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %81, i64 %84
%86 = load i32, i32* %85
%87 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%88 = call i64 @connect(i32 %86, %struct.sockaddr* %87, i32 12)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %69
%91 = call i32 @dieWithMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %92
92: ; preds = %90, %69
%93 = load i32*, i32** %15
%94 = load i32, i32* %6
%95 = sub nsw i32 %94, 1
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %93, i64 %96
%98 = load i32, i32* %97
%99 = call i32 @FD_SET(i32 %98, i32* %16)
%100 = load i32*, i32** %15
%101 = load i32, i32* %6
%102 = sub nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %100, i64 %103
%105 = load i32, i32* %104
%106 = load i32, i32* %10
%107 = icmp sgt i32 %105, %106
br i1 %107, label %108, label %115
108: ; preds = %92
%109 = load i32*, i32** %15
%110 = load i32, i32* %6
%111 = sub nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i32, i32* %109, i64 %112
%114 = load i32, i32* %113
br label %117
115: ; preds = %92
%116 = load i32, i32* %10
br label %117
117: ; preds = %115, %108
%118 = phi i32 [ %114, %108 ], [ %116, %115 ]
store i32 %118, i32* %10
br label %119
119: ; preds = %117
%120 = load i32, i32* %6
%121 = add nsw i32 %120, 1
store i32 %121, i32* %6
br label %37
122: ; preds = %37
br label %123
123: ; preds = %122, %195
%124 = call i32 @FD_ZERO(i32* %16)
store i32 0, i32* %6
br label %125
125: ; preds = %136, %123
%126 = load i32, i32* %6
%127 = load i32, i32* %9
%128 = icmp slt i32 %126, %127
br i1 %128, label %129, label %139
129: ; preds = %125
%130 = load i32*, i32** %15
%131 = load i32, i32* %6
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i32, i32* %130, i64 %132
%134 = load i32, i32* %133
%135 = call i32 @FD_SET(i32 %134, i32* %16)
br label %136
136: ; preds = %129
%137 = load i32, i32* %6
%138 = add nsw i32 %137, 1
store i32 %138, i32* %6
br label %125
139: ; preds = %125
%140 = load i32, i32* %10
%141 = add nsw i32 %140, 1
%142 = call i32 @select(i32 %141, i32* %16, i32* null, i32* null, i32* null)
store i32 %142, i32* %7
%143 = load i32, i32* %7
%144 = icmp eq i32 %143, -1
br i1 %144, label %145, label %147
145: ; preds = %139
%146 = call i32 @dieWithMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %195
147: ; preds = %139
%148 = load i32, i32* %7
%149 = icmp ne i32 %148, 0
br i1 %149, label %150, label %192
150: ; preds = %147
store i32 0, i32* %6
br label %151
151: ; preds = %188, %150
%152 = load i32, i32* %6
%153 = load i32, i32* %9
%154 = icmp slt i32 %152, %153
br i1 %154, label %155, label %191
155: ; preds = %151
%156 = load i32*, i32** %15
%157 = load i32, i32* %6
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i32, i32* %156, i64 %158
%160 = load i32, i32* %159
%161 = call i64 @FD_ISSET(i32 %160, i32* %16)
%162 = icmp ne i64 %161, 0
br i1 %162, label %163, label %187
163: ; preds = %155
%164 = load i32*, i32** %15
%165 = load i32, i32* %6
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i32, i32* %164, i64 %166
%168 = load i32, i32* %167
%169 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%170 = call i32 @recv(i32 %168, i8* %169, i32 1023, i32 0)
store i32 %170, i32* %8
%171 = load i32, i32* %8
%172 = icmp slt i32 %171, 0
br i1 %172, label %173, label %175
173: ; preds = %163
%174 = call i32 @dieWithMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %181
175: ; preds = %163
%176 = load i32, i32* %8
%177 = icmp eq i32 %176, 0
br i1 %177, label %178, label %180
178: ; preds = %175
%179 = call i32 @dieWithMessage(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %180
180: ; preds = %178, %175
br label %181
181: ; preds = %180, %173
%182 = load i32, i32* %8
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 %183
store i8 0, i8* %184
%185 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%186 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %185)
br label %187
187: ; preds = %181, %155
br label %188
188: ; preds = %187
%189 = load i32, i32* %6
%190 = add nsw i32 %189, 1
store i32 %190, i32* %6
br label %151
191: ; preds = %151
br label %194
192: ; preds = %147
%193 = call i32 @dieWithMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %194
194: ; preds = %192, %191
br label %195
195: ; preds = %194, %145
br label %123
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [49 x i8] c"Usage: %s <server1:port1> [<server2:port2> ... ]\00"
@.str.1 = [15 x i8] c"memory too low\00"
@.str.2 = [2 x i8] c":\00"
@AF_INET = global i32 0
@.str.3 = [44 x i8] c"inet_pton() failed - Invalid address string\00"
@.str.4 = [19 x i8] c"inet_pton() failed\00"
@SOCK_STREAM = global i32 0
@.str.5 = [17 x i8] c"connect() failed\00"
@.str.6 = [16 x i8] c"select() failed\00"
@.str.7 = [14 x i8] c"recv() failed\00"
@.str.8 = [37 x i8] c"recv() Connection closed prematurely\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@.str.10 = [17 x i8] c"Select timedout!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @dieWithMessage(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = add nsw i32 %0, -1
%14 = shl i32 %13, 2
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @dieWithMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = call i32 @FD_ZERO(i32* %4)
%22 = icmp sgt i32 %0, 1
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = zext i32 %0 to i64
br label %35
29: ; preds = %63
%30 = add i32 %68, 1
br label %31
31: ; preds = %29, %20
%32 = phi i32 [ 1, %20 ], [ %30, %29 ]
%33 = zext i32 %13 to i64
%34 = zext i32 %13 to i64
br label %71
35: ; preds = %23, %63
%36 = phi i64 [ 1, %23 ], [ %69, %63 ]
%37 = phi i32 [ 0, %23 ], [ %68, %63 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 %36
%39 = load i8*, i8** %38
%40 = call i8* @strtok(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @atoi(i8* %41)
%43 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%44 = load i32, i32* @AF_INET
store i32 %44, i32* %24
%45 = call i32 @inet_pton(i32 %44, i8* %40, i32* %25)
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %35
%48 = icmp slt i32 %45, 0
br i1 %48, label %49, label %52
49: ; preds = %47, %35
%50 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), %35 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), %47 ]
%51 = call i32 @dieWithMessage(i8* %50)
br label %52
52: ; preds = %49, %47
%53 = call i32 @htons(i32 %42)
store i32 %53, i32* %26
%54 = load i32, i32* @AF_INET
%55 = load i32, i32* @SOCK_STREAM
%56 = call i32 @socket(i32 %54, i32 %55, i32 0)
%57 = add nsw i64 %36, -1
%58 = getelementptr inbounds i32, i32* %16, i64 %57
store i32 %56, i32* %58
%59 = call i64 @connect(i32 %56, %struct.sockaddr* %27, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %52
%62 = call i32 @dieWithMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61, %52
%64 = load i32, i32* %58
%65 = call i32 @FD_SET(i32 %64, i32* %4)
%66 = load i32, i32* %58
%67 = icmp sgt i32 %66, %37
%68 = select i1 %67, i32 %66, i32 %37
%69 = add nuw nsw i64 %36, 1
%70 = icmp eq i64 %69, %28
br i1 %70, label %29, label %35
71: ; preds = %112, %31
%72 = call i32 @FD_ZERO(i32* %4)
br i1 %22, label %73, label %80
73: ; preds = %71, %73
%74 = phi i64 [ %78, %73 ], [ 0, %71 ]
%75 = getelementptr inbounds i32, i32* %16, i64 %74
%76 = load i32, i32* %75
%77 = call i32 @FD_SET(i32 %76, i32* %4)
%78 = add nuw nsw i64 %74, 1
%79 = icmp eq i64 %78, %33
br i1 %79, label %80, label %73
80: ; preds = %73, %71
br label %83
81: ; preds = %85
%82 = call i32 @FD_ZERO(i32* %4)
br label %83
83: ; preds = %80, %81
%84 = call i32 @select(i32 %32, i32* %4, i32* null, i32* null, i32* null)
switch i32 %84, label %85 [
i32 -1, label %108
i32 0, label %109
]
85: ; preds = %83
br i1 %22, label %86, label %81
86: ; preds = %85, %105
%87 = phi i64 [ %106, %105 ], [ 0, %85 ]
%88 = getelementptr inbounds i32, i32* %16, i64 %87
%89 = load i32, i32* %88
%90 = call i64 @FD_ISSET(i32 %89, i32* %4)
%91 = icmp eq i64 %90, 0
br i1 %91, label %105, label %92
92: ; preds = %86
%93 = load i32, i32* %88
%94 = call i32 @recv(i32 %93, i8* %8, i32 1023, i32 0)
%95 = icmp slt i32 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %92
%97 = icmp eq i32 %94, 0
br i1 %97, label %98, label %101
98: ; preds = %96, %92
%99 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), %92 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), %96 ]
%100 = call i32 @dieWithMessage(i8* %99)
br label %101
101: ; preds = %98, %96
%102 = sext i32 %94 to i64
%103 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %102
store i8 0, i8* %103
%104 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %8)
br label %105
105: ; preds = %86, %101
%106 = add nuw nsw i64 %87, 1
%107 = icmp eq i64 %106, %34
br i1 %107, label %112, label %86
108: ; preds = %83
br label %109
109: ; preds = %83, %108
%110 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), %108 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), %83 ]
%111 = call i32 @dieWithMessage(i8* %110)
br label %112
112: ; preds = %105, %109
br label %71
}