#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(int argc, char **argv) {
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c0 <main+0x70>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11ad <main+0x5d>
mov    $0x0,%al
call   1040 <task@plt>
jmp    11b2 <main+0x62>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <main+0x39>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ea <main+0x9a>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c7 <main+0x77>
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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %6
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %10
10: ; preds = %20, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (...) @task()
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %10
23: ; preds = %10
store i32 0, i32* %7
br label %24
24: ; preds = %30, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = call i32 @wait(i32* null)
br label %30
30: ; preds = %28
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %24
33: ; preds = %24
%34 = 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(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %2, %11
%6 = phi i32 [ 0, %2 ], [ %12, %11 ]
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 (...) @task()
br label %11
11: ; preds = %5, %9
%12 = add nuw nsw i32 %6, 1
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %5
14: ; preds = %11, %14
%15 = phi i32 [ %17, %14 ], [ 0, %11 ]
%16 = tail call i32 @wait(i32* null)
%17 = add nuw nsw i32 %15, 1
%18 = icmp eq i32 %17, 100
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = tail call i32 @exit(i32 0)
unreachable
}