// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::AppendChangedSp(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, int)
bool WholeGenome::AppendChangedSp(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 c)
{
    int pos = sp.current_genome_pos+1;

    SequencePath path = sp;

    if(c == NOT_USE){
        path.choice_vector[variant_index] = c;
        sequence_path_list.push_back(path);
        return true;
    }

    pair<int, int> var_choice[2];
    int x = 0;
    int var_index = variant_index;
    DiploidVariant var = variant_list[var_index];
    if(var.flag) x = 1;
    string ref = var.ref;
    string alts[2];

    if(c == -1){
        alts[0] = ref;
        alts[1] = var.alts[0];
    }else if(c == -2){
        alts[0] = ref;
        alts[1] = var.alts[1];
    }else if(c >= 0){
        // c == 0 or 1
        alts[0] = var.alts[c];
        alts[1] = alts[0];

        if(var.multi_alts && !var.zero_one_var){
            // choose 1 or 0
            alts[1] = var.alts[1- c];
        }else{
            // c is 0, choose 0 or -1
            if(var.heterozygous) alts[1] = ref;
        }
    }else{
        dout << "Unrecognized choice" << endl;
    }
    path.score += CalculateScore(var,
                                 c,
                                 score_unit,
                                 match_mode,
                                 score_scheme);
    ToUpper(ref);
    ToUpper(alts[0]);
    ToUpper(alts[1]);
    for(int y = 0; y < 2; y++){
        // iterate two alts
        string alt = alts[y];
        if(alt == ref) continue;
        vector<string> alt_vector;
        GenerateAltVector(ref, alt, alt_vector);

        int k = 0;
        for(; k < ref.length()-1; k++){

            if(alt_vector[k].size() != 1 || ref[k] != alt_vector[k][0]){
                path.string_sequences[x*2+y][pos+k] = alt_vector[k];
            }
            // else changes nothing

        }
        // hence k == ref.length()-1, the last position
        assert(k == ref.length()-1);
        string alt_part = alt_vector[k];
        if(alt_part.length() > 0){
            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] != alt_vector[k][0]){
                    path.string_sequences[x*2+y][pos+k] = alt_part;
                }
            }
        }else{
            path.string_sequences[x*2+y][pos+k] = "";
        }
    }

    // choice made
    path.choice_vector[variant_index] = c;
    //dout << "after decision at variant " << variant_index << endl;
    //PrintPath(path);
    sequence_path_list.push_back(path);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movl %r9d, %ebx
movq %rcx, %r15
movq %rdx, %r14
movq %rdi, (%rsp)
movslq 0x360(%rsp), %r12
movl 0xc8(%rsi), %r13d
leaq 0x198(%rsp), %rdi
callq 0x1a3e8
cmpl $-0x9, 0x368(%rsp)
jne 0x11998
leaq 0x198(%rsp), %rsi
movq 0x168(%rsi), %rax
movl $0xfffffff7, (%rax,%r12,4) # imm = 0xFFFFFFF7
movq %r15, %rdi
callq 0x1a5a4
jmp 0x11d69
movq %r15, 0x38(%rsp)
movq %r12, 0x30(%rsp)
imulq $0x58, %r12, %rsi
addq (%r14), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x1a174
leaq 0xc8(%rsp), %rsi
movb 0x44(%rsi), %bpl
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x53f0
movl 0x368(%rsp), %edx
movl 0x350(%rsp), %r14d
incl %r13d
pushq $0x10
popq %rax
leaq (%rsp,%rax), %rcx
addq $0x80, %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x119e4
cmpl $-0x2, %edx
je 0x11a2f
cmpl $-0x1, %edx
jne 0x11d8a
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x51d0
movq 0xe8(%rsp), %r15
jmp 0x11a4d
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x51d0
movq 0xe8(%rsp), %r15
addq $0x20, %r15
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x51d0
leaq 0xc0(%rsp), %rsi
movq (%rsp), %rdi
movl 0x368(%rsp), %edx
movl %ebx, %ecx
movl %r14d, %r8d
movl 0x358(%rsp), %r9d
callq 0x1106a
addl %eax, 0x2f0(%rsp)
leaq 0x10(%rsp), %rsi
movq (%rsp), %rdi
callq 0x19ac2
leaq 0x80(%rsp), %rsi
movq (%rsp), %rdi
callq 0x19ac2
leaq 0xa0(%rsp), %rsi
movq (%rsp), %rdi
callq 0x19ac2
movslq %r13d, %r14
movzbl %bpl, %eax
addl %eax, %eax
movq %rax, 0x58(%rsp)
movl %r14d, %eax
movq %rax, 0x8(%rsp)
shlq $0x5, %r14
xorl %r12d, %r12d
leaq 0x118(%rsp), %r13
leaq 0x10(%rsp), %rbp
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r15
cmpq $0x2, %r12
je 0x11d13
movq %r12, %rax
shlq $0x5, %rax
leaq (%rsp,%rax), %rsi
addq $0x80, %rsi
movq %r13, %rdi
callq 0x53f0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x93ce
testb %al, %al
jne 0x11cc5
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x53f0
leaq 0x158(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x53f0
movq (%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
leaq 0x40(%rsp), %rcx
callq 0xed80
movq %r15, %rdi
callq 0x55e8
movq %rbx, %rdi
callq 0x55e8
movq %r12, %rax
orq 0x58(%rsp), %rax
imulq $0x18, %rax, %r13
leaq 0x1a0(%rsp), %rax
addq %rax, %r13
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
decq %rax
cmpq %rbx, %rax
jbe 0x11bdf
movq 0x40(%rsp), %rax
leaq (%rax,%rbp), %rsi
cmpq $0x1, 0x8(%rax,%rbp)
jne 0x11bc7
movq 0x10(%rsp), %rax
movb (%rax,%rbx), %al
movq (%rsi), %rcx
cmpb (%rcx), %al
je 0x11bd6
movq (%r13), %rdi
addq %r14, %rdi
addq %rbp, %rdi
callq 0x51d0
incq %rbx
addq $0x20, %rbp
jmp 0x11b9a
jne 0x11e26
movq 0x40(%rsp), %rsi
addq %rbp, %rsi
leaq 0x60(%rsp), %rdi
callq 0x53f0
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x11c2a
cmpq $0x1, %rax
jne 0x11c4c
movq 0x10(%rsp), %rax
movb (%rax,%rbx), %al
movq 0x40(%rsp), %rcx
movq (%rcx,%rbp), %rcx
cmpb (%rcx), %al
leaq 0x10(%rsp), %rbp
je 0x11c9f
addl 0x8(%rsp), %ebx
movslq %ebx, %rbp
jmp 0x11c85
addl 0x8(%rsp), %ebx
movslq %ebx, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
leaq 0x1096a(%rip), %rsi     # 0x225aa
callq 0x55b0
leaq 0x10(%rsp), %rbp
jmp 0x11c9f
movq 0x60(%rsp), %rax
movb (%rax), %al
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
addl %ebx, %edx
movslq %edx, %rbp
movq %rbp, %r15
shlq $0x5, %r15
movq (%r13), %rdi
addq %r15, %rdi
cmpb (%rcx,%rbx), %al
jne 0x11c90
leaq 0x10dc2(%rip), %rsi     # 0x22a3e
callq 0xa912
testb %al, %al
je 0x11cd5
shlq $0x5, %rbp
addq (%r13), %rbp
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
callq 0x51d0
leaq 0x10(%rsp), %rbp
leaq 0x60(%rsp), %rdi
callq 0x55e8
leaq 0x40(%rsp), %rdi
callq 0xadcc
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r15
leaq 0x118(%rsp), %r13
movq %r13, %rdi
callq 0x55e8
incq %r12
jmp 0x11af0
movq 0x68(%rsp), %rcx
decq %rcx
leaq 0x138(%rsp), %rbx
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x5320
addq (%r13), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x55c0
leaq 0x10(%rsp), %rbp
movq %rbx, %rdi
callq 0x55e8
jmp 0x11c9f
leaq 0x198(%rsp), %rsi
movq 0x168(%rsi), %rax
movl 0x368(%rsp), %ecx
movl %ecx, (%rax,%r15,4)
movq %rbx, %rdi
callq 0x1a5a4
pushq $0x20
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x80, %rdi
callq 0x55e8
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x11d38
leaq 0x10(%rsp), %rdi
callq 0x55e8
leaq 0xc0(%rsp), %rdi
callq 0x19c16
leaq 0x198(%rsp), %rdi
callq 0x1a5b0
movb $0x1, %al
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %edx, %edx
js 0x11de8
movl %edx, %esi
shlq $0x5, %rsi
addq 0xe8(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x51d0
leaq 0xa0(%rsp), %r12
leaq 0x80(%rsp), %rsi
movq %r12, %rdi
callq 0x51d0
cmpb $0x1, 0x101(%rsp)
jne 0x11dd5
cmpb $0x0, 0x102(%rsp)
je 0x11e08
cmpb $0x1, 0x100(%rsp)
je 0x11a55
jmp 0x11a60
movq 0x1e1d1(%rip), %rdi     # 0x2ffc0
leaq 0x107ef(%rip), %rsi     # 0x225e5
callq 0x52f0
movq %rax, %rdi
callq 0x5190
jmp 0x11a60
pushq $0x1
popq %rax
subl 0x368(%rsp), %eax
movslq %eax, %r15
shlq $0x5, %r15
addq 0xe8(%rsp), %r15
jmp 0x11a55
leaq 0x107cc(%rip), %rdi     # 0x225f9
leaq 0x107d9(%rip), %rsi     # 0x2260d
leaq 0x107e2(%rip), %rcx     # 0x2261d
movl $0x562, %edx            # imm = 0x562
callq 0x5230
movq %rax, %rbx
jmp 0x11ee6
jmp 0x11e4f
movq %rax, %rbx
jmp 0x11ef3
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x55e8
jmp 0x11e70
jmp 0x11e6d
jmp 0x11e9f
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x11e98
jmp 0x11ea4
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x55e8
jmp 0x11e90
jmp 0x11ea4
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x55e8
jmp 0x11ea7
movq %rax, %rbx
jmp 0x11ebe
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xadcc
leaq 0x118(%rsp), %rdi
callq 0x55e8
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x80, %rdi
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x11ec2
leaq 0x10(%rsp), %rdi
callq 0x55e8
leaq 0xc0(%rsp), %rdi
callq 0x19c16
leaq 0x198(%rsp), %rdi
callq 0x1a5b0
movq %rbx, %rdi
callq 0x5540