#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;
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int anetCreateSocket(char *, int /*<<< orphan*/);
int anetListen(char *, int, struct sockaddr *, int, int);
int /*<<< orphan*/ chmod(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int anetUnixServer(char *err, char *path, mode_t perm, int backlog) {
  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), backlog) == -1)
    return -1;
  if (perm)
    chmod(sa.sun_path, perm);
  return s;
}


x86 assembly (clang, -O0):
<anetUnixServer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1060 <anetCreateSocket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1190 <anetUnixServer+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <anetUnixServer+0xb6>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%r8d
mov    $0x8,%ecx
call   1040 <anetListen@plt>
cmp    $0xffffffff,%eax
jne    11eb <anetUnixServer+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <anetUnixServer+0xb6>
cmpl   $0x0,-0x1c(%rbp)
je     1200 <anetUnixServer+0xb0>
mov    -0x30(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1070 <chmod@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetUnixServer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,0x14(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
mov    0x2e76(%rip),%r14
mov    (%r14),%esi
call   1060 <anetCreateSocket@plt>
mov    $0xffffffff,%r12d
cmp    $0xffffffff,%eax
je     11e0 <anetUnixServer+0x90>
mov    %eax,%ebp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %r13,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
lea    0x8(%rsp),%rdx
mov    $0x8,%ecx
mov    %r15d,%r8d
call   1040 <anetListen@plt>
cmp    $0xffffffff,%eax
je     11e0 <anetUnixServer+0x90>
mov    0x14(%rsp),%esi
test   %esi,%esi
je     11dd <anetUnixServer+0x8d>
mov    0x8(%rsp),%edi
call   1070 <chmod@plt>
mov    %ebp,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_un
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = load i32, i32* @AF_LOCAL
%14 = call i32 @anetCreateSocket(i8* %12, i32 %13)
store i32 %14, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %42
17: ; preds = %4
%18 = call i32 @memset(%struct.sockaddr_un* %11, i32 0, i32 8)
%19 = load i32, i32* @AF_LOCAL
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %11, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %11, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i8*, i8** %7
%24 = call i32 @strncpy(i32 %22, i8* %23, i32 3)
%25 = load i8*, i8** %6
%26 = load i32, i32* %10
%27 = bitcast %struct.sockaddr_un* %11 to %struct.sockaddr*
%28 = load i32, i32* %9
%29 = call i32 @anetListen(i8* %25, i32 %26, %struct.sockaddr* %27, i32 8, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %32
31: ; preds = %17
store i32 -1, i32* %5
br label %42
32: ; preds = %17
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %11, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load i32, i32* %8
%39 = call i32 @chmod(i32 %37, i32 %38)
br label %40
40: ; preds = %35, %32
%41 = load i32, i32* %10
store i32 %41, i32* %5
br label %42
42: ; preds = %40, %31, %16
%43 = load i32, i32* %5
ret i32 %43
}

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, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_un
%6 = bitcast %struct.sockaddr_un* %5 to i8*
%7 = load i32, i32* @AF_LOCAL
%8 = tail call i32 @anetCreateSocket(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %25, label %10
10: ; preds = %4
%11 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 8)
%12 = load i32, i32* @AF_LOCAL
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @strncpy(i32 %15, i8* %1, i32 3)
%17 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%18 = call i32 @anetListen(i8* %0, i32 %8, %struct.sockaddr* %17, i32 8, i32 %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %25, label %20
20: ; preds = %10
%21 = icmp eq i32 %2, 0
br i1 %21, label %25, label %22
22: ; preds = %20
%23 = load i32, i32* %14
%24 = call i32 @chmod(i32 %23, i32 %2)
br label %25
25: ; preds = %20, %22, %10, %4
%26 = phi i32 [ -1, %4 ], [ -1, %10 ], [ %8, %22 ], [ %8, %20 ]
ret i32 %26
}