#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 */
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pipe_vprofiler(int *);
int /*<<< orphan*/ printf(char *, int, char *);
int read_vprofiler(int, char *, int);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int /*<<< orphan*/ write_vprofiler(int, char *, size_t);
int main() {
  int pipefds[2];
  pipe_vprofiler(pipefds);
  pid_t pid = fork();
  char buf[200];
  memset(buf, 0, sizeof(buf));
  if (pid != 0) {
    close(pipefds[0]);
    char *test_string = "Test";
    size_t len = strlen(test_string);
    strncpy(buf, test_string, len);
    write_vprofiler(pipefds[1], buf, len + 1);
    close(pipefds[1]);
  } else {
    close(pipefds[1]);
    int sread = read_vprofiler(pipefds[0], buf, sizeof(buf));
    printf("Message: %d, %s\n", sread, buf);
    close(pipefds[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <pipe_vprofiler@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x18(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     123e <main+0xae>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
lea    0xe1d(%rip),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0xf0(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xe8(%rbp),%rsi
mov    -0xf0(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    -0xf0(%rbp),%rdx
add    $0x1,%rdx
call   1090 <write_vprofiler@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
jmp    1281 <main+0xf1>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xc8,%edx
call   10a0 <read_vprofiler@plt>
mov    %eax,-0xf4(%rbp)
mov    -0xf4(%rbp),%esi
lea    -0xe0(%rbp),%rdx
lea    0xd91(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xe0,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe_vprofiler@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
test   %rbx,%rbx
je     11eb <main+0x6b>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xe3e(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    $0x4,%edx
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    0xc(%rsp),%edi
mov    $0x5,%edx
mov    %rbx,%rsi
call   1080 <write_vprofiler@plt>
mov    0xc(%rsp),%edi
jmp    121f <main+0x9f>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xc8,%edx
call   1090 <read_vprofiler@plt>
lea    0xdf4(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"Test\00"
@.str.1 = [17 x i8] c"Message: %d, %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca [200 x i8]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe_vprofiler(i32* %8)
%10 = call i64 (...) @fork()
store i64 %10, i64* %3
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 200)
%13 = load i64, i64* %3
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %6
%21 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i32 @strncpy(i8* %21, i8* %22, i64 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%28 = load i64, i64* %6
%29 = add i64 %28, 1
%30 = call i32 @write_vprofiler(i32 %26, i8* %27, i64 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
br label %48
34: ; preds = %0
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%41 = call i32 @read_vprofiler(i32 %39, i8* %40, i32 200)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %42, i8* %43)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
br label %48
48: ; preds = %34, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"Test\00"
@.str.1 = [17 x i8] c"Message: %d, %s\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [200 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pipe_vprofiler(i32* %4)
%6 = call i64 (...) @fork()
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 200)
%9 = icmp eq i64 %6, 0
br i1 %9, label %18, label %10
10: ; preds = %0
%11 = load i32, i32* %4
%12 = call i32 @close(i32 %11)
%13 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @write_vprofiler(i32 %15, i8* %7, i64 5)
%17 = load i32, i32* %14
br label %26
18: ; preds = %0
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %4
%23 = call i32 @read_vprofiler(i32 %22, i8* %7, i32 200)
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %7)
%25 = load i32, i32* %4
br label %26
26: ; preds = %18, %10
%27 = phi i32 [ %25, %18 ], [ %17, %10 ]
%28 = call i32 @close(i32 %27)
ret i32 0
}