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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int childpid, a, n, pd[2], i, buffer1[50], buffer2[50];
  a = pipe(pd);
  if (a == -1) {
    fprintf(stderr, "Pipe creation Failed.\n");
    exit(1);
  }
  childpid = fork();
  switch (childpid) {
  case -1:
    perror("Error creating child");
    exit(1);
  case 0:
    n = read(pd[0], buffer2, sizeof(buffer2));
    printf("Inside child, pid: %d\n", getpid());
    n = n / sizeof(int);
    printf("Numbers recieved are :- \n");
    for (i = 0; i < n; i++)
      printf("%d\n", buffer2[i]);
    exit(0);
    break;
  default:
    printf("Inside parent, pid: %d\n", getpid());
    printf("No of input? :\t");
    scanf("%d", &n);
    printf("Enter elements 1 by 1 \n");
    for (i = 0; i < n; i++) {
      scanf("%d", &buffer1[i]);
    }
    write(pd[1], buffer1, n * sizeof(int));
    waitpid(childpid, NULL, 0);
    break;
  }
  close(pd[0]);
  close(pd[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1207 <main+0x47>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c4(%rbp)
sub    $0xffffffff,%eax
je     123b <main+0x7b>
jmp    1228 <main+0x68>
mov    -0x1c4(%rbp),%eax
test   %eax,%eax
je     1251 <main+0x91>
jmp    12d9 <main+0x119>
lea    0xdd5(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c0(%rbp),%rsi
mov    $0xc8,%edx
call   1080 <read@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x10(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x10(%rbp)
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12d2 <main+0x112>
movslq -0x1c(%rbp),%rax
mov    -0x1c0(%rbp,%rax,4),%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    129f <main+0xdf>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd80(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <scanf@plt>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    135b <main+0x19b>
movslq -0x1c(%rbp),%rax
lea    -0xf0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xd3d(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1323 <main+0x163>
mov    -0x14(%rbp),%edi
lea    -0xf0(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
je     12cc <main+0xfc>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12eb <main+0x11b>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     135e <main+0x18e>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe2a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe34(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    128d <main+0xbd>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
lea    0xe08(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%rbp
jl     1270 <main+0xa0>
mov    0xc(%rsp),%edi
shl    $0x2,%edx
lea    0x10(%rsp),%rsi
call   1040 <write@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xc8,%edx
call   1090 <read@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd1e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%ebp
sar    $0x2,%ebp
mov    %ebp,0x4(%rsp)
lea    0xd47(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x4,%ebx
jl     1357 <main+0x187>
movslq %ebp,%rbp
lea    0xd04(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbp,%rbx
jl     1340 <main+0x170>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xcb2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Pipe creation Failed.\0A\00"
@.str.1 = [21 x i8] c"Error creating child\00"
@.str.2 = [23 x i8] c"Inside child, pid: %d\0A\00"
@.str.3 = [26 x i8] c"Numbers recieved are :- \0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [24 x i8] c"Inside parent, pid: %d\0A\00"
@.str.6 = [16 x i8] c"No of input? :\09\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [24 x i8] c"Enter elements 1 by 1 \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca [50 x i32]
%8 = alloca [50 x i32]
store i32 0, i32* %1
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32 (...) @fork()
store i32 %18, i32* %2
%19 = load i32, i32* %2
switch i32 %19, label %50 [
i32 -1, label %20
i32 0, label %23
]
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds [50 x i32], [50 x i32]* %8, i64 0, i64 0
%27 = call i32 @read(i32 %25, i32* %26, i32 200)
store i32 %27, i32* %4
%28 = call i32 (...) @getpid()
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = udiv i64 %31, 4
%33 = trunc i64 %32 to i32
store i32 %33, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %35
35: ; preds = %45, %23
%36 = load i32, i32* %6
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [50 x i32], [50 x i32]* %8, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %39
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %35
48: ; preds = %35
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %17
%51 = call i32 (...) @getpid()
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %4)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %6
br label %56
56: ; preds = %65, %50
%57 = load i32, i32* %6
%58 = load i32, i32* %4
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %68
60: ; preds = %56
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [50 x i32], [50 x i32]* %7, i64 0, i64 %62
%64 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %63)
br label %65
65: ; preds = %60
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %56
68: ; preds = %56
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%70 = load i32, i32* %69
%71 = getelementptr inbounds [50 x i32], [50 x i32]* %7, i64 0, i64 0
%72 = load i32, i32* %4
%73 = sext i32 %72 to i64
%74 = mul i64 %73, 4
%75 = trunc i64 %74 to i32
%76 = call i32 @write(i32 %70, i32* %71, i32 %75)
%77 = load i32, i32* %2
%78 = call i32 @waitpid(i32 %77, i32* null, i32 0)
br label %79
79: ; preds = %68
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%81 = load i32, i32* %80
%82 = call i32 @close(i32 %81)
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%84 = load i32, i32* %83
%85 = call i32 @close(i32 %84)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Pipe creation Failed.\0A\00"
@.str.1 = [21 x i8] c"Error creating child\00"
@.str.2 = [23 x i8] c"Inside child, pid: %d\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [24 x i8] c"Inside parent, pid: %d\0A\00"
@.str.6 = [16 x i8] c"No of input? :\09\00"
@.str.7 = [3 x i8] c"%d\00"
@str = [25 x i8] c"Numbers recieved are :- \00"
@str.9 = [23 x i8] c"Enter elements 1 by 1 \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [50 x i32]
%4 = alloca [50 x i32]
%5 = bitcast i32* %1 to i8*
%6 = bitcast [2 x i32]* %2 to i8*
%7 = bitcast [50 x i32]* %3 to i8*
%8 = bitcast [50 x i32]* %4 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32 (...) @fork()
switch i32 %17, label %41 [
i32 -1, label %18
i32 0, label %21
]
18: ; preds = %16
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %16
%22 = load i32, i32* %9
%23 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%24 = call i32 @read(i32 %22, i32* %23, i32 200)
%25 = call i32 (...) @getpid()
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = ashr i32 %24, 2
store i32 %27, i32* %1
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%29 = icmp sgt i32 %24, 3
br i1 %29, label %30, label %39
30: ; preds = %21
%31 = sext i32 %27 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %37, %32 ]
%34 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp slt i64 %37, %31
br i1 %38, label %32, label %39
39: ; preds = %32, %21
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %16
%42 = call i32 (...) @getpid()
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%47 = load i32, i32* %1
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %41, %49
%50 = phi i64 [ %53, %49 ], [ 0, %41 ]
%51 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %50
%52 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %51)
%53 = add nuw nsw i64 %50, 1
%54 = load i32, i32* %1
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %49, label %57
57: ; preds = %49, %41
%58 = phi i32 [ %47, %41 ], [ %54, %49 ]
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%60 = load i32, i32* %59
%61 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 0
%62 = shl i32 %58, 2
%63 = call i32 @write(i32 %60, i32* %61, i32 %62)
%64 = call i32 @waitpid(i32 %17, i32* null, i32 0)
%65 = load i32, i32* %9
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* %59
%68 = call i32 @close(i32 %67)
ret i32 0
}