#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 */

/* Type definitions */
struct timeval {
  int member_1;
  int /*<<< orphan*/ member_0;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ *member_7;
  int /*<<< orphan*/ *member_6;
  int /*<<< orphan*/ *member_5;
  int /*<<< orphan*/ member_4;
  int /*<<< orphan*/ member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNSPEC;
int FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char const *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
scalar_t__ read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ write(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ write_err_msg(char const *);
int main(int argc, char **argv) {
  int fd, nfds, gai_result, con_result, hasData;
  ssize_t nread, nwrite;
  const char *input_err_msg = "node and service must be provided\n",
             *read_err_msg = "An error occurred while reading\n",
             *select_err_msg = "An error occurred while waiting\n",
             *write_error_msg = "An error occurred while writing\n",
             *gai_err_msg =
                 "An error occurred while interpretting the service\n",
             *con_err_msg =
                 "An error occurred while connecting to the service\n";
  struct addrinfo *info,
      hints = {0, AF_UNSPEC, SOCK_STREAM, 0, 0, NULL, NULL, NULL};
  struct timeval t, r = {0, 100000};
  char buffer[512];
  fd_set fds;
  if (argc < 3) {
    write_err_msg(input_err_msg);
    return 1;
  }
  gai_result = getaddrinfo(argv[1], argv[2], &hints, &info);
  if (gai_result) {
    write_err_msg(gai_err_msg);
    write_err_msg(gai_strerror(gai_result));
    write_err_msg("\n");
    return 1;
  }
  fd = socket(AF_INET, SOCK_STREAM, 0);
  con_result = connect(fd, info->ai_addr, info->ai_addrlen);
  if (con_result < 0) {
    write_err_msg(con_err_msg);
    return 1;
  }
  freeaddrinfo(info);
  t = r;
  FD_ZERO(&fds);
  FD_SET(fd, &fds);
  while (nfds = select(fd + 1, &fds, NULL, NULL, &t)) {
    if (nfds < 0) {
      write_err_msg(select_err_msg);
      return 1;
    }
    hasData = FD_ISSET(fd, &fds);
    FD_ZERO(&fds);
    if (hasData) {
      nread = read(fd, buffer, 512);
      if (nread < 0) {
        write_err_msg(read_err_msg);
        return 1;
      }
      nwrite = write(STDOUT_FILENO, buffer, nread);
      if (nwrite < 0) {
        write_err_msg(write_error_msg);
        return 1;
      }
      if (nread == 0) {
        close(fd);
      } else {
        FD_SET(fd, &fds);
      }
    }
    t = r;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe00(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe18(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe2e(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe44(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    -0xa8(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1060 <memset@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2d64(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0xb8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    129b <main+0xbb>
mov    -0x40(%rbp),%rdi
call   10b0 <write_err_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b4 <main+0x2d4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0xa8(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12f9 <main+0x119>
mov    -0x60(%rbp),%rdi
call   10b0 <write_err_msg@plt>
mov    -0x1c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    %rax,%rdi
call   10b0 <write_err_msg@plt>
lea    0xd39(%rip),%rdi
call   10b0 <write_err_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b4 <main+0x2d4>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
mov    0x2cbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x70(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x70(%rbp),%rax
mov    (%rax),%edx
call   10c0 <connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    134c <main+0x16c>
mov    -0x68(%rbp),%rdi
call   10b0 <write_err_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b4 <main+0x2d4>
mov    -0x70(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0xb8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x2c4(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x2c4(%rbp),%rsi
call   10e0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x2c4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xb0(%rbp),%r8
mov    %rcx,%rdx
call   10a0 <select@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     14a5 <main+0x2c5>
cmpl   $0x0,-0x18(%rbp)
jge    13c9 <main+0x1e9>
mov    -0x50(%rbp),%rdi
call   10b0 <write_err_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b4 <main+0x2d4>
mov    -0x14(%rbp),%edi
lea    -0x2c4(%rbp),%rsi
call   1040 <FD_ISSET@plt>
mov    %eax,-0x24(%rbp)
lea    -0x2c4(%rbp),%rdi
call   1090 <FD_ZERO@plt>
cmpl   $0x0,-0x24(%rbp)
je     1492 <main+0x2b2>
mov    -0x14(%rbp),%edi
lea    -0x2c0(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1429 <main+0x249>
mov    -0x48(%rbp),%rdi
call   10b0 <write_err_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b4 <main+0x2d4>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
lea    -0x2c0(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    1466 <main+0x286>
mov    -0x58(%rbp),%rdi
call   10b0 <write_err_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b4 <main+0x2d4>
cmpq   $0x0,-0x30(%rbp)
jne    147e <main+0x29e>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    148d <main+0x2ad>
mov    -0x14(%rbp),%edi
lea    -0x2c4(%rbp),%rsi
call   10e0 <FD_SET@plt>
jmp    1492 <main+0x2b2>
mov    -0xb8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
jmp    137e <main+0x19e>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movq   $0x0,0x50(%rsp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2db8(%rip),%rbp
movslq 0x0(%rbp),%rax
mov    %rax,0x28(%rsp)
cmp    $0x2,%edi
jg     1227 <main+0x57>
lea    0xddb(%rip),%rdi
jmp    1266 <main+0x96>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     1286 <main+0xb6>
mov    %eax,%ebx
lea    0xe3b(%rip),%rdi
call   10a0 <write_err_msg@plt>
mov    %ebx,%edi
call   1050 <gai_strerror@plt>
mov    %rax,%rdi
call   10a0 <write_err_msg@plt>
lea    0xdbb(%rip),%rdi
call   10a0 <write_err_msg@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r15d
mov    0x18(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r15d,%edi
call   10b0 <connect@plt>
test   %eax,%eax
js     13ba <main+0x1ea>
movabs $0x186a000000000,%rbp
mov    0x18(%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    %rbp,0x8(%rsp)
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10d0 <FD_SET@plt>
mov    %r15d,%edi
add    $0x1,%edi
xor    %r14d,%r14d
lea    0x8(%rsp),%r8
mov    %edi,0x10(%rsp)
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <select@plt>
test   %eax,%eax
je     13c6 <main+0x1f6>
lea    0x14(%rsp),%r13
lea    0x60(%rsp),%rbp
jmp    1350 <main+0x180>
nopl   0x0(%rax)
mov    %r13,%rsi
call   10d0 <FD_SET@plt>
movabs $0x186a000000000,%rax
mov    %rax,0x8(%rsp)
mov    0x10(%rsp),%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
call   1090 <select@plt>
test   %eax,%eax
je     13c6 <main+0x1f6>
test   %eax,%eax
js     13d3 <main+0x203>
mov    %r15d,%edi
mov    %r13,%rsi
call   1040 <FD_ISSET@plt>
mov    %rbp,%rbx
mov    %eax,%ebp
mov    %r13,%rdi
call   1080 <FD_ZERO@plt>
test   %ebp,%ebp
mov    %rbx,%rbp
je     1328 <main+0x158>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
test   %rax,%rax
js     13df <main+0x20f>
mov    %rax,%r12
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1030 <write@plt>
test   %rax,%rax
js     13eb <main+0x21b>
mov    %r15d,%edi
test   %r12,%r12
jne    1320 <main+0x150>
call   1060 <close@plt>
jmp    1328 <main+0x158>
lea    0xcf8(%rip),%rdi
jmp    1266 <main+0x96>
mov    %r15d,%edi
call   1060 <close@plt>
jmp    1271 <main+0xa1>
lea    0xc6a(%rip),%rdi
jmp    1266 <main+0x96>
lea    0xc3d(%rip),%rdi
jmp    1266 <main+0x96>
lea    0xc73(%rip),%rdi
jmp    1266 <main+0x96>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.addrinfo = type { i32, i32, i32*, i32*, i32*, i32, i32, i32, i32, i32 }
@.str = [35 x i8] c"node and service must be provided\0A\00"
@.str.1 = [33 x i8] c"An error occurred while reading\0A\00"
@.str.2 = [33 x i8] c"An error occurred while waiting\0A\00"
@.str.3 = [33 x i8] c"An error occurred while writing\0A\00"
@.str.4 = [51 x i8] c"An error occurred while interpretting the service\0A\00"
@.str.5 = [51 x i8] c"An error occurred while connecting to the service\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@__const.main.r = %struct.timeval { i32 0, i32 100000 }
@.str.6 = [2 x i8] c"\0A\00"
@AF_INET = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca %struct.addrinfo*
%20 = alloca %struct.addrinfo
%21 = alloca %struct.timeval
%22 = alloca %struct.timeval
%23 = alloca [512 x i8]
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8** %16
store i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8** %17
store i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i8** %18
%25 = bitcast %struct.addrinfo* %20 to i8*
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 1
%27 = load i32, i32* @AF_UNSPEC
store i32 %27, i32* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 2
%29 = load i32, i32* @SOCK_STREAM
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %28
%32 = bitcast %struct.timeval* %22 to i8*
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 3
br i1 %34, label %35, label %38
35: ; preds = %2
%36 = load i8*, i8** %13
%37 = call i32 @write_err_msg(i8* %36)
store i32 1, i32* %3
br label %132
38: ; preds = %2
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @getaddrinfo(i8* %41, i8* %44, %struct.addrinfo* %20, %struct.addrinfo** %19)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %38
%49 = load i8*, i8** %17
%50 = call i32 @write_err_msg(i8* %49)
%51 = load i32, i32* %8
%52 = call i8* @gai_strerror(i32 %51)
%53 = call i32 @write_err_msg(i8* %52)
%54 = call i32 @write_err_msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %132
55: ; preds = %38
%56 = load i32, i32* @AF_INET
%57 = load i32, i32* @SOCK_STREAM
%58 = call i32 @socket(i32 %56, i32 %57, i32 0)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = load %struct.addrinfo*, %struct.addrinfo** %19
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 1
%62 = load i32, i32* %61
%63 = load %struct.addrinfo*, %struct.addrinfo** %19
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @connect(i32 %59, i32 %62, i32 %65)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %55
%70 = load i8*, i8** %18
%71 = call i32 @write_err_msg(i8* %70)
store i32 1, i32* %3
br label %132
72: ; preds = %55
%73 = load %struct.addrinfo*, %struct.addrinfo** %19
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %73)
%75 = bitcast %struct.timeval* %21 to i8*
%76 = bitcast %struct.timeval* %22 to i8*
%77 = call i32 @FD_ZERO(i32* %24)
%78 = load i32, i32* %6
%79 = call i32 @FD_SET(i32 %78, i32* %24)
br label %80
80: ; preds = %126, %72
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
%83 = call i32 @select(i32 %82, i32* %24, i32* null, i32* null, %struct.timeval* %21)
store i32 %83, i32* %7
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %129
85: ; preds = %80
%86 = load i32, i32* %7
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8*, i8** %15
%90 = call i32 @write_err_msg(i8* %89)
store i32 1, i32* %3
br label %132
91: ; preds = %85
%92 = load i32, i32* %6
%93 = call i32 @FD_ISSET(i32 %92, i32* %24)
store i32 %93, i32* %10
%94 = call i32 @FD_ZERO(i32* %24)
%95 = load i32, i32* %10
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %126
97: ; preds = %91
%98 = load i32, i32* %6
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %23, i64 0, i64 0
%100 = call i64 @read(i32 %98, i8* %99, i32 512)
store i64 %100, i64* %11
%101 = load i64, i64* %11
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %97
%104 = load i8*, i8** %14
%105 = call i32 @write_err_msg(i8* %104)
store i32 1, i32* %3
br label %132
106: ; preds = %97
%107 = load i32, i32* @STDOUT_FILENO
%108 = getelementptr inbounds [512 x i8], [512 x i8]* %23, i64 0, i64 0
%109 = load i64, i64* %11
%110 = call i64 @write(i32 %107, i8* %108, i64 %109)
store i64 %110, i64* %12
%111 = load i64, i64* %12
%112 = icmp slt i64 %111, 0
br i1 %112, label %113, label %116
113: ; preds = %106
%114 = load i8*, i8** %16
%115 = call i32 @write_err_msg(i8* %114)
store i32 1, i32* %3
br label %132
116: ; preds = %106
%117 = load i64, i64* %11
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %116
%120 = load i32, i32* %6
%121 = call i32 @close(i32 %120)
br label %125
122: ; preds = %116
%123 = load i32, i32* %6
%124 = call i32 @FD_SET(i32 %123, i32* %24)
br label %125
125: ; preds = %122, %119
br label %126
126: ; preds = %125, %91
%127 = bitcast %struct.timeval* %21 to i8*
%128 = bitcast %struct.timeval* %22 to i8*
br label %80
129: ; preds = %80
%130 = load i32, i32* %6
%131 = call i32 @close(i32 %130)
store i32 0, i32* %3
br label %132
132: ; preds = %129, %113, %103, %88, %69, %48, %35
%133 = load i32, i32* %3
ret i32 %133
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32*, i32*, i32*, i32, i32, i32, i32, i32 }
%struct.timeval = type { i32, i32 }
@.str = [35 x i8] c"node and service must be provided\0A\00"
@.str.1 = [33 x i8] c"An error occurred while reading\0A\00"
@.str.2 = [33 x i8] c"An error occurred while waiting\0A\00"
@.str.3 = [33 x i8] c"An error occurred while writing\0A\00"
@.str.4 = [51 x i8] c"An error occurred while interpretting the service\0A\00"
@.str.5 = [51 x i8] c"An error occurred while connecting to the service\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [2 x i8] c"\0A\00"
@AF_INET = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = alloca i64
%6 = bitcast i64* %5 to %struct.timeval*
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = bitcast %struct.addrinfo** %3 to i8*
%10 = bitcast %struct.addrinfo* %4 to i8*
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
%12 = load i32, i32* @AF_UNSPEC
store i32 %12, i32* %11
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
%14 = load i32, i32* @SOCK_STREAM
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %13
%17 = bitcast i64* %5 to i8*
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%19 = bitcast i32* %8 to i8*
%20 = icmp slt i32 %0, 3
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = tail call i32 @write_err_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %87
23: ; preds = %2
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @getaddrinfo(i8* %25, i8* %27, %struct.addrinfo* %4, %struct.addrinfo** %3)
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %23
%31 = call i32 @write_err_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%32 = call i8* @gai_strerror(i32 %28)
%33 = call i32 @write_err_msg(i8* %32)
%34 = call i32 @write_err_msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %87
35: ; preds = %23
%36 = load i32, i32* @AF_INET
%37 = load i32, i32* @SOCK_STREAM
%38 = call i32 @socket(i32 %36, i32 %37, i32 0)
%39 = load %struct.addrinfo*, %struct.addrinfo** %3
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @connect(i32 %38, i32 %41, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %35
%47 = call i32 @write_err_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0))
br label %87
48: ; preds = %35
%49 = load %struct.addrinfo*, %struct.addrinfo** %3
%50 = call i32 @freeaddrinfo(%struct.addrinfo* %49)
store i64 429496729600000, i64* %5
%51 = call i32 @FD_ZERO(i32* %8)
%52 = call i32 @FD_SET(i32 %38, i32* %8)
%53 = add nsw i32 %38, 1
%54 = call i32 @select(i32 %53, i32* %8, i32* null, i32* null, %struct.timeval* %6)
%55 = icmp eq i32 %54, 0
br i1 %55, label %85, label %56
56: ; preds = %48, %82
%57 = phi i32 [ %83, %82 ], [ %54, %48 ]
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @write_err_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %87
61: ; preds = %56
%62 = call i32 @FD_ISSET(i32 %38, i32* %8)
%63 = call i32 @FD_ZERO(i32* %8)
%64 = icmp eq i32 %62, 0
br i1 %64, label %82, label %65
65: ; preds = %61
%66 = call i64 @read(i32 %38, i8* %18, i32 512)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = call i32 @write_err_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %87
70: ; preds = %65
%71 = load i32, i32* @STDOUT_FILENO
%72 = call i64 @write(i32 %71, i8* %18, i64 %66)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 @write_err_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %87
76: ; preds = %70
%77 = icmp eq i64 %66, 0
br i1 %77, label %78, label %80
78: ; preds = %76
%79 = call i32 @close(i32 %38)
br label %82
80: ; preds = %76
%81 = call i32 @FD_SET(i32 %38, i32* %8)
br label %82
82: ; preds = %78, %80, %61
store i64 429496729600000, i64* %5
%83 = call i32 @select(i32 %53, i32* %8, i32* null, i32* null, %struct.timeval* %6)
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %56
85: ; preds = %82, %48
%86 = call i32 @close(i32 %38)
br label %87
87: ; preds = %85, %74, %68, %59, %46, %30, %21
%88 = phi i32 [ 1, %21 ], [ 1, %30 ], [ 1, %46 ], [ 1, %59 ], [ 1, %68 ], [ 1, %74 ], [ 0, %85 ]
ret i32 %88
}