#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int SOCK_DGRAM;
int SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ chmod(char const *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ unlink(char const *);
int InitUnixServerSocket(const char *Path, int ConType) {
  int result;
  struct sockaddr_un addr;
  int sockfd = -1, SockType;
  result = 1;
  if (ConType == 1)
    SockType = SOCK_STREAM;
  else
    SockType = SOCK_DGRAM;
  memset(&addr, 0, sizeof(struct sockaddr_un));
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, Path);
  sockfd = socket(AF_UNIX, SockType, 0);
  if (sockfd > -1) {
    unlink(Path);
    result = bind(sockfd, (struct sockaddr *)&addr, SUN_LEN(&addr));
    chmod(Path, 0666);
    if (result != 0) {
      close(sockfd);
      return (-1);
    } else {
      if (SockType == SOCK_STREAM)
        listen(sockfd, 5);
    }
  }
  return (sockfd);
}


x86 assembly (clang, -O0):
<InitUnixServerSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11c8 <InitUnixServerSocket+0x38>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    11d4 <InitUnixServerSocket+0x44>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jle    12a2 <InitUnixServerSocket+0x112>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   10a0 <SUN_LEN@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1090 <bind@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1b6,%esi
call   1080 <chmod@plt>
cmpl   $0x0,-0x18(%rbp)
je     1279 <InitUnixServerSocket+0xe9>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <InitUnixServerSocket+0x118>
mov    -0x28(%rbp),%eax
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%eax
jne    1298 <InitUnixServerSocket+0x108>
mov    -0x24(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
jmp    129d <InitUnixServerSocket+0x10d>
jmp    12a2 <InitUnixServerSocket+0x112>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InitUnixServerSocket>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
cmp    $0x1,%esi
jne    11ad <InitUnixServerSocket+0x1d>
mov    0x2e25(%rip),%rax
jmp    11b4 <InitUnixServerSocket+0x24>
mov    0x2e2c(%rip),%rax
mov    (%rax),%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e19(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    (%rbx),%edi
mov    %r14d,%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     124d <InitUnixServerSocket+0xbd>
mov    %r12,%rdi
call   1030 <unlink@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   10a0 <SUN_LEN@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1090 <bind@plt>
mov    %eax,%ebx
mov    %r12,%rdi
mov    $0x1b6,%esi
call   1080 <chmod@plt>
test   %ebx,%ebx
je     1235 <InitUnixServerSocket+0xa5>
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0xffffffff,%ebp
jmp    124d <InitUnixServerSocket+0xbd>
mov    0x2d94(%rip),%rax
cmp    (%rax),%r14d
jne    124d <InitUnixServerSocket+0xbd>
mov    %ebp,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@AF_UNIX = global i32 0
define i32 @InitUnixServerSocket(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 -1, i32* %8
store i32 1, i32* %6
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @SOCK_STREAM
store i32 %13, i32* %9
br label %16
14: ; preds = %2
%15 = load i32, i32* @SOCK_DGRAM
store i32 %15, i32* %9
br label %16
16: ; preds = %14, %12
%17 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 8)
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i32 %21, i8* %22)
%24 = load i32, i32* @AF_UNIX
%25 = load i32, i32* %9
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp sgt i32 %27, -1
br i1 %28, label %29, label %52
29: ; preds = %16
%30 = load i8*, i8** %4
%31 = call i32 @unlink(i8* %30)
%32 = load i32, i32* %8
%33 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%34 = call i32 @SUN_LEN(%struct.sockaddr_un* %7)
%35 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 %34)
store i32 %35, i32* %6
%36 = load i8*, i8** %4
%37 = call i32 @chmod(i8* %36, i32 438)
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* %8
%42 = call i32 @close(i32 %41)
store i32 -1, i32* %3
br label %54
43: ; preds = %29
%44 = load i32, i32* %9
%45 = load i32, i32* @SOCK_STREAM
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %8
%49 = call i32 @listen(i32 %48, i32 5)
br label %50
50: ; preds = %47, %43
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51, %16
%53 = load i32, i32* %8
store i32 %53, i32* %3
br label %54
54: ; preds = %52, %40
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@AF_UNIX = global i32 0
define i32 @InitUnixServerSocket(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = icmp eq i32 %1, 1
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @SOCK_DGRAM
%8 = select i1 %5, i32 %6, i32 %7
%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* @AF_UNIX
%16 = call i32 @socket(i32 %15, i32 %8, i32 0)
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %32
18: ; preds = %2
%19 = call i32 @unlink(i8* %0)
%20 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%21 = call i32 @SUN_LEN(%struct.sockaddr_un* %3)
%22 = call i32 @bind(i32 %16, %struct.sockaddr* %20, i32 %21)
%23 = call i32 @chmod(i8* %0, i32 438)
%24 = icmp eq i32 %22, 0
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = call i32 @close(i32 %16)
br label %32
27: ; preds = %18
%28 = load i32, i32* @SOCK_STREAM
%29 = icmp eq i32 %8, %28
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @listen(i32 %16, i32 5)
br label %32
32: ; preds = %2, %27, %30, %25
%33 = phi i32 [ -1, %25 ], [ %16, %30 ], [ %16, %27 ], [ %16, %2 ]
ret i32 %33
}