#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 /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int unix_socket_client(const char *path) {
  struct sockaddr_un addr;
  int unix_socket;
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, path);
  unix_socket = socket(AF_UNIX, SOCK_STREAM, 0);
  if (unix_socket == -1)
    return -1;
  if (connect(unix_socket, (struct sockaddr *)&addr,
              (socklen_t)sizeof(struct sockaddr_un)) == 1)
    return -1;
  return unix_socket;
}


x86 assembly (clang, -O0):
<unix_socket_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1186 <unix_socket_client+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <unix_socket_client+0x82>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <connect@plt>
cmp    $0x1,%eax
jne    11ac <unix_socket_client+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <unix_socket_client+0x82>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unix_socket_client>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    %rdi,%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
cmp    $0xffffffff,%eax
je     1181 <unix_socket_client+0x51>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1040 <connect@plt>
cmp    $0x1,%eax
mov    $0xffffffff,%eax
cmovne %ebx,%eax
jmp    1186 <unix_socket_client+0x56>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @unix_socket_client(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @AF_UNIX
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i32 %9, i8* %10)
%12 = load i32, i32* @AF_UNIX
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %26
18: ; preds = %1
%19 = load i32, i32* %5
%20 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%21 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 8)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -1, i32* %2
br label %26
24: ; preds = %18
%25 = load i32, i32* %5
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %23, %17
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @unix_socket_client(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = load i32, i32* @AF_UNIX
%5 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %4, i32* %5
%6 = tail call i32 @strcpy(i32 undef, i8* %0)
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%13 = call i32 @connect(i32 %9, %struct.sockaddr* %12, i32 8)
%14 = icmp eq i32 %13, 1
%15 = select i1 %14, i32 -1, i32 %9
br label %16
16: ; preds = %11, %1
%17 = phi i32 [ -1, %1 ], [ %15, %11 ]
ret i32 %17
}