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

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int WIFSIGNALED(int);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ wait(int *);
void main() {
  int status;
  pid_t pid = fork();
  if (pid != 0) {
    wait(&status);
    printf("\n-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P");
    printf("\n\nThis is PARENT'S block");
    if (WIFEXITED(status)) {
      printf("\n\nChild's Termination was NORMAL.\n\tWIFEXITED returned : %d");
      printf("\nThe exit status returned by the child is :: %d\n",
             WEXITSTATUS(status));
    } else {
      printf("\nChild's Termination was ABNORMAL\n\n");
      printf("The value of WIFSIGNALED is :: %d\n", WIFSIGNALED(status));
    }
    printf(
        "\n-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P\n");
  } else {
    printf("\n-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C");
    printf("\n\nThis is CHILD'S block");
    char option;
    printf("\nHow do you wish to terminate the child?\n\t1. "
           "NORMALLY\n\t(Not)1. ABNORMALLY\nYour Response ::");
    if ((option = getchar()) == '1') {
      printf("\nWhat (8 bit) value should the child return to the parent?\n");
      int op;
      scanf("%d", &op);
      printf(
          "\n-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C");
      exit(op);
    } else {
      printf(
          "\n-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C");
      abort();
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1259 <main+0xb9>
lea    -0x4(%rbp),%rdi
call   10b0 <wait@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1220 <main+0x80>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1246 <main+0xa6>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
mov    %eax,%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e2 <main+0x142>
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x31,%eax
jne    12cd <main+0x12d>
lea    0xf60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde3(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   10a0 <exit@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     1243 <main+0x93>
mov    %rsp,%rdi
call   10c0 <wait@plt>
lea    0xfe9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     1211 <main+0x61>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%edi
call   1090 <WEXITSTATUS@plt>
lea    0xe45(%rip),%rdi
jmp    122c <main+0x7c>
lea    0xf7e(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%edi
call   1060 <WIFSIGNALED@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf7d(%rip),%rdi
call   1040 <puts@plt>
pop    %rax
ret
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x31,%al
jne    12ac <main+0xfc>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
lea    0xdc6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   10b0 <exit@plt>
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [64 x i8] c"\0A-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P\00"
@.str.1 = [25 x i8] c"\0A\0AThis is PARENT'S block\00"
@.str.2 = [59 x i8] c"\0A\0AChild's Termination was NORMAL.\0A\09WIFEXITED returned : %d\00"
@.str.3 = [49 x i8] c"\0AThe exit status returned by the child is :: %d\0A\00"
@.str.4 = [36 x i8] c"\0AChild's Termination was ABNORMAL\0A\0A\00"
@.str.5 = [35 x i8] c"The value of WIFSIGNALED is :: %d\0A\00"
@.str.6 = [65 x i8] c"\0A-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P\0A\00"
@.str.7 = [64 x i8] c"\0A-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C\00"
@.str.8 = [24 x i8] c"\0A\0AThis is CHILD'S block\00"
@.str.9 = [91 x i8] c"\0AHow do you wish to terminate the child?\0A\091. NORMALLY\0A\09(Not)1. ABNORMALLY\0AYour Response ::\00"
@.str.10 = [60 x i8] c"\0AWhat (8 bit) value should the child return to the parent?\0A\00"
@.str.11 = [3 x i8] c"%d\00"
define void @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8
%4 = alloca i32
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %0
%9 = call i32 @wait(i32* %1)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = call i64 @WIFEXITED(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %1
%18 = call i32 @WEXITSTATUS(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %25
20: ; preds = %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* %1
%23 = call i32 @WIFSIGNALED(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %20, %15
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
br label %43
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.9, i64 0, i64 0))
%31 = call signext i8 (...) @getchar()
store i8 %31, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 49
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.10, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32* %4)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%38 = load i32, i32* %4
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %25
ret void
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"\0A\0AThis is PARENT'S block\00"
@.str.2 = [59 x i8] c"\0A\0AChild's Termination was NORMAL.\0A\09WIFEXITED returned : %d\00"
@.str.3 = [49 x i8] c"\0AThe exit status returned by the child is :: %d\0A\00"
@.str.5 = [35 x i8] c"The value of WIFSIGNALED is :: %d\0A\00"
@.str.7 = [64 x i8] c"\0A-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C\00"
@.str.8 = [24 x i8] c"\0A\0AThis is CHILD'S block\00"
@.str.9 = [91 x i8] c"\0AHow do you wish to terminate the child?\0A\091. NORMALLY\0A\09(Not)1. ABNORMALLY\0AYour Response ::\00"
@.str.11 = [3 x i8] c"%d\00"
@str = [59 x i8] c"\0AWhat (8 bit) value should the child return to the parent?\00"
@str.12 = [35 x i8] c"\0AChild's Termination was ABNORMAL\0A\00"
@str.13 = [64 x i8] c"\0A-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %0
%7 = call i32 @wait(i32* %1)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.13, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = call i64 @WIFEXITED(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %6
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %23
18: ; preds = %6
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = call i32 @WIFSIGNALED(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %18, %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.13, i64 0, i64 0))
ret void
25: ; preds = %0
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.9, i64 0, i64 0))
%29 = tail call signext i8 (...) @getchar()
%30 = icmp eq i8 %29, 49
br i1 %30, label %31, label %38
31: ; preds = %25
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%33 = bitcast i32* %2 to i8*
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32* %2)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%36 = load i32, i32* %2
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %25
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%40 = tail call i32 (...) @abort()
unreachable
}