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

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fds[2];
  char str1[] = "Who are u?";
  char str2[] = "Thank you!";
  char buf[40];
  pid_t pid;
  pipe(fds);
  pid = fork();
  if (pid == 0) {
    write(fds[1], str1, sizeof(str1));
    sleep(2);
    read(fds[0], buf, 40);
    printf("Child Out: %s\n", buf);
  } else {
    read(fds[0], buf, 40);
    printf("Parent Out: %s\n", buf);
    write(fds[1], str2, sizeof(str2));
    sleep(3);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe83(%rip),%rax
mov    %rax,-0x23(%rbp)
mov    0xe80(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe78(%rip),%al
mov    %al,-0x19(%rbp)
mov    0xe6f(%rip),%rax
mov    %rax,-0x2e(%rbp)
mov    0xe6c(%rip),%ax
mov    %ax,-0x26(%rbp)
mov    0xe64(%rip),%al
mov    %al,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1214 <main+0xb4>
mov    -0x14(%rbp),%edi
lea    -0x23(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x28,%edx
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
jmp    1250 <main+0xf0>
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x28,%edx
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movabs $0x20657261206f6857,%rax
72 65 20
mov    %rax,0x20(%rsp)
movl   $0x3f7520,0x27(%rsp)
movabs $0x6f79206b6e616854,%rax
20 79 6f
mov    %rax,0x10(%rsp)
movl   $0x21756f,0x17(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ed <main+0x8d>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x28,%edx
call   1060 <read@plt>
lea    0xe5f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
jmp    122f <main+0xcf>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x28,%edx
call   1060 <read@plt>
lea    0xdef(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str1 = [11 x i8] c"Who are u?\00"
@__const.main.str2 = [11 x i8] c"Thank you!\00"
@.str = [15 x i8] c"Child Out: %s\0A\00"
@.str.1 = [16 x i8] c"Parent Out: %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 [11 x i8]
%8 = alloca [11 x i8]
%9 = alloca [40 x i8]
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [11 x i8]* %7 to i8*
%12 = bitcast [11 x i8]* %8 to i8*
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = call i64 (...) @fork()
store i64 %15, i64* %10
%16 = load i64, i64* %10
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %2
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 11)
%23 = call i32 @sleep(i32 2)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 40)
%28 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %42
30: ; preds = %2
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 40)
%35 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%36 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%40 = call i32 @write(i32 %38, i8* %39, i32 11)
%41 = call i32 @sleep(i32 3)
br label %42
42: ; preds = %30, %18
ret i32 0
}

LLVM IR (-O2):
@__const.main.str1 = [11 x i8] c"Who are u?\00"
@__const.main.str2 = [11 x i8] c"Thank you!\00"
@.str = [15 x i8] c"Child Out: %s\0A\00"
@.str.1 = [16 x i8] c"Parent Out: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [11 x i8]
%5 = alloca [11 x i8]
%6 = alloca [40 x i8]
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @write(i32 %17, i8* %8, i32 11)
%19 = call i32 @sleep(i32 2)
%20 = load i32, i32* %11
%21 = call i32 @read(i32 %20, i8* %10, i32 40)
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %31
23: ; preds = %2
%24 = load i32, i32* %11
%25 = call i32 @read(i32 %24, i8* %10, i32 40)
%26 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @write(i32 %28, i8* %9, i32 11)
%30 = call i32 @sleep(i32 3)
br label %31
31: ; preds = %23, %15
ret i32 0
}