#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ task();
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(void) {
  int n_tasks = 100, i;
  fprintf(stderr, "[No further output means we're allright]\n");
  for (i = 0; i < n_tasks; i++)
    if (fork() == 0)
      task();
  for (i = 0; i < n_tasks; i++)
    wait(NULL);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b9 <main+0x69>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11a6 <main+0x56>
mov    $0x0,%al
call   1040 <task@plt>
jmp    11ab <main+0x5b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <main+0x32>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <main+0x93>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c0 <main+0x70>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x64,%ebx
jmp    1175 <main+0x25>
nopl   (%rax)
add    $0xffffffff,%ebx
je     118a <main+0x3a>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    1170 <main+0x20>
xor    %eax,%eax
call   1040 <task@plt>
jmp    1170 <main+0x20>
mov    $0x64,%ebx
nop
xor    %edi,%edi
call   1060 <wait@plt>
add    $0xffffffff,%ebx
jne    1190 <main+0x40>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"[No further output means we're allright]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %2
%4 = load i32, i32* @stderr
%5 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %16, %0
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (...) @task()
br label %15
15: ; preds = %13, %10
br label %16
16: ; preds = %15
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %6
19: ; preds = %6
store i32 0, i32* %3
br label %20
20: ; preds = %26, %19
%21 = load i32, i32* %3
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = call i32 @wait(i32* null)
br label %26
26: ; preds = %24
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %20
29: ; preds = %20
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"[No further output means we're allright]\0A\00"
define i32 @main() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %0, %9
%4 = phi i32 [ 0, %0 ], [ %10, %9 ]
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (...) @task()
br label %9
9: ; preds = %3, %7
%10 = add nuw nsw i32 %4, 1
%11 = icmp eq i32 %10, 100
br i1 %11, label %12, label %3
12: ; preds = %9, %12
%13 = phi i32 [ %15, %12 ], [ 0, %9 ]
%14 = tail call i32 @wait(i32* null)
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, 100
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = tail call i32 @exit(i32 0)
unreachable
}