// File: /workspace/github_c_makefile_star2_O0/OhYee[P]computer_application_programming_experiment/tree/radix4_search/radix4_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(2);

    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());

    // 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%d\n", memory_length,
    // _bits_string_num,
    //        _bits_string_mem, _bits_num, _bits_mem, _radix_node_number,
    //        _radix_strmem, _radix_nodemem, _radix_strnum,sizeof(bits));

    fclose(output);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movb $0x0, %al
callq 0x2ce0
movl $0xbc95873, %edi        # imm = 0xBC95873
leaq -0x1902(%rip), %rsi     # 0x2f80
callq 0x2f90
movl $0x100, %edi            # imm = 0x100
callq 0x32a0
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x2, %edi
callq 0x3cc0
movq %rax, -0x20(%rbp)
movq 0x3858(%rip), %rdi      # 0x8110
leaq 0xace(%rip), %rsi       # 0x538d
callq 0x2e50
movq %rax, -0x28(%rbp)
movq 0x3831(%rip), %rdi      # 0x8100
leaq 0xab9(%rip), %rsi       # 0x538f
callq 0x2e50
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea0
cmpl $0x0, %eax
je 0x491b
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1060
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl %eax, %edx
callq 0x3d00
jmp 0x48df
movq -0x30(%rbp), %rdi
callq 0x1050
movb $0x0, %al
callq 0x2d30
movq 0x37d6(%rip), %rdi      # 0x8108
leaq 0xa56(%rip), %rsi       # 0x538f
callq 0x2e50
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea0
cmpl $0x0, %eax
je 0x49c6
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1060
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %eax, %edx
callq 0x3d80
cmpl $0x0, %eax
je 0x49ab
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x9ef(%rip), %rsi       # 0x5391
movb $0x0, %al
callq 0x10e0
jmp 0x49c1
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x9df(%rip), %rsi       # 0x5399
movb $0x0, %al
callq 0x10e0
jmp 0x4942
movq -0x30(%rbp), %rdi
callq 0x1050
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x37aa(%rip), %rax      # 0x8188
movl (%rax), %eax
movl %eax, -0x54(%rbp)
xorl %eax, %eax
callq 0x3200
movq -0x60(%rbp), %rdi
movl -0x54(%rbp), %edx
movq %rax, %xmm0
movaps 0x933(%rip), %xmm1      # 0x5330
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x937(%rip), %xmm1      # 0x5340
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x900(%rip), %xmm1      # 0x5320
divsd %xmm1, %xmm0
leaq 0x3725(%rip), %rax      # 0x8150
movq (%rax), %rcx
movl -0x14(%rbp), %r8d
movl -0x18(%rbp), %r9d
leaq 0x963(%rip), %rsi       # 0x53a0
movb $0x1, %al
callq 0x10e0
movb $0x0, %al
callq 0x2d00
leaq 0x967(%rip), %rdi       # 0x53b9
movb $0x1, %al
callq 0x1080
movq -0x28(%rbp), %rdi
callq 0x1050
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq