#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 */
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");
    f = fork();
    if (f == 0) {
      printf("C");
      f = fork();
      if (f == 0) {
        printf("D");
      }
    }
  }
  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    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ea <main+0xaa>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e5 <main+0xa5>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <main+0xa0>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e5 <main+0xa5>
jmp    11ea <main+0xaa>
mov    $0xa,%edi
call   1050 <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    0xea1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x41,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11b4 <main+0x64>
mov    $0x42,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11b4 <main+0x64>
mov    $0x43,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11b4 <main+0x64>
mov    $0x44,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
pop    %rcx
ret

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"
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 %23
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 i64 (...) @fork()
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = call i64 (...) @fork()
store i64 %16, i64* %2
%17 = load i64, i64* %2
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
br label %22
22: ; preds = %21, %9
br label %23
23: ; preds = %22, %0
%24 = 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 %16
6: ; preds = %0
%7 = tail call i32 @putchar(i32 66)
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = tail call i32 @putchar(i32 67)
%12 = tail call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @putchar(i32 68)
br label %16
16: ; preds = %6, %14, %10, %0
%17 = tail call i32 @sleep(i32 10)
ret i32 0
}