// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::DirectMatch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void WholeGenome::DirectMatch(string ref_vcf, string query_vcf, int match_mode_, string output_prefix)
{
    //dout << "direct match" << endl;
    match_mode_indicator = match_mode_;
    //int ref_variant_num = ReadReferenceVariants(ref_vcf);
    int que_variant_num = ReadQueryVariants(query_vcf);
    //dout << que_variant_num << endl;
    int match_num = 0;
    ofstream output_stat_file;
    output_stat_file.open(output_dir + "/" + output_prefix+".direct");
    for(int i = 0; i < chrom_num; i++){
        if(ref_variant_by_chrid[i]->size() == 0 || que_variant_by_chrid[i]->size() == 0)
            continue;
        //[TODO] not the right way to do it, at least need multimap
        multimap<int, int> ref_variant_by_pos;
        for(int j = 0; j < ref_variant_by_chrid[i]->size(); j++){
            DiploidVariant var = ref_variant_by_chrid[i]->at(j);
            int pos = var.pos;
            ref_variant_by_pos.insert(pair<int, int>(pos, j));
        }

        for(int j = 0; j < que_variant_by_chrid[i]->size(); j++){
            DiploidVariant var = que_variant_by_chrid[i]->at(j);
            int pos = var.pos;
            if(ref_variant_by_pos.find(pos) == ref_variant_by_pos.end())
                continue;

            pair<multimap<int, int>::iterator, multimap<int, int>::iterator> var_range;
            var_range = ref_variant_by_pos.equal_range(pos);

            for(auto it = var_range.first; it != var_range.second; ++it){
                int ref_index = (*it).second;
                DiploidVariant ref_var = ref_variant_by_chrid[i]->at(ref_index);
                if (match_mode_indicator != 1 && var == ref_var){
                    match_num ++;
                    string matched_variant = chrname_by_chrid[i] + "\t" + to_string(ref_var.pos) + "\t" + ref_var.ref + "\t";
                    output_stat_file << matched_variant << endl;
                    break;
                }else if(match_mode_indicator == 1 && var.CompareNoGenotype(ref_var)){
                    match_num ++;
                    break;
                }
            }
        }
    }
    output_stat_file.close();
    dout << "matched variants: " << match_num << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3e8, %rsp            # imm = 0x3E8
movq %r8, %r14
movq %rdi, %rbx
movl %ecx, 0x1e4(%rdi)
leaq 0x188(%rsp), %r15
movq %r15, %rdi
movq %rdx, %rsi
callq 0x53f0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x18cc0
leaq 0x188(%rsp), %rdi
callq 0x55e8
leaq 0x1e8(%rsp), %rdi
callq 0x5510
leaq 0x1c0(%rbx), %rsi
leaq 0x9186(%rip), %rdx      # 0x225ab
leaq 0x18(%rsp), %rdi
callq 0x96b0
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x9691
leaq 0x960d(%rip), %rdx      # 0x22a55
leaq 0xb0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x7fce
leaq 0x1e8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x5180
leaq 0xb0(%rsp), %rdi
callq 0x55e8
leaq 0x58(%rsp), %rdi
callq 0x55e8
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x55e8
leaq 0xb8(%rbx), %rax
movq %rax, 0x50(%rsp)
xorl %ecx, %ecx
leaq 0x14(%rsp), %r13
movl $0x0, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
cmpl (%rbx), %ecx
jge 0x197de
movq 0x148(%rbx), %rax
movslq %ecx, %rdx
movq (%rax,%rdx,8), %rsi
movq 0x8(%rsi), %rdi
cmpq (%rsi), %rdi
je 0x197d7
movq 0x150(%rbx), %rsi
movq (%rsi,%rdx,8), %rdx
movq 0x8(%rdx), %rsi
cmpq (%rdx), %rsi
je 0x197d7
andl $0x0, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0x20(%rsp), %rdx
movq %rdx, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
xorl %r12d, %r12d
movslq %ecx, %rdx
movq (%rax,%rdx,8), %rdi
movq 0x8(%rdi), %rax
subq (%rdi), %rax
cqto
pushq $0x58
popq %rsi
idivq %rsi
cmpq %r12, %rax
jbe 0x19580
movq %r12, %rsi
callq 0x1a386
leaq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x1a174
movl 0xb0(%rsp), %eax
movl %eax, 0x58(%rsp)
movl %r12d, 0x5c(%rsp)
movq %r14, %rdi
leaq 0x58(%rsp), %rsi
callq 0x1f0e8
leaq 0xb0(%rsp), %rdi
callq 0x19c16
incq %r12
movq 0x148(%rbx), %rax
movl 0xc(%rsp), %ecx
jmp 0x19513
xorl %esi, %esi
movq 0x150(%rbx), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rax
subq (%rdi), %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x197cb
movq %rsi, 0x48(%rsp)
callq 0x1a386
leaq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x1a174
movl 0xb0(%rsp), %eax
movl %eax, 0x14(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x1e11c
leaq 0x20(%rsp), %rcx
cmpq %rcx, %rax
je 0x197ad
movq %r14, %rdi
movq %r13, %rsi
callq 0x1f2e8
movq %rax, %r13
movq %rdx, %r12
cmpq %r12, %r13
je 0x197a3
movslq 0x24(%r13), %rsi
movq 0x148(%rbx), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1a386
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x1a174
cmpl $0x1, 0x1e4(%rbx)
jne 0x19659
leaq 0xb0(%rsp), %rdi
leaq 0x58(%rsp), %r15
movq %r15, %rsi
callq 0x1ac6c
movzbl %al, %r14d
movq %r15, %rdi
addl %r14d, 0x10(%rsp)
xorb $0x1, %r14b
jmp 0x19789
leaq 0xb0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1a05e
testb %al, %al
je 0x19774
movq 0x50(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x19a5a
leaq 0x8f20(%rip), %r14      # 0x225a9
leaq 0x108(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x96b0
movl 0x58(%rsp), %esi
leaq 0x128(%rsp), %r15
movq %r15, %rdi
callq 0x8011
leaq 0x148(%rsp), %rbp
movq %rbp, %rdi
leaq 0x108(%rsp), %rsi
movq %r15, %rdx
callq 0x94bb
leaq 0x168(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x7fce
leaq 0x1a8(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x60(%rsp), %rdx
callq 0x9691
leaq 0x1c8(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x7fce
movq %rbp, %rdi
callq 0x55e8
leaq 0x168(%rsp), %rdi
callq 0x55e8
leaq 0x148(%rsp), %rdi
callq 0x55e8
leaq 0x128(%rsp), %rdi
callq 0x55e8
leaq 0x108(%rsp), %rdi
callq 0x55e8
leaq 0x1e8(%rsp), %rdi
movq %r15, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
incl 0x10(%rsp)
movq %r15, %rdi
callq 0x55e8
xorl %r14d, %r14d
jmp 0x19784
movb $0x1, %r14b
cmpl $0x1, 0x1e4(%rbx)
je 0x1962f
leaq 0x58(%rsp), %rdi
callq 0x19c16
testb %r14b, %r14b
je 0x197a3
movq %r13, %rdi
callq 0x5240
movq %rax, %r13
jmp 0x195f7
leaq 0x18(%rsp), %r14
leaq 0x14(%rsp), %r13
leaq 0xb0(%rsp), %rdi
callq 0x19c16
movq 0x48(%rsp), %rsi
incq %rsi
movl 0xc(%rsp), %ecx
jmp 0x19582
movq %r14, %rdi
callq 0x1b0cc
movl 0xc(%rsp), %ecx
incl %ecx
jmp 0x194b1
leaq 0x1e8(%rsp), %rdi
callq 0x5400
movq 0x167ce(%rip), %rdi     # 0x2ffc0
leaq 0x9264(%rip), %rsi      # 0x22a5d
callq 0x52f0
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x5530
movq %rax, %rdi
callq 0x5190
leaq 0x1e8(%rsp), %rdi
callq 0x5430
addq $0x3e8, %rsp            # imm = 0x3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x55e8
jmp 0x19846
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x55e8
jmp 0x19855
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x55e8
jmp 0x1992c
jmp 0x1987b
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
callq 0x55e8
jmp 0x19939
movq %rax, %rbx
jmp 0x1992c
jmp 0x19912
jmp 0x19912
jmp 0x19912
jmp 0x19894
movq %rax, %rbx
jmp 0x19922
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x55e8
jmp 0x198b1
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
callq 0x55e8
jmp 0x198cd
movq %rax, %rbx
jmp 0x198e7
movq %rax, %rbx
jmp 0x198da
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x55e8
leaq 0x128(%rsp), %rdi
callq 0x55e8
leaq 0x108(%rsp), %rdi
jmp 0x19901
movq %rax, %rbx
jmp 0x19906
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0x55e8
leaq 0x58(%rsp), %rdi
callq 0x19c16
jmp 0x19915
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x19c16
leaq 0x18(%rsp), %rdi
callq 0x1b0cc
leaq 0x1e8(%rsp), %rdi
callq 0x5430
movq %rbx, %rdi
callq 0x5540
nop