#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*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int uudplsn(char *path) {
  int sock;
  struct sockaddr_un addr;
  if (path == NULL)
    return -1;
  sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
  if (sock < 0) {
    return -1;
  }
  unlink(path);
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_LOCAL;
  snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
  if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<uudplsn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <uudplsn+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <uudplsn+0xbf>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a5 <uudplsn+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <uudplsn+0xbf>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
lea    0xe23(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
je     1209 <uudplsn+0xb9>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <uudplsn+0xbf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uudplsn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11d5 <uudplsn+0x85>
mov    %rdi,%rbx
mov    0x2e7d(%rip),%r15
mov    (%r15),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11d5 <uudplsn+0x85>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    (%rsp),%edi
lea    0xe50(%rip),%rdx
mov    $0x4,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1060 <bind@plt>
neg    %rax
sbb    %ebp,%ebp
or     %r14d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
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
@SOCK_DGRAM = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @uudplsn(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %33
9: ; preds = %1
%10 = load i32, i32* @AF_LOCAL
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 -1, i32* %2
br label %33
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = call i32 @unlink(i8* %17)
%19 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 8)
%20 = load i32, i32* @AF_LOCAL
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i8*, i8** %3
%25 = call i32 @snprintf(i32 %23, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %4
%27 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 8)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %16
store i32 -1, i32* %2
br label %33
31: ; preds = %16
%32 = load i32, i32* %4
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %30, %15, %8
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @uudplsn(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = load i32, i32* @AF_LOCAL
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %5
%11 = tail call i32 @unlink(i8* %0)
%12 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%13 = load i32, i32* @AF_LOCAL
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @snprintf(i32 %16, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%18 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%19 = call i64 @bind(i32 %8, %struct.sockaddr* %18, i32 8)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i32 %8, i32 -1
br label %22
22: ; preds = %10, %5, %1
%23 = phi i32 [ -1, %1 ], [ -1, %5 ], [ %21, %10 ]
ret i32 %23
}