#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ getchar();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
void main() {
  printf("P.S. :: View the processes created by a.out from another tty using "
         "the command :: ps -vf\n\n");
  pid_t pid = fork();
  if (pid > 0) {
    printf("This is PARENT'S block,PID = %d...Sleeping for 10s\n", getpid());
    sleep(10);
  } else {
    printf("This is CHILD'S block,PID = %d", getpid());
    exit(0);
  }
  printf("Now creating orphan\n");
  pid = fork();
  if (pid > 0)
    printf("This is PARENT'S block,PID = %d\n", getpid());
  else {
    sleep(1);
    printf("This is ORPHAN CHILD'S block,PID = %d,press a key to exit",
           getpid());
    getchar();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jle    11b2 <main+0x52>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1070 <sleep@plt>
jmp    11d0 <main+0x70>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jle    1210 <main+0xb0>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1238 <main+0xd8>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
test   %rbx,%rbx
jle    1206 <main+0x96>
lea    0xe66(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
lea    0xf54(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jle    11dd <main+0x6d>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe80(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1050 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
jmp    1060 <getchar@plt>
lea    0xe27(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [91 x i8] c"P.S. :: View the processes created by a.out from another tty using the command :: ps -vf\0A\0A\00"
@.str.1 = [52 x i8] c"This is PARENT'S block,PID = %d...Sleeping for 10s\0A\00"
@.str.2 = [31 x i8] c"This is CHILD'S block,PID = %d\00"
@.str.3 = [21 x i8] c"Now creating orphan\0A\00"
@.str.4 = [33 x i8] c"This is PARENT'S block,PID = %d\0A\00"
@.str.5 = [58 x i8] c"This is ORPHAN CHILD'S block,PID = %d,press a key to exit\00"
define void @main() {
%1 = alloca i64
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
%3 = call i64 (...) @fork()
store i64 %3, i64* %1
%4 = load i64, i64* %1
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 (...) @getpid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 @sleep(i32 10)
br label %14
10: ; preds = %0
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%16 = call i64 (...) @fork()
store i64 %16, i64* %1
%17 = load i64, i64* %1
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 (...) @getpid()
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %27
22: ; preds = %14
%23 = call i32 @sleep(i32 1)
%24 = call i32 (...) @getpid()
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @getchar()
br label %27
27: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@.str.1 = [52 x i8] c"This is PARENT'S block,PID = %d...Sleeping for 10s\0A\00"
@.str.2 = [31 x i8] c"This is CHILD'S block,PID = %d\00"
@.str.4 = [33 x i8] c"This is PARENT'S block,PID = %d\0A\00"
@.str.5 = [58 x i8] c"This is ORPHAN CHILD'S block,PID = %d,press a key to exit\00"
@str = [90 x i8] c"P.S. :: View the processes created by a.out from another tty using the command :: ps -vf\0A\00"
@str.6 = [20 x i8] c"Now creating orphan\00"
define void @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @fork()
%3 = icmp sgt i64 %2, 0
%4 = tail call i32 (...) @getpid()
br i1 %3, label %5, label %11
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%7 = tail call i32 @sleep(i32 10)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i64 (...) @fork()
%10 = icmp sgt i64 %9, 0
br i1 %10, label %14, label %17
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %5
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %22
17: ; preds = %5
%18 = tail call i32 @sleep(i32 1)
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = tail call i32 (...) @getchar()
br label %22
22: ; preds = %17, %14
ret void
}