#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t f;
  printf("Pai (PID=%u) \n", getpid());
  printf("A");
  f = fork();
  if (f == 0) {
    printf("B");
    exit(0);
  }
  f = fork();
  if (f == 0) {
    printf("C");
    f = fork();
    if (f == 0) {
      printf("D");
      exit(0);
    }
    f = fork();
    if (f == 0) {
      printf("E");
      exit(0);
    }
  }
  sleep(10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11af <main+0x5f>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122e <main+0xde>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11fe <main+0xae>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1229 <main+0xd9>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    122e <main+0xde>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x41,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ca <main+0x6a>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11bc <main+0x5c>
mov    $0x43,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11d1 <main+0x71>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11d8 <main+0x78>
mov    $0xa,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x42,%edi
jmp    11dd <main+0x7d>
mov    $0x44,%edi
jmp    11dd <main+0x7d>
mov    $0x45,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Pai (PID=%u) \0A\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"B\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [2 x i8] c"D\00"
@.str.5 = [2 x i8] c"E\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i32 (...) @getpid()
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = call i64 (...) @fork()
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = call i64 (...) @fork()
store i64 %18, i64* %2
%19 = load i64, i64* %2
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = call i64 (...) @fork()
store i64 %25, i64* %2
%26 = load i64, i64* %2
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %24
br label %32
32: ; preds = %31, %12
%33 = call i32 @sleep(i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Pai (PID=%u) \0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @putchar(i32 65)
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @putchar(i32 66)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = tail call i32 @putchar(i32 67)
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @putchar(i32 68)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %12
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @putchar(i32 69)
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %19, %9
%26 = tail call i32 @sleep(i32 10)
ret i32 0
}