#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;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, servlen, n;
  socklen_t clilen;
  struct sockaddr_un cli_addr, serv_addr, name_addr;
  socklen_t namelen;
  char buffer[80];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s path\n", argv[0]);
    exit(2);
  }
  if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  memset((char *)&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  strcpy(serv_addr.sun_path, argv[1]);
  servlen = (sizeof(*(&serv_addr)) - sizeof((&serv_addr)->sun_path) +
             strlen((&serv_addr)->sun_path));
  if (bind(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0) {
    perror("bind");
    exit(1);
  }
  namelen = (sizeof(*(&name_addr)) - sizeof((&name_addr)->sun_path) +
             strlen((&name_addr)->sun_path));
  if (getsockname(sockfd, (struct sockaddr *)&name_addr, &namelen) < 0) {
    perror("getsockname");
    exit(1);
  }
  listen(sockfd, 1);
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
  if (newsockfd < 0) {
    perror("accept");
    exit(1);
  }
  n = read(newsockfd, buffer, 80);
  if (write(1, buffer, n) < 0) {
    perror("write(1)");
    exit(1);
  }
  if (write(newsockfd, buffer, n) < 0) {
    perror("write(newsockfd)");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1219 <main+0x49>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1254 <main+0x84>
lea    0xdcb(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%edi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12c0 <main+0xf0>
lea    0xd66(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x40(%rbp),%edi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   10d0 <getsockname@plt>
cmp    $0x0,%rax
jge    1301 <main+0x131>
lea    0xd2a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1090 <listen@plt>
movl   $0x8,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1348 <main+0x178>
lea    0xcef(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,-0x20(%rbp)
lea    -0xa0(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1393 <main+0x1c3>
lea    0xcab(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    13c5 <main+0x1f5>
lea    0xc82(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12ec <main+0x11c>
mov    0x2dfb(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     130e <main+0x13e>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    (%rsp),%edi
mov    0x8(%r14),%rsi
call   1030 <strcpy@plt>
mov    (%rsp),%edi
call   1050 <strlen@plt>
lea    0x4(%rax),%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   10a0 <bind@plt>
test   %rax,%rax
js     1317 <main+0x147>
call   1050 <strlen@plt>
add    $0x4,%eax
mov    %eax,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   10d0 <getsockname@plt>
test   %rax,%rax
js     1320 <main+0x150>
mov    %ebx,%edi
mov    $0x1,%esi
call   1090 <listen@plt>
movl   $0x8,0xc(%rsp)
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10c0 <accept@plt>
test   %eax,%eax
js     1329 <main+0x159>
mov    %eax,%ebx
lea    0x20(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1332 <main+0x162>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1040 <write@plt>
test   %rax,%rax
js     133b <main+0x16b>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd01(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    0xcfb(%rip),%rdi
jmp    1342 <main+0x172>
lea    0xcf9(%rip),%rdi
jmp    1342 <main+0x172>
lea    0xcf5(%rip),%rdi
jmp    1342 <main+0x172>
lea    0xcf8(%rip),%rdi
jmp    1342 <main+0x172>
lea    0xcf6(%rip),%rdi
jmp    1342 <main+0x172>
lea    0xcf6(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s path\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [12 x i8] c"getsockname\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [9 x i8] c"write(1)\00"
@.str.6 = [17 x i8] c"write(newsockfd)\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_un
%12 = alloca %struct.sockaddr_un
%13 = alloca %struct.sockaddr_un
%14 = alloca i32
%15 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %2
%26 = load i32, i32* @AF_UNIX
%27 = load i32, i32* @SOCK_STREAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
store i32 %28, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
%34 = bitcast %struct.sockaddr_un* %12 to i8*
%35 = call i32 @memset(i8* %34, i32 0, i32 8)
%36 = load i32, i32* @AF_UNIX
%37 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%39 = load i32, i32* %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @strcpy(i32 %39, i8* %42)
%44 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @strlen(i32 %45)
%47 = sext i32 %46 to i64
%48 = add i64 4, %47
%49 = trunc i64 %48 to i32
store i32 %49, i32* %8
%50 = load i32, i32* %6
%51 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
%52 = load i32, i32* %8
%53 = call i64 @bind(i32 %50, %struct.sockaddr* %51, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %33
%56 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %33
%59 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %13, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @strlen(i32 %60)
%62 = sext i32 %61 to i64
%63 = add i64 4, %62
%64 = trunc i64 %63 to i32
store i32 %64, i32* %14
%65 = load i32, i32* %6
%66 = bitcast %struct.sockaddr_un* %13 to %struct.sockaddr*
%67 = call i64 @getsockname(i32 %65, %struct.sockaddr* %66, i32* %14)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %58
%70 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %58
%73 = load i32, i32* %6
%74 = call i32 @listen(i32 %73, i32 1)
store i32 8, i32* %10
%75 = load i32, i32* %6
%76 = bitcast %struct.sockaddr_un* %11 to %struct.sockaddr*
%77 = call i32 @accept(i32 %75, %struct.sockaddr* %76, i32* %10)
store i32 %77, i32* %7
%78 = load i32, i32* %7
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %72
%81 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %72
%84 = load i32, i32* %7
%85 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%86 = call i32 @read(i32 %84, i8* %85, i32 80)
store i32 %86, i32* %9
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%88 = load i32, i32* %9
%89 = call i64 @write(i32 1, i8* %87, i32 %88)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %83
%92 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %83
%95 = load i32, i32* %7
%96 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%97 = load i32, i32* %9
%98 = call i64 @write(i32 %95, i8* %96, i32 %97)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %94
%101 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %94
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s path\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [12 x i8] c"getsockname\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [9 x i8] c"write(1)\00"
@.str.6 = [17 x i8] c"write(newsockfd)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca %struct.sockaddr_un
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca [80 x i8]
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.sockaddr_un* %4 to i8*
%11 = bitcast %struct.sockaddr_un* %5 to i8*
%12 = bitcast %struct.sockaddr_un* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%15 = icmp eq i32 %0, 2
br i1 %15, label %21, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %2
%22 = load i32, i32* @AF_UNIX
%23 = load i32, i32* @SOCK_STREAM
%24 = tail call i32 @socket(i32 %22, i32 %23, i32 0)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = call i32 @memset(i8* %11, i32 0, i32 8)
%31 = load i32, i32* @AF_UNIX
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds i8*, i8** %1, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcpy(i32 %34, i8* %36)
%38 = load i32, i32* %33
%39 = call i32 @strlen(i32 %38)
%40 = add i32 %39, 4
%41 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%42 = call i64 @bind(i32 %24, %struct.sockaddr* %41, i32 %40)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %29
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %29
%48 = call i32 @strlen(i32 undef)
%49 = add i32 %48, 4
store i32 %49, i32* %7
%50 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%51 = call i64 @getsockname(i32 %24, %struct.sockaddr* %50, i32* %7)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %47
%57 = call i32 @listen(i32 %24, i32 1)
store i32 8, i32* %3
%58 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%59 = call i32 @accept(i32 %24, %struct.sockaddr* %58, i32* %3)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %56
%65 = call i32 @read(i32 %59, i8* %14, i32 80)
%66 = call i64 @write(i32 1, i8* %14, i32 %65)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %64
%72 = call i64 @write(i32 %59, i8* %14, i32 %65)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %71
ret i32 0
}