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

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int socket_local_client_connect(int fd, const char *name) {
  struct sockaddr_un addr;
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_LOCAL;
  strncpy(addr.sun_path, name, sizeof(addr.sun_path) - 1);
  if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<socket_local_client_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
jge    1193 <socket_local_client_connect+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <socket_local_client_connect+0x69>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_local_client_connect>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1050 <connect@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovns %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i32 0
define i32 @socket_local_client_connect(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.sockaddr_un
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = call i32 @memset(%struct.sockaddr_un* %6, i32 0, i32 8)
%8 = load i32, i32* @AF_LOCAL
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %5
%13 = call i32 @strncpy(i32 %11, i8* %12, i32 3)
%14 = load i32, i32* %4
%15 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%16 = call i64 @connect(i32 %14, %struct.sockaddr* %15, i32 8)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
br label %21
19: ; preds = %2
%20 = load i32, i32* %4
store i32 %20, i32* %3
br label %21
21: ; preds = %19, %18
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i32 0
define i32 @socket_local_client_connect(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%6 = load i32, i32* @AF_LOCAL
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @strncpy(i32 %9, i8* %1, i32 3)
%11 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%12 = call i64 @connect(i32 %0, %struct.sockaddr* %11, i32 8)
%13 = icmp slt i64 %12, 0
%14 = select i1 %13, i32 -1, i32 %0
ret i32 %14
}