#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 {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
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(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, servlen, n;
  struct sockaddr_un serv_addr;
  char buffer[82];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s path message\n", argv[0]);
    exit(2);
  }
  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 ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  if (connect(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0) {
    perror("connect");
    exit(1);
  }
  memset(buffer, 0, 82);
  strncpy(buffer, argv[2], 80);
  if (write(sockfd, buffer, strlen(buffer)) < 0) {
    perror("write(newsockfd)");
    exit(1);
  }
  n = read(sockfd, buffer, 80);
  if (write(1, 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   $0x3,-0x8(%rbp)
je     11f9 <main+0x49>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cltq
add    $0x8,%rax
mov    %eax,-0x18(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1273 <main+0xc3>
lea    0xdb4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    12a2 <main+0xf2>
lea    0xd8c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x52,%edx
call   1070 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1325 <main+0x175>
lea    0xd11(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x90(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1370 <main+0x1c0>
lea    0xcc6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    12a8 <main+0xf8>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2e0e(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rdi
mov    0x8(%r14),%rsi
call   1040 <strcpy@plt>
mov    (%rsp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12ca <main+0x11a>
mov    %eax,%ebp
add    $0x8,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12d3 <main+0x123>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x52,%edx
call   1070 <memset@plt>
mov    0x10(%r14),%rsi
mov    %rbx,%rdi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
js     129f <main+0xef>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1080 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
js     129f <main+0xef>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd81(%rip),%rdi
jmp    12da <main+0x12a>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd45(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xd47(%rip),%rdi
jmp    12da <main+0x12a>
lea    0xd45(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

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

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