#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buf;

/* 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*/ atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int fileno(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  struct sockaddr_in server_addr;
  int connfd;
  char buf[1024 + 1];
  int n;
  if (argc != 3) {
    perror("Please use 3 args**\n");
    exit(1);
  }
  connfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(atoi(argv[2]));
  if (inet_aton(argv[1], &server_addr.sin_addr) == 0) {
    perror("inet_aton.");
    exit(1);
  }
  if (connect(connfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    perror("Connecting");
    exit(1);
  }
  fd_set sets;
  int maxfd = connfd;
  printf("@Please enter your message:\n");
  while (1) {
    FD_ZERO(&sets);
    FD_SET(fileno(stdin), &sets);
    FD_SET(connfd, &sets);
    memset(buf, 0, 1024 + 1);
    if (select(maxfd + 1, &sets, NULL, NULL, NULL) < 0) {
      perror("Select Error.\n");
      continue;
    }
    if (FD_ISSET(connfd, &sets)) {
      n = recv(connfd, buf, 1024, 0);
      if (n == 0) {
        perror("***Server closed.\n");
        exit(1);
      }
      if (n == -1) {
        perror("Receive from Server");
        exit(1);
      } else {
        buf[n] = '\0';
        printf("@[Server] send back to you:\n%s", buf);
      }
    }
    if (FD_ISSET(fileno(stdin), &sets)) {
      if (fgets(buf, sizeof(buf), stdin) == NULL) {
        continue;
      }
      n = send(connfd, buf, strlen(buf), 0);
      if (n == -1) {
        perror("Send to Server");
        exit(1);
      }
      if (strcmp(buf, "exit\n") == 0) {
        break;
      }
    }
  }
  if (close(connfd) == -1) {
    perror("Close");
    exit(1);
  }
  puts("TCP Client has been closed");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1299 <main+0x39>
lea    0xd76(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1110 <inet_aton@plt>
cmp    $0x0,%rax
jne    1317 <main+0xb7>
lea    0xd0d(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
cmp    $0x0,%rax
jge    1348 <main+0xe8>
lea    0xce7(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x438(%rbp),%rdi
call   10f0 <FD_ZERO@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   10e0 <fileno@plt>
mov    %eax,%edi
lea    -0x438(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x24(%rbp),%edi
lea    -0x438(%rbp),%rsi
call   1170 <FD_SET@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   10a0 <memset@plt>
mov    -0x43c(%rbp),%edi
add    $0x1,%edi
lea    -0x438(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1100 <select@plt>
cmp    $0x0,%rax
jge    13e4 <main+0x184>
lea    0xc6e(%rip),%rdi
call   1120 <perror@plt>
jmp    135f <main+0xff>
mov    -0x24(%rbp),%edi
lea    -0x438(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1488 <main+0x228>
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jne    143c <main+0x1dc>
lea    0xc2a(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
cmpl   $0xffffffff,-0x434(%rbp)
jne    145f <main+0x1ff>
lea    0xc1a(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movslq -0x434(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1488 <main+0x228>
mov    0x2b51(%rip),%rax
mov    (%rax),%edi
call   10e0 <fileno@plt>
mov    %eax,%edi
lea    -0x438(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1560 <main+0x300>
lea    -0x430(%rbp),%rdi
mov    0x2b24(%rip),%rax
mov    (%rax),%edx
mov    $0x401,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
jne    14d7 <main+0x277>
jmp    135f <main+0xff>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x430(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0xffffffff,-0x434(%rbp)
jne    1539 <main+0x2d9>
lea    0xb73(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    -0x430(%rbp),%rdi
lea    0xb65(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    155b <main+0x2fb>
jmp    1565 <main+0x305>
jmp    1560 <main+0x300>
jmp    135f <main+0xff>
mov    -0x24(%rbp),%edi
call   10b0 <close@plt>
cmp    $0xffffffff,%eax
jne    158c <main+0x32c>
lea    0xb35(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    0xb25(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x3,%edi
jne    147d <main+0x21d>
mov    %rsi,%rbp
mov    0x2d64(%rip),%r15
mov    (%r15),%edi
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rbp),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbp),%rdi
mov    %r14,%rsi
call   1110 <inet_aton@plt>
test   %rax,%rax
je     1486 <main+0x226>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1160 <connect@plt>
test   %rax,%rax
js     148f <main+0x22f>
lea    0xdbe(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%r14d
add    $0x1,%r14d
lea    0xc(%rsp),%rbp
mov    0x2cd0(%rip),%r13
lea    0x10(%rsp),%r15
lea    0xd45(%rip),%r12
jmp    1330 <main+0xd0>
lea    0xd06(%rip),%rdi
call   1120 <perror@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10f0 <FD_ZERO@plt>
mov    0x0(%r13),%edi
call   10e0 <fileno@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1170 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1170 <FD_SET@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   10a0 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1100 <select@plt>
test   %rax,%rax
js     131e <main+0xbe>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13c0 <main+0x160>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1455 <main+0x1f5>
test   %eax,%eax
je     145e <main+0x1fe>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x0(%r13),%edi
call   10e0 <fileno@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1330 <main+0xd0>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    $0x401,%esi
call   10c0 <fgets@plt>
test   %rax,%rax
je     1330 <main+0xd0>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
je     1467 <main+0x207>
mov    %r15,%rdi
lea    0xc74(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1330 <main+0xd0>
mov    %ebx,%edi
call   10b0 <close@plt>
cmp    $0xffffffff,%eax
je     1498 <main+0x238>
lea    0xc5f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbf1(%rip),%rdi
jmp    146e <main+0x20e>
lea    0xbd5(%rip),%rdi
jmp    146e <main+0x20e>
lea    0xc12(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    0xb7c(%rip),%rdi
jmp    146e <main+0x20e>
lea    0xb88(%rip),%rdi
jmp    146e <main+0x20e>
lea    0xb8a(%rip),%rdi
jmp    146e <main+0x20e>
lea    0xbf6(%rip),%rdi
jmp    146e <main+0x20e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Please use 3 args**\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [11 x i8] c"inet_aton.\00"
@.str.2 = [11 x i8] c"Connecting\00"
@.str.3 = [29 x i8] c"@Please enter your message:\0A\00"
@stdin = global i32 0
@.str.4 = [15 x i8] c"Select Error.\0A\00"
@.str.5 = [19 x i8] c"***Server closed.\0A\00"
@.str.6 = [20 x i8] c"Receive from Server\00"
@.str.7 = [31 x i8] c"@[Server] send back to you:\0A%s\00"
@.str.8 = [15 x i8] c"Send to Server\00"
@.str.9 = [6 x i8] c"exit\0A\00"
@.str.10 = [6 x i8] c"Close\00"
@.str.11 = [27 x i8] c"TCP Client has been closed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [1025 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %7
%21 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %28, i32* %29
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%34 = call i64 @inet_aton(i8* %32, i32* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %17
%37 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %17
%40 = load i32, i32* %7
%41 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%42 = call i64 @connect(i32 %40, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
%48 = load i32, i32* %7
store i32 %48, i32* %11
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %47, %63, %101, %119
%51 = call i32 @FD_ZERO(i32* %10)
%52 = load i32, i32* @stdin
%53 = call i32 @fileno(i32 %52)
%54 = call i32 @FD_SET(i32 %53, i32* %10)
%55 = load i32, i32* %7
%56 = call i32 @FD_SET(i32 %55, i32* %10)
%57 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%58 = call i32 @memset(i8* %57, i32 0, i32 1025)
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
%61 = call i64 @select(i32 %60, i32* %10, i32* null, i32* null, i32* null)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %50
%64 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %50
65: ; preds = %50
%66 = load i32, i32* %7
%67 = call i64 @FD_ISSET(i32 %66, i32* %10)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %91
69: ; preds = %65
%70 = load i32, i32* %7
%71 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%72 = call i32 @recv(i32 %70, i8* %71, i32 1024, i32 0)
store i32 %72, i32* %9
%73 = load i32, i32* %9
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %69
%79 = load i32, i32* %9
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %78
%85 = load i32, i32* %9
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 %86
store i8 0, i8* %87
%88 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %84
br label %91
91: ; preds = %90, %65
%92 = load i32, i32* @stdin
%93 = call i32 @fileno(i32 %92)
%94 = call i64 @FD_ISSET(i32 %93, i32* %10)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %119
96: ; preds = %91
%97 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%98 = load i32, i32* @stdin
%99 = call i32* @fgets(i8* %97, i32 1025, i32 %98)
%100 = icmp eq i32* %99, null
br i1 %100, label %101, label %102
101: ; preds = %96
br label %50
102: ; preds = %96
%103 = load i32, i32* %7
%104 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%105 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%106 = call i32 @strlen(i8* %105)
%107 = call i32 @send(i32 %103, i8* %104, i32 %106, i32 0)
store i32 %107, i32* %9
%108 = load i32, i32* %9
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %102
%111 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %102
%114 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%115 = call i64 @strcmp(i8* %114, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %113
br label %120
118: ; preds = %113
br label %119
119: ; preds = %118, %91
br label %50
120: ; preds = %117
%121 = load i32, i32* %7
%122 = call i32 @close(i32 %121)
%123 = icmp eq i32 %122, -1
br i1 %123, label %124, label %127
124: ; preds = %120
%125 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%126 = call i32 @exit(i32 1)
unreachable
127: ; preds = %120
%128 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Please use 3 args**\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [11 x i8] c"inet_aton.\00"
@.str.2 = [11 x i8] c"Connecting\00"
@stdin = global i32 0
@.str.4 = [15 x i8] c"Select Error.\0A\00"
@.str.5 = [19 x i8] c"***Server closed.\0A\00"
@.str.6 = [20 x i8] c"Receive from Server\00"
@.str.7 = [31 x i8] c"@[Server] send back to you:\0A%s\00"
@.str.8 = [15 x i8] c"Send to Server\00"
@.str.9 = [6 x i8] c"exit\0A\00"
@.str.10 = [6 x i8] c"Close\00"
@.str.11 = [27 x i8] c"TCP Client has been closed\00"
@str = [28 x i8] c"@Please enter your message:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1025 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%8 = icmp eq i32 %0, 3
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %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 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%27 = call i64 @inet_aton(i8* %25, i32* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %12
%30 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %12
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i64 @connect(i32 %15, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
%40 = bitcast i32* %5 to i8*
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%42 = add nsw i32 %15, 1
br label %43
43: ; preds = %74, %39
%44 = call i32 @FD_ZERO(i32* %5)
%45 = load i32, i32* @stdin
%46 = call i32 @fileno(i32 %45)
%47 = call i32 @FD_SET(i32 %46, i32* %5)
%48 = call i32 @FD_SET(i32 %15, i32* %5)
%49 = call i32 @memset(i8* %7, i32 0, i32 1025)
%50 = call i64 @select(i32 %42, i32* %5, i32* null, i32* null, i32* null)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %43
%53 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %74
54: ; preds = %43
%55 = call i64 @FD_ISSET(i32 %15, i32* %5)
%56 = icmp eq i64 %55, 0
br i1 %56, label %69, label %57
57: ; preds = %54
%58 = call i32 @recv(i32 %15, i8* %7, i32 1024, i32 0)
switch i32 %58, label %65 [
i32 0, label %59
i32 -1, label %62
]
59: ; preds = %57
%60 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %57
%66 = sext i32 %58 to i64
%67 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 %66
store i8 0, i8* %67
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %7)
br label %69
69: ; preds = %65, %54
%70 = load i32, i32* @stdin
%71 = call i32 @fileno(i32 %70)
%72 = call i64 @FD_ISSET(i32 %71, i32* %5)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %69, %86, %52, %75
br label %43
75: ; preds = %69
%76 = load i32, i32* @stdin
%77 = call i32* @fgets(i8* %7, i32 1025, i32 %76)
%78 = icmp eq i32* %77, null
br i1 %78, label %74, label %79
79: ; preds = %75
%80 = call i32 @strlen(i8* %7)
%81 = call i32 @send(i32 %15, i8* %7, i32 %80, i32 0)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %86
83: ; preds = %79
%84 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %79
%87 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %74
89: ; preds = %86
%90 = call i32 @close(i32 %15)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %89
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}