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

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *const);
int /*<<< orphan*/ write_text(int, char const *const);
int main(int argc, char *const argv[]) {
  const char *const socket_name = argv[1];
  const char *const message = argv[2];
  int socket_fd;
  struct sockaddr_un name;
  socket_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
  name.sun_family = AF_LOCAL;
  strcpy(name.sun_path, socket_name);
  connect(socket_fd, (struct sockaddr *)&name, SUN_LEN(&name));
  write_text(socket_fd, message);
  close(socket_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <SUN_LEN@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1060 <connect@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <write_text@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r14
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <SUN_LEN@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <connect@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <write_text@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_LOCAL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
store i8* %15, i8** %7
%16 = load i32, i32* @PF_LOCAL
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %8
%19 = load i32, i32* @AF_LOCAL
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i8*, i8** %6
%24 = call i32 @strcpy(i32 %22, i8* %23)
%25 = load i32, i32* %8
%26 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%27 = call i32 @SUN_LEN(%struct.sockaddr_un* %9)
%28 = call i32 @connect(i32 %25, %struct.sockaddr* %26, i32 %27)
%29 = load i32, i32* %8
%30 = load i8*, i8** %7
%31 = call i32 @write_text(i32 %29, i8* %30)
%32 = load i32, i32* %8
%33 = call i32 @close(i32 %32)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_LOCAL = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = bitcast %struct.sockaddr_un* %3 to i8*
%9 = load i32, i32* @PF_LOCAL
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32, i32* @AF_LOCAL
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = tail call i32 @strcpy(i32 undef, i8* %5)
%15 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%16 = call i32 @SUN_LEN(%struct.sockaddr_un* %3)
%17 = call i32 @connect(i32 %11, %struct.sockaddr* %15, i32 %16)
%18 = call i32 @write_text(i32 %11, i8* %7)
%19 = call i32 @close(i32 %11)
ret i32 0
}