#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_LOCAL;
int anetCreateSocket(char *, int /*<<< orphan*/);
int anetListen(char *, int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int anetUnixServer(char *err, char *path) {
  int s;
  struct sockaddr_un sa;
  if ((s = anetCreateSocket(err, AF_LOCAL)) == -1)
    return -1;
  memset(&sa, 0, sizeof(sa));
  sa.sun_family = AF_LOCAL;
  strncpy(sa.sun_path, path, sizeof(sa.sun_path) - 1);
  if (anetListen(err, s, (struct sockaddr *)&sa, sizeof(sa)) == -1)
    return -1;
  return s;
}


x86 assembly (clang, -O0):
<anetUnixServer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1060 <anetCreateSocket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    117a <anetUnixServer+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <anetUnixServer+0x97>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x28(%rbp),%rdx
mov    $0x8,%ecx
call   1040 <anetListen@plt>
cmp    $0xffffffff,%eax
jne    11d1 <anetUnixServer+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <anetUnixServer+0x97>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetUnixServer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e8e(%rip),%r13
mov    0x0(%r13),%esi
call   1060 <anetCreateSocket@plt>
cmp    $0xffffffff,%eax
je     11b1 <anetUnixServer+0x71>
mov    %eax,%ebx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x0(%r13),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    $0x8,%ecx
call   1040 <anetListen@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
jmp    11b6 <anetUnixServer+0x76>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i32 0
define i32 @anetUnixServer(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @AF_LOCAL
%10 = call i32 @anetCreateSocket(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %29
13: ; preds = %2
%14 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 8)
%15 = load i32, i32* @AF_LOCAL
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i8*, i8** %5
%20 = call i32 @strncpy(i32 %18, i8* %19, i32 3)
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%24 = call i32 @anetListen(i8* %21, i32 %22, %struct.sockaddr* %23, i32 8)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %13
store i32 -1, i32* %3
br label %29
27: ; preds = %13
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %26, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i32 0
define i32 @anetUnixServer(i8* %0, i8* %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = load i32, i32* @AF_LOCAL
%6 = tail call i32 @anetCreateSocket(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%10 = load i32, i32* @AF_LOCAL
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @strncpy(i32 %13, i8* %1, i32 3)
%15 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%16 = call i32 @anetListen(i8* %0, i32 %6, %struct.sockaddr* %15, i32 8)
%17 = icmp eq i32 %16, -1
%18 = select i1 %17, i32 -1, i32 %6
br label %19
19: ; preds = %8, %2
%20 = phi i32 [ -1, %2 ], [ %18, %8 ]
ret i32 %20
}