#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 EXIT_SUCCESS;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  pid_t pid = getpid();
  printf("Parent PID: %d.\n", pid);
  pid_t child_pid = fork();
  if (child_pid < 0) {
    printf("Fork error!\n");
    abort();
  } else if (child_pid == 0) {
    pid_t child_pid = getpid();
    printf(" → Child with PID of %d created!\n", child_pid);
    exit(0);
  } else {
    waitpid(child_pid, NULL, 2);
    printf(" ♦ Child with PID %ld exited.", (long)child_pid);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ba <main+0x5a>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11e6 <main+0x86>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x2,%edx
call   1060 <waitpid@plt>
movslq -0x18(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120e <main+0xae>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
js     11c0 <main+0x50>
je     11d3 <main+0x63>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x2,%edx
call   1070 <waitpid@plt>
mov    %ebx,%esi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe30(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Parent PID: %d.\0A\00"
@.str.1 = [13 x i8] c"Fork error!\0A\00"
@.str.2 = [36 x i8] c" \E2\86\92 Child with PID of %d created!\0A\00"
@.str.3 = [32 x i8] c" \E2\99\A6 Child with PID %ld exited.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getpid()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @fork()
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %2
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i32 (...) @getpid()
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %18
%27 = load i32, i32* %7
%28 = call i32 @waitpid(i32 %27, i32* null, i32 2)
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %26
br label %33
33: ; preds = %32
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}

LLVM IR (-O2):
@.str = [17 x i8] c"Parent PID: %d.\0A\00"
@.str.2 = [36 x i8] c" \E2\86\92 Child with PID of %d created!\0A\00"
@.str.3 = [32 x i8] c" \E2\99\A6 Child with PID %ld exited.\00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"Fork error!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @fork()
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %2
%11 = icmp eq i32 %5, 0
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %10
%17 = tail call i32 @waitpid(i32 %5, i32* null, i32 2)
%18 = zext i32 %5 to i64
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %18)
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}