// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdx, -0xf8(%rbp)
movq %rsi, -0x100(%rbp)
movb %cl, %al
movl 0x10(%rbp), %ecx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
addq $0x28, %rdi
callq 0x6070
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x6070
movq -0xf0(%rbp), %rax
movb -0x19(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x80(%rax)
movl -0x20(%rbp), %ecx
movl %ecx, 0x1e0(%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0x1e4(%rax)
movl 0x10(%rbp), %ecx
movl %ecx, 0x1e8(%rax)
cmpl $0x3, 0x1e8(%rax)
jne 0x31315
movq -0xf0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %rdi
callq 0x61b0
movq -0x100(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x61b0
jmp 0x31266
movq -0xf8(%rbp), %rsi
movl -0x24(%rbp), %eax
movl %eax, -0x104(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x61b0
jmp 0x31284
movl -0x104(%rbp), %ecx
movq -0xf0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x98(%rbp), %r8
callq 0x318f0
jmp 0x312a7
leaq -0x98(%rbp), %rdi
callq 0x6828
leaq -0x68(%rbp), %rdi
callq 0x6828
leaq -0x48(%rbp), %rdi
callq 0x6828
jmp 0x318d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x31307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x312fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x6828
leaq -0x68(%rbp), %rdi
callq 0x6828
leaq -0x48(%rbp), %rdi
callq 0x6828
jmp 0x318df
movq -0x100(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x61b0
movq -0xf0(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x30cc0
movl %eax, -0x108(%rbp)
jmp 0x3134a
movq -0xf0(%rbp), %rax
movl -0x108(%rbp), %ecx
movl %ecx, 0x4c(%rax)
leaq -0xb8(%rbp), %rdi
callq 0x6828
movq -0xf0(%rbp), %rax
cmpl $-0x1, 0x1e0(%rax)
jne 0x313dd
movq -0xf0(%rbp), %rdi
addq $0x1f0, %rdi            # imm = 0x1F0
movl $0x0, -0xbc(%rbp)
leaq -0xbc(%rbp), %rsi
callq 0x344f0
movq -0xf0(%rbp), %rdi
addq $0x1f0, %rdi            # imm = 0x1F0
movl $0x1, -0xc0(%rbp)
leaq -0xc0(%rbp), %rsi
callq 0x344f0
jmp 0x313fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x6828
jmp 0x318df
movq -0xf0(%rbp), %rsi
movq %rsi, %rdi
addq $0x1f0, %rdi            # imm = 0x1F0
addq $0x1e0, %rsi            # imm = 0x1E0
callq 0x364f0
movq -0xf0(%rbp), %rax
cmpl $-0x1, 0x1e4(%rax)
jne 0x31454
movq -0xf0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movl $0x0, -0xc4(%rbp)
leaq -0xc4(%rbp), %rsi
callq 0x344f0
movq -0xf0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movl $0x1, -0xc8(%rbp)
leaq -0xc8(%rbp), %rsi
callq 0x344f0
jmp 0x31471
movq -0xf0(%rbp), %rsi
movq %rsi, %rdi
addq $0x208, %rdi            # imm = 0x208
addq $0x1e4, %rsi            # imm = 0x1E4
callq 0x364f0
movq -0xf0(%rbp), %rax
cmpl $-0x1, 0x1e8(%rax)
jne 0x314ef
movq -0xf0(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movl $0x0, -0xcc(%rbp)
leaq -0xcc(%rbp), %rsi
callq 0x344f0
movq -0xf0(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movl $0x1, -0xd0(%rbp)
leaq -0xd0(%rbp), %rsi
callq 0x344f0
movq -0xf0(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movl $0x2, -0xd4(%rbp)
leaq -0xd4(%rbp), %rsi
callq 0x344f0
jmp 0x3150c
movq -0xf0(%rbp), %rsi
movq %rsi, %rdi
addq $0x220, %rdi            # imm = 0x220
addq $0x1e8, %rsi            # imm = 0x1E8
callq 0x364f0
movl $0x0, -0xd8(%rbp)
movq -0xf0(%rbp), %rdi
movslq -0xd8(%rbp), %rax
movq %rax, -0x118(%rbp)
addq $0x1f0, %rdi            # imm = 0x1F0
callq 0x19a40
movq %rax, %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
jae 0x3169e
movl $0x0, -0xdc(%rbp)
movq -0xf0(%rbp), %rdi
movslq -0xdc(%rbp), %rax
movq %rax, -0x120(%rbp)
addq $0x208, %rdi            # imm = 0x208
callq 0x19a40
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x31688
movl $0x0, -0xe0(%rbp)
movq -0xf0(%rbp), %rdi
movslq -0xe0(%rbp), %rax
movq %rax, -0x128(%rbp)
addq $0x220, %rdi            # imm = 0x220
callq 0x19a40
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
jae 0x31672
movq -0xf0(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movslq -0xd8(%rbp), %rsi
callq 0x19a60
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x130(%rbp)
addq $0x208, %rdi            # imm = 0x208
movslq -0xdc(%rbp), %rsi
callq 0x19a60
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x12c(%rbp)
addq $0x220, %rdi            # imm = 0x220
movslq -0xe0(%rbp), %rsi
callq 0x19a60
movl -0x130(%rbp), %esi
movl -0x12c(%rbp), %edx
movq -0xf0(%rbp), %rdi
movl (%rax), %ecx
callq 0x35500
movq -0xf0(%rbp), %rdi
movl %eax, -0xe4(%rbp)
addq $0x238, %rdi            # imm = 0x238
leaq -0xe4(%rbp), %rsi
callq 0x364f0
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0x31592
jmp 0x31674
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x31554
jmp 0x3168a
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x31516
movq 0x42913(%rip), %rdi     # 0x73fb8
leaq 0x24307(%rip), %rsi     # 0x559b3
callq 0x6420
movq -0xf0(%rbp), %rsi
movq %rax, %rdi
addq $0x8, %rsi
callq 0x63e0
movq %rax, %rdi
movq 0x428b2(%rip), %rsi     # 0x73f80
callq 0x6480
movq 0x428de(%rip), %rdi     # 0x73fb8
leaq 0x242e1(%rip), %rsi     # 0x559c2
callq 0x6420
movq -0x100(%rbp), %rsi
movq %rax, %rdi
callq 0x63e0
movq %rax, %rdi
movq 0x42881(%rip), %rsi     # 0x73f80
callq 0x6480
movq 0x428ad(%rip), %rdi     # 0x73fb8
leaq 0x242bc(%rip), %rsi     # 0x559ce
callq 0x6420
movq %rax, %rdi
movq 0x4285f(%rip), %rsi     # 0x73f80
callq 0x6480
movq 0x4288b(%rip), %rdi     # 0x73fb8
leaq 0x242b6(%rip), %rsi     # 0x559ea
callq 0x6420
movq %rax, %rdi
movq 0x4283d(%rip), %rsi     # 0x73f80
callq 0x6480
movq 0x42869(%rip), %rdi     # 0x73fb8
leaq 0x242b2(%rip), %rsi     # 0x55a08
callq 0x6420
movq %rax, %rdi
movq -0xf0(%rbp), %rax
movl 0x48(%rax), %esi
callq 0x6740
movq %rax, %rdi
leaq 0x2429c(%rip), %rsi     # 0x55a13
callq 0x6420
movq %rax, %rdi
movq -0xf0(%rbp), %rax
movl 0x4c(%rax), %esi
callq 0x6740
movq %rax, %rdi
movq 0x427e8(%rip), %rsi     # 0x73f80
callq 0x6480
movq 0x42814(%rip), %rdi     # 0x73fb8
leaq 0x24272(%rip), %rsi     # 0x55a1d
callq 0x6420
movq %rax, %rdi
movq 0x427c6(%rip), %rsi     # 0x73f80
callq 0x6480
movq -0xf0(%rbp), %rdi
callq 0x1e190
movq 0x427e6(%rip), %rdi     # 0x73fb8
leaq 0x2425b(%rip), %rsi     # 0x55a34
callq 0x6420
movq %rax, %rdi
movq 0x42798(%rip), %rsi     # 0x73f80
callq 0x6480
movq -0xf0(%rbp), %rdi
callq 0x2e4b0
movq -0xf0(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
callq 0x33c60
movl $0x0, -0xe8(%rbp)
movq -0xf0(%rbp), %rcx
movl -0xe8(%rbp), %eax
cmpl (%rcx), %eax
jge 0x31856
movq -0xf0(%rbp), %rax
movq 0x150(%rax), %rax
movslq -0xe8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x32660
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x31816
movq -0xf0(%rbp), %rdi
addq $0x68, %rdi
callq 0x17a60
movq -0xf0(%rbp), %rdi
movl $0x0, 0x4c(%rdi)
addq $0x250, %rdi            # imm = 0x250
callq 0x36560
movq -0xf0(%rbp), %rdi
movl $0x0, 0x268(%rdi)
addq $0x1f0, %rdi            # imm = 0x1F0
callq 0x36580
movq -0xf0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x36580
movq -0xf0(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
callq 0x36580
movq -0xf0(%rbp), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0x36580
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x6750
nopl (%rax,%rax)