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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int);
int main() {
  int flag = 0;
  printf("Process_1\n");
  if (fork() == 0) {
    printf("Process_2\n");
    flag = 1;
    if (fork() == 0) {
      printf("Process_3\n");
      flag = 0;
    }
    if (flag == 1) {
      printf("Wait call by Process_2\n");
      wait(10);
    }
    if (flag == 0) {
      printf("Process_3 Terminates\n");
      exit(0);
    }
    flag = 1;
  }
  if (flag == 0) {
    printf("Wait call by Process_1\n");
    wait(10);
  }
  if (flag == 1) {
    printf("Process_2 Terminates\n");
    exit(0);
  }
  printf("Process_1 Terminates\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xee9(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11ee <main+0xae>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11aa <main+0x6a>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ca <main+0x8a>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1050 <wait@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11e7 <main+0xa7>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    120e <main+0xce>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1050 <wait@plt>
cmpl   $0x1,-0x8(%rbp)
jne    122b <main+0xeb>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     117f <main+0x3f>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1050 <wait@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jne    11ac <main+0x6c>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xe97(%rip),%rdi
jmp    11c9 <main+0x89>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1050 <wait@plt>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"Process_1\0A\00"
@.str.1 = [11 x i8] c"Process_2\0A\00"
@.str.2 = [11 x i8] c"Process_3\0A\00"
@.str.3 = [24 x i8] c"Wait call by Process_2\0A\00"
@.str.4 = [22 x i8] c"Process_3 Terminates\0A\00"
@.str.5 = [24 x i8] c"Wait call by Process_1\0A\00"
@.str.6 = [22 x i8] c"Process_2 Terminates\0A\00"
@.str.7 = [22 x i8] c"Process_1 Terminates\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
%8 = call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %12
12: ; preds = %10, %6
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @wait(i32 10)
br label %18
18: ; preds = %15, %12
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %18
store i32 1, i32* %2
br label %25
25: ; preds = %24, %0
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @wait(i32 10)
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %31
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [10 x i8] c"Process_1\00"
@str.8 = [21 x i8] c"Process_1 Terminates\00"
@str.9 = [21 x i8] c"Process_2 Terminates\00"
@str.10 = [23 x i8] c"Wait call by Process_1\00"
@str.11 = [10 x i8] c"Process_2\00"
@str.12 = [21 x i8] c"Process_3 Terminates\00"
@str.13 = [23 x i8] c"Wait call by Process_2\00"
@str.14 = [10 x i8] c"Process_3\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.11, i64 0, i64 0))
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.13, i64 0, i64 0))
%14 = tail call i32 @wait(i32 10)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%19 = tail call i32 @wait(i32 10)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}