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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ unlink(char const *);
int init_listen_server(const char *domain_name) {
  int lsn_fd;
  struct sockaddr_un srv_addr;
  int ret;
  lsn_fd = socket(PF_UNIX, SOCK_STREAM, 0);
  if (lsn_fd < 0) {
    perror("can't create communication socket!");
    return -1;
  }
  srv_addr.sun_family = AF_UNIX;
  strncpy(srv_addr.sun_path, domain_name, sizeof(srv_addr.sun_path) - 1);
  unlink(domain_name);
  ret = bind(lsn_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
  if (ret == -1) {
    perror("can't bind local sockaddr!");
    close(lsn_fd);
    unlink(domain_name);
    return -1;
  }
  ret = listen(lsn_fd, 1);
  if (ret == -1) {
    perror("can't listen client connect request");
    close(lsn_fd);
    unlink(domain_name);
    return -1;
  }
  return lsn_fd;
}


x86 assembly (clang, -O0):
<init_listen_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ba <init_listen_server+0x4a>
lea    0xe57(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <init_listen_server+0x100>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1227 <init_listen_server+0xb7>
lea    0xe1e(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <init_listen_server+0x100>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1060 <listen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    126a <init_listen_server+0xfa>
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <init_listen_server+0x100>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_listen_server>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     11e5 <init_listen_server+0x75>
mov    %eax,%ebp
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     11f3 <init_listen_server+0x83>
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
je     11fc <init_listen_server+0x8c>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe14(%rip),%rdi
call   1080 <perror@plt>
jmp    1217 <init_listen_server+0xa7>
lea    0xe29(%rip),%rdi
jmp    1203 <init_listen_server+0x93>
lea    0xe3b(%rip),%rdi
call   1080 <perror@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%ebp
jmp    11dc <init_listen_server+0x6c>

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

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [35 x i8] c"can't create communication socket!\00"
@AF_UNIX = global i32 0
@.str.1 = [27 x i8] c"can't bind local sockaddr!\00"
@.str.2 = [36 x i8] c"can't listen client connect request\00"
define i32 @init_listen_server(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 slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %29
10: ; preds = %1
%11 = load i32, i32* @AF_UNIX
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %11, i32* %12
%13 = tail call i32 @strncpy(i32 undef, i8* %0, i32 3)
%14 = tail call i32 @unlink(i8* %0)
%15 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%16 = call i32 @bind(i32 %6, %struct.sockaddr* %15, i32 8)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @close(i32 %6)
%21 = call i32 @unlink(i8* %0)
br label %29
22: ; preds = %10
%23 = call i32 @listen(i32 %6, i32 1)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @close(i32 %6)
%28 = call i32 @unlink(i8* %0)
br label %29
29: ; preds = %22, %25, %18, %8
%30 = phi i32 [ -1, %8 ], [ -1, %18 ], [ -1, %25 ], [ %6, %22 ]
ret i32 %30
}