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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x2d(%rbp)
mov    0xe7e(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xe79(%rip),%al
mov    %al,-0x21(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe6d(%rip),%ax
mov    %ax,-0x30(%rbp)
mov    0xe65(%rip),%al
mov    %al,-0x2e(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
lea    -0x20(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jne    1220 <main+0xc0>
mov    -0x14(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x440(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
jmp    1262 <main+0x102>
mov    -0x18(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x440(%rbp),%rsi
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x450,%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>
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ff <main+0x9f>
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
jmp    1236 <main+0xd6>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    (%rsp),%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    0xdea(%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 [2 x i32]
%8 = alloca [13 x i8]
%9 = alloca [11 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [13 x i8]* %8 to i8*
%13 = bitcast [11 x i8]* %9 to i8*
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = call i64 (...) @fork()
store i64 %18, i64* %11
%19 = load i64, i64* %11
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%25 = call i32 @write(i32 %23, i8* %24, i32 13)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 1024)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %44
32: ; preds = %2
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 1024)
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%42 = call i32 @write(i32 %40, i8* %41, i32 11)
%43 = call i32 @sleep(i32 3)
br label %44
44: ; preds = %32, %21
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 [2 x i32]
%5 = alloca [13 x i8]
%6 = alloca [11 x i8]
%7 = alloca [1024 x i8]
%8 = bitcast [2 x i32]* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%16 = call i32 @pipe(i32* %15)
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @write(i32 %21, i8* %10, i32 13)
%23 = load i32, i32* %15
%24 = call i32 @read(i32 %23, i8* %12, i32 1024)
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %34
26: ; preds = %2
%27 = load i32, i32* %13
%28 = call i32 @read(i32 %27, i8* %12, i32 1024)
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @write(i32 %31, i8* %11, i32 11)
%33 = call i32 @sleep(i32 3)
br label %34
34: ; preds = %26, %19
ret i32 0
}