// File: /workspace/github_cpp_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
movl %r9d, 0xc(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, 0x18(%rsp)
movslq 0x170(%rsp), %r12
movslq 0xc8(%rsi), %rax
movq %rax, 0xb8(%rsp)
movq (%rdx), %r14
imulq $0x58, %r12, %r13
leaq (%r14,%r13), %rbx
addq $0x28, %rbx
movl -0x28(%rbx), %eax
leaq 0x68(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
movq -0x20(%rbx), %rsi
movq -0x18(%rbx), %rdx
addq %rsi, %rdx
callq 0x1123c
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x28582
movl 0x168(%rsp), %r10d
movl 0x160(%rsp), %r8d
addq %r13, %r14
movq 0x50(%r14), %rax
movq %rax, 0xb0(%rsp)
movups 0x40(%r14), %xmm0
movups %xmm0, 0xa0(%rsp)
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $-0x9
pushq %r12
pushq %r10
pushq %r8
callq 0x197ae
addq $0x20, %rsp
movq %rbp, 0x10(%rsp)
movzbl 0xac(%rsp), %eax
movq %rax, 0x58(%rsp)
leaq 0x38(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x1123c
movq %r15, 0x48(%rsp)
movq %r12, 0x50(%rsp)
movq 0xb8(%rsp), %r15
incq %r15
movl $0x10, %eax
leaq (%rsp,%rax), %rcx
addq $0xe0, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x19493
movq 0x88(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
leaq 0x78(%rsp), %r12
callq 0x51c0
leaq 0x100(%rsp), %r14
leaq 0xe0(%rsp), %rsi
movq %r14, %rdi
callq 0x51c0
cmpb $0x1, 0xa1(%rsp)
jne 0x194fd
cmpb $0x0, 0xa2(%rsp)
je 0x19509
cmpb $0x1, 0xa0(%rsp)
je 0x19515
jmp 0x19520
movq 0x88(%rsp), %rbx
addq $0x20, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51c0
movq %r14, %r12
cmpq $0x0, 0x30(%rsp)
je 0x19596
movq 0x58(%rsp), %rax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x8, %r14
movq %r15, %r13
shlq $0x5, %r13
xorl %ebp, %ebp
leaq 0x18532(%rip), %rbx     # 0x31a86
movq (%r14), %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x19588
movq 0xe8(%rsp), %rdx
cmpq %rbp, %rdx
jbe 0x195d6
movq 0x28(%rsp), %rax
movb (%rax,%rbp), %al
movq 0xe0(%rsp), %rcx
cmpb (%rcx,%rbp), %al
jne 0x195d6
incq %rbp
addq $0x20, %r13
cmpq %rbp, 0x30(%rsp)
ja 0x19554
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $0x0
pushq 0x58(%rsp)
movl 0x178(%rsp), %eax
pushq %rax
movl 0x178(%rsp), %eax
pushq %rax
callq 0x197ae
addq $0x20, %rsp
movq 0xe8(%rsp), %rdx
leaq 0xd0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0xe0(%rsp), %rsi
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x1123c
leaq 0xe0(%rsp), %rdi
movq %r12, %rbx
movq %r12, %rsi
callq 0x51c0
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0x51c0
cmpq $0x0, 0x30(%rsp)
je 0x1968d
movq 0x58(%rsp), %rax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x8, %r14
movslq %r15d, %r13
shlq $0x5, %r13
xorl %ebp, %ebp
leaq 0x18438(%rip), %rbx     # 0x31a86
movq (%r14), %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x1967f
cmpq %rbp, 0xe8(%rsp)
jbe 0x196c5
movq 0x28(%rsp), %rax
movb (%rax,%rbp), %al
movq 0xe0(%rsp), %rcx
cmpb (%rcx,%rbp), %al
jne 0x196c5
incq %rbp
addq $0x20, %r13
cmpq %rbp, 0x30(%rsp)
ja 0x1964e
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $0x1
pushq 0x58(%rsp)
movl 0x178(%rsp), %eax
pushq %rax
movl 0x178(%rsp), %eax
pushq %rax
callq 0x182bc
addq $0x20, %rsp
leaq 0xc0(%rsp), %rdi
callq 0x5648
movq %rax, %r14
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x78(%rsp), %r12
je 0x1970b
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x1970b
jmp 0x19703
movq %rax, %r14
leaq 0x78(%rsp), %r12
leaq 0x38(%rsp), %rbp
jmp 0x19715
movq %rax, %r14
movq $-0x40, %rbx
leaq 0x110(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x19738
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %rbx
jne 0x19724
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x19759
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x88(%rsp), %rdi
jmp 0x19775
jmp 0x19765
movq %rax, %r14
leaq 0x88(%rsp), %rdi
leaq 0x78(%rsp), %r12
callq 0xe71c
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
jne 0x19798
jmp 0x197a5
movq %rax, %r14
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x197a5
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5340
movq %r14, %rdi
callq 0x55c0
nop