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

/* Variables and functions */
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int set_non_blocking(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ unlink(char const *);
int __setup_control_path(const char *path) {
  int ss;
  struct sockaddr_un sun;
  ss = socket(PF_UNIX, SOCK_STREAM, 0);
  if (ss == -1) {
    perror("socket");
    return -1;
  }
  if (set_non_blocking(ss) == -1) {
    return -1;
  }
  memset(&sun, 0, sizeof(sun));
  sun.sun_family = PF_UNIX;
  strcpy(sun.sun_path, path);
  unlink(path);
  if (bind(ss, (struct sockaddr *)&sun, sizeof(sun)) != 0) {
    perror("bind");
    goto on_error;
  }
  if (listen(ss, 5) != 0) {
    perror("listen");
    goto on_error;
  }
  return ss;
on_error:
  close(ss);
  return -1;
}


x86 assembly (clang, -O0):
<__setup_control_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11da <__setup_control_path+0x4a>
lea    0xe37(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <__setup_control_path+0x106>
mov    -0x14(%rbp),%edi
call   10a0 <set_non_blocking@plt>
cmp    $0xffffffff,%eax
jne    11f7 <__setup_control_path+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <__setup_control_path+0x106>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
je     1254 <__setup_control_path+0xc4>
lea    0xdbd(%rip),%rdi
call   1090 <perror@plt>
jmp    1287 <__setup_control_path+0xf7>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
je     127c <__setup_control_path+0xec>
lea    0xd9a(%rip),%rdi
call   1090 <perror@plt>
jmp    1287 <__setup_control_path+0xf7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1296 <__setup_control_path+0x106>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__setup_control_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e52(%rip),%r12
mov    (%r12),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     123b <__setup_control_path+0xab>
mov    %eax,%ebp
mov    %eax,%edi
call   10a0 <set_non_blocking@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     122b <__setup_control_path+0x9b>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    (%r12),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
test   %rax,%rax
jne    124f <__setup_control_path+0xbf>
mov    %ebp,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
test   %rax,%rax
jne    1258 <__setup_control_path+0xc8>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbe(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%r14d
jmp    122b <__setup_control_path+0x9b>
lea    0xdb1(%rip),%rdi
jmp    125f <__setup_control_path+0xcf>
lea    0xdad(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    122b <__setup_control_path+0x9b>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
define i32 @__setup_control_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
store i8* %0, i8** %3
%6 = load i32, i32* @PF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call i32 @set_non_blocking(i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %2
br label %45
18: ; preds = %13
%19 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 8)
%20 = load i32, i32* @PF_UNIX
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i8*, i8** %3
%25 = call i32 @strcpy(i32 %23, i8* %24)
%26 = load i8*, i8** %3
%27 = call i32 @unlink(i8* %26)
%28 = load i32, i32* %4
%29 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%30 = call i64 @bind(i32 %28, %struct.sockaddr* %29, i32 8)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %18
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %42
34: ; preds = %18
%35 = load i32, i32* %4
%36 = call i64 @listen(i32 %35, i32 5)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %42
40: ; preds = %34
%41 = load i32, i32* %4
store i32 %41, i32* %2
br label %45
42: ; preds = %38, %32
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
store i32 -1, i32* %2
br label %45
45: ; preds = %42, %40, %17, %11
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
define i32 @__setup_control_path(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = load i32, i32* @PF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %31
10: ; preds = %1
%11 = tail call i32 @set_non_blocking(i32 %6)
%12 = icmp eq i32 %11, -1
br i1 %12, label %31, label %13
13: ; preds = %10
%14 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%15 = load i32, i32* @PF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @strcpy(i32 %18, i8* %0)
%20 = call i32 @unlink(i8* %0)
%21 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%22 = call i64 @bind(i32 %6, %struct.sockaddr* %21, i32 8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = call i64 @listen(i32 %6, i32 5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %24, %13
%28 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %24 ]
%29 = call i32 @perror(i8* %28)
%30 = call i32 @close(i32 %6)
br label %31
31: ; preds = %24, %10, %27, %8
%32 = phi i32 [ -1, %8 ], [ -1, %27 ], [ -1, %10 ], [ %6, %24 ]
ret i32 %32
}