#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*/);
int fork();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  int i, p;
  for (i = 0; i < 5; i++) {
    p = fork();
    if (p == 0) {
      exit(0);
    }
  }
  sleep(10);
  for (i = 0; i < 5; i++) {
    wait(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    118e <main+0x4e>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117b <main+0x3b>
xor    %edi,%edi
call   1030 <exit@plt>
jmp    1180 <main+0x40>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x16>
mov    $0xa,%edi
call   1040 <sleep@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11be <main+0x7e>
xor    %edi,%edi
call   1050 <wait@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119f <main+0x5f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a9 <main+0x69>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a9 <main+0x69>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a9 <main+0x69>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a9 <main+0x69>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a9 <main+0x69>
mov    $0xa,%edi
call   1040 <sleep@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %edi,%edi
call   1030 <exit@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 5
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = call i32 (...) @fork()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %7
br label %14
14: ; preds = %13
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %4
17: ; preds = %4
%18 = call i32 @sleep(i32 10)
store i32 0, i32* %2
br label %19
19: ; preds = %24, %17
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 5
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = call i32 @wait(i32 0)
br label %24
24: ; preds = %22
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %19
27: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %22, label %3
3: ; preds = %0
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %3
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %9
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = tail call i32 @sleep(i32 10)
%17 = tail call i32 @wait(i32 0)
%18 = tail call i32 @wait(i32 0)
%19 = tail call i32 @wait(i32 0)
%20 = tail call i32 @wait(i32 0)
%21 = tail call i32 @wait(i32 0)
ret i32 0
22: ; preds = %12, %9, %6, %3, %0
%23 = tail call i32 @exit(i32 0)
unreachable
}