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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe96(%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    11a6 <main+0x56>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1245 <main+0xf5>
lea    -0x40(%rbp),%rsi
lea    0xe8e(%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>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe8e(%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>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    0xec1(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe89(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xor    %ebp,%ebp
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     1231 <main+0xe1>
lea    0xe8e(%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>
mov    0x8(%rsp),%edi
lea    0x40(%rsp),%rbx
mov    $0x14,%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <read@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
lea    0x24(%rsp),%rsi
mov    $0x14,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0x8(%rsp),%edi
mov    $0x14,%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <read@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1242 <main+0xf2>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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 = [35 x i8] c"Writing to pipe - Message 1 is %s\0A\00"
@.str.2 = [39 x i8] c"Reading from pipe \E2\80\93 Message 1 is %s\0A\00"
@.str.3 = [35 x i8] c"Writing to pipe - Message 2 is %s\0A\00"
@.str.4 = [39 x i8] c"Reading from pipe \E2\80\93 Message 2 is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [2 x [20 x i8]]
%5 = alloca [20 x i8]
store i32 0, i32* %1
%6 = bitcast [2 x [20 x i8]]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i32 (i32*, ...) bitcast (i32 (...)* @pipe to i32 (i32*, ...)*)(i32* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = 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 %42
13: ; preds = %0
%14 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %4, i64 0, i64 0
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %4, i64 0, i64 0
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%21 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %18, i8* %20, i64 20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%25 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %23, i8* %24, i64 20)
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %4, i64 0, i64 0
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %28, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %4, i64 0, i64 1
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %33, i64 0, i64 0
%35 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %32, i8* %34, i64 20)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%39 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %37, i8* %38, i64 20)
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %40)
store i32 0, i32* %1
br label %42
42: ; preds = %13, %11
%43 = load i32, i32* %1
ret i32 %43
}

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 = [35 x i8] c"Writing to pipe - Message 1 is %s\0A\00"
@.str.2 = [39 x i8] c"Reading from pipe \E2\80\93 Message 1 is %s\0A\00"
@.str.3 = [35 x i8] c"Writing to pipe - Message 2 is %s\0A\00"
@.str.4 = [39 x i8] c"Reading from pipe \E2\80\93 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 %27
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %15, i8* %5, i64 20)
%17 = load i32, i32* %7
%18 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %17, i8* %6, i64 20)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%21 = load i32, i32* %14
%22 = getelementptr inbounds [2 x [20 x i8]], [2 x [20 x i8]]* %2, i64 0, i64 1, i64 0
%23 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %21, i8* %22, i64 20)
%24 = load i32, i32* %7
%25 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %24, i8* %6, i64 20)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %27
27: ; preds = %12, %10
%28 = phi i32 [ 1, %10 ], [ 0, %12 ]
ret i32 %28
}