#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*/ printf(char *);
int main(void) {
  int i;
  for (i = 0; i < 3; i++) {
    if (fork() != 0) {
      printf("a");
      if (fork() == 0) {
        printf("c");
      } else {
        printf("d");
        exit(0);
      }
    } else {
      printf("b");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c6 <main+0x96>
mov    $0x0,%al
call   1050 <fork@plt>
cmp    $0x0,%rax
je     11a7 <main+0x77>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
cmp    $0x0,%rax
jne    118f <main+0x5f>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
jmp    11a2 <main+0x72>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11b3 <main+0x83>
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
jmp    11b8 <main+0x88>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <fork@plt>
mov    $0x62,%ebx
mov    $0x62,%edi
test   %rax,%rax
je     1162 <main+0x32>
mov    $0x61,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <fork@plt>
mov    $0x63,%edi
test   %rax,%rax
jne    11bc <main+0x8c>
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     118e <main+0x5e>
mov    $0x61,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <fork@plt>
mov    $0x63,%ebx
test   %rax,%rax
jne    11bc <main+0x8c>
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     11cd <main+0x9d>
mov    $0x61,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <fork@plt>
mov    $0x63,%edi
test   %rax,%rax
je     11d2 <main+0xa2>
mov    $0x64,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1040 <exit@plt>
mov    $0x62,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32 @putchar(i32 97)
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %24, %15, %3
%8 = tail call i32 @putchar(i32 100)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %0, %3
%11 = phi i32 [ 99, %3 ], [ 98, %0 ]
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = tail call i32 @putchar(i32 97)
%17 = tail call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %7
19: ; preds = %10, %15
%20 = phi i32 [ 99, %15 ], [ 98, %10 ]
%21 = tail call i32 @putchar(i32 %20)
%22 = tail call i64 (...) @fork()
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = tail call i32 @putchar(i32 97)
%26 = tail call i64 (...) @fork()
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %7
28: ; preds = %19, %24
%29 = phi i32 [ 99, %24 ], [ 98, %19 ]
%30 = tail call i32 @putchar(i32 %29)
ret i32 0
}