#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 /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t f1, f2, f3, f4;
  f1 = fork();
  if (f1 == 0) {
    printf("A\n");
  } else {
    f2 = fork();
    if (f2 == 0) {
      printf("B\n");
    } else {
      f3 = fork();
      if (f3 == 0) {
        printf("C\n");
      } else {
        f4 = fork();
        if (f4 == 0) {
          printf("D\n");
        }
      }
    }
  }
  sleep(15);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1166 <main+0x36>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
jmp    11e5 <main+0xb5>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <main+0x5d>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <main+0xb0>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <main+0x84>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
jmp    11db <main+0xab>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d6 <main+0xa6>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
jmp    11db <main+0xab>
jmp    11e0 <main+0xb0>
jmp    11e5 <main+0xb5>
mov    $0xf,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     116a <main+0x3a>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1173 <main+0x43>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     117c <main+0x4c>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jne    1188 <main+0x58>
lea    0xe98(%rip),%rdi
jmp    1183 <main+0x53>
lea    0xe95(%rip),%rdi
jmp    1183 <main+0x53>
lea    0xe8a(%rip),%rdi
jmp    1183 <main+0x53>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xf,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@str = [2 x i8] c"D\00"
@str.4 = [2 x i8] c"C\00"
@str.5 = [2 x i8] c"B\00"
@str.6 = [2 x i8] c"A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %12, label %3
3: ; preds = %0
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9, %6, %3, %0
%13 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0), %0 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %3 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %9 ]
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
br label %15
15: ; preds = %12, %9
%16 = tail call i32 @sleep(i32 15)
ret i32 0
}