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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ imv_ipc_path(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <pid> <command>\n", argv[0]);
    return 0;
  }
  int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  assert(sockfd);
  struct sockaddr_un desc = {.sun_family = AF_UNIX};
  imv_ipc_path(desc.sun_path, sizeof desc.sun_path, atoi(argv[1]));
  if (connect(sockfd, (struct sockaddr *)&desc, sizeof desc) < 0) {
    perror("Failed to connect");
    return 1;
  }
  char buf[4096] = {0};
  for (int i = 2; i < argc; ++i) {
    strncat(buf, argv[i], sizeof buf - 1);
    if (i + 1 < argc) {
      strncat(buf, " ", sizeof buf - 1);
    }
  }
  strncat(buf, "\n", sizeof buf - 1);
  write(sockfd, buf, strlen(buf));
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    120b <main+0x4b>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <main+0x1ca>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <assert@plt>
movl   $0x0,-0x20(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1028(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    -0x1028(%rbp),%edi
mov    %eax,%edx
mov    $0x4,%esi
call   10a0 <imv_ipc_path@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    129d <main+0xdd>
lea    0xd8f(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    138a <main+0x1ca>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
movl   $0x2,-0x1024(%rbp)
mov    -0x1024(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    132c <main+0x16c>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1024(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0xfff,%edx
call   1060 <strncat@plt>
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    1313 <main+0x153>
lea    -0x1020(%rbp),%rdi
lea    0xd24(%rip),%rsi
mov    $0xfff,%edx
call   1060 <strncat@plt>
jmp    1318 <main+0x158>
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1024(%rbp)
jmp    12ba <main+0xfa>
lea    -0x1020(%rbp),%rdi
lea    0xcdf(%rip),%rsi
mov    $0xfff,%edx
call   1060 <strncat@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1034(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r12
cmp    $0x2,%edi
jg     11f7 <main+0x37>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe13(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1303 <main+0x143>
mov    %edi,%r15d
mov    0x2de7(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <assert@plt>
movl   $0x0,0x8(%rsp)
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%r12),%rdi
call   10c0 <atoi@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %eax,%edx
call   10a0 <imv_ipc_path@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     1317 <main+0x157>
mov    %ebp,0x4(%rsp)
lea    0x10(%rsp),%r13
mov    $0x1000,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r15d,%ebx
mov    $0x2,%ebp
sub    %rbx,%rbp
mov    $0x3,%r14d
lea    0xda1(%rip),%r15
jmp    12a2 <main+0xe2>
xchg   %ax,%ax
lea    (%r14,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%r14
cmp    $0x3,%rax
je     12cb <main+0x10b>
mov    -0x8(%r12,%r14,8),%rsi
mov    %r13,%rdi
mov    $0xfff,%edx
call   1060 <strncat@plt>
cmp    %rbx,%r14
jae    1290 <main+0xd0>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xfff,%edx
call   1060 <strncat@plt>
jmp    1290 <main+0xd0>
lea    0xd47(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xfff,%edx
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfd(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
jmp    1305 <main+0x145>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <pid> <command>\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [18 x i8] c"Failed to connect\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca [4096 x i8]
%9 = alloca i32
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, 3
br i1 %11, label %12, label %18
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 ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %75
18: ; preds = %2
%19 = load i32, i32* @AF_UNIX
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
store i32 0, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
%26 = load i32, i32* @AF_UNIX
store i32 %26, i32* %25
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @imv_ipc_path(i32 %28, i32 4, i32 %32)
%34 = load i32, i32* %6
%35 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%36 = call i64 @connect(i32 %34, %struct.sockaddr* %35, i32 8)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %18
%39 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %75
40: ; preds = %18
%41 = bitcast [4096 x i8]* %8 to i8*
store i32 2, i32* %9
br label %42
42: ; preds = %62, %40
%43 = load i32, i32* %9
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %65
46: ; preds = %42
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @strncat(i8* %47, i8* %52, i32 4095)
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %4
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %46
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%60 = call i32 @strncat(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 4095)
br label %61
61: ; preds = %58, %46
br label %62
62: ; preds = %61
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %42
65: ; preds = %42
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%67 = call i32 @strncat(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 4095)
%68 = load i32, i32* %6
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%71 = call i32 @strlen(i8* %70)
%72 = call i32 @write(i32 %68, i8* %69, i32 %71)
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
store i32 0, i32* %3
br label %75
75: ; preds = %65, %38, %12
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <pid> <command>\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [18 x i8] c"Failed to connect\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [4096 x i8]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %50
10: ; preds = %2
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = tail call i32 @assert(i32 %13)
%15 = bitcast %struct.sockaddr_un* %3 to i8*
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
store i32 0, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
%18 = load i32, i32* @AF_UNIX
store i32 %18, i32* %17
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @imv_ipc_path(i32 0, i32 4, i32 %21)
%23 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%24 = call i64 @connect(i32 %13, %struct.sockaddr* %23, i32 8)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %10
%27 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %48
28: ; preds = %10
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%30 = zext i32 %0 to i64
%31 = zext i32 %0 to i64
br label %37
32: ; preds = %46
%33 = call i32 @strncat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 4095)
%34 = call i32 @strlen(i8* %29)
%35 = call i32 @write(i32 %13, i8* %29, i32 %34)
%36 = call i32 @close(i32 %13)
br label %48
37: ; preds = %28, %46
%38 = phi i64 [ 2, %28 ], [ %42, %46 ]
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @strncat(i8* %29, i8* %40, i32 4095)
%42 = add nuw nsw i64 %38, 1
%43 = icmp ult i64 %42, %30
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @strncat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 4095)
br label %46
46: ; preds = %37, %44
%47 = icmp eq i64 %42, %31
br i1 %47, label %32, label %37
48: ; preds = %32, %26
%49 = phi i32 [ 1, %26 ], [ 0, %32 ]
br label %50
50: ; preds = %48, %6
%51 = phi i32 [ 0, %6 ], [ %49, %48 ]
ret i32 %51
}