#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*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int n = 20;
  int pid = 0;
  printf("main process has id %d\n", getpid());
  while (n > 0) {
    int pid = fork();
    if (pid == 0) {
      printf("pid %d %d %d \n", getpid(), pid, n);
      exit(0);
    }
    n--;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11c4 <main+0x84>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11b6 <main+0x76>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1174 <main+0x34>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x14,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x13,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x12,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x11,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x10,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xf,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xe,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xd,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xc,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xb,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xa,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x9,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x8,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x7,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x6,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x5,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x4,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x3,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x2,%ebx
test   %eax,%eax
je     12c8 <main+0x188>
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x1,%ebx
test   %eax,%eax
jne    12e3 <main+0x1a3>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd42(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"main process has id %d\0A\00"
@.str.1 = [15 x i8] c"pid %d %d %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 20, i32* %2
store i32 0, i32* %3
%5 = call i32 (...) @getpid()
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = call i32 (...) @fork()
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = call i32 (...) @getpid()
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16, i32 %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %10
%21 = load i32, i32* %2
%22 = add nsw i32 %21, -1
store i32 %22, i32* %2
br label %7
23: ; preds = %7
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [24 x i8] c"main process has id %d\0A\00"
@.str.1 = [15 x i8] c"pid %d %d %d \0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %64, %61, %58, %55, %52, %49, %46, %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %0
%6 = phi i32 [ 20, %0 ], [ 19, %10 ], [ 18, %13 ], [ 17, %16 ], [ 16, %19 ], [ 15, %22 ], [ 14, %25 ], [ 13, %28 ], [ 12, %31 ], [ 11, %34 ], [ 10, %37 ], [ 9, %40 ], [ 8, %43 ], [ 7, %46 ], [ 6, %49 ], [ 5, %52 ], [ 4, %55 ], [ 3, %58 ], [ 2, %61 ], [ 1, %64 ]
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 0, i32 %6)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = tail call i32 (...) @fork()
%12 = icmp eq i32 %11, 0
br i1 %12, label %5, label %13
13: ; preds = %10
%14 = tail call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %5, label %16
16: ; preds = %13
%17 = tail call i32 (...) @fork()
%18 = icmp eq i32 %17, 0
br i1 %18, label %5, label %19
19: ; preds = %16
%20 = tail call i32 (...) @fork()
%21 = icmp eq i32 %20, 0
br i1 %21, label %5, label %22
22: ; preds = %19
%23 = tail call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %5, label %25
25: ; preds = %22
%26 = tail call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %5, label %28
28: ; preds = %25
%29 = tail call i32 (...) @fork()
%30 = icmp eq i32 %29, 0
br i1 %30, label %5, label %31
31: ; preds = %28
%32 = tail call i32 (...) @fork()
%33 = icmp eq i32 %32, 0
br i1 %33, label %5, label %34
34: ; preds = %31
%35 = tail call i32 (...) @fork()
%36 = icmp eq i32 %35, 0
br i1 %36, label %5, label %37
37: ; preds = %34
%38 = tail call i32 (...) @fork()
%39 = icmp eq i32 %38, 0
br i1 %39, label %5, label %40
40: ; preds = %37
%41 = tail call i32 (...) @fork()
%42 = icmp eq i32 %41, 0
br i1 %42, label %5, label %43
43: ; preds = %40
%44 = tail call i32 (...) @fork()
%45 = icmp eq i32 %44, 0
br i1 %45, label %5, label %46
46: ; preds = %43
%47 = tail call i32 (...) @fork()
%48 = icmp eq i32 %47, 0
br i1 %48, label %5, label %49
49: ; preds = %46
%50 = tail call i32 (...) @fork()
%51 = icmp eq i32 %50, 0
br i1 %51, label %5, label %52
52: ; preds = %49
%53 = tail call i32 (...) @fork()
%54 = icmp eq i32 %53, 0
br i1 %54, label %5, label %55
55: ; preds = %52
%56 = tail call i32 (...) @fork()
%57 = icmp eq i32 %56, 0
br i1 %57, label %5, label %58
58: ; preds = %55
%59 = tail call i32 (...) @fork()
%60 = icmp eq i32 %59, 0
br i1 %60, label %5, label %61
61: ; preds = %58
%62 = tail call i32 (...) @fork()
%63 = icmp eq i32 %62, 0
br i1 %63, label %5, label %64
64: ; preds = %61
%65 = tail call i32 (...) @fork()
%66 = icmp eq i32 %65, 0
br i1 %66, label %5, label %67
67: ; preds = %64
%68 = tail call i32 @exit(i32 0)
unreachable
}