#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 connect(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/ *, char *, int);
int init_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) {
    perror("drcomc: Socket creation");
    return -1;
  }
  r = connect(s, (struct sockaddr *)&un_daemon, sizeof(un_daemon));
  if (r) {
    perror("drcomc: Connect");
    return -1;
  }
  return s;
}


x86 assembly (clang, -O0):
<init_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
lea    0xe7d(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cb <init_socket+0x7b>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <init_socket+0xb7>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1060 <connect@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1201 <init_socket+0xb1>
lea    0xe39(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <init_socket+0xb7>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_socket>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rdi
add    $0x4,%rdi
lea    0xe80(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     11c5 <init_socket+0x75>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1060 <connect@plt>
test   %eax,%eax
jne    11ce <init_socket+0x7e>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe45(%rip),%rdi
jmp    11d5 <init_socket+0x85>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11bd <init_socket+0x6d>

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 = [24 x i8] c"drcomc: Socket creation\00"
@.str.2 = [16 x i8] c"drcomc: Connect\00"
define i32 @init_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 %19
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %29
19: ; preds = %0
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%22 = call i32 @connect(i32 %20, %struct.sockaddr* %21, i32 16)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %29
27: ; preds = %19
%28 = load i32, i32* %2
store i32 %28, i32* %1
br label %29
29: ; preds = %27, %25, %17
%30 = load i32, i32* %1
ret i32 %30
}

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 = [24 x i8] c"drcomc: Socket creation\00"
@.str.2 = [16 x i8] c"drcomc: Connect\00"
define i32 @init_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 %18, label %14
14: ; preds = %0
%15 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%16 = call i32 @connect(i32 %12, %struct.sockaddr* %15, i32 16)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14, %0
%19 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %14 ]
%20 = call i32 @perror(i8* %19)
br label %21
21: ; preds = %18, %14
%22 = phi i32 [ %12, %14 ], [ -1, %18 ]
ret i32 %22
}