// File: /workspace/github_cpp_makefile_star2_O3/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, 0xc(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, 0x40(%rsp)
movslq 0x180(%rsp), %r13
movslq 0xc8(%rsi), %rax
movq %rax, 0x18(%rsp)
movq (%rdx), %r14
imulq $0x58, %r13, %r15
leaq (%r14,%r15), %rbx
addq $0x28, %rbx
movl -0x28(%rbx), %eax
leaq 0xc0(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0xd0(%rsp), %rax
movq %rax, -0x10(%rax)
movq -0x20(%rbx), %rsi
movq -0x18(%rbx), %rdx
addq %rsi, %rdx
callq 0x1123c
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
callq 0x28582
movl 0x178(%rsp), %r10d
movl 0x170(%rsp), %r8d
addq %r15, %r14
movq 0x50(%r14), %rax
movq %rax, 0x108(%rsp)
movups 0x40(%r14), %xmm0
movups %xmm0, 0xf8(%rsp)
movq 0x40(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $-0x9
pushq %r13
pushq %r10
pushq %r8
callq 0x182bc
addq $0x20, %rsp
movq %r13, %rbx
movq %r12, %r14
movq %rbp, %r12
movzbl 0x104(%rsp), %r13d
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rbp
movq %rbp, %rdi
callq 0x1123c
movq %r13, 0x38(%rsp)
movq 0x18(%rsp), %r13
incq %r13
movl $0x10, %eax
leaq (%rsp,%rax), %rcx
addq $0x70, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x18d96
movq 0xe0(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x51c0
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x51c0
cmpb $0x1, 0xf9(%rsp)
jne 0x18def
cmpb $0x0, 0xfa(%rsp)
je 0x18dfb
cmpb $0x1, 0xf8(%rsp)
je 0x18e07
jmp 0x18e17
movq 0xe0(%rsp), %rbp
addq $0x20, %rbp
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
callq 0x51c0
movq %r13, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0xb0(%rsp)
movq 0x98(%rsp), %rdx
movq 0x50(%rsp), %rbx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq %rbx, %rdx
jne 0x18e77
testq %rdx, %rdx
je 0x18e71
movq 0x48(%rsp), %rsi
movq 0x90(%rsp), %rdi
callq 0x5350
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x18e77
movl $0x1, %r15d
testq %rbx, %rbx
jne 0x1914e
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq $0x0
pushq 0x38(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x182bc
addq $0x20, %rsp
cmpb $0x1, 0xf8(%rsp)
jne 0x18fc9
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
leaq 0x110(%rsp), %rdi
callq 0x1123c
leaq 0x70(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x51c0
leaq 0x110(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x51c0
movq 0x78(%rsp), %rdx
movq 0x50(%rsp), %rbx
cmpq %rbx, %rdx
jne 0x18f46
testq %rdx, %rdx
je 0x18f3a
movq 0x48(%rsp), %rsi
movq 0x70(%rsp), %rdi
callq 0x5350
testl %eax, %eax
jne 0x18f46
movq $0x0, 0xb0(%rsp)
testq %rbx, %rbx
jne 0x19203
cmpb $0x1, 0xf9(%rsp)
jne 0x18f68
movl $0x1, %eax
cmpb $0x1, 0xfa(%rsp)
jne 0x18f6d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %r9d
pushq %rax
pushq 0x38(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x182bc
addq $0x20, %rsp
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x18fc9
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0xe0(%rsp), %rsi
addq $0x20, %rsi
leaq 0x70(%rsp), %rdi
callq 0x51c0
leaq 0x48(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x51c0
cmpq $0x0, 0x50(%rsp)
movl 0xc(%rsp), %ebp
movq 0x40(%rsp), %r13
je 0x19069
movq 0x38(%rsp), %rax
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x8, %r14
movslq 0x18(%rsp), %r15
shlq $0x5, %r15
xorl %r12d, %r12d
leaq 0x18a58(%rip), %rbx     # 0x31a86
movq (%r14), %rdi
addq %r15, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x1905b
cmpq %r12, 0x78(%rsp)
jbe 0x1909d
movq 0x48(%rsp), %rax
movb (%rax,%r12), %al
movq 0x70(%rsp), %rcx
cmpb (%rcx,%r12), %al
jne 0x1909d
incq %r12
addq $0x20, %r15
cmpq %r12, 0x50(%rsp)
ja 0x1902e
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl %ebp, %r9d
pushq $0x1
pushq 0x38(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x182bc
addq $0x20, %rsp
leaq 0x70(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x51c0
movq 0xe0(%rsp), %rsi
addq $0x20, %rsi
leaq 0x90(%rsp), %rdi
callq 0x51c0
cmpq $0x0, 0x50(%rsp)
je 0x1911a
movq 0x38(%rsp), %rax
leaq 0x1(,%rax,2), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
addq $0x8, %r14
movslq 0x18(%rsp), %r15
shlq $0x5, %r15
xorl %r12d, %r12d
leaq 0x18988(%rip), %rbx     # 0x31a86
movq (%r14), %rdi
addq %r15, %rdi
movq %rbx, %rsi
callq 0x50e0
incq %r12
addq $0x20, %r15
cmpq %r12, 0x50(%rsp)
ja 0x190fe
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl %ebp, %r9d
pushq $-0x2
pushq 0x38(%rsp)
movl 0x188(%rsp), %eax
pushq %rax
movl 0x188(%rsp), %eax
pushq %rax
callq 0x182bc
addq $0x20, %rsp
movq 0x10(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x68(%rsp)
movq 0x38(%rsp), %rax
addl %eax, %eax
movq %rax, 0x130(%rsp)
xorl %r14d, %r14d
movq 0x18(%rsp), %r13
shlq $0x5, %r13
movb $0x1, %bpl
movq %r14, %r12
shlq $0x5, %r12
leaq 0x70(%rsp), %rbx
xorl %eax, %eax
cmpq %r15, %rax
je 0x191d8
orq 0x130(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0x68(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
addq %r12, %rdi
addq %r13, %rdi
leaq 0x188d7(%rip), %rsi     # 0x31a86
callq 0x50e0
testl %eax, %eax
je 0x191d8
cmpq %r14, 0x8(%rbx)
jbe 0x18eb8
movq 0x48(%rsp), %rax
movb (%rax,%r14), %al
movq (%rbx), %rcx
cmpb (%rcx,%r14), %al
jne 0x18eb8
movl $0x1, %eax
leaq 0x90(%rsp), %rbx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x19188
incq %r14
cmpq %r14, 0x50(%rsp)
ja 0x19177
jmp 0x18e80
movq 0x10(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x68(%rsp)
movq 0x38(%rsp), %rax
leal (%rax,%rax), %r12d
movslq 0x18(%rsp), %rbx
xorl %ebp, %ebp
shlq $0x5, %rbx
movb $0x1, %r14b
movq %rbp, %r13
shlq $0x5, %r13
leaq 0x70(%rsp), %r15
xorl %eax, %eax
cmpq %rax, 0xb0(%rsp)
je 0x19284
orq %r12, %rax
leaq (%rax,%rax,2), %rax
movq 0x68(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
addq %r13, %rdi
addq %rbx, %rdi
leaq 0x18829(%rip), %rsi     # 0x31a86
callq 0x50e0
testl %eax, %eax
je 0x19284
cmpq %rbp, 0x8(%r15)
jbe 0x18fa4
movq 0x48(%rsp), %rax
movb (%rax,%rbp), %al
movq (%r15), %rcx
cmpb (%rcx,%rbp), %al
jne 0x18fa4
movl $0x1, %eax
leaq 0x90(%rsp), %r15
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x19236
incq %rbp
cmpq %rbp, 0x50(%rsp)
ja 0x19225
jmp 0x18f4f
jmp 0x192e0
movq %rax, %rbx
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x192e3
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x192e3
jmp 0x192e0
jmp 0x192e0
movq %rax, %rbx
movq $-0x40, %r14
leaq 0xa0(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x19306
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %r14
jne 0x192f2
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x19333
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x19333
jmp 0x19330
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0xe71c
jmp 0x19345
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x1936a
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5340
movq %rbx, %rdi
callq 0x55c0