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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int pipeFds[2];
  int buffer[30];
  pipe(pipeFds);
  if (!fork()) {
    printf(" CHILD: writing into the pipe\n");
    write(pipeFds[1], "test", 5);
    printf(" CHILD: exiting\n");
    exit(0);
  } else {
    printf("PARENT: reading from pipe\n");
    read(pipeFds[0], buffer, 5);
    printf("PARENT: read - %s -\n", buffer);
    wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    11d9 <main+0x69>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xe65(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
lea    -0x90(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x90,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11e2 <main+0x62>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x5,%edx
call   1070 <read@plt>
lea    0xe3f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <wait@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
ret
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0xe07(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c" CHILD: writing into the pipe\0A\00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [17 x i8] c" CHILD: exiting\0A\00"
@.str.3 = [27 x i8] c"PARENT: reading from pipe\0A\00"
@.str.4 = [21 x i8] c"PARENT: read - %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 [30 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
%11 = icmp ne i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%24 = call i32 @read(i32 %22, i32* %23, i32 5)
%25 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32* %25)
%27 = call i32 @wait(i32* null)
br label %28
28: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"test\00"
@.str.4 = [21 x i8] c"PARENT: read - %s -\0A\00"
@str = [30 x i8] c" CHILD: writing into the pipe\00"
@str.5 = [16 x i8] c" CHILD: exiting\00"
@str.6 = [26 x i8] c"PARENT: reading from pipe\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [30 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = bitcast [30 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = getelementptr inbounds [30 x i32], [30 x i32]* %4, i64 0, i64 0
%22 = call i32 @read(i32 %20, i32* %21, i32 5)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32* %21)
%24 = call i32 @wait(i32* null)
ret i32 0
}