#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;
};
typedef int /*<<< orphan*/ serv;

/* Variables and functions */
int /*<<< orphan*/ AF_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 sapi_unix_tcp_client_create(char *path) {
  int ret;
  struct sockaddr_un serv = {
      .sun_family = AF_UNIX,
  };
  strcpy(serv.sun_path, path);
  int sock;
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock < 0)
    return -1;
  ret = connect(sock, (struct sockaddr *)&serv, sizeof(serv));
  if (ret < 0)
    goto err_connect;
  return sock;
err_connect:
  close(sock);
  return -1;
}


x86 assembly (clang, -O0):
<sapi_unix_tcp_client_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    119d <sapi_unix_tcp_client_create+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <sapi_unix_tcp_client_create+0x9a>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c0 <sapi_unix_tcp_client_create+0x80>
jmp    11cb <sapi_unix_tcp_client_create+0x8b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <sapi_unix_tcp_client_create+0x9a>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sapi_unix_tcp_client_create>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rsi
movl   $0x0,(%rsp)
mov    0x2e94(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
xor    %edi,%edi
call   1030 <strcpy@plt>
mov    (%rbx),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     119c <sapi_unix_tcp_client_create+0x5c>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1050 <connect@plt>
test   %eax,%eax
js     1195 <sapi_unix_tcp_client_create+0x55>
mov    %ebp,%ebx
jmp    119c <sapi_unix_tcp_client_create+0x5c>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @sapi_unix_tcp_client_create(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
store i8* %0, i8** %3
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
store i32 0, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
%9 = load i32, i32* @AF_UNIX
store i32 %9, i32* %8
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i32 %11, i8* %12)
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %1
store i32 -1, i32* %2
br label %32
20: ; preds = %1
%21 = load i32, i32* %6
%22 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%23 = call i32 @connect(i32 %21, %struct.sockaddr* %22, i32 8)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp slt i32 %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* %2
br label %32
29: ; preds = %26
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
store i32 -1, i32* %2
br label %32
32: ; preds = %29, %27, %19
%33 = load i32, i32* %2
ret i32 %33
}

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