// File: /workspace/github_c_makefile_star2_O3/OhYee[P]computer_application_programming_experiment/hash_search/hashtable_search/hashtable_search.c
// Function: main
int main(int argc, char **argv) {
    clock_start();

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

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

    while (read_file(f, temp)) {
        ht_add(ht, temp);
    }
    fclose(f);

    // for (int i = 0; i < (ht->length); ++i) {
    //     printf("%d %d\n", i, ht->array[i] == NULL ? 0 :
    //     ht->array[i]->length);
    // }

    f = open_file(words_filename, "r");
    while (read_file(f, temp)) {
        ++word_number;
        // if (word_number % 10000 == 0)
        //     printf("%d %fs %d ok\n", word_number, clock_duration(),
        //            word_exist_number);

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x23bc
leaq -0x1033(%rip), %rsi     # 0x24cc
movl $0x155ce710, %edi       # imm = 0x155CE710
callq 0x24d7
movl $0x10, %edi
callq 0x2710
movq %rax, %r15
movl $0x10000, 0x8(%rax)     # imm = 0x10000
movl $0x80000, %edi          # imm = 0x80000
callq 0x2710
movq %rax, (%r15)
movslq 0x8(%r15), %rdx
shlq $0x3, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x10a0
movl $0x100, %edi            # imm = 0x100
callq 0x2710
movq %rax, %r12
movq 0x3bc8(%rip), %rdi      # 0x7118
leaq 0xe4e(%rip), %rsi       # 0x43a5
callq 0x2448
movq %rax, %r14
movq 0x3ba2(%rip), %rdi      # 0x7108
leaq 0xe3a(%rip), %rsi       # 0x43a7
callq 0x2448
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0x2473
testl %eax, %eax
je 0x3594
movq %r15, %rdi
movq %r12, %rsi
callq 0x3427
movq %r13, %rdi
jmp 0x3578
movq %r13, %rdi
callq 0x1070
movq 0x3b6d(%rip), %rdi      # 0x7110
leaq 0xdfd(%rip), %rsi       # 0x43a7
callq 0x2448
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0x2473
movl $0x0, %ebp
testl %eax, %eax
je 0x360e
xorl %ebp, %ebp
xorl %ebx, %ebx
incl %ebp
movq %r15, %rdi
movq %r12, %rsi
callq 0x3494
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leaq 0xdcc(%rip), %rsi       # 0x43b1
leaq 0xdbd(%rip), %rax       # 0x43a9
cmovneq %rax, %rsi
addl %ecx, %ebx
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10f0
movq %r13, %rdi
movq %r12, %rsi
callq 0x2473
testl %eax, %eax
jne 0x35ca
movq %r13, %rdi
callq 0x1070
xorl %eax, %eax
callq 0x26bc
movq %rax, %xmm1
punpckldq 0xd16(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xd1e(%rip), %xmm1      # 0x4350
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0xd1a(%rip), %xmm0      # 0x4360
leaq 0x3b0b(%rip), %rax      # 0x7158
movq (%rax), %rdx
leaq 0xd61(%rip), %rsi       # 0x43b8
movq %r14, %rdi
movl %ebp, %ecx
movl %ebx, %r8d
movb $0x1, %al
callq 0x10f0
xorl %eax, %eax
callq 0x23cb
leaq 0xd58(%rip), %rdi       # 0x43cc
movb $0x1, %al
callq 0x1090
movq %r14, %rdi
callq 0x1070
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq