#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(int /*<<< orphan*/);
int create_client_fd(char *sock_path) {
  int len, remote_fd;
  struct sockaddr_un remote;
  if (-1 == (remote_fd = socket(PF_UNIX, SOCK_STREAM, 0))) {
    return -1;
  }
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, sock_path);
  len = strlen(remote.sun_path) + sizeof(remote.sun_family);
  if (-1 == connect(remote_fd, (struct sockaddr *)&remote, len)) {
    close(remote_fd);
    return -1;
  }
  return remote_fd;
}


x86 assembly (clang, -O0):
<create_client_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1193 <create_client_fd+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <create_client_fd+0xa4>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%edi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <connect@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ee <create_client_fd+0x9e>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <create_client_fd+0xa4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_client_fd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11b9 <create_client_fd+0x69>
mov    %eax,%ebp
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rsi
call   1030 <strcpy@plt>
call   1040 <strlen@plt>
lea    0x4(%rax),%edx
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
je     11b2 <create_client_fd+0x62>
mov    %ebp,%ebx
jmp    11b9 <create_client_fd+0x69>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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