#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;
  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    $0x30,%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,-0x28(%rbp)
cmpl   $0x0,-0x28(%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    $0x30,%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 i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = call i32 @socket_make_sockaddr_un(i8* %13, i32 %14, %struct.sockaddr_un* %10, i32* %11)
store i32 %15, i32* %12
%16 = load i32, i32* %12
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
br label %28
19: ; preds = %4
%20 = load i32, i32* %6
%21 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%22 = load i32, i32* %11
%23 = call i64 @connect(i32 %20, %struct.sockaddr* %21, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %28
26: ; preds = %19
%27 = load i32, i32* %6
store i32 %27, i32* %5
br label %29
28: ; preds = %25, %18
store i32 -1, i32* %5
br label %29
29: ; preds = %28, %26
%30 = load i32, i32* %5
ret i32 %30
}

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
}