#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 /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  int i, child, sum = 0;
  for (i = 0; i < 20; i++) {
    child = fork();
    if (child == 0) {
      sum += 1;
      printf("Child %d sum %d\n", i, sum);
      exit(0);
    }
  }
  for (i = 0; i < 20; i++) {
    wait(0);
  }
  printf("Parent sum %d\n", sum);
  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   $0x14,-0x8(%rbp)
jge    11b2 <main+0x72>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    119f <main+0x5f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11a4 <main+0x64>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115d <main+0x1d>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    11d8 <main+0x98>
xor    %edi,%edi
call   1050 <wait@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b9 <main+0x79>
mov    -0x10(%rbp),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1392 <main+0x252>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     130f <main+0x1cf>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1316 <main+0x1d6>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     131d <main+0x1dd>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1324 <main+0x1e4>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     132b <main+0x1eb>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1332 <main+0x1f2>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1339 <main+0x1f9>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1340 <main+0x200>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1347 <main+0x207>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     134e <main+0x20e>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1355 <main+0x215>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     135c <main+0x21c>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1363 <main+0x223>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     136a <main+0x22a>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1371 <main+0x231>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1378 <main+0x238>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     137f <main+0x23f>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1386 <main+0x246>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     138d <main+0x24d>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %edi,%edi
call   1050 <wait@plt>
lea    0xd0f(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%ebx
jmp    1392 <main+0x252>
mov    $0x2,%ebx
jmp    1392 <main+0x252>
mov    $0x3,%ebx
jmp    1392 <main+0x252>
mov    $0x4,%ebx
jmp    1392 <main+0x252>
mov    $0x5,%ebx
jmp    1392 <main+0x252>
mov    $0x6,%ebx
jmp    1392 <main+0x252>
mov    $0x7,%ebx
jmp    1392 <main+0x252>
mov    $0x8,%ebx
jmp    1392 <main+0x252>
mov    $0x9,%ebx
jmp    1392 <main+0x252>
mov    $0xa,%ebx
jmp    1392 <main+0x252>
mov    $0xb,%ebx
jmp    1392 <main+0x252>
mov    $0xc,%ebx
jmp    1392 <main+0x252>
mov    $0xd,%ebx
jmp    1392 <main+0x252>
mov    $0xe,%ebx
jmp    1392 <main+0x252>
mov    $0xf,%ebx
jmp    1392 <main+0x252>
mov    $0x10,%ebx
jmp    1392 <main+0x252>
mov    $0x11,%ebx
jmp    1392 <main+0x252>
mov    $0x12,%ebx
jmp    1392 <main+0x252>
mov    $0x13,%ebx
lea    0xc67(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Child %d sum %d\0A\00"
@.str.1 = [15 x i8] c"Parent 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 = %20, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 20
br i1 %7, label %8, label %23
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 %19
12: ; preds = %8
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = load i32, i32* %4
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %8
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %5
23: ; preds = %5
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
%33 = load i32, i32* %4
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Child %d sum %d\0A\00"
@.str.1 = [15 x i8] c"Parent sum %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %61, %58, %55, %52, %49, %46, %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %0
%4 = phi i32 [ 0, %0 ], [ 1, %7 ], [ 2, %10 ], [ 3, %13 ], [ 4, %16 ], [ 5, %19 ], [ 6, %22 ], [ 7, %25 ], [ 8, %28 ], [ 9, %31 ], [ 10, %34 ], [ 11, %37 ], [ 12, %40 ], [ 13, %43 ], [ 14, %46 ], [ 15, %49 ], [ 16, %52 ], [ 17, %55 ], [ 18, %58 ], [ 19, %61 ]
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4, i32 1)
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %3, label %10
10: ; preds = %7
%11 = tail call i32 (...) @fork()
%12 = icmp eq i32 %11, 0
br i1 %12, label %3, label %13
13: ; preds = %10
%14 = tail call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %13
%17 = tail call i32 (...) @fork()
%18 = icmp eq i32 %17, 0
br i1 %18, label %3, label %19
19: ; preds = %16
%20 = tail call i32 (...) @fork()
%21 = icmp eq i32 %20, 0
br i1 %21, label %3, label %22
22: ; preds = %19
%23 = tail call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %3, label %25
25: ; preds = %22
%26 = tail call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %3, label %28
28: ; preds = %25
%29 = tail call i32 (...) @fork()
%30 = icmp eq i32 %29, 0
br i1 %30, label %3, label %31
31: ; preds = %28
%32 = tail call i32 (...) @fork()
%33 = icmp eq i32 %32, 0
br i1 %33, label %3, label %34
34: ; preds = %31
%35 = tail call i32 (...) @fork()
%36 = icmp eq i32 %35, 0
br i1 %36, label %3, label %37
37: ; preds = %34
%38 = tail call i32 (...) @fork()
%39 = icmp eq i32 %38, 0
br i1 %39, label %3, label %40
40: ; preds = %37
%41 = tail call i32 (...) @fork()
%42 = icmp eq i32 %41, 0
br i1 %42, label %3, label %43
43: ; preds = %40
%44 = tail call i32 (...) @fork()
%45 = icmp eq i32 %44, 0
br i1 %45, label %3, label %46
46: ; preds = %43
%47 = tail call i32 (...) @fork()
%48 = icmp eq i32 %47, 0
br i1 %48, label %3, label %49
49: ; preds = %46
%50 = tail call i32 (...) @fork()
%51 = icmp eq i32 %50, 0
br i1 %51, label %3, label %52
52: ; preds = %49
%53 = tail call i32 (...) @fork()
%54 = icmp eq i32 %53, 0
br i1 %54, label %3, label %55
55: ; preds = %52
%56 = tail call i32 (...) @fork()
%57 = icmp eq i32 %56, 0
br i1 %57, label %3, label %58
58: ; preds = %55
%59 = tail call i32 (...) @fork()
%60 = icmp eq i32 %59, 0
br i1 %60, label %3, label %61
61: ; preds = %58
%62 = tail call i32 (...) @fork()
%63 = icmp eq i32 %62, 0
br i1 %63, label %3, label %64
64: ; preds = %61
%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)
%81 = tail call i32 @wait(i32 0)
%82 = tail call i32 @wait(i32 0)
%83 = tail call i32 @wait(i32 0)
%84 = tail call i32 @wait(i32 0)
%85 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 0)
ret i32 0
}