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

/* Variables and functions */
scalar_t__ fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fdes[2];
  if (pipe(fdes) == 0) {
    pid_t pid = fork();
    if (pid != 0) {
      printf("THIS IS PARENT BLOCK\n");
      char buff[15] = "Hello World\n";
      printf("Message sent :: %s\n", buff);
      write(fdes[1], buff, sizeof(buff));
    } else {
      printf("THIS IS CHILD BLOCK\n");
      char arr[20];
      ssize_t length = read(fdes[0], arr, 100);
      write(1, arr, length);
    }
  } else
    printf("Pipe Error...\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jne    121e <main+0xce>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e6 <main+0x96>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0xeb1(%rip),%rax
mov    %rax,-0x27(%rbp)
mov    0xeaf(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xea9(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xea1(%rip),%al
mov    %al,-0x19(%rbp)
lea    -0x27(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x27(%rbp),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
jmp    1219 <main+0xc9>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    122c <main+0xdc>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
je     1185 <main+0x25>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
jmp    1210 <main+0xb0>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11df <main+0x7f>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
movabs $0xa646c726f,%rax
mov    %rax,0x17(%rsp)
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,0x10(%rsp)
lea    0xe4d(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0xf,%edx
jmp    120b <main+0xab>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"THIS IS PARENT BLOCK\0A\00"
@__const.main.buff = [15 x i8] c"Hello World\0A\00\00\00"
@.str.1 = [20 x i8] c"Message sent :: %s\0A\00"
@.str.2 = [21 x i8] c"THIS IS CHILD BLOCK\0A\00"
@.str.3 = [15 x i8] c"Pipe Error...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca [15 x i8]
%5 = alloca [20 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %0
%11 = call i64 (...) @fork()
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = bitcast [15 x i8]* %4 to i8*
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 15)
br label %32
23: ; preds = %10
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 100)
store i32 %28, i32* %6
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* %6
%31 = call i32 @write(i32 1, i8* %29, i32 %30)
br label %32
32: ; preds = %23, %14
br label %35
33: ; preds = %0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %32
ret i32 0
}

LLVM IR (-O2):
@__const.main.buff = [15 x i8] c"Hello World\0A\00\00\00"
@.str.1 = [20 x i8] c"Message sent :: %s\0A\00"
@str = [14 x i8] c"Pipe Error...\00"
@str.4 = [20 x i8] c"THIS IS CHILD BLOCK\00"
@str.5 = [21 x i8] c"THIS IS PARENT BLOCK\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [15 x i8]
%3 = alloca [20 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %0
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @write(i32 %16, i8* %13, i32 15)
br label %26
18: ; preds = %8
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 @read(i32 %21, i8* %20, i32 100)
%23 = call i32 @write(i32 1, i8* %20, i32 %22)
br label %26
24: ; preds = %0
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %11, %18, %24
ret i32 0
}