// File: /workspace/github_c_makefile_star2_O0/OhYee[P]computer_application_programming_experiment/tree/bplus_search/bplus_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;

    bplus_tree *bpt = bpt_init(m, compare);

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

    while (read_file(f, temp)) {
        bpt_add(bpt, temp, strlen(temp) + 1);
    }
    fclose(f);

#ifdef debug
    bpt_print(bpt);
#endif

    compare_init();

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

        if (bpt_exist(bpt, 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",
            _bplus_node_number, (double)mp_get_length() / 1024, compare_number,
            word_number, word_exist_number);
    printf("%f s\n", clock_duration());
    fclose(output);

    // extern int _bplus_string_mem;
    // extern int _bplus_node_mem;
    // printf("%d %d %d\n", _bplus_string_mem,
    // _bplus_node_mem,sizeof(bplus_tree));

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movb $0x0, %al
callq 0x2ce0
movl $0xed6988b, %edi        # imm = 0xED6988B
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 $0xa, %edi
leaq -0x7f(%rip), %rsi       # 0x4830
callq 0x2350
movq %rax, -0x20(%rbp)
movq 0x3851(%rip), %rdi      # 0x8110
leaq 0xac7(%rip), %rsi       # 0x538d
callq 0x2e50
movq %rax, -0x28(%rbp)
movq 0x382a(%rip), %rdi      # 0x8100
leaq 0xab2(%rip), %rsi       # 0x538f
callq 0x2e50
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea0
cmpl $0x0, %eax
je 0x4926
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
addq $0x1, %rax
movl %eax, %edx
callq 0x23a0
jmp 0x48e6
movq -0x30(%rbp), %rdi
callq 0x1050
movb $0x0, %al
callq 0x2d30
movq 0x37cb(%rip), %rdi      # 0x8108
leaq 0xa4b(%rip), %rsi       # 0x538f
callq 0x2e50
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea0
cmpl $0x0, %eax
je 0x49b3
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2540
cmpl $0x0, %eax
je 0x499b
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x9ff(%rip), %rsi       # 0x5391
movb $0x0, %al
callq 0x10e0
jmp 0x49b1
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x9ef(%rip), %rsi       # 0x5399
movb $0x0, %al
callq 0x10e0
jmp 0x494d
movq -0x30(%rbp), %rdi
callq 0x1050
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x3771(%rip), %rax      # 0x813c
movl (%rax), %eax
movl %eax, -0x44(%rbp)
xorl %eax, %eax
callq 0x3200
movq -0x50(%rbp), %rdi
movl -0x44(%rbp), %edx
movq %rax, %xmm0
movaps 0x946(%rip), %xmm1      # 0x5330
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x94a(%rip), %xmm1      # 0x5340
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x913(%rip), %xmm1      # 0x5320
divsd %xmm1, %xmm0
leaq 0x3738(%rip), %rax      # 0x8150
movq (%rax), %rcx
movl -0x14(%rbp), %r8d
movl -0x18(%rbp), %r9d
leaq 0x976(%rip), %rsi       # 0x53a0
movb $0x1, %al
callq 0x10e0
movb $0x0, %al
callq 0x2d00
leaq 0x97a(%rip), %rdi       # 0x53b9
movb $0x1, %al
callq 0x1080
movq -0x28(%rbp), %rdi
callq 0x1050
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq