// File: /workspace/github_cpp_makefile_star2_O1/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::VariantMakeDecision(SequencePath&, std::vector<DiploidVariant, std::allocator<DiploidVariant>>&, std::__cxx11::list<SequencePath, std::allocator<SequencePath>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, int, int, int)
bool WholeGenome::VariantMakeDecision(SequencePath& sp,
                         vector<DiploidVariant> & variant_list,
                         list<SequencePath> & sequence_path_list,
                         const string & reference_sequence,
                         int score_unit,
                         int match_mode,
                         int score_scheme,
                         int variant_index)
{

    int pos = sp.current_genome_pos+1;

    int var_index = variant_index;
    DiploidVariant var = variant_list[var_index];

    // also this variant may not be used
    AppendChangedSp(sp,
                variant_list,
                sequence_path_list,
                reference_sequence,
                score_unit,
                match_mode,
                score_scheme,
                var_index,
                NOT_USE);

    int i = 0;
    if(var.flag) i = 1;
    //PrintVariant(var);

    // check if current var influence
    string ref = var.ref; //even we do not know the offset, we know ref start from pos of reference_sequence
    string alts[2];
    alts[0] = var.alts[0];
    alts[1] = alts[0];
    if(var.multi_alts && !var.zero_one_var){
        alts[1] = var.alts[1];
    }else if(var.heterozygous){
        alts[1] = ref;
    }

    // not just purely consider if a vqriant can be applied, but if a choice
    int skiped_y = -1;
    if(alts[1] == ref) skiped_y = 1;

    bool choice_applicable = true;
    for(int k = 0; k < ref.length(); k++){
    // for each ref char
        for(int y = 0; y < 2; y++){
            // for each strain
            if(y == skiped_y) continue;
            if(sp.string_sequences[i*2+y][k+pos] != "."){
                // decision in this area has already been made
                if(k >= alts[y].length()){
                    choice_applicable = false;
                    break;
                }else{
                    if(ref[k] != alts[y][k]){
                        choice_applicable = false;
                        break;
                    }
                }
            }
        }
        if(!choice_applicable) break;
    }

    if(choice_applicable){
        //candidate_choices[i].push_back(pair<int, int>(var_index, 0));
        AppendChangedSp(sp,
                        variant_list,
                        sequence_path_list,
                        reference_sequence,
                        score_unit,
                        match_mode,
                        score_scheme,
                        var_index,
                        0);
    }

    if(var.heterozygous){

        //if heterozygous, then there is another choice, check if it is applicable

        string temp = alts[0];
        alts[0] = alts[1];
        alts[1] = temp;

        skiped_y = -1;
        if(alts[0] == ref) skiped_y = 0;

        choice_applicable = true;
        for(int k = 0; k < ref.length(); k++){
        // for each ref char
            for(int y = 0; y < 2; y++){
                // for each strain
                if(skiped_y == y) continue;
                if(sp.string_sequences[i*2+y][k+pos] != "."){
                    // decision in this area has already been made
                    if(k >= alts[y].length()){
                        // should be a deletion
                        choice_applicable = false;
                        break;
                    }else{
                        // should be equal at current position
                        // can be an insertion, as long as current position is the same
                        if(ref[k] != alts[y][k]){
                            choice_applicable = false;
                            break;
                        }
                    }
                }
            }
            if(!choice_applicable) break;
        }

        if(choice_applicable){
            if(var.multi_alts && !var.zero_one_var){
                //candidate_choices[i].push_back(pair<int, int>(var_index, 1));
                AppendChangedSp(sp,
                        variant_list,
                        sequence_path_list,
                        reference_sequence,
                        score_unit,
                        match_mode,
                        score_scheme,
                        var_index,
                        1);
            }else{
                //candidate_choices[i].push_back(pair<int, int>(var_index, -1));
                AppendChangedSp(sp,
                        variant_list,
                        sequence_path_list,
                        reference_sequence,
                        score_unit,
                        match_mode,
                        score_scheme,
                        var_index,
                        -1);
            }
        }
    }

    if(var.multi_alts && var.zero_one_var){
        // here contains another two combinations  alt1/ref and ref/alt1
        alts[0] = var.alts[1];
        alts[1] = ref;

        choice_applicable = true;
        int y = 0;
        for(int k = 0; k < ref.length(); k++){
        // for each ref char
            {
                // for each strain
                if(sp.string_sequences[i*2+y][k+pos] != "."){
                    // decision in this area has already been made
                    if(k >= alts[y].length()){
                        // should be a deletion
                        choice_applicable = false;
                        break;
                    }else{
                        // should be equal at current position
                        // can be an insertion, as long as current position is the same
                        if(ref[k] != alts[y][k]){
                            choice_applicable = false;
                            break;
                        }
                    }
                }
            }
            if(!choice_applicable) break;
        }

        if(choice_applicable){
            //candidate_choices[i].push_back(pair<int, int>(var_index, 1));
            AppendChangedSp(sp,
                variant_list,
                sequence_path_list,
                reference_sequence,
                score_unit,
                match_mode,
                score_scheme,
                var_index,
                1);
        }


        alts[0] = ref;
        alts[1] = var.alts[1];

        choice_applicable = true;
        y = 1;
        for(int k = 0; k < ref.length(); k++){
        // for each ref char
            {
                // for each strain
                if(sp.string_sequences[i*2+y][k+pos] != "."){
                    // decision in this area has already been made
                    if(k >= alts[y].length()){
                        // should be a deletion
                        choice_applicable = false;
                        break;
                    }else{
                        // should be equal at current position
                        // can be an insertion, as long as current position is the same
                        if(ref[k] != alts[y][k]){
                            choice_applicable = false;
                            break;
                        }
                    }
                }
            }
            if(!choice_applicable) break;
        }

        if(choice_applicable){
            //candidate_choices[i].push_back(pair<int, int>(var_index, -2));
            AppendChangedSp(sp,
                variant_list,
                sequence_path_list,
                reference_sequence,
                score_unit,
                match_mode,
                score_scheme,
                var_index,
                -2);
        }
    }
        
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r9d, 0xc(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, 0x30(%rsp)
movslq 0x180(%rsp), %rbp
movslq 0xc8(%rsi), %rax
movq %rax, 0x28(%rsp)
movq (%rdx), %r14
imulq $0x58, %rbp, %r15
leaq (%r14,%r15), %rbx
addq $0x28, %rbx
movl -0x28(%rbx), %eax
leaq 0xc8(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
movq -0x20(%rbx), %rsi
movq -0x18(%rbx), %rdx
addq %rsi, %rdx
callq 0x112ce
leaq 0xe8(%rsp), %rdi
movq %rbx, %rsi
callq 0x289ec
movl 0x178(%rsp), %r10d
movl 0x170(%rsp), %r8d
addq %r15, %r14
movq 0x50(%r14), %rax
movq %rax, 0x110(%rsp)
movups 0x40(%r14), %xmm0
movups %xmm0, 0x100(%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $-0x9
pushq %rbp
pushq %r10
pushq %r8
callq 0x1854a
addq $0x20, %rsp
movq %rbp, %r15
movq %r12, 0x10(%rsp)
movq %r13, 0x70(%rsp)
movzbl 0x10c(%rsp), %r12d
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x112ce
movq %r12, 0x68(%rsp)
movq 0x28(%rsp), %r12
incq %r12
movl $0x10, %eax
leaq (%rsp,%rax), %rcx
addq $0x80, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x19041
movq 0xe8(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x51c0
leaq 0xa0(%rsp), %r13
leaq 0x80(%rsp), %rsi
movq %r13, %rdi
callq 0x51c0
cmpb $0x1, 0x101(%rsp)
jne 0x190a6
cmpb $0x0, 0x102(%rsp)
je 0x190b2
cmpb $0x1, 0x100(%rsp)
je 0x190be
jmp 0x190c9
movq 0xe8(%rsp), %rbx
addq $0x20, %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x51c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x40(%rsp)
movq 0xa8(%rsp), %rdx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq 0x50(%rsp), %rdx
jne 0x19116
movl $0x1, %r13d
testq %rdx, %rdx
je 0x19116
movq 0x48(%rsp), %rsi
movq 0xa0(%rsp), %rdi
callq 0x5350
testl %eax, %eax
movl $0x1, %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovneq %rax, %r13
cmpq $0x0, 0x50(%rsp)
movq %r12, %rbp
movq 0x68(%rsp), %r12
je 0x191ed
movq %r15, 0x20(%rsp)
shlq $0x5, %r13
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x10(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x78(%rsp)
movb $0x1, %al
xorl %r15d, %r15d
movq %rbp, 0x28(%rsp)
movq %rbp, %r14
shlq $0x5, %r14
movl %eax, 0x1c(%rsp)
movq %r15, %rbp
shlq $0x5, %rbp
movq 0x78(%rsp), %r12
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0x191b1
movq (%r12), %rdi
addq %rbp, %rdi
addq %r14, %rdi
leaq 0x188cf(%rip), %rsi     # 0x31a56
callq 0x50e0
testl %eax, %eax
je 0x191b1
cmpq %r15, 0x88(%rsp,%rbx)
jbe 0x191c5
movq 0x48(%rsp), %rax
movb (%rax,%r15), %al
movq 0x80(%rsp,%rbx), %rcx
cmpb (%rcx,%r15), %al
jne 0x191c5
addq $0x20, %rbx
addq $0x18, %r12
cmpq $0x20, %rbx
je 0x19171
movl 0x1c(%rsp), %eax
jmp 0x191c7
xorl %eax, %eax
testb $0x1, %al
je 0x191d5
incq %r15
cmpq %r15, 0x50(%rsp)
ja 0x1915f
testb $0x1, %al
leaq 0x58(%rsp), %r14
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
movq 0x68(%rsp), %r12
je 0x19223
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $0x0
pushq %r15
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x1854a
addq $0x20, %rsp
cmpb $0x1, 0x100(%rsp)
jne 0x1940f
leaq 0x128(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0x118(%rsp), %rdi
callq 0x112ce
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rbx
movq %rbx, %rsi
callq 0x51c0
leaq 0x118(%rsp), %rsi
movq %rbx, %rdi
callq 0x51c0
movq 0x88(%rsp), %rdx
cmpq 0x50(%rsp), %rdx
jne 0x192c8
testq %rdx, %rdx
jne 0x192a4
movq $0x0, 0x40(%rsp)
jmp 0x192c8
movq 0x48(%rsp), %rsi
movq 0x80(%rsp), %rdi
callq 0x5350
xorl %ecx, %ecx
testl %eax, %eax
movq 0x40(%rsp), %rax
cmoveq %rcx, %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x50(%rsp)
je 0x1939f
movq %r15, 0x20(%rsp)
movq %rbp, 0x28(%rsp)
movslq %ebp, %r13
shlq $0x5, 0x40(%rsp)
leaq (%r12,%r12,2), %rax
shll $0x4, %eax
movq 0x10(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x78(%rsp)
movb $0x1, %al
xorl %r15d, %r15d
shlq $0x5, %r13
leaq 0x18747(%rip), %rbx     # 0x31a56
movl %eax, 0x1c(%rsp)
movq %r15, %r14
shlq $0x5, %r14
movq 0x78(%rsp), %rbp
xorl %r12d, %r12d
cmpq %r12, 0x40(%rsp)
je 0x19360
movq (%rbp), %rdi
addq %r14, %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x19360
cmpq %r15, 0x88(%rsp,%r12)
jbe 0x19374
movq 0x48(%rsp), %rax
movb (%rax,%r15), %al
movq 0x80(%rsp,%r12), %rcx
cmpb (%rcx,%r15), %al
jne 0x19374
addq $0x20, %r12
addq $0x18, %rbp
cmpq $0x20, %r12
je 0x19322
movl 0x1c(%rsp), %eax
jmp 0x19376
xorl %eax, %eax
testb $0x1, %al
je 0x19384
incq %r15
cmpq %r15, 0x50(%rsp)
ja 0x1930f
testb $0x1, %al
leaq 0x58(%rsp), %r14
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbp
leaq 0x128(%rsp), %r13
je 0x193f2
cmpb $0x1, 0x101(%rsp)
jne 0x193b8
movl $0x1, %eax
cmpb $0x1, 0x102(%rsp)
jne 0x193bd
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq %rax
pushq %r15
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x1854a
addq $0x20, %rsp
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0x1940f
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0xe8(%rsp), %rsi
addq $0x20, %rsi
leaq 0x80(%rsp), %rdi
callq 0x51c0
leaq 0x48(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x51c0
movq %r15, 0x20(%rsp)
movq %r14, %r13
cmpq $0x0, 0x50(%rsp)
je 0x194b5
movq 0x68(%rsp), %rax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x8, %r14
movslq %ebp, %r15
shlq $0x5, %r15
xorl %r12d, %r12d
leaq 0x185e2(%rip), %rbx     # 0x31a56
movq (%r14), %rdi
addq %r15, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x194a7
cmpq %r12, 0x88(%rsp)
jbe 0x194ed
movq 0x48(%rsp), %rax
movb (%rax,%r12), %al
movq 0x80(%rsp), %rcx
cmpb (%rcx,%r12), %al
jne 0x194ed
incq %r12
addq $0x20, %r15
cmpq %r12, 0x50(%rsp)
ja 0x19474
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $0x1
pushq 0x28(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x1854a
addq $0x20, %rsp
leaq 0x80(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x51c0
movq 0xe8(%rsp), %rsi
addq $0x20, %rsi
leaq 0xa0(%rsp), %rdi
callq 0x51c0
cmpq $0x0, 0x50(%rsp)
je 0x19590
movq 0x68(%rsp), %rax
leaq 0x1(,%rax,2), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
addq $0x8, %r14
movslq %ebp, %r15
shlq $0x5, %r15
xorl %r12d, %r12d
leaq 0x18507(%rip), %rbx     # 0x31a56
movq (%r14), %rdi
addq %r15, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x19582
cmpq %r12, 0xa8(%rsp)
jbe 0x19590
movq 0x48(%rsp), %rax
movb (%rax,%r12), %al
movq 0xa0(%rsp), %rcx
cmpb (%rcx,%r12), %al
jne 0x19590
incq %r12
addq $0x20, %r15
cmpq %r12, 0x50(%rsp)
ja 0x1954f
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $-0x2
pushq 0x28(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x1854a
addq $0x20, %rsp
jmp 0x195f9
movq %r13, %rcx
movq %r14, %r13
movq %rax, %r14
movq 0x118(%rsp), %rdi
cmpq %rcx, %rdi
je 0x195fc
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x195fc
jmp 0x195f6
jmp 0x195f6
movq %r14, %r13
movq %rax, %r14
movq $-0x40, %rbx
leaq 0xb0(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x1961f
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %rbx
jne 0x1960b
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x19647
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x19647
jmp 0x19644
movq %rax, %r14
leaq 0xd8(%rsp), %rbx
leaq 0xe8(%rsp), %rdi
callq 0xe7ca
movq 0xc8(%rsp), %rdi
cmpq %rbx, %rdi
jne 0x19683
jmp 0x19693
movq %rax, %r14
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x19693
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5340
movq %r14, %rdi
callq 0x55c0
nop