#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 */
struct tree_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ destroy_tree(struct tree_node *);
int /*<<< orphan*/ print_tree(struct tree_node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_array(size_t, int *);
struct tree_node *rebuild_tree(size_t, int *, size_t, int *);
int scanf(char *, size_t *);
int main(void) {
  printf(
      "Enter the size of the tree, followed by the in-order traversal values,\n"
      "followed by the pre-oder traversal values (space separated)\n");
  printf("> ");
  size_t tree_sz;
  while (scanf("%zu", &tree_sz) == 1) {
    int in_order[tree_sz];
    int pre_order[tree_sz];
    read_array(tree_sz, in_order);
    read_array(tree_sz, pre_order);
    struct tree_node *root =
        rebuild_tree(tree_sz, in_order, tree_sz, pre_order);
    print_tree(root);
    destroy_tree(root);
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
lea    0xf02(%rip),%rdi
call   1030 <printf@plt>
lea    0xef9(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1242 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <read_array@plt>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1080 <read_array@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rdx
call   1050 <rebuild_tree@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <print_tree@plt>
mov    -0x30(%rbp),%rdi
call   1040 <destroy_tree@plt>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1187 <main+0x27>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1251 <main+0xe1>
lea    0xe4d(%rip),%r15
lea    -0x30(%rbp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rsp,%r14
mov    -0x30(%rbp),%rax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x30(%rbp),%rdi
mov    %rsp,%rbx
lea    0xf(,%rdi,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r13,%rsi
call   1090 <read_array@plt>
mov    -0x30(%rbp),%rdi
mov    %rbx,%rsi
call   1090 <read_array@plt>
mov    -0x30(%rbp),%rdi
mov    %r13,%rsi
mov    %rdi,%rdx
mov    %rbx,%rcx
call   1060 <rebuild_tree@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <print_tree@plt>
mov    %rbx,%rdi
call   1050 <destroy_tree@plt>
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rsp
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     11c0 <main+0x50>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@.str = [132 x i8] c"Enter the size of the tree, followed by the in-order traversal values,\0Afollowed by the pre-oder traversal values (space separated)\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.tree_node*
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %12, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = load i64, i64* %2
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
%16 = load i64, i64* %2
%17 = alloca i32, i64 %16
store i64 %16, i64* %5
%18 = load i64, i64* %2
%19 = call i32 @read_array(i64 %18, i32* %15)
%20 = load i64, i64* %2
%21 = call i32 @read_array(i64 %20, i32* %17)
%22 = load i64, i64* %2
%23 = load i64, i64* %2
%24 = call %struct.tree_node* @rebuild_tree(i64 %22, i32* %15, i64 %23, i32* %17)
store %struct.tree_node* %24, %struct.tree_node** %6
%25 = load %struct.tree_node*, %struct.tree_node** %6
%26 = call i32 @print_tree(%struct.tree_node* %25)
%27 = load %struct.tree_node*, %struct.tree_node** %6
%28 = call i32 @destroy_tree(%struct.tree_node* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** %3
br label %9
31: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@str = [131 x i8] c"Enter the size of the tree, followed by the in-order traversal values,\0Afollowed by the pre-oder traversal values (space separated)\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([131 x i8], [131 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i64* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %23
7: ; preds = %0, %7
%8 = load i64, i64* %1
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i64, i64* %1
%12 = alloca i32, i64 %11
%13 = call i32 @read_array(i64 %11, i32* %10)
%14 = load i64, i64* %1
%15 = call i32 @read_array(i64 %14, i32* %12)
%16 = load i64, i64* %1
%17 = call %struct.tree_node* @rebuild_tree(i64 %16, i32* %10, i64 %16, i32* %12)
%18 = call i32 @print_tree(%struct.tree_node* %17)
%19 = call i32 @destroy_tree(%struct.tree_node* %17)
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %7, label %23
23: ; preds = %7, %0
ret i32 0
}