#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;
typedef int /*<<< orphan*/ buf;

/* 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[] = "hello world!";
  char str2[] = "thank you!";
  char buf[1024];
  pid_t pid;
  pipe(fds);
  pid = fork();
  if (pid == 0) {
    write(fds[1], str1, sizeof(str1));
    sleep(2);
    read(fds[0], buf, sizeof(buf));
    printf("child recv: %s\n", buf);
  } else {
    read(fds[0], buf, sizeof(buf));
    printf("parent recv: %s\n", buf);
    write(fds[1], str2, sizeof(str2));
    sleep(3);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x25(%rbp)
mov    0xe7e(%rip),%eax
mov    %eax,-0x1d(%rbp)
mov    0xe79(%rip),%al
mov    %al,-0x19(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe6d(%rip),%ax
mov    %ax,-0x28(%rbp)
mov    0xe65(%rip),%al
mov    %al,-0x26(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    1221 <main+0xc1>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x430(%rbp),%rsi
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
jmp    1263 <main+0x103>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x430(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x430,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x25(%rsp)
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,0x20(%rsp)
movabs $0x6f79206b6e616874,%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     11f7 <main+0x97>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    0xe58(%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    1239 <main+0xd9>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    0xde7(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str1 = [13 x i8] c"hello world!\00"
@__const.main.str2 = [11 x i8] c"thank you!\00"
@.str = [16 x i8] c"child recv: %s\0A\00"
@.str.1 = [17 x i8] c"parent recv: %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 [13 x i8]
%8 = alloca [11 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [13 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 [13 x i8], [13 x i8]* %7, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 13)
%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 [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 1024)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 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 [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 1024)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%36 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 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 = [13 x i8] c"hello world!\00"
@__const.main.str2 = [11 x i8] c"thank you!\00"
@.str = [16 x i8] c"child recv: %s\0A\00"
@.str.1 = [17 x i8] c"parent recv: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [13 x i8]
%5 = alloca [11 x i8]
%6 = alloca [1024 x i8]
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 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 13)
%19 = call i32 @sleep(i32 2)
%20 = load i32, i32* %11
%21 = call i32 @read(i32 %20, i8* %10, i32 1024)
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 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 1024)
%26 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 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
}