// File: /workspace/github_c_makefile_star2_O1/OhYee[P]computer_application_programming_experiment/hash_search/bf_search/bf_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;

    bloom_filter *bf = bf_init(hash_number, bit_length);

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

    while (read_file(f, temp)) {
        bf_add(bf, 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);
    // }

    // bg_print(bf->value);
    // printf("\n");

    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 (bf_exist(bf, 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 0x23e4
leaq -0x1188(%rip), %rsi     # 0x2508
movl $0x20010028, %edi       # imm = 0x20010028
callq 0x2513
movl $0x100, %edi            # imm = 0x100
callq 0x2748
movq %rax, %r15
movl $0x4000000, %esi        # imm = 0x4000000
movl $0x5, %edi
callq 0x34da
movq %rax, %r12
movq 0x3a50(%rip), %rdi      # 0x7110
leaq 0xcf5(%rip), %rsi       # 0x43bc
callq 0x2480
movq %rax, %r14
movq 0x3a2a(%rip), %rdi      # 0x7100
leaq 0xce1(%rip), %rsi       # 0x43be
callq 0x2480
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x24ab
testl %eax, %eax
je 0x3704
movq %r12, %rdi
movq %r15, %rsi
callq 0x35c2
movq %r13, %rdi
jmp 0x36e8
movq %r13, %rdi
callq 0x1060
movq 0x39f5(%rip), %rdi      # 0x7108
leaq 0xca4(%rip), %rsi       # 0x43be
callq 0x2480
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x24ab
movl $0x0, %ebp
testl %eax, %eax
je 0x377e
xorl %ebp, %ebp
xorl %ebx, %ebx
incl %ebp
movq %r12, %rdi
movq %r15, %rsi
callq 0x360a
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leaq 0xc73(%rip), %rsi       # 0x43c8
leaq 0xc64(%rip), %rax       # 0x43c0
cmovneq %rax, %rsi
addl %ecx, %ebx
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10e0
movq %r13, %rdi
movq %r15, %rsi
callq 0x24ab
testl %eax, %eax
jne 0x373a
movq %r13, %rdi
callq 0x1060
xorl %eax, %eax
callq 0x26f4
movq %rax, %xmm1
punpckldq 0xbb6(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xbbe(%rip), %xmm1      # 0x4360
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0xbba(%rip), %xmm0      # 0x4370
leaq 0x399b(%rip), %rax      # 0x7158
movq (%rax), %rdx
leaq 0xc08(%rip), %rsi       # 0x43cf
movq %r14, %rdi
movl %ebp, %ecx
movl %ebx, %r8d
movb $0x1, %al
callq 0x10e0
xorl %eax, %eax
callq 0x23f3
leaq 0xbff(%rip), %rdi       # 0x43e3
movb $0x1, %al
callq 0x1080
movq %r14, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq