#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 getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ wait(int *);
int main() {
  int pidf = 0, i, status;
  for (i = 0; i < 10; i++) {
    if (pidf == 0) {
      printf("%d - PID: %d  PPID: %d\n", i, getpid(), getppid());
      pidf = fork();
    } else
      wait(&status);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11d7 <main+0x87>
cmpl   $0x0,-0x8(%rbp)
jne    11bb <main+0x6b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
jmp    11c4 <main+0x74>
lea    -0x10(%rbp),%rdi
call   1060 <wait@plt>
jmp    11c9 <main+0x79>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116d <main+0x1d>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%r14
lea    0x4(%rsp),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1180 <main+0x30>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1060 <wait@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
je     11ad <main+0x5d>
test   %ebx,%ebx
jne    1170 <main+0x20>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebx
jmp    1178 <main+0x28>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%d - PID: %d PPID: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %20, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %23
8: ; preds = %5
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 (...) @getpid()
%14 = call i32 (...) @getppid()
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13, i32 %14)
%16 = call i32 (...) @fork()
store i32 %16, i32* %2
br label %19
17: ; preds = %8
%18 = call i32 @wait(i32* %4)
br label %19
19: ; preds = %17, %11
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %5
23: ; preds = %5
ret i32 1
}

LLVM IR (-O2):
@.str = [24 x i8] c"%d - PID: %d PPID: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %0, %14
%4 = phi i32 [ 0, %0 ], [ %16, %14 ]
%5 = phi i32 [ 0, %0 ], [ %15, %14 ]
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = call i32 (...) @getpid()
%9 = call i32 (...) @getppid()
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %8, i32 %9)
%11 = call i32 (...) @fork()
br label %14
12: ; preds = %3
%13 = call i32 @wait(i32* %1)
br label %14
14: ; preds = %7, %12
%15 = phi i32 [ %11, %7 ], [ %5, %12 ]
%16 = add nuw nsw i32 %4, 1
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %3
18: ; preds = %14
ret i32 1
}