// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::ConstructMatchRecord(SequencePath&, std::vector<DiploidVariant, std::allocator<DiploidVariant>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, int, int, int, int, int)
void WholeGenome::ConstructMatchRecord(SequencePath & best_path,
                                       vector<DiploidVariant> & variant_list,
                                       string & subsequence,
                                       int offset,
                                       int thread_index,
                                       int chr_id,
                                       int mode_index,
                                       int threshold_index){
    int truth_num = 0;
    int predict_num = 0;
    int truth_edit_distance = 0;
    int predict_edit_distance = 0;

    bool need_match_record = false;

    if (threshold_index == 0) need_match_record = true;

    bool multiple_match = false;

    if(best_path.donor_sequences[0] != best_path.donor_sequences[1]) multiple_match = true;

    string parsimonious_ref = subsequence;
    string parsimonious_alt0 = best_path.donor_sequences[0];
    string parsimonious_alt1 = best_path.donor_sequences[1];

    int parsimonious_pos = offset;
//    NormalizeVariantSequence(offset,
//                             parsimonious_ref,
//                             parsimonious_alt0,
//                             parsimonious_alt1,
//                             chr_id);

    string match_record = chrname_by_chrid[chr_id] + "\t" + to_string(parsimonious_pos+1) + "\t" + parsimonious_ref + "\t" + parsimonious_alt0;
    if(multiple_match) match_record += "/" + parsimonious_alt1;

    string vcf_record[2];
    string phasing_record[2];

    for (int i = 0; i < 2; i++) {
        for (int var_index = 0; var_index < variant_list.size(); var_index++) {
            DiploidVariant variant = variant_list[var_index];
            if(variant.flag != i) continue;
            //The exact wording from the C++ standard is (§4.7/4): "If the source type is bool,
            // the value false is converted to zero and the value true is converted to one."
            int phasing = best_path.choice_vector[var_index];
            if(phasing <= NOT_USE) continue;
            int edit_distance = CalculateEditDistance(variant, phasing, 0);
            if(i == 0){
                truth_num ++;
                truth_edit_distance += edit_distance;
            }else{
                predict_num ++;
                predict_edit_distance += edit_distance;
            }

            if(need_match_record){
                string alt_string = variant.alts[0];
                if(variant.multi_alts){
                    alt_string += "/" + variant.alts[1];
                }
                string phasing_string = "";
                if(phasing == 0){
                    phasing_string += "1";
                    if(variant.heterozygous){
                        if(variant.multi_alts && !variant.zero_one_var){
                            phasing_string += "|2";
                        }else{
                            phasing_string += "|0";
                        }
                    }else{
                        phasing_string += "|1";
                    }
                }else if(phasing == 1){
                    if(variant.multi_alts && !variant.zero_one_var){
                        phasing_string += "2|1";
                    }else if(variant.multi_alts && variant.zero_one_var){
                        phasing_string += "2|0";
                    }else{
                        phasing_string += "0|1";
                    }
                }else if(phasing == -1){
                    phasing_string += "0|1";
                }else if(phasing == -2){
                    phasing_string += "0|2";
                }
                string variant_record = to_string(variant.pos+1) + "," + variant.ref + "," + alt_string;
                vcf_record[i] += variant_record;
                phasing_record[i] += phasing_string;
                vcf_record[i] += ";";
                phasing_record[i] += ";";
            }
        }
        if(need_match_record){
            vcf_record[i] = vcf_record[i].substr(0, vcf_record[i].size()-1);
            phasing_record[i] = phasing_record[i].substr(0, phasing_record[i].size()-1);
        }

    }

    if(need_match_record){
        match_record += "\t" + vcf_record[0] + "\t" + vcf_record[1];
        match_record += "\t" + phasing_record[0] + "\t" + phasing_record[1];
        match_record += "\t" + to_string(best_path.score) + "\n";

        //complex_match_records[thread_index]->push_back(match_record);
        

        // this line should be recovered
        match_records_by_mode_by_thread[thread_index][mode_index]->push_back(match_record);
    


    }

    baseline_total_match_num[thread_index][threshold_index]->at(mode_index) += truth_num;
    query_total_match_num[thread_index][threshold_index]->at(mode_index) += predict_num;

    baseline_total_edit_distance[thread_index][threshold_index]->at(mode_index) += truth_edit_distance;
    query_total_edit_distance[thread_index][threshold_index]->at(mode_index) += predict_edit_distance;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl %r9d, %r14d
movl %r8d, %ebp
movq %rcx, %r13
movq %rdx, 0xd8(%rsp)
movq %rdi, 0x60(%rsp)
leaq 0xd0(%rsi), %rbx
movq %rsi, 0x78(%rsp)
leaq 0xf0(%rsi), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa908
movl %eax, %r15d
leaq 0x1e8(%rsp), %rdi
movq %r13, %rsi
callq 0x53f0
leaq 0x1c8(%rsp), %rdi
movq %rbx, %rsi
callq 0x53f0
leaq 0x1a8(%rsp), %rdi
movq %r12, %rsi
callq 0x53f0
movq 0x60(%rsp), %rax
leaq 0xb8(%rax), %rdi
leaq 0x2c0(%rsp), %rsi
callq 0x19a5a
leaq 0xe367(%rip), %rdx      # 0x225a9
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x96b0
incl %ebp
leaq 0xe0(%rsp), %rdi
movl %ebp, %esi
callq 0x8011
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x94bb
leaq 0xe32b(%rip), %rdx      # 0x225a9
leaq 0x120(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x7fce
leaq 0x160(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0x1e8(%rsp), %rdx
callq 0x9691
leaq 0xe2f5(%rip), %rdx      # 0x225a9
leaq 0x80(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x7fce
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x1c8(%rsp), %rdx
callq 0x9691
leaq 0x80(%rsp), %rdi
callq 0x55e8
leaq 0x160(%rsp), %rdi
callq 0x55e8
leaq 0x120(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0x55e8
leaq 0xe0(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
callq 0x55e8
testb %r15b, %r15b
je 0x14371
leaq 0xe271(%rip), %rsi      # 0x225ab
leaq 0x80(%rsp), %rdi
leaq 0x1a8(%rsp), %rdx
callq 0x9dae
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x55c0
leaq 0x80(%rsp), %rdi
callq 0x55e8
pushq $0x10
popq %rax
leaq (%rsp,%rax), %rcx
addq $0x160, %rcx            # imm = 0x160
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x14374
movl %r14d, 0xc(%rsp)
pushq $0x10
popq %rax
leaq (%rsp,%rax), %rcx
addq $0x120, %rcx            # imm = 0x120
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x1439d
xorl %r14d, %r14d
leaq 0x80(%rsp), %r13
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x10(%rsp)
cmpq $0x2, %r14
je 0x1475a
movq %r14, %rax
shlq $0x5, %rax
leaq (%rsp,%rax), %rcx
addq $0x160, %rcx            # imm = 0x160
movq %rcx, 0x70(%rsp)
addq %rsp, %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, 0x68(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0xd8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
cmpq %rbp, %rax
jbe 0x146f0
addq %rbx, %rsi
movq %r13, %rdi
callq 0x1a174
movzbl 0xcc(%rsp), %eax
cmpq %rax, %r14
jne 0x146dc
movq 0x78(%rsp), %rax
movq 0x168(%rax), %rax
movl (%rax,%rbp,4), %r12d
cmpl $-0x8, %r12d
jl 0x146dc
movq 0x60(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x104ac
testq %r14, %r14
je 0x14496
incl 0x1c(%rsp)
addl %eax, 0x18(%rsp)
jmp 0x1449e
incl 0x10(%rsp)
addl %eax, 0x14(%rsp)
cmpl $0x0, 0x2d0(%rsp)
jne 0x146dc
movq 0xa8(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x53f0
cmpb $0x1, 0xc1(%rsp)
leaq 0x20(%rsp), %rdi
jne 0x1450c
movq %r14, %r15
movq %r13, %r14
movq 0xa8(%rsp), %rdx
addq $0x20, %rdx
movq %rdi, %r13
leaq 0xe0c2(%rip), %rsi      # 0x225ab
callq 0x9dae
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x55c0
movq %r13, %rdi
callq 0x55e8
movq %r13, %rdi
movq %r14, %r13
movq %r15, %r14
leaq 0xe097(%rip), %rsi      # 0x225aa
leaq 0xe0(%rsp), %rdx
callq 0x72ee
addl $0x2, %r12d
cmpl $0x3, %r12d
ja 0x145ce
leaq 0xdd53(%rip), %rcx      # 0x22288
movslq (%rcx,%r12,4), %rax
addq %rcx, %rax
leaq 0xe2f8(%rip), %rsi      # 0x2283b
jmpq *%rax
leaq 0xe2f3(%rip), %rsi      # 0x2283f
jmp 0x145c4
leaq 0x20(%rsp), %rdi
leaq 0xe0b1(%rip), %rsi      # 0x2260b
callq 0x55a0
cmpb $0x1, 0xc0(%rsp)
leaq 0xe2ce(%rip), %rsi      # 0x2283c
jne 0x145c4
cmpb $0x1, 0xc1(%rsp)
leaq 0xe2b9(%rip), %rsi      # 0x22838
jne 0x145c4
cmpb $0x0, 0xc2(%rsp)
leaq 0xe2b0(%rip), %rsi      # 0x22840
leaq 0xe2a1(%rip), %rax      # 0x22838
jmp 0x145c0
cmpb $0x1, 0xc1(%rsp)
leaq 0xe293(%rip), %rsi      # 0x2283b
jne 0x145c4
cmpb $0x0, 0xc2(%rsp)
leaq 0xe27a(%rip), %rsi      # 0x22833
leaq 0xe277(%rip), %rax      # 0x22837
cmovneq %rax, %rsi
leaq 0x20(%rsp), %rdi
callq 0x55a0
movl 0x80(%rsp), %esi
incl %esi
leaq 0x208(%rsp), %r12
movq %r12, %rdi
callq 0x8011
leaq 0x228(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
leaq 0xdf4d(%rip), %rdx      # 0x22549
callq 0x7fce
leaq 0x248(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
leaq 0x88(%rsp), %rdx
callq 0x9691
leaq 0x268(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
leaq 0xdf18(%rip), %rdx      # 0x22549
callq 0x7fce
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
leaq 0x40(%rsp), %rdx
callq 0x9691
movq %r15, %rdi
callq 0x55e8
leaq 0x248(%rsp), %rdi
callq 0x55e8
leaq 0x228(%rsp), %rdi
callq 0x55e8
leaq 0x208(%rsp), %rdi
callq 0x55e8
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x55c0
movq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x55c0
movq 0x70(%rsp), %rdi
leaq 0xe19e(%rip), %rsi      # 0x22843
callq 0x55a0
movq 0x68(%rsp), %rdi
leaq 0xe18d(%rip), %rsi      # 0x22843
callq 0x55a0
leaq 0xe0(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0x55e8
movq %r13, %rdi
callq 0x19c16
incq %rbp
addq $0x58, %rbx
jmp 0x1441c
cmpl $0x0, 0x2d0(%rsp)
jne 0x14752
movq 0x70(%rsp), %rbx
movq 0x8(%rbx), %rcx
decq %rcx
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x5320
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5390
movq %r13, %rdi
callq 0x55e8
movq 0x68(%rsp), %rbx
movq 0x8(%rbx), %rcx
decq %rcx
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x5320
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5390
movq %r13, %rdi
callq 0x55e8
incq %r14
jmp 0x143e9
cmpl $0x0, 0x2d0(%rsp)
je 0x1477b
movslq 0xc(%rsp), %r14
movslq 0x2c8(%rsp), %rbx
movq 0x60(%rsp), %r12
jmp 0x14924
leaq 0xde27(%rip), %rsi      # 0x225a9
leaq 0x20(%rsp), %rdi
leaq 0x160(%rsp), %rdx
callq 0x9dae
movq 0x60(%rsp), %r12
movl 0xc(%rsp), %ebx
leaq 0xde05(%rip), %rdx      # 0x225a9
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7fce
leaq 0x180(%rsp), %rdx
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x9691
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x55c0
leaq 0x80(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
callq 0x55e8
leaq 0xdd9f(%rip), %rsi      # 0x225a9
leaq 0x20(%rsp), %rdi
leaq 0x120(%rsp), %rdx
callq 0x9dae
leaq 0xdd86(%rip), %rdx      # 0x225a9
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x7fce
leaq 0x140(%rsp), %rdx
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x9691
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x55c0
leaq 0x80(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
callq 0x55e8
movq 0x78(%rsp), %rax
movl 0x158(%rax), %esi
leaq 0x20(%rsp), %rdi
callq 0x8011
leaq 0xdd0b(%rip), %rsi      # 0x225a9
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x7fed
leaq 0xc7b8(%rip), %rdx      # 0x2106c
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x7fce
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x55c0
leaq 0x80(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
callq 0x55e8
movq 0x178(%r12), %rax
movslq %ebx, %r14
movq (%rax,%r14,8), %rax
movslq 0x2c8(%rsp), %rbx
movq (%rax,%rbx,8), %rdi
leaq 0x100(%rsp), %rsi
callq 0xc896
movq 0x180(%r12), %rax
movq (%rax,%r14,8), %rax
movslq 0x2d0(%rsp), %r15
movq (%rax,%r15,8), %rdi
movq %rbx, %rsi
callq 0x1a1ca
movl 0x10(%rsp), %ecx
addl %ecx, (%rax)
movq 0x188(%r12), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rdi
movq %rbx, %rsi
callq 0x1a1ca
movl 0x1c(%rsp), %ecx
addl %ecx, (%rax)
movq 0x190(%r12), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rdi
movq %rbx, %rsi
callq 0x1a1ca
movl 0x14(%rsp), %ecx
addl %ecx, (%rax)
movq 0x198(%r12), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rdi
movq %rbx, %rsi
callq 0x1a1ca
movl 0x18(%rsp), %ecx
addl %ecx, (%rax)
pushq $0x20
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x55e8
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x149a7
pushq $0x20
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x160, %rdi            # imm = 0x160
callq 0x55e8
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x149c4
leaq 0x100(%rsp), %rdi
callq 0x55e8
leaq 0x1a8(%rsp), %rdi
callq 0x55e8
leaq 0x1c8(%rsp), %rdi
callq 0x55e8
leaq 0x1e8(%rsp), %rdi
callq 0x55e8
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14a3a
jmp 0x14a4c
jmp 0x14a5b
jmp 0x14ba7
jmp 0x14a3a
jmp 0x14a4c
jmp 0x14a5b
jmp 0x14ba7
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x55e8
jmp 0x14a4f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x55e8
jmp 0x14a5e
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x55e8
jmp 0x14baa
jmp 0x14ba7
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x55e8
jmp 0x14be6
movq %rax, %rbx
jmp 0x14be6
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x55e8
jmp 0x14aa4
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x55e8
jmp 0x14ab6
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x55e8
jmp 0x14ac8
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x55e8
jmp 0x14ad7
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
jmp 0x14bee
movq %rax, %rbx
jmp 0x14ae4
movq %rax, %rbx
jmp 0x14c00
movq %rax, %rbx
jmp 0x14c0d
movq %rax, %rbx
jmp 0x14bf3
jmp 0x14ba7
jmp 0x14ba7
jmp 0x14ba7
jmp 0x14b31
jmp 0x14b6a
jmp 0x14b6a
movq %rax, %rbx
jmp 0x14b60
jmp 0x14b6f
movq %rax, %rbx
jmp 0x14b53
movq %rax, %rbx
jmp 0x14b46
movq %rax, %rbx
jmp 0x14b8e
movq %rax, %rbx
leaq 0x268(%rsp), %rdi
callq 0x55e8
leaq 0x248(%rsp), %rdi
callq 0x55e8
leaq 0x228(%rsp), %rdi
callq 0x55e8
leaq 0x208(%rsp), %rdi
jmp 0x14b7f
movq %rax, %rbx
jmp 0x14b84
movq %rax, %rbx
jmp 0x14b98
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x55e8
leaq 0x20(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0x55e8
leaq 0x80(%rsp), %rdi
callq 0x19c16
jmp 0x14baa
movq %rax, %rbx
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x14bae
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x160, %rdi            # imm = 0x160
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x14bcc
leaq 0x100(%rsp), %rdi
callq 0x55e8
leaq 0x1a8(%rsp), %rdi
callq 0x55e8
leaq 0x1c8(%rsp), %rdi
callq 0x55e8
leaq 0x1e8(%rsp), %rdi
callq 0x55e8
movq %rbx, %rdi
callq 0x5540