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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid = fork();
  if (pid == 0) {
    printf("child process\n");
    sleep(5);
    exit(0);
  } else if (pid > 0) {
    wait(NULL);
    printf("parent process\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118b <main+0x3b>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jle    11b2 <main+0x62>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11b7 <main+0x67>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1163 <main+0x13>
jg     1180 <main+0x30>
xor    %eax,%eax
pop    %rcx
ret
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1040 <exit@plt>
xor    %edi,%edi
call   1060 <wait@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"child process\0A\00"
@.str.1 = [16 x i8] c"parent process\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @sleep(i32 5)
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = load i64, i64* %1
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i32 @wait(i32* null)
%14 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %9
br label %17
17: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@str = [15 x i8] c"parent process\00"
@str.2 = [14 x i8] c"child process\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.2, i64 0, i64 0))
%5 = tail call i32 @sleep(i32 5)
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0
%8 = icmp sgt i64 %1, 0
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = tail call i32 @wait(i32* null)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %7
ret i32 0
}