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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(scalar_t__ *, char *, char const *);
int anonsocket(const char *name) {
  int fd;
  struct sockaddr_un sun;
  memset(&sun, 0, sizeof(sun));
  sun.sun_family = AF_UNIX;
  sun.sun_path[0] = 0;
  sprintf(sun.sun_path + 1, "%s", name);
  if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    return -1;
  }
  if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
    return -2;
  }
  if (listen(fd, 5) < 0) {
    return -3;
  }
  return fd;
}


x86 assembly (clang, -O0):
<anonsocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x8,%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6a(%rip),%rsi
call   1060 <sprintf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11cc <anonsocket+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    121c <anonsocket+0xcc>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    11f3 <anonsocket+0xa3>
movl   $0xfffffffe,-0x4(%rbp)
jmp    121c <anonsocket+0xcc>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1040 <listen@plt>
cmp    $0x0,%rax
jge    1216 <anonsocket+0xc6>
movl   $0xfffffffd,-0x4(%rbp)
jmp    121c <anonsocket+0xcc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anonsocket>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,0x10(%rsp)
mov    0x8(%rsp),%rdi
movq   $0x0,(%rdi)
add    $0x8,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11d6 <anonsocket+0x86>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     11dd <anonsocket+0x8d>
mov    %ebx,%edi
mov    $0x5,%esi
call   1050 <listen@plt>
test   %rax,%rax
mov    $0xfffffffd,%eax
cmovs  %eax,%ebx
jmp    11e2 <anonsocket+0x92>
mov    $0xffffffff,%ebx
jmp    11e2 <anonsocket+0x92>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i64*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@.str = [3 x i8] c"%s\00"
@SOCK_STREAM = global i32 0
define i32 @anonsocket(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
store i8* %0, i8** %3
%6 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 16)
%7 = load i32, i32* @AF_UNIX
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%10 = load i64*, i64** %9
%11 = getelementptr inbounds i64, i64* %10, i64 0
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%13 = load i64*, i64** %12
%14 = getelementptr inbounds i64, i64* %13, i64 1
%15 = load i8*, i8** %3
%16 = call i32 @sprintf(i64* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @AF_UNIX
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %1
store i32 -1, i32* %2
br label %35
22: ; preds = %1
%23 = load i32, i32* %4
%24 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%25 = call i64 @bind(i32 %23, %struct.sockaddr* %24, i32 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -2, i32* %2
br label %35
28: ; preds = %22
%29 = load i32, i32* %4
%30 = call i64 @listen(i32 %29, i32 5)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -3, i32* %2
br label %35
33: ; preds = %28
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %32, %27, %21
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i64*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @anonsocket(i8* nocapture %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 16)
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%8 = load i64*, i64** %7
store i64 0, i64* %8
%9 = getelementptr inbounds i64, i64* %8, i64 1
%10 = bitcast i64* %9 to i8*
%11 = call i64* @strcpy(i8* %10, i8* dereferenceable(1) %0)
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %5, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %1
%16 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%17 = call i64 @bind(i32 %13, %struct.sockaddr* %16, i32 16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = call i64 @listen(i32 %13, i32 5)
%21 = icmp slt i64 %20, 0
%22 = select i1 %21, i32 -3, i32 %13
br label %23
23: ; preds = %19, %15, %1
%24 = phi i32 [ -1, %1 ], [ -2, %15 ], [ %22, %19 ]
ret i32 %24
}