// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/tree/patricia_search/patricia_search.c
// Function: main
int main() {
    clock_start();

    mp_init(memory_length, mp_exit);
    char *temp = mp_new(max_string_length * sizeof(char));
    int   word_number = 0;
    int   word_exist_number = 0;

    radix_tree *rt = rt_init(1);

    FILE *output = open_file(output_filename, "w");
    FILE *f = open_file(patterns_filename, "r");

    while (read_file(f, temp)) {
        rt_add(rt, temp, strlen(temp));
        // rt_print(rt);
    }
    fclose(f);

    // rt_print(rt);

    compare_init();

    f = open_file(words_filename, "r");
    while (read_file(f, temp)) {
        ++word_number;

        if (rt_exist(rt, temp, strlen(temp))) {
            ++word_exist_number;
            fprintf(output, "%s yes\n", temp);
        } else {
            fprintf(output, "%s no\n", temp);
        }
    }
    fclose(f);

    fprintf(output,
            "%10d %10.2f "
            "%" PRIu64 " %7d %7d\n",
            _radix_node_number, (double)mp_get_length() / 1024, compare_number,
            word_number, word_exist_number);
    printf("%f s\n", clock_duration());
    fclose(output);

    // extern int _bits_string_num;
    // extern int _bits_string_mem;
    // extern int _bits_num;
    // extern int _bits_mem;

    // extern int _radix_node_number;
    // extern int _radix_strmem;
    // extern int _radix_nodemem;
    // extern int _radix_strnum;

    // printf("%d\n%d %d %d %d\n%d %d %d %d\n", memory_length, _bits_string_num,
    //        _bits_string_mem, _bits_num, _bits_mem, _radix_node_number,
    //        _radix_strmem, _radix_nodemem, _radix_strnum);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %eax, %eax
callq 0x1fec
leaq -0xea2(%rip), %rsi      # 0x20f8
movl $0x9585873, %edi        # imm = 0x9585873
callq 0x2101
movl $0x100, %edi            # imm = 0x100
callq 0x22ed
movq %rax, %r14
pushq $0x1
popq %rdi
callq 0x28d0
movq %rax, %r15
movq 0x414d(%rip), %rdi      # 0x7110
leaq 0x13bb(%rip), %rsi      # 0x4385
callq 0x2078
movq %rax, (%rsp)
movq 0x4126(%rip), %rdi      # 0x7100
leaq 0x13a6(%rip), %rsi      # 0x4387
callq 0x2078
movq %rax, %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x20a1
testl %eax, %eax
je 0x300f
movq %r14, %rdi
callq 0x1070
movq %r15, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x28fa
jmp 0x2fe9
movq %r12, %rdi
callq 0x1060
xorl %eax, %eax
callq 0x2018
movq 0x40e3(%rip), %rdi      # 0x7108
leaq 0x135b(%rip), %rsi      # 0x4387
callq 0x2078
movq %rax, %r13
leaq 0x1356(%rip), %rbx      # 0x4391
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %r13, %rdi
movq %r14, %rsi
callq 0x20a1
testl %eax, %eax
je 0x308e
incl %r12d
movq %r14, %rdi
callq 0x1070
movq %r15, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x292b
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movq %rbx, %rsi
leaq 0x1311(%rip), %rax      # 0x4389
cmovneq %rax, %rsi
addl %ecx, %ebp
movq (%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10e0
jmp 0x3040
movq %r13, %rdi
callq 0x1060
leaq 0x40eb(%rip), %rax      # 0x7188
movl (%rax), %r14d
xorl %eax, %eax
callq 0x229d
movq %rax, %xmm1
punpckldq 0x126c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1274(%rip), %xmm1     # 0x4330
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x1270(%rip), %xmm0     # 0x4340
leaq 0x4079(%rip), %rax      # 0x7150
movq (%rax), %rcx
leaq 0x12b7(%rip), %rsi      # 0x4398
movq (%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
movl %r12d, %r8d
movl %ebp, %r9d
movb $0x1, %al
callq 0x10e0
xorl %eax, %eax
callq 0x1ffb
leaq 0x12ab(%rip), %rdi      # 0x43b1
movb $0x1, %al
callq 0x1080
movq %rbx, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq