#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, long);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i;
  for (i = 0; i < 5; i++) {
    pid_t proc_id = fork();
    if (proc_id == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (proc_id == 0) {
      printf("%ld -> %ld;\n", (long)getppid(), (long)getpid());
      exit(EXIT_SUCCESS);
    }
    wait(NULL);
  }
}


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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1219 <main+0xa9>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c5 <main+0x55>
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1202 <main+0x92>
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1206 <main+0x96>
cmp    $0xffffffff,%eax
je     11ec <main+0x7c>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11ec <main+0x7c>
test   %eax,%eax
je     1206 <main+0x96>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11ec <main+0x7c>
test   %eax,%eax
je     1206 <main+0x96>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11ec <main+0x7c>
test   %eax,%eax
je     1206 <main+0x96>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11ec <main+0x7c>
test   %eax,%eax
je     1206 <main+0x96>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe0d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xde7(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"%ld -> %ld;\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %30, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 5
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = call i32 (...) @fork()
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = call i64 (...) @getppid()
%24 = call i64 (...) @getpid()
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %23, i64 %24)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = call i32 @wait(i32* null)
br label %30
30: ; preds = %28
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %8
33: ; preds = %8
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"%ld -> %ld;\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %14 [
i32 -1, label %4
i32 0, label %8
]
4: ; preds = %23, %20, %17, %14, %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %23, %20, %17, %14, %2
%9 = tail call i64 (...) @getppid()
%10 = tail call i64 (...) @getpid()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %9, i64 %10)
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = tail call i32 @wait(i32* null)
%16 = tail call i32 (...) @fork()
switch i32 %16, label %17 [
i32 -1, label %4
i32 0, label %8
]
17: ; preds = %14
%18 = tail call i32 @wait(i32* null)
%19 = tail call i32 (...) @fork()
switch i32 %19, label %20 [
i32 -1, label %4
i32 0, label %8
]
20: ; preds = %17
%21 = tail call i32 @wait(i32* null)
%22 = tail call i32 (...) @fork()
switch i32 %22, label %23 [
i32 -1, label %4
i32 0, label %8
]
23: ; preds = %20
%24 = tail call i32 @wait(i32* null)
%25 = tail call i32 (...) @fork()
switch i32 %25, label %26 [
i32 -1, label %4
i32 0, label %8
]
26: ; preds = %23
%27 = tail call i32 @wait(i32* null)
ret i32 0
}