#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 */
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int);
void main() {
  int i;
  if (fork()) {
    for (i = 0; i < 100000; i++)
      printf("**     PARENT %d\n", i);
  } else {
    for (i = 0; i < 100000; i++)
      printf("  **   CHILD  %d\n", i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <fork@plt>
cmp    $0x0,%rax
je     116f <main+0x4f>
movl   $0x0,-0x4(%rbp)
cmpl   $0x186a0,-0x4(%rbp)
jge    116a <main+0x4a>
mov    -0x4(%rbp),%esi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1140 <main+0x20>
jmp    11a5 <main+0x85>
movl   $0x0,-0x4(%rbp)
cmpl   $0x186a0,-0x4(%rbp)
jge    11a0 <main+0x80>
mov    -0x4(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <main+0x56>
jmp    11a5 <main+0x85>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
je     1157 <main+0x37>
lea    0xec7(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x186a0,%ebx
jne    1140 <main+0x20>
jmp    1175 <main+0x55>
xor    %ebx,%ebx
lea    0xeb2(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x186a0,%ebx
jne    1160 <main+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"** PARENT %d\0A\00"
@.str.1 = [18 x i8] c" ** CHILD %d\0A\00"
define void @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %8, label %3
3: ; preds = %0, %3
%4 = phi i32 [ %6, %3 ], [ 0, %0 ]
%5 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = add nuw nsw i32 %4, 1
%7 = icmp eq i32 %6, 100000
br i1 %7, label %13, label %3
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ 0, %0 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, 100000
br i1 %12, label %13, label %8
13: ; preds = %3, %8
ret void
}