#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;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int accept(int, struct sockaddr_un *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr_un *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ listen(int, int);
int server(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *const);
int /*<<< orphan*/ unlink(char const *const);
int main(int argc, char *const argv[]) {
  const char *const socket_name = argv[1];
  int socket_fd;
  struct sockaddr_un name;
  int client_sent_quit_message;
  socket_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
  name.sun_family = AF_LOCAL;
  strcpy(name.sun_path, socket_name);
  bind(socket_fd, &name, SUN_LEN(&name));
  listen(socket_fd, 5);
  do {
    struct sockaddr_un client_name;
    socklen_t client_name_len;
    int client_socket_fd;
    client_socket_fd = accept(socket_fd, &client_name, &client_name_len);
    client_sent_quit_message = server(client_socket_fd);
    close(client_socket_fd);
  } while (!client_sent_quit_message);
  close(socket_fd);
  unlink(socket_name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x28(%rbp),%rdi
call   10a0 <SUN_LEN@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%edx
lea    -0x28(%rbp),%rsi
call   1080 <bind@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
call   1060 <server@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1210 <main+0x80>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%r14
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r13d
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <SUN_LEN@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <bind@plt>
mov    %r13d,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <accept@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <server@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
test   %ebp,%ebp
je     1210 <main+0x80>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_LOCAL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca i32
%10 = alloca %struct.sockaddr_un
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %6
%16 = load i32, i32* @PF_LOCAL
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %7
%19 = load i32, i32* @AF_LOCAL
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i8*, i8** %6
%24 = call i32 @strcpy(i32 %22, i8* %23)
%25 = load i32, i32* %7
%26 = call i32 @SUN_LEN(%struct.sockaddr_un* %8)
%27 = call i32 @bind(i32 %25, %struct.sockaddr_un* %8, i32 %26)
%28 = load i32, i32* %7
%29 = call i32 @listen(i32 %28, i32 5)
br label %30
30: ; preds = %37, %2
%31 = load i32, i32* %7
%32 = call i32 @accept(i32 %31, %struct.sockaddr_un* %10, i32* %11)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = call i32 @server(i32 %33)
store i32 %34, i32* %9
%35 = load i32, i32* %12
%36 = call i32 @close(i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
br i1 %40, label %30, label %41
41: ; preds = %37
%42 = load i32, i32* %7
%43 = call i32 @close(i32 %42)
%44 = load i8*, i8** %6
%45 = call i32 @unlink(i8* %44)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_LOCAL = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = bitcast %struct.sockaddr_un* %3 to i8*
%9 = load i32, i32* @PF_LOCAL
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32, i32* @AF_LOCAL
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = tail call i32 @strcpy(i32 undef, i8* %7)
%15 = call i32 @SUN_LEN(%struct.sockaddr_un* %3)
%16 = call i32 @bind(i32 %11, %struct.sockaddr_un* %3, i32 %15)
%17 = call i32 @listen(i32 %11, i32 5)
%18 = bitcast %struct.sockaddr_un* %4 to i8*
%19 = bitcast i32* %5 to i8*
br label %20
20: ; preds = %20, %2
%21 = call i32 @accept(i32 %11, %struct.sockaddr_un* %4, i32* %5)
%22 = call i32 @server(i32 %21)
%23 = call i32 @close(i32 %21)
%24 = icmp eq i32 %22, 0
br i1 %24, label %20, label %25
25: ; preds = %20
%26 = call i32 @close(i32 %11)
%27 = call i32 @unlink(i8* %7)
ret i32 0
}