#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(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
scalar_t__ getppid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  fprintf(stdout, "digraph G {\n");
  fflush(stdout);
  pid_t parent_pid = getpid();
  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) {
      fprintf(stdout, "\t%ld -> %ld;\n", (long)getppid(), (long)getpid());
    }
    wait(NULL);
  }
  if (getpid() == parent_pid) {
    fprintf(stdout, "}\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    125b <main+0xdb>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1204 <main+0x84>
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1244 <main+0xc4>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
movslq %eax,%rcx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cc <main+0x4c>
mov    $0x0,%al
call   1030 <getpid@plt>
cmp    -0x14(%rbp),%eax
jne    1282 <main+0x102>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e4a(%rip),%r15
mov    (%r15),%edi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11c6 <main+0x46>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x70>
jmp    12d6 <main+0x156>
mov    (%r15),%ebp
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
movslq %eax,%rcx
lea    0xe2e(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <wait@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     120c <main+0x8c>
cmp    $0xffffffff,%eax
jne    1236 <main+0xb6>
jmp    12d6 <main+0x156>
mov    (%r15),%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
movslq %eax,%rcx
lea    0xde8(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <wait@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1252 <main+0xd2>
cmp    $0xffffffff,%eax
jne    127c <main+0xfc>
jmp    12d6 <main+0x156>
mov    (%r15),%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
movslq %eax,%rcx
lea    0xda2(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <wait@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1295 <main+0x115>
cmp    $0xffffffff,%eax
jne    12bf <main+0x13f>
jmp    12d6 <main+0x156>
mov    (%r15),%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
movslq %eax,%rcx
lea    0xd5f(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <wait@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     12f0 <main+0x170>
cmp    $0xffffffff,%eax
jne    131a <main+0x19a>
lea    0xd30(%rip),%rdi
call   1060 <perror@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    (%r15),%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
movslq %eax,%rcx
lea    0xd04(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <wait@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %r14d,%eax
jne    133e <main+0x1be>
mov    (%r15),%edi
lea    0xce9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [13 x i8] c"digraph G {\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"\09%ld -> %ld;\0A\00"
@.str.3 = [3 x i8] c"}\0A\00"
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 = load i32, i32* @stdout
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
%13 = call i32 (...) @getpid()
store i32 %13, i32* %6
store i32 0, i32* %7
br label %14
14: ; preds = %36, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 5
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = call i32 (...) @fork()
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* @stdout
%30 = call i64 (...) @getppid()
%31 = call i32 (...) @getpid()
%32 = sext i32 %31 to i64
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %30, i64 %32)
br label %34
34: ; preds = %28, %25
%35 = call i32 @wait(i32* null)
br label %36
36: ; preds = %34
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %14
39: ; preds = %14
%40 = call i32 (...) @getpid()
%41 = load i32, i32* %6
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %43, %39
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [13 x i8] c"digraph G {\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"\09%ld -> %ld;\0A\00"
@.str.3 = [3 x i8] c"}\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (...) @fork()
switch i32 %8, label %19 [
i32 -1, label %9
i32 0, label %13
]
9: ; preds = %46, %37, %28, %19, %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = tail call i64 (...) @getppid()
%16 = tail call i32 (...) @getpid()
%17 = sext i32 %16 to i64
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %15, i64 %17)
br label %19
19: ; preds = %2, %13
%20 = tail call i32 @wait(i32* null)
%21 = tail call i32 (...) @fork()
switch i32 %21, label %28 [
i32 -1, label %9
i32 0, label %22
]
22: ; preds = %19
%23 = load i32, i32* @stdout
%24 = tail call i64 (...) @getppid()
%25 = tail call i32 (...) @getpid()
%26 = sext i32 %25 to i64
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %24, i64 %26)
br label %28
28: ; preds = %22, %19
%29 = tail call i32 @wait(i32* null)
%30 = tail call i32 (...) @fork()
switch i32 %30, label %37 [
i32 -1, label %9
i32 0, label %31
]
31: ; preds = %28
%32 = load i32, i32* @stdout
%33 = tail call i64 (...) @getppid()
%34 = tail call i32 (...) @getpid()
%35 = sext i32 %34 to i64
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %33, i64 %35)
br label %37
37: ; preds = %31, %28
%38 = tail call i32 @wait(i32* null)
%39 = tail call i32 (...) @fork()
switch i32 %39, label %46 [
i32 -1, label %9
i32 0, label %40
]
40: ; preds = %37
%41 = load i32, i32* @stdout
%42 = tail call i64 (...) @getppid()
%43 = tail call i32 (...) @getpid()
%44 = sext i32 %43 to i64
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %42, i64 %44)
br label %46
46: ; preds = %40, %37
%47 = tail call i32 @wait(i32* null)
%48 = tail call i32 (...) @fork()
switch i32 %48, label %55 [
i32 -1, label %9
i32 0, label %49
]
49: ; preds = %46
%50 = load i32, i32* @stdout
%51 = tail call i64 (...) @getppid()
%52 = tail call i32 (...) @getpid()
%53 = sext i32 %52 to i64
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %51, i64 %53)
br label %55
55: ; preds = %49, %46
%56 = tail call i32 @wait(i32* null)
%57 = tail call i32 (...) @getpid()
%58 = icmp eq i32 %57, %7
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* @stdout
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %59, %55
ret i32 0
}