#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__ {
  void *s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
void *AF_INET;
int INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
void *htons(int);
scalar_t__ inet_aton(char *, TYPE_1__ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("usage : ./%s port! \n", argv[0]);
    exit(1);
  }
  struct sockaddr_in client_addr;
  bzero(&client_addr, sizeof(client_addr));
  client_addr.sin_family = AF_INET;
  client_addr.sin_addr.s_addr = htons(INADDR_ANY);
  client_addr.sin_port = htons(0);
  int client_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (client_socket < 0) {
    printf("create socket failed!\n");
    exit(1);
  }
  if (bind(client_socket, (struct sockaddr *)&client_addr,
           sizeof(client_addr))) {
    printf("Client bind port failed! \n");
    exit(1);
  }
  struct sockaddr_in server_addr;
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  if (inet_aton(argv[1], &server_addr.sin_addr) == 0) {
    printf("Server Ip address Error!\n");
    exit(1);
  }
  server_addr.sin_port = htons(6666);
  socklen_t server_addr_length = sizeof(server_addr);
  if (connect(client_socket, (struct sockaddr *)&server_addr,
              server_addr_length) < 0) {
    printf("connect failed! \n");
    exit(1);
  }
  while (1) {
    send(client_socket, "hello", 5, 0);
    sleep(10);
  }
  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)
cmpl   $0x2,-0x8(%rbp)
je     11df <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0x18,%esi
call   1080 <bzero@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1257 <main+0xb7>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
je     128a <main+0xea>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x48(%rbp),%rdi
mov    $0x18,%esi
call   1080 <bzero@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x48(%rbp),%rsi
add    $0x8,%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
jne    12dd <main+0x13d>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x1a0a,%edi
call   1030 <htons@plt>
mov    %rax,-0x48(%rbp)
movl   $0x18,-0x4c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1323 <main+0x183>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1328 <main+0x188>
mov    -0x2c(%rbp),%edi
lea    0xd41(%rip),%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    $0xa,%edi
call   10b0 <sleep@plt>
jmp    1328 <main+0x188>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12ad <main+0xfd>
lea    0x18(%rsp),%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2e0e(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x28(%rsp)
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %rax,0x20(%rsp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %rax,0x18(%rsp)
mov    (%rbx),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12c8 <main+0x118>
mov    %eax,%ebp
lea    0x18(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1080 <bind@plt>
test   %rax,%rax
jne    12d1 <main+0x121>
mov    %rsp,%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    (%rbx),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%rsi
call   1070 <inet_aton@plt>
test   %rax,%rax
je     12da <main+0x12a>
mov    $0x1a0a,%edi
call   1040 <htons@plt>
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     12e3 <main+0x133>
lea    0xd8c(%rip),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
jmp    1290 <main+0xe0>
mov    (%r14),%rsi
lea    0xd49(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd90(%rip),%rdi
jmp    12ea <main+0x13a>
lea    0xd6d(%rip),%rdi
jmp    12ea <main+0x13a>
lea    0xd4b(%rip),%rdi
jmp    12ea <main+0x13a>
lea    0xd31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"usage : ./%s port! \0A\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"create socket failed!\0A\00"
@.str.2 = [27 x i8] c"Client bind port failed! \0A\00"
@.str.3 = [26 x i8] c"Server Ip address Error!\0A\00"
@.str.4 = [18 x i8] c"connect failed! \0A\00"
@.str.5 = [6 x i8] c"hello\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 %struct.sockaddr_in
%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, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 @bzero(%struct.sockaddr_in* %6, i32 24)
%20 = load i8*, i8** @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %20, i8** %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i8* @htons(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i8* %23, i8** %25
%26 = call i8* @htons(i32 0)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i8* %26, i8** %27
%28 = load i8*, i8** @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i8* %28, i32 %29, i32 0)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %18
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %18
%37 = load i32, i32* %7
%38 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%39 = call i64 @bind(i32 %37, %struct.sockaddr* %38, i32 24)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %36
%45 = call i32 @bzero(%struct.sockaddr_in* %8, i32 24)
%46 = load i8*, i8** @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i8* %46, i8** %47
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%52 = call i64 @inet_aton(i8* %50, %struct.TYPE_2__* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %44
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %44
%58 = call i8* @htons(i32 6666)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i8* %58, i8** %59
store i32 24, i32* %9
%60 = load i32, i32* %7
%61 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%62 = load i32, i32* %9
%63 = call i64 @connect(i32 %60, %struct.sockaddr* %61, i32 %62)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %57
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %57
br label %69
69: ; preds = %68, %69
%70 = load i32, i32* %7
%71 = call i32 @send(i32 %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5, i32 0)
%72 = call i32 @sleep(i32 10)
br label %69
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"usage : ./%s port! \0A\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [6 x i8] c"hello\00"
@str = [17 x i8] c"connect failed! \00"
@str.6 = [25 x i8] c"Server Ip address Error!\00"
@str.7 = [26 x i8] c"Client bind port failed! \00"
@str.8 = [22 x i8] c"create socket failed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = icmp eq i32 %0, 2
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 ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = call i32 @bzero(%struct.sockaddr_in* %3, i32 24)
%13 = load i8*, i8** @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %13, i8** %14
%15 = load i32, i32* @INADDR_ANY
%16 = tail call i8* @htons(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i8* %16, i8** %17
%18 = tail call i8* @htons(i32 0)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %18, i8** %19
%20 = load i8*, i8** @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i8* %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %10
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %10
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @bind(i32 %22, %struct.sockaddr* %28, i32 24)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = bitcast %struct.sockaddr_in* %4 to i8*
%36 = call i32 @bzero(%struct.sockaddr_in* %4, i32 24)
%37 = load i8*, i8** @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %37, i8** %38
%39 = getelementptr inbounds i8*, i8** %1, i64 1
%40 = load i8*, i8** %39
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%42 = call i64 @inet_aton(i8* %40, %struct.TYPE_2__* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %34
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %34
%48 = call i8* @htons(i32 6666)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %48, i8** %49
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = call i64 @connect(i32 %22, %struct.sockaddr* %50, i32 24)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %47, %56
%57 = call i32 @send(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5, i32 0)
%58 = call i32 @sleep(i32 10)
br label %56
}