// File: /workspace/github_cpp_makefile_star2_O2/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, %r15d
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movslq 0x180(%rsp), %r13
movl 0xc8(%rsi), %eax
movl %eax, 0x18(%rsp)
imulq $0x58, %r13, %rsi
addq (%rdx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x1a174
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq %r14, 0x10(%rsp)
movq %r14, %rsi
movq %r12, 0x28(%rsp)
movq %r12, %rdx
movq %rbp, %rcx
movl %r15d, %ebx
movl %r15d, %r9d
pushq $-0x9
pushq %r13
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x11930
addq $0x20, %rsp
movq %rbp, 0x38(%rsp)
movq %r13, 0x40(%rsp)
leaq 0xc8(%rsp), %rsi
movzbl 0x44(%rsi), %r14d
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
callq 0x53f0
movl 0x18(%rsp), %r12d
incl %r12d
pushq $0x10
popq %rax
leaq (%rsp,%rax), %rcx
addq $0x80, %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x11fbb
movq 0xe8(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x51d0
leaq 0xa0(%rsp), %r15
leaq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x51d0
cmpb $0x1, 0x101(%rsp)
jne 0x1201d
cmpb $0x0, 0x102(%rsp)
je 0x12029
cmpb $0x1, 0x100(%rsp)
je 0x12035
jmp 0x12040
movq 0xe8(%rsp), %rbp
addq $0x20, %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x51d0
movl %ebx, 0xc(%rsp)
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x93ce
movl %eax, %ebp
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x48(%rsp)
leal (%r14,%r14), %ecx
movq %rcx, 0x78(%rsp)
movslq %r12d, %rcx
imulq $0x30, %r14, %rdx
movq %rdx, 0x50(%rsp)
leaq (%rax,%rdx), %r12
xorl %r15d, %r15d
movq %rcx, 0x30(%rsp)
shlq $0x5, %rcx
movq %rcx, 0x18(%rsp)
cmpq %r15, 0x60(%rsp)
jbe 0x120f9
movq %r15, %r13
shlq $0x5, %r13
leaq 0x88(%rsp), %r14
pushq $-0x30
popq %rbx
testq %rbx, %rbx
je 0x120f4
cmpq $-0x18, %rbx
sete %al
testb %al, %bpl
jne 0x120ea
movq 0x38(%r12,%rbx), %rdi
addq %r13, %rdi
addq 0x18(%rsp), %rdi
leaq 0x10975(%rip), %rsi     # 0x22a3e
callq 0xca73
testb %al, %al
je 0x120ea
cmpq %r15, (%r14)
jbe 0x12131
movq 0x58(%rsp), %rax
movb (%rax,%r15), %al
movq -0x8(%r14), %rcx
cmpb (%rcx,%r15), %al
jne 0x12131
addq $0x18, %rbx
addq $0x20, %r14
jmp 0x120a4
incq %r15
jmp 0x1208b
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $0x0
pushq 0x48(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x11930
addq $0x20, %rsp
cmpb $0x1, 0x100(%rsp)
jne 0x12288
leaq 0x118(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x53f0
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x51d0
leaq 0x118(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x51d0
leaq 0x80(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x93ce
xorl %ebp, %ebp
testb %al, %al
movabsq $0x17ffffffe8, %r12     # imm = 0x17FFFFFFE8
cmovneq %rbp, %r12
movq 0x10(%rsp), %rax
movq 0x50(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x50(%rsp)
movq 0x30(%rsp), %r13
shlq $0x5, %r13
cmpq %rbp, 0x60(%rsp)
jbe 0x12229
movq %rbp, %rbx
shlq $0x5, %rbx
leaq 0x88(%rsp), %r14
xorl %r15d, %r15d
cmpq $0x30, %r15
je 0x12224
cmpq %r15, %r12
je 0x1221a
movq 0x50(%rsp), %rax
movq (%rax,%r15), %rdi
addq %rbx, %rdi
addq %r13, %rdi
leaq 0x10843(%rip), %rsi     # 0x22a3e
callq 0xca73
testb %al, %al
je 0x1221a
cmpq %rbp, (%r14)
jbe 0x1227b
movq 0x58(%rsp), %rax
movb (%rax,%rbp), %al
movq -0x8(%r14), %rcx
cmpb (%rcx,%rbp), %al
jne 0x1227b
addq $0x18, %r15
addq $0x20, %r14
jmp 0x121da
incq %rbp
jmp 0x121c1
cmpb $0x1, 0x101(%rsp)
jne 0x1223d
cmpb $0x1, 0x102(%rsp)
jne 0x12241
pushq $-0x1
jmp 0x12243
pushq $0x1
popq %rax
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq %rax
pushq 0x48(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x11930
addq $0x20, %rsp
leaq 0x118(%rsp), %rdi
callq 0x55e8
movq 0xe8(%rsp), %rsi
addq $0x20, %rsi
leaq 0x80(%rsp), %rdi
callq 0x51d0
leaq 0x58(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x51d0
imulq $0x18, 0x78(%rsp), %r14
addq 0x48(%rsp), %r14
xorl %r15d, %r15d
leaq 0x10776(%rip), %rbx     # 0x22a3e
movl 0x178(%rsp), %r12d
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rbp
cmpq %r15, 0x60(%rsp)
jbe 0x12321
movq (%r14), %rdi
addq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xca73
testb %al, %al
je 0x12316
cmpq %r15, 0x88(%rsp)
jbe 0x1234f
movq 0x58(%rsp), %rax
movb (%rax,%r15), %al
movq 0x80(%rsp), %rcx
cmpb (%rcx,%r15), %al
jne 0x1234f
incq %r15
addq $0x20, 0x18(%rsp)
jmp 0x122da
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movl 0xc(%rsp), %r9d
pushq $0x1
pushq %r13
pushq %r12
movl 0x188(%rsp), %eax
pushq %rax
callq 0x11930
addq $0x20, %rsp
leaq 0x80(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x51d0
movq 0xe8(%rsp), %rsi
addq $0x20, %rsi
leaq 0xa0(%rsp), %rdi
callq 0x51d0
movq 0x78(%rsp), %rax
orb $0x1, %al
movzbl %al, %eax
imulq $0x18, %rax, %rax
addq %rax, 0x48(%rsp)
shlq $0x5, 0x30(%rsp)
xorl %r14d, %r14d
leaq 0x106a1(%rip), %rbx     # 0x22a3e
movl 0x170(%rsp), %r15d
cmpq %r14, 0x60(%rsp)
jbe 0x123f1
movq 0x48(%rsp), %rax
movq (%rax), %rdi
addq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xca73
testb %al, %al
je 0x123e6
cmpq %r14, 0xa8(%rsp)
jbe 0x123f1
movq 0x58(%rsp), %rax
movb (%rax,%r14), %al
movq 0xa0(%rsp), %rcx
cmpb (%rcx,%r14), %al
jne 0x123f1
incq %r14
addq $0x20, 0x30(%rsp)
jmp 0x123a5
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movl 0xc(%rsp), %r9d
pushq $-0x2
pushq %r13
pushq %r12
pushq %r15
callq 0x11930
addq $0x20, %rsp
jmp 0x12439
jmp 0x12421
jmp 0x12439
jmp 0x12439
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x55e8
jmp 0x1243c
jmp 0x12439
jmp 0x12439
jmp 0x12439
movq %rax, %rbx
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x80, %rdi
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x12440
leaq 0x58(%rsp), %rdi
callq 0x55e8
jmp 0x1246b
jmp 0x12468
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x19c16
movq %rbx, %rdi
callq 0x5540