#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 EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sfd, cfd;
  struct sockaddr_un my_addr, peer_addr;
  socklen_t peer_addr_size;
  char buffer[256];
  int n;
  if (argc < 2) {
    fprintf(stderr, "ERROR, no path provided\n");
    exit(1);
  }
  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, argv[1], 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);
  bzero(buffer, 256);
  n = read(cfd, buffer, 255);
  if (n < 0)
    do {
      perror("ERROR reading from socket");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Here is the message: %s\n", buffer);
  n = write(cfd, "I got your message", 18);
  if (n < 0)
    do {
      perror("ERROR writing to socket");
      exit(EXIT_FAILURE);
    } while (0);
  close(cfd);
  close(sfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1222 <main+0x42>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1267 <main+0x87>
jmp    124d <main+0x6d>
lea    0xdeb(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12d1 <main+0xf1>
jmp    12b7 <main+0xd7>
lea    0xd5b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x32,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1306 <main+0x126>
jmp    12ec <main+0x10c>
lea    0xd2b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0x8,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1349 <main+0x169>
jmp    132f <main+0x14f>
lea    0xcef(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    -0x18(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xff,%edx
call   1080 <read@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    13a0 <main+0x1c0>
jmp    1386 <main+0x1a6>
lea    0xc9f(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x130(%rbp),%rsi
lea    0xc98(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xca2(%rip),%rsi
mov    $0x12,%edx
call   1040 <write@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    13f9 <main+0x219>
jmp    13df <main+0x1ff>
lea    0xc8c(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x128,%rsp
cmp    $0x1,%edi
jle    130b <main+0x12b>
mov    %rsi,%rbp
mov    0x2de8(%rip),%r15
mov    (%r15),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     132a <main+0x14a>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%edi
mov    0x8(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     1333 <main+0x153>
mov    %ebx,%edi
mov    $0x32,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     133c <main+0x15c>
movl   $0x8,0xc(%rsp)
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
je     1345 <main+0x165>
mov    %eax,%ebp
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
js     134e <main+0x16e>
lea    0xd7a(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1050 <printf@plt>
lea    0xd82(%rip),%rsi
mov    %ebp,%edi
mov    $0x12,%edx
call   1040 <write@plt>
test   %eax,%eax
js     1357 <main+0x177>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xce5(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd0e(%rip),%rdi
jmp    135e <main+0x17e>
lea    0xcdf(%rip),%rdi
jmp    135e <main+0x17e>
lea    0xcdb(%rip),%rdi
jmp    135e <main+0x17e>
lea    0xcd9(%rip),%rdi
jmp    135e <main+0x17e>
lea    0xcd7(%rip),%rdi
jmp    135e <main+0x17e>
lea    0xd14(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERROR, no path provided\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
@.str.6 = [25 x i8] c"Here is the message: %s\0A\00"
@.str.7 = [19 x i8] c"I got your message\00"
@.str.8 = [24 x i8] c"ERROR writing to socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = bitcast %struct.sockaddr_un* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_UNIX
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%27 = load i32, i32* @AF_UNIX
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strncpy(i32 %30, i8* %32, i32 3)
%34 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%35 = call i32 @bind(i32 %19, %struct.sockaddr* %34, i32 8)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %25
%42 = call i32 @listen(i32 %19, i32 50)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %41
%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: ; preds = %41
store i32 8, i32* %5
%49 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%50 = call i32 @accept(i32 %19, %struct.sockaddr* %49, i32* %5)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = call i32 @bzero(i8* %10, i32 256)
%58 = call i32 @read(i32 %50, i8* %10, i32 255)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %56
%65 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%66 = call i32 @write(i32 %50, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 18)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %64
%73 = call i32 @close(i32 %50)
%74 = call i32 @close(i32 %19)
ret i32 0
}