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

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int SOCK_STREAM;
int /*<<< orphan*/ close(int);
int listen(int, int);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int socket_local_server_bind(int, char const *, int);
int socket_local_server(const char *name, int namespaceId, int type) {
  int err;
  int s;
  s = socket(AF_LOCAL, type, 0);
  if (s < 0)
    return -1;
  err = socket_local_server_bind(s, name, namespaceId);
  if (err < 0) {
    close(s);
    return -1;
  }
  if (type == SOCK_STREAM) {
    int ret;
    ret = listen(s, 4);
    if (ret < 0) {
      close(s);
      return -1;
    }
  }
  return s;
}


x86 assembly (clang, -O0):
<socket_local_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    117e <socket_local_server+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <socket_local_server+0xb9>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <socket_local_server_bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ae <socket_local_server+0x6e>
mov    -0x20(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <socket_local_server+0xb9>
mov    -0x18(%rbp),%eax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%eax
jne    11f3 <socket_local_server+0xb3>
mov    -0x20(%rbp),%edi
mov    $0x4,%esi
call   1050 <listen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ee <socket_local_server+0xae>
mov    -0x20(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <socket_local_server+0xb9>
jmp    11f3 <socket_local_server+0xb3>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_local_server>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r12
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    %edx,%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     11a6 <socket_local_server+0x66>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <socket_local_server_bind@plt>
test   %eax,%eax
js     119f <socket_local_server+0x5f>
mov    0x2e52(%rip),%rax
cmp    %ebx,(%rax)
jne    119a <socket_local_server+0x5a>
mov    %ebp,%edi
mov    $0x4,%esi
call   1050 <listen@plt>
test   %eax,%eax
js     119f <socket_local_server+0x5f>
mov    %ebp,%r14d
jmp    11a6 <socket_local_server+0x66>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
define i32 @socket_local_server(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* @AF_LOCAL
%12 = load i32, i32* %7
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %42
17: ; preds = %3
%18 = load i32, i32* %9
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i32 @socket_local_server_bind(i32 %18, i8* %19, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %9
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %4
br label %42
27: ; preds = %17
%28 = load i32, i32* %7
%29 = load i32, i32* @SOCK_STREAM
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32, i32* %9
%33 = call i32 @listen(i32 %32, i32 4)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* %9
%38 = call i32 @close(i32 %37)
store i32 -1, i32* %4
br label %42
39: ; preds = %31
br label %40
40: ; preds = %39, %27
%41 = load i32, i32* %9
store i32 %41, i32* %4
br label %42
42: ; preds = %40, %36, %24, %16
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
define i32 @socket_local_server(i8* %0, i32 %1, i32 %2) {
%4 = load i32, i32* @AF_LOCAL
%5 = tail call i32 @socket(i32 %4, i32 %2, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = tail call i32 @socket_local_server_bind(i32 %5, i8* %0, i32 %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = load i32, i32* @SOCK_STREAM
%12 = icmp eq i32 %11, %2
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = tail call i32 @listen(i32 %5, i32 4)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13, %7
%17 = tail call i32 @close(i32 %5)
br label %18
18: ; preds = %16, %10, %13, %3
%19 = phi i32 [ -1, %3 ], [ %5, %13 ], [ %5, %10 ], [ -1, %16 ]
ret i32 %19
}