#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*/ gen_new_tree(int *, int, int *, int, int);
int gen_bin_tree(int n, int tree_id, int *new_tree) {
  int i, j;
  int old_tree[2 * 20 + 1];
  int size_of_tree = 2 * n - 1;
  if (n == 3) {
    for (i = 0; i < size_of_tree; i++)
      new_tree[i] = 0;
    new_tree[0] = 0;
    new_tree[1] = 1;
    new_tree[2] = -1;
    new_tree[3] = 2;
    new_tree[4] = 3;
  } else {
    gen_bin_tree(n - 1, tree_id / (2 * n - 5), old_tree);
    j = tree_id % (2 * n - 5);
    gen_new_tree(old_tree, j, new_tree, n, size_of_tree);
  }
  return 0;
}


x86 assembly (clang, -O0):
<gen_bin_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
mov    %eax,-0xc4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    11bc <gen_bin_tree+0x9c>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jge    1181 <gen_bin_tree+0x61>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1155 <gen_bin_tree+0x35>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x10(%rax)
jmp    120e <gen_bin_tree+0xee>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    -0xc0(%rbp),%rdx
call   1040 <gen_bin_tree@plt>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    -0xc4(%rbp),%r8d
call   1030 <gen_new_tree@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_bin_tree>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb0,%rsp
mov    %rdx,%r14
mov    %edi,%ebx
lea    (%rbx,%rbx,1),%ebp
add    $0xffffffff,%ebp
cmp    $0x3,%edi
jne    117d <gen_bin_tree+0x4d>
cmp    $0x2,%ebp
mov    $0x1,%edx
cmovge %ebp,%edx
shl    $0x2,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movaps 0xe91(%rip),%xmm0
movups %xmm0,(%r14)
movl   $0x3,0x10(%r14)
jmp    11ae <gen_bin_tree+0x7e>
lea    (%rbx,%rbx,1),%ecx
lea    -0x1(%rbx),%edi
add    $0xfffffffb,%ecx
mov    %esi,%eax
cltd
idiv   %ecx
mov    %edx,%r15d
mov    %rsp,%r12
mov    %eax,%esi
mov    %r12,%rdx
call   1050 <gen_bin_tree@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
call   1030 <gen_new_tree@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gen_bin_tree(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [41 x i32]
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%11 = load i32, i32* %4
%12 = mul nsw i32 2, %11
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %10
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %40
16: ; preds = %3
store i32 0, i32* %7
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32*, i32** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 0, i32* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %17
29: ; preds = %17
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i64 0
store i32 0, i32* %31
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i64 1
store i32 1, i32* %33
%34 = load i32*, i32** %6
%35 = getelementptr inbounds i32, i32* %34, i64 2
store i32 -1, i32* %35
%36 = load i32*, i32** %6
%37 = getelementptr inbounds i32, i32* %36, i64 3
store i32 2, i32* %37
%38 = load i32*, i32** %6
%39 = getelementptr inbounds i32, i32* %38, i64 4
store i32 3, i32* %39
br label %61
40: ; preds = %3
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = load i32, i32* %5
%44 = load i32, i32* %4
%45 = mul nsw i32 2, %44
%46 = sub nsw i32 %45, 5
%47 = sdiv i32 %43, %46
%48 = getelementptr inbounds [41 x i32], [41 x i32]* %9, i64 0, i64 0
%49 = call i32 @gen_bin_tree(i32 %42, i32 %47, i32* %48)
%50 = load i32, i32* %5
%51 = load i32, i32* %4
%52 = mul nsw i32 2, %51
%53 = sub nsw i32 %52, 5
%54 = srem i32 %50, %53
store i32 %54, i32* %8
%55 = getelementptr inbounds [41 x i32], [41 x i32]* %9, i64 0, i64 0
%56 = load i32, i32* %8
%57 = load i32*, i32** %6
%58 = load i32, i32* %4
%59 = load i32, i32* %10
%60 = call i32 @gen_new_tree(i32* %55, i32 %56, i32* %57, i32 %58, i32 %59)
br label %61
61: ; preds = %40, %29
ret i32 0
}

LLVM IR (-O2):
define i32 @gen_bin_tree(i32 %0, i32 %1, i32* %2) {
%4 = alloca [41 x i32]
%5 = bitcast [41 x i32]* %4 to i8*
%6 = shl nsw i32 %0, 1
%7 = add i32 %6, -1
%8 = icmp eq i32 %0, 3
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = bitcast i32* %2 to i8*
%11 = call i32 @llvm.smax.i32(i32 %7, i32 1)
%12 = zext i32 %11 to i64
%13 = shl nuw nsw i64 %12, 2
%14 = bitcast i32* %2 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 -1, i32 2>, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %2, i64 4
store i32 3, i32* %15
br label %24
16: ; preds = %3
%17 = add nsw i32 %0, -1
%18 = add nsw i32 %6, -5
%19 = sdiv i32 %1, %18
%20 = getelementptr inbounds [41 x i32], [41 x i32]* %4, i64 0, i64 0
%21 = call i32 @gen_bin_tree(i32 %17, i32 %19, i32* %20)
%22 = srem i32 %1, %18
%23 = call i32 @gen_new_tree(i32* %20, i32 %22, i32* %2, i32 %0, i32 %7)
br label %24
24: ; preds = %16, %9
ret i32 0
}