#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*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int getpid();
int getppid();
int /*<<< orphan*/ stdout;
int main() {
  int i;
  fprintf(stdout, "Starting PID=%d\n", getpid());
  for (i = 0; i < 3; i++) {
    if (fork() == 0) {
      fprintf(stdout, "Body: Process %d (PID=%d)\n", i, getpid());
      break;
    }
  }
  fprintf(stdout, "Ending PID=%d (PPID=%d)\n", getpid(), getppid());
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%edx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ee <main+0x9e>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11db <main+0x8b>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    %eax,%ecx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11ee <main+0x9e>
jmp    11e0 <main+0x90>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118c <main+0x3c>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e85(%rip),%r14
mov    (%r14),%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11a7 <main+0x57>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11a7 <main+0x57>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x2,%ebx
test   %rax,%rax
jne    11c5 <main+0x75>
mov    (%r14),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe59(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe4d(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [17 x i8] c"Starting PID=%d\0A\00"
@.str.1 = [27 x i8] c"Body: Process %d (PID=%d)\0A\00"
@.str.2 = [25 x i8] c"Ending PID=%d (PPID=%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @stdout
%4 = call i32 (...) @getpid()
%5 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 0, i32* %2
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stdout
%14 = load i32, i32* %2
%15 = call i32 (...) @getpid()
%16 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15)
br label %21
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %6
21: ; preds = %12, %6
%22 = load i32, i32* @stdout
%23 = call i32 (...) @getpid()
%24 = call i32 (...) @getppid()
%25 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
%26 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [17 x i8] c"Starting PID=%d\0A\00"
@.str.1 = [27 x i8] c"Body: Process %d (PID=%d)\0A\00"
@.str.2 = [25 x i8] c"Ending PID=%d (PPID=%d)\0A\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %14, %11, %0
%7 = phi i32 [ 0, %0 ], [ 1, %11 ], [ 2, %14 ]
%8 = load i32, i32* @stdout
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9)
br label %17
11: ; preds = %0
%12 = tail call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %11
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %14, %6
%18 = load i32, i32* @stdout
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 (...) @getppid()
%21 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
%22 = tail call i32 @exit(i32 0)
unreachable
}