// File: wx-csy[P]librmq/prep.cpp
// Function: main
int main() {
    work();
    decision_tree_node *node = new decision_tree_node(instances, 0);
    puts("#include <cstdint>");
    puts("#include \"librmq/hardcode.h\"");
    puts("namespace librmq {");
    puts("static const decision_tree_node _nodes[] = {");
    node->serialize();
    delete node;
    puts("};\n");
    fprintf(stderr, "# of nodes in decision tree: %d\n", next_node_id);
    puts("decision_tree_node const * const decision_tree_nodes = _nodes;");

    puts("const std::int8_t lookup_table[][SEGLEN][SEGLEN] = {");
    for (const auto& tr : trees) print_lookup(tree_sample[tr]);
    puts("};\n");
    
    puts("const std::int8_t lookup_pref[][SEGLEN] = {");
    for (const auto& tr : trees) print_lookup_pref(tree_sample[tr]);
    puts("};\n");
    
    puts("const std::int8_t lookup_suf[][SEGLEN] = {");
    for (const auto& tr : trees) print_lookup_suf(tree_sample[tr]);
    puts("};\n");
    
    puts("}");
    fprintf(stderr, "# of different Cartesian trees: %d\n", (int)trees.size());
    return 0;
}

// Assembly:
subq $0xb8, %rsp
movl $0x0, 0xb4(%rsp)
callq 0x1860
movl $0x20, %edi
callq 0x10e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
leaq 0xc76d(%rip), %rsi      # 0xe170
xorl %edx, %edx
callq 0x2330
jmp 0x1a0c
movq 0x18(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x75f5(%rip), %rdi      # 0x9015
callq 0x1150
leaq 0x75fc(%rip), %rdi      # 0x9028
callq 0x1150
leaq 0x760d(%rip), %rdi      # 0x9045
callq 0x1150
leaq 0x7614(%rip), %rdi      # 0x9058
callq 0x1150
movq 0xa8(%rsp), %rdi
callq 0x2620
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x1a82
movq 0x10(%rsp), %rdi
callq 0x26b0
movq 0x10(%rsp), %rdi
movl $0x20, %esi
callq 0x10f0
leaq 0x75fc(%rip), %rdi      # 0x9085
callq 0x1150
movq 0xc543(%rip), %rax      # 0xdfd8
movq (%rax), %rdi
movl 0xc6ca(%rip), %edx      # 0xe168
leaq 0x75e4(%rip), %rsi      # 0x9089
movb $0x0, %al
callq 0x1120
leaq 0x75f7(%rip), %rdi      # 0x90aa
callq 0x1150
leaq 0x762a(%rip), %rdi      # 0x90e9
callq 0x1150
leaq 0xc625(%rip), %rax      # 0xe0f0
movq %rax, 0x90(%rsp)
leaq 0xc616(%rip), %rdi      # 0xe0f0
callq 0x2720
movq %rax, 0x88(%rsp)
leaq 0xc602(%rip), %rdi      # 0xe0f0
callq 0x2750
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x2780
testb $0x1, %al
jne 0x1b16
jmp 0x1b82
leaq 0x88(%rsp), %rdi
callq 0x27c0
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rsi
leaq 0xc604(%rip), %rdi      # 0xe138
callq 0x27d0
movq (%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0x1580
leaq 0x88(%rsp), %rdi
callq 0x28c0
jmp 0x1afb
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
movl $0x20, %esi
callq 0x10f0
jmp 0x1d06
leaq 0x74fc(%rip), %rdi      # 0x9085
callq 0x1150
leaq 0x7589(%rip), %rdi      # 0x911e
callq 0x1150
leaq 0xc54f(%rip), %rax      # 0xe0f0
movq %rax, 0x68(%rsp)
leaq 0xc543(%rip), %rdi      # 0xe0f0
callq 0x2720
movq %rax, 0x60(%rsp)
leaq 0xc532(%rip), %rdi      # 0xe0f0
callq 0x2750
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2780
testb $0x1, %al
jne 0x1bdd
jmp 0x1c1b
leaq 0x60(%rsp), %rdi
callq 0x27c0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rsi
leaq 0xc540(%rip), %rdi      # 0xe138
callq 0x27d0
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x1700
leaq 0x60(%rsp), %rdi
callq 0x28c0
jmp 0x1bc8
leaq 0x7463(%rip), %rdi      # 0x9085
callq 0x1150
leaq 0x751c(%rip), %rdi      # 0x914a
callq 0x1150
leaq 0xc4b6(%rip), %rax      # 0xe0f0
movq %rax, 0x40(%rsp)
leaq 0xc4aa(%rip), %rdi      # 0xe0f0
callq 0x2720
movq %rax, 0x38(%rsp)
leaq 0xc499(%rip), %rdi      # 0xe0f0
callq 0x2750
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2780
testb $0x1, %al
jne 0x1c76
jmp 0x1cb4
leaq 0x38(%rsp), %rdi
callq 0x27c0
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rsi
leaq 0xc4a7(%rip), %rdi      # 0xe138
callq 0x27d0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x17b0
leaq 0x38(%rsp), %rdi
callq 0x28c0
jmp 0x1c61
leaq 0x73ca(%rip), %rdi      # 0x9085
callq 0x1150
leaq 0x74ae(%rip), %rdi      # 0x9175
callq 0x1150
movq 0xc305(%rip), %rax      # 0xdfd8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0xc40e(%rip), %rdi      # 0xe0f0
callq 0x2160
movq 0x8(%rsp), %rdi
movl %eax, %edx
leaq 0x7482(%rip), %rsi      # 0x9177
movb $0x0, %al
callq 0x1120
xorl %eax, %eax
addq $0xb8, %rsp
retq
movq 0xa0(%rsp), %rdi
callq 0x1180
nopw %cs:(%rax,%rax)
nopl (%rax)