// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movl %r9d, 0x4(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x18(%rsp)
movslq 0x160(%rsp), %rbp
movslq 0xc8(%rsi), %rax
movq %rax, 0x10(%rsp)
movq (%rdx), %r14
imulq $0x58, %rbp, %r15
leaq (%r14,%r15), %rbx
addq $0x28, %rbx
movl -0x28(%rbx), %eax
leaq 0x60(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
movq -0x20(%rbx), %rsi
movq -0x18(%rbx), %rdx
addq %rsi, %rdx
callq 0x112ce
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x289ec
movl 0x158(%rsp), %r10d
movl 0x150(%rsp), %r8d
addq %r15, %r14
movq 0x50(%r14), %rax
movq %rax, 0xa8(%rsp)
movups 0x40(%r14), %xmm0
movups %xmm0, 0x98(%rsp)
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movl 0x4(%rsp), %r14d
movl %r14d, %r9d
pushq $-0x9
pushq %rbp
pushq %r10
pushq %r8
callq 0x19b38
addq $0x20, %rsp
movq %r13, 0x8(%rsp)
movq %rbp, 0x30(%rsp)
movzbl 0xa4(%rsp), %eax
movq %rax, 0x28(%rsp)
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x112ce
incq 0x10(%rsp)
movl $0x10, %eax
leaq (%rsp,%rax), %rcx
addq $0xb0, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x197b1
movq 0x80(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %r13
leaq 0x80(%rsp), %rbp
callq 0x51c0
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x51c0
cmpb $0x1, 0x99(%rsp)
jne 0x19820
cmpb $0x0, 0x9a(%rsp)
je 0x1982c
cmpb $0x1, 0x98(%rsp)
je 0x19838
jmp 0x19848
movq 0x80(%rsp), %rbx
addq $0x20, %rbx
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
callq 0x51c0
movb $0x1, %al
cmpq $0x0, 0x40(%rsp)
je 0x198f2
movq 0x28(%rsp), %rax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r13
addq $0x8, %r13
movq 0x10(%rsp), %r14
shlq $0x5, %r14
movb $0x1, %r15b
xorl %ebp, %ebp
leaq 0x181d2(%rip), %rbx     # 0x31a56
movq (%r13), %rdi
addq %r14, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x198bf
xorl %eax, %eax
movl $0x0, %ecx
cmpq %rbp, 0xb8(%rsp)
jbe 0x198c5
movq 0x38(%rsp), %rax
movb (%rax,%rbp), %dl
movq 0xb0(%rsp), %rsi
xorl %eax, %eax
cmpb (%rsi,%rbp), %dl
jne 0x198c5
movl %r15d, %eax
movl %r15d, %ecx
testb $0x1, %cl
je 0x198db
incq %rbp
addq $0x20, %r14
movl %eax, %r15d
cmpq %rbp, 0x40(%rsp)
ja 0x19884
leaq 0x70(%rsp), %r13
leaq 0x80(%rsp), %rbp
leaq 0x48(%rsp), %r15
movl 0x4(%rsp), %r14d
testb $0x1, %al
je 0x1992a
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movl %r14d, %r9d
pushq $0x0
pushq 0x38(%rsp)
movl 0x168(%rsp), %eax
pushq %rax
movl 0x168(%rsp), %eax
pushq %rax
callq 0x19b38
addq $0x20, %rsp
leaq 0x108(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf8(%rsp), %rdi
callq 0x112ce
leaq 0xb0(%rsp), %rdi
leaq 0xd0(%rsp), %rbx
movq %rbx, %rsi
callq 0x51c0
leaq 0xf8(%rsp), %rsi
movq %rbx, %rdi
callq 0x51c0
cmpq $0x0, 0x40(%rsp)
je 0x19a2a
movq 0x28(%rsp), %rax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r13
addq $0x8, %r13
movslq 0x10(%rsp), %r14
shlq $0x5, %r14
movb $0x1, %r15b
xorl %ebp, %ebp
leaq 0x1809e(%rip), %rbx     # 0x31a56
movq (%r13), %rdi
addq %r14, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x199f3
xorl %eax, %eax
movl $0x0, %ecx
cmpq %rbp, 0xb8(%rsp)
jbe 0x199f9
movq 0x38(%rsp), %rax
movb (%rax,%rbp), %dl
movq 0xb0(%rsp), %rsi
xorl %eax, %eax
cmpb (%rsi,%rbp), %dl
jne 0x199f9
movl %r15d, %eax
movl %r15d, %ecx
testb $0x1, %cl
je 0x19a0f
incq %rbp
addq $0x20, %r14
movl %eax, %r15d
cmpq %rbp, 0x40(%rsp)
ja 0x199b8
testb $0x1, %al
leaq 0x70(%rsp), %r13
leaq 0x80(%rsp), %rbp
leaq 0x48(%rsp), %r15
movl 0x4(%rsp), %r14d
je 0x19a5e
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movl %r14d, %r9d
pushq $0x1
pushq 0x38(%rsp)
movl 0x168(%rsp), %eax
pushq %rax
movl 0x168(%rsp), %eax
pushq %rax
callq 0x1854a
addq $0x20, %rsp
leaq 0xf8(%rsp), %rdi
callq 0x5648
jmp 0x19a9f
movq %rax, %r14
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x19a9a
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x19a9a
movq %rax, %r14
movq %r15, %r12
jmp 0x19aa5
movq %r15, %r12
movq %rax, %r14
movq $-0x40, %rbx
leaq 0xe0(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x19ac8
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %rbx
jne 0x19ab4
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x19afd
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x19afd
jmp 0x19aed
movq %rax, %r14
leaq 0x70(%rsp), %r13
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
callq 0xe7ca
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
jne 0x19b23
jmp 0x19b30
movq %rax, %r14
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x19b30
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5340
movq %r14, %rdi
callq 0x55c0