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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char *argv[]) {
  char *SERVER_IP = "127.0.0.1";
  int SERVER_PORT = 6666;
  if (argc > 3)
    printf("param err:\nUsage: %s ip port | %s port | %s\n", argv[0], argv[0],
           argv[0]);
  else if (argc == 3) {
    SERVER_IP = argv[1];
    SERVER_PORT = atoi(argv[2]);
  } else if (argc == 2)
    SERVER_PORT = atoi(argv[1]);
  struct sockaddr_in servAddr;
  int cliSocket;
  char *sendbuf = "Hello Server, I am Client.";
  if ((cliSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("socket err");
    exit(1);
  }
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(SERVER_PORT);
  inet_aton(SERVER_IP, &servAddr.sin_addr);
  if (connect(cliSocket, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) {
    printf("connect err");
    exit(1);
  }
  printf("Connect with destination host %s:%d ...\n\n", SERVER_IP, SERVER_PORT);
  while (1) {
    int num = send(cliSocket, sendbuf, strlen(sendbuf) + 1, 0);
    if (num == strlen(sendbuf) + 1)
      printf("Send: Hello Server, I am Client.\nlength:%d\n\n", num);
    else
      printf("send err\n");
    sleep(1);
  }
  close(cliSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1a0a,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    11fa <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1249 <main+0xa9>
cmpl   $0x3,-0x8(%rbp)
jne    1225 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1244 <main+0xa4>
cmpl   $0x2,-0x8(%rbp)
jne    123f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1244 <main+0xa4>
jmp    1249 <main+0xa9>
lea    0xde7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1291 <main+0xf1>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <inet_aton@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    12e8 <main+0x148>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jne    135f <main+0x1bf>
mov    -0x3c(%rbp),%esi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    136d <main+0x1cd>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    12fd <main+0x15d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x4,%edi
jl     11e6 <main+0x36>
mov    (%rsi),%rcx
lea    0xe3f(%rip),%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe21(%rip),%r14
mov    $0x1a0a,%ebp
jmp    1211 <main+0x61>
lea    0xe13(%rip),%r14
cmp    $0x2,%edi
je     1206 <main+0x56>
mov    $0x1a0a,%ebp
cmp    $0x3,%edi
jne    1211 <main+0x61>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
jmp    120a <main+0x5a>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x2dd0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12e9 <main+0x139>
mov    %eax,%r12d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <inet_aton@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     12f2 <main+0x142>
lea    0xdf5(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdb0(%rip),%rbp
lea    0xe05(%rip),%r14
lea    0xe2b(%rip),%r15
jmp    12b2 <main+0x102>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    %eax,%ebx
jne    12a0 <main+0xf0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12a8 <main+0xf8>
lea    0xd62(%rip),%rdi
jmp    12f9 <main+0x149>
lea    0xd64(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [45 x i8] c"param err:\0AUsage: %s ip port | %s port | %s\0A\00"
@.str.2 = [27 x i8] c"Hello Server, I am Client.\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [11 x i8] c"socket err\00"
@.str.4 = [12 x i8] c"connect err\00"
@.str.5 = [42 x i8] c"Connect with destination host %s:%d ...\0A\0A\00"
@.str.6 = [45 x i8] c"Send: Hello Server, I am Client.\0Alength:%d\0A\0A\00"
@.str.7 = [10 x i8] c"send err\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 6666, i32* %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %20, i8* %23)
br label %46
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %6
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %7
br label %45
36: ; preds = %25
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %39, %36
br label %45
45: ; preds = %44, %28
br label %46
46: ; preds = %45, %14
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8** %10
%47 = load i32, i32* @AF_INET
%48 = load i32, i32* @SOCK_STREAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
store i32 %49, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = load i32, i32* @AF_INET
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %55, i32* %56
%57 = load i32, i32* %7
%58 = call i32 @htons(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %58, i32* %59
%60 = load i8*, i8** %6
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%62 = call i32 @inet_aton(i8* %60, i32* %61)
%63 = load i32, i32* %9
%64 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%65 = call i64 @connect(i32 %63, %struct.sockaddr* %64, i32 12)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %54
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %54
%71 = load i8*, i8** %6
%72 = load i32, i32* %7
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %71, i32 %72)
br label %74
74: ; preds = %70, %91
%75 = load i32, i32* %9
%76 = load i8*, i8** %10
%77 = load i8*, i8** %10
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 %78, 1
%80 = call i32 @send(i32 %75, i8* %76, i32 %79, i32 0)
store i32 %80, i32* %11
%81 = load i32, i32* %11
%82 = load i8*, i8** %10
%83 = call i32 @strlen(i8* %82)
%84 = add nsw i32 %83, 1
%85 = icmp eq i32 %81, %84
br i1 %85, label %86, label %89
86: ; preds = %74
%87 = load i32, i32* %11
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %87)
br label %91
89: ; preds = %74
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %91
91: ; preds = %89, %86
%92 = call i32 @sleep(i32 1)
br label %74
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [45 x i8] c"param err:\0AUsage: %s ip port | %s port | %s\0A\00"
@.str.2 = [27 x i8] c"Hello Server, I am Client.\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [11 x i8] c"socket err\00"
@.str.4 = [12 x i8] c"connect err\00"
@.str.5 = [42 x i8] c"Connect with destination host %s:%d ...\0A\0A\00"
@.str.6 = [45 x i8] c"Send: Hello Server, I am Client.\0Alength:%d\0A\0A\00"
@str = [9 x i8] c"send err\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = icmp sgt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %6, i8* %6)
br label %19
8: ; preds = %2
switch i32 %0, label %19 [
i32 3, label %9
i32 2, label %15
]
9: ; preds = %8
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
br label %19
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %8, %9, %15, %5
%20 = phi i32 [ 6666, %5 ], [ %14, %9 ], [ %18, %15 ], [ 6666, %8 ]
%21 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %5 ], [ %11, %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %8 ]
%22 = bitcast %struct.sockaddr_in* %3 to i8*
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = tail call i32 @htons(i32 %20)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%36 = call i32 @inet_aton(i8* %21, i32* %35)
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i64 @connect(i32 %25, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %30
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %21, i32 %20)
br label %45
45: ; preds = %56, %43
%46 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%47 = add nsw i32 %46, 1
%48 = call i32 @send(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 0)
%49 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%50 = add nsw i32 %49, 1
%51 = icmp eq i32 %48, %50
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %48)
br label %56
54: ; preds = %45
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
%57 = call i32 @sleep(i32 1)
br label %45
}