#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int);
int createProcessPerfectTree(int i, int n) {
  int lc = (i << 1) + 1, rc = (i << 1) + 2;
  printf("%d\n", getpid());
  if (lc >= n)
    return i;
  pid_t leftchild = fork();
  if (leftchild == 0)
    return createProcessPerfectTree(lc, n);
  else {
    pid_t rightChild;
    rightChild = fork();
    if (rightChild == 0)
      return createProcessPerfectTree(rc, n);
  }
  return i;
}


x86 assembly (clang, -O0):
<createProcessPerfectTree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1192 <createProcessPerfectTree+0x52>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ef <createProcessPerfectTree+0xaf>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <createProcessPerfectTree+0x7b>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <createProcessPerfectTree@plt>
mov    %eax,-0x4(%rbp)
jmp    11ef <createProcessPerfectTree+0xaf>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e4 <createProcessPerfectTree+0xa4>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <createProcessPerfectTree@plt>
mov    %eax,-0x4(%rbp)
jmp    11ef <createProcessPerfectTree+0xaf>
jmp    11e9 <createProcessPerfectTree+0xa9>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createProcessPerfectTree>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xead(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%ebx
lea    (%rbx,%rbx,1),%ebp
add    $0x1,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
cmp    %r15d,%ebp
jge    1196 <createProcessPerfectTree+0x56>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1160 <createProcessPerfectTree+0x20>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     11a3 <createProcessPerfectTree+0x63>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    %ebx,%ebx
add    $0x2,%ebx
mov    %ebx,%edi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <createProcessPerfectTree@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @createProcessPerfectTree(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = load i32, i32* %4
%11 = shl i32 %10, 1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = shl i32 %13, 1
%15 = add nsw i32 %14, 2
store i32 %15, i32* %7
%16 = call i32 (...) @getpid()
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = load i32, i32* %4
store i32 %22, i32* %3
br label %42
23: ; preds = %2
%24 = call i64 (...) @fork()
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = call i32 @createProcessPerfectTree(i32 %28, i32 %29)
store i32 %30, i32* %3
br label %42
31: ; preds = %23
%32 = call i64 (...) @fork()
store i64 %32, i64* %9
%33 = load i64, i64* %9
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* %7
%37 = load i32, i32* %5
%38 = call i32 @createProcessPerfectTree(i32 %36, i32 %37)
store i32 %38, i32* %3
br label %42
39: ; preds = %31
br label %40
40: ; preds = %39
%41 = load i32, i32* %4
store i32 %41, i32* %3
br label %42
42: ; preds = %40, %35, %27, %21
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @createProcessPerfectTree(i32 %0, i32 %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i32 [ %0, %2 ], [ %6, %10 ]
%5 = shl i32 %4, 1
%6 = or i32 %5, 1
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %6, %1
br i1 %9, label %10, label %19
10: ; preds = %3
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %3, label %13
13: ; preds = %10
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = add nsw i32 %5, 2
%18 = tail call i32 @createProcessPerfectTree(i32 %17, i32 %1)
br label %19
19: ; preds = %3, %16, %13
%20 = phi i32 [ %4, %13 ], [ %18, %16 ], [ %4, %3 ]
ret i32 %20
}