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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int listen(int, int);
int /*<<< orphan*/ logerr(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/ *, char *, int);
int init_daemon_socket(void) {
  int s, r;
  struct sockaddr_un un_daemon;
  memset(&un_daemon, 0x00, sizeof(struct sockaddr_un));
  un_daemon.sun_family = AF_UNIX;
  strncpy(&un_daemon.sun_path[1], "/var/run/drcomcd",
          sizeof(un_daemon.sun_path) - 1);
  s = socket(PF_UNIX, SOCK_STREAM, 0);
  if (s == -1) {
    logerr("drcomd: Socket creation failed: %s\n", strerror(errno));
    return -1;
  }
  r = bind(s, (struct sockaddr *)&un_daemon, sizeof(un_daemon));
  if (r) {
    logerr("drcomd: Bind failed: %s\n", strerror(errno));
    return -1;
  }
  r = listen(s, 1);
  if (r) {
    logerr("drcomd: Listen failed: %s\n", strerror(errno));
    return -1;
  }
  return s;
}


x86 assembly (clang, -O0):
<init_daemon_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
lea    0xe5d(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11fb <init_daemon_socket+0x8b>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
call   1050 <logerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <init_daemon_socket+0x119>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1241 <init_daemon_socket+0xd1>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xe05(%rip),%rdi
call   1050 <logerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <init_daemon_socket+0x119>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <listen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1283 <init_daemon_socket+0x113>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xddc(%rip),%rdi
call   1050 <logerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <init_daemon_socket+0x119>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_daemon_socket>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rdi
add    $0x4,%rdi
lea    0xe60(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11e6 <init_daemon_socket+0x76>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1070 <bind@plt>
test   %eax,%eax
je     11ef <init_daemon_socket+0x7f>
lea    0xe51(%rip),%rbx
jmp    1206 <init_daemon_socket+0x96>
lea    0xe24(%rip),%rbx
jmp    1206 <init_daemon_socket+0x96>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <listen@plt>
test   %eax,%eax
je     1223 <init_daemon_socket+0xb3>
lea    0xe48(%rip),%rbx
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <logerr@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [17 x i8] c"/var/run/drcomcd\00"
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [36 x i8] c"drcomd: Socket creation failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [25 x i8] c"drcomd: Bind failed: %s\0A\00"
@.str.3 = [27 x i8] c"drcomd: Listen failed: %s\0A\00"
define i32 @init_daemon_socket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i32 16)
%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 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = call i32 @strncpy(i32* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 7)
%12 = load i32, i32* @PF_UNIX
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @logerr(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 -1, i32* %1
br label %42
21: ; preds = %0
%22 = load i32, i32* %2
%23 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%24 = call i32 @bind(i32 %22, %struct.sockaddr* %23, i32 16)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @logerr(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %29)
store i32 -1, i32* %1
br label %42
31: ; preds = %21
%32 = load i32, i32* %2
%33 = call i32 @listen(i32 %32, i32 1)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 @logerr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %38)
store i32 -1, i32* %1
br label %42
40: ; preds = %31
%41 = load i32, i32* %2
store i32 %41, i32* %1
br label %42
42: ; preds = %40, %36, %27, %17
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [17 x i8] c"/var/run/drcomcd\00"
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [36 x i8] c"drcomd: Socket creation failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [25 x i8] c"drcomd: Bind failed: %s\0A\00"
@.str.3 = [27 x i8] c"drcomd: Listen failed: %s\0A\00"
define i32 @init_daemon_socket() {
%1 = alloca %struct.sockaddr_un
%2 = bitcast %struct.sockaddr_un* %1 to i8*
%3 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 16)
%4 = load i32, i32* @AF_UNIX
%5 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %4, i32* %5
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%7 = load i32*, i32** %6
%8 = getelementptr inbounds i32, i32* %7, i64 1
%9 = call i32 @strncpy(i32* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = load i32, i32* @PF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %21, label %14
14: ; preds = %0
%15 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%16 = call i32 @bind(i32 %12, %struct.sockaddr* %15, i32 16)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @listen(i32 %12, i32 1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18, %14, %0
%22 = phi i8* [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), %18 ]
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @logerr(i8* %22, i32 %24)
br label %26
26: ; preds = %21, %18
%27 = phi i32 [ %12, %18 ], [ -1, %21 ]
ret i32 %27
}