#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_family;
  int /*<<< orphan*/ sun_path;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ E2BIG;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int listen(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(char *);
int /*<<< orphan*/ unlink(char *);
int createServerChannel(char *path) {
  int sfd;
  struct sockaddr_un sa;
  if (path == NULL || strlen(path) == 0)
    return -1;
  if (strlen(path) > 108) {
    errno = E2BIG;
    return -1;
  }
  if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
    return -1;
  strcpy(sa.sun_path, path);
  sa.sun_family = AF_UNIX;
  if (bind(sfd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
    close(sfd);
    return -1;
  }
  if (listen(sfd, SOMAXCONN) == -1) {
    close(sfd);
    (void)unlink(path);
    return -1;
  }
  return sfd;
}


x86 assembly (clang, -O0):
<createServerChannel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <createServerChannel+0x29>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    11a5 <createServerChannel+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <createServerChannel+0x119>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x6c,%eax
jle    11d5 <createServerChannel+0x65>
mov    0x2e2a(%rip),%rax
mov    (%rax),%ecx
mov    0x2df9(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <createServerChannel+0x119>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1206 <createServerChannel+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <createServerChannel+0x119>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    124c <createServerChannel+0xdc>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <createServerChannel+0x119>
mov    -0x14(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    1283 <createServerChannel+0x113>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <createServerChannel+0x119>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createServerChannel>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1230 <createServerChannel+0xc0>
mov    %rdi,%rbx
call   1050 <strlen@plt>
test   %eax,%eax
je     1230 <createServerChannel+0xc0>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x6d,%eax
jl     11b6 <createServerChannel+0x46>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    0x2e0e(%rip),%rcx
mov    %eax,(%rcx)
jmp    1230 <createServerChannel+0xc0>
mov    0x2e23(%rip),%r15
mov    (%r15),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     1230 <createServerChannel+0xc0>
mov    %eax,%r14d
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%r15),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     1216 <createServerChannel+0xa6>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
je     1220 <createServerChannel+0xb0>
mov    %r14d,%ebp
jmp    1230 <createServerChannel+0xc0>
mov    %r14d,%edi
call   1060 <close@plt>
jmp    1230 <createServerChannel+0xc0>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
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 }
@E2BIG = global i32 0
@errno = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@SOMAXCONN = global i32 0
define i32 @createServerChannel(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 %12, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8, %1
store i32 -1, i32* %2
br label %51
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 108
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load i32, i32* @E2BIG
store i32 %18, i32* @errno
store i32 -1, i32* %2
br label %51
19: ; preds = %13
%20 = load i32, i32* @AF_UNIX
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %4
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %2
br label %51
25: ; preds = %19
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i32 %27, i8* %28)
%30 = load i32, i32* @AF_UNIX
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* %4
%33 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 8)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = load i32, i32* %4
%38 = call i32 @close(i32 %37)
store i32 -1, i32* %2
br label %51
39: ; preds = %25
%40 = load i32, i32* %4
%41 = load i32, i32* @SOMAXCONN
%42 = call i32 @listen(i32 %40, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i32, i32* %4
%46 = call i32 @close(i32 %45)
%47 = load i8*, i8** %3
%48 = call i32 @unlink(i8* %47)
store i32 -1, i32* %2
br label %51
49: ; preds = %39
%50 = load i32, i32* %4
store i32 %50, i32* %2
br label %51
51: ; preds = %49, %44, %36, %24, %17, %12
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@E2BIG = global i32 0
@errno = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@SOMAXCONN = global i32 0
define i32 @createServerChannel(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 %34, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %34, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 108
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* @E2BIG
store i32 %12, i32* @errno
br label %34
13: ; preds = %8
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %34, label %18
18: ; preds = %13
%19 = tail call i32 @strcpy(i32 undef, i8* %0)
%20 = load i32, i32* @AF_UNIX
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%23 = call i32 @bind(i32 %16, %struct.sockaddr* %22, i32 8)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @close(i32 %16)
br label %34
27: ; preds = %18
%28 = load i32, i32* @SOMAXCONN
%29 = call i32 @listen(i32 %16, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @close(i32 %16)
%33 = call i32 @unlink(i8* %0)
br label %34
34: ; preds = %27, %13, %1, %5, %31, %25, %11
%35 = phi i32 [ -1, %11 ], [ -1, %25 ], [ -1, %31 ], [ -1, %5 ], [ -1, %1 ], [ -1, %13 ], [ %16, %27 ]
ret i32 %35
}