#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 /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(void) {
  pid_t pids[10];
  int i;
  for (i = 9; i >= 0; --i) {
    pids[i] = fork();
    if (pids[i] == 0) {
      sleep(i + 1);
      _exit(0);
    }
  }
  for (i = 9; i >= 0; --i)
    waitpid(pids[i], NULL, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x9,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jl     11a8 <main+0x68>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
movslq -0x64(%rbp),%rax
cmpq   $0x0,-0x60(%rbp,%rax,8)
jne    1195 <main+0x55>
mov    -0x64(%rbp),%edi
add    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    119a <main+0x5a>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    1156 <main+0x16>
movl   $0x9,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jl     11db <main+0x9b>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    11af <main+0x6f>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12b1 <main+0x171>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12b8 <main+0x178>
mov    %rax,%r13
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12bf <main+0x17f>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12c6 <main+0x186>
mov    %rax,%rbp
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12cd <main+0x18d>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12d4 <main+0x194>
mov    %rax,0x20(%rsp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     12db <main+0x19b>
mov    %rbx,0x10(%rsp)
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12e2 <main+0x1a2>
mov    %rax,%r15
mov    %rbp,0x8(%rsp)
mov    %r13,%rbp
mov    %r12,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12e9 <main+0x1a9>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     12f0 <main+0x1b0>
mov    %rax,%r13
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x10(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x20(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x18(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %r12,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
jmp    12f5 <main+0x1b5>
mov    $0x9,%edi
jmp    12f5 <main+0x1b5>
mov    $0x8,%edi
jmp    12f5 <main+0x1b5>
mov    $0x7,%edi
jmp    12f5 <main+0x1b5>
mov    $0x6,%edi
jmp    12f5 <main+0x1b5>
mov    $0x5,%edi
jmp    12f5 <main+0x1b5>
mov    $0x4,%edi
jmp    12f5 <main+0x1b5>
mov    $0x3,%edi
jmp    12f5 <main+0x1b5>
mov    $0x2,%edi
jmp    12f5 <main+0x1b5>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i64]
%3 = alloca i32
store i32 0, i32* %1
store i32 9, i32* %3
br label %4
4: ; preds = %23, %0
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = call i64 (...) @fork()
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 %10
store i64 %8, i64* %11
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 %13
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %7
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = call i32 @sleep(i32 %19)
%21 = call i32 @_exit(i32 0)
unreachable
22: ; preds = %7
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %4
26: ; preds = %4
store i32 9, i32* %3
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %3
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 %32
%34 = load i64, i64* %33
%35 = call i32 @waitpid(i64 %34, i32* null, i32 0)
br label %36
36: ; preds = %30
%37 = load i32, i32* %3
%38 = add nsw i32 %37, -1
store i32 %38, i32* %3
br label %27
39: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %31, %28, %25, %22, %19, %16, %13, %10, %7, %0
%4 = phi i32 [ 10, %0 ], [ 9, %7 ], [ 8, %10 ], [ 7, %13 ], [ 6, %16 ], [ 5, %19 ], [ 4, %22 ], [ 3, %25 ], [ 2, %28 ], [ 1, %31 ]
%5 = tail call i32 @sleep(i32 %4)
%6 = tail call i32 @_exit(i32 0)
unreachable
7: ; preds = %0
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %3, label %10
10: ; preds = %7
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %3, label %13
13: ; preds = %10
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %13
%17 = tail call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %3, label %19
19: ; preds = %16
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %3, label %22
22: ; preds = %19
%23 = tail call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %3, label %25
25: ; preds = %22
%26 = tail call i64 (...) @fork()
%27 = icmp eq i64 %26, 0
br i1 %27, label %3, label %28
28: ; preds = %25
%29 = tail call i64 (...) @fork()
%30 = icmp eq i64 %29, 0
br i1 %30, label %3, label %31
31: ; preds = %28
%32 = tail call i64 (...) @fork()
%33 = icmp eq i64 %32, 0
br i1 %33, label %3, label %34
34: ; preds = %31
%35 = tail call i32 @waitpid(i64 %1, i32* null, i32 0)
%36 = tail call i32 @waitpid(i64 %8, i32* null, i32 0)
%37 = tail call i32 @waitpid(i64 %11, i32* null, i32 0)
%38 = tail call i32 @waitpid(i64 %14, i32* null, i32 0)
%39 = tail call i32 @waitpid(i64 %17, i32* null, i32 0)
%40 = tail call i32 @waitpid(i64 %20, i32* null, i32 0)
%41 = tail call i32 @waitpid(i64 %23, i32* null, i32 0)
%42 = tail call i32 @waitpid(i64 %26, i32* null, i32 0)
%43 = tail call i32 @waitpid(i64 %29, i32* null, i32 0)
%44 = tail call i32 @waitpid(i64 %32, i32* null, i32 0)
ret i32 0
}