#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ generate_and_run();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ wait_and_print_status(int);
int main(void) {
  const int N = 45;
  int i;
  for (i = 0; i < N; ++i) {
    pid_t p = fork();
    if (0 == p) {
      generate_and_run();
    } else if (-1 == p) {
      perror("fork");
      exit(-errno);
    } else {
      wait_and_print_status(p);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2d,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2d,-0xc(%rbp)
jge    11e2 <main+0x92>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
jne    1198 <main+0x48>
mov    $0x0,%al
call   1030 <generate_and_run@plt>
jmp    11cf <main+0x7f>
mov    $0xffffffff,%eax
cmp    -0x10(%rbp),%eax
jne    11c2 <main+0x72>
lea    0xe53(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
mov    0x2e25(%rip),%rax
sub    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%edi
call   1060 <wait_and_print_status@plt>
jmp    11cf <main+0x7f>
jmp    11d4 <main+0x84>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x2d,%ebx
jmp    116c <main+0x1c>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <generate_and_run@plt>
add    $0xffffffff,%ebx
je     1188 <main+0x38>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1160 <main+0x10>
cmp    $0xffffffff,%eax
je     118c <main+0x3c>
mov    %eax,%edi
call   1060 <wait_and_print_status@plt>
add    $0xffffffff,%ebx
jne    116c <main+0x1c>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe6d(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e41(%rip),%rax
xor    %edi,%edi
sub    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 45, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %27, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 45
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 0, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (...) @generate_and_run()
br label %26
14: ; preds = %8
%15 = load i32, i32* %4
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @errno
%20 = sub nsw i32 0, %19
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load i32, i32* %4
%24 = call i32 @wait_and_print_status(i32 %23)
br label %25
25: ; preds = %22
br label %26
26: ; preds = %25, %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %5
30: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@errno = global i32 0
define i32 @main() {
br label %1
1: ; preds = %0, %13
%2 = phi i32 [ 0, %0 ], [ %14, %13 ]
%3 = tail call i32 (...) @fork()
switch i32 %3, label %11 [
i32 0, label %4
i32 -1, label %6
]
4: ; preds = %1
%5 = tail call i32 (...) @generate_and_run()
br label %13
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = tail call i32 @wait_and_print_status(i32 %3)
br label %13
13: ; preds = %11, %4
%14 = add nuw nsw i32 %2, 1
%15 = icmp eq i32 %14, 45
br i1 %15, label %16, label %1
16: ; preds = %13
ret i32 0
}