#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;
};
typedef int /*<<< orphan*/ sa_family_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int SOCK_CLOEXEC;
int SOCK_DGRAM;
int SOCK_NONBLOCK;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr_un *, size_t);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, char const *, size_t);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
size_t strlen(char const *);
int /*<<< orphan*/ write(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void io_send(const char *path) {
  int fd;
  struct sockaddr_un sa;
  size_t len = strlen(path);
  sa.sun_family = AF_UNIX;
  memcpy(sa.sun_path, path, len);
  len += sizeof(sa_family_t);
  fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
  if (fd < 0)
    return;
  if (connect(fd, &sa, len) < 0)
    return;
  write(fd, NULL, 0);
  close(fd);
}


x86 assembly (clang, -O0):
<io_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e36(%rip),%rax
or     (%rax),%esi
mov    0x2e05(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11de <io_send+0x7e>
jmp    1213 <io_send+0xb3>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1070 <connect@plt>
cmp    $0x0,%rax
jge    11fd <io_send+0x9d>
jmp    1213 <io_send+0xb3>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    0x2e66(%rip),%r14
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    0x2e45(%rip),%rax
mov    0x2e56(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    (%r14),%edi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11e1 <io_send+0x81>
mov    %eax,%ebp
add    $0x4,%rbx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    %rbx,%rdx
call   1070 <connect@plt>
test   %rax,%rax
js     11e1 <io_send+0x81>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_CLOEXEC = global i32 0
@SOCK_NONBLOCK = global i32 0
define void @io_send(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = load i32, i32* @AF_UNIX
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = load i64, i64* %5
%14 = call i32 @memcpy(i32 %11, i8* %12, i64 %13)
%15 = load i64, i64* %5
%16 = add i64 %15, 4
store i64 %16, i64* %5
%17 = load i32, i32* @AF_UNIX
%18 = load i32, i32* @SOCK_DGRAM
%19 = load i32, i32* @SOCK_CLOEXEC
%20 = or i32 %18, %19
%21 = load i32, i32* @SOCK_NONBLOCK
%22 = or i32 %20, %21
%23 = call i32 @socket(i32 %17, i32 %22, i32 0)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %1
br label %38
27: ; preds = %1
%28 = load i32, i32* %3
%29 = load i64, i64* %5
%30 = call i64 @connect(i32 %28, %struct.sockaddr_un* %4, i64 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
br label %38
33: ; preds = %27
%34 = load i32, i32* %3
%35 = call i32 @write(i32 %34, i32* null, i32 0)
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
br label %38
38: ; preds = %33, %32, %26
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_CLOEXEC = global i32 0
@SOCK_NONBLOCK = global i32 0
define void @io_send(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = tail call i32 @memcpy(i32 undef, i8* %0, i64 %4)
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @SOCK_CLOEXEC
%11 = or i32 %10, %9
%12 = load i32, i32* @SOCK_NONBLOCK
%13 = or i32 %11, %12
%14 = tail call i32 @socket(i32 %8, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %1
%17 = add i64 %4, 4
%18 = call i64 @connect(i32 %14, %struct.sockaddr_un* %2, i64 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = call i32 @write(i32 %14, i32* null, i32 0)
%22 = call i32 @close(i32 %14)
br label %23
23: ; preds = %16, %1, %20
ret void
}