// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x18(%rbp), %rax
movl 0xc8(%rax), %eax
incl %eax
movl %eax, -0x38(%rbp)
movl 0x20(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x33de0
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x340a0
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl -0x34(%rbp), %r9d
movl 0x10(%rbp), %r10d
movl 0x18(%rbp), %r11d
movl -0x3c(%rbp), %ebx
movq %rsp, %rax
movl %ebx, 0x10(%rax)
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
movl $0xfffffff7, 0x18(%rax) # imm = 0xFFFFFFF7
callq 0x25100
jmp 0x24b5a
movl $0x0, -0xa8(%rbp)
testb $0x1, -0x4c(%rbp)
je 0x24b8d
movl $0x1, -0xa8(%rbp)
jmp 0x24b8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x250e7
leaq -0x90(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x61b0
jmp 0x24ba2
leaq -0x110(%rbp), %rax
movq %rax, %rcx
addq $0x40, %rcx
movq %rcx, -0x160(%rbp)
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x65e0
movq -0x168(%rbp), %rax
movq -0x160(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x158(%rbp)
jne 0x24bbe
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9080
movq %rax, %rsi
leaq -0x110(%rbp), %rdi
callq 0x6070
jmp 0x24c0d
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x6070
jmp 0x24c22
testb $0x1, -0x57(%rbp)
je 0x24c66
testb $0x1, -0x56(%rbp)
jne 0x24c66
leaq -0x70(%rbp), %rdi
movl $0x1, %esi
callq 0x9080
movq %rax, %rsi
leaq -0xf0(%rbp), %rdi
callq 0x6070
jmp 0x24c4d
jmp 0x24c85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x25091
testb $0x1, -0x58(%rbp)
je 0x24c83
leaq -0xf0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6070
jmp 0x24c81
jmp 0x24c83
jmp 0x24c85
movb $0x1, -0x111(%rbp)
movl $0x0, -0x118(%rbp)
movslq -0x118(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6630
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0x24e02
movl $0x0, -0x11c(%rbp)
movq -0x18(%rbp), %rax
movl -0xa8(%rbp), %ecx
movl -0x11c(%rbp), %esi
movl %ecx, %edx
movl %esi, %ecx
leal (%rcx,%rdx,2), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x8(%rax,%rcx,8), %rdi
movl -0x118(%rbp), %eax
movl -0x38(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq 0x30d25(%rip), %rsi     # 0x55a32
callq 0x17c70
movb %al, -0x171(%rbp)
jmp 0x24d1a
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x24d29
jmp 0x24de1
movslq -0x118(%rbp), %rax
movq %rax, -0x180(%rbp)
movslq -0x11c(%rbp), %rax
leaq -0x110(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6630
movq %rax, %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
jb 0x24d6c
movb $0x0, -0x111(%rbp)
jmp 0x24e02
movslq -0x118(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x6810
movq %rax, -0x188(%rbp)
jmp 0x24d88
movq -0x188(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x194(%rbp)
movslq -0x11c(%rbp), %rax
shlq $0x5, %rax
leaq -0x110(%rbp,%rax), %rdi
movslq -0x118(%rbp), %rsi
callq 0x6810
movq %rax, -0x190(%rbp)
jmp 0x24dc0
movl -0x194(%rbp), %eax
movq -0x190(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x24ddd
movb $0x0, -0x111(%rbp)
jmp 0x24e02
jmp 0x24ddf
jmp 0x24de1
testb $0x1, -0x111(%rbp)
jne 0x24dec
jmp 0x24e02
jmp 0x24dee
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x24c96
testb $0x1, -0x111(%rbp)
je 0x24e4e
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl -0x34(%rbp), %r9d
movl 0x10(%rbp), %r10d
movl 0x18(%rbp), %r11d
movl -0x3c(%rbp), %ebx
movq %rsp, %rax
movl %ebx, 0x10(%rax)
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
movl $0x0, 0x18(%rax)
callq 0x25100
jmp 0x24e4c
jmp 0x24e4e
testb $0x1, -0x57(%rbp)
je 0x2508f
leaq -0x140(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x61b0
jmp 0x24e6d
leaq -0xf0(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x6070
jmp 0x24e82
leaq -0xf0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x6070
jmp 0x24e97
movb $0x1, -0x111(%rbp)
movl $0x0, -0x144(%rbp)
movslq -0x144(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6630
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x25037
movl $0x0, -0x148(%rbp)
movq -0x18(%rbp), %rax
movl -0xa8(%rbp), %ecx
movl -0x148(%rbp), %esi
movl %ecx, %edx
movl %esi, %ecx
leal (%rcx,%rdx,2), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x8(%rax,%rcx,8), %rdi
movl -0x144(%rbp), %eax
movl -0x38(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq 0x30b13(%rip), %rsi     # 0x55a32
callq 0x17c70
movb %al, -0x1a1(%rbp)
jmp 0x24f2c
movb -0x1a1(%rbp), %al
testb $0x1, %al
jne 0x24f3b
jmp 0x25016
movslq -0x144(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movslq -0x148(%rbp), %rax
leaq -0x110(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6630
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
cmpq %rcx, %rax
jb 0x24fa1
movb $0x0, -0x111(%rbp)
jmp 0x25037
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x6828
jmp 0x25091
movslq -0x144(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x6810
movq %rax, -0x1b8(%rbp)
jmp 0x24fbd
movq -0x1b8(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x1c4(%rbp)
movslq -0x148(%rbp), %rax
shlq $0x5, %rax
leaq -0x110(%rbp,%rax), %rdi
movslq -0x144(%rbp), %rsi
callq 0x6810
movq %rax, -0x1c0(%rbp)
jmp 0x24ff5
movl -0x1c4(%rbp), %eax
movq -0x1c0(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x25012
movb $0x0, -0x111(%rbp)
jmp 0x25037
jmp 0x25014
jmp 0x25016
testb $0x1, -0x111(%rbp)
jne 0x25021
jmp 0x25037
jmp 0x25023
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x24ea8
testb $0x1, -0x111(%rbp)
je 0x25083
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl -0x34(%rbp), %r9d
movl 0x10(%rbp), %r10d
movl 0x18(%rbp), %r11d
movl -0x3c(%rbp), %ebx
movq %rsp, %rax
movl %ebx, 0x10(%rax)
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
movl $0x1, 0x18(%rax)
callq 0x233b0
jmp 0x25081
jmp 0x25083
leaq -0x140(%rbp), %rdi
callq 0x6828
ud2
leaq -0x110(%rbp), %rax
movq %rax, -0x1d8(%rbp)
addq $0x40, %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x6828
movq -0x1d8(%rbp), %rcx
movq -0x1e0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1d0(%rbp)
jne 0x250aa
leaq -0xc8(%rbp), %rdi
callq 0x6828
leaq -0x98(%rbp), %rdi
callq 0x32c60
movq -0xa0(%rbp), %rdi
callq 0x6750
nop