#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memcpy(TYPE_1__ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
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*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  char buf[1024];
  char send_str[1024];
  int recvbytes;
  int sockfd, k;
  struct hostent *hp;
  struct sockaddr_in addr;
  char *ip;
  int port;
  int ret;
  struct timeval timeout;
  fd_set rfd_set, wfd_set, efd_set;
  fd_set rfd_set2, wfd_set2, efd_set2;
  if (argc < 3) {
    printf("client ip port\n");
    return -1;
  }
  ip = argv[1];
  port = atoi(argv[2]);
  hp = gethostbyname(ip);
  if (hp == NULL) {
    perror("hostent error");
    return -2;
  }
  if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket error");
    return (-1);
  }
  memset(&addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = PF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr.s_addr = inet_addr(ip);
  memcpy(&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
  printf("connecting with %s:%d\n", ip, port);
  if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("connect");
    exit(1);
  }
  FD_ZERO(&rfd_set2);
  FD_ZERO(&wfd_set2);
  FD_ZERO(&efd_set2);
  FD_SET(0, &rfd_set2);
  FD_SET(sockfd, &rfd_set2);
  FD_SET(sockfd, &efd_set2);
  while (1) {
    rfd_set = rfd_set2;
    wfd_set = wfd_set2;
    efd_set = efd_set2;
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    ret = select(sockfd + 1, &rfd_set, &wfd_set, &efd_set, &timeout);
    if (ret == 0)
      continue;
    if (ret < 0) {
      perror("select error: ");
      exit(-1);
    }
    if (FD_ISSET(0, &rfd_set)) {
      fgets(send_str, 1024, stdin);
      send_str[strlen(send_str) - 1] = 0;
      if (strncmp("quit", send_str, 4) == 0) {
        close(sockfd);
        exit(0);
      }
      send(sockfd, send_str, strlen(send_str), 0);
    }
    if (FD_ISSET(sockfd, &rfd_set)) {
      recvbytes = recv(sockfd, buf, 1024, 0);
      if (recvbytes == 0) {
        close(sockfd);
        exit(0);
      }
      buf[recvbytes] = 0;
      printf("-----------\nserver said:%s\n", buf);
      fflush(stdout);
    }
    if (FD_ISSET(sockfd, &efd_set)) {
      close(sockfd);
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x880,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    129d <main+0x3d>
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    165f <main+0x3ff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x840(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,-0x844(%rbp)
mov    -0x840(%rbp),%rdi
call   10e0 <gethostbyname@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    12f8 <main+0x98>
lea    0xd29(%rip),%rdi
call   1130 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    165f <main+0x3ff>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x818(%rbp)
cmp    $0x0,%eax
jge    1338 <main+0xd8>
lea    0xcf7(%rip),%rdi
call   1130 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    165f <main+0x3ff>
lea    -0x838(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x830(%rbp)
mov    -0x844(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x834(%rbp)
mov    -0x840(%rbp),%rdi
call   10d0 <inet_addr@plt>
mov    %eax,-0x838(%rbp)
lea    -0x838(%rbp),%rdi
mov    -0x828(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x828(%rbp),%rax
mov    (%rax),%edx
call   10f0 <memcpy@plt>
mov    -0x840(%rbp),%rsi
mov    -0x844(%rbp),%edx
lea    0xc78(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x818(%rbp),%edi
lea    -0x838(%rbp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
cmp    $0x0,%rax
jge    13f1 <main+0x191>
lea    0xc60(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    -0x868(%rbp),%rdi
call   1100 <FD_ZERO@plt>
lea    -0x86c(%rbp),%rdi
call   1100 <FD_ZERO@plt>
lea    -0x870(%rbp),%rdi
call   1100 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x868(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x818(%rbp),%edi
lea    -0x868(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x818(%rbp),%edi
lea    -0x870(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x868(%rbp),%eax
mov    %eax,-0x85c(%rbp)
mov    -0x86c(%rbp),%eax
mov    %eax,-0x860(%rbp)
mov    -0x870(%rbp),%eax
mov    %eax,-0x864(%rbp)
movl   $0xa,-0x858(%rbp)
movq   $0x0,-0x850(%rbp)
mov    -0x818(%rbp),%edi
add    $0x1,%edi
lea    -0x85c(%rbp),%rsi
lea    -0x860(%rbp),%rdx
lea    -0x864(%rbp),%rcx
lea    -0x858(%rbp),%r8
call   1110 <select@plt>
mov    %eax,-0x848(%rbp)
cmpl   $0x0,-0x848(%rbp)
jne    14c2 <main+0x262>
jmp    1447 <main+0x1e7>
cmpl   $0x0,-0x848(%rbp)
jge    14e5 <main+0x285>
lea    0xb74(%rip),%rdi
call   1130 <perror@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
xor    %edi,%edi
lea    -0x85c(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15a0 <main+0x340>
lea    -0x810(%rbp),%rdi
mov    0x2add(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   10c0 <fgets@plt>
lea    -0x810(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rsi
lea    0xb1b(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1564 <main+0x304>
mov    -0x818(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1150 <exit@plt>
mov    -0x818(%rbp),%eax
mov    %eax,-0x87c(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x878(%rbp)
lea    -0x810(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x87c(%rbp),%edi
mov    -0x878(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    -0x818(%rbp),%edi
lea    -0x85c(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     162c <main+0x3cc>
mov    -0x818(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jne    15fa <main+0x39a>
mov    -0x818(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1150 <exit@plt>
movslq -0x814(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xa47(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x29a3(%rip),%rax
mov    (%rax),%edi
call   1120 <fflush@plt>
mov    -0x818(%rbp),%edi
lea    -0x864(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     165a <main+0x3fa>
mov    -0x818(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1150 <exit@plt>
jmp    1447 <main+0x1e7>
mov    -0x4(%rbp),%eax
add    $0x880,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x848,%rsp
cmp    $0x2,%edi
jg     12a9 <main+0x39>
lea    0xddd(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x848,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rdi
call   1150 <atoi@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   10f0 <gethostbyname@plt>
test   %rax,%rax
jne    12d9 <main+0x69>
lea    0xd33(%rip),%rdi
call   1140 <perror@plt>
mov    $0xfffffffe,%eax
jmp    1297 <main+0x27>
mov    %rax,%rbx
mov    0x2ced(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
test   %eax,%eax
jns    1309 <main+0x99>
lea    0xd0c(%rip),%rdi
call   1140 <perror@plt>
jmp    1292 <main+0x22>
mov    %eax,%r14d
lea    0x20(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    0x0(%r13),%eax
mov    %eax,0x28(%rsp)
mov    %r15d,%edi
call   1080 <htons@plt>
mov    %eax,0x24(%rsp)
mov    %rbp,%rdi
call   10e0 <inet_addr@plt>
mov    %eax,0x20(%rsp)
mov    0x8(%rbx),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
mov    %r12,%rdi
call   1100 <memcpy@plt>
lea    0xcc4(%rip),%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,0x4(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
test   %rax,%rax
jns    1394 <main+0x124>
lea    0xcad(%rip),%rdi
call   1140 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1110 <FD_ZERO@plt>
lea    0xc(%rsp),%rdi
call   1110 <FD_ZERO@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1110 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1180 <FD_SET@plt>
mov    0x4(%rsp),%r14d
mov    %r14d,%edi
mov    %rbx,%rsi
call   1180 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1180 <FD_SET@plt>
mov    %r14d,%r12d
add    $0x1,%r12d
lea    0x1c(%rsp),%rbx
lea    0x14(%rsp),%r13
lea    0x440(%rsp),%r15
jmp    140c <main+0x19c>
mov    %r14d,%edi
mov    %r13,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
jne    1521 <main+0x2b1>
mov    0x10(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0xc(%rsp),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x14(%rsp)
movl   $0xa,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
lea    0x18(%rsp),%rdx
mov    %r13,%rcx
lea    0x30(%rsp),%r8
call   1120 <select@plt>
test   %eax,%eax
je     140c <main+0x19c>
js     1526 <main+0x2b6>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     14bc <main+0x24c>
mov    0x2b7b(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x400,%esi
call   10d0 <fgets@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xbb6(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1521 <main+0x2b1>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     13f8 <main+0x188>
mov    %r13,%rbp
mov    %r14d,%edi
lea    0x40(%rsp),%r13
mov    %r13,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     153c <main+0x2cc>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
lea    0xb52(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x2abb(%rip),%rax
mov    (%rax),%edi
call   1130 <fflush@plt>
mov    %rbp,%r13
mov    0x4(%rsp),%r14d
jmp    13f8 <main+0x188>
mov    %r14d,%edi
jmp    1540 <main+0x2d0>
lea    0xb0d(%rip),%rdi
call   1140 <perror@plt>
mov    $0xffffffff,%edi
call   1160 <exit@plt>
mov    0x4(%rsp),%edi
call   10c0 <close@plt>
xor    %edi,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"client ip port\0A\00"
@.str.1 = [14 x i8] c"hostent error\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [13 x i8] c"socket error\00"
@.str.3 = [23 x i8] c"connecting with %s:%d\0A\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [15 x i8] c"select error: \00"
@stdin = global i32 0
@.str.6 = [5 x i8] c"quit\00"
@.str.7 = [28 x i8] c"-----------\0Aserver said:%s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.hostent*
%12 = alloca %struct.sockaddr_in
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.timeval
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %162
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %13
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %14
%35 = load i8*, i8** %13
%36 = call %struct.hostent* @gethostbyname(i8* %35)
store %struct.hostent* %36, %struct.hostent** %11
%37 = load %struct.hostent*, %struct.hostent** %11
%38 = icmp eq %struct.hostent* %37, null
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %162
41: ; preds = %27
%42 = load i32, i32* @PF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = call i32 @socket(i32 %42, i32 %43, i32 0)
store i32 %44, i32* %9
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %162
48: ; preds = %41
%49 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%50 = load i32, i32* @PF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* %14
%53 = call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %53, i32* %54
%55 = load i8*, i8** %13
%56 = call i32 @inet_addr(i8* %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
store i32 %56, i32* %58
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%60 = load %struct.hostent*, %struct.hostent** %11
%61 = getelementptr inbounds %struct.hostent, %struct.hostent* %60, i32 0, i32 1
%62 = load i32*, i32** %61
%63 = getelementptr inbounds i32, i32* %62, i64 0
%64 = load i32, i32* %63
%65 = load %struct.hostent*, %struct.hostent** %11
%66 = getelementptr inbounds %struct.hostent, %struct.hostent* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @memcpy(%struct.TYPE_2__* %59, i32 %64, i32 %67)
%69 = load i8*, i8** %13
%70 = load i32, i32* %14
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %69, i32 %70)
%72 = load i32, i32* %9
%73 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%74 = call i64 @connect(i32 %72, %struct.sockaddr* %73, i32 12)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %48
%77 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %48
%80 = call i32 @FD_ZERO(i32* %20)
%81 = call i32 @FD_ZERO(i32* %21)
%82 = call i32 @FD_ZERO(i32* %22)
%83 = call i32 @FD_SET(i32 0, i32* %20)
%84 = load i32, i32* %9
%85 = call i32 @FD_SET(i32 %84, i32* %20)
%86 = load i32, i32* %9
%87 = call i32 @FD_SET(i32 %86, i32* %22)
br label %88
88: ; preds = %79, %99, %161
%89 = load i32, i32* %20
store i32 %89, i32* %17
%90 = load i32, i32* %21
store i32 %90, i32* %18
%91 = load i32, i32* %22
store i32 %91, i32* %19
%92 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
store i32 10, i32* %92
%93 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
store i64 0, i64* %93
%94 = load i32, i32* %9
%95 = add nsw i32 %94, 1
%96 = call i32 @select(i32 %95, i32* %17, i32* %18, i32* %19, %struct.timeval* %16)
store i32 %96, i32* %15
%97 = load i32, i32* %15
%98 = icmp eq i32 %97, 0
br i1 %98, label %99, label %100
99: ; preds = %88
br label %88
100: ; preds = %88
%101 = load i32, i32* %15
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%105 = call i32 @exit(i32 -1)
unreachable
106: ; preds = %100
%107 = call i64 @FD_ISSET(i32 0, i32* %17)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %131
109: ; preds = %106
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%111 = load i32, i32* @stdin
%112 = call i32 @fgets(i8* %110, i32 1024, i32 %111)
%113 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%114 = call i32 @strlen(i8* %113)
%115 = sub nsw i32 %114, 1
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %116
store i8 0, i8* %117
%118 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%119 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %118, i32 4)
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %125
121: ; preds = %109
%122 = load i32, i32* %9
%123 = call i32 @close(i32 %122)
%124 = call i32 @exit(i32 0)
unreachable
125: ; preds = %109
%126 = load i32, i32* %9
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%129 = call i32 @strlen(i8* %128)
%130 = call i32 @send(i32 %126, i8* %127, i32 %129, i32 0)
br label %131
131: ; preds = %125, %106
%132 = load i32, i32* %9
%133 = call i64 @FD_ISSET(i32 %132, i32* %17)
%134 = icmp ne i64 %133, 0
br i1 %134, label %135, label %153
135: ; preds = %131
%136 = load i32, i32* %9
%137 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%138 = call i32 @recv(i32 %136, i8* %137, i32 1024, i32 0)
store i32 %138, i32* %8
%139 = load i32, i32* %8
%140 = icmp eq i32 %139, 0
br i1 %140, label %141, label %145
141: ; preds = %135
%142 = load i32, i32* %9
%143 = call i32 @close(i32 %142)
%144 = call i32 @exit(i32 0)
unreachable
145: ; preds = %135
%146 = load i32, i32* %8
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %147
store i8 0, i8* %148
%149 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %149)
%151 = load i32, i32* @stdout
%152 = call i32 @fflush(i32 %151)
br label %153
153: ; preds = %145, %131
%154 = load i32, i32* %9
%155 = call i64 @FD_ISSET(i32 %154, i32* %19)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %161
157: ; preds = %153
%158 = load i32, i32* %9
%159 = call i32 @close(i32 %158)
%160 = call i32 @exit(i32 0)
unreachable
161: ; preds = %153
br label %88
162: ; preds = %46, %39, %25
%163 = load i32, i32* %3
ret i32 %163
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i32, i32* }
%struct.sockaddr = type { i32 }
@.str.1 = [14 x i8] c"hostent error\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [13 x i8] c"socket error\00"
@.str.3 = [23 x i8] c"connecting with %s:%d\0A\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [15 x i8] c"select error: \00"
@stdin = global i32 0
@.str.6 = [5 x i8] c"quit\00"
@.str.7 = [28 x i8] c"-----------\0Aserver said:%s\0A\00"
@stdout = global i32 0
@str = [15 x i8] c"client ip port\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = bitcast %struct.sockaddr_in* %5 to i8*
%16 = bitcast %struct.timeval* %6 to i8*
%17 = bitcast i32* %7 to i8*
%18 = bitcast i32* %8 to i8*
%19 = bitcast i32* %9 to i8*
%20 = bitcast i32* %10 to i8*
%21 = bitcast i32* %11 to i8*
%22 = bitcast i32* %12 to i8*
%23 = icmp slt i32 %0, 3
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %126
26: ; preds = %2
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = tail call %struct.hostent* @gethostbyname(i8* %28)
%33 = icmp eq %struct.hostent* %32, null
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %126
36: ; preds = %26
%37 = load i32, i32* @PF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = tail call i32 @socket(i32 %37, i32 %38, i32 0)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %126
43: ; preds = %36
%44 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%45 = load i32, i32* @PF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %45, i32* %46
%47 = call i32 @htons(i32 %31)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %47, i32* %48
%49 = call i32 @inet_addr(i8* %28)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %49, i32* %51
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i64 0, i32 1
%53 = load i32*, i32** %52
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @memcpy(%struct.TYPE_2__* %50, i32 %54, i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32 %31)
%59 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%60 = call i64 @connect(i32 %39, %struct.sockaddr* %59, i32 12)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %43
%63 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %43
%66 = call i32 @FD_ZERO(i32* %10)
%67 = call i32 @FD_ZERO(i32* %11)
%68 = call i32 @FD_ZERO(i32* %12)
%69 = call i32 @FD_SET(i32 0, i32* %10)
%70 = call i32 @FD_SET(i32 %39, i32* %10)
%71 = call i32 @FD_SET(i32 %39, i32* %12)
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%74 = add nuw nsw i32 %39, 1
br label %75
75: ; preds = %81, %65
%76 = load i32, i32* %10
store i32 %76, i32* %7
%77 = load i32, i32* %11
store i32 %77, i32* %8
%78 = load i32, i32* %12
store i32 %78, i32* %9
store i32 10, i32* %72
store i64 0, i64* %73
%79 = call i32 @select(i32 %74, i32* %7, i32* %8, i32* %9, %struct.timeval* %6)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %75, %120
br label %75
82: ; preds = %75
%83 = icmp slt i32 %79, 0
br i1 %83, label %84, label %87
84: ; preds = %82
%85 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%86 = call i32 @exit(i32 -1)
unreachable
87: ; preds = %82
%88 = call i64 @FD_ISSET(i32 0, i32* %7)
%89 = icmp eq i64 %88, 0
br i1 %89, label %105, label %90
90: ; preds = %87
%91 = load i32, i32* @stdin
%92 = call i32 @fgets(i8* %14, i32 1024, i32 %91)
%93 = call i32 @strlen(i8* %14)
%94 = add nsw i32 %93, -1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %95
store i8 0, i8* %96
%97 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %14, i32 4)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %90
%100 = call i32 @close(i32 %39)
%101 = call i32 @exit(i32 0)
unreachable
102: ; preds = %90
%103 = call i32 @strlen(i8* %14)
%104 = call i32 @send(i32 %39, i8* %14, i32 %103, i32 0)
br label %105
105: ; preds = %102, %87
%106 = call i64 @FD_ISSET(i32 %39, i32* %7)
%107 = icmp eq i64 %106, 0
br i1 %107, label %120, label %108
108: ; preds = %105
%109 = call i32 @recv(i32 %39, i8* %13, i32 1024, i32 0)
%110 = icmp eq i32 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %108
%112 = call i32 @close(i32 %39)
%113 = call i32 @exit(i32 0)
unreachable
114: ; preds = %108
%115 = sext i32 %109 to i64
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %115
store i8 0, i8* %116
%117 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %13)
%118 = load i32, i32* @stdout
%119 = call i32 @fflush(i32 %118)
br label %120
120: ; preds = %114, %105
%121 = call i64 @FD_ISSET(i32 %39, i32* %9)
%122 = icmp eq i64 %121, 0
br i1 %122, label %81, label %123
123: ; preds = %120
%124 = call i32 @close(i32 %39)
%125 = call i32 @exit(i32 0)
unreachable
126: ; preds = %41, %34, %24
%127 = phi i32 [ -1, %24 ], [ -2, %34 ], [ -1, %41 ]
ret i32 %127
}