#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*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ assert(int);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int strlen(char const *);
int un__socket();
int /*<<< orphan*/ unlink(int /*<<< orphan*/);
int un_listen(const char *path) {
  int fd;
  struct sockaddr_un sa;
  fd = un__socket();
  sa.sun_family = AF_UNIX;
  assert(strlen(path) < sizeof(sa.sun_path));
  strcpy(sa.sun_path, path);
  unlink(sa.sun_path);
  if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
    perror("bind");
    exit(1);
  }
  if (listen(fd, 5) == -1) {
    perror("listen");
    exit(1);
  }
  return fd;
}


x86 assembly (clang, -O0):
<un_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   10b0 <un__socket@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
cmp    $0x4,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%edi
call   1030 <unlink@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    1212 <un_listen+0x82>
lea    0xdfd(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    123e <un_listen+0xae>
lea    0xdd6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<un_listen>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   10b0 <un__socket@plt>
mov    %eax,%ebp
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    $0x4,%eax
setb   %dil
call   1060 <assert@plt>
mov    %rbx,%rsi
call   1040 <strcpy@plt>
call   1030 <unlink@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     11fd <un_listen+0x6d>
mov    %ebp,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
je     1206 <un_listen+0x76>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdfc(%rip),%rdi
jmp    120d <un_listen+0x7d>
lea    0xdf8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [5 x i8] c"bind\00"
@.str.1 = [7 x i8] c"listen\00"
define i32 @un_listen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
store i8* %0, i8** %2
%5 = call i32 (...) @un__socket()
store i32 %5, i32* %3
%6 = load i32, i32* @AF_UNIX
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = icmp ult i64 %10, 4
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i32 %15, i8* %16)
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @unlink(i32 %19)
%21 = load i32, i32* %3
%22 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 8)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %1
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %1
%29 = load i32, i32* %3
%30 = call i32 @listen(i32 %29, i32 5)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [5 x i8] c"bind\00"
@.str.1 = [7 x i8] c"listen\00"
define i32 @un_listen(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = tail call i32 (...) @un__socket()
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp ult i32 %7, 4
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @strcpy(i32 undef, i8* %0)
%12 = tail call i32 @unlink(i32 undef)
%13 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%14 = call i32 @bind(i32 %4, %struct.sockaddr* %13, i32 8)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
%20 = call i32 @listen(i32 %4, i32 5)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %19
ret i32 %4
}