#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  pid_t pid1, pid2, pid3, pid4, pid5;
  int status;
  pid1 = fork();
  if (pid1 < 0) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (pid1 > 0) {
    int myExitStatus;
    waitpid(pid1, &status, 0);
    if (WIFEXITED(status)) {
      printf("The 1st child %d exits with exit status: %d\n", pid1,
             WEXITSTATUS(status));
    } else
      printf("The 1st child did not terminate with exit\n");
    myExitStatus = WEXITSTATUS(status);
    sleep(1);
    printf("All child processes have terminated. Main parent process is "
           "terminating now\n");
    exit(myExitStatus);
  }
  pid2 = fork();
  if (pid2 < 0) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (pid2 > 0) {
    int myExitStatus;
    waitpid(pid2, &status, 0);
    if (WIFEXITED(status)) {
      printf("The 2nd child %d exits with exit status: %d\n", pid2,
             WEXITSTATUS(status));
    } else
      printf("The 2nd child did not terminate with exit\n");
    myExitStatus = WEXITSTATUS(status) + 1;
    sleep(1);
    exit(myExitStatus);
  }
  pid3 = fork();
  if (pid3 < 0) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (pid3 > 0) {
    int myExitStatus;
    waitpid(pid3, &status, 0);
    if (WIFEXITED(status)) {
      printf("The 3rd child %d exits with exit status: %d\n", pid3,
             WEXITSTATUS(status));
    } else
      printf("The 3rd child did not terminate with exit\n");
    myExitStatus = WEXITSTATUS(status) + 1;
    sleep(1);
    exit(myExitStatus);
  }
  pid4 = fork();
  if (pid4 < 0) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (pid4 > 0) {
    int myExitStatus;
    waitpid(pid4, &status, 0);
    if (WIFEXITED(status)) {
      printf("The 4th child %d exits with exit status: %d\n", pid4,
             WEXITSTATUS(status));
    } else
      printf("The 4th child did not terminate with exit\n");
    myExitStatus = WEXITSTATUS(status) + 1;
    sleep(1);
    exit(myExitStatus);
  }
  pid5 = fork();
  if (pid5 < 0) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (pid5 > 0) {
    int myExitStatus;
    waitpid(pid5, &status, 0);
    if (WIFEXITED(status)) {
      printf("The 5th child %d exits with exit status: %d\n", pid5,
             WEXITSTATUS(status));
    } else
      printf("The 5th child did not terminate with exit\n");
    myExitStatus = WEXITSTATUS(status) + 1;
    sleep(1);
    exit(myExitStatus);
  }
  sleep(1);
  exit(0);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11bf <main+0x3f>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    124d <main+0xcd>
mov    -0x10(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x34(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1214 <main+0x94>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1222 <main+0xa2>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x38(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    127d <main+0xfd>
lea    0xd96(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jle    1300 <main+0x180>
mov    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x34(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12d2 <main+0x152>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e0 <main+0x160>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x3c(%rbp),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1330 <main+0x1b0>
lea    0xce3(%rip),%rdi
call   1060 <perror@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    13b3 <main+0x233>
mov    -0x20(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x34(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1385 <main+0x205>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1393 <main+0x213>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x40(%rbp),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    13e3 <main+0x263>
lea    0xc30(%rip),%rdi
call   1060 <perror@plt>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jle    1466 <main+0x2e6>
mov    -0x28(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x34(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1438 <main+0x2b8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1446 <main+0x2c6>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x44(%rbp),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1496 <main+0x316>
lea    0xb7d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2b51(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jle    1519 <main+0x399>
mov    -0x30(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x34(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     14eb <main+0x36b>
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    14f9 <main+0x379>
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x48(%rbp),%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jns    11bb <main+0x2b>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jne    1216 <main+0x86>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     11a1 <main+0x11>
jne    1288 <main+0xf8>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     11a1 <main+0x11>
jne    12ef <main+0x15f>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     11a1 <main+0x11>
jne    132a <main+0x19a>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     11a1 <main+0x11>
jne    136b <main+0x1db>
mov    $0x1,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    1244 <main+0xb4>
lea    0xf51(%rip),%rdi
call   1030 <puts@plt>
jmp    1260 <main+0xd0>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xdb1(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xf3c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    12b6 <main+0x126>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
jmp    12d2 <main+0x142>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd6c(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0x1(%rax),%ebx
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    1318 <main+0x188>
lea    0xe24(%rip),%rdi
jmp    12af <main+0x11f>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd37(%rip),%rdi
jmp    12c6 <main+0x136>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    1356 <main+0x1c6>
lea    0xdbf(%rip),%rdi
jmp    12af <main+0x11f>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd26(%rip),%rdi
jmp    12c6 <main+0x136>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    1397 <main+0x207>
lea    0xd54(%rip),%rdi
jmp    12af <main+0x11f>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xd12(%rip),%rdi
jmp    12c6 <main+0x136>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [45 x i8] c"The 1st child %d exits with exit status: %d\0A\00"
@.str.2 = [43 x i8] c"The 1st child did not terminate with exit\0A\00"
@.str.3 = [77 x i8] c"All child processes have terminated. Main parent process is terminating now\0A\00"
@.str.4 = [45 x i8] c"The 2nd child %d exits with exit status: %d\0A\00"
@.str.5 = [43 x i8] c"The 2nd child did not terminate with exit\0A\00"
@.str.6 = [45 x i8] c"The 3rd child %d exits with exit status: %d\0A\00"
@.str.7 = [43 x i8] c"The 3rd child did not terminate with exit\0A\00"
@.str.8 = [45 x i8] c"The 4th child %d exits with exit status: %d\0A\00"
@.str.9 = [43 x i8] c"The 4th child did not terminate with exit\0A\00"
@.str.10 = [45 x i8] c"The 5th child %d exits with exit status: %d\0A\00"
@.str.11 = [43 x i8] c"The 5th child did not terminate with exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i64 (...) @fork()
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %0
%21 = load i64, i64* %2
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %20
%24 = load i64, i64* %2
%25 = call i32 @waitpid(i64 %24, i32* %7, i32 0)
%26 = load i32, i32* %7
%27 = call i64 @WIFEXITED(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i64, i64* %2
%31 = load i32, i32* %7
%32 = call i32 @WEXITSTATUS(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i64 %30, i32 %32)
br label %36
34: ; preds = %23
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = load i32, i32* %7
%38 = call i32 @WEXITSTATUS(i32 %37)
store i32 %38, i32* %8
%39 = call i32 @sleep(i32 1)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* %8
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %20
%44 = call i64 (...) @fork()
store i64 %44, i64* %3
%45 = load i64, i64* %3
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %43
%52 = load i64, i64* %3
%53 = icmp sgt i64 %52, 0
br i1 %53, label %54, label %74
54: ; preds = %51
%55 = load i64, i64* %3
%56 = call i32 @waitpid(i64 %55, i32* %7, i32 0)
%57 = load i32, i32* %7
%58 = call i64 @WIFEXITED(i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %54
%61 = load i64, i64* %3
%62 = load i32, i32* %7
%63 = call i32 @WEXITSTATUS(i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i64 %61, i32 %63)
br label %67
65: ; preds = %54
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %65, %60
%68 = load i32, i32* %7
%69 = call i32 @WEXITSTATUS(i32 %68)
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
%71 = call i32 @sleep(i32 1)
%72 = load i32, i32* %9
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %51
%75 = call i64 (...) @fork()
store i64 %75, i64* %4
%76 = load i64, i64* %4
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %74
%83 = load i64, i64* %4
%84 = icmp sgt i64 %83, 0
br i1 %84, label %85, label %105
85: ; preds = %82
%86 = load i64, i64* %4
%87 = call i32 @waitpid(i64 %86, i32* %7, i32 0)
%88 = load i32, i32* %7
%89 = call i64 @WIFEXITED(i32 %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %85
%92 = load i64, i64* %4
%93 = load i32, i32* %7
%94 = call i32 @WEXITSTATUS(i32 %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i64 %92, i32 %94)
br label %98
96: ; preds = %85
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
br label %98
98: ; preds = %96, %91
%99 = load i32, i32* %7
%100 = call i32 @WEXITSTATUS(i32 %99)
%101 = add nsw i32 %100, 1
store i32 %101, i32* %10
%102 = call i32 @sleep(i32 1)
%103 = load i32, i32* %10
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %82
%106 = call i64 (...) @fork()
store i64 %106, i64* %5
%107 = load i64, i64* %5
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %105
%110 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%111 = load i32, i32* @EXIT_FAILURE
%112 = call i32 @exit(i32 %111)
unreachable
113: ; preds = %105
%114 = load i64, i64* %5
%115 = icmp sgt i64 %114, 0
br i1 %115, label %116, label %136
116: ; preds = %113
%117 = load i64, i64* %5
%118 = call i32 @waitpid(i64 %117, i32* %7, i32 0)
%119 = load i32, i32* %7
%120 = call i64 @WIFEXITED(i32 %119)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %127
122: ; preds = %116
%123 = load i64, i64* %5
%124 = load i32, i32* %7
%125 = call i32 @WEXITSTATUS(i32 %124)
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i64 %123, i32 %125)
br label %129
127: ; preds = %116
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
br label %129
129: ; preds = %127, %122
%130 = load i32, i32* %7
%131 = call i32 @WEXITSTATUS(i32 %130)
%132 = add nsw i32 %131, 1
store i32 %132, i32* %11
%133 = call i32 @sleep(i32 1)
%134 = load i32, i32* %11
%135 = call i32 @exit(i32 %134)
unreachable
136: ; preds = %113
%137 = call i64 (...) @fork()
store i64 %137, i64* %6
%138 = load i64, i64* %6
%139 = icmp slt i64 %138, 0
br i1 %139, label %140, label %144
140: ; preds = %136
%141 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%142 = load i32, i32* @EXIT_FAILURE
%143 = call i32 @exit(i32 %142)
unreachable
144: ; preds = %136
%145 = load i64, i64* %6
%146 = icmp sgt i64 %145, 0
br i1 %146, label %147, label %167
147: ; preds = %144
%148 = load i64, i64* %6
%149 = call i32 @waitpid(i64 %148, i32* %7, i32 0)
%150 = load i32, i32* %7
%151 = call i64 @WIFEXITED(i32 %150)
%152 = icmp ne i64 %151, 0
br i1 %152, label %153, label %158
153: ; preds = %147
%154 = load i64, i64* %6
%155 = load i32, i32* %7
%156 = call i32 @WEXITSTATUS(i32 %155)
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.10, i64 0, i64 0), i64 %154, i32 %156)
br label %160
158: ; preds = %147
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0))
br label %160
160: ; preds = %158, %153
%161 = load i32, i32* %7
%162 = call i32 @WEXITSTATUS(i32 %161)
%163 = add nsw i32 %162, 1
store i32 %163, i32* %12
%164 = call i32 @sleep(i32 1)
%165 = load i32, i32* %12
%166 = call i32 @exit(i32 %165)
unreachable
167: ; preds = %144
%168 = call i32 @sleep(i32 1)
%169 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [45 x i8] c"The 1st child %d exits with exit status: %d\0A\00"
@.str.4 = [45 x i8] c"The 2nd child %d exits with exit status: %d\0A\00"
@.str.6 = [45 x i8] c"The 3rd child %d exits with exit status: %d\0A\00"
@.str.8 = [45 x i8] c"The 4th child %d exits with exit status: %d\0A\00"
@.str.10 = [45 x i8] c"The 5th child %d exits with exit status: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [42 x i8] c"The 5th child did not terminate with exit\00"
@str.12 = [42 x i8] c"The 4th child did not terminate with exit\00"
@str.13 = [42 x i8] c"The 3rd child did not terminate with exit\00"
@str.14 = [42 x i8] c"The 2nd child did not terminate with exit\00"
@str.15 = [42 x i8] c"The 1st child did not terminate with exit\00"
@str.16 = [76 x i8] c"All child processes have terminated. Main parent process is terminating now\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = icmp eq i64 %3, 0
br i1 %10, label %28, label %11
11: ; preds = %9
%12 = call i32 @waitpid(i64 %3, i32* %1, i32 0)
%13 = load i32, i32* %1
%14 = call i64 @WIFEXITED(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i32, i32* %1
%18 = call i32 @WEXITSTATUS(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i64 %3, i32 %18)
br label %22
20: ; preds = %11
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.15, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* %1
%24 = call i32 @WEXITSTATUS(i32 %23)
%25 = call i32 @sleep(i32 1)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str.16, i64 0, i64 0))
%27 = call i32 @exit(i32 %24)
unreachable
28: ; preds = %9
%29 = tail call i64 (...) @fork()
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %28
%36 = icmp eq i64 %29, 0
br i1 %36, label %54, label %37
37: ; preds = %35
%38 = call i32 @waitpid(i64 %29, i32* %1, i32 0)
%39 = load i32, i32* %1
%40 = call i64 @WIFEXITED(i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %37
%43 = load i32, i32* %1
%44 = call i32 @WEXITSTATUS(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i64 %29, i32 %44)
br label %48
46: ; preds = %37
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.14, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* %1
%50 = call i32 @WEXITSTATUS(i32 %49)
%51 = add nsw i32 %50, 1
%52 = call i32 @sleep(i32 1)
%53 = call i32 @exit(i32 %51)
unreachable
54: ; preds = %35
%55 = tail call i64 (...) @fork()
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = tail call i32 @exit(i32 %59)
unreachable
61: ; preds = %54
%62 = icmp eq i64 %55, 0
br i1 %62, label %80, label %63
63: ; preds = %61
%64 = call i32 @waitpid(i64 %55, i32* %1, i32 0)
%65 = load i32, i32* %1
%66 = call i64 @WIFEXITED(i32 %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %63
%69 = load i32, i32* %1
%70 = call i32 @WEXITSTATUS(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i64 %55, i32 %70)
br label %74
72: ; preds = %63
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.13, i64 0, i64 0))
br label %74
74: ; preds = %72, %68
%75 = load i32, i32* %1
%76 = call i32 @WEXITSTATUS(i32 %75)
%77 = add nsw i32 %76, 1
%78 = call i32 @sleep(i32 1)
%79 = call i32 @exit(i32 %77)
unreachable
80: ; preds = %61
%81 = tail call i64 (...) @fork()
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%85 = load i32, i32* @EXIT_FAILURE
%86 = tail call i32 @exit(i32 %85)
unreachable
87: ; preds = %80
%88 = icmp eq i64 %81, 0
br i1 %88, label %106, label %89
89: ; preds = %87
%90 = call i32 @waitpid(i64 %81, i32* %1, i32 0)
%91 = load i32, i32* %1
%92 = call i64 @WIFEXITED(i32 %91)
%93 = icmp eq i64 %92, 0
br i1 %93, label %98, label %94
94: ; preds = %89
%95 = load i32, i32* %1
%96 = call i32 @WEXITSTATUS(i32 %95)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i64 %81, i32 %96)
br label %100
98: ; preds = %89
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.12, i64 0, i64 0))
br label %100
100: ; preds = %98, %94
%101 = load i32, i32* %1
%102 = call i32 @WEXITSTATUS(i32 %101)
%103 = add nsw i32 %102, 1
%104 = call i32 @sleep(i32 1)
%105 = call i32 @exit(i32 %103)
unreachable
106: ; preds = %87
%107 = tail call i64 (...) @fork()
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %106
%110 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%111 = load i32, i32* @EXIT_FAILURE
%112 = tail call i32 @exit(i32 %111)
unreachable
113: ; preds = %106
%114 = icmp eq i64 %107, 0
br i1 %114, label %132, label %115
115: ; preds = %113
%116 = call i32 @waitpid(i64 %107, i32* %1, i32 0)
%117 = load i32, i32* %1
%118 = call i64 @WIFEXITED(i32 %117)
%119 = icmp eq i64 %118, 0
br i1 %119, label %124, label %120
120: ; preds = %115
%121 = load i32, i32* %1
%122 = call i32 @WEXITSTATUS(i32 %121)
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.10, i64 0, i64 0), i64 %107, i32 %122)
br label %126
124: ; preds = %115
%125 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %126
126: ; preds = %124, %120
%127 = load i32, i32* %1
%128 = call i32 @WEXITSTATUS(i32 %127)
%129 = add nsw i32 %128, 1
%130 = call i32 @sleep(i32 1)
%131 = call i32 @exit(i32 %129)
unreachable
132: ; preds = %113
%133 = tail call i32 @sleep(i32 1)
%134 = tail call i32 @exit(i32 0)
unreachable
}