#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 __socket_setup(struct sockaddr_un *, size_t *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, size_t);
int setup_socket(void) {
  struct sockaddr_un addr;
  size_t addrsize;
  int sfd;
  sfd = __socket_setup(&addr, &addrsize);
  if (sfd == -1)
    goto out;
  if (connect(sfd, (struct sockaddr *)&addr, addrsize) == -1)
    goto close_and_exit;
  return sfd;
close_and_exit:
  close(sfd);
  sfd = -1;
out:
  return sfd;
}


x86 assembly (clang, -O0):
<setup_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <__socket_setup@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1157 <setup_socket+0x27>
jmp    118f <setup_socket+0x5f>
mov    -0x14(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <connect@plt>
cmp    $0xffffffff,%eax
jne    1175 <setup_socket+0x45>
jmp    1180 <setup_socket+0x50>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <setup_socket+0x65>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_socket>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <__socket_setup@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1172 <setup_socket+0x42>
mov    %eax,%ebp
mov    0x10(%rsp),%rdx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1050 <connect@plt>
cmp    $0xffffffff,%eax
je     116b <setup_socket+0x3b>
mov    %ebp,%ebx
jmp    1172 <setup_socket+0x42>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @setup_socket() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i64
%4 = alloca i32
%5 = call i32 @__socket_setup(%struct.sockaddr_un* %2, i64* %3)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
br label %21
9: ; preds = %0
%10 = load i32, i32* %4
%11 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%12 = load i64, i64* %3
%13 = call i32 @connect(i32 %10, %struct.sockaddr* %11, i64 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %9
br label %18
16: ; preds = %9
%17 = load i32, i32* %4
store i32 %17, i32* %1
br label %23
18: ; preds = %15
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
store i32 -1, i32* %4
br label %21
21: ; preds = %18, %8
%22 = load i32, i32* %4
store i32 %22, i32* %1
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @setup_socket() {
%1 = alloca %struct.sockaddr_un
%2 = alloca i64
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i32 @__socket_setup(%struct.sockaddr_un* %1, i64* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %14, label %7
7: ; preds = %0
%8 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%9 = load i64, i64* %2
%10 = call i32 @connect(i32 %5, %struct.sockaddr* %8, i64 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @close(i32 %5)
br label %14
14: ; preds = %12, %0, %7
%15 = phi i32 [ %5, %7 ], [ -1, %0 ], [ -1, %12 ]
ret i32 %15
}