#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_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ in_addr;
typedef int /*<<< orphan*/ b;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int s;
  struct sockaddr_in in_addr;
  int Sport = 2222;
  char addr[16] = "10.0.2.18";
  char *Data = "hi hi";
  printf("start the client  \n");
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    printf("ERROR: Could not create socket!\n");
    return -1;
  }
  printf("Bind socket to %d\n", Sport);
  in_addr.sin_port = htons(Sport);
  in_addr.sin_family = AF_INET;
  in_addr.sin_addr.s_addr = inet_addr(addr);
  if (connect(s, (struct sockaddr *)&in_addr, sizeof(in_addr)) == -1) {
    printf("ERROR: Could not connect to the server !\n");
    close(s);
    return -1;
  }
  printf("connect >>>>>>>>>>>>>>>\n");
  printf("write to the server : %s\n", Data);
  char *b = Data;
  int sval = 0;
  while (*b) {
    sval = send(s, b, sizeof(b), 0);
    b += sval;
  }
  free(Data);
  free(b);
  printf("send %d", sval);
  if (sval < 0)
    printf("ERROR: Could not write to the server !\n");
  close(s);
  printf("Done");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x8ae,-0x1c(%rbp)
mov    0xe63(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe60(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1205 <main+0x85>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x1b5>
mov    -0x1c(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    1275 <main+0xf5>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x1b5>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
je     12dd <main+0x15d>
mov    -0x8(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    12a4 <main+0x124>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%esi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x44(%rbp)
jge    1318 <main+0x198>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e2d(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     12c4 <main+0x134>
mov    %eax,%r15d
lea    0xe36(%rip),%rdi
mov    $0x8ae,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x8ae,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
lea    0x10(%rsp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     12d2 <main+0x142>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf0(%rip),%rdi
lea    0xdd0(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rbx
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,%r12d
cltq
add    %rax,%rbp
cmpb   $0x0,(%rbx,%rax,1)
jne    1250 <main+0xc0>
lea    0xd96(%rip),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xdb5(%rip),%rdi
xor    %r14d,%r14d
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r12d,%r12d
jns    12ac <main+0x11c>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   1080 <close@plt>
lea    0xd90(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12ec <main+0x15c>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
jmp    12e6 <main+0x156>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.addr = [16 x i8] c"10.0.2.18\00\00\00\00\00\00\00"
@.str = [6 x i8] c"hi hi\00"
@.str.1 = [20 x i8] c"start the client \0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [33 x i8] c"ERROR: Could not create socket!\0A\00"
@.str.3 = [19 x i8] c"Bind socket to %d\0A\00"
@.str.4 = [42 x i8] c"ERROR: Could not connect to the server !\0A\00"
@.str.5 = [25 x i8] c"connect >>>>>>>>>>>>>>>\0A\00"
@.str.6 = [26 x i8] c"write to the server : %s\0A\00"
@.str.7 = [8 x i8] c"send %d\00"
@.str.8 = [40 x i8] c"ERROR: Could not write to the server !\0A\00"
@.str.9 = [5 x i8] c"Done\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %1
store i32 2222, i32* %4
%9 = bitcast [16 x i8]* %5 to i8*
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %70
18: ; preds = %0
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%27 = call i32 @inet_addr(i8* %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @connect(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %18
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* %2
%37 = call i32 @close(i32 %36)
store i32 -1, i32* %1
br label %70
38: ; preds = %18
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%40 = load i8*, i8** %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %6
store i8* %42, i8** %7
store i32 0, i32* %8
br label %43
43: ; preds = %47, %38
%44 = load i8*, i8** %7
%45 = load i8, i8* %44
%46 = icmp ne i8 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i32, i32* %2
%49 = load i8*, i8** %7
%50 = call i32 @send(i32 %48, i8* %49, i32 8, i32 0)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = load i8*, i8** %7
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %7
br label %43
55: ; preds = %43
%56 = load i8*, i8** %6
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %8
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %8
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %66
66: ; preds = %64, %55
%67 = load i32, i32* %2
%68 = call i32 @close(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %70
70: ; preds = %66, %34, %16
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.addr = [16 x i8] c"10.0.2.18\00\00\00\00\00\00\00"
@.str = [6 x i8] c"hi hi\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [19 x i8] c"Bind socket to %d\0A\00"
@.str.6 = [26 x i8] c"write to the server : %s\0A\00"
@.str.7 = [8 x i8] c"send %d\00"
@.str.9 = [5 x i8] c"Done\00"
@str = [19 x i8] c"start the client \00"
@str.10 = [24 x i8] c"connect >>>>>>>>>>>>>>>\00"
@str.11 = [39 x i8] c"ERROR: Could not write to the server !\00"
@str.12 = [41 x i8] c"ERROR: Could not connect to the server !\00"
@str.13 = [32 x i8] c"ERROR: Could not create socket!\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [16 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
br label %46
12: ; preds = %0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 2222)
%14 = tail call i32 @htons(i32 2222)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* %4)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i32 @connect(i32 %8, %struct.sockaddr* %20, i32 12)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.12, i64 0, i64 0))
%25 = call i32 @close(i32 %8)
br label %46
26: ; preds = %12
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.10, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %26, %29
%30 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %26 ], [ %33, %29 ]
%31 = call i32 @send(i32 %8, i8* %30, i32 8, i32 0)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %29
36: ; preds = %29
%37 = call i32 @free(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @free(i8* %33)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%40 = icmp slt i32 %31, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.11, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = call i32 @close(i32 %8)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %46
46: ; preds = %43, %23, %10
%47 = phi i32 [ -1, %10 ], [ -1, %23 ], [ 0, %43 ]
ret i32 %47
}