// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::Compare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, int, int, int)
void WholeGenome::Compare(string query_vcf,
	string output_prefix,
    bool detail_results,
    int score_unit_,
    int match_mode_,
    int score_scheme_)
{
    // initialize query variant data structure


	que_vcf_filename = query_vcf;

    this->output_prefix = output_prefix;
    this->detail_results = detail_results;

    score_unit_indicator = score_unit_;
    match_mode_indicator = match_mode_;
    score_scheme_indicator = score_scheme_;

    if(score_scheme_indicator == 3){
        DirectMatch(ref_vcf_filename, query_vcf, match_mode_, output_prefix);
        return;
    }

    query_variant_total_num = ReadQueryVariants(query_vcf);

    if(score_unit_indicator == -1){
        score_unit_list.push_back(0);
        score_unit_list.push_back(1);
    }else{
        score_unit_list.push_back(score_unit_indicator);
    }

    if(match_mode_indicator == -1){
        match_mode_list.push_back(0);
        match_mode_list.push_back(1);
    }else{
        match_mode_list.push_back(match_mode_indicator);
    }

    if(score_scheme_indicator == -1){
        score_scheme_list.push_back(0);
        score_scheme_list.push_back(1);
        score_scheme_list.push_back(2);
    }else{
        score_scheme_list.push_back(score_scheme_indicator);
    }

    for(int i = 0; i < score_unit_list.size(); i++){
        for(int j = 0; j < match_mode_list.size(); j++){
            for(int k = 0; k < score_scheme_list.size(); k++){
                int mode_index = GetIndexFromMatchScore(score_scheme_list[i], match_mode_list[j], score_scheme_list[k]);
                mode_index_list.push_back(mode_index);  // so that I can directly know how many mode, do not need to calculate all the time
            }
        }
    }

    cout << "Baseline VCF: " << ref_vcf_filename << endl;
    cout << "Query VCF: " << query_vcf << endl;
    cout << "========VCF Stat.==========" << endl;
    cout << "Total Number of VCF Entries: " << endl;
    cout << "Baseline: " << baseline_variant_total_num << "; Query: " << query_variant_total_num << endl;

    cout << "parallel clustering..." << endl;
    ParallelClustering();
    
    cout << "matching variants..." << endl;
    ClusteringMatchMultiThread();

    // most clustering results are cleared inside ParallelClustering function except the following one
    // which is needed for matching
    variants_by_cluster.clear();
    // clean at the end of function
    for(int j = 0; j < chrom_num; j++){
        que_variant_by_chrid[j]->clear();
        //delete que_variant_by_chrid[j];
    }
    //delete[] que_variant_by_chrid;

    query_variant_strings.clear();
    query_variant_total_num = 0;
    threshold_list.clear();
    threshold_num = 0;
    // The following three matching results are cleared inside ClusteringMatchMultiThread function
    // match_records_by_mode_by_thread;
    // baseline_total_match_num;
    // query_total_match_num;

    score_unit_list.clear();
    match_mode_list.clear();
    score_scheme_list.clear();
    mode_index_list.clear();

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r9d, %r12d
movl %r8d, %r15d
movl %ecx, %r13d
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %rbx
addq $0x28, %rdi
callq 0x51d0
leaq 0x1a0(%rbx), %rdi
movq %r14, 0x10(%rsp)
movq %r14, %rsi
callq 0x51d0
movb %r13b, 0x80(%rbx)
movl %r15d, 0x1e0(%rbx)
movl %r12d, 0x1e4(%rbx)
movl 0xd0(%rsp), %eax
movl %eax, 0x1e8(%rbx)
cmpl $0x3, %eax
jne 0x19010
leaq 0x8(%rbx), %rsi
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x53f0
leaq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x53f0
leaq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x53f0
leaq 0x38(%rsp), %rdx
leaq 0x18(%rsp), %r8
movq %rbx, %rdi
movl %r12d, %ecx
callq 0x193c2
leaq 0x18(%rsp), %rdi
callq 0x55e8
leaq 0x38(%rsp), %rdi
callq 0x55e8
leaq 0x78(%rsp), %rdi
callq 0x55e8
jmp 0x1937d
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x53f0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x18cc0
movl %eax, 0x4c(%rbx)
leaq 0x58(%rsp), %rdi
callq 0x55e8
leaq 0x1f0(%rbx), %r15
cmpl $-0x1, 0x1e0(%rbx)
je 0x19059
leaq 0x1e0(%rbx), %rsi
movq %r15, %rdi
callq 0x1ac4e
jmp 0x19083
leaq 0x4(%rsp), %r12
andl $0x0, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1c1d4
movl $0x1, (%r12)
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x1c1d4
leaq 0x208(%rbx), %r15
cmpl $-0x1, 0x1e4(%rbx)
je 0x190a4
leaq 0x1e4(%rbx), %rsi
movq %r15, %rdi
callq 0x1ac4e
jmp 0x190ce
leaq 0x4(%rsp), %r12
andl $0x0, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1c1d4
movl $0x1, (%r12)
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x1c1d4
leaq 0x220(%rbx), %r15
cmpl $-0x1, 0x1e8(%rbx)
movq %rbp, 0x8(%rsp)
je 0x190f4
leaq 0x1e8(%rbx), %rsi
movq %r15, %rdi
callq 0x1ac4e
jmp 0x19136
leaq 0x4(%rsp), %r12
andl $0x0, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1c1d4
movl $0x1, (%r12)
leaq 0x4(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1c1d4
movl $0x2, (%r12)
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x1c1d4
leaq 0x238(%rbx), %r15
xorl %r13d, %r13d
leaq 0x4(%rsp), %r12
movq 0x1f8(%rbx), %rax
subq 0x1f0(%rbx), %rax
sarq $0x2, %rax
cmpq %r13, %rax
jbe 0x191d4
xorl %ebp, %ebp
movq 0x210(%rbx), %rax
subq 0x208(%rbx), %rax
sarq $0x2, %rax
cmpq %rbp, %rax
jbe 0x191cc
xorl %r14d, %r14d
movq 0x220(%rbx), %rax
movq 0x228(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r14, %rcx
jbe 0x191c7
movl (%rax,%r13,4), %ecx
movq 0x208(%rbx), %rdx
movl (%rdx,%rbp,4), %edx
movl (%rax,%r14,4), %eax
andl $0x1, %ecx
andl $0x1, %edx
leal (%rdx,%rcx,2), %ecx
andl $0x3, %eax
leal (%rax,%rcx,4), %eax
movl %eax, 0x4(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1ac4e
incq %r14
jmp 0x19178
incq %rbp
jmp 0x1915e
incq %r13
jmp 0x19145
movq 0x16de5(%rip), %r15     # 0x2ffc0
leaq 0x97dd(%rip), %rsi      # 0x229bf
movq %r15, %rdi
callq 0x52f0
leaq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
leaq 0x97c9(%rip), %rsi      # 0x229ce
movq %r15, %rdi
callq 0x52f0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
leaq 0x97b1(%rip), %rsi      # 0x229da
movq %r15, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5190
leaq 0x97b6(%rip), %rsi      # 0x229f6
movq %r15, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5190
leaq 0x97bd(%rip), %rsi      # 0x22a14
movq %r15, %rdi
callq 0x52f0
movl 0x48(%rbx), %esi
movq %rax, %rdi
callq 0x5530
leaq 0x97ae(%rip), %rsi      # 0x22a1f
movq %rax, %rdi
callq 0x52f0
movl 0x4c(%rbx), %esi
movq %rax, %rdi
callq 0x5530
movq %rax, %rdi
callq 0x5190
leaq 0x9796(%rip), %rsi      # 0x22a29
movq %r15, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq %rbx, %rdi
callq 0xef70
leaq 0x978e(%rip), %rsi      # 0x22a40
movq %r15, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq %rbx, %rdi
callq 0x17564
leaq 0x160(%rbx), %rdi
callq 0x1a056
xorl %r14d, %r14d
movslq (%rbx), %rax
cmpq %rax, %r14
jge 0x192f6
movq 0x150(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x19a30
incq %r14
jmp 0x192d9
leaq 0x68(%rbx), %rdi
callq 0xc9ca
andl $0x0, 0x4c(%rbx)
movq 0x250(%rbx), %rax
cmpq %rax, 0x258(%rbx)
je 0x1931a
movq %rax, 0x258(%rbx)
andl $0x0, 0x268(%rbx)
movq 0x1f0(%rbx), %rax
cmpq %rax, 0x1f8(%rbx)
je 0x19338
movq %rax, 0x1f8(%rbx)
movq 0x208(%rbx), %rax
cmpq %rax, 0x210(%rbx)
je 0x1934f
movq %rax, 0x210(%rbx)
movq 0x220(%rbx), %rax
cmpq %rax, 0x228(%rbx)
je 0x19366
movq %rax, 0x228(%rbx)
movq 0x238(%rbx), %rax
cmpq %rax, 0x240(%rbx)
je 0x1937d
movq %rax, 0x240(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x55e8
jmp 0x193a1
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x55e8
jmp 0x193b2
jmp 0x193af
movq %rax, %rbx
movq %r15, %rdi
callq 0x55e8
movq %rbx, %rdi
callq 0x5540