// File: /workspace/github_cpp_makefile_star2_O3/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::PathMakeDecision(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::PathMakeDecision(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));
        // 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];
            //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));
            }

            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));
                    }else{
                        candidate_choices[i].push_back(pair<int, int>(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));
                }


                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));
                }
            }
        }
    }

    //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){
//                    string temp_sequence = reference_sequence.substr(pos, 1);
//                    path.string_sequences[x*2][pos] = temp_sequence;
//                    path.string_sequences[x*2+1][pos] = temp_sequence;
//                }else{
                    // set score


                    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;
                    if(c == -1){
                        alts[0] = ref;
                        alts[1] = var.alts[0];
                    }else if(c == -2){
                        alts[0] = ref;
                        alts[1] = var.alts[1];
                    }else{
                        // 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;
                        }
                    }

                    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];
                        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] = "";
                        }
                    }
                }
                path.choice_made[x][pos] = var_choice[x];
            }
            // choice made
            dout << "after decision at pos " << pos << endl;
            PrintPath(path);
            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 $0x3b8, %rsp            # imm = 0x3B8
movq %r8, 0x150(%rsp)
movq %rcx, 0x1e8(%rsp)
movq %rdx, 0x158(%rsp)
movq %rdi, 0x1f8(%rsp)
movl 0xc8(%rsi), %eax
incl %eax
leaq 0xc(%rsp), %rcx
movl %eax, (%rcx)
xorps %xmm0, %xmm0
leaq 0x178(%rsp), %rax
movaps %xmm0, 0x8(%rax)
movaps %xmm0, -0x8(%rax)
movaps %xmm0, -0x18(%rax)
movq %rsi, 0x1f0(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0x38(%rsp)
leaq 0x160(%rsp), %r14
movb $0x1, %bl
xorl %r15d, %r15d
movq $-0x1, 0x238(%rsp)
movq %r14, %rdi
leaq 0x238(%rsp), %rsi
callq 0x2ddde
movq %r14, 0x10(%rsp)
movl %ebx, 0x12c(%rsp)
movq 0x1e8(%rsp), %rax
movq (%rax,%r15,8), %rdi
leaq 0xc(%rsp), %rsi
callq 0x2dd60
cmpq %rdx, %rax
je 0x1a6cc
leaq (%r15,%r15), %rbp
leaq (%r15,%r15,2), %rsi
shlq $0x4, %rsi
movq 0x38(%rsp), %rcx
addq %rcx, %rsi
movq %rsi, 0x120(%rsp)
leaq 0x1(,%r15,2), %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %rcx
movq %rcx, 0x118(%rsp)
movq %rdx, 0x68(%rsp)
movq %rax, 0x110(%rsp)
movslq 0x24(%rax), %rcx
movq 0x158(%rsp), %rax
movq (%rax), %rbx
movq %rcx, 0x40(%rsp)
imulq $0x58, %rcx, %r14
movl (%rbx,%r14), %eax
movl %eax, 0x238(%rsp)
leaq 0x250(%rsp), %rax
movq %rax, 0x240(%rsp)
movq 0x8(%rbx,%r14), %rsi
movq 0x10(%rbx,%r14), %rdx
addq %rsi, %rdx
leaq 0x240(%rsp), %r15
movq %r15, %rdi
callq 0x1123c
addq %r14, %rbx
leaq 0x28(%rbx), %rsi
leaq 0x260(%rsp), %rdi
callq 0x28582
movq 0x50(%rbx), %rax
movq %rax, 0x48(%r15)
movups 0x40(%rbx), %xmm0
movups %xmm0, 0x38(%r15)
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x240(%rsp), %rsi
movq 0x248(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x1123c
movl $0x10, %eax
leaq (%rsp,%rax), %rcx
addq $0xb0, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x1a1a5
movq 0x260(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x51c0
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x51c0
cmpb $0x1, 0x279(%rsp)
jne 0x1a207
cmpb $0x0, 0x27a(%rsp)
je 0x1a218
cmpb $0x1, 0x278(%rsp)
leaq 0x70(%rsp), %rsi
je 0x1a224
jmp 0x1a231
movq 0x260(%rsp), %rsi
addq $0x20, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x51c0
movq 0xd8(%rsp), %rdx
movq 0x78(%rsp), %rbx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq %rbx, %rdx
jne 0x1a270
testq %rdx, %rdx
je 0x1a26a
movq 0x70(%rsp), %rsi
movq 0xd0(%rsp), %rdi
callq 0x5350
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x1a270
movl $0x1, %r15d
testq %rbx, %rbx
leaq 0xd0(%rsp), %rdx
je 0x1a304
xorl %r12d, %r12d
movb $0x1, %r14b
movslq %r12d, %rbx
leaq 0xb0(%rsp), %r13
xorl %eax, %eax
cmpq %r15, %rax
je 0x1a2e6
orq %rbp, %rax
leaq (%rax,%rax,2), %rax
movslq 0xc(%rsp), %rdi
addq %rbx, %rdi
shlq $0x5, %rdi
movq 0x38(%rsp), %rcx
addq (%rcx,%rax,8), %rdi
leaq 0x177ca(%rip), %rsi     # 0x31a86
callq 0x50e0
leaq 0xd0(%rsp), %rdx
testl %eax, %eax
je 0x1a2e6
cmpq %r12, 0x8(%r13)
jbe 0x1a324
movq 0x70(%rsp), %rax
movb (%rax,%r12), %al
movq (%r13), %rcx
cmpb (%rcx,%r12), %al
jne 0x1a324
movl $0x1, %eax
movq %rdx, %r13
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x1a294
incq %r12
cmpq %r12, 0x78(%rsp)
ja 0x1a284
movq 0x40(%rsp), %rax
movl %eax, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2ddde
cmpb $0x1, 0x278(%rsp)
jne 0x1a4c8
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x1123c
leaq 0xb0(%rsp), %rdi
leaq 0xd0(%rsp), %rbx
movq %rbx, %rsi
callq 0x51c0
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x51c0
movq 0xb8(%rsp), %rdx
movq 0x78(%rsp), %rbx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq %rbx, %rdx
jne 0x1a3ba
testq %rdx, %rdx
je 0x1a3b7
movq 0x70(%rsp), %rsi
movq 0xb0(%rsp), %rdi
callq 0x5350
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x1a3ba
xorl %r15d, %r15d
testq %rbx, %rbx
leaq 0xd0(%rsp), %rdx
je 0x1a456
xorl %r12d, %r12d
movb $0x1, %r14b
movslq %r12d, %rbx
leaq 0xb0(%rsp), %r13
xorl %eax, %eax
cmpq %rax, %r15
je 0x1a434
orq %rbp, %rax
leaq (%rax,%rax,2), %rax
movslq 0xc(%rsp), %rdi
addq %rbx, %rdi
shlq $0x5, %rdi
movq 0x38(%rsp), %rcx
addq (%rcx,%rax,8), %rdi
leaq 0x17680(%rip), %rsi     # 0x31a86
callq 0x50e0
leaq 0xd0(%rsp), %rdx
testl %eax, %eax
je 0x1a434
cmpq %r12, 0x8(%r13)
jbe 0x1a4ac
movq 0x70(%rsp), %rax
movb (%rax,%r12), %al
movq (%r13), %rcx
cmpb (%rcx,%r12), %al
jne 0x1a4ac
movl $0x1, %eax
movq %rdx, %r13
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x1a3de
incq %r12
cmpq %r12, 0x78(%rsp)
ja 0x1a3ce
cmpb $0x1, 0x279(%rsp)
jne 0x1a46a
cmpb $0x0, 0x27a(%rsp)
je 0x1a48c
movq 0x40(%rsp), %rax
movl %eax, 0x48(%rsp)
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2ddde
jmp 0x1a4ac
movq 0x40(%rsp), %rax
movl %eax, 0x48(%rsp)
movl $0x1, 0x4c(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2ddde
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1a4c8
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
cmpb $0x0, 0x279(%rsp)
je 0x1a630
cmpb $0x1, 0x27a(%rsp)
jne 0x1a630
movq 0x260(%rsp), %rsi
addq $0x20, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x51c0
leaq 0xd0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x51c0
cmpq $0x0, 0x78(%rsp)
je 0x1a56a
xorl %ebx, %ebx
movl 0xc(%rsp), %eax
addl %ebx, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
movq 0x120(%rsp), %rax
addq (%rax), %rdi
leaq 0x1754e(%rip), %rsi     # 0x31a86
callq 0x50e0
testl %eax, %eax
je 0x1a560
cmpq %rbx, 0xb8(%rsp)
jbe 0x1a58a
movq 0x70(%rsp), %rax
movb (%rax,%rbx), %al
movq 0xb0(%rsp), %rcx
cmpb (%rcx,%rbx), %al
jne 0x1a58a
incq %rbx
cmpq %rbx, 0x78(%rsp)
ja 0x1a519
movq 0x40(%rsp), %rax
movl %eax, 0x18(%rsp)
movl $0x1, 0x1c(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2ddde
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x51c0
movq 0x260(%rsp), %rsi
addq $0x20, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x51c0
cmpq $0x0, 0x78(%rsp)
je 0x1a610
xorl %ebx, %ebx
movl 0xc(%rsp), %eax
addl %ebx, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
movq 0x118(%rsp), %rax
addq (%rax), %rdi
leaq 0x174a8(%rip), %rsi     # 0x31a86
callq 0x50e0
testl %eax, %eax
je 0x1a606
cmpq %rbx, 0xd8(%rsp)
jbe 0x1a630
movq 0x70(%rsp), %rax
movb (%rax,%rbx), %al
movq 0xd0(%rsp), %rcx
cmpb (%rcx,%rbx), %al
jne 0x1a630
incq %rbx
cmpq %rbx, 0x78(%rsp)
ja 0x1a5bf
movq 0x40(%rsp), %rax
movl %eax, 0x18(%rsp)
movl $0xfffffffe, 0x1c(%rsp) # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2ddde
movq $-0x40, %rbx
leaq 0xe0(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x1a653
movq (%r14), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x1a63f
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x1a67f
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x260(%rsp), %rdi
callq 0xe71c
movq 0x240(%rsp), %rdi
leaq 0x250(%rsp), %rax
cmpq %rax, %rdi
je 0x1a6b1
movq 0x250(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x110(%rsp), %rdi
callq 0x5250
movq 0x68(%rsp), %rdx
cmpq %rdx, %rax
jne 0x1a0f9
movl $0x1, %r15d
leaq 0x178(%rsp), %r14
testb $0x1, 0x12c(%rsp)
movl $0x0, %ebx
jne 0x1a079
movq 0x160(%rsp), %rax
movq 0x168(%rsp), %rcx
cmpq %rax, %rcx
je 0x1affd
leaq 0xb8(%rsp), %r13
leaq 0xc8(%rsp), %r15
leaq 0x58(%rsp), %r12
leaq 0x210(%rsp), %rbp
movq 0x178(%rsp), %rdx
movq 0x180(%rsp), %rsi
movq $0x0, 0x10(%rsp)
cmpq %rdx, %rsi
movq %rdx, %rsi
je 0x1afdd
movq $0x0, 0x68(%rsp)
leaq 0x238(%rsp), %rdi
movq 0x1f0(%rsp), %rsi
callq 0x28ef6
movq 0x160(%rsp), %rax
movq 0x178(%rsp), %rcx
movq 0x68(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x10(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movaps %xmm1, 0x220(%rsp)
movb $0x1, %bl
leaq 0x220(%rsp), %r14
xorl %edx, %edx
movslq (%r14), %rcx
movq %rcx, 0x120(%rsp)
cmpq $-0x1, %rcx
je 0x1ae3e
movq %rdx, 0x110(%rsp)
movq %r14, 0x118(%rsp)
movl %ebx, 0x40(%rsp)
movq 0x158(%rsp), %rax
movq (%rax), %rbx
imulq $0x58, 0x120(%rsp), %r14
movl (%rbx,%r14), %eax
movl %eax, 0xb0(%rsp)
movq %r15, 0xb8(%rsp)
movq 0x8(%rbx,%r14), %rsi
movq 0x10(%rbx,%r14), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x1123c
addq %r14, %rbx
leaq 0x28(%rbx), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x28582
movq 0x50(%rbx), %rax
movq %rax, 0x48(%r13)
movups 0x40(%rbx), %xmm0
movups %xmm0, 0x38(%r13)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x1123c
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 0x1a857
movq 0x118(%rsp), %rax
movslq 0x4(%rax), %rbx
cmpq $-0x2, %rbx
je 0x1a8ab
cmpl $-0x1, %ebx
jne 0x1a8c8
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x51c0
movq 0xd8(%rsp), %rsi
jmp 0x1a92e
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x51c0
movq 0xd8(%rsp), %rsi
addq $0x20, %rsi
jmp 0x1a92e
movq %rbx, %rsi
shlq $0x5, %rsi
addq 0xd8(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x51c0
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x51c0
cmpb $0x1, 0xf1(%rsp)
jne 0x1a907
cmpb $0x0, 0xf2(%rsp)
je 0x1a918
cmpb $0x1, 0xf0(%rsp)
leaq 0x18(%rsp), %rsi
je 0x1a92e
jmp 0x1a93b
movl $0x1, %eax
subl %ebx, %eax
movslq %eax, %rsi
shlq $0x5, %rsi
addq 0xd8(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x51c0
movq 0x1f8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl %ebx, %edx
movl 0x3f0(%rsp), %ecx
movl 0x3f8(%rsp), %r8d
movl 0x400(%rsp), %r9d
callq 0x174b2
addl %eax, 0x390(%rsp)
movq 0x20(%rsp), %rbx
testq %rbx, %rbx
je 0x1a998
movq 0x18(%rsp), %r14
xorl %r15d, %r15d
movsbl (%r14,%r15), %edi
callq 0x5610
movb %al, (%r14,%r15)
incq %r15
cmpq %r15, %rbx
jne 0x1a982
movq 0x78(%rsp), %rbx
testq %rbx, %rbx
je 0x1a9c0
movq 0x70(%rsp), %r14
xorl %r15d, %r15d
movsbl (%r14,%r15), %edi
callq 0x5610
movb %al, (%r14,%r15)
incq %r15
cmpq %r15, %rbx
jne 0x1a9aa
movq 0x98(%rsp), %rbx
testq %rbx, %rbx
je 0x1a9ee
movq 0x90(%rsp), %r14
xorl %r15d, %r15d
movsbl (%r14,%r15), %edi
callq 0x5610
movb %al, (%r14,%r15)
incq %r15
cmpq %r15, %rbx
jne 0x1a9d8
movq 0x110(%rsp), %rax
addq %rax, %rax
movq %rax, 0x38(%rsp)
movb $0x1, %r13b
leaq 0x70(%rsp), %rax
xorl %r15d, %r15d
leaq 0x1a8(%rsp), %rbx
movq %r12, 0x48(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x1123c
xorps %xmm0, %xmm0
movaps %xmm0, 0x190(%rsp)
movq $0x0, 0x1a0(%rsp)
movq %rbp, 0x200(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x200(%rsp), %rdi
callq 0x1123c
leaq 0x1b8(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x1123c
leaq 0x200(%rsp), %rsi
movq %rbx, %rdx
leaq 0x190(%rsp), %rcx
callq 0x13eb2
movq 0x1a8(%rsp), %rdi
leaq 0x1b8(%rsp), %rax
cmpq %rax, %rdi
je 0x1aac5
movq 0x1b8(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x200(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1aae2
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x5340
movq %rbp, %rbx
movq 0x20(%rsp), %rax
cmpq $0x1, %rax
jne 0x1aaf7
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x1ab6a
movq %r15, %rcx
orq 0x38(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x240(%rsp), %rdx
leaq (%rdx,%rcx,8), %r14
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x190(%rsp), %rcx
leaq (%rcx,%r12), %rsi
cmpq $0x1, 0x8(%rcx,%r12)
jne 0x1ab37
movq 0x18(%rsp), %rcx
movb (%rcx,%rbp), %cl
movq (%rsi), %rdx
cmpb (%rdx), %cl
je 0x1ab51
movl 0xc(%rsp), %eax
addl %ebp, %eax
movslq %eax, %rdi
shlq $0x5, %rdi
addq (%r14), %rdi
callq 0x51c0
movq 0x20(%rsp), %rax
incq %rbp
leaq -0x1(%rax), %rcx
addq $0x20, %r12
cmpq %rbp, %rcx
ja 0x1ab14
jne 0x1b039
movl %ebp, %r14d
movq 0x190(%rsp), %rax
movq %rbp, %r12
shlq $0x5, %r12
leaq 0x140(%rsp), %rcx
movq %rcx, 0x130(%rsp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq 0x130(%rsp), %rdi
callq 0x1123c
movq 0x138(%rsp), %rax
testq %rax, %rax
je 0x1abf7
cmpq $0x1, %rax
jne 0x1ac42
movq 0x18(%rsp), %rax
movb (%rax,%rbp), %al
movq 0x190(%rsp), %rcx
movq (%rcx,%r12), %rcx
cmpb (%rcx), %al
leaq 0x58(%rsp), %r12
movq %rbx, %rbp
je 0x1ad38
orq 0x38(%rsp), %r15
leaq (%r15,%r15,2), %rax
leaq 0x240(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
jmp 0x1ad19
orq 0x38(%rsp), %r15
leaq (%r15,%r15,2), %rax
movslq 0xc(%rsp), %rcx
movslq %r14d, %rdx
addq %rcx, %rdx
leaq 0x240(%rsp), %rcx
movq (%rcx,%rax,8), %rax
shlq $0x5, %rdx
leaq (%rax,%rdx), %rdi
movq 0x8(%rax,%rdx), %rdx
xorl %esi, %esi
leaq 0x169c5(%rip), %rcx     # 0x315f2
xorl %r8d, %r8d
leaq 0x58(%rsp), %r12
callq 0x54b0
movq %rbx, %rbp
jmp 0x1ad38
movq 0x130(%rsp), %rax
movb (%rax), %cl
movq 0x18(%rsp), %rdx
orq 0x38(%rsp), %r15
leaq (%r15,%r15,2), %rax
movslq 0xc(%rsp), %rdi
movslq %r14d, %r12
addq %r12, %rdi
shlq $0x5, %rdi
leaq 0x240(%rsp), %rsi
addq (%rsi,%rax,8), %rdi
cmpb (%rdx,%rbp), %cl
jne 0x1ad0a
leaq (%rsi,%rax,8), %r15
leaq 0x16dfd(%rip), %rsi     # 0x31a86
callq 0x50e0
testl %eax, %eax
movq %rbx, %rbp
je 0x1ad14
movq 0x138(%rsp), %rcx
decq %rcx
movl $0x1, %edx
leaq 0x1c8(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x5360
movslq 0xc(%rsp), %rdi
addq %r12, %rdi
shlq $0x5, %rdi
addq (%r15), %rdi
movq 0x1c8(%rsp), %rsi
movq 0x1d0(%rsp), %rdx
callq 0x50f0
movq 0x1c8(%rsp), %rdi
leaq 0x1d8(%rsp), %rax
cmpq %rax, %rdi
je 0x1ad03
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x58(%rsp), %r12
jmp 0x1ad38
leaq 0x58(%rsp), %r12
movq %rbx, %rbp
jmp 0x1ad2b
leaq 0x58(%rsp), %r12
movslq 0xc(%rsp), %rax
movslq %r14d, %rdi
addq %rax, %rdi
shlq $0x5, %rdi
addq (%r15), %rdi
leaq 0x130(%rsp), %rsi
callq 0x51c0
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x1ad5d
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x190(%rsp), %rdi
callq 0xe71c
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
leaq 0x1a8(%rsp), %rbx
je 0x1ad89
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5340
movl $0x1, %r15d
leaq 0x90(%rsp), %rax
testb $0x1, %r13b
movl $0x0, %r13d
jne 0x1aa11
movq $-0x40, %rbx
leaq 0xa0(%rsp), %r14
leaq 0xc8(%rsp), %r15
leaq 0xb8(%rsp), %r13
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x1adda
movq (%r14), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x1adc6
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1ae00
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0xd8(%rsp), %rdi
callq 0xe71c
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
movl 0x40(%rsp), %ebx
movq 0x118(%rsp), %r14
je 0x1ae36
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x110(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
leaq 0x2a0(%rsp), %rax
addq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2906e
movq 0x120(%rsp), %rcx
movl %ecx, (%rax)
movl 0x4(%r14), %ecx
movl %ecx, 0x4(%rax)
movl $0x1, %edx
leaq 0x228(%rsp), %r14
testb $0x1, %bl
movl $0x0, %ebx
jne 0x1a7a1
movl $0x16, %edx
movq 0x2213d(%rip), %rdi     # 0x3cfd0
leaq 0x16984(%rip), %rsi     # 0x3181e
callq 0x53a0
movl 0xc(%rsp), %esi
movq 0x22126(%rip), %rdi     # 0x3cfd0
callq 0x55a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
leaq 0x238(%rsp), %rsi
callq 0x1b366
movq 0x150(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x2e160
movq %rax, %rdi
movq 0x150(%rsp), %rbx
movq %rbx, %rsi
callq 0x5070
incq 0x10(%rbx)
movq 0x3a0(%rsp), %rdi
testq %rdi, %rdi
je 0x1af2f
movq 0x3b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movl $0x140, %ebx            # imm = 0x140
leaq (%rsp,%rbx), %rax
addq $0x238, %rax            # imm = 0x238
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x1af52
movq (%rax), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %rbx
cmpq $0xc0, %rbx
jne 0x1af34
movl $0x98, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0x2a10c
addq $-0x30, %rbx
cmpq $0x38, %rbx
jne 0x1af64
movl $0x50, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0xe71c
addq $-0x18, %rbx
cmpq $-0x10, %rbx
jne 0x1af83
movq 0x68(%rsp), %rdi
incq %rdi
movq 0x178(%rsp), %rdx
movq 0x180(%rsp), %rsi
movq %rsi, %rax
subq %rdx, %rax
sarq $0x3, %rax
movq %rdi, 0x68(%rsp)
cmpq %rdi, %rax
ja 0x1a751
movq 0x160(%rsp), %rax
movq 0x168(%rsp), %rcx
movq 0x10(%rsp), %r9
incq %r9
movq %rcx, %rdi
subq %rax, %rdi
sarq $0x3, %rdi
movq %r9, 0x10(%rsp)
cmpq %r9, %rdi
ja 0x1a73c
movl $0x30, %ebx
movq 0x148(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0x1b01f
movq 0x158(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x5340
addq $-0x18, %rbx
jne 0x1b002
movb $0x1, %al
addq $0x3b8, %rsp            # imm = 0x3B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16601(%rip), %rdi     # 0x31641
leaq 0x1660e(%rip), %rsi     # 0x31655
leaq 0x16737(%rip), %rcx     # 0x31785
movl $0x845, %edx            # imm = 0x845
callq 0x5230
jmp 0x1b080
jmp 0x1b080
jmp 0x1b088
jmp 0x1b080
jmp 0x1b088
jmp 0x1b0c3
jmp 0x1b0c3
jmp 0x1b0c3
jmp 0x1b0c3
jmp 0x1b0c3
jmp 0x1b0c3
jmp 0x1b0bb
movq %rax, %r14
jmp 0x1b122
movq %rax, %r14
jmp 0x1b115
movq %rax, %r14
jmp 0x1b335
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1b0c6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x1b0c6
movq %rax, %r14
jmp 0x1b280
jmp 0x1b0bb
movq %rax, %r14
jmp 0x1b28d
movq %rax, %r14
jmp 0x1b2aa
movq %rax, %r14
movq $-0x40, %rbx
leaq 0xe0(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x1b0e9
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %rbx
jne 0x1b0d5
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x1b115
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x260(%rsp), %rdi
callq 0xe71c
movq 0x240(%rsp), %rdi
leaq 0x250(%rsp), %rax
cmpq %rax, %rdi
je 0x1b335
movq 0x250(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x1b335
jmp 0x1b1fe
movq %rax, %r14
jmp 0x1b182
movq %rax, %r14
movq 0x1c8(%rsp), %rdi
leaq 0x1d8(%rsp), %rax
cmpq %rax, %rdi
je 0x1b182
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x58(%rsp), %r12
jmp 0x1b18c
movq %rax, %r14
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x1b20b
movq 0x140(%rsp), %rsi
jmp 0x1b1f4
jmp 0x1b203
movq %rax, %r14
jmp 0x1b1df
movq %rax, %r14
jmp 0x1b20b
movq %rax, %r14
movq 0x1a8(%rsp), %rdi
leaq 0x1b8(%rsp), %rax
cmpq %rax, %rdi
je 0x1b1df
movq 0x1b8(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x200(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1b20b
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x1b20b
movq %rax, %r14
jmp 0x1b22f
movq %rax, %r14
leaq 0x58(%rsp), %r12
leaq 0x190(%rsp), %rdi
callq 0xe71c
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x1b22f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5340
movq $-0x40, %rbx
leaq 0xa0(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x1b252
movq (%r15), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
addq $0x20, %rbx
jne 0x1b23e
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1b278
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0xc8(%rsp), %r15
leaq 0xd8(%rsp), %rdi
callq 0xe71c
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x1b2aa
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x3a0(%rsp), %rdi
testq %rdi, %rdi
je 0x1b2c7
movq 0x3b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movl $0x140, %ebx            # imm = 0x140
leaq (%rsp,%rbx), %rax
addq $0x238, %rax            # imm = 0x238
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x1b2ea
movq (%rax), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %rbx
cmpq $0xc0, %rbx
jne 0x1b2cc
movl $0x98, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0x2a10c
addq $-0x30, %rbx
cmpq $0x38, %rbx
jne 0x1b2fc
movl $0x50, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0xe71c
addq $-0x18, %rbx
cmpq $-0x10, %rbx
jne 0x1b31b
movl $0x30, %ebx
movq 0x148(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0x1b357
movq 0x158(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x5340
addq $-0x18, %rbx
jne 0x1b33a
movq %r14, %rdi
callq 0x55c0
nop