// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::PathMakeDecisionNoGenotype(SequencePath&, std::vector<DiploidVariant, std::allocator<DiploidVariant>>&, std::multimap<int, int, std::less<int>, std::allocator<std::pair<int const, int>>>**, std::__cxx11::list<SequencePath, std::allocator<SequencePath>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, int, int)
bool WholeGenome::PathMakeDecisionNoGenotype(SequencePath& sp,
                                 vector<DiploidVariant> & variant_list,
                                 multimap<int, int> * choices_by_pos[],
                                 list<SequencePath> & sequence_path_list,
                                 const string & reference_sequence,
                                 int score_unit,
                                 int match_mode,
                                 int score_scheme)
{
    int pos = sp.current_genome_pos+1;
    vector<pair<int, int>> candidate_choices[2];
    for(int i = 0; i < 2; i++){
        // because if it's (-1,-1), it will do nothing, so it's ok to have this one...
        candidate_choices[i].push_back(pair<int, int>(-1, -1));
        // to maintain existance
        // in this position, make choice of not use any variants, no matter if there is variant

        pair<multimap<int, int>::iterator, multimap<int, int>::iterator> var_range;
        var_range = choices_by_pos[i]->equal_range(pos);

        for(auto it = var_range.first; it != var_range.second; ++it){
            int var_index = (*it).second;
            DiploidVariant var = variant_list[var_index];
            // 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){ //here do not have to change anything
                alts[1] = var.alts[1];
            }

            // not just purely consider if a vqriant can be applied, but if a choice
            bool choice_applicable = true;
            for(int k = 0; k < ref.length(); k++){
            // for each ref char
                int y = 0;
                // 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()){
                        choice_applicable = false;
                        break;
                    }else{
                        if(ref[k] != alts[y][k]){
                            choice_applicable = false;
                            break;
                        }
                    }
                }
            }

            if(choice_applicable){
                candidate_choices[i].push_back(pair<int, int>(var_index, 0));
            }

            if(var.multi_alts){ // here do not have to change anything

                //if heterozygous, 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
                    //for(int y = 0; y < 2; y++)
                    int y = 0;
                    // 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){
                    candidate_choices[i].push_back(pair<int, int>(var_index, 1));
                }
            }
        }
    }

    //dout << candidate_choices[0].size() << "," << candidate_choices[1].size() << endl;

    for(int i = 0; i < candidate_choices[0].size(); i++){
        for(int j = 0; j < candidate_choices[1].size(); j++){
            // iterate all choices
            SequencePath path = sp;
            pair<int, int> var_choice[2];
            var_choice[0] = candidate_choices[0][i];
            var_choice[1] = candidate_choices[1][j];
            for(int x = 0; x < 2; x++){
                // iterate truth and predict
                int var_index = var_choice[x].first;
                if(var_index != -1){
                    DiploidVariant var = variant_list[var_index];
                    // if(var.flag != x){
                    //     dout << "Error" << endl;
                    // }
                    string ref = var.ref;
                    string alts[2];
                    int c = var_choice[x].second;
                    alts[0] = var.alts[c];
                    path.score += CalculateScore(var,
                                                 c,
                                                 score_unit,
                                                 match_mode,
                                                 score_scheme);

                    ToUpper(ref);
                    ToUpper(alts[0]);
                    int y = 0;

                    int k = 0;
                    for(; k < ref.length()-1; k++){
                        if(k < alts[y].length()){
                            if(ref[k] != alts[y][k]){
                                path.string_sequences[x*2+y][pos+k] = alts[y].substr(k,1);
                            }
                            // else change nothing
                        }else{
                            path.string_sequences[x*2+y][pos+k] = "";
                        }
                    }
                    // hence k == ref.length()-1, the last position
                    if(k < alts[y].length()){
                        string alt_part = alts[y].substr(k, alts[y].length()-k);
                        if(alt_part.length() > 1){
                            if(alt_part[0] == ref[k]){
                                if(path.string_sequences[x*2+y][pos+k] == "."){
                                    path.string_sequences[x*2+y][pos+k] = alt_part;
                                }else{
                                    path.string_sequences[x*2+y][pos+k] += alt_part.substr(1, alt_part.size() - 1);
                                }
                            }else{
                                path.string_sequences[x*2+y][pos+k] = alt_part;
                            }
                        }else{
                            if(ref[k] != alts[y][k]){
                                path.string_sequences[x*2+y][pos+k] = alt_part;
                            }
                        }
                    }else{
                        path.string_sequences[x*2+y][pos+k] = "";
                    }

                }
                path.choice_made[x][pos] = var_choice[x];
            }
            sequence_path_list.push_back(path);
        }
    }

    //expected number of inserted paths are 2,3,4,6,x...
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %r8, 0xf0(%rsp)
movq %rcx, 0xe0(%rsp)
movq %rdx, 0x48(%rsp)
movq %rdi, %r13
movl 0xc8(%rsi), %eax
incl %eax
leaq 0xc(%rsp), %rcx
movl %eax, (%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq %rsi, 0xf8(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0xd8(%rsp)
xorl %r15d, %r15d
leaq 0x120(%rsp), %r14
leaq 0x11879(%rip), %rbx     # 0x22a3e
movq %rdi, 0x40(%rsp)
cmpq $0x2, %r15
je 0x11450
imulq $0x18, %r15, %rax
leaq (%rsp,%rax), %rdi
addq $0xa0, %rdi
orq $-0x1, 0x198(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0x198(%rsp), %rsi
callq 0x1f3c0
movq 0xe0(%rsp), %rax
movq (%rax,%r15,8), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1f2e8
movq %rdx, 0x18(%rsp)
leaq 0x140(%rsp), %r13
movq %rax, %rbp
movq %r15, 0xe8(%rsp)
imulq $0x30, %r15, %r12
addq 0xd8(%rsp), %r12
cmpq 0x18(%rsp), %rbp
je 0x1143b
movslq 0x24(%rbp), %r15
imulq $0x58, %r15, %rsi
movq 0x48(%rsp), %rax
addq (%rax), %rsi
leaq 0x198(%rsp), %rdi
callq 0x1a174
leaq 0x50(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x53f0
pushq $0x10
popq %rax
leaq (%rsp,%rax), %rcx
addq $0x120, %rcx            # imm = 0x120
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x11275
movq 0x1c0(%rsp), %rsi
movq %r14, %rdi
callq 0x51d0
movq %r13, %rdi
movq %r14, %rsi
callq 0x51d0
cmpb $0x0, 0x1d9(%rsp)
je 0x112cf
movq 0x1c0(%rsp), %rsi
addq $0x20, %rsi
movq %r13, %rdi
callq 0x51d0
xorl %r13d, %r13d
cmpq %r13, 0x58(%rsp)
jbe 0x1131d
movl 0xc(%rsp), %eax
addl %r13d, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r12), %rdi
movq %rbx, %rsi
callq 0xca73
testb %al, %al
je 0x11318
cmpq %r13, 0x128(%rsp)
jbe 0x11336
movq 0x50(%rsp), %rax
movb (%rax,%r13), %al
movq 0x120(%rsp), %rcx
cmpb (%rcx,%r13), %al
jne 0x11336
incq %r13
jmp 0x112d2
movl %r15d, 0x20(%rsp)
andl $0x0, 0x24(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1f3c0
cmpb $0x0, 0x1d9(%rsp)
je 0x113ee
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x53f0
leaq 0x140(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x51d0
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x51d0
xorl %r13d, %r13d
cmpq %r13, 0x58(%rsp)
jbe 0x113bf
movl 0xc(%rsp), %eax
addl %r13d, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r12), %rdi
movq %rbx, %rsi
callq 0xca73
testb %al, %al
je 0x113ba
cmpq %r13, 0x128(%rsp)
jbe 0x113e4
movq 0x50(%rsp), %rax
movb (%rax,%r13), %al
movq 0x120(%rsp), %rcx
cmpb (%rcx,%r13), %al
jne 0x113e4
incq %r13
jmp 0x11374
movl %r15d, 0x100(%rsp)
movl $0x1, 0x104(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x1f3c0
leaq 0x20(%rsp), %rdi
callq 0x55e8
pushq $0x20
popq %r15
leaq 0x140(%rsp), %r13
leaq (%rsp,%r15), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x55e8
addq $-0x20, %r15
cmpq $-0x20, %r15
jne 0x113fa
leaq 0x50(%rsp), %rdi
callq 0x55e8
leaq 0x198(%rsp), %rdi
callq 0x19c16
movq %rbp, %rdi
callq 0x5240
movq %rax, %rbp
jmp 0x11238
movq 0xe8(%rsp), %r15
incq %r15
movq 0x40(%rsp), %r13
jmp 0x111ca
xorl %r15d, %r15d
leaq 0x198(%rsp), %r12
leaq 0x120(%rsp), %rbp
leaq 0x100(%rsp), %r14
leaq 0x11138(%rip), %rbx     # 0x225aa
movq 0xa8(%rsp), %rax
subq 0xa0(%rsp), %rax
sarq $0x3, %rax
cmpq %r15, %rax
jbe 0x117f2
xorl %ecx, %ecx
movq %r15, 0x10(%rsp)
movq 0xc0(%rsp), %rax
subq 0xb8(%rsp), %rax
sarq $0x3, %rax
movq %rcx, 0x18(%rsp)
cmpq %rcx, %rax
jbe 0x117ea
movq %r12, %rdi
movq 0xf8(%rsp), %rsi
callq 0x1a3e8
movq 0xa0(%rsp), %rax
movq 0xb8(%rsp), %rcx
movq 0x18(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movsd (%rax,%r15,8), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movaps %xmm1, 0x90(%rsp)
xorl %r12d, %r12d
cmpq $0x2, %r12
je 0x117b5
movslq 0x90(%rsp,%r12,8), %rax
cmpq $-0x1, %rax
je 0x11789
imulq $0x58, %rax, %rsi
movq 0x48(%rsp), %rax
addq (%rax), %rsi
movq %rbp, %rdi
callq 0x1a174
leaq 0x20(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x53f0
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 0x1153b
movslq 0x94(%rsp,%r12,8), %r15
movq %r15, %rsi
shlq $0x5, %rsi
addq 0x148(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x51d0
movq %r13, %rdi
movq %rbp, %rsi
movl %r15d, %edx
movl 0x350(%rsp), %ecx
movl 0x358(%rsp), %r8d
movl 0x360(%rsp), %r9d
callq 0x1106a
addl %eax, 0x2f0(%rsp)
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x19ac2
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
callq 0x19ac2
imulq $0x30, %r12, %r13
leaq 0x1a0(%rsp), %rax
addq %rax, %r13
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x28(%rsp), %rax
decq %rax
cmpq %r15, %rax
jbe 0x11654
cmpq %r15, 0x58(%rsp)
jbe 0x11633
movq 0x20(%rsp), %rax
movb (%rax,%r15), %al
movq 0x50(%rsp), %rcx
cmpb (%rcx,%r15), %al
je 0x1164d
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
pushq $0x1
popq %rcx
callq 0x5320
movl 0xc(%rsp), %eax
addl %r15d, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
movq %r14, %rsi
callq 0x5390
movq %r14, %rdi
callq 0x55e8
jmp 0x1164d
movl 0xc(%rsp), %eax
addl %r15d, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
movq %rbx, %rsi
callq 0x55b0
incq %r15
decl %ebp
jmp 0x115d4
movq 0x58(%rsp), %rcx
subq %r15, %rcx
jbe 0x116ff
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x5320
cmpq $0x2, 0x108(%rsp)
jb 0x1171a
movq 0x100(%rsp), %rax
movb (%rax), %al
movq 0x20(%rsp), %rcx
movl 0xc(%rsp), %edx
subl %ebp, %edx
movslq %edx, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
cmpb (%rcx,%r15), %al
jne 0x1173f
leaq 0x1138c(%rip), %rsi     # 0x22a3e
callq 0xa912
testb %al, %al
jne 0x1172e
movq 0x108(%rsp), %rcx
decq %rcx
leaq 0x178(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x5320
movl 0xc(%rsp), %eax
subl %ebp, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
movq %r15, %rsi
callq 0x55c0
movq %r15, %rdi
callq 0x55e8
jmp 0x11747
movl 0xc(%rsp), %eax
subl %ebp, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
movq %rbx, %rsi
callq 0x55b0
jmp 0x1174f
movq 0x20(%rsp), %rax
movb (%rax,%r15), %al
movq 0x50(%rsp), %rcx
cmpb (%rcx,%r15), %al
je 0x11747
movl 0xc(%rsp), %eax
subl %ebp, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
movq %r14, %rsi
callq 0x51d0
movq %r14, %rdi
callq 0x55e8
pushq $0x20
popq %r15
leaq (%rsp,%r15), %rdi
addq $0x50, %rdi
callq 0x55e8
addq $-0x20, %r15
cmpq $-0x20, %r15
jne 0x11753
leaq 0x20(%rsp), %rdi
callq 0x55e8
leaq 0x120(%rsp), %rbp
movq %rbp, %rdi
callq 0x19c16
movq 0x40(%rsp), %r13
imulq $0x30, %r12, %rdi
leaq 0x200(%rsp), %rax
addq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x1a556
movq 0x90(%rsp,%r12,8), %rcx
movq %rcx, (%rax)
incq %r12
jmp 0x114f6
movq 0xf0(%rsp), %rdi
leaq 0x198(%rsp), %r12
movq %r12, %rsi
callq 0x1a5a4
movq 0x18(%rsp), %r15
movq %r12, %rdi
callq 0x1a5b0
incq %r15
movq %r15, %rcx
movq 0x10(%rsp), %r15
jmp 0x11496
incq %r15
jmp 0x11472
pushq $0x18
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0xa0, %rdi
callq 0x1f38c
addq $-0x18, %rbx
cmpq $-0x18, %rbx
jne 0x117f5
movb $0x1, %al
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1184a
jmp 0x1184a
jmp 0x1186f
jmp 0x11885
jmp 0x11885
jmp 0x118bf
jmp 0x1184a
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x55e8
jmp 0x1185c
jmp 0x11859
jmp 0x1186f
movq %rax, %rbx
jmp 0x1190a
movq %rax, %rbx
jmp 0x118b0
jmp 0x11885
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x55e8
jmp 0x118cb
jmp 0x118c8
jmp 0x118c8
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x55e8
jmp 0x11888
jmp 0x118bf
movq %rax, %rbx
jmp 0x118f0
movq %rax, %rbx
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x1188c
leaq 0x50(%rsp), %rdi
callq 0x55e8
leaq 0x198(%rsp), %rdi
callq 0x19c16
jmp 0x1190a
movq %rax, %rbx
jmp 0x118fd
jmp 0x118c8
jmp 0x118c8
movq %rax, %rbx
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x50, %rdi
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x118cf
leaq 0x20(%rsp), %rdi
callq 0x55e8
leaq 0x120(%rsp), %rdi
callq 0x19c16
leaq 0x198(%rsp), %rdi
callq 0x1a5b0
pushq $0x18
popq %r14
leaq (%rsp,%r14), %rdi
addq $0xa0, %rdi
callq 0x1f38c
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x1190e
movq %rbx, %rdi
callq 0x5540