#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 in_addr {
  int dummy;
};
typedef scalar_t__ socklen_t;
typedef int /*<<< orphan*/ s_addr;
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*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in s_addr;
  socklen_t len;
  unsigned int port;
  char buf[1024];
  fd_set rfds;
  struct timeval tv;
  int retval, maxfd;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(errno);
  } else
    printf("socket create success!\n");
  memset(&s_addr, 0, sizeof(s_addr));
  s_addr.sin_family = AF_INET;
  s_addr.sin_port = htons(6666);
  if (inet_aton(argv[1], (struct in_addr *)&s_addr.sin_addr.s_addr) == 0) {
    perror(argv[1]);
    exit(errno);
  }
  if (connect(sockfd, (struct sockaddr *)&s_addr, sizeof(struct sockaddr)) ==
      -1) {
    perror("connect");
    exit(errno);
  } else
    printf("conncet success!\n");
  while (1) {
    FD_ZERO(&rfds);
    FD_SET(0, &rfds);
    maxfd = 0;
    FD_SET(sockfd, &rfds);
    if (maxfd < sockfd)
      maxfd = sockfd;
    tv.tv_sec = 6;
    tv.tv_usec = 0;
    retval = select(maxfd + 1, &rfds, NULL, NULL, &tv);
    if (retval == -1) {
      printf("select出错，客户端程序退出\n");
      break;
    } else if (retval == 0) {
      printf("waiting...\n");
      continue;
    } else {
      if (FD_ISSET(sockfd, &rfds)) {
        bzero(buf, 1024);
        len = recv(sockfd, buf, 1024, 0);
        if (len > 0)
          printf("服务器发来的消息是：%s\n", buf);
        else {
          if (len < 0)
            printf("接受消息失败！\n");
          else
            printf("服务器退出了，聊天终止！\n");
          break;
        }
      }
      if (FD_ISSET(0, &rfds)) {
        bzero(buf, 1024);
        fgets(buf, 1024, stdin);
        if (!strncasecmp(buf, "quit", 4)) {
          printf("client 请求终止聊天!\n");
          break;
        }
        len = send(sockfd, buf, strlen(buf), 0);
        if (len > 0)
          printf("\t消息发送成功：%s\n", buf);
        else {
          printf("消息发送失败!\n");
          break;
        }
      }
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1288 <main+0x58>
lea    0xd8b(%rip),%rdi
call   1100 <perror@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1a0a,%edi
call   1060 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10e0 <inet_aton@plt>
cmp    $0x0,%rax
jne    12f5 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <perror@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
jne    1329 <main+0xf9>
lea    0xd09(%rip),%rdi
call   1100 <perror@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    133c <main+0x10c>
lea    -0x434(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x434(%rbp),%rsi
call   1140 <FD_SET@plt>
movl   $0x0,-0x450(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x434(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x450(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1387 <main+0x157>
mov    -0x14(%rbp),%eax
mov    %eax,-0x450(%rbp)
movl   $0x6,-0x448(%rbp)
movq   $0x0,-0x440(%rbp)
mov    -0x450(%rbp),%edi
add    $0x1,%edi
lea    -0x434(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x448(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x44c(%rbp)
cmpl   $0xffffffff,-0x44c(%rbp)
jne    13e5 <main+0x1b5>
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15a4 <main+0x374>
cmpl   $0x0,-0x44c(%rbp)
jne    1405 <main+0x1d5>
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    133c <main+0x10c>
mov    -0x14(%rbp),%edi
lea    -0x434(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14a4 <main+0x274>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1110 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    146e <main+0x23e>
lea    -0x430(%rbp),%rsi
lea    0xc09(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    149f <main+0x26f>
cmpq   $0x0,-0x28(%rbp)
jge    148c <main+0x25c>
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    149a <main+0x26a>
lea    0xc11(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15a4 <main+0x374>
jmp    14a4 <main+0x274>
xor    %edi,%edi
lea    -0x434(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1595 <main+0x365>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1110 <bzero@plt>
lea    -0x430(%rbp),%rdi
mov    0x2b05(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   10b0 <fgets@plt>
lea    -0x430(%rbp),%rdi
lea    0xbd5(%rip),%rsi
mov    $0x4,%edx
call   10f0 <strncasecmp@plt>
cmp    $0x0,%eax
jne    151b <main+0x2eb>
lea    0xbc0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15a4 <main+0x374>
mov    -0x14(%rbp),%eax
mov    %eax,-0x45c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x458(%rbp)
lea    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    157d <main+0x34d>
lea    -0x430(%rbp),%rsi
lea    0xb7a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1590 <main+0x360>
lea    0xb81(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15a4 <main+0x374>
jmp    1595 <main+0x365>
jmp    159a <main+0x36a>
jmp    159f <main+0x36f>
jmp    133c <main+0x10c>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%r14
mov    0x2d8d(%rip),%r15
mov    (%r15),%edi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
je     1477 <main+0x237>
mov    %eax,%ebx
lea    0xdd0(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0x1a0a,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
mov    %rbp,%rsi
call   10f0 <inet_aton@plt>
test   %rax,%rax
je     1480 <main+0x240>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1140 <connect@plt>
cmp    $0xffffffff,%eax
je     1486 <main+0x246>
lea    0xd87(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
test   %ebx,%ebx
mov    %ebx,%r15d
cmovs  %eax,%r15d
add    $0x1,%r15d
lea    0xc(%rsp),%rbp
lea    0x10(%rsp),%r12
lea    0xddd(%rip),%r13
lea    0x20(%rsp),%r14
jmp    1318 <main+0xd8>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1150 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1150 <FD_SET@plt>
movl   $0x6,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10e0 <select@plt>
test   %eax,%eax
je     1310 <main+0xd0>
cmp    $0xffffffff,%eax
je     142a <main+0x1ea>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13ab <main+0x16b>
mov    %r14,%rdi
mov    $0x400,%esi
call   1120 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1433 <main+0x1f3>
lea    0xc6e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1318 <main+0xd8>
mov    %r14,%rdi
mov    $0x400,%esi
call   1120 <bzero@plt>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   10c0 <fgets@plt>
mov    %r14,%rdi
lea    0xc46(%rip),%rsi
mov    $0x4,%edx
call   1100 <strncasecmp@plt>
test   %eax,%eax
je     1447 <main+0x207>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
jle    1450 <main+0x210>
lea    0xc1b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1318 <main+0xd8>
lea    0xcbc(%rip),%rdi
jmp    1457 <main+0x217>
lea    0xc6d(%rip),%rax
lea    0xc8b(%rip),%rdi
cmove  %rax,%rdi
jmp    1457 <main+0x217>
lea    0xc2a(%rip),%rdi
jmp    1457 <main+0x217>
lea    0xc3c(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb82(%rip),%rdi
jmp    148d <main+0x24d>
mov    0x8(%r14),%rdi
jmp    148d <main+0x24d>
lea    0xb7a(%rip),%rdi
call   1110 <perror@plt>
mov    0x2b2f(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.1 = [24 x i8] c"socket create success!\0A\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [18 x i8] c"conncet success!\0A\00"
@.str.4 = [38 x i8] c"select\E5\87\BA\E9\94\99\EF\BC\8C\E5\AE\A2\E6\88\B7\E7\AB\AF\E7\A8\8B\E5\BA\8F\E9\80\80\E5\87\BA\0A\00"
@.str.5 = [12 x i8] c"waiting...\0A\00"
@.str.6 = [34 x i8] c"\E6\9C\8D\E5\8A\A1\E5\99\A8\E5\8F\91\E6\9D\A5\E7\9A\84\E6\B6\88\E6\81\AF\E6\98\AF\EF\BC\9A%s\0A\00"
@.str.7 = [23 x i8] c"\E6\8E\A5\E5\8F\97\E6\B6\88\E6\81\AF\E5\A4\B1\E8\B4\A5\EF\BC\81\0A\00"
@.str.8 = [38 x i8] c"\E6\9C\8D\E5\8A\A1\E5\99\A8\E9\80\80\E5\87\BA\E4\BA\86\EF\BC\8C\E8\81\8A\E5\A4\A9\E7\BB\88\E6\AD\A2\EF\BC\81\0A\00"
@stdin = global i32 0
@.str.9 = [5 x i8] c"quit\00"
@.str.10 = [28 x i8] c"client \E8\AF\B7\E6\B1\82\E7\BB\88\E6\AD\A2\E8\81\8A\E5\A4\A9!\0A\00"
@.str.11 = [26 x i8] c"\09\E6\B6\88\E6\81\AF\E5\8F\91\E9\80\81\E6\88\90\E5\8A\9F\EF\BC\9A%s\0A\00"
@.str.12 = [21 x i8] c"\E6\B6\88\E6\81\AF\E5\8F\91\E9\80\81\E5\A4\B1\E8\B4\A5!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i64
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @errno
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23
%26 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i32 6666)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = bitcast i32* %35 to %struct.in_addr*
%37 = call i64 @inet_aton(i8* %33, %struct.in_addr* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %25
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @perror(i8* %42)
%44 = load i32, i32* @errno
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %25
%47 = load i32, i32* %6
%48 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%49 = call i32 @connect(i32 %47, %struct.sockaddr* %48, i32 4)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* @errno
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %46
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55
br label %58
58: ; preds = %57, %81, %137
%59 = call i32 @FD_ZERO(i32* %11)
%60 = call i32 @FD_SET(i32 0, i32* %11)
store i32 0, i32* %14
%61 = load i32, i32* %6
%62 = call i32 @FD_SET(i32 %61, i32* %11)
%63 = load i32, i32* %14
%64 = load i32, i32* %6
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %58
%67 = load i32, i32* %6
store i32 %67, i32* %14
br label %68
68: ; preds = %66, %58
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 6, i32* %69
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %70
%71 = load i32, i32* %14
%72 = add nsw i32 %71, 1
%73 = call i32 @select(i32 %72, i32* %11, i32* null, i32* null, %struct.timeval* %12)
store i32 %73, i32* %13
%74 = load i32, i32* %13
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %68
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %138
78: ; preds = %68
%79 = load i32, i32* %13
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %58
83: ; preds = %78
%84 = load i32, i32* %6
%85 = call i64 @FD_ISSET(i32 %84, i32* %11)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %107
87: ; preds = %83
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%89 = call i32 @bzero(i8* %88, i32 1024)
%90 = load i32, i32* %6
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%92 = call i64 @recv(i32 %90, i8* %91, i32 1024, i32 0)
store i64 %92, i64* %8
%93 = load i64, i64* %8
%94 = icmp sgt i64 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %87
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %96)
br label %106
98: ; preds = %87
%99 = load i64, i64* %8
%100 = icmp slt i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %98
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %105
103: ; preds = %98
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %105
105: ; preds = %103, %101
br label %138
106: ; preds = %95
br label %107
107: ; preds = %106, %83
%108 = call i64 @FD_ISSET(i32 0, i32* %11)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %135
110: ; preds = %107
%111 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%112 = call i32 @bzero(i8* %111, i32 1024)
%113 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%114 = load i32, i32* @stdin
%115 = call i32 @fgets(i8* %113, i32 1024, i32 %114)
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%117 = call i32 @strncasecmp(i8* %116, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%118 = icmp ne i32 %117, 0
br i1 %118, label %121, label %119
119: ; preds = %110
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %138
121: ; preds = %110
%122 = load i32, i32* %6
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%124 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%125 = call i32 @strlen(i8* %124)
%126 = call i64 @send(i32 %122, i8* %123, i32 %125, i32 0)
store i64 %126, i64* %8
%127 = load i64, i64* %8
%128 = icmp sgt i64 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %121
%130 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %130)
br label %134
132: ; preds = %121
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
br label %138
134: ; preds = %129
br label %135
135: ; preds = %134, %107
br label %136
136: ; preds = %135
br label %137
137: ; preds = %136
br label %58
138: ; preds = %132, %119, %105, %76
%139 = load i32, i32* %6
%140 = call i32 @close(i32 %139)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"connect\00"
@.str.6 = [34 x i8] c"\E6\9C\8D\E5\8A\A1\E5\99\A8\E5\8F\91\E6\9D\A5\E7\9A\84\E6\B6\88\E6\81\AF\E6\98\AF\EF\BC\9A%s\0A\00"
@stdin = global i32 0
@.str.9 = [5 x i8] c"quit\00"
@.str.11 = [26 x i8] c"\09\E6\B6\88\E6\81\AF\E5\8F\91\E9\80\81\E6\88\90\E5\8A\9F\EF\BC\9A%s\0A\00"
@str = [23 x i8] c"socket create success!\00"
@str.13 = [17 x i8] c"conncet success!\00"
@str.14 = [27 x i8] c"client \E8\AF\B7\E6\B1\82\E7\BB\88\E6\AD\A2\E8\81\8A\E5\A4\A9!\00"
@str.15 = [20 x i8] c"\E6\B6\88\E6\81\AF\E5\8F\91\E9\80\81\E5\A4\B1\E8\B4\A5!\00"
@str.16 = [37 x i8] c"\E6\9C\8D\E5\8A\A1\E5\99\A8\E9\80\80\E5\87\BA\E4\BA\86\EF\BC\8C\E8\81\8A\E5\A4\A9\E7\BB\88\E6\AD\A2\EF\BC\81\00"
@str.17 = [22 x i8] c"\E6\8E\A5\E5\8F\97\E6\B6\88\E6\81\AF\E5\A4\B1\E8\B4\A5\EF\BC\81\00"
@str.18 = [11 x i8] c"waiting...\00"
@str.19 = [37 x i8] c"select\E5\87\BA\E9\94\99\EF\BC\8C\E5\AE\A2\E6\88\B7\E7\AB\AF\E7\A8\8B\E5\BA\8F\E9\80\80\E5\87\BA\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = bitcast %struct.timeval* %6 to i8*
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @errno
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%21 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 6666)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = bitcast %struct.sockaddr_in* %3 to %struct.in_addr*
%29 = call i64 @inet_aton(i8* %27, %struct.in_addr* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %19
%32 = load i8*, i8** %26
%33 = call i32 @perror(i8* %32)
%34 = load i32, i32* @errno
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %19
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @connect(i32 %13, %struct.sockaddr* %37, i32 4)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @errno
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
%46 = icmp sgt i32 %13, 0
%47 = select i1 %46, i32 %13, i32 0
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%50 = add nuw nsw i32 %47, 1
br label %51
51: ; preds = %73, %44
%52 = call i32 @FD_ZERO(i32* %5)
%53 = call i32 @FD_SET(i32 0, i32* %5)
%54 = call i32 @FD_SET(i32 %13, i32* %5)
store i32 6, i32* %48
store i64 0, i64* %49
%55 = call i32 @select(i32 %50, i32* %5, i32* null, i32* null, %struct.timeval* %6)
switch i32 %55, label %58 [
i32 -1, label %86
i32 0, label %56
]
56: ; preds = %51
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.18, i64 0, i64 0))
br label %73
58: ; preds = %51
%59 = call i64 @FD_ISSET(i32 %13, i32* %5)
%60 = icmp eq i64 %59, 0
br i1 %60, label %70, label %61
61: ; preds = %58
%62 = call i32 @bzero(i8* %8, i32 1024)
%63 = call i64 @recv(i32 %13, i8* %8, i32 1024, i32 0)
%64 = icmp sgt i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %70
67: ; preds = %61
%68 = icmp eq i64 %63, 0
%69 = select i1 %68, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str.17, i64 0, i64 0)
br label %86
70: ; preds = %65, %58
%71 = call i64 @FD_ISSET(i32 0, i32* %5)
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %70, %84, %56
br label %51
74: ; preds = %70
%75 = call i32 @bzero(i8* %8, i32 1024)
%76 = load i32, i32* @stdin
%77 = call i32 @fgets(i8* %8, i32 1024, i32 %76)
%78 = call i32 @strncasecmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%79 = icmp eq i32 %78, 0
br i1 %79, label %86, label %80
80: ; preds = %74
%81 = call i32 @strlen(i8* %8)
%82 = call i64 @send(i32 %13, i8* %8, i32 %81, i32 0)
%83 = icmp sgt i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %8)
br label %73
86: ; preds = %80, %74, %51, %67
%87 = phi i8* [ %69, %67 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @str.19, i64 0, i64 0), %51 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @str.14, i64 0, i64 0), %74 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0), %80 ]
%88 = call i32 @puts(i8* dereferenceable(1) %87)
%89 = call i32 @close(i32 %13)
ret i32 0
}