#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 sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ ip;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ cliaddr;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ addr;

/* 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*/ SHUT_RD;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 3)
    err_quit("usage:./tcp_client ip port");
  int ret1, ret2, ret3;
  int sockfd;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    err_sys("socket error");
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(atoi(argv[2]));
  inet_pton(AF_INET, argv[1], &addr.sin_addr);
  ret1 = bind(sockfd, (struct sockaddr *)&addr, sizeof(addr));
  if (ret1 < 0)
    err_sys("bind error");
  ret2 = listen(sockfd, 2);
  if (ret2 < 0)
    err_sys("listen error");
  for (;;) {
    int clifd;
    char ip[16];
    struct sockaddr_in cliaddr;
    socklen_t len = sizeof(cliaddr);
    clifd = accept(sockfd, (struct sockaddr *)&cliaddr, &len);
    inet_ntop(AF_INET, &cliaddr.sin_addr, ip, sizeof(ip));
    printf("connect with ip %s  port %d\n", ip, ntohs(cliaddr.sin_port));
    fd_set read_set;
    int flag = 0;
    for (;;) {
      int n;
      char buffer[1024];
      FD_ZERO(&read_set);
      FD_SET(0, &read_set);
      if (flag == 0)
        FD_SET(clifd, &read_set);
      ret3 = select(clifd + 1, &read_set, NULL, NULL, NULL);
      if (ret3 < 0)
        err_sys("select error");
      else {
        if (FD_ISSET(0, &read_set)) {
          bzero(buffer, sizeof(buffer));
          n = read(0, buffer, 1024);
          buffer[n] = '\0';
          write(clifd, buffer, 1024);
        }
        if (FD_ISSET(clifd, &read_set)) {
          bzero(buffer, sizeof(buffer));
          n = recv(clifd, buffer, sizeof(buffer), 0);
          if (n < 0)
            break;
          if (n == 0) {
            printf("disconnect\n");
            break;
          }
          if (strncmp(buffer, "stop", strlen("stop")) == 0)
            shutdown(clifd, SHUT_RD);
          else {
            buffer[n] = '\0';
            printf("%s\n", buffer);
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     129f <main+0x2f>
lea    0xd66(%rip),%rdi
call   10d0 <err_quit@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12d1 <main+0x61>
lea    0xd4f(%rip),%rdi
call   1060 <err_sys@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1170 <atoi@plt>
mov    %eax,%edi
call   10b0 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x30(%rbp),%rdx
add    $0x4,%rdx
call   10f0 <inet_pton@plt>
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1140 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    133c <main+0xcc>
lea    0xcf1(%rip),%rdi
call   1060 <err_sys@plt>
mov    -0x20(%rbp),%edi
mov    $0x2,%esi
call   1120 <listen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1362 <main+0xf2>
lea    0xcd6(%rip),%rdi
call   1060 <err_sys@plt>
jmp    1367 <main+0xf7>
movl   $0xc,-0x64(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdx
call   1160 <accept@plt>
mov    %eax,-0x34(%rbp)
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
add    $0x4,%rsi
lea    -0x50(%rbp),%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    -0x60(%rbp),%edi
call   1130 <ntohs@plt>
mov    -0x478(%rbp),%rsi
mov    %eax,%edx
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
movl   $0x0,-0x6c(%rbp)
lea    -0x68(%rbp),%rdi
call   1100 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x68(%rbp),%rsi
call   1180 <FD_SET@plt>
cmpl   $0x0,-0x6c(%rbp)
jne    13fb <main+0x18b>
mov    -0x34(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   1180 <FD_SET@plt>
mov    -0x34(%rbp),%edi
add    $0x1,%edi
lea    -0x68(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1110 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1433 <main+0x1c3>
lea    0xc34(%rip),%rdi
call   1060 <err_sys@plt>
jmp    1575 <main+0x305>
xor    %edi,%edi
lea    -0x68(%rbp),%rsi
call   1080 <FD_ISSET@plt>
cmp    $0x0,%rax
je     148f <main+0x21f>
lea    -0x470(%rbp),%rdi
mov    $0x400,%esi
call   1150 <bzero@plt>
lea    -0x470(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   10e0 <read@plt>
mov    %eax,-0x70(%rbp)
movslq -0x70(%rbp),%rax
movb   $0x0,-0x470(%rbp,%rax,1)
mov    -0x34(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    $0x400,%edx
call   1070 <write@plt>
mov    -0x34(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   1080 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1570 <main+0x300>
lea    -0x470(%rbp),%rdi
mov    $0x400,%esi
call   1150 <bzero@plt>
mov    -0x34(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
jge    14de <main+0x26e>
jmp    157a <main+0x30a>
cmpl   $0x0,-0x70(%rbp)
jne    14fb <main+0x28b>
lea    0xb7b(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
jmp    157a <main+0x30a>
lea    -0x470(%rbp),%rax
mov    %rax,-0x480(%rbp)
lea    0xb66(%rip),%rdi
call   10a0 <strlen@plt>
mov    -0x480(%rbp),%rdi
mov    %eax,%edx
lea    0xb51(%rip),%rsi
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    154a <main+0x2da>
mov    -0x34(%rbp),%edi
mov    0x2aa2(%rip),%rax
mov    (%rax),%esi
call   1090 <shutdown@plt>
jmp    156b <main+0x2fb>
movslq -0x70(%rbp),%rax
movb   $0x0,-0x470(%rbp,%rax,1)
lea    -0x470(%rbp),%rsi
lea    0xb17(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
jmp    1570 <main+0x300>
jmp    1575 <main+0x305>
jmp    13d1 <main+0x161>
jmp    1367 <main+0xf7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     12a5 <main+0x25>
lea    0xd60(%rip),%rdi
call   10e0 <err_quit@plt>
mov    0x2d3c(%rip),%r14
mov    (%r14),%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11a0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12d1 <main+0x51>
lea    0xd4f(%rip),%rdi
call   1070 <err_sys@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rbx),%rdi
call   1180 <atoi@plt>
mov    %eax,%edi
call   10c0 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%r14),%edi
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdx
call   1100 <inet_pton@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1150 <bind@plt>
test   %eax,%eax
jns    131e <main+0x9e>
lea    0xd0f(%rip),%rdi
call   1070 <err_sys@plt>
mov    %ebp,0x8(%rsp)
mov    %ebp,%edi
mov    $0x2,%esi
call   1130 <listen@plt>
test   %eax,%eax
jns    133e <main+0xbe>
lea    0xcfa(%rip),%rdi
call   1070 <err_sys@plt>
lea    0x2c(%rsp),%r14
lea    0x40(%rsp),%r12
lea    0xd1b(%rip),%r13
jmp    136c <main+0xec>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd08(%rip),%rdi
call   1060 <puts@plt>
movl   $0xc,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1170 <accept@plt>
mov    %eax,%ebp
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
lea    0x24(%rsp),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    0x20(%rsp),%edi
call   1140 <ntohs@plt>
lea    0xc87(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <printf@plt>
mov    %ebp,%ebx
add    $0x1,%ebx
jmp    13dc <main+0x15c>
nopl   0x0(%rax)
lea    0xc86(%rip),%rdi
call   1070 <err_sys@plt>
mov    %r14,%rdi
call   1110 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1190 <FD_SET@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1190 <FD_SET@plt>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1120 <select@plt>
test   %eax,%eax
js     13d0 <main+0x150>
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <FD_ISSET@plt>
test   %rax,%rax
je     144e <main+0x1ce>
mov    %r12,%rdi
mov    $0x400,%esi
call   1160 <bzero@plt>
xor    %edi,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   10f0 <read@plt>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1080 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <FD_ISSET@plt>
test   %rax,%rax
je     13dc <main+0x15c>
mov    %r12,%rdi
mov    $0x400,%esi
call   1160 <bzero@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
js     136c <main+0xec>
je     1360 <main+0xe0>
mov    %eax,%r15d
mov    %r13,%rdi
call   10b0 <strlen@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     14bf <main+0x23f>
mov    %r15d,%eax
movb   $0x0,0x40(%rsp,%rax,1)
mov    %r12,%rdi
call   1060 <puts@plt>
jmp    13dc <main+0x15c>
mov    0x2b1a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   10a0 <shutdown@plt>
jmp    13dc <main+0x15c>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"usage:./tcp_client ip port\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [11 x i8] c"bind error\00"
@.str.3 = [13 x i8] c"listen error\00"
@.str.4 = [29 x i8] c"connect with ip %s port %d\0A\00"
@.str.5 = [13 x i8] c"select error\00"
@.str.6 = [12 x i8] c"disconnect\0A\00"
@.str.7 = [5 x i8] c"stop\00"
@SHUT_RD = global i32 0
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [16 x i8]
%13 = alloca %struct.sockaddr_in
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* @AF_INET
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%45 = call i32 @inet_pton(i32 %40, i8* %43, i32* %44)
%46 = load i32, i32* %9
%47 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%48 = call i32 @bind(i32 %46, %struct.sockaddr* %47, i32 12)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %31
%52 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %51, %31
%54 = load i32, i32* %9
%55 = call i32 @listen(i32 %54, i32 2)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
br label %61
61: ; preds = %140, %60
store i32 12, i32* %14
%62 = load i32, i32* %9
%63 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%64 = call i32 @accept(i32 %62, %struct.sockaddr* %63, i32* %14)
store i32 %64, i32* %11
%65 = load i32, i32* @AF_INET
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%68 = call i32 @inet_ntop(i32 %65, i32* %66, i8* %67, i32 16)
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%71 = load i32, i32* %70
%72 = call i32 @ntohs(i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %69, i32 %72)
store i32 0, i32* %16
br label %74
74: ; preds = %139, %61
%75 = call i32 @FD_ZERO(i32* %15)
%76 = call i32 @FD_SET(i32 0, i32* %15)
%77 = load i32, i32* %16
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = load i32, i32* %11
%81 = call i32 @FD_SET(i32 %80, i32* %15)
br label %82
82: ; preds = %79, %74
%83 = load i32, i32* %11
%84 = add nsw i32 %83, 1
%85 = call i32 @select(i32 %84, i32* %15, i32* null, i32* null, i32* null)
store i32 %85, i32* %8
%86 = load i32, i32* %8
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %139
90: ; preds = %82
%91 = call i64 @FD_ISSET(i32 0, i32* %15)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %104
93: ; preds = %90
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%95 = call i32 @bzero(i8* %94, i32 1024)
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%97 = call i32 @read(i32 0, i8* %96, i32 1024)
store i32 %97, i32* %17
%98 = load i32, i32* %17
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 %99
store i8 0, i8* %100
%101 = load i32, i32* %11
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%103 = call i32 @write(i32 %101, i8* %102, i32 1024)
br label %104
104: ; preds = %93, %90
%105 = load i32, i32* %11
%106 = call i64 @FD_ISSET(i32 %105, i32* %15)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %138
108: ; preds = %104
%109 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%110 = call i32 @bzero(i8* %109, i32 1024)
%111 = load i32, i32* %11
%112 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%113 = call i32 @recv(i32 %111, i8* %112, i32 1024, i32 0)
store i32 %113, i32* %17
%114 = load i32, i32* %17
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %117
116: ; preds = %108
br label %140
117: ; preds = %108
%118 = load i32, i32* %17
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %117
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %140
122: ; preds = %117
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%124 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%125 = call i64 @strncmp(i8* %123, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %124)
%126 = icmp eq i64 %125, 0
br i1 %126, label %127, label %131
127: ; preds = %122
%128 = load i32, i32* %11
%129 = load i32, i32* @SHUT_RD
%130 = call i32 @shutdown(i32 %128, i32 %129)
br label %137
131: ; preds = %122
%132 = load i32, i32* %17
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 %133
store i8 0, i8* %134
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %135)
br label %137
137: ; preds = %131, %127
br label %138
138: ; preds = %137, %104
br label %139
139: ; preds = %138, %88
br label %74
140: ; preds = %120, %116
br label %61
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"usage:./tcp_client ip port\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [11 x i8] c"bind error\00"
@.str.3 = [13 x i8] c"listen error\00"
@.str.4 = [29 x i8] c"connect with ip %s port %d\0A\00"
@.str.5 = [13 x i8] c"select error\00"
@.str.7 = [5 x i8] c"stop\00"
@SHUT_RD = global i32 0
@str = [11 x i8] c"disconnect\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [16 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = icmp eq i32 %0, 3
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = bitcast %struct.sockaddr_in* %3 to i8*
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = tail call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%32 = call i32 @inet_pton(i32 %28, i8* %30, i32* %31)
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i32 @bind(i32 %15, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %19
%37 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %19
%39 = call i32 @listen(i32 %15, i32 2)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%45 = bitcast %struct.sockaddr_in* %5 to i8*
%46 = bitcast i32* %6 to i8*
%47 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%50 = bitcast i32* %7 to i8*
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
br label %52
52: ; preds = %100, %43
store i32 12, i32* %6
%53 = call i32 @accept(i32 %15, %struct.sockaddr* %47, i32* %6)
%54 = load i32, i32* @AF_INET
%55 = call i32 @inet_ntop(i32 %54, i32* %48, i8* %44, i32 16)
%56 = load i32, i32* %49
%57 = call i32 @ntohs(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %44, i32 %57)
%59 = add nsw i32 %53, 1
br label %60
60: ; preds = %99, %52
%61 = call i32 @FD_ZERO(i32* %7)
%62 = call i32 @FD_SET(i32 0, i32* %7)
%63 = call i32 @FD_SET(i32 %53, i32* %7)
%64 = call i32 @select(i32 %59, i32* %7, i32* null, i32* null, i32* null)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %99
68: ; preds = %60
%69 = call i64 @FD_ISSET(i32 0, i32* %7)
%70 = icmp eq i64 %69, 0
br i1 %70, label %77, label %71
71: ; preds = %68
%72 = call i32 @bzero(i8* %51, i32 1024)
%73 = call i32 @read(i32 0, i8* %51, i32 1024)
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %74
store i8 0, i8* %75
%76 = call i32 @write(i32 %53, i8* %51, i32 1024)
br label %77
77: ; preds = %71, %68
%78 = call i64 @FD_ISSET(i32 %53, i32* %7)
%79 = icmp eq i64 %78, 0
br i1 %79, label %99, label %80
80: ; preds = %77
%81 = call i32 @bzero(i8* %51, i32 1024)
%82 = call i32 @recv(i32 %53, i8* %51, i32 1024, i32 0)
%83 = icmp slt i32 %82, 0
br i1 %83, label %100, label %84
84: ; preds = %80
%85 = icmp eq i32 %82, 0
br i1 %85, label %86, label %88
86: ; preds = %84
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %100
88: ; preds = %84
%89 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%90 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %89)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %88
%93 = load i32, i32* @SHUT_RD
%94 = call i32 @shutdown(i32 %53, i32 %93)
br label %99
95: ; preds = %88
%96 = zext i32 %82 to i64
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %96
store i8 0, i8* %97
%98 = call i32 @puts(i8* %51)
br label %99
99: ; preds = %66, %92, %95, %77
br label %60
100: ; preds = %80, %86
br label %52
}