#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 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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("Usage: %s serverIP serverPort", argv[0]);
    exit(1);
  }
  int sockfd;
  char server_addr_a[4];
  long addr_len;
  char buffer[128];
  struct sockaddr_in server_addr;
  if (-1 == (sockfd = socket(AF_INET, SOCK_STREAM, 0))) {
    printf("Create socket fail!\n");
    exit(1);
  }
  bzero(&server_addr, sizeof(struct sockaddr_in));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(atoi(argv[2]));
  server_addr.sin_addr.s_addr = inet_addr(argv[1]);
  if (-1 == (connect(sockfd, (struct sockaddr *)(&server_addr),
                     sizeof(struct sockaddr)))) {
    printf("Create connect fail!\n");
    exit(1);
  } else
    printf("Create connect with %s successful!\n", argv[1]);
  while (1) {
    printf("Please input something, input \"quit\" for close the client, "
           "\"end\" for exit for server:\n");
    fgets(buffer, 128, stdin);
    if (-1 == send(sockfd, buffer, strlen(buffer), 0)) {
      printf("Send message fail!\n");
      exit(1);
    } else
      printf("The message had been sended!\n");
    if (0 == strncmp(buffer, "quit", 4)) {
      printf("Client will be close!\n");
      break;
    }
    if (0 == strncmp(buffer, "end", 3)) {
      printf("Server and Client will be close!\n");
      break;
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1212 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1255 <main+0x85>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0xb0(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0xac(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0xb0(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12dd <main+0x10d>
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12f8 <main+0x128>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2ccc(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1090 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1380 <main+0x1b0>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xd5a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    13c7 <main+0x1f7>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1405 <main+0x235>
lea    -0xa0(%rbp),%rdi
lea    0xd26(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1400 <main+0x230>
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1405 <main+0x235>
jmp    12f8 <main+0x128>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    135f <main+0x17f>
mov    0x2de4(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     137a <main+0x19a>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
je     1383 <main+0x1a3>
mov    0x8(%r14),%rsi
lea    0xda4(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d58(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe0d(%rip),%r12
lea    0xda7(%rip),%r13
lea    0xda5(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd94(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   10a0 <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     1349 <main+0x169>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1322 <main+0x142>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    12b0 <main+0xd0>
lea    0xd9e(%rip),%rdi
jmp    1329 <main+0x149>
lea    0xda0(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    (%r14),%rsi
lea    0xc97(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd86(%rip),%rdi
jmp    1350 <main+0x170>
lea    0xd68(%rip),%rdi
jmp    1350 <main+0x170>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [30 x i8] c"Usage: %s serverIP serverPort\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"Create socket fail!\0A\00"
@.str.2 = [22 x i8] c"Create connect fail!\0A\00"
@.str.3 = [36 x i8] c"Create connect with %s successful!\0A\00"
@.str.4 = [87 x i8] c"Please input something, input \22quit\22 for close the client, \22end\22 for exit for server:\0A\00"
@stdin = global i32 0
@.str.5 = [20 x i8] c"Send message fail!\0A\00"
@.str.6 = [30 x i8] c"The message had been sended!\0A\00"
@.str.7 = [5 x i8] c"quit\00"
@.str.8 = [23 x i8] c"Client will be close!\0A\00"
@.str.9 = [4 x i8] c"end\00"
@.str.10 = [34 x i8] c"Server and Client will be close!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4 x i8]
%8 = alloca i64
%9 = alloca [128 x i8]
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp eq i32 -1, %22
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = call i32 @bzero(%struct.sockaddr_in* %10, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = call i32 @htons(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @inet_addr(i8* %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = load i32, i32* %6
%44 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%45 = call i32 @connect(i32 %43, %struct.sockaddr* %44, i32 4)
%46 = icmp eq i32 -1, %45
br i1 %46, label %47, label %50
47: ; preds = %27
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %27
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %50
br label %56
56: ; preds = %55, %84
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.4, i64 0, i64 0))
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%59 = load i32, i32* @stdin
%60 = call i32 @fgets(i8* %58, i32 128, i32 %59)
%61 = load i32, i32* %6
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = call i32 @send(i32 %61, i8* %62, i32 %64, i32 0)
%66 = icmp eq i32 -1, %65
br i1 %66, label %67, label %70
67: ; preds = %56
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %56
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %70
%73 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%74 = call i64 @strncmp(i8* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 4)
%75 = icmp eq i64 0, %74
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %85
78: ; preds = %72
%79 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%80 = call i64 @strncmp(i8* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%81 = icmp eq i64 0, %80
br i1 %81, label %82, label %84
82: ; preds = %78
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
br label %85
84: ; preds = %78
br label %56
85: ; preds = %82, %76
%86 = load i32, i32* %6
%87 = call i32 @close(i32 %86)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [30 x i8] c"Usage: %s serverIP serverPort\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [36 x i8] c"Create connect with %s successful!\0A\00"
@stdin = global i32 0
@.str.7 = [5 x i8] c"quit\00"
@.str.9 = [4 x i8] c"end\00"
@str = [86 x i8] c"Please input something, input \22quit\22 for close the client, \22end\22 for exit for server:\00"
@str.11 = [29 x i8] c"The message had been sended!\00"
@str.12 = [33 x i8] c"Server and Client will be close!\00"
@str.13 = [22 x i8] c"Client will be close!\00"
@str.14 = [19 x i8] c"Send message fail!\00"
@str.15 = [21 x i8] c"Create connect fail!\00"
@str.16 = [20 x i8] c"Create socket fail!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca %struct.sockaddr_in
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = bitcast %struct.sockaddr_in* %4 to i8*
%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 eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = tail call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 @inet_addr(i8* %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @connect(i32 %15, %struct.sockaddr* %33, i32 4)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %20
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.15, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %20
%40 = load i8*, i8** %29
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %56, %39
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @str, i64 0, i64 0))
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %11, i32 128, i32 %44)
%46 = call i32 @strlen(i8* %11)
%47 = call i32 @send(i32 %15, i8* %11, i32 %46, i32 0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.11, i64 0, i64 0))
%54 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 4)
%55 = icmp eq i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %52
%57 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %42
59: ; preds = %56, %52
%60 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.13, i64 0, i64 0), %52 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.12, i64 0, i64 0), %56 ]
%61 = call i32 @puts(i8* dereferenceable(1) %60)
%62 = call i32 @close(i32 %15)
ret i32 0
}