#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*/ 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 *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, 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, (struct sockaddr *)&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, (struct sockaddr *)&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,-0x4c(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x28(%rbp),%rdi
call   10a0 <SUN_LEN@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
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    1218 <main+0x88>
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 }
%struct.sockaddr = type { 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 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%27 = call i32 @SUN_LEN(%struct.sockaddr_un* %8)
%28 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 %27)
%29 = load i32, i32* %7
%30 = call i32 @listen(i32 %29, i32 5)
br label %31
31: ; preds = %39, %2
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%34 = call i32 @accept(i32 %32, %struct.sockaddr* %33, i32* %11)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = call i32 @server(i32 %35)
store i32 %36, i32* %9
%37 = load i32, i32* %12
%38 = call i32 @close(i32 %37)
br label %39
39: ; preds = %31
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
%42 = xor i1 %41, true
br i1 %42, label %31, label %43
43: ; preds = %39
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
%46 = load i8*, i8** %6
%47 = call i32 @unlink(i8* %46)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { 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 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%16 = call i32 @SUN_LEN(%struct.sockaddr_un* %3)
%17 = call i32 @bind(i32 %11, %struct.sockaddr* %15, i32 %16)
%18 = call i32 @listen(i32 %11, i32 5)
%19 = bitcast %struct.sockaddr_un* %4 to i8*
%20 = bitcast i32* %5 to i8*
%21 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
br label %22
22: ; preds = %22, %2
%23 = call i32 @accept(i32 %11, %struct.sockaddr* %21, i32* %5)
%24 = call i32 @server(i32 %23)
%25 = call i32 @close(i32 %23)
%26 = icmp eq i32 %24, 0
br i1 %26, label %22, label %27
27: ; preds = %22
%28 = call i32 @close(i32 %11)
%29 = call i32 @unlink(i8* %7)
ret i32 0
}