#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;
};

/* Variables and functions */
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int /*<<< orphan*/);
scalar_t__ fill_sock_name(struct sockaddr_un *, char const *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int setup_clnt_sock(const char *filename) {
  struct sockaddr_un name;
  int sock;
  if (fill_sock_name(&name, filename) < 0)
    return -1;
  sock = socket(PF_LOCAL, SOCK_STREAM, 0);
  if (sock < 0)
    return -1;
  if (connect(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0)
    goto err;
  return sock;
err:
  close(sock);
  return -1;
}


x86 assembly (clang, -O0):
<setup_clnt_sock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1040 <fill_sock_name@plt>
cmp    $0x0,%rax
jge    117f <setup_clnt_sock+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <setup_clnt_sock+0xaf>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b1 <setup_clnt_sock+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <setup_clnt_sock+0xaf>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <SUN_LEN@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
jge    11e5 <setup_clnt_sock+0x95>
jmp    11f0 <setup_clnt_sock+0xa0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <setup_clnt_sock+0xaf>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_clnt_sock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rsi
lea    0x8(%rsp),%rdi
call   1040 <fill_sock_name@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11b7 <setup_clnt_sock+0x67>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11b7 <setup_clnt_sock+0x67>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1060 <SUN_LEN@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <connect@plt>
test   %rax,%rax
js     11b0 <setup_clnt_sock+0x60>
mov    %ebp,%ebx
jmp    11b7 <setup_clnt_sock+0x67>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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