#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
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 /*<<< 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*/);
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);
  }
  while (1) {
    memset(buf, 0, 1024 + 1);
    printf("You would say :");
    fgets(buf, sizeof(buf), stdin);
    n = send(connfd, buf, strlen(buf), 0);
    if (n == -1) {
      perror("Send to Server");
      exit(1);
    }
    if (strcmp(buf, "exit\n") == 0) {
      break;
    }
    n = recv(connfd, buf, 1024, 0);
    if (n == -1) {
      perror("Receive from Server");
      exit(1);
    } else {
      buf[n] = '\0';
      printf("Server send to you: %s\n", buf);
    }
  }
  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     1249 <main+0x39>
lea    0xdc6(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <inet_aton@plt>
cmp    $0x0,%rax
jne    12c7 <main+0xb7>
lea    0xd5b(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jge    12f8 <main+0xe8>
lea    0xd35(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    12fd <main+0xed>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1090 <memset@plt>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x430(%rbp),%rdi
mov    0x2cb4(%rip),%rax
mov    (%rax),%edx
mov    $0x401,%esi
call   10b0 <fgets@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0xffffffff,-0x434(%rbp)
jne    139a <main+0x18a>
lea    0xcae(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x430(%rbp),%rdi
lea    0xca0(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    13bc <main+0x1ac>
jmp    1424 <main+0x214>
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0xffffffff,-0x434(%rbp)
jne    13fb <main+0x1eb>
lea    0xc62(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movslq -0x434(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    12fd <main+0xed>
mov    -0x24(%rbp),%edi
call   10a0 <close@plt>
cmp    $0xffffffff,%eax
jne    144b <main+0x23b>
lea    0xc3e(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc2e(%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    139f <main+0x18f>
mov    %rsi,%rbx
mov    0x2db4(%rip),%r15
mov    (%r15),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   10d0 <inet_aton@plt>
test   %rax,%rax
je     13a8 <main+0x198>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %rax,%rax
js     13b1 <main+0x1a1>
lea    0x10(%rsp),%rbx
lea    0xd7c(%rip),%r14
mov    0x2d2c(%rip),%r13
lea    0xd8d(%rip),%r15
lea    0xda0(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1090 <memset@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x401,%esi
call   10b0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     1380 <main+0x170>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1354 <main+0x144>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1389 <main+0x179>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12d0 <main+0xc0>
mov    %ebp,%edi
call   10a0 <close@plt>
cmp    $0xffffffff,%eax
je     13ba <main+0x1aa>
lea    0xd19(%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    0xcb2(%rip),%rdi
jmp    1390 <main+0x180>
lea    0xcbe(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc5a(%rip),%rdi
jmp    1390 <main+0x180>
lea    0xc64(%rip),%rdi
jmp    1390 <main+0x180>
lea    0xc66(%rip),%rdi
jmp    1390 <main+0x180>
lea    0xcb9(%rip),%rdi
jmp    1390 <main+0x180>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 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 = [16 x i8] c"You would say :\00"
@stdin = global i32 0
@.str.4 = [15 x i8] c"Send to Server\00"
@.str.5 = [6 x i8] c"exit\0A\00"
@.str.6 = [20 x i8] c"Receive from Server\00"
@.str.7 = [24 x i8] c"Server send to you: %s\0A\00"
@.str.8 = [6 x i8] c"Close\00"
@.str.9 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %7
%19 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %20, i32* %21
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%32 = call i64 @inet_aton(i8* %30, i32* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %15
%35 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %15
%38 = load i32, i32* %7
%39 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%40 = call i64 @connect(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %37
br label %46
46: ; preds = %45, %83
%47 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%48 = call i32 @memset(i8* %47, i32 0, i32 1025)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%50 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %50, i32 1025, i32 %51)
%53 = load i32, i32* %7
%54 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%55 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @send(i32 %53, i8* %54, i32 %56, i32 0)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %46
%61 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %46
%64 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %63
br label %84
68: ; preds = %63
%69 = load i32, i32* %7
%70 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%71 = call i32 @recv(i32 %69, i8* %70, i32 1024, i32 0)
store i32 %71, i32* %9
%72 = load i32, i32* %9
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %77
74: ; preds = %68
%75 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %68
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 %79
store i8 0, i8* %80
%81 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %77
br label %46
84: ; preds = %67
%85 = load i32, i32* %7
%86 = call i32 @close(i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %84
%92 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 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 = [16 x i8] c"You would say :\00"
@stdin = global i32 0
@.str.4 = [15 x i8] c"Send to Server\00"
@.str.5 = [6 x i8] c"exit\0A\00"
@.str.6 = [20 x i8] c"Receive from Server\00"
@.str.7 = [24 x i8] c"Server send to you: %s\0A\00"
@.str.8 = [6 x i8] c"Close\00"
@.str.9 = [27 x i8] c"TCP Client has been closed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1025 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%26 = call i64 @inet_aton(i8* %24, i32* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %11
%29 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %11
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i64 @connect(i32 %14, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31, %58
%39 = call i32 @memset(i8* %6, i32 0, i32 1025)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %6, i32 1025, i32 %41)
%43 = call i32 @strlen(i8* %6)
%44 = call i32 @send(i32 %14, i8* %6, i32 %43, i32 0)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %62, label %52
52: ; preds = %49
%53 = call i32 @recv(i32 %14, i8* %6, i32 1024, i32 0)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %52
%59 = sext i32 %53 to i64
%60 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 %59
store i8 0, i8* %60
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %6)
br label %38
62: ; preds = %49
%63 = call i32 @close(i32 %14)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %62
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}