#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 */
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ listen(int, int);
scalar_t__ sockaddrpathfill(struct sockaddr_un *, char const *);
int unixlisten(int sock, const char *path, int queue) {
  struct sockaddr_un sa;
  if (sockaddrpathfill(&sa, path) < 0) {
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr_un)) < 0) {
    return -1;
  }
  if (listen(sock, queue) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<unixlisten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1040 <sockaddrpathfill@plt>
cmp    $0x0,%rax
jge    1165 <unixlisten+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <unixlisten+0x84>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    118c <unixlisten+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <unixlisten+0x84>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <listen@plt>
cmp    $0x0,%rax
jge    11ad <unixlisten+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <unixlisten+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unixlisten>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %edi,%ebp
lea    0x8(%rsp),%rdi
call   1040 <sockaddrpathfill@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     1178 <unixlisten+0x48>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <bind@plt>
test   %rax,%rax
js     1178 <unixlisten+0x48>
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <listen@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
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 }
define i32 @unixlisten(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = call i64 @sockaddrpathfill(%struct.sockaddr_un* %8, i8* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %26
13: ; preds = %3
%14 = load i32, i32* %5
%15 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%16 = call i64 @bind(i32 %14, %struct.sockaddr* %15, i32 4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %4
br label %26
19: ; preds = %13
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = call i64 @listen(i32 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %4
br label %26
25: ; preds = %19
store i32 0, i32* %4
br label %26
26: ; preds = %25, %24, %18, %12
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @unixlisten(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_un
%5 = bitcast %struct.sockaddr_un* %4 to i8*
%6 = call i64 @sockaddrpathfill(%struct.sockaddr_un* %4, i8* %1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %3
%9 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%10 = call i64 @bind(i32 %0, %struct.sockaddr* %9, i32 4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = call i64 @listen(i32 %0, i32 %2)
%14 = ashr i64 %13, 63
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %12, %8, %3
%17 = phi i32 [ -1, %3 ], [ -1, %8 ], [ %15, %12 ]
ret i32 %17
}