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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ label_buffer(int /*<<< orphan*/, int);
int pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ query_buffer(int /*<<< orphan*/, int);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd[2];
  pid_t pid;
  if (pipe(fd) == -1) {
    fprintf(stderr, "Pipe failed");
    exit(EXIT_FAILURE);
  }
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Fork error");
    exit(EXIT_FAILURE);
  }
  if (pid > 0) {
    char buffer[100] = "The quick brown fox jumped over the lazy dog";
    printf("Parent Buffer: %s\n", buffer);
    label_buffer((uint64_t)&buffer, 100);
    close(fd[0]);
    if (write(fd[1], buffer, 100) < 0) {
      fprintf(stderr, "Parent: Error writing to pipe.\n");
      exit(EXIT_FAILURE);
    }
    close(fd[1]);
  } else {
    char inbuf[100];
    close(fd[1]);
    if (read(fd[0], inbuf, 100) < 0) {
      fprintf(stderr, "Child: Error reading from pipe.\n");
      exit(EXIT_FAILURE);
    }
    close(fd[0]);
    printf("Child Buffer: %s\n", inbuf);
    query_buffer((uint64_t)&inbuf, 100);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11fe <main+0x4e>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1236 <main+0x86>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    12d5 <main+0x125>
lea    -0x90(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x64,%edx
call   10a0 <memcpy@plt>
lea    -0x90(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rax
mov    %eax,%edi
mov    $0x64,%esi
call   1040 <label_buffer@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12c8 <main+0x118>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
jmp    134c <main+0x19c>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    131e <main+0x16e>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    -0x100(%rbp),%rsi
lea    0xd37(%rip),%rdi
call   1050 <printf@plt>
lea    -0x100(%rbp),%rax
mov    %eax,%edi
mov    $0x64,%esi
call   10b0 <query_buffer@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     12c4 <main+0x124>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     12d6 <main+0x136>
je     126f <main+0xcf>
movaps 0xef8(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
lea    0xdef(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
mov    $0x64,%esi
call   1040 <label_buffer@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1030 <write@plt>
test   %rax,%rax
js     12e8 <main+0x148>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
jmp    12b9 <main+0x119>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
test   %rax,%rax
js     12fa <main+0x15a>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xdcb(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
mov    $0x64,%esi
call   10a0 <query_buffer@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
jmp    130a <main+0x16a>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xd26(%rip),%rsi
jmp    130a <main+0x16a>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xd32(%rip),%rsi
jmp    130a <main+0x16a>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"Pipe failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"Fork error\00"
@__const.main.buffer = [100 x i8] c"The quick brown fox jumped over the lazy dog\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [19 x i8] c"Parent Buffer: %s\0A\00"
@.str.3 = [32 x i8] c"Parent: Error writing to pipe.\0A\00"
@.str.4 = [33 x i8] c"Child: Error reading from pipe.\0A\00"
@.str.5 = [18 x i8] c"Child Buffer: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i64
%8 = alloca [100 x i8]
%9 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = call i64 (...) @fork()
store i64 %19, i64* %7
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
%27 = load i64, i64* %7
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %26
%30 = bitcast [100 x i8]* %8 to i8*
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = ptrtoint [100 x i8]* %8 to i32
%34 = call i32 @label_buffer(i32 %33, i32 100)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%41 = call i64 @write(i32 %39, i8* %40, i32 100)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %29
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %29
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
br label %74
52: ; preds = %26
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%59 = call i64 @read(i32 %57, i8* %58, i32 100)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %52
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %52
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%68 = load i32, i32* %67
%69 = call i32 @close(i32 %68)
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %70)
%72 = ptrtoint [100 x i8]* %9 to i32
%73 = call i32 @query_buffer(i32 %72, i32 100)
br label %74
74: ; preds = %66, %48
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"Pipe failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"Fork error\00"
@__const.main.buffer = [100 x i8] c"The quick brown fox jumped over the lazy dog\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [19 x i8] c"Parent Buffer: %s\0A\00"
@.str.3 = [32 x i8] c"Parent: Error writing to pipe.\0A\00"
@.str.4 = [33 x i8] c"Child: Error reading from pipe.\0A\00"
@.str.5 = [18 x i8] c"Child Buffer: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i64 (...) @fork()
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %15
%24 = icmp eq i64 %16, 0
br i1 %24, label %45, label %25
25: ; preds = %23
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = ptrtoint [100 x i8]* %4 to i64
%29 = trunc i64 %28 to i32
%30 = call i32 @label_buffer(i32 %29, i32 100)
%31 = load i32, i32* %7
%32 = call i32 @close(i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i64 @write(i32 %34, i8* %26, i32 100)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %25
%43 = load i32, i32* %33
%44 = call i32 @close(i32 %43)
br label %65
45: ; preds = %23
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %7
%51 = call i64 @read(i32 %50, i8* %46, i32 100)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %45
%59 = load i32, i32* %7
%60 = call i32 @close(i32 %59)
%61 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%62 = ptrtoint [100 x i8]* %5 to i64
%63 = trunc i64 %62 to i32
%64 = call i32 @query_buffer(i32 %63, i32 100)
br label %65
65: ; preds = %58, %42
ret i32 0
}