// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::VariantMakeDecisionNoGenotype(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::VariantMakeDecisionNoGenotype(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
    AppendChangedSpNoGenotype(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;
    }

    bool choice_applicable = true;
    for(int k = 0; k < ref.length(); k++){
    // for each ref char
        int y = 0;
        {
            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));
        AppendChangedSpNoGenotype(sp,
                        variant_list,
                        sequence_path_list,
                        reference_sequence,
                        score_unit,
                        match_mode,
                        score_scheme,
                        var_index,
                        0);
    }

    // if variants is 0/1, then it does not make sense to apply reference, as it is the same as not_use
    // if variants is 0/1 but contains multi alts, then should try another alt
    // if variants is 1/2 , then should try another alt
    // if variants is 1/1 or 2/2 then should not try another alt
    // but here we do not care the phasing
    // so as long as variant has multi_alts, use another alt

    if(var.multi_alts){

        //if it contains multi alts, then there is another choice, check if it is applicable

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

        choice_applicable = true;
        for(int k = 0; k < ref.length(); k++){
        // for each ref char
            int y = 0;
            {
                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){
            AppendChangedSp(sp,
                    variant_list,
                    sequence_path_list,
                    reference_sequence,
                    score_unit,
                    match_mode,
                    score_scheme,
                    var_index,
                    1);
        }
    }   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %r9d, %r14d
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
movslq 0x150(%rsp), %rbp
movl 0xc8(%rsi), %eax
movl %eax, 0x4(%rsp)
imulq $0x58, %rbp, %rsi
addq (%rdx), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x1a174
movq %r15, 0x18(%rsp)
movq %r15, %rdi
movq %r13, 0x8(%rsp)
movq %r13, %rsi
movq %r12, 0x20(%rsp)
movq %r12, %rdx
movq %rbx, 0x28(%rsp)
movq %rbx, %rcx
movl %r14d, %ebx
movl %r14d, %r9d
pushq $-0x9
pushq %rbp
movl 0x158(%rsp), %eax
pushq %rax
movl 0x158(%rsp), %eax
pushq %rax
callq 0x1276a
addq $0x20, %rsp
movq %rbp, 0x10(%rsp)
leaq 0xb8(%rsp), %rsi
movzbl 0x44(%rsi), %r14d
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
callq 0x53f0
movl 0x4(%rsp), %r15d
incl %r15d
pushq $0x10
popq %rax
leaq (%rsp,%rax), %rcx
addq $0x50, %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x12532
movq 0xd8(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x51d0
leaq 0x70(%rsp), %r12
leaq 0x50(%rsp), %rsi
movq %r12, %rdi
callq 0x51d0
cmpb $0x1, 0xf1(%rsp)
jne 0x12588
cmpb $0x0, 0xf2(%rsp)
je 0x12594
cmpb $0x1, 0xf0(%rsp)
je 0x125a0
jmp 0x125ab
movq 0xd8(%rsp), %rbp
addq $0x20, %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x51d0
movl %ebx, 0x4(%rsp)
imulq $0x30, %r14, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x8, %r14
movslq %r15d, %rbx
movq %rbx, %r13
shlq $0x5, %r13
xorl %r15d, %r15d
leaq 0x1046a(%rip), %rbp     # 0x22a3e
cmpq %r15, 0x38(%rsp)
jbe 0x12611
movq (%r14), %rdi
addq %r13, %rdi
movq %rbp, %rsi
callq 0xca73
testb %al, %al
je 0x12608
cmpq %r15, 0x58(%rsp)
jbe 0x12649
movq 0x30(%rsp), %rax
movb (%rax,%r15), %al
movq 0x50(%rsp), %rcx
cmpb (%rcx,%r15), %al
jne 0x12649
incq %r15
addq $0x20, %r13
jmp 0x125d4
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl 0x4(%rsp), %r9d
pushq $0x0
pushq 0x18(%rsp)
movl 0x158(%rsp), %eax
pushq %rax
movl 0x158(%rsp), %eax
pushq %rax
callq 0x1276a
addq $0x20, %rsp
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x53f0
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x51d0
movl 0x4(%rsp), %r15d
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x51d0
shlq $0x5, %rbx
xorl %r13d, %r13d
leaq 0x103b3(%rip), %rbp     # 0x22a3e
cmpq %r13, 0x38(%rsp)
jbe 0x126c8
movq (%r14), %rdi
addq %rbx, %rdi
movq %rbp, %rsi
callq 0xca73
testb %al, %al
je 0x126bf
cmpq %r13, 0x58(%rsp)
jbe 0x126fe
movq 0x30(%rsp), %rax
movb (%rax,%r13), %al
movq 0x50(%rsp), %rcx
cmpb (%rcx,%r13), %al
jne 0x126fe
incq %r13
addq $0x20, %rbx
jmp 0x1268b
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl %r15d, %r9d
pushq $0x1
pushq 0x18(%rsp)
movl 0x158(%rsp), %eax
pushq %rax
movl 0x158(%rsp), %eax
pushq %rax
callq 0x11930
addq $0x20, %rsp
leaq 0x90(%rsp), %rdi
callq 0x55e8
jmp 0x1270f
jmp 0x12725
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x55e8
jmp 0x12728
jmp 0x12725
jmp 0x12725
movq %rax, %rbx
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x50, %rdi
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x1272c
leaq 0x30(%rsp), %rdi
callq 0x55e8
jmp 0x12754
jmp 0x12751
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x19c16
movq %rbx, %rdi
callq 0x5540
nop