#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 socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int sfd, cfd;
  struct sockaddr_un my_addr, peer_addr;
  socklen_t peer_addr_size;
  sfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sfd == -1)
    do {
      perror("socket");
      exit(EXIT_FAILURE);
    } while (0);
  memset(&my_addr, 0, sizeof(struct sockaddr_un));
  my_addr.sun_family = AF_UNIX;
  strncpy(my_addr.sun_path, "/tmp/unix_bind_path",
          sizeof(my_addr.sun_path) - 1);
  if (bind(sfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr_un)) == -1)
    do {
      perror("bind");
      exit(EXIT_FAILURE);
    } while (0);
  if (listen(sfd, 50) == -1)
    do {
      perror("listen");
      exit(EXIT_FAILURE);
    } while (0);
  peer_addr_size = sizeof(struct sockaddr_un);
  cfd = accept(sfd, (struct sockaddr *)&peer_addr, &peer_addr_size);
  if (cfd == -1)
    do {
      perror("accept");
      exit(EXIT_FAILURE);
    } while (0);
  unlink("/tmp/unix_bind_path");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11eb <main+0x5b>
jmp    11d1 <main+0x41>
lea    0xe28(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xdf6(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1254 <main+0xc4>
jmp    123a <main+0xaa>
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x32,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    1289 <main+0xf9>
jmp    126f <main+0xdf>
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x8,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12cc <main+0x13c>
jmp    12b2 <main+0x122>
lea    0xd6e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd34(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e48(%rip),%r15
mov    (%r15),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1249 <main+0xb9>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%edi
lea    0xe23(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     1252 <main+0xc2>
mov    %ebx,%edi
mov    $0x32,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
je     125b <main+0xcb>
movl   $0x8,0xc(%rsp)
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1090 <accept@plt>
cmp    $0xffffffff,%eax
je     1264 <main+0xd4>
lea    0xdcf(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdb0(%rip),%rdi
jmp    126b <main+0xdb>
lea    0xdc2(%rip),%rdi
jmp    126b <main+0xdb>
lea    0xdbe(%rip),%rdi
jmp    126b <main+0xdb>
lea    0xdbc(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"/tmp/unix_bind_path\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca %struct.sockaddr_un
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %2
br label %17
17: ; preds = %16
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; No predecessors!
br label %22
22: ; preds = %21, %2
%23 = call i32 @memset(%struct.sockaddr_un* %8, i32 0, i32 8)
%24 = load i32, i32* @AF_UNIX
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @strncpy(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 3)
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 8)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %22
br label %34
34: ; preds = %33
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %22
%40 = load i32, i32* %6
%41 = call i32 @listen(i32 %40, i32 50)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %49
43: ; preds = %39
br label %44
44: ; preds = %43
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; No predecessors!
br label %49
49: ; preds = %48, %39
store i32 8, i32* %10
%50 = load i32, i32* %6
%51 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%52 = call i32 @accept(i32 %50, %struct.sockaddr* %51, i32* %10)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %61
55: ; preds = %49
br label %56
56: ; preds = %55
%57 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; No predecessors!
br label %61
61: ; preds = %60, %49
%62 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"/tmp/unix_bind_path\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = bitcast %struct.sockaddr_un* %3 to i8*
%7 = bitcast %struct.sockaddr_un* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%19 = load i32, i32* @AF_UNIX
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @strncpy(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 3)
%24 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%25 = call i32 @bind(i32 %11, %struct.sockaddr* %24, i32 8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %17
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %17
%32 = call i32 @listen(i32 %11, i32 50)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %31
store i32 8, i32* %5
%39 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%40 = call i32 @accept(i32 %11, %struct.sockaddr* %39, i32* %5)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %38
%47 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}