#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*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ nice(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(int argc, char *argv[]) {
  for (int i = 0; i <= 20; i++) {
    if (fork() == 0) {
      char label[5];
      sprintf(label, "ID%02d", i);
      nice(i);
      char *args[] = {"./simpson", "0", "6.28", "1000000000", label};
      execv("./simpson", args);
    }
  }
  printf("forked all\n");
  sleep(30);
  printf("done all\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jg     121a <main+0xaa>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1207 <main+0x97>
lea    -0x19(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe4a(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <nice@plt>
lea    0xe3d(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe4a(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe31(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe2b(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x19(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1080 <execv@plt>
jmp    120c <main+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x1d>
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1e,%edi
call   1070 <sleep@plt>
lea    0xdf6(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xb(%rsp),%r15
lea    0xe7d(%rip),%rbx
lea    0xe80(%rip),%r14
lea    0xe7e(%rip),%r13
lea    0x10(%rsp),%r12
xor    %ebp,%ebp
jmp    11b8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x15,%ebp
je     1209 <main+0x99>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    11b0 <main+0x40>
mov    %r15,%rdi
lea    0xe32(%rip),%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %ebp,%edi
call   1040 <nice@plt>
mov    %rbx,0x10(%rsp)
lea    0xe37(%rip),%rax
mov    %rax,0x18(%rsp)
mov    %r14,0x20(%rsp)
mov    %r13,0x28(%rsp)
mov    %r15,0x30(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <execv@plt>
jmp    11b0 <main+0x40>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1e,%edi
call   1070 <sleep@plt>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"ID%02d\00"
@.str.1 = [10 x i8] c"./simpson\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [5 x i8] c"6.28\00"
@.str.4 = [11 x i8] c"1000000000\00"
@.str.5 = [12 x i8] c"forked all\0A\00"
@.str.6 = [10 x i8] c"done all\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [5 x i8]
%8 = alloca [5 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %6
%11 = icmp sle i32 %10, 20
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %6
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @nice(i32 %19)
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds i8*, i8** %22, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
store i8* %26, i8** %25
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i64 0, i64 0
%28 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %27)
br label %29
29: ; preds = %15, %12
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %9
33: ; preds = %9
%34 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @sleep(i32 30)
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"ID%02d\00"
@.str.1 = [10 x i8] c"./simpson\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [5 x i8] c"6.28\00"
@.str.4 = [11 x i8] c"1000000000\00"
@str = [11 x i8] c"forked all\00"
@str.7 = [9 x i8] c"done all\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8]
%4 = alloca [5 x i8*]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = bitcast [5 x i8*]* %4 to i8*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 1
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 2
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 3
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 4
br label %17
12: ; preds = %25
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%14 = call i32 @sleep(i32 30)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2, %25
%18 = phi i32 [ 0, %2 ], [ %26, %25 ]
%19 = call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %18)
%23 = call i32 @nice(i32 %18)
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %10
store i8* %5, i8** %11
%24 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %7)
br label %25
25: ; preds = %17, %21
%26 = add nuw nsw i32 %18, 1
%27 = icmp eq i32 %26, 21
br i1 %27, label %12, label %17
}