#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 */
typedef int /*<<< orphan*/ sun;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int strlen(char const *);
int usock_connect(struct sockaddr *, int, int /*<<< orphan*/, int, int);
int usock_unix(const char *host, int socktype, bool server) {
  struct sockaddr_un sun = {.sun_family = AF_UNIX};
  if (strlen(host) >= sizeof(sun.sun_path)) {
    errno = EINVAL;
    return -1;
  }
  strcpy(sun.sun_path, host);
  return usock_connect((struct sockaddr *)&sun, sizeof(sun), AF_UNIX, socktype,
                       server);
}


x86 assembly (clang, -O0):
<usock_unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x4,%rax
jb     1188 <usock_unix+0x58>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e5e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <usock_unix+0x85>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    $0x8,%esi
call   1050 <usock_connect@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usock_unix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
movl   $0x0,(%rsp)
mov    0x2e9a(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
call   1040 <strlen@plt>
cmp    $0x4,%eax
jb     1178 <usock_unix+0x48>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    0x2e69(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    1198 <usock_unix+0x68>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x0(%rbp),%edx
mov    %rsp,%rdi
mov    $0x8,%esi
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1050 <usock_connect@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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