// File: 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
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movl 0x28(%rbp), %eax
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, -0x370(%rbp)
movq -0x18(%rbp), %rax
movl 0xc8(%rax), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0x34b20
cmpl $-0x9, 0x28(%rbp)
jne 0x2346a
movl 0x28(%rbp), %eax
movl %eax, -0x374(%rbp)
leaq -0x50(%rbp), %rdi
movslq 0x20(%rbp), %rsi
callq 0x19a60
movl -0x374(%rbp), %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x34fe0
jmp 0x23440
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1c8(%rbp)
jmp 0x23ef1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x23f0b
leaq -0x1e0(%rbp), %rax
movq %rax, %rcx
addq $0x10, %rcx
movq %rcx, -0x388(%rbp)
movq %rax, -0x380(%rbp)
movq -0x380(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x34e90
jmp 0x2349b
movq -0x388(%rbp), %rcx
movq -0x390(%rbp), %rax
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x380(%rbp)
jne 0x23486
movl $0x0, -0x1e4(%rbp)
movl 0x20(%rbp), %eax
movl %eax, -0x1e8(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x1e8(%rbp), %rsi
callq 0x33de0
movq %rax, %rsi
leaq -0x240(%rbp), %rdi
callq 0x340a0
jmp 0x234ed
testb $0x1, -0x1f4(%rbp)
je 0x23500
movl $0x1, -0x1e4(%rbp)
leaq -0x238(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x61b0
jmp 0x23515
leaq -0x2a0(%rbp), %rax
movq %rax, %rcx
addq $0x40, %rcx
movq %rcx, -0x3a0(%rbp)
movq %rax, -0x398(%rbp)
movq -0x398(%rbp), %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x65e0
movq -0x3a8(%rbp), %rax
movq -0x3a0(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x398(%rbp)
jne 0x23531
cmpl $-0x1, 0x28(%rbp)
jne 0x235d1
leaq -0x2a0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x6070
jmp 0x2357d
leaq -0x218(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9080
movq %rax, %rsi
leaq -0x280(%rbp), %rdi
callq 0x6070
jmp 0x2359e
jmp 0x236ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x23ee3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x23e8d
cmpl $-0x2, 0x28(%rbp)
jne 0x23613
leaq -0x2a0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x6070
jmp 0x235ec
leaq -0x218(%rbp), %rdi
movl $0x1, %esi
callq 0x9080
movq %rax, %rsi
leaq -0x280(%rbp), %rdi
callq 0x6070
jmp 0x2360e
jmp 0x236ea
cmpl $0x0, 0x28(%rbp)
jl 0x236b5
leaq -0x218(%rbp), %rdi
movslq 0x28(%rbp), %rsi
callq 0x9080
movq %rax, %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x6070
jmp 0x2363e
leaq -0x280(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x6070
jmp 0x23653
testb $0x1, -0x1ff(%rbp)
je 0x23691
testb $0x1, -0x1fe(%rbp)
jne 0x23691
leaq -0x218(%rbp), %rdi
movl 0x28(%rbp), %ecx
movl $0x1, %eax
subl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rsi
leaq -0x280(%rbp), %rdi
callq 0x6070
jmp 0x2368f
jmp 0x236b3
testb $0x1, -0x200(%rbp)
je 0x236b1
leaq -0x280(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x6070
jmp 0x236af
jmp 0x236b1
jmp 0x236b3
jmp 0x236e8
movq 0x508fc(%rip), %rdi     # 0x73fb8
leaq 0x31f16(%rip), %rsi     # 0x555d9
callq 0x6420
movq %rax, -0x3b0(%rbp)
jmp 0x236d1
movq -0x3b0(%rbp), %rdi
movq 0x508a1(%rip), %rsi     # 0x73f80
callq 0x6480
jmp 0x236e6
jmp 0x236e8
jmp 0x236ea
jmp 0x236ec
movq -0x370(%rbp), %rdi
movl 0x28(%rbp), %edx
movl -0x34(%rbp), %ecx
movl 0x10(%rbp), %r8d
movl 0x18(%rbp), %r9d
leaq -0x240(%rbp), %rsi
callq 0x21fd0
movl %eax, -0x3b4(%rbp)
jmp 0x23715
movq -0x370(%rbp), %rdi
movl -0x3b4(%rbp), %ecx
movl -0x60(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x60(%rbp)
leaq -0x260(%rbp), %rsi
callq 0x328c0
jmp 0x23738
movq -0x370(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x328c0
jmp 0x2374d
movq -0x370(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x328c0
jmp 0x23762
movl $0x0, -0x2a4(%rbp)
cmpl $0x2, -0x2a4(%rbp)
jge 0x23deb
movslq -0x2a4(%rbp), %rax
shlq $0x5, %rax
leaq -0x2a0(%rbp,%rax), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x61b0
jmp 0x2379a
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0xdcb0
testb $0x1, %al
jne 0x237b3
jmp 0x237c2
movl $0x4, -0x1c8(%rbp)
jmp 0x23d92
leaq -0x2e0(%rbp), %rdi
callq 0x12d30
leaq -0x300(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x61b0
jmp 0x237e3
leaq -0x320(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x61b0
jmp 0x237f8
movq -0x370(%rbp), %rdi
leaq -0x300(%rbp), %rsi
leaq -0x320(%rbp), %rdx
leaq -0x2e0(%rbp), %rcx
callq 0x1dc90
jmp 0x2381b
leaq -0x320(%rbp), %rdi
callq 0x6828
leaq -0x300(%rbp), %rdi
callq 0x6828
movl $0x0, -0x324(%rbp)
movslq -0x324(%rbp), %rax
movq %rax, -0x3c0(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x6630
movq %rax, %rcx
movq -0x3c0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x239cc
movslq -0x324(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x9080
movq %rax, %rdi
callq 0x6320
cmpq $0x1, %rax
jne 0x238fb
movslq -0x324(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x6810
movq %rax, -0x3c8(%rbp)
jmp 0x238ab
movq -0x3c8(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x3d4(%rbp)
movslq -0x324(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x9080
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6810
movq %rax, -0x3d0(%rbp)
jmp 0x238e3
movl -0x3d4(%rbp), %eax
movq -0x3d0(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x239b6
movslq -0x324(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x9080
movq %rax, -0x3e0(%rbp)
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq -0x3e0(%rbp), %rsi
movq %rax, %rdi
callq 0x6070
jmp 0x2395a
jmp 0x239b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x23dce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x239a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x6828
leaq -0x300(%rbp), %rdi
callq 0x6828
jmp 0x23dce
jmp 0x239b8
movl -0x324(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x324(%rbp)
jmp 0x2383d
movslq -0x324(%rbp), %rax
movq %rax, -0x3e8(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x6630
movq %rax, %rcx
movq -0x3e8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x239fb
jmp 0x23a1a
leaq 0x31beb(%rip), %rdi     # 0x555ed
leaq 0x31bf8(%rip), %rsi     # 0x55601
movl $0x562, %edx            # imm = 0x562
leaq 0x31bfc(%rip), %rcx     # 0x55611
callq 0x62f0
movslq -0x324(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x9080
movq %rax, %rsi
leaq -0x348(%rbp), %rdi
callq 0x61b0
jmp 0x23a3e
leaq -0x348(%rbp), %rdi
callq 0x6630
cmpq $0x0, %rax
jbe 0x23d29
leaq -0x348(%rbp), %rdi
callq 0x6630
cmpq $0x1, %rax
jbe 0x23c76
xorl %eax, %eax
movl %eax, %esi
leaq -0x348(%rbp), %rdi
callq 0x6810
movq %rax, -0x3f0(%rbp)
jmp 0x23a83
movq -0x3f0(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x3fc(%rbp)
movslq -0x324(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x6810
movq %rax, -0x3f8(%rbp)
jmp 0x23aaf
movl -0x3fc(%rbp), %eax
movq -0x3f8(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x23c2a
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq 0x31f2d(%rip), %rsi     # 0x55a32
callq 0x125e0
movb %al, -0x3fd(%rbp)
jmp 0x23b12
movb -0x3fd(%rbp), %al
testb $0x1, %al
jne 0x23b1e
jmp 0x23b7f
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq -0x348(%rbp), %rsi
callq 0x6070
jmp 0x23b63
jmp 0x23c28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x23dc2
leaq -0x348(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x6320
movq -0x408(%rbp), %rsi
movq %rax, %rcx
decq %rcx
leaq -0x368(%rbp), %rdi
movl $0x1, %edx
callq 0x6460
jmp 0x23bb2
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq -0x368(%rbp), %rsi
callq 0x6560
jmp 0x23bf7
leaq -0x368(%rbp), %rdi
callq 0x6828
jmp 0x23c28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x6828
jmp 0x23dc2
jmp 0x23c71
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq -0x348(%rbp), %rsi
callq 0x6070
jmp 0x23c6f
jmp 0x23c71
jmp 0x23d27
movslq -0x324(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x6810
movq %rax, -0x410(%rbp)
jmp 0x23c92
movq -0x410(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x41c(%rbp)
movslq -0x324(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x9080
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6810
movq %rax, -0x418(%rbp)
jmp 0x23cca
movl -0x41c(%rbp), %eax
movq -0x418(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x23d25
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq -0x348(%rbp), %rsi
callq 0x6070
jmp 0x23d23
jmp 0x23d25
jmp 0x23d27
jmp 0x23d70
movl -0x1e4(%rbp), %eax
movl -0x2a4(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq -0x1b0(%rbp,%rax,8), %rdi
movl -0x38(%rbp), %eax
movl -0x324(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x9080
movq %rax, %rdi
leaq 0x31837(%rip), %rsi     # 0x5559e
callq 0x65c0
jmp 0x23d6e
jmp 0x23d70
leaq -0x348(%rbp), %rdi
callq 0x6828
leaq -0x2e0(%rbp), %rdi
callq 0x13370
movl $0x0, -0x1c8(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x6828
movl -0x1c8(%rbp), %eax
testl %eax, %eax
je 0x23dac
jmp 0x23daa
jmp 0x23dae
jmp 0x23dae
movl -0x2a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x2376c
leaq -0x348(%rbp), %rdi
callq 0x6828
leaq -0x2e0(%rbp), %rdi
callq 0x13370
leaq -0x2c8(%rbp), %rdi
callq 0x6828
jmp 0x23e8d
movl 0x28(%rbp), %eax
movl %eax, -0x420(%rbp)
leaq -0x50(%rbp), %rdi
movslq 0x20(%rbp), %rsi
callq 0x19a60
movl -0x420(%rbp), %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x34fe0
jmp 0x23e1b
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1c8(%rbp)
leaq -0x2a0(%rbp), %rax
movq %rax, -0x430(%rbp)
addq $0x40, %rax
movq %rax, -0x428(%rbp)
movq -0x428(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x438(%rbp)
callq 0x6828
movq -0x430(%rbp), %rcx
movq -0x438(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x428(%rbp)
jne 0x23e42
leaq -0x260(%rbp), %rdi
callq 0x6828
leaq -0x240(%rbp), %rdi
callq 0x32c60
jmp 0x23ef1
leaq -0x2a0(%rbp), %rax
movq %rax, -0x448(%rbp)
addq $0x40, %rax
movq %rax, -0x440(%rbp)
movq -0x440(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x450(%rbp)
callq 0x6828
movq -0x448(%rbp), %rcx
movq -0x450(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x440(%rbp)
jne 0x23ea6
leaq -0x260(%rbp), %rdi
callq 0x6828
leaq -0x240(%rbp), %rdi
callq 0x32c60
jmp 0x23f0b
leaq -0x1b8(%rbp), %rdi
callq 0x35020
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
leaq -0x1b8(%rbp), %rdi
callq 0x35020
movq -0x1c0(%rbp), %rdi
callq 0x6750
nopw %cs:(%rax,%rax)