#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*/ rdMsg;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ wait(int *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(void) {
  int fd[2];
  pid_t pid, pd;
  int ret;
  ret = pipe(fd);
  if (ret < 0) {
    perror("failiure in creating pipe");
    exit(1);
  }
  pid = fork();
  if (pid < 0) {
    perror("failure in creating child process");
    exit(2);
  }
  if (pid == 0) {
    char wrMsg[64];
    printf("Enter a small message: ");
    scanf("%s", wrMsg);
    write(fd[1], wrMsg, strlen(wrMsg));
  } else {
    int status;
    pd = wait(&status);
    char rdMsg[64];
    read(fd[0], rdMsg, sizeof(rdMsg));
    sleep(5);
    printf("Message Entered Was :: %s\n", rdMsg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ee <main+0x3e>
lea    0xe21(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    121a <main+0x6a>
lea    0xe0f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1279 <main+0xc9>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    12b9 <main+0x109>
lea    -0x74(%rbp),%rdi
call   10c0 <wait@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x40,%edx
call   1070 <read@plt>
mov    $0x5,%edi
call   10b0 <sleep@plt>
lea    -0xc0(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
lea    0x4(%rsp),%rdi
call   1060 <pipe@plt>
test   %eax,%eax
js     125a <main+0xaa>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     1270 <main+0xc0>
je     1217 <main+0x67>
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <read@plt>
mov    $0x5,%edi
call   10b0 <sleep@plt>
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1251 <main+0xa1>
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd9f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xda3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"failiure in creating pipe\00"
@.str.1 = [34 x i8] c"failure in creating child process\00"
@.str.2 = [24 x i8] c"Enter a small message: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [27 x i8] c"Message Entered Was :: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca [64 x i8]
store i32 0, i32* %1
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i64 (...) @fork()
store i64 %17, i64* %3
%18 = load i64, i64* %3
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %16
%24 = load i64, i64* %3
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @write(i32 %31, i8* %32, i32 %34)
br label %45
36: ; preds = %23
%37 = call i64 @wait(i32* %7)
store i64 %37, i64* %4
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 64)
%42 = call i32 @sleep(i32 5)
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %36, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"failiure in creating pipe\00"
@.str.1 = [34 x i8] c"failure in creating child process\00"
@.str.2 = [24 x i8] c"Enter a small message: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [27 x i8] c"Message Entered Was :: %s\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = bitcast [2 x i32]* %1 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %12
%19 = icmp eq i64 %13, 0
br i1 %19, label %20, label %28
20: ; preds = %18
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @strlen(i8* %21)
%27 = call i32 @write(i32 %25, i8* %21, i32 %26)
br label %36
28: ; preds = %18
%29 = bitcast i32* %3 to i8*
%30 = call i64 @wait(i32* %3)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @read(i32 %32, i8* %31, i32 64)
%34 = call i32 @sleep(i32 5)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %36
36: ; preds = %28, %20
ret i32 0
}