// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rdx, %r15
movq %rdi, %r14
movslq 0x360(%rsp), %r13
movl 0xc8(%rsi), %eax
movl %eax, 0xc(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x2935c
cmpl $-0x9, 0x368(%rsp)
jne 0x185c4
leaq 0x198(%rsp), %rsi
movq 0x168(%rsi), %rax
movl $0xfffffff7, (%rax,%r13,4) # imm = 0xFFFFFFF7
movq %r12, %rdi
callq 0x2e600
movq %rax, %rdi
movq %r12, %rsi
callq 0x5070
incq 0x10(%r12)
jmp 0x18c1b
movq %r12, 0x78(%rsp)
movq (%r15), %r15
movq %r13, 0x10(%rsp)
imulq $0x58, %r13, %r12
movl (%r15,%r12), %eax
leaq 0xe0(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x8(%r15,%r12), %rsi
movq 0x10(%r15,%r12), %rdx
addq %rsi, %rdx
callq 0x112ce
addq %r12, %r15
leaq 0x100(%rsp), %rdi
leaq 0x28(%r15), %rsi
callq 0x289ec
movl 0x368(%rsp), %r13d
movups 0x40(%r15), %xmm0
movups %xmm0, 0x118(%rsp)
movq 0x50(%r15), %rax
movq %rax, 0x128(%rsp)
movzbl 0x124(%rsp), %r15d
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x112ce
movl 0x350(%rsp), %ebp
incl 0xc(%rsp)
addl %r15d, %r15d
movl $0x10, %eax
leaq (%rsp,%rax), %rcx
addq $0x130, %rcx            # imm = 0x130
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x1867c
cmpl $-0x2, %r13d
je 0x186cc
cmpl $-0x1, %r13d
jne 0x18cba
leaq 0x130(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x51c0
movq 0x100(%rsp), %r12
jmp 0x186ea
leaq 0x130(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x51c0
movq 0x100(%rsp), %r12
addq $0x20, %r12
leaq 0x150(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x51c0
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
movl 0x368(%rsp), %edx
movl %ebx, %ecx
movl %ebp, %r8d
movl 0x358(%rsp), %r9d
callq 0x176ee
addl %eax, 0x2f0(%rsp)
movq 0x20(%rsp), %rbx
testq %rbx, %rbx
je 0x18750
movq 0x18(%rsp), %r14
xorl %r12d, %r12d
movsbl (%r14,%r12), %edi
callq 0x5610
movb %al, (%r14,%r12)
incq %r12
cmpq %r12, %rbx
jne 0x1873a
movq 0x138(%rsp), %rbx
testq %rbx, %rbx
je 0x1877e
movq 0x130(%rsp), %r14
xorl %r12d, %r12d
movsbl (%r14,%r12), %edi
callq 0x5610
movb %al, (%r14,%r12)
incq %r12
cmpq %r12, %rbx
jne 0x18768
movq 0x158(%rsp), %rbx
testq %rbx, %rbx
je 0x187ac
movq 0x150(%rsp), %r14
xorl %r12d, %r12d
movsbl (%r14,%r12), %edi
callq 0x5610
movb %al, (%r14,%r12)
incq %r12
cmpq %r12, %rbx
jne 0x18796
leaq 0x68(%rsp), %rbp
movslq 0xc(%rsp), %r12
movl %r15d, %r13d
shlq $0x5, %r12
xorl %r14d, %r14d
movq 0x10(%rsp), %r15
movq %r14, %rax
shlq $0x5, %rax
movq %rbp, 0x58(%rsp)
movq 0x130(%rsp,%rax), %rsi
movq 0x138(%rsp,%rax), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x112ce
movq 0x60(%rsp), %rdx
movq 0x20(%rsp), %rbx
cmpq %rbx, %rdx
jne 0x1881d
testq %rdx, %rdx
je 0x18b41
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0x5350
testl %eax, %eax
je 0x18b41
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x18(%rsp), %rsi
addq %rsi, %rbx
leaq 0xb8(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x112ce
leaq 0x188(%rsp), %r15
movq %r15, 0x178(%rsp)
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq %rsi, %rdx
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
callq 0x112ce
movq %rbp, %rsi
movq %rbx, %rdx
leaq 0x80(%rsp), %rcx
callq 0x13f5e
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x188bc
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x188e1
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x20(%rsp), %rax
decq %rax
je 0x18951
movq %r14, %rax
orq %r13, %rax
leaq (%rax,%rax,2), %rax
leaq 0x1a0(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x80(%rsp), %rax
leaq (%rax,%rbp), %rsi
cmpq $0x1, 0x8(%rax,%rbp)
jne 0x1892a
movq 0x18(%rsp), %rax
movb (%rax,%r15), %al
movq (%rsi), %rcx
cmpb (%rcx), %al
je 0x18938
movq (%rbx), %rdi
addq %r12, %rdi
addq %rbp, %rdi
callq 0x51c0
incq %r15
movq 0x20(%rsp), %rax
decq %rax
addq $0x20, %rbp
cmpq %r15, %rax
ja 0x18906
movl %r15d, %ebx
jmp 0x18956
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpq %r15, %rax
jne 0x18d86
movq 0x80(%rsp), %rax
movq %r15, %rbp
shlq $0x5, %rbp
leaq 0x48(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0x112ce
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x189e6
cmpq $0x1, %rax
jne 0x18a2b
movq 0x18(%rsp), %rax
movb (%rax,%r15), %al
movq 0x80(%rsp), %rcx
movq (%rcx,%rbp), %rcx
cmpb (%rcx), %al
movq 0x10(%rsp), %r15
je 0x18b13
movq %r14, %rax
orq %r13, %rax
leaq (%rax,%rax,2), %rax
leaq 0x1a0(%rsp), %rcx
leaq (%rcx,%rax,8), %rbp
addl 0xc(%rsp), %ebx
movslq %ebx, %rbx
jmp 0x18afe
movq %r14, %rax
orq %r13, %rax
leaq (%rax,%rax,2), %rax
addl 0xc(%rsp), %ebx
movslq %ebx, %rcx
leaq 0x1a0(%rsp), %rdx
movq (%rdx,%rax,8), %rax
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
movq 0x8(%rax,%rcx), %rdx
xorl %esi, %esi
leaq 0x18ba9(%rip), %rcx     # 0x315c2
xorl %r8d, %r8d
callq 0x54b0
movq 0x10(%rsp), %r15
jmp 0x18b13
movq 0x38(%rsp), %rax
movb (%rax), %al
movq 0x18(%rsp), %rcx
addl 0xc(%rsp), %ebx
movslq %ebx, %rbx
cmpb (%rcx,%r15), %al
jne 0x18ae3
movq %r14, %rax
orq %r13, %rax
leaq (%rax,%rax,2), %rax
leaq 0x1a0(%rsp), %rcx
leaq (%rcx,%rax,8), %rbp
movq %rbx, %r15
shlq $0x5, %r15
movq (%rbp), %rdi
addq %r15, %rdi
leaq 0x18fe3(%rip), %rsi     # 0x31a56
callq 0x50e0
testl %eax, %eax
je 0x18af9
movq 0x40(%rsp), %rcx
decq %rcx
movl $0x1, %edx
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x5360
addq (%rbp), %r15
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movq %r15, %rdi
callq 0x50f0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
movq 0x10(%rsp), %r15
je 0x18b13
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x18b13
movq %r14, %rax
orq %r13, %rax
leaq (%rax,%rax,2), %rax
leaq 0x1a0(%rsp), %rcx
leaq (%rcx,%rax,8), %rbp
movq 0x10(%rsp), %r15
shlq $0x5, %rbx
addq (%rbp), %rbx
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x51c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x18b2f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x80(%rsp), %rdi
callq 0xe7ca
leaq 0x68(%rsp), %rbp
movq 0x58(%rsp), %rdi
cmpq %rbp, %rdi
je 0x18b58
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
je 0x187c5
leaq 0x198(%rsp), %rsi
movq 0x168(%rsi), %rax
movl 0x368(%rsp), %ecx
movl %ecx, (%rax,%r15,4)
movq 0x78(%rsp), %rdi
callq 0x2e600
movq %rax, %rdi
movq 0x78(%rsp), %rbx
movq %rbx, %rsi
callq 0x5070
incq 0x10(%rbx)
movq $-0x40, %rbx
leaq 0x160(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x18bc3
movq (%r14), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x18baf
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x18be9
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x100(%rsp), %rdi
callq 0xe7ca
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x18c1b
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x300(%rsp), %rdi
testq %rdi, %rdi
je 0x18c38
movq 0x310(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movl $0x140, %ebx            # imm = 0x140
leaq (%rsp,%rbx), %rax
addq $0x198, %rax            # imm = 0x198
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x18c5b
movq (%rax), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %rbx
cmpq $0xc0, %rbx
jne 0x18c3d
movl $0x98, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x2a5c6
addq $-0x30, %rbx
cmpq $0x38, %rbx
jne 0x18c6d
movl $0x50, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0xe7ca
addq $-0x18, %rbx
cmpq $-0x10, %rbx
jne 0x18c8c
movb $0x1, %al
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r13d, %r13d
js 0x18d1a
movl %r13d, %esi
shlq $0x5, %rsi
addq 0x100(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x51c0
leaq 0x150(%rsp), %r13
leaq 0x130(%rsp), %rsi
movq %r13, %rdi
callq 0x51c0
cmpb $0x1, 0x119(%rsp)
jne 0x18d07
cmpb $0x0, 0x11a(%rsp)
je 0x18d66
cmpb $0x1, 0x118(%rsp)
je 0x186f2
jmp 0x186fd
movq 0x232af(%rip), %r12     # 0x3bfd0
leaq 0x188d5(%rip), %rsi     # 0x315fd
movl $0x13, %edx
movq %r12, %rdi
callq 0x53a0
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq 0x2327c(%rip), %rdi     # 0x3bfd0
callq 0x5040
movq %rax, %rdi
callq 0x5240
jmp 0x186fd
movl $0x1, %eax
subl 0x368(%rsp), %eax
movslq %eax, %r12
shlq $0x5, %r12
addq 0x100(%rsp), %r12
jmp 0x186f2
leaq 0x18884(%rip), %rdi     # 0x31611
leaq 0x18891(%rip), %rsi     # 0x31625
leaq 0x1889a(%rip), %rcx     # 0x31635
movl $0x562, %edx            # imm = 0x562
callq 0x5230
movq %rax, %rbx
jmp 0x18ef9
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x18f06
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x18f06
jmp 0x18de0
movq %rax, %rbx
jmp 0x18f06
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x18e19
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x18e19
jmp 0x18e16
jmp 0x18e7f
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x18e87
movq 0x48(%rsp), %rsi
jmp 0x18e73
jmp 0x18e84
movq %rax, %rbx
jmp 0x18e56
movq %rax, %rbx
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x18e56
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x18e87
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x18e87
jmp 0x18e84
movq %rax, %rbx
jmp 0x18eb0
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xe7ca
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x18eb0
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5340
movq $-0x40, %r14
leaq 0x160(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x18ed3
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %r14
jne 0x18ebf
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x18ef9
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0xd8(%rsp), %rdi
callq 0x28b44
leaq 0x198(%rsp), %rdi
callq 0x29560
movq %rbx, %rdi
callq 0x55c0
nop