#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*/ bst_sequences(struct tree_node *);
struct tree_node *deserialize(size_t);
int /*<<< orphan*/ destroy_tree(struct tree_node *);
int /*<<< orphan*/ printf(char *);
int scanf(char *, size_t *);
int main(void) {
  printf("Enter the number of nodes in the BST, followed by the preorder "
         "traversal, followed by the inorder traversal\n");
  printf("> ");
  size_t nodes;
  while (scanf("%zu", &nodes) == 1) {
    struct tree_node *root = deserialize(nodes);
    bst_sequences(root);
    destroy_tree(root);
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11c0 <main+0x70>
mov    -0x10(%rbp),%rdi
call   1050 <deserialize@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <bst_sequences@plt>
mov    -0x18(%rbp),%rdi
call   1040 <destroy_tree@plt>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
jmp    1177 <main+0x27>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11e4 <main+0x84>
lea    0xe65(%rip),%r14
lea    0xe61(%rip),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rdi
call   1060 <deserialize@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <bst_sequences@plt>
mov    %rbx,%rdi
call   1050 <destroy_tree@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     11b0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@.str = [109 x i8] c"Enter the number of nodes in the BST, followed by the preorder traversal, followed by the inorder traversal\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 %struct.tree_node*
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %9, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i64, i64* %2
%11 = call %struct.tree_node* @deserialize(i64 %10)
store %struct.tree_node* %11, %struct.tree_node** %3
%12 = load %struct.tree_node*, %struct.tree_node** %3
%13 = call i32 @bst_sequences(%struct.tree_node* %12)
%14 = load %struct.tree_node*, %struct.tree_node** %3
%15 = call i32 @destroy_tree(%struct.tree_node* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %6
17: ; preds = %6
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 = [108 x i8] c"Enter the number of nodes in the BST, followed by the preorder traversal, followed by the inorder traversal\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([108 x i8], [108 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 %15
7: ; preds = %0, %7
%8 = load i64, i64* %1
%9 = call %struct.tree_node* @deserialize(i64 %8)
%10 = call i32 @bst_sequences(%struct.tree_node* %9)
%11 = call i32 @destroy_tree(%struct.tree_node* %9)
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %7, label %15
15: ; preds = %7, %0
ret i32 0
}