#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 fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t forkStatus;
  forkStatus = fork();
  if (forkStatus == 0) {
    printf("Child is running, processing.\n");
    sleep(5);
    printf("Child is done, exiting.\n");
  } else if (forkStatus != -1) {
    printf("Parent is waiting...\n");
    wait(NULL);
    printf("Parent is exiting...\n");
  } else {
    perror("Error while calling the fork function");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    119a <main+0x4a>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    11db <main+0x8b>
cmpl   $0xffffffff,-0x8(%rbp)
je     11ca <main+0x7a>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    11d6 <main+0x86>
lea    0xe93(%rip),%rdi
call   1040 <perror@plt>
jmp    11db <main+0x8b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     117d <main+0x2d>
cmp    $0xffffffff,%eax
je     11a3 <main+0x53>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <wait@plt>
lea    0xec0(%rip),%rdi
jmp    119a <main+0x4a>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe56(%rip),%rdi
call   1040 <perror@plt>
jmp    119f <main+0x4f>

LLVM IR (-O0):
@.str = [31 x i8] c"Child is running, processing.\0A\00"
@.str.1 = [25 x i8] c"Child is done, exiting.\0A\00"
@.str.2 = [22 x i8] c"Parent is waiting...\0A\00"
@.str.3 = [22 x i8] c"Parent is exiting...\0A\00"
@.str.4 = [38 x i8] c"Error while calling the fork function\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 eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @sleep(i32 5)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %20
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @wait(i32* null)
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %19
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
br label %20
20: ; preds = %19, %6
ret i32 0
}

LLVM IR (-O2):
@.str.4 = [38 x i8] c"Error while calling the fork function\00"
@str = [21 x i8] c"Parent is waiting...\00"
@str.5 = [21 x i8] c"Parent is exiting...\00"
@str.6 = [30 x i8] c"Child is running, processing.\00"
@str.7 = [24 x i8] c"Child is done, exiting.\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %6 [
i32 0, label %2
i32 -1, label %10
]
2: ; preds = %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%4 = tail call i32 @sleep(i32 5)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0))
br label %12
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @wait(i32* null)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
br label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %6, %10, %2
ret i32 0
}