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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, char, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int create_admin_socket(char *socket_path) {
  int sockfd;
  struct sockaddr_un client_addr;
  sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sockfd < 0)
    fprintf(stderr, "Error creating admin socket\n");
  memset(&client_addr, '\0', sizeof(client_addr));
  client_addr.sun_family = AF_UNIX;
  strcpy(client_addr.sun_path, socket_path);
  unlink(socket_path);
  if (bind(sockfd, (struct sockaddr *)&client_addr, sizeof(client_addr)) < 0)
    fprintf(stderr, "Error binding: %s: %s\n", socket_path, strerror(errno));
  if (listen(sockfd, 5) < 0)
    fprintf(stderr, "Error listening on %s\n", socket_path);
  return sockfd;
}


x86 assembly (clang, -O0):
<create_admin_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c9 <create_admin_socket+0x49>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    124f <create_admin_socket+0xcf>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    1281 <create_admin_socket+0x101>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_admin_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e57(%rip),%r15
mov    (%r15),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11c1 <create_admin_socket+0x41>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    (%rsp),%edi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1080 <bind@plt>
test   %rax,%rax
jns    122e <create_admin_socket+0xae>
mov    0x2dd0(%rip),%rax
mov    (%rax),%ebx
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfe(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
test   %rax,%rax
jns    1259 <create_admin_socket+0xd9>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@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 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Error creating admin socket\0A\00"
@.str.1 = [23 x i8] c"Error binding: %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Error listening on %s\0A\00"
define i32 @create_admin_socket(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
store i8* %0, i8** %2
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
%14 = call i32 @memset(%struct.sockaddr_un* %4, i8 signext 0, i32 8)
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i8*, i8** %2
%20 = call i32 @strcpy(i32 %18, i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @unlink(i8* %21)
%23 = load i32, i32* %3
%24 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%25 = call i64 @bind(i32 %23, %struct.sockaddr* %24, i32 8)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %13
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %2
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %31)
br label %33
33: ; preds = %27, %13
%34 = load i32, i32* %3
%35 = call i64 @listen(i32 %34, i32 5)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %2
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %37, %33
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Error creating admin socket\0A\00"
@.str.1 = [23 x i8] c"Error binding: %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Error listening on %s\0A\00"
define i32 @create_admin_socket(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %1
%12 = call i32 @memset(%struct.sockaddr_un* %2, i8 signext 0, i32 8)
%13 = load i32, i32* @AF_UNIX
%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 @strcpy(i32 %16, i8* %0)
%18 = call i32 @unlink(i8* %0)
%19 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%20 = call i64 @bind(i32 %6, %struct.sockaddr* %19, i32 8)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %25)
br label %27
27: ; preds = %22, %11
%28 = call i64 @listen(i32 %6, i32 5)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %33
33: ; preds = %30, %27
ret i32 %6
}