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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int bind(int, struct sockaddr *, int);
scalar_t__ fd_pipe(int *);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int strlen(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *);
int ns_pipe(const char *name, int fd[2]) {
  int len;
  struct sockaddr_un unix_addr;
  if (fd_pipe(fd) < 0)
    return (-1);
  unlink(name);
  memset(&unix_addr, 0, sizeof(unix_addr));
  unix_addr.sun_family = AF_UNIX;
  strcpy(unix_addr.sun_path, name);
  len = strlen(unix_addr.sun_path) + sizeof(unix_addr.sun_family);
  return (bind(fd[0], (struct sockaddr *)&unix_addr, len));
}


x86 assembly (clang, -O0):
<ns_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <fd_pipe@plt>
cmp    $0x0,%rax
jge    118f <ns_pipe+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <ns_pipe+0x86>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%edi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <bind@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ns_pipe>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1070 <fd_pipe@plt>
test   %rax,%rax
js     11ca <ns_pipe+0x6a>
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x8(%rsp),%edi
call   1050 <strlen@plt>
lea    0x4(%rax),%edx
mov    (%r14),%edi
mov    %r15,%rsi
call   1080 <bind@plt>
jmp    11cf <ns_pipe+0x6f>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
define i32 @ns_pipe(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = call i64 @fd_pipe(i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %34
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @unlink(i8* %13)
%15 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 8)
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i32 %19, i8* %20)
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strlen(i32 %23)
%25 = sext i32 %24 to i64
%26 = add i64 %25, 4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
%28 = load i32*, i32** %5
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%32 = load i32, i32* %6
%33 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 %32)
store i32 %33, i32* %3
br label %34
34: ; preds = %12, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
define i32 @ns_pipe(i8* %0, i32* %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = tail call i64 @fd_pipe(i32* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = tail call i32 @unlink(i8* %0)
%9 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%10 = load i32, i32* @AF_UNIX
%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 @strcpy(i32 %13, i8* %0)
%15 = load i32, i32* %12
%16 = call i32 @strlen(i32 %15)
%17 = add i32 %16, 4
%18 = load i32, i32* %1
%19 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%20 = call i32 @bind(i32 %18, %struct.sockaddr* %19, i32 %17)
br label %21
21: ; preds = %2, %7
%22 = phi i32 [ %20, %7 ], [ -1, %2 ]
ret i32 %22
}