int main() {
  int pipefds[2];
  int returnstatus;
  int pid;
  char writemessages[2][20] = {"Hi", "Hello"};
  char readmessage[20];
  returnstatus = pipe(pipefds);
  if (returnstatus == -1) {
    printf("Unable to create pipe\n");
    return 1;
  }
  pid = fork();
  if (pid == 0) {
    read(pipefds[0], readmessage, sizeof(readmessage));
    printf("Child Process - Reading from pipe – Message 1 is %s\n",
           readmessage);
    read(pipefds[0], readmessage, sizeof(readmessage));
    printf("Child Process - Reading from pipe – Message 2 is %s\n",
           readmessage);
  } else {
    printf("Parent Process - Writing to pipe - Message 1 is %s\n",
           writemessages[0]);
    write(pipefds[1], writemessages[0], sizeof(writemessages[0]));
    printf("Parent Process - Writing to pipe - Message 2 is %s\n",
           writemessages[1]);
    write(pipefds[1], writemessages[1], sizeof(writemessages[1]));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
lea    -0xc(%rbp),%rdi
mov    $0x0,%al
call   1050 <pipe@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11b6 <main+0x56>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x112>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1219 <main+0xb9>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126b <main+0x10b>
lea    -0x40(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x40(%rbp),%rsi
add    $0x14,%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
add    $0x14,%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0xeb2(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe7a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     11fd <main+0x9d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1210 <main+0xb0>
lea    0xee6(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
mov    $0x14,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <write@plt>
lea    0x24(%rsp),%r14
lea    0xeec(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
mov    $0x14,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <write@plt>
jmp    125f <main+0xff>
lea    0xefa(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    125f <main+0xff>
mov    0x8(%rsp),%edi
xor    %ebx,%ebx
lea    0x40(%rsp),%r14
mov    $0x14,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <read@plt>
lea    0xdf7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
mov    $0x14,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <read@plt>
lea    0xe0a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.writemessages = [2 x [20 x i8]] [[20 x i8] c"Hi\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [20 x i8] c"Hello\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"]
@.str = [23 x i8] c"Unable to create pipe\0A\00"
@.str.1 = [55 x i8] c"Child Process - Reading from pipe \E2\80\93 Message 1 is %s\0A\00"
@.str.2 = [55 x i8] c"Child Process - Reading from pipe \E2\80\93 Message 2 is %s\0A\00"
@.str.3 = [52 x i8] c"Parent Process - Writing to pipe - Message 1 is %s\0A\00"
@.str.4 = [52 x i8] c"Parent Process - Writing to pipe - Message 2 is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x [20 x i8]]
%6 = alloca [20 x i8]
store i32 0, i32* %1
%7 = bitcast [2 x [20 x i8]]* %5 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %49
14: ; preds = %0
%15 = call i32 (...) @fork()
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%22 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %20, i8* %21, i64 20)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%28 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %26, i8* %27, i64 20)
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %48
31: ; preds = %14
%32 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %5, i64 0, i64 0
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %32, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %5, i64 0, i64 0
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %37, i64 0, i64 0
%39 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %36, i8* %38, i64 20)
%40 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %5, i64 0, i64 1
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %40, i64 0, i64 0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %5, i64 0, i64 1
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %45, i64 0, i64 0
%47 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %44, i8* %46, i64 20)
br label %48
48: ; preds = %31, %18
store i32 0, i32* %1
br label %49
49: ; preds = %48, %12
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@__const.main.writemessages = [2 x [20 x i8]] [[20 x i8] c"Hi\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [20 x i8] c"Hello\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"]
@.str.1 = [55 x i8] c"Child Process - Reading from pipe \E2\80\93 Message 1 is %s\0A\00"
@.str.2 = [55 x i8] c"Child Process - Reading from pipe \E2\80\93 Message 2 is %s\0A\00"
@.str.3 = [52 x i8] c"Parent Process - Writing to pipe - Message 1 is %s\0A\00"
@.str.4 = [52 x i8] c"Parent Process - Writing to pipe - Message 2 is %s\0A\00"
@str = [22 x i8] c"Unable to create pipe\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x [20 x i8]]
%3 = alloca [20 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %2, i64 0, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %31
12: ; preds = %0
%13 = call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %7
%17 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %16, i8* %6, i64 20)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%19 = load i32, i32* %7
%20 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %19, i8* %6, i64 20)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %31
22: ; preds = %12
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %25, i8* %5, i64 20)
%27 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %2, i64 0, i64 1, i64 0
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %24
%30 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %29, i8* %27, i64 20)
br label %31
31: ; preds = %15, %22, %10
%32 = phi i32 [ 1, %10 ], [ 0, %22 ], [ 0, %15 ]
ret i32 %32
}