#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 fork();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(void) {
  int is_parent = fork();
  if (is_parent) {
    puts("\nI'm the parent and I'll wait for my child.");
    wait(0);
    puts("\nI'm the parent and I'm finished waiting.");
  } else {
    sleep(1);
    puts("\nI'm the  child and I'll derp for my herp.");
    sleep(1);
    puts("\nI'm the  child and I'm finished derping.");
  }
  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,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1187 <main+0x47>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <wait@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
jmp    11b3 <main+0x73>
mov    $0x1,%edi
call   1040 <sleep@plt>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1168 <main+0x28>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <wait@plt>
lea    0xec6(%rip),%rdi
jmp    118f <main+0x4f>
mov    $0x1,%edi
call   1040 <sleep@plt>
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [44 x i8] c"\0AI'm the parent and I'll wait for my child.\00"
@.str.1 = [42 x i8] c"\0AI'm the parent and I'm finished waiting.\00"
@.str.2 = [43 x i8] c"\0AI'm the child and I'll derp for my herp.\00"
@.str.3 = [42 x i8] c"\0AI'm the child and I'm finished derping.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @wait(i32 0)
%9 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = call i32 @sleep(i32 1)
%12 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @sleep(i32 1)
%14 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %10, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"\0AI'm the parent and I'll wait for my child.\00"
@.str.1 = [42 x i8] c"\0AI'm the parent and I'm finished waiting.\00"
@.str.2 = [43 x i8] c"\0AI'm the child and I'll derp for my herp.\00"
@.str.3 = [42 x i8] c"\0AI'm the child and I'm finished derping.\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @wait(i32 0)
br label %10
6: ; preds = %0
%7 = tail call i32 @sleep(i32 1)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @sleep(i32 1)
br label %10
10: ; preds = %6, %3
%11 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), %6 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), %3 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
ret i32 0
}