#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 getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
void main() {
  pid_t pid = fork();
  if (pid != 0) {
    wait(0);
    printf("\nThis is PARENT BLOCK");
    printf("\n\t* MY PID          = %d", getpid());
    printf("\n\t* MY CHILD'S PID  = %d", pid);
    printf("\n\t* MY OWNER'S PID  = %d\n\n", getppid());
  } else {
    printf("\nTHIS IS CHILD'S BLOCK");
    printf("\n\t* MY PARENT'S PID = %d", getppid());
    printf("\n\t* MY PID          = %d\n", getpid());
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d8 <main+0x78>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121b <main+0xbb>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11c5 <main+0x65>
mov    %rax,%rbx
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"\0AThis is PARENT BLOCK\00"
@.str.1 = [25 x i8] c"\0A\09* MY PID = %d\00"
@.str.2 = [25 x i8] c"\0A\09* MY CHILD'S PID = %d\00"
@.str.3 = [27 x i8] c"\0A\09* MY OWNER'S PID = %d\0A\0A\00"
@.str.4 = [23 x i8] c"\0ATHIS IS CHILD'S BLOCK\00"
@.str.5 = [25 x i8] c"\0A\09* MY PARENT'S PID = %d\00"
@.str.6 = [26 x i8] c"\0A\09* MY PID = %d\0A\00"
define void @main() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = call i32 @wait(i32 0)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i64, i64* %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %10)
%12 = call i32 (...) @getppid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %21
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (...) @getppid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @getpid()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0AThis is PARENT BLOCK\00"
@.str.1 = [25 x i8] c"\0A\09* MY PID = %d\00"
@.str.2 = [25 x i8] c"\0A\09* MY CHILD'S PID = %d\00"
@.str.3 = [27 x i8] c"\0A\09* MY OWNER'S PID = %d\0A\0A\00"
@.str.4 = [23 x i8] c"\0ATHIS IS CHILD'S BLOCK\00"
@.str.5 = [25 x i8] c"\0A\09* MY PARENT'S PID = %d\00"
@.str.6 = [26 x i8] c"\0A\09* MY PID = %d\0A\00"
define void @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call i32 @wait(i32 0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %1)
%9 = tail call i32 (...) @getppid()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %9)
ret void
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 (...) @getppid()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %15)
%17 = tail call i32 @exit(i32 0)
unreachable
}