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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, n;
  struct sockaddr_un serv_addr;
  char buffer[256];
  if (argc < 2) {
    fprintf(stderr, "usage %s path\n", argv[0]);
    exit(0);
  }
  sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  strncpy(serv_addr.sun_path, argv[1], sizeof(serv_addr.sun_path) - 1);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR connecting");
  printf("Please enter the message: ");
  bzero(buffer, 256);
  fgets(buffer, 255, stdin);
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0)
    error("ERROR writing to socket");
  bzero(buffer, 256);
  n = read(sockfd, buffer, 255);
  if (n < 0)
    error("ERROR reading from socket");
  printf("%s\n", buffer);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1216 <main+0x46>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1248 <main+0x78>
lea    0xdcc(%rip),%rdi
call   10b0 <error@plt>
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   10c0 <bzero@plt>
mov    0x2d8b(%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   10e0 <connect@plt>
cmp    $0x0,%rax
jge    129e <main+0xce>
lea    0xd8b(%rip),%rdi
call   10b0 <error@plt>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
lea    -0x120(%rbp),%rdi
mov    0x2d15(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1090 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x12c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1327 <main+0x157>
lea    0xd2e(%rip),%rdi
call   10b0 <error@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1365 <main+0x195>
lea    0xd08(%rip),%rdi
call   10b0 <error@plt>
lea    -0x120(%rbp),%rsi
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    131a <main+0x13a>
mov    0x2de8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1224 <main+0x44>
lea    0xdf0(%rip),%rdi
call   10c0 <error@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x8,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    0x8(%r14),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   10f0 <connect@plt>
test   %rax,%rax
jns    126e <main+0x8e>
lea    0xdbb(%rip),%rdi
call   10c0 <error@plt>
lea    0xdc0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %eax,%eax
jns    12c8 <main+0xe8>
lea    0xd8d(%rip),%rdi
call   10c0 <error@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1090 <read@plt>
test   %eax,%eax
jns    12f9 <main+0x119>
lea    0xd74(%rip),%rdi
call   10c0 <error@plt>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcd3(%rip),%rsi
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"usage %s path\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [17 x i8] c"ERROR connecting\00"
@.str.3 = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [256 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = call i32 @bzero(i8* %5, i32 8)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call i32 @strncpy(i32 %25, i8* %27, i32 3)
%29 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%30 = call i64 @connect(i32 %16, %struct.sockaddr* %29, i32 8)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %20
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @bzero(i8* %6, i32 256)
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %6, i32 255, i32 %37)
%39 = call i32 @strlen(i8* %6)
%40 = call i32 @write(i32 %16, i8* %6, i32 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %34
%45 = call i32 @bzero(i8* %6, i32 256)
%46 = call i32 @read(i32 %16, i8* %6, i32 255)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = call i32 @puts(i8* %6)
%52 = call i32 @close(i32 %16)
ret i32 0
}