#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 tv_sec;
  scalar_t__ tv_usec;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  scalar_t__ ai_flags;
};
typedef int /*<<< orphan*/ state;
typedef int /*<<< orphan*/ hints;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ TCP_CORK;
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read(int /*<<< orphan*/, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sock, retrd, retwr, len;
  struct addrinfo hints;
  struct addrinfo *rp;
  struct timeval tv;
  fd_set rfds, wfds;
  static char buff[4096];
  int state = 1;
  if (argc != 3) {
    fprintf(stderr, "usage: %s <server_ip> <port>\n", argv[0]);
    exit(1);
  }
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  if (getaddrinfo(argv[1], argv[2], &hints, &rp) != 0)
    die("getaddrinfo()");
  if ((sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0)
    die("socket()");
  if (setsockopt(sock, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)) < 0)
    die("setsockopt()");
  if (connect(sock, rp->ai_addr, rp->ai_addrlen) == -1)
    die("connect()");
  fcntl(sock, F_SETFL, O_NONBLOCK);
  fcntl(0, F_SETFL, O_NONBLOCK);
  fcntl(1, F_SETFL, O_NONBLOCK);
  for (;;) {
    tv.tv_sec = 30;
    tv.tv_usec = 0;
    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
    FD_SET(0, &rfds);
    FD_SET(sock, &rfds);
    FD_SET(1, &wfds);
    FD_SET(sock, &wfds);
    retrd = select(sock + 1, &rfds, NULL, NULL, &tv);
    retwr = select(sock + 1, NULL, &wfds, NULL, &tv);
    if (retrd == -1 || retwr == -1) {
      perror("select()");
    } else if (retrd && retwr) {
      if (FD_ISSET(0, &rfds) && FD_ISSET(sock, &wfds)) {
        len = read(0, buff, sizeof(buff));
        if (len < 1) {
          shutdown(sock, SHUT_RDWR);
          exit(0);
        }
        send(sock, buff, len, 0);
      }
      if (FD_ISSET(sock, &rfds) && FD_ISSET(1, &wfds)) {
        len = recv(sock, buff, sizeof(buff), 0);
        if (len < 1) {
          shutdown(sock, SHUT_RDWR);
          exit(0);
        }
        write(1, buff, len);
      }
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x64(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     127d <main+0x4d>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd92(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10a0 <memset@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1130 <getaddrinfo@plt>
cmp    $0x0,%rax
je     12e8 <main+0xb8>
lea    0xd3b(%rip),%rdi
call   10f0 <die@plt>
mov    -0x48(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    131b <main+0xeb>
lea    0xd16(%rip),%rdi
call   10f0 <die@plt>
mov    -0x14(%rbp),%edi
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
mov    0x2c9a(%rip),%rax
mov    (%rax),%edx
lea    -0x64(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1355 <main+0x125>
lea    0xce5(%rip),%rdi
call   10f0 <die@plt>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
jne    137f <main+0x14f>
lea    0xcc8(%rip),%rdi
call   10f0 <die@plt>
mov    -0x14(%rbp),%edi
mov    0x2c27(%rip),%rax
mov    (%rax),%esi
mov    0x2c4e(%rip),%rax
mov    (%rax),%edx
call   1050 <fcntl@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%esi
mov    0x2c37(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1050 <fcntl@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%esi
mov    0x2c1e(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1050 <fcntl@plt>
movl   $0x1e,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
lea    -0x5c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
lea    -0x60(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x5c(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x5c(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    $0x1,%edi
lea    -0x60(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x5c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x58(%rbp),%r8
mov    %rcx,%rdx
call   10e0 <select@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x60(%rbp),%rdx
lea    -0x58(%rbp),%r8
mov    %rcx,%rsi
call   10e0 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     146e <main+0x23e>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    147f <main+0x24f>
lea    0xbd7(%rip),%rdi
call   1100 <perror@plt>
jmp    1591 <main+0x361>
cmpl   $0x0,-0x18(%rbp)
je     158c <main+0x35c>
cmpl   $0x0,-0x1c(%rbp)
je     158c <main+0x35c>
xor    %edi,%edi
lea    -0x5c(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     150a <main+0x2da>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     150a <main+0x2da>
xor    %edi,%edi
lea    0x2c09(%rip),%rsi
mov    $0x1000,%edx
call   10b0 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    14f6 <main+0x2c6>
mov    -0x14(%rbp),%edi
mov    0x2b08(%rip),%rax
mov    (%rax),%esi
call   1080 <shutdown@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%edx
lea    0x2bcd(%rip),%rsi
xor    %ecx,%ecx
call   1090 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0x5c(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1587 <main+0x357>
mov    $0x1,%edi
lea    -0x60(%rbp),%rsi
call   1070 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1587 <main+0x357>
mov    -0x14(%rbp),%edi
lea    0x2b8e(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    1573 <main+0x343>
mov    -0x14(%rbp),%edi
mov    0x2a8b(%rip),%rax
mov    (%rax),%esi
call   1080 <shutdown@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x20(%rbp),%edx
mov    $0x1,%edi
lea    0x2b4e(%rip),%rsi
call   1060 <write@plt>
jmp    158c <main+0x35c>
jmp    1591 <main+0x361>
jmp    13ce <main+0x19e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
movl   $0x1,0x4(%rsp)
cmp    $0x3,%edi
jne    14e0 <main+0x2b0>
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10a0 <memset@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
movq   $0x0,0x40(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x8(%rsp),%rcx
mov    %rbp,%rdx
call   1130 <getaddrinfo@plt>
test   %rax,%rax
je     12b8 <main+0x88>
lea    0xd6b(%rip),%rdi
call   10f0 <die@plt>
mov    0x8(%rsp),%rax
mov    0x14(%rax),%edi
mov    0x10(%rax),%esi
mov    0x8(%rax),%rdx
call   1150 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    12df <main+0xaf>
lea    0xd52(%rip),%rdi
call   10f0 <die@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
mov    0x2cd9(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jns    1315 <main+0xe5>
lea    0xd25(%rip),%rdi
call   10f0 <die@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r15d,%edi
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
jne    1338 <main+0x108>
lea    0xd0f(%rip),%rdi
call   10f0 <die@plt>
mov    0x2c71(%rip),%rbx
mov    (%rbx),%esi
mov    0x2c98(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %r15d,%edi
call   1050 <fcntl@plt>
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
xor    %edi,%edi
call   1050 <fcntl@plt>
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
mov    $0x1,%edi
call   1050 <fcntl@plt>
mov    %r15d,%r14d
add    $0x1,%r14d
lea    0x14(%rsp),%rbp
lea    0x10(%rsp),%rbx
lea    0x18(%rsp),%r12
jmp    13a0 <main+0x170>
lea    0xcbf(%rip),%rdi
call   1100 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x1e,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
mov    %rbx,%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10e0 <select@plt>
mov    %eax,%r13d
mov    %r14d,%edi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
call   10e0 <select@plt>
cmp    $0xffffffff,%r13d
je     1386 <main+0x156>
cmp    $0xffffffff,%eax
je     1386 <main+0x156>
test   %r13d,%r13d
je     13a0 <main+0x170>
test   %eax,%eax
je     13a0 <main+0x170>
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     1485 <main+0x255>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     1485 <main+0x255>
xor    %edi,%edi
lea    0x2c6f(%rip),%r13
mov    %r13,%rsi
mov    $0x1000,%edx
call   10b0 <read@plt>
test   %eax,%eax
jle    1502 <main+0x2d2>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    %r15d,%edi
lea    0x2c17(%rip),%r13
mov    %r13,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1502 <main+0x2d2>
mov    $0x1,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1060 <write@plt>
jmp    13a0 <main+0x170>
mov    0x2ad1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb0d(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2ae7(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1080 <shutdown@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i64 }
%struct.timeval = type { i32, i64 }
@main.buff = internal global [4096 x i8] zeroinitializer
@stderr = global i32 0
@.str = [30 x i8] c"usage: %s <server_ip> <port>\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"getaddrinfo()\00"
@.str.2 = [9 x i8] c"socket()\00"
@IPPROTO_TCP = global i32 0
@TCP_CORK = global i32 0
@.str.3 = [13 x i8] c"setsockopt()\00"
@.str.4 = [10 x i8] c"connect()\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [9 x i8] c"select()\00"
@SHUT_RDWR = 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 %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %15
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 32)
%27 = load i32, i32* @AF_UNSPEC
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %27, i32* %28
%29 = load i32, i32* @SOCK_STREAM
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 5
store i64 0, i64* %31
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
store i64 0, i64* %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i64 @getaddrinfo(i8* %35, i8* %38, %struct.addrinfo* %10, %struct.addrinfo** %11)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %25
%42 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %25
%44 = load %struct.addrinfo*, %struct.addrinfo** %11
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 4
%46 = load i32, i32* %45
%47 = load %struct.addrinfo*, %struct.addrinfo** %11
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 3
%49 = load i32, i32* %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %11
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 2
%52 = load i64, i64* %51
%53 = call i32 @socket(i32 %46, i32 %49, i64 %52)
store i32 %53, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %43
%56 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %43
%58 = load i32, i32* %6
%59 = load i32, i32* @IPPROTO_TCP
%60 = load i32, i32* @TCP_CORK
%61 = call i64 @setsockopt(i32 %58, i32 %59, i32 %60, i32* %15, i32 4)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = call i32 @die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %63, %57
%66 = load i32, i32* %6
%67 = load %struct.addrinfo*, %struct.addrinfo** %11
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 1
%69 = load i32, i32* %68
%70 = load %struct.addrinfo*, %struct.addrinfo** %11
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @connect(i32 %66, i32 %69, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %65
%76 = call i32 @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %77
77: ; preds = %75, %65
%78 = load i32, i32* %6
%79 = load i32, i32* @F_SETFL
%80 = load i32, i32* @O_NONBLOCK
%81 = call i32 @fcntl(i32 %78, i32 %79, i32 %80)
%82 = load i32, i32* @F_SETFL
%83 = load i32, i32* @O_NONBLOCK
%84 = call i32 @fcntl(i32 0, i32 %82, i32 %83)
%85 = load i32, i32* @F_SETFL
%86 = load i32, i32* @O_NONBLOCK
%87 = call i32 @fcntl(i32 1, i32 %85, i32 %86)
br label %88
88: ; preds = %160, %77
%89 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 30, i32* %89
%90 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %90
%91 = call i32 @FD_ZERO(i32* %13)
%92 = call i32 @FD_ZERO(i32* %14)
%93 = call i32 @FD_SET(i32 0, i32* %13)
%94 = load i32, i32* %6
%95 = call i32 @FD_SET(i32 %94, i32* %13)
%96 = call i32 @FD_SET(i32 1, i32* %14)
%97 = load i32, i32* %6
%98 = call i32 @FD_SET(i32 %97, i32* %14)
%99 = load i32, i32* %6
%100 = add nsw i32 %99, 1
%101 = call i32 @select(i32 %100, i32* %13, i32* null, i32* null, %struct.timeval* %12)
store i32 %101, i32* %7
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
%104 = call i32 @select(i32 %103, i32* null, i32* %14, i32* null, %struct.timeval* %12)
store i32 %104, i32* %8
%105 = load i32, i32* %7
%106 = icmp eq i32 %105, -1
br i1 %106, label %110, label %107
107: ; preds = %88
%108 = load i32, i32* %8
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %112
110: ; preds = %107, %88
%111 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %160
112: ; preds = %107
%113 = load i32, i32* %7
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %159
115: ; preds = %112
%116 = load i32, i32* %8
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %159
118: ; preds = %115
%119 = call i64 @FD_ISSET(i32 0, i32* %13)
%120 = icmp ne i64 %119, 0
br i1 %120, label %121, label %138
121: ; preds = %118
%122 = load i32, i32* %6
%123 = call i64 @FD_ISSET(i32 %122, i32* %14)
%124 = icmp ne i64 %123, 0
br i1 %124, label %125, label %138
125: ; preds = %121
%126 = call i32 @read(i32 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 4096)
store i32 %126, i32* %9
%127 = load i32, i32* %9
%128 = icmp slt i32 %127, 1
br i1 %128, label %129, label %134
129: ; preds = %125
%130 = load i32, i32* %6
%131 = load i32, i32* @SHUT_RDWR
%132 = call i32 @shutdown(i32 %130, i32 %131)
%133 = call i32 @exit(i32 0)
unreachable
134: ; preds = %125
%135 = load i32, i32* %6
%136 = load i32, i32* %9
%137 = call i32 @send(i32 %135, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 %136, i32 0)
br label %138
138: ; preds = %134, %121, %118
%139 = load i32, i32* %6
%140 = call i64 @FD_ISSET(i32 %139, i32* %13)
%141 = icmp ne i64 %140, 0
br i1 %141, label %142, label %158
142: ; preds = %138
%143 = call i64 @FD_ISSET(i32 1, i32* %14)
%144 = icmp ne i64 %143, 0
br i1 %144, label %145, label %158
145: ; preds = %142
%146 = load i32, i32* %6
%147 = call i32 @recv(i32 %146, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 4096, i32 0)
store i32 %147, i32* %9
%148 = load i32, i32* %9
%149 = icmp slt i32 %148, 1
br i1 %149, label %150, label %155
150: ; preds = %145
%151 = load i32, i32* %6
%152 = load i32, i32* @SHUT_RDWR
%153 = call i32 @shutdown(i32 %151, i32 %152)
%154 = call i32 @exit(i32 0)
unreachable
155: ; preds = %145
%156 = load i32, i32* %9
%157 = call i32 @write(i32 1, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 %156)
br label %158
158: ; preds = %155, %142, %138
br label %159
159: ; preds = %158, %115, %112
br label %160
160: ; preds = %159, %110
br label %88
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i64 }
%struct.timeval = type { i32, i64 }
@main.buff = internal global [4096 x i8] zeroinitializer
@stderr = global i32 0
@.str = [30 x i8] c"usage: %s <server_ip> <port>\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"getaddrinfo()\00"
@.str.2 = [9 x i8] c"socket()\00"
@IPPROTO_TCP = global i32 0
@TCP_CORK = global i32 0
@.str.3 = [13 x i8] c"setsockopt()\00"
@.str.4 = [10 x i8] c"connect()\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [9 x i8] c"select()\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast %struct.addrinfo* %3 to i8*
%10 = bitcast %struct.addrinfo** %4 to i8*
%11 = bitcast %struct.timeval* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
store i32 1, i32* %8
%15 = icmp eq i32 %0, 3
br i1 %15, label %21, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%23 = load i32, i32* @AF_UNSPEC
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @SOCK_STREAM
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @getaddrinfo(i8* %30, i8* %32, %struct.addrinfo* %3, %struct.addrinfo** %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %21
%36 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %21
%38 = load %struct.addrinfo*, %struct.addrinfo** %4
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 4
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 3
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 2
%44 = load i64, i64* %43
%45 = call i32 @socket(i32 %40, i32 %42, i64 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %37
%50 = load i32, i32* @IPPROTO_TCP
%51 = load i32, i32* @TCP_CORK
%52 = call i64 @setsockopt(i32 %45, i32 %50, i32 %51, i32* %8, i32 4)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %49
%57 = load %struct.addrinfo*, %struct.addrinfo** %4
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 1
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 @connect(i32 %45, i32 %59, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %56
%65 = call i32 @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64, %56
%67 = load i32, i32* @F_SETFL
%68 = load i32, i32* @O_NONBLOCK
%69 = call i32 @fcntl(i32 %45, i32 %67, i32 %68)
%70 = load i32, i32* @F_SETFL
%71 = load i32, i32* @O_NONBLOCK
%72 = call i32 @fcntl(i32 0, i32 %70, i32 %71)
%73 = load i32, i32* @F_SETFL
%74 = load i32, i32* @O_NONBLOCK
%75 = call i32 @fcntl(i32 1, i32 %73, i32 %74)
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%78 = add nsw i32 %45, 1
br label %79
79: ; preds = %97, %66
store i32 30, i32* %76
store i64 0, i64* %77
%80 = call i32 @FD_ZERO(i32* %6)
%81 = call i32 @FD_ZERO(i32* %7)
%82 = call i32 @FD_SET(i32 0, i32* %6)
%83 = call i32 @FD_SET(i32 %45, i32* %6)
%84 = call i32 @FD_SET(i32 1, i32* %7)
%85 = call i32 @FD_SET(i32 %45, i32* %7)
%86 = call i32 @select(i32 %78, i32* %6, i32* null, i32* null, %struct.timeval* %5)
%87 = call i32 @select(i32 %78, i32* null, i32* %7, i32* null, %struct.timeval* %5)
%88 = icmp eq i32 %86, -1
%89 = icmp eq i32 %87, -1
%90 = select i1 %88, i1 true, i1 %89
br i1 %90, label %91, label %93
91: ; preds = %79
%92 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %97
93: ; preds = %79
%94 = icmp ne i32 %86, 0
%95 = icmp ne i32 %87, 0
%96 = select i1 %94, i1 %95, i1 false
br i1 %96, label %98, label %97
97: ; preds = %93, %126, %116, %113, %91
br label %79
98: ; preds = %93
%99 = call i64 @FD_ISSET(i32 0, i32* %6)
%100 = icmp eq i64 %99, 0
br i1 %100, label %113, label %101
101: ; preds = %98
%102 = call i64 @FD_ISSET(i32 %45, i32* %7)
%103 = icmp eq i64 %102, 0
br i1 %103, label %113, label %104
104: ; preds = %101
%105 = call i32 @read(i32 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 4096)
%106 = icmp slt i32 %105, 1
br i1 %106, label %107, label %111
107: ; preds = %104
%108 = load i32, i32* @SHUT_RDWR
%109 = call i32 @shutdown(i32 %45, i32 %108)
%110 = call i32 @exit(i32 0)
unreachable
111: ; preds = %104
%112 = call i32 @send(i32 %45, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 %105, i32 0)
br label %113
113: ; preds = %111, %101, %98
%114 = call i64 @FD_ISSET(i32 %45, i32* %6)
%115 = icmp eq i64 %114, 0
br i1 %115, label %97, label %116
116: ; preds = %113
%117 = call i64 @FD_ISSET(i32 1, i32* %7)
%118 = icmp eq i64 %117, 0
br i1 %118, label %97, label %119
119: ; preds = %116
%120 = call i32 @recv(i32 %45, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 4096, i32 0)
%121 = icmp slt i32 %120, 1
br i1 %121, label %122, label %126
122: ; preds = %119
%123 = load i32, i32* @SHUT_RDWR
%124 = call i32 @shutdown(i32 %45, i32 %123)
%125 = call i32 @exit(i32 0)
unreachable
126: ; preds = %119
%127 = call i32 @write(i32 1, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buff, i64 0, i64 0), i32 %120)
br label %97
}