// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movb $0x0, %al
callq 0x2ce0
movl $0x20010028, %edi       # imm = 0x20010028
leaq -0x1c92(%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 $0x5, %edi
movl $0x4000000, %esi        # imm = 0x4000000
callq 0x4a10
movq %rax, -0x20(%rbp)
movq 0x34c3(%rip), %rdi      # 0x8110
leaq 0x740(%rip), %rsi       # 0x5394
callq 0x2e50
movq %rax, -0x28(%rbp)
movq 0x349c(%rip), %rdi      # 0x8100
leaq 0x72b(%rip), %rsi       # 0x5396
callq 0x2e50
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea0
cmpl $0x0, %eax
je 0x4c95
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4b10
jmp 0x4c74
movq -0x30(%rbp), %rdi
callq 0x1050
movq 0x3463(%rip), %rdi      # 0x8108
leaq 0x6ea(%rip), %rsi       # 0x5396
callq 0x2e50
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea0
cmpl $0x0, %eax
je 0x4d1b
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4b70
cmpl $0x0, %eax
je 0x4d03
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x69e(%rip), %rsi       # 0x5398
movb $0x0, %al
callq 0x10e0
jmp 0x4d19
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x68e(%rip), %rsi       # 0x53a0
movb $0x0, %al
callq 0x10e0
jmp 0x4cb5
movq -0x30(%rbp), %rdi
callq 0x1050
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
callq 0x3200
movq -0x38(%rbp), %rdi
movq %rax, %xmm0
movaps 0x5ed(%rip), %xmm1      # 0x5330
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x5f1(%rip), %xmm1      # 0x5340
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x5ba(%rip), %xmm1      # 0x5320
divsd %xmm1, %xmm0
leaq 0x33e7(%rip), %rax      # 0x8158
movq (%rax), %rdx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
leaq 0x625(%rip), %rsi       # 0x53a7
movb $0x1, %al
callq 0x10e0
movb $0x0, %al
callq 0x2d00
leaq 0x624(%rip), %rdi       # 0x53bb
movb $0x1, %al
callq 0x1080
movq -0x28(%rbp), %rdi
callq 0x1050
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq