#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;

/* Variables and functions */
int EXIT_FAILURE;
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 /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char **, int);
int main() {
  int pid, a, n, p[2], i, vv;
  char str1[100][100], str2[100][100];
  printf("Number of strings:- ");
  scanf("%d", &n);
  a = pipe(p);
  if (a == -1) {
    fprintf(stderr, "Pipe Failed.\n");
    return EXIT_FAILURE;
  }
  pid = fork();
  switch (pid) {
  case -1:
    perror("main: fork");
    exit(1);
  case 0:
    read(p[0], str2, sizeof(str2));
    printf("In child process (ID: %d)\n", getpid());
    for (i = 0; i < n; i++)
      printf("String %d:- %s\n", i + 1, str2[i]);
    exit(1);
    break;
  default:
    printf("In parent process (ID: %d)\n", getpid());
    for (i = 0; i < n; i++) {
      printf("Enter the string %d:- ", i + 1);
      scanf("%s", str1[i]);
    }
    write(p[1], str1, sizeof(str1));
    waitpid(pid, NULL, 0);
    break;
  }
  close(p[0]);
  close(p[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2e(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    122e <main+0x6e>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1399 <main+0x1d9>
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4e44(%rbp)
sub    $0xffffffff,%eax
je     1262 <main+0xa2>
jmp    124f <main+0x8f>
mov    -0x4e44(%rbp),%eax
test   %eax,%eax
je     1278 <main+0xb8>
jmp    12f4 <main+0x134>
lea    0xdbd(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x4e40(%rbp),%rsi
mov    $0x2710,%edx
call   1080 <read@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12ea <main+0x12a>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
movslq -0x1c(%rbp),%rax
lea    -0x4e40(%rbp),%rdx
imul   $0x64,%rax,%rax
add    %rax,%rdx
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12aa <main+0xea>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1360 <main+0x1a0>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x1c(%rbp),%rax
lea    -0x2730(%rbp),%rsi
imul   $0x64,%rax,%rax
add    %rax,%rsi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1312 <main+0x152>
mov    -0x14(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    $0x2710,%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>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe2f(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     12be <main+0xfe>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f2 <main+0x132>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     135b <main+0x19b>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe2b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    128b <main+0xcb>
lea    0x10(%rsp),%rbx
lea    0xe2b(%rip),%r12
lea    0xe3b(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
movslq 0x4(%rsp),%rax
add    $0x64,%rbx
cmp    %rax,%rbp
jl     1260 <main+0xa0>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x2710,%edx
call   1030 <write@plt>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
jmp    12dd <main+0x11d>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1080 <read@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd1b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1351 <main+0x191>
lea    0xd1f(%rip),%r14
xor    %ebp,%ebp
nop
add    $0x1,%rbp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0x4(%rsp),%rax
add    $0x64,%rbx
cmp    %rax,%rbp
jl     1330 <main+0x170>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xcc4(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Number of strings:- \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [14 x i8] c"Pipe Failed.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [11 x i8] c"main: fork\00"
@.str.4 = [27 x i8] c"In child process (ID: %d)\0A\00"
@.str.5 = [16 x i8] c"String %d:- %s\0A\00"
@.str.6 = [28 x i8] c"In parent process (ID: %d)\0A\00"
@.str.7 = [23 x i8] c"Enter the string %d:- \00"
@.str.8 = [3 x i8] c"%s\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 i32
%8 = alloca [100 x [100 x i8]]
%9 = alloca [100 x [100 x i8]]
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %1
br label %85
20: ; preds = %0
%21 = call i32 (...) @fork()
store i32 %21, i32* %2
%22 = load i32, i32* %2
switch i32 %22, label %51 [
i32 -1, label %23
i32 0, label %26
]
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %9, i64 0, i64 0
%30 = bitcast [100 x i8]* %29 to i8**
%31 = call i32 @read(i32 %28, i8** %30, i32 10000)
%32 = call i32 (...) @getpid()
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %32)
store i32 0, i32* %6
br label %34
34: ; preds = %46, %26
%35 = load i32, i32* %6
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %9, i64 0, i64 %42
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %43, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %40, i8* %44)
br label %46
46: ; preds = %38
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %34
49: ; preds = %34
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %20
%52 = call i32 (...) @getpid()
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %52)
store i32 0, i32* %6
br label %54
54: ; preds = %67, %51
%55 = load i32, i32* %6
%56 = load i32, i32* %4
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %70
58: ; preds = %54
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %8, i64 0, i64 %63
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %64, i64 0, i64 0
%66 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %58
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %54
70: ; preds = %54
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%72 = load i32, i32* %71
%73 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %8, i64 0, i64 0
%74 = bitcast [100 x i8]* %73 to i8**
%75 = call i32 @write(i32 %72, i8** %74, i32 10000)
%76 = load i32, i32* %2
%77 = call i32 @waitpid(i32 %76, i32* null, i32 0)
br label %78
78: ; preds = %70
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%80 = load i32, i32* %79
%81 = call i32 @close(i32 %80)
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%83 = load i32, i32* %82
%84 = call i32 @close(i32 %83)
store i32 0, i32* %1
br label %85
85: ; preds = %78, %16
%86 = load i32, i32* %1
ret i32 %86
}

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