#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*/ child();
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  const int kChildren = 40;
  pid_t pid;
  for (int i = 0; i < kChildren; ++i) {
    pid = fork();
    if (pid < 0) {
      exit(1);
    } else if (pid == 0) {
      child();
      exit(0);
    } else {
      int status;
      wait(&status);
      if (status == 0)
        exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x28,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x28,-0x24(%rbp)
jge    11e1 <main+0xa1>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    118e <main+0x4e>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <main+0x67>
mov    $0x0,%al
call   1030 <child@plt>
xor    %edi,%edi
call   1040 <exit@plt>
lea    -0x28(%rbp),%rdi
call   1050 <wait@plt>
cmpl   $0x0,-0x28(%rbp)
jne    11c4 <main+0x84>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11c9 <main+0x89>
jmp    11ce <main+0x8e>
jmp    11d3 <main+0x93>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x28,%ebp
lea    0x4(%rsp),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     117b <main+0x3b>
je     1185 <main+0x45>
mov    %rbx,%rdi
call   1050 <wait@plt>
cmpl   $0x0,0x4(%rsp)
je     117b <main+0x3b>
add    $0xffffffff,%ebp
jne    1150 <main+0x10>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%edi
call   1040 <exit@plt>
xor    %eax,%eax
call   1030 <child@plt>
xor    %edi,%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %6
5: ; preds = %23
ret i32 0
6: ; preds = %2, %23
%7 = phi i32 [ 0, %2 ], [ %24, %23 ]
%8 = call i64 (...) @fork()
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = icmp eq i64 %8, 0
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = call i32 (...) @child()
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %12
%18 = call i32 @wait(i32* %3)
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = add nuw nsw i32 %7, 1
%25 = icmp eq i32 %24, 40
br i1 %25, label %5, label %6
}