#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*/ buff;

/* Variables and functions */
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int pfd[2];
  char buff[20];
  int n = 0, pid = -1;
  pipe(pfd);
  pid = fork();
  if (pid > 0) {
    printf("In Parent Process\n");
    write(pfd[1], "Hello", sizeof("Hello"));
  } else {
    n = read(pfd[0], buff, sizeof(buff));
    buff[n] = '\0';
    printf("In Child Process : received the message : %s\n", buff);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11b1 <main+0x61>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe71(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
jmp    11e0 <main+0x90>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jle    119d <main+0x3d>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0xe6f(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
jmp    11cb <main+0x6b>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x14,%edx
call   1070 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe45(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"In Parent Process\0A\00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [46 x i8] c"In Child Process : received the message : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 -1, i32* %5
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i32 (...) @fork()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
br label %26
16: ; preds = %0
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 20)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %16, %11
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [46 x i8] c"In Child Process : received the message : %s\0A\00"
@str = [18 x i8] c"In Parent Process\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [20 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
br label %20
14: ; preds = %0
%15 = load i32, i32* %5
%16 = call i32 @read(i32 %15, i8* %4, i32 20)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %20
20: ; preds = %14, %9
ret i32 0
}