#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int const);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
int main(int argc, char **argv) {
  char *path = "/var/ssd/vm/cl/vm7";
  struct sockaddr_un un;
  un.sun_family = AF_UNIX;
  strcpy(un.sun_path, argv[1]);
  int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  int ret = bind(sockfd, (struct sockaddr *)&un, sizeof(struct sockaddr_un));
  strcpy(un.sun_path, argv[1]);
  ret = connect(sockfd, (struct sockaddr *)&un, sizeof(struct sockaddr_un));
  const int bufsize = 1024 * 64;
  char buf[bufsize];
  usleep(1000);
  ret = read(sockfd, buf, bufsize);
  write(1, buf, ret);
  while (1) {
    memset(buf, 0, sizeof(buf));
    ret = read(0, buf, bufsize);
    ret = write(sockfd, buf, ret);
    memset(buf, 0, sizeof(buf));
    usleep(1000);
    ret = read(sockfd, buf, bufsize);
    write(1, buf, ret);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1080 <connect@plt>
mov    %eax,-0x28(%rbp)
movl   $0x10000,-0x2c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x38(%rbp)
mov    $0x3e8,%edi
call   1090 <usleep@plt>
mov    -0x24(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edx
mov    $0x1,%edi
lea    -0x10040(%rbp),%rsi
call   1040 <write@plt>
jmp    125c <main+0xdc>
lea    -0x10040(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
xor    %edi,%edi
lea    -0x10040(%rbp),%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%edx
lea    -0x10040(%rbp),%rsi
call   1040 <write@plt>
mov    %eax,-0x28(%rbp)
lea    -0x10040(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
mov    $0x3e8,%edi
call   1090 <usleep@plt>
mov    -0x24(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edx
mov    $0x1,%edi
lea    -0x10040(%rbp),%rsi
call   1040 <write@plt>
jmp    1257 <main+0xd7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10010,%rsp
mov    %rsi,%rbx
mov    0x2e53(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsi),%rsi
call   1030 <strcpy@plt>
mov    0x0(%rbp),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
mov    0x8(%rsp),%edi
mov    0x8(%rbx),%rsi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1080 <connect@plt>
mov    $0x3e8,%edi
call   1090 <usleep@plt>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
mov    $0x3e8,%edi
call   1090 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1220 <main+0xa0>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"/var/ssd/vm/cl/vm7\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %6
%12 = load i32, i32* @AF_UNIX
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strcpy(i32 %15, i8* %18)
%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* %8
%23 = load i32, i32* %8
%24 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 8)
store i32 %25, i32* %9
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i32 %27, i8* %30)
%32 = load i32, i32* %8
%33 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%34 = call i32 @connect(i32 %32, %struct.sockaddr* %33, i32 8)
store i32 %34, i32* %9
store i32 65536, i32* %10
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %11
%36 = alloca i8, i64 65536
%37 = call i32 @usleep(i32 1000)
%38 = load i32, i32* %8
%39 = call i32 @read(i32 %38, i8* %36, i32 65536)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = call i32 @write(i32 1, i8* %36, i32 %40)
br label %42
42: ; preds = %43, %2
br label %43
43: ; preds = %42
%44 = call i32 @memset(i8* %36, i32 0, i32 65536)
%45 = call i32 @read(i32 0, i8* %36, i32 65536)
store i32 %45, i32* %9
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = call i32 @write(i32 %46, i8* %36, i32 %47)
store i32 %48, i32* %9
%49 = call i32 @memset(i8* %36, i32 0, i32 65536)
%50 = call i32 @usleep(i32 1000)
%51 = load i32, i32* %8
%52 = call i32 @read(i32 %51, i8* %36, i32 65536)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = call i32 @write(i32 1, i8* %36, i32 %53)
br label %42
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = load i32, i32* @AF_UNIX
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcpy(i32 undef, i8* %9)
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%15 = call i32 @bind(i32 %13, %struct.sockaddr* %14, i32 8)
%16 = load i32, i32* %7
%17 = load i8*, i8** %8
%18 = call i32 @strcpy(i32 %16, i8* %17)
%19 = call i32 @connect(i32 %13, %struct.sockaddr* %14, i32 8)
%20 = alloca [65536 x i8]
%21 = getelementptr inbounds [65536 x i8], [65536 x i8]* %20, i64 0, i64 0
%22 = call i32 @usleep(i32 1000)
%23 = call i32 @read(i32 %13, i8* %21, i32 65536)
%24 = call i32 @write(i32 1, i8* %21, i32 %23)
br label %25
25: ; preds = %25, %2
%26 = call i32 @memset(i8* %21, i32 0, i32 65536)
%27 = call i32 @read(i32 0, i8* %21, i32 65536)
%28 = call i32 @write(i32 %13, i8* %21, i32 %27)
%29 = call i32 @memset(i8* %21, i32 0, i32 65536)
%30 = call i32 @usleep(i32 1000)
%31 = call i32 @read(i32 %13, i8* %21, i32 65536)
%32 = call i32 @write(i32 1, i8* %21, i32 %31)
br label %25
}