#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*/ 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*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, servlen, clilen, n;
  struct sockaddr_un cli_addr, serv_addr;
  char buf[80];
  if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
    error("creating socket");
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  strcpy(serv_addr.sun_path, argv[1]);
  servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0)
    error("binding socket");
  listen(sockfd, 5);
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
  if (newsockfd < 0)
    error("accepting");
  n = read(newsockfd, buf, 80);
  printf("A connection has been established\n");
  write(1, buf, n);
  write(newsockfd, "I got your message\n", 19);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11fa <main+0x4a>
lea    0xe0b(%rip),%rdi
call   10a0 <error@plt>
lea    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    0x2dd9(%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   1090 <bind@plt>
cmp    $0x0,%rax
jge    125a <main+0xaa>
lea    0xdbb(%rip),%rdi
call   10a0 <error@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
movl   $0x8,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1297 <main+0xe7>
lea    0xd8d(%rip),%rdi
call   10a0 <error@plt>
mov    -0x18(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,-0x24(%rbp)
lea    0xd74(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
lea    0xd74(%rip),%rsi
mov    $0x13,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    0x2e24(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e9 <main+0x39>
lea    0xe1c(%rip),%rdi
call   10a0 <error@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%ebp
mov    0x8(%r14),%rsi
mov    %ebp,%edi
call   1030 <strcpy@plt>
mov    %ebp,%edi
call   1060 <strlen@plt>
lea    0x4(%rax),%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   1090 <bind@plt>
test   %rax,%rax
jns    1236 <main+0x86>
lea    0xddf(%rip),%rdi
call   10a0 <error@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
movl   $0x8,0xc(%rsp)
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10c0 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    126d <main+0xbd>
lea    0xdb7(%rip),%rdi
call   10a0 <error@plt>
lea    0x20(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,%ebp
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
lea    0xd84(%rip),%rsi
mov    %ebx,%edi
mov    $0x13,%edx
call   1050 <write@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"creating socket\00"
@.str.1 = [15 x i8] c"binding socket\00"
@.str.2 = [10 x i8] c"accepting\00"
@.str.3 = [35 x i8] c"A connection has been established\0A\00"
@.str.4 = [20 x i8] c"I got your message\0A\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 [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = bitcast %struct.sockaddr_un* %12 to i8*
%22 = call i32 @bzero(i8* %21, i32 8)
%23 = load i32, i32* @AF_UNIX
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i32 %26, i8* %29)
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @strlen(i32 %32)
%34 = sext i32 %33 to i64
%35 = add i64 %34, 4
%36 = trunc i64 %35 to i32
store i32 %36, i32* %8
%37 = load i32, i32* %6
%38 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
%39 = load i32, i32* %8
%40 = call i64 @bind(i32 %37, %struct.sockaddr* %38, i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %20
%43 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %20
%45 = load i32, i32* %6
%46 = call i32 @listen(i32 %45, i32 5)
store i32 8, i32* %9
%47 = load i32, i32* %6
%48 = bitcast %struct.sockaddr_un* %11 to %struct.sockaddr*
%49 = call i32 @accept(i32 %47, %struct.sockaddr* %48, i32* %9)
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52, %44
%55 = load i32, i32* %7
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 80)
store i32 %57, i32* %10
%58 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%60 = load i32, i32* %10
%61 = call i32 @write(i32 1, i8* %59, i32 %60)
%62 = load i32, i32* %7
%63 = call i32 @write(i32 %62, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 19)
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"creating socket\00"
@.str.1 = [15 x i8] c"binding socket\00"
@.str.2 = [10 x i8] c"accepting\00"
@.str.4 = [20 x i8] c"I got your message\0A\00"
@str = [34 x i8] c"A connection has been established\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca %struct.sockaddr_un
%6 = alloca [80 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = bitcast %struct.sockaddr_un* %5 to i8*
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = call i32 @bzero(i8* %9, i32 8)
%19 = load i32, i32* @AF_UNIX
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @strcpy(i32 %22, i8* %24)
%26 = tail call i32 @strlen(i32 %22)
%27 = add i32 %26, 4
%28 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%29 = call i64 @bind(i32 %13, %struct.sockaddr* %28, i32 %27)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %17
%32 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %17
%34 = call i32 @listen(i32 %13, i32 5)
store i32 8, i32* %3
%35 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%36 = call i32 @accept(i32 %13, %struct.sockaddr* %35, i32* %3)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = call i32 @read(i32 %36, i8* %10, i32 80)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%43 = call i32 @write(i32 1, i8* %10, i32 %41)
%44 = call i32 @write(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 19)
ret i32 0
}