#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);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char const *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int client_open(const char *path, struct sockaddr_un *server) {
  int sock;
  sock = socket(PF_UNIX, SOCK_STREAM, 0);
  if (sock == -1) {
    ;
    return -1;
  }
  memset(server, 0, sizeof(struct sockaddr_un));
  server->sun_family = AF_UNIX;
  snprintf(server->sun_path, sizeof(server->sun_path), "%s", path);
  if (connect(sock, (struct sockaddr *)server, sizeof(struct sockaddr_un)) <
      0) {
    ;
    close(sock);
    return -2;
  }
  return sock;
}


x86 assembly (clang, -O0):
<client_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1192 <client_open+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1202 <client_open+0xb2>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
lea    0xe38(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
cmp    $0x0,%rax
jge    11fc <client_open+0xac>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1202 <client_open+0xb2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_open>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     11d0 <client_open+0x80>
mov    %eax,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%r14)
mov    (%r14),%edi
lea    0xe5f(%rip),%rdx
mov    $0x4,%esi
mov    %r15,%rcx
call   1030 <snprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
test   %rax,%rax
jns    11d5 <client_open+0x85>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xfffffffe,%ebx
jmp    11d5 <client_open+0x85>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
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
@.str = [3 x i8] c"%s\00"
define i32 @client_open(i8* %0, %struct.sockaddr_un* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_un*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.sockaddr_un* %1, %struct.sockaddr_un** %5
%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* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %34
13: ; preds = %2
%14 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%15 = call i32 @memset(%struct.sockaddr_un* %14, i32 0, i32 8)
%16 = load i32, i32* @AF_UNIX
%17 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %17, i32 0, i32 1
store i32 %16, i32* %18
%19 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i8*, i8** %4
%23 = call i32 @snprintf(i32 %21, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %6
%25 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%26 = bitcast %struct.sockaddr_un* %25 to %struct.sockaddr*
%27 = call i64 @connect(i32 %24, %struct.sockaddr* %26, i32 8)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %13
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
store i32 -2, i32* %3
br label %34
32: ; preds = %13
%33 = load i32, i32* %6
store i32 %33, i32* %3
br label %34
34: ; preds = %32, %29, %12
%35 = load i32, i32* %3
ret i32 %35
}

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
@.str = [3 x i8] c"%s\00"
define i32 @client_open(i8* %0, %struct.sockaddr_un* %1) {
%3 = load i32, i32* @PF_UNIX
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = tail call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 8)
%9 = load i32, i32* @AF_UNIX
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @snprintf(i32 %12, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%15 = tail call i64 @connect(i32 %5, %struct.sockaddr* %14, i32 8)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = tail call i32 @close(i32 %5)
br label %19
19: ; preds = %7, %2, %17
%20 = phi i32 [ -2, %17 ], [ -1, %2 ], [ %5, %7 ]
ret i32 %20
}