#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int i, status;
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    printf("Process Creation Error. \n");
    exit(-1);
  } else if (pid > 0) {
    wait(NULL);
    printf("Parent Starts: \n");
    printf("Even Numbers: \n");
    for (i = 0; i <= 10; i++) {
      if (!(i % 2)) {
        printf("%d \n", i);
      }
    }
    printf("Parent Ends. \n");
    printf("\n");
  } else {
    printf("Child Starts: \n");
    printf("Odd Numbers: \n");
    for (i = 0; i <= 10; i++) {
      if (i % 2) {
        printf("%d \n", i);
      }
    }
    printf("Child Ends. \n");
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    117b <main+0x3b>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
jle    1214 <main+0xd4>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     11f3 <main+0xb3>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e0 <main+0xa0>
mov    -0x8(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e5 <main+0xa5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b1 <main+0x71>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1295 <main+0x155>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     1279 <main+0x139>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1266 <main+0x126>
mov    -0x8(%rbp),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126b <main+0x12b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1237 <main+0xf7>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129a <main+0x15a>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     1275 <main+0x115>
test   %eax,%eax
jle    11d3 <main+0x73>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5b(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe99(%rip),%r14
mov    $0xa,%r15d
mov    $0x8,%r12d
mov    $0x6,%r13d
mov    $0x4,%ebx
mov    $0x2,%esi
jmp    120e <main+0xae>
lea    0xe2b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe30(%rip),%r14
mov    $0x9,%r15d
mov    $0x7,%r12d
mov    $0x5,%r13d
mov    $0x3,%ebx
mov    $0x1,%esi
lea    0xdeb(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Process Creation Error. \0A\00"
@.str.1 = [17 x i8] c"Parent Starts: \0A\00"
@.str.2 = [16 x i8] c"Even Numbers: \0A\00"
@.str.3 = [5 x i8] c"%d \0A\00"
@.str.4 = [15 x i8] c"Parent Ends. \0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [16 x i8] c"Child Starts: \0A\00"
@.str.7 = [15 x i8] c"Odd Numbers: \0A\00"
@.str.8 = [14 x i8] c"Child Ends. \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = call i32 @wait(i32* null)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %18
18: ; preds = %29, %14
%19 = load i32, i32* %2
%20 = icmp sle i32 %19, 10
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i32, i32* %2
%23 = srem i32 %22, 2
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %21
br label %29
29: ; preds = %28
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %18
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %55
35: ; preds = %11
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %2
br label %38
38: ; preds = %49, %35
%39 = load i32, i32* %2
%40 = icmp sle i32 %39, 10
br i1 %40, label %41, label %52
41: ; preds = %38
%42 = load i32, i32* %2
%43 = srem i32 %42, 2
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %2
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %41
br label %49
49: ; preds = %48
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %38
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %52, %32
br label %56
56: ; preds = %55
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [5 x i8] c"%d \0A\00"
@str = [15 x i8] c"Child Starts: \00"
@str.9 = [14 x i8] c"Odd Numbers: \00"
@str.10 = [13 x i8] c"Child Ends. \00"
@str.11 = [16 x i8] c"Parent Starts: \00"
@str.12 = [15 x i8] c"Even Numbers: \00"
@str.13 = [14 x i8] c"Parent Ends. \00"
@str.14 = [25 x i8] c"Process Creation Error. \00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0))
%5 = tail call i32 @exit(i32 -1)
unreachable
6: ; preds = %0
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = tail call i32 @wait(i32* null)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %16
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
br label %16
16: ; preds = %8, %13
%17 = phi i32 [ 2, %8 ], [ 1, %13 ]
%18 = phi i32 [ 4, %8 ], [ 3, %13 ]
%19 = phi i32 [ 6, %8 ], [ 5, %13 ]
%20 = phi i32 [ 8, %8 ], [ 7, %13 ]
%21 = phi i32 [ 10, %8 ], [ 9, %13 ]
%22 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.13, i64 0, i64 0), %8 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0), %13 ]
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%28 = tail call i32 @puts(i8* dereferenceable(1) %22)
%29 = tail call i32 @putchar(i32 10)
ret i32 0
}