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

/* Variables and functions */
scalar_t__ connect(int, struct sockaddr *, int /*<<< orphan*/);
int socket_make_sockaddr_un(char const *, int, struct sockaddr_un *,
                            int /*<<< orphan*/ *);
int socket_local_client_connect(int fd, const char *name, int namespaceId,
                                int type) {
  struct sockaddr_un addr;
  socklen_t alen;
  size_t namelen;
  int err;
  err = socket_make_sockaddr_un(name, namespaceId, &addr, &alen);
  if (err < 0) {
    goto error;
  }
  if (connect(fd, (struct sockaddr *)&addr, alen) < 0) {
    goto error;
  }
  return fd;
error:
  return -1;
}


x86 assembly (clang, -O0):
<socket_local_client_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1030 <socket_make_sockaddr_un@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    115b <socket_local_client_connect+0x3b>
jmp    1184 <socket_local_client_connect+0x64>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <connect@plt>
cmp    $0x0,%rax
jge    1179 <socket_local_client_connect+0x59>
jmp    1184 <socket_local_client_connect+0x64>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <socket_local_client_connect+0x6b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_local_client_connect>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%rcx
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rax,%rdx
call   1030 <socket_make_sockaddr_un@plt>
test   %eax,%eax
js     1157 <socket_local_client_connect+0x37>
mov    0xc(%rsp),%edx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1040 <connect@plt>
test   %rax,%rax
jns    115c <socket_local_client_connect+0x3c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @socket_local_client_connect(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_un
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i32 @socket_make_sockaddr_un(i8* %14, i32 %15, %struct.sockaddr_un* %10, i32* %11)
store i32 %16, i32* %13
%17 = load i32, i32* %13
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4
br label %29
20: ; preds = %4
%21 = load i32, i32* %6
%22 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%23 = load i32, i32* %11
%24 = call i64 @connect(i32 %21, %struct.sockaddr* %22, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
br label %29
27: ; preds = %20
%28 = load i32, i32* %6
store i32 %28, i32* %5
br label %30
29: ; preds = %26, %19
store i32 -1, i32* %5
br label %30
30: ; preds = %29, %27
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @socket_local_client_connect(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
%7 = bitcast %struct.sockaddr_un* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 @socket_make_sockaddr_un(i8* %1, i32 %2, %struct.sockaddr_un* %5, i32* %6)
%10 = icmp slt i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %4
%12 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%13 = load i32, i32* %6
%14 = call i64 @connect(i32 %0, %struct.sockaddr* %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11, %4
br label %17
17: ; preds = %11, %16
%18 = phi i32 [ -1, %16 ], [ %0, %11 ]
ret i32 %18
}