#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 /*<<< orphan*/ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ wait();
void main(void) {
  printf("pid = %d\n", getpid());
  fork();
  wait();
  fork();
  wait();
  fork();
  wait();
  printf("pid = %d ppid = %d\n", getpid(), getppid());
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    $0x0,%al
call   1060 <wait@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    $0x0,%al
call   1060 <wait@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    $0x0,%al
call   1060 <wait@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x4(%rbp),%esi
mov    %eax,%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeab(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1060 <wait@plt>
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1060 <wait@plt>
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1060 <wait@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe57(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"pid = %d\0A\00"
@.str.1 = [20 x i8] c"pid = %d ppid = %d\0A\00"
define void @main() {
%1 = call i32 (...) @getpid()
%2 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = call i32 (...) @fork()
%4 = call i32 (...) @wait()
%5 = call i32 (...) @fork()
%6 = call i32 (...) @wait()
%7 = call i32 (...) @fork()
%8 = call i32 (...) @wait()
%9 = call i32 (...) @getpid()
%10 = call i32 (...) @getppid()
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"pid = %d\0A\00"
@.str.1 = [20 x i8] c"pid = %d ppid = %d\0A\00"
define void @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @fork()
%4 = tail call i32 (...) @wait()
%5 = tail call i32 (...) @fork()
%6 = tail call i32 (...) @wait()
%7 = tail call i32 (...) @fork()
%8 = tail call i32 (...) @wait()
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (...) @getppid()
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
ret void
}