#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 */
struct sockaddr_un {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(void) {
  int client, t, len;
  struct sockaddr_un remote;
  char str[] = "Hola Mundo";
  if ((client = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  printf("Intentando conectar...\n");
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, "echo_socket");
  len = strlen(remote.sun_path) + sizeof(remote.sun_family);
  if (connect(client, (struct sockaddr *)&remote, len) < 0) {
    printf("Error: connect()\n");
    return -1;
  }
  printf("Conectado.\n");
  if (send(client, str, strlen(str), 0) < 0) {
    printf("Error: send()\n");
    return -1;
  }
  close(client);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xe57(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe4f(%rip),%al
mov    %al,-0x21(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11f9 <main+0x69>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1060 <printf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1264 <main+0xd4>
lea    0xddc(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c8 <main+0x138>
lea    0xdd6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x2b(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x2b(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    12b9 <main+0x129>
lea    0xda5(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c8 <main+0x138>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movabs $0x6e754d20616c6f48,%rax
4d 75 6e
mov    %rax,(%rsp)
movl   $0x6f646e,0x7(%rsp)
mov    0x2e33(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1265 <main+0xd5>
mov    %eax,%ebx
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
lea    0xe1e(%rip),%rsi
call   1030 <strcpy@plt>
call   1050 <strlen@plt>
lea    0x4(%rax),%edx
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   10a0 <connect@plt>
test   %rax,%rax
js     1240 <main+0xb0>
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
js     1249 <main+0xb9>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    125a <main+0xca>
lea    0xe00(%rip),%rdi
jmp    1250 <main+0xc0>
lea    0xde9(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xda4(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@__const.main.str = [11 x i8] c"Hola Mundo\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [24 x i8] c"Intentando conectar...\0A\00"
@.str.2 = [12 x i8] c"echo_socket\00"
@.str.3 = [18 x i8] c"Error: connect()\0A\00"
@.str.4 = [12 x i8] c"Conectado.\0A\00"
@.str.5 = [15 x i8] c"Error: send()\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
%6 = alloca [11 x i8]
store i32 0, i32* %1
%7 = bitcast [11 x i8]* %6 to i8*
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @AF_UNIX
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = add i64 %25, 4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%30 = load i32, i32* %4
%31 = call i64 @connect(i32 %28, %struct.sockaddr* %29, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %15
%34 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %48
35: ; preds = %15
%36 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i64 @send(i32 %37, i8* %38, i32 %40, i32 0)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %35
%44 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %48
45: ; preds = %35
%46 = load i32, i32* %2
%47 = call i32 @close(i32 %46)
store i32 0, i32* %1
br label %48
48: ; preds = %45, %43, %33
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@__const.main.str = [11 x i8] c"Hola Mundo\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.2 = [12 x i8] c"echo_socket\00"
@str = [23 x i8] c"Intentando conectar...\00"
@str.6 = [11 x i8] c"Conectado.\00"
@str.7 = [14 x i8] c"Error: send()\00"
@str.8 = [17 x i8] c"Error: connect()\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [11 x i8]
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %14, i32* %15
%16 = tail call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @strlen(i8* undef)
%18 = add i32 %17, 4
%19 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%20 = call i64 @connect(i32 %7, %struct.sockaddr* %19, i32 %18)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
br label %33
24: ; preds = %12
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%26 = call i32 @strlen(i8* %4)
%27 = call i64 @send(i32 %7, i8* %4, i32 %26, i32 0)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %33
31: ; preds = %24
%32 = call i32 @close(i32 %7)
br label %33
33: ; preds = %31, %29, %22
%34 = phi i32 [ -1, %22 ], [ -1, %29 ], [ 0, %31 ]
ret i32 %34
}