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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ assert(int);
int connect(int const, struct sockaddr const *, int const);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int socket_connect_unix(const int fd, const char *path_unix) {
  assert(fd != -1 && path_unix != NULL);
  struct sockaddr_un server_addr;
  const socklen_t addr_len = sizeof(server_addr);
  memset(&server_addr, 0, addr_len);
  server_addr.sun_family = AF_UNIX;
  strcpy(server_addr.sun_path, path_unix);
  return connect(fd, (const struct sockaddr *)&server_addr, addr_len);
}


x86 assembly (clang, -O0):
<socket_connect_unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x4(%rbp)
mov    %al,-0x1d(%rbp)
je     1169 <socket_connect_unix+0x29>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x8,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_connect_unix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0xffffffff,%edi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
define i32 @socket_connect_unix(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br label %12
12: ; preds = %9, %2
%13 = phi i1 [ false, %2 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
store i32 8, i32* %6
%16 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 8)
%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 i32, i32* %19
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i32 %20, i8* %21)
%23 = load i32, i32* %3
%24 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%25 = call i32 @connect(i32 %23, %struct.sockaddr* %24, i32 8)
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
define i32 @socket_connect_unix(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr_un
%4 = icmp ne i32 %0, -1
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = bitcast %struct.sockaddr_un* %3 to i8*
%10 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%11 = load i32, i32* @AF_UNIX
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @strcpy(i32 %14, i8* %1)
%16 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%17 = call i32 @connect(i32 %0, %struct.sockaddr* %16, i32 8)
ret i32 %17
}