#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*/ EXIT_FAILURE;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
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);
  if (bind(socket_fd, (struct sockaddr *)&name, SUN_LEN(&name)) == -1)
    do {
      perror("bind");
      exit(EXIT_FAILURE);
    } while (0);
  if (listen(socket_fd, 5) == -1)
    do {
      perror("listen");
      exit(EXIT_FAILURE);
    } while (0);
  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    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2df3(%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   10c0 <SUN_LEN@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0xa3>
jmp    1239 <main+0x89>
lea    0xdc0(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    1288 <main+0xd8>
jmp    126e <main+0xbe>
lea    0xd90(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    128d <main+0xdd>
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10a0 <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    128d <main+0xdd>
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    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r13d
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10c0 <SUN_LEN@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     1275 <main+0xc5>
mov    %r13d,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
je     127e <main+0xce>
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <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     1230 <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
lea    0xd84(%rip),%rdi
jmp    1285 <main+0xd5>
lea    0xd80(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

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
@.str = [5 x i8] c"bind\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"listen\00"
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 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %2
br label %31
31: ; preds = %30
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; No predecessors!
br label %36
36: ; preds = %35, %2
%37 = load i32, i32* %7
%38 = call i32 @listen(i32 %37, i32 5)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %36
br label %41
41: ; preds = %40
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; No predecessors!
br label %46
46: ; preds = %45, %36
br label %47
47: ; preds = %55, %46
%48 = load i32, i32* %7
%49 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%50 = call i32 @accept(i32 %48, %struct.sockaddr* %49, i32* %11)
store i32 %50, i32* %12
%51 = load i32, i32* %12
%52 = call i32 @server(i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %12
%54 = call i32 @close(i32 %53)
br label %55
55: ; preds = %47
%56 = load i32, i32* %9
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
br i1 %58, label %47, label %59
59: ; preds = %55
%60 = load i32, i32* %7
%61 = call i32 @close(i32 %60)
%62 = load i8*, i8** %6
%63 = call i32 @unlink(i8* %62)
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
@.str = [5 x i8] c"bind\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"listen\00"
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 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = call i32 @listen(i32 %11, i32 5)
%25 = icmp eq i32 %24, -1
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = bitcast %struct.sockaddr_un* %4 to i8*
%28 = bitcast i32* %5 to i8*
%29 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
br label %34
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26, %34
%35 = call i32 @accept(i32 %11, %struct.sockaddr* %29, i32* %5)
%36 = call i32 @server(i32 %35)
%37 = call i32 @close(i32 %35)
%38 = icmp eq i32 %36, 0
br i1 %38, label %34, label %39
39: ; preds = %34
%40 = call i32 @close(i32 %11)
%41 = call i32 @unlink(i8* %7)
ret i32 0
}