#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 EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i, j;
  int n = atoi(argv[1]);
  pid_t pidGeneration[100];
  int var = 1;
  printf("Start pid: %d\n", getpid());
  for (i = 0; i < n; i++) {
    pidGeneration[i] = var;
    var = var * 2;
    if (fork()) {
      var++;
      if (fork()) {
        exit(EXIT_SUCCESS);
      }
    }
    if (i == (n - 1)) {
      printf("Process tree : ");
      for (j = 0; j < n; j++) {
        printf("%d ", pidGeneration[j]);
      }
      printf("%d", var);
      printf("\n");
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x1b4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    129f <main+0x14f>
mov    -0x1b4(%rbp),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x1b0(%rbp,%rax,4)
mov    -0x1b4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1211 <main+0xc1>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     120c <main+0xbc>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1211 <main+0xc1>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    128c <main+0x13c>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    126a <main+0x11a>
movslq -0x18(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1237 <main+0xe7>
mov    -0x1b4(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1291 <main+0x141>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <main+0x51>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1247 <main+0xe7>
lea    -0x1(%rbx),%r12d
mov    %ebx,%ebp
mov    $0x1,%r13d
lea    0xe71(%rip),%rbx
xor    %r14d,%r14d
jmp    11c9 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
cmp    %rbp,%r14
je     1247 <main+0xe7>
mov    %r13d,(%rsp,%r14,4)
add    %r13d,%r13d
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ec <main+0x8c>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    1262 <main+0x102>
or     $0x1,%r13d
cmp    %r12,%r14
jne    11c0 <main+0x60>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp,%r15,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1210 <main+0xb0>
lea    0xdf5(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <main+0x60>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Start pid: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [16 x i8] c"Process tree : \00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 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
%9 = alloca [100 x i32]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %8
store i32 1, i32* %10
%15 = call i32 (...) @getpid()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 0, i32* %6
br label %17
17: ; preds = %64, %2
%18 = load i32, i32* %6
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %67
21: ; preds = %17
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %9, i64 0, i64 %24
store i32 %22, i32* %25
%26 = load i32, i32* %10
%27 = mul nsw i32 %26, 2
store i32 %27, i32* %10
%28 = call i64 (...) @fork()
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %21
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
%33 = call i64 (...) @fork()
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* @EXIT_SUCCESS
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %30
br label %39
39: ; preds = %38, %21
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = sub nsw i32 %41, 1
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %63
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %46
46: ; preds = %56, %44
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %59
50: ; preds = %46
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i32], [100 x i32]* %9, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %50
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %46
59: ; preds = %46
%60 = load i32, i32* %10
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %59, %39
br label %64
64: ; preds = %63
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %17
67: ; preds = %17
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
@.str = [15 x i8] c"Start pid: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [16 x i8] c"Process tree : \00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i32]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
%7 = bitcast [100 x i32]* %3 to i8*
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp sgt i32 %6, 0
br i1 %10, label %11, label %47
11: ; preds = %2
%12 = add nsw i32 %6, -1
%13 = zext i32 %12 to i64
%14 = zext i32 %6 to i64
br label %15
15: ; preds = %11, %44
%16 = phi i64 [ 0, %11 ], [ %45, %44 ]
%17 = phi i32 [ 1, %11 ], [ %30, %44 ]
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %16
store i32 %17, i32* %18
%19 = shl nsw i32 %17, 1
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = or i32 %19, 1
%24 = tail call i64 (...) @fork()
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %22, %15
%30 = phi i32 [ %23, %22 ], [ %19, %15 ]
%31 = icmp eq i64 %16, %13
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %34
%35 = phi i64 [ 0, %32 ], [ %39, %34 ]
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = add nuw nsw i64 %35, 1
%40 = icmp eq i64 %39, %14
br i1 %40, label %41, label %34
41: ; preds = %34
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%43 = tail call i32 @putchar(i32 10)
br label %44
44: ; preds = %29, %41
%45 = add nuw nsw i64 %16, 1
%46 = icmp eq i64 %45, %14
br i1 %46, label %47, label %15
47: ; preds = %44, %2
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}