#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*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  int i, child, sum = 0;
  for (i = 0; i < 5; i++) {
    child = fork();
    if (child == 0) {
      sum += getpid();
      printf("Child %d sum %d\n", getpid(), sum);
      exit(0);
    }
    sum = i;
    printf("Parent created %d sum %d\n", child, sum);
  }
  for (i = 0; i < 5; i++) {
    wait(0);
  }
  sleep(10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11ed <main+0x8d>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11c7 <main+0x67>
mov    $0x0,%al
call   1030 <getpid@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%edx
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117d <main+0x1d>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1213 <main+0xb3>
xor    %edi,%edi
call   1070 <wait@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f4 <main+0x94>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1244 <main+0xe4>
lea    0xe98(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %edx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1244 <main+0xe4>
lea    0xe77(%rip),%rdi
mov    $0x1,%ebx
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1244 <main+0xe4>
lea    0xe50(%rip),%rdi
mov    $0x2,%ebx
mov    %eax,%esi
mov    $0x2,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1244 <main+0xe4>
lea    0xe2d(%rip),%rdi
mov    $0x3,%ebx
mov    %eax,%esi
mov    $0x3,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1244 <main+0xe4>
lea    0xe0a(%rip),%rdi
mov    %eax,%esi
mov    $0x4,%edx
call   1040 <printf@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>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1030 <getpid@plt>
add    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xda5(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [17 x i8] c"Child %d sum %d\0A\00"
@.str.1 = [26 x i8] c"Parent created %d sum %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %10
3: ; preds = %22, %18, %14, %10, %0
%4 = phi i32 [ 0, %0 ], [ 0, %10 ], [ 1, %14 ], [ 2, %18 ], [ 3, %22 ]
%5 = tail call i32 (...) @getpid()
%6 = add nsw i32 %5, %4
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %6)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 0)
%12 = tail call i32 (...) @fork()
%13 = icmp eq i32 %12, 0
br i1 %13, label %3, label %14
14: ; preds = %10
%15 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 1)
%16 = tail call i32 (...) @fork()
%17 = icmp eq i32 %16, 0
br i1 %17, label %3, label %18
18: ; preds = %14
%19 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 2)
%20 = tail call i32 (...) @fork()
%21 = icmp eq i32 %20, 0
br i1 %21, label %3, label %22
22: ; preds = %18
%23 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 3)
%24 = tail call i32 (...) @fork()
%25 = icmp eq i32 %24, 0
br i1 %25, label %3, label %26
26: ; preds = %22
%27 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 4)
%28 = tail call i32 @wait(i32 0)
%29 = tail call i32 @wait(i32 0)
%30 = tail call i32 @wait(i32 0)
%31 = tail call i32 @wait(i32 0)
%32 = tail call i32 @wait(i32 0)
%33 = tail call i32 @sleep(i32 10)
ret i32 0
}