#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*/ ChildProcess();
int /*<<< orphan*/ ParentProcess();
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int main() {
  pid_t pid;
  int i = 0;
  for (i = 0; i < 4; i++) {
    pid = fork();
    if (pid < 0) {
      printf("Error");
      exit(1);
    } else if (pid == 0) {
      ChildProcess();
    } else {
      ParentProcess();
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11d9 <main+0x89>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11a3 <main+0x53>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11ba <main+0x6a>
mov    $0x0,%al
call   1050 <ChildProcess@plt>
jmp    11c1 <main+0x71>
mov    $0x0,%al
call   1040 <ParentProcess@plt>
jmp    11c6 <main+0x76>
jmp    11cb <main+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11cd <main+0x7d>
je     1168 <main+0x18>
xor    %eax,%eax
call   1040 <ParentProcess@plt>
jmp    116f <main+0x1f>
xor    %eax,%eax
call   1050 <ChildProcess@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11cd <main+0x7d>
je     1186 <main+0x36>
xor    %eax,%eax
call   1040 <ParentProcess@plt>
jmp    118d <main+0x3d>
xor    %eax,%eax
call   1050 <ChildProcess@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11cd <main+0x7d>
je     11a4 <main+0x54>
xor    %eax,%eax
call   1040 <ParentProcess@plt>
jmp    11ab <main+0x5b>
xor    %eax,%eax
call   1050 <ChildProcess@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11cd <main+0x7d>
je     11c2 <main+0x72>
xor    %eax,%eax
call   1040 <ParentProcess@plt>
jmp    11c9 <main+0x79>
xor    %eax,%eax
call   1050 <ChildProcess@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"Error\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %30, %21, %12, %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (...) @ChildProcess()
br label %12
10: ; preds = %6
%11 = tail call i32 (...) @ParentProcess()
br label %12
12: ; preds = %10, %8
%13 = tail call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %3, label %15
15: ; preds = %12
%16 = icmp eq i64 %13, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 (...) @ParentProcess()
br label %21
19: ; preds = %15
%20 = tail call i32 (...) @ChildProcess()
br label %21
21: ; preds = %19, %17
%22 = tail call i64 (...) @fork()
%23 = icmp slt i64 %22, 0
br i1 %23, label %3, label %24
24: ; preds = %21
%25 = icmp eq i64 %22, 0
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = tail call i32 (...) @ParentProcess()
br label %30
28: ; preds = %24
%29 = tail call i32 (...) @ChildProcess()
br label %30
30: ; preds = %28, %26
%31 = tail call i64 (...) @fork()
%32 = icmp slt i64 %31, 0
br i1 %32, label %3, label %33
33: ; preds = %30
%34 = icmp eq i64 %31, 0
br i1 %34, label %37, label %35
35: ; preds = %33
%36 = tail call i32 (...) @ParentProcess()
br label %39
37: ; preds = %33
%38 = tail call i32 (...) @ChildProcess()
br label %39
39: ; preds = %37, %35
ret i32 0
}