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

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
scalar_t__ fork();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int mknod_vprofiler(char *, int, int /*<<< orphan*/);
int open_vprofiler(char *, int);
int /*<<< orphan*/ perror(char *);
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() {
  char *fifo_name = "fifo_channel";
  int err = mknod_vprofiler(fifo_name, 4096 | 420, (dev_t)0);
  if (err != 0 && errno != EEXIST) {
    perror("mknod fails");
  }
  int fd = open_vprofiler(fifo_name, 2);
  pid_t pid = fork();
  char buf[200];
  memset(buf, 0, sizeof(buf));
  if (pid != 0) {
    char *test_string = "Test";
    size_t len = strlen(test_string);
    strncpy(buf, test_string, len);
    write_vprofiler(fd, buf, len + 1);
  } else {
    int sread = read_vprofiler(fd, buf, sizeof(buf));
    printf("Message: %d, %s\n", sread, buf);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x11a4,%esi
xor    %edx,%edx
call   1090 <mknod_vprofiler@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1210 <main+0x60>
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%rax
je     1210 <main+0x60>
lea    0xe02(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1040 <open_vprofiler@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x20(%rbp)
lea    -0xf0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
je     12a4 <main+0xf4>
lea    0xdc8(%rip),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x100(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    -0x100(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    -0x100(%rbp),%rdx
add    $0x1,%rdx
call   10a0 <write_vprofiler@plt>
jmp    12d7 <main+0x127>
mov    -0x18(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0xc8,%edx
call   10b0 <read_vprofiler@plt>
mov    %eax,-0x104(%rbp)
mov    -0x104(%rbp),%esi
lea    -0xf0(%rbp),%rdx
lea    0xd4c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xc8,%rsp
lea    0xe50(%rip),%rdi
mov    $0x11a4,%esi
xor    %edx,%edx
call   1080 <mknod_vprofiler@plt>
test   %eax,%eax
je     11da <main+0x3a>
mov    0x2e11(%rip),%rax
mov    (%rax),%rax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%rax
jne    1269 <main+0xc9>
lea    0xe1f(%rip),%rdi
mov    $0x2,%esi
call   1040 <open_vprofiler@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1060 <memset@plt>
test   %rbx,%rbx
je     1233 <main+0x93>
lea    0xe07(%rip),%rsi
mov    %rsp,%rbx
mov    $0x4,%edx
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    $0x5,%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <write_vprofiler@plt>
jmp    1256 <main+0xb6>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc8,%edx
call   10a0 <read_vprofiler@plt>
lea    0xdd2(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd9d(%rip),%rdi
call   10b0 <perror@plt>
jmp    11da <main+0x3a>

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

LLVM IR (-O2):
@.str = [13 x i8] c"fifo_channel\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [12 x i8] c"mknod fails\00"
@.str.2 = [5 x i8] c"Test\00"
@.str.3 = [17 x i8] c"Message: %d, %s\0A\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = tail call i32 @mknod_vprofiler(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 4516, i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = load i64, i64* @errno
%6 = load i64, i64* @EEXIST
%7 = icmp eq i64 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %4, %0
%11 = tail call i32 @open_vprofiler(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = tail call i64 (...) @fork()
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 200)
%15 = icmp eq i64 %12, 0
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4)
%18 = call i32 @write_vprofiler(i32 %11, i8* %13, i64 5)
br label %22
19: ; preds = %10
%20 = call i32 @read_vprofiler(i32 %11, i8* %13, i32 200)
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %20, i8* %13)
br label %22
22: ; preds = %19, %16
%23 = call i32 @close(i32 %11)
ret i32 0
}