#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_unix_connect(char *);
int main(int argc, char **argv) {
  char buffer[64];
  int sock;
  ssize_t n;
  if ((sock = socket_unix_connect("test.sock")) < 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)
lea    0xe83(%rip),%rdi
call   1080 <socket_unix_connect@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jge    119a <main+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    120e <main+0xae>
mov    -0x54(%rbp),%edi
lea    0xe66(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <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    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x54(%rbp),%edi
call   1070 <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),%rdi
call   1080 <socket_unix_connect@plt>
test   %eax,%eax
js     11e1 <main+0x81>
mov    %eax,%ebp
lea    0xe89(%rip),%rsi
xor    %r14d,%r14d
mov    %eax,%edi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    11e7 <main+0x87>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"test.sock\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_unix_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
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 = [10 x i8] c"test.sock\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_unix_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%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
}