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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_SEQPACKET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int vipc_connect() {
  int err;
  int sock = socket(AF_UNIX, SOCK_SEQPACKET, 0);
  assert(sock >= 0);
  struct sockaddr_un addr = {
      .sun_family = AF_UNIX,
      .sun_path = "/tmp/vision_socket",
  };
  err = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
  if (err != 0) {
    close(sock);
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<vipc_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe84(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <connect@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11be <vipc_connect+0x7e>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <vipc_connect+0x84>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vipc_connect>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e9a(%rip),%r14
mov    (%r14),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
lea    0xe8a(%rip),%rax
mov    %rax,0x8(%rsp)
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1050 <connect@plt>
test   %eax,%eax
je     11a3 <vipc_connect+0x63>
mov    %ebx,%edi
call   1030 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_SEQPACKET = global i32 0
@.str = [19 x i8] c"/tmp/vision_socket\00"
define i32 @vipc_connect() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_SEQPACKET
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
%14 = load i32, i32* @AF_UNIX
store i32 %14, i32* %13
%15 = load i32, i32* %3
%16 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%17 = call i32 @connect(i32 %15, %struct.sockaddr* %16, i32 16)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
store i32 -1, i32* %1
br label %25
23: ; preds = %0
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_SEQPACKET = global i32 0
@.str = [19 x i8] c"/tmp/vision_socket\00"
define i32 @vipc_connect() {
%1 = alloca %struct.sockaddr_un
%2 = load i32, i32* @AF_UNIX
%3 = load i32, i32* @SOCK_SEQPACKET
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = xor i32 %4, -1
%6 = lshr i32 %5, 31
%7 = tail call i32 @assert(i32 %6)
%8 = bitcast %struct.sockaddr_un* %1 to i8*
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
%11 = load i32, i32* @AF_UNIX
store i32 %11, i32* %10
%12 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%13 = call i32 @connect(i32 %4, %struct.sockaddr* %12, i32 16)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 @close(i32 %4)
br label %17
17: ; preds = %0, %15
%18 = phi i32 [ -1, %15 ], [ %4, %0 ]
ret i32 %18
}