#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket_tcp_connect(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char buffer[64];
  int sock;
  ssize_t n;
  if ((sock = socket_tcp_connect(NULL, "8080", NULL)) < 0)
    return (1);
  n = send(sock, "Hello Server\n", 13, 0);
  printf("Send %d\n", n);
  memset(buffer, 0, 64);
  n = recv(sock, buffer, 64, 0);
  printf("RECV %d '%s'\n", n, buffer);
  close(sock);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edx
lea    0xe7f(%rip),%rsi
mov    %rdx,%rdi
call   1040 <socket_tcp_connect@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jge    11a1 <main+0x41>
movl   $0x1,-0x4(%rbp)
jmp    1215 <main+0xb5>
mov    -0x54(%rbp),%edi
lea    0xe5a(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xe91(%rip),%rsi
xor    %r14d,%r14d
xor    %edi,%edi
xor    %edx,%edx
call   1040 <socket_tcp_connect@plt>
test   %eax,%eax
js     11e5 <main+0x85>
mov    %eax,%ebp
lea    0xe7d(%rip),%rsi
mov    %eax,%edi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    11eb <main+0x8b>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"8080\00"
@.str.1 = [14 x i8] c"Hello Server\0A\00"
@.str.2 = [9 x i8] c"Send %d\0A\00"
@.str.3 = [14 x i8] c"RECV %d '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @socket_tcp_connect(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* null)
store i32 %9, i32* %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %27
12: ; preds = %2
%13 = load i32, i32* %7
%14 = call i32 @send(i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13, i32 0)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 64)
%19 = load i32, i32* %7
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%21 = call i32 @recv(i32 %19, i8* %20, i32 64, i32 0)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %22, i8* %23)
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
store i32 0, i32* %3
br label %27
27: ; preds = %12, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [5 x i8] c"8080\00"
@.str.1 = [14 x i8] c"Hello Server\0A\00"
@.str.2 = [9 x i8] c"Send %d\0A\00"
@.str.3 = [14 x i8] c"RECV %d '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @socket_tcp_connect(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* null)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = tail call i32 @send(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13, i32 0)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = call i32 @memset(i8* %4, i32 0, i32 64)
%11 = call i32 @recv(i32 %5, i8* %4, i32 64, i32 0)
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %11, i8* %4)
%13 = call i32 @close(i32 %5)
br label %14
14: ; preds = %2, %7
%15 = phi i32 [ 0, %7 ], [ 1, %2 ]
ret i32 %15
}