#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 execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  int i, child;
  for (i = 0; i < 20; i++) {
    child = fork();
    if (child == 0) {
      printf("\n###########################################\n");
      if (execl("/bin/ps", "/bin/ps", "-f", NULL) == -1) {
        perror("Failed to do exec");
      }
      exit(0);
    }
  }
  for (i = 0; i < 20; i++) {
    wait(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    11e9 <main+0x89>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11d6 <main+0x76>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
lea    0xe87(%rip),%rsi
lea    0xe88(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1060 <execl@plt>
cmp    $0xffffffff,%eax
jne    11cf <main+0x6f>
lea    0xe6f(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11db <main+0x7b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <main+0x16>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    120f <main+0xaf>
xor    %edi,%edi
call   1070 <wait@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f0 <main+0x90>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     131d <main+0x1bd>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xcf9(%rip),%rdi
call   1030 <puts@plt>
lea    0xcd0(%rip),%rdi
lea    0xcd1(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execl@plt>
cmp    $0xffffffff,%eax
jne    1352 <main+0x1f2>
lea    0xcbe(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"\0A###########################################\0A\00"
@.str.1 = [8 x i8] c"/bin/ps\00"
@.str.2 = [3 x i8] c"-f\00"
@.str.3 = [18 x i8] c"Failed to do exec\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %20, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 20
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = call i32 (...) @fork()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %7
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %4
23: ; preds = %4
store i32 0, i32* %2
br label %24
24: ; preds = %29, %23
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 20
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = call i32 @wait(i32 0)
br label %29
29: ; preds = %27
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %24
32: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"/bin/ps\00"
@.str.2 = [3 x i8] c"-f\00"
@.str.3 = [18 x i8] c"Failed to do exec\00"
@str = [45 x i8] c"\0A###########################################\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %81, label %3
3: ; preds = %0
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %81, label %6
6: ; preds = %3
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %81, label %9
9: ; preds = %6
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %81, label %12
12: ; preds = %9
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %81, label %15
15: ; preds = %12
%16 = tail call i32 (...) @fork()
%17 = icmp eq i32 %16, 0
br i1 %17, label %81, label %18
18: ; preds = %15
%19 = tail call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %81, label %21
21: ; preds = %18
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %81, label %24
24: ; preds = %21
%25 = tail call i32 (...) @fork()
%26 = icmp eq i32 %25, 0
br i1 %26, label %81, label %27
27: ; preds = %24
%28 = tail call i32 (...) @fork()
%29 = icmp eq i32 %28, 0
br i1 %29, label %81, label %30
30: ; preds = %27
%31 = tail call i32 (...) @fork()
%32 = icmp eq i32 %31, 0
br i1 %32, label %81, label %33
33: ; preds = %30
%34 = tail call i32 (...) @fork()
%35 = icmp eq i32 %34, 0
br i1 %35, label %81, label %36
36: ; preds = %33
%37 = tail call i32 (...) @fork()
%38 = icmp eq i32 %37, 0
br i1 %38, label %81, label %39
39: ; preds = %36
%40 = tail call i32 (...) @fork()
%41 = icmp eq i32 %40, 0
br i1 %41, label %81, label %42
42: ; preds = %39
%43 = tail call i32 (...) @fork()
%44 = icmp eq i32 %43, 0
br i1 %44, label %81, label %45
45: ; preds = %42
%46 = tail call i32 (...) @fork()
%47 = icmp eq i32 %46, 0
br i1 %47, label %81, label %48
48: ; preds = %45
%49 = tail call i32 (...) @fork()
%50 = icmp eq i32 %49, 0
br i1 %50, label %81, label %51
51: ; preds = %48
%52 = tail call i32 (...) @fork()
%53 = icmp eq i32 %52, 0
br i1 %53, label %81, label %54
54: ; preds = %51
%55 = tail call i32 (...) @fork()
%56 = icmp eq i32 %55, 0
br i1 %56, label %81, label %57
57: ; preds = %54
%58 = tail call i32 (...) @fork()
%59 = icmp eq i32 %58, 0
br i1 %59, label %81, label %60
60: ; preds = %57
%61 = tail call i32 @wait(i32 0)
%62 = tail call i32 @wait(i32 0)
%63 = tail call i32 @wait(i32 0)
%64 = tail call i32 @wait(i32 0)
%65 = tail call i32 @wait(i32 0)
%66 = tail call i32 @wait(i32 0)
%67 = tail call i32 @wait(i32 0)
%68 = tail call i32 @wait(i32 0)
%69 = tail call i32 @wait(i32 0)
%70 = tail call i32 @wait(i32 0)
%71 = tail call i32 @wait(i32 0)
%72 = tail call i32 @wait(i32 0)
%73 = tail call i32 @wait(i32 0)
%74 = tail call i32 @wait(i32 0)
%75 = tail call i32 @wait(i32 0)
%76 = tail call i32 @wait(i32 0)
%77 = tail call i32 @wait(i32 0)
%78 = tail call i32 @wait(i32 0)
%79 = tail call i32 @wait(i32 0)
%80 = tail call i32 @wait(i32 0)
ret i32 0
81: ; preds = %57, %54, %51, %48, %45, %42, %39, %36, %33, %30, %27, %24, %21, %18, %15, %12, %9, %6, %3, %0
%82 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%83 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %87
87: ; preds = %85, %81
%88 = tail call i32 @exit(i32 0)
unreachable
}