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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int dbzunixclient(const char *path) {
  struct sockaddr_un s_un;
  int s;
  bzero((char *)&s_un, sizeof(s_un));
  s_un.sun_family = AF_UNIX;
  if (path == NULL)
    return (-1);
  strcpy(s_un.sun_path, path);
  s = socket(PF_UNIX, SOCK_STREAM, 0);
  if (s < 0)
    return -1;
  if (connect(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0)
    return -1;
  return s;
}


x86 assembly (clang, -O0):
<dbzunixclient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1040 <bzero@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117d <dbzunixclient+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <dbzunixclient+0xa8>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bb <dbzunixclient+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <dbzunixclient+0xa8>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
jge    11e2 <dbzunixclient+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <dbzunixclient+0xa8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbzunixclient>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    %rsp,%rdi
mov    $0x8,%esi
call   1040 <bzero@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    $0xffffffff,%ebx
test   %rbp,%rbp
je     11ae <dbzunixclient+0x6e>
mov    (%rsp),%edi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11ae <dbzunixclient+0x6e>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1050 <connect@plt>
test   %rax,%rax
mov    $0xffffffff,%ebx
cmovns %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @dbzunixclient(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
store i8* %0, i8** %3
%6 = bitcast %struct.sockaddr_un* %4 to i8*
%7 = call i32 @bzero(i8* %6, i32 8)
%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 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %32
13: ; preds = %1
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i32 %15, i8* %16)
%18 = load i32, i32* @PF_UNIX
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %13
store i32 -1, i32* %2
br label %32
24: ; preds = %13
%25 = load i32, i32* %5
%26 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%27 = call i64 @connect(i32 %25, %struct.sockaddr* %26, i32 8)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %2
br label %32
30: ; preds = %24
%31 = load i32, i32* %5
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %29, %23, %12
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @dbzunixclient(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = call i32 @bzero(i8* %3, i32 8)
%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 = icmp eq i8* %0, null
br i1 %7, label %21, label %8
8: ; preds = %1
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @strcpy(i32 %10, i8* %0)
%12 = load i32, i32* @PF_UNIX
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %8
%17 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%18 = call i64 @connect(i32 %14, %struct.sockaddr* %17, i32 8)
%19 = icmp slt i64 %18, 0
%20 = select i1 %19, i32 -1, i32 %14
br label %21
21: ; preds = %16, %8, %1
%22 = phi i32 [ -1, %1 ], [ -1, %8 ], [ %20, %16 ]
ret i32 %22
}