#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serverAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int ret = -1;
  int clientSock;
  struct sockaddr_in serverAddr;
  if ((clientSock = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    goto leave;
  }
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  serverAddr.sin_port = htons(3000);
  if ((ret = connect(clientSock, (struct sockaddr *)&serverAddr,
                     sizeof(serverAddr)))) {
    perror("connect");
    goto error;
  }
  if ((ret = send(clientSock, "Hello, JoJo!", sizeof("Hello, JoJo!"), 0)) <=
      0) {
    perror("send");
    ret = -1;
  } else
    printf("Wrote '%s' (%d Bytes)\n", "Hello, JoJo!", ret);
error:
  close(clientSock);
leave:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11cc <main+0x4c>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
jmp    127f <main+0xff>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe28(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0xbb8,%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1222 <main+0xa2>
lea    0xdf9(%rip),%rdi
call   1080 <perror@plt>
jmp    1277 <main+0xf7>
mov    -0xc(%rbp),%edi
lea    0xded(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jg     125c <main+0xdc>
lea    0xddb(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    1272 <main+0xf2>
mov    -0x8(%rbp),%edx
lea    0xdc5(%rip),%rdi
lea    0xdac(%rip),%rsi
call   1050 <printf@plt>
jmp    1277 <main+0xf7>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     122a <main+0xaa>
mov    %eax,%ebx
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xe49(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0xbb8,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %eax,%eax
jne    123d <main+0xbd>
lea    0xe28(%rip),%rsi
mov    %ebx,%edi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %eax,%eax
jle    124d <main+0xcd>
mov    %eax,%ebp
lea    0xe1f(%rip),%rdi
lea    0xe06(%rip),%rsi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdcf(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1221 <main+0xa1>
mov    %eax,%ebp
lea    0xdcb(%rip),%rdi
call   1080 <perror@plt>
jmp    121a <main+0x9a>
lea    0xdd2(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebp
jmp    121a <main+0x9a>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [13 x i8] c"Hello, JoJo!\00"
@.str.4 = [5 x i8] c"send\00"
@.str.5 = [23 x i8] c"Wrote '%s' (%d Bytes)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i32 -1, i32* %2
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %38
11: ; preds = %0
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %12, i32* %13
%14 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = call i32 @htons(i32 3000)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* %3
%20 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%21 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 12)
store i32 %21, i32* %2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %35
25: ; preds = %11
%26 = load i32, i32* %3
%27 = call i32 @send(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
store i32 %27, i32* %2
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
31: ; preds = %25
%32 = load i32, i32* %2
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %29
br label %35
35: ; preds = %34, %23
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
br label %38
38: ; preds = %35, %9
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [13 x i8] c"Hello, JoJo!\00"
@.str.4 = [5 x i8] c"send\00"
@.str.5 = [23 x i8] c"Wrote '%s' (%d Bytes)\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %31
9: ; preds = %0
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 3000)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%17 = call i32 @connect(i32 %5, %struct.sockaddr* %16, i32 12)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %9
%20 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %28
21: ; preds = %9
%22 = call i32 @send(i32 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %28
28: ; preds = %24, %26, %19
%29 = phi i32 [ %17, %19 ], [ -1, %24 ], [ %22, %26 ]
%30 = call i32 @close(i32 %5)
br label %31
31: ; preds = %28, %7
%32 = phi i32 [ -1, %7 ], [ %29, %28 ]
ret i32 %32
}