// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_rphase_dp(haplotype_evdience_alloc*, overlap_region_alloc*, UC_Read*, double, unsigned long, Chain_Data*, asg64_v*, asg64_v*, unsigned long, asg8_v*)
void gen_rphase_dp(haplotype_evdience_alloc* hl, overlap_region_alloc* ol, UC_Read* g_read, double st_rate, uint64_t st_max, Chain_Data *dp, asg64_v *idx, asg64_v *res, uint64_t rid, asg8_v *qv)
{
    if(hl->length <= 0) return;

    uint64_t k, l, i, i0, o, ii, m_snp_stat, m_snp_stat0, m_list /**m_off**/, m1, c0, c1, rev_n, tqual, wqual, hq_cut = 2; uint32_t hq[5], hp[4], is_st; SnpStats *s; haplotype_evdience ev; char mc;
    retrive_bqual(qv, NULL, rid, -1, -1, 0, sc_bn);

    idx->n = 0; 
    kv_resize(uint64_t, *res, ol->length); memset(res->a, -1, sizeof((*(res->a)))*ol->length); res->n = ol->length;
    for (k = 1, l = 0, i = m_snp_stat = m_list = 0; k <= hl->snp_stat.n; ++k) {///filter snps
        if(k == hl->snp_stat.n || hl->snp_stat.a[k].site != hl->snp_stat.a[l].site) {
            for (; i < hl->length && hl->list[i].site != hl->snp_stat.a[l].site; i++);
            assert(i < hl->length && hl->list[i].site == hl->snp_stat.a[l].site);
            for (o = l, m1 = 0; o < k; o++) {
                s = &(hl->snp_stat.a[o]);
                // fprintf(stderr, "+[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, s->site, s->occ_0, s->occ_1);
                if((s->occ_0 < 2 || s->occ_1 < 2) || (is_st_bs((*s), st_rate, st_max)) || (!(s->occ_0 >= asm_opt.s_hap_cov && s->occ_1 >= asm_opt.infor_cov))) {
                    continue;
                }
                // fprintf(stderr, "-[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, s->site, s->occ_0, s->occ_1);
                m1++;
            }

            if(m1) {
                hq[0] = hq[1] = hq[2] = hq[3] = hq[4] = 0; hp[0] = hp[1] = hp[2] = hp[3] = ((uint32_t)-1); 
                for (i0 = i, c0 = rev_n = 0; i0 < hl->length && hl->list[i0].site == hl->snp_stat.a[l].site; i0++) {
                    hl->list[i0].site = ((uint32_t)-1);
                    if(hh_tp(hl->list[i0]) == 0) {
                        c0 += 1/**hl->list[i0].cov**/;
                        if((ol->list[hl->list[i0].overlapID].y_pos_strand == 0)) rev_n += 1/**hl->list[i0].cov**/;
                    }
                    if(qv) {
                        if(hh_tp(hl->list[i0]) == 0) {
                            if((hh_bq(hl->list[i0]) > 1) || (hh_wq(hl->list[i0]) > 1)) hq[4]++;
                        } else {
                            hp[seq_nt6_table[(uint8_t)(hl->list[i0].misBase)]] = hl->list[i0].overlapSite;
                            if((hh_bq(hl->list[i0]) > 1) || (hh_wq(hl->list[i0]) > 1)) {
                                hq[seq_nt6_table[(uint8_t)(hl->list[i0].misBase)]]++;
                            }
                        }
                    }
                }
                assert(i0 > i);
                if(qv) {
                    if(hp[0] != ((uint32_t)-1) && hq[0] < hq_cut) {
                        // fprintf(stderr, "-[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, hl->snp_stat.a[hp[0]].site, hl->snp_stat.a[hp[0]].occ_0, hl->snp_stat.a[hp[0]].occ_1);
                        hl->snp_stat.a[hp[0]].occ_1 = 0;
                    }

                    if(hp[1] != ((uint32_t)-1) && hq[1] < hq_cut) {
                        // fprintf(stderr, "-[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, hl->snp_stat.a[hp[1]].site, hl->snp_stat.a[hp[1]].occ_0, hl->snp_stat.a[hp[1]].occ_1);
                        hl->snp_stat.a[hp[1]].occ_1 = 0;
                    }

                    if(hp[2] != ((uint32_t)-1) && hq[2] < hq_cut) {
                        // fprintf(stderr, "-[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, hl->snp_stat.a[hp[2]].site, hl->snp_stat.a[hp[2]].occ_0, hl->snp_stat.a[hp[2]].occ_1);
                        hl->snp_stat.a[hp[2]].occ_1 = 0;
                    }

                    if(hp[3] != ((uint32_t)-1) && hq[3] < hq_cut) {
                        // fprintf(stderr, "-[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, hl->snp_stat.a[hp[3]].site, hl->snp_stat.a[hp[3]].occ_0, hl->snp_stat.a[hp[3]].occ_1);
                        hl->snp_stat.a[hp[3]].occ_1 = 0;
                    }

                    get_wqual(rid, hl->snp_stat.a[l].site, 0, NULL, qv->a, sc_wn, &tqual, &wqual);
                    if(tqual > 1 || wqual > 1) hq[4]++;
                    // if(hq[4] == 0) {
                    //     fprintf(stderr, "+[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, hl->snp_stat.a[l].site, hl->snp_stat.a[l].occ_0, hl->snp_stat.a[l].occ_1);
                    // }
                } else {
                    hq[0] = hq[1] = hq[2] = hq[3] = hq[4] = ((uint32_t)-1);
                }

                if((hq[4] >= hq_cut) && (hq[0] >= hq_cut || hq[1] >= hq_cut || hq[2] >= hq_cut || hq[3] >= hq_cut)) {
                    for (o = l, m_snp_stat0 = m_snp_stat; o < k; o++) {
                        s = &(hl->snp_stat.a[o]);
                        if((s->occ_0 < 2 || s->occ_1 < 2) || (is_st_bs((*s), st_rate, st_max)) || (!(s->occ_0 >= asm_opt.s_hap_cov && s->occ_1 >= asm_opt.infor_cov))) {
                            continue;
                        }
                        
                        hl->snp_stat.a[m_snp_stat] = *s; 
                        for (ii = i, c1 = 0; ii < i0; ii++) {
                            if(((hl->list[ii].overlapSite == o) && (hl->list[ii].site == ((uint32_t)-1))) || (hh_tp(hl->list[ii]) == 0)) {
                                hl->list[ii].overlapSite = m_snp_stat;
                                hl->list[ii].site = hl->snp_stat.a[o].site;
                                if(hh_tp(hl->list[ii]) == 1) c1 += 1/**hl->list[ii].cov**/;///not correct if we don't do read correction
                            }
                        }
                        // fprintf(stderr, "-0-[M::%s]\tsite::%u\tc0::%lu\tc1::%lu\n", __func__, s->site, c0, c1);
                        hl->snp_stat.a[m_snp_stat].occ_0 = c0 + 1;
                        hl->snp_stat.a[m_snp_stat].occ_1 = c1;
                        hl->snp_stat.a[m_snp_stat].overlap_num = rev_n + 1;
                        hl->snp_stat.a[m_snp_stat].non_homopolymer_num = m_list;
                        hl->snp_stat.a[m_snp_stat++].score = -1;
                    }

                    for (ii = i, m1 = m_list; ii < i0; ii++) {
                        if((hl->list[ii].site == ((uint32_t)-1))) {
                            hl->list[ii].overlapSite = ((uint32_t)-1);
                            hl->list[ii].site = hl->snp_stat.a[l].site;
                        }
                        fill_incom(res, hl->list[ii].overlapID, hl->list[ii].site, idx->a, idx->n, ol->list[0].x_id);
                        hl->list[m_list++] = hl->list[ii];
                    }
                    radix_sort_haplotype_evdience_id_srt(hl->list + m1, hl->list + m_list);
                    for (ii = m_snp_stat0; ii < m_snp_stat; ii++) {
                        hl->snp_stat.a[ii].homopolymer_num = m_list;
                    }
                    
                    i = i0;

                    kv_push(uint64_t, *idx, hl->snp_stat.a[l].site);
                }
            }

            l = k;
        }
    }
    hl->snp_stat.n = m_snp_stat; hl->length = m_list;
    if(hl->snp_stat.n == 0 || hl->length == 0) return;


    ///fill incomplete values
    if(res->n > ol->length) {
        // fprintf(stderr, "\n[M::%s]\tin_comp::%lu\n", __func__, ((uint64_t)res->n - ol->length));
        for (k = ol->length; k < res->n; k++) {
            ev.misBase = 0;
            ev.overlapID = res->a[k]>>32;
            ev.site = ((uint32_t)res->a[k]);
            ev.overlapSite = ((uint32_t)-1);
            ev.type = 0;
            ev.cov = 1;
            addHaplotypeEvdience(hl, &ev, NULL);
            // fprintf(stderr, "[M::%s]\toid::%u\tsite::%u\n", __func__, ev.overlapID, ev.site);
        }
        radix_sort_haplotype_evdience_srt(hl->list, hl->list + hl->length);

        for (k = 1, l = 0, i = 0; k <= hl->snp_stat.n; ++k) {
            if(k == hl->snp_stat.n || hl->snp_stat.a[k].site != hl->snp_stat.a[l].site) {
                for (; i < hl->length && hl->list[i].site != hl->snp_stat.a[l].site; i++);
                assert(i < hl->length && hl->list[i].site == hl->snp_stat.a[l].site);
                
                m1 = ((uint32_t)-1); mc = 0;
                for (i0 = i, c0 = rev_n = 0; i0 < hl->length && hl->list[i0].site == hl->snp_stat.a[l].site; i0++) {
                    if(hh_tp(hl->list[i0]) == 0) {
                        c0+=1/**hl->list[i0].cov**/;
                        if((ol->list[hl->list[i0].overlapID].y_pos_strand == 0)) rev_n += 1/**hl->list[i0].cov**/;
                        if(hl->list[i0].overlapSite != ((uint32_t)-1)) {
                            m1 = hl->list[i0].overlapSite; mc = hl->list[i0].misBase;
                        }
                    }
                    // if(hl->snp_stat.a[l].site == 6995) {
                    //     fprintf(stderr, "[M::%s]\tsite::%u\tosite::%u\toid::%u\ttp::%u\n", __func__, hl->list[i0].site, hl->list[i0].overlapSite, hl->list[i0].overlapID, hh_tp(hl->list[i0]));
                    // }
                }
                assert(i0 > i);
                assert(m1 != ((uint32_t)-1));
                assert(mc != 0);

                
                for (ii = i, is_st = 1; ii < i0; ii++) {
                    if(hh_tp(hl->list[ii]) == 0) {
                        assert(hl->list[ii].overlapSite == ((uint32_t)-1) || hl->list[ii].overlapSite == m1);
                        hl->list[ii].overlapSite = m1; hl->list[ii].misBase = mc;
                    }
                    if((ii > i) && (hl->list[ii].overlapID <= hl->list[ii-1].overlapID)) {
                        is_st = 0;
                        // fprintf(stderr, "[M::%s]\tid::[%u,%u]\tsite::[%u,%u]\n", __func__, hl->list[ii].overlapID, hl->list[ii-1].overlapID,  hl->list[ii].overlapSite,  hl->list[ii-1].overlapSite);
                    }
                }
                if(is_st == 0) radix_sort_haplotype_evdience_id_srt(hl->list + i, hl->list + i0);
                // assert(is_st == 1);

                

                for (o = l; o < k; o++) {
                    s = &(hl->snp_stat.a[o]);
                    for (ii = i, c1 = 0; ii < i0; ii++) {
                        if((hl->list[ii].overlapSite == o) && (hh_tp(hl->list[ii]) == 1)) c1 += 1/**hl->list[ii].cov**/;///not correct if we don't do read correction
                    }
                    // fprintf(stderr, "-1-[M::%s]\tsite::%u\tc0::%lu\tc1::%lu\n", __func__, s->site, c0, c1);
                    s->occ_0 = c0 + 1;
                    s->occ_1 = c1;
                    s->overlap_num = rev_n + 1;
                    s->non_homopolymer_num = i;
                    s->homopolymer_num = i0;
                }
                
                i = i0;
                l = k;
            }
        }

    }





    // gen_rphase_dp0_multiple_path(hl->snp_stat.a, hl->snp_stat.n, hl->list, dp, idx, res);
    gen_rphase_dp0_single_path(hl->snp_stat.a, hl->snp_stat.n, hl->list, dp, idx, asm_opt.het_cov, asm_opt.hom_cov, asm_opt.polyploidy, 0.7, 6, res, qv->a);

    for (k = 1, l = 0, i = m_snp_stat = m_list = 0; k <= hl->snp_stat.n; ++k) {///filter snps
        if(k == hl->snp_stat.n || hl->snp_stat.a[k].site != hl->snp_stat.a[l].site) {
            for (; i < hl->length && hl->list[i].site != hl->snp_stat.a[l].site; i++);
            assert(i < hl->length && hl->list[i].site == hl->snp_stat.a[l].site);
            for (o = l, m1 = 0; o < k; o++) {
                s = &(hl->snp_stat.a[o]);
                if(s->score == -1) continue;
                m1++;
            }

            if(m1) {
                for (i0 = i, c0 = rev_n = 0; i0 < hl->length && hl->list[i0].site == hl->snp_stat.a[l].site; i0++) {
                    hl->list[i0].site = ((uint32_t)-1);
                    if(hh_tp(hl->list[i0]) == 0) {
                        c0 += 1/**hl->list[i0].cov**/;
                        if((ol->list[hl->list[i0].overlapID].y_pos_strand == 0)) rev_n += 1/**hl->list[i0].cov**/;
                    }
                }
                assert(i0 > i);

                for (o = l, m_snp_stat0 = m_snp_stat; o < k; o++) {
                    s = &(hl->snp_stat.a[o]);
                    if(s->score == -1) continue;
                    
                    hl->snp_stat.a[m_snp_stat] = *s; 
                    for (ii = i, c1 = 0; ii < i0; ii++) {
                        if(((hl->list[ii].overlapSite == o) && (hl->list[ii].site == ((uint32_t)-1))) || (hh_tp(hl->list[ii]) == 0)) {
                            hl->list[ii].overlapSite = m_snp_stat;
                            hl->list[ii].site = hl->snp_stat.a[o].site;
                            if(hh_tp(hl->list[ii]) == 1) c1 += 1/**hl->list[ii].cov**/;///not correct if we don't do read correction
                        }
                    }

                    // if(hl->snp_stat.a[m_snp_stat].site == 4) {
                    //     fprintf(stderr, "[M::%s] occ_0->%lu, occ_1->%lu, site->%u\n", __func__, c0 + 1, c1, hl->snp_stat.a[m_snp_stat].site);
                    // }
                    
                    hl->snp_stat.a[m_snp_stat].occ_0 = c0 + 1;
                    hl->snp_stat.a[m_snp_stat].occ_1 = c1;
                    hl->snp_stat.a[m_snp_stat].overlap_num = rev_n + 1;
                    hl->snp_stat.a[m_snp_stat].non_homopolymer_num = m_list;
                    hl->snp_stat.a[m_snp_stat++].score = -1;
                }

                for (ii = i, m1 = m_list; ii < i0; ii++) {
                    if((hl->list[ii].site == ((uint32_t)-1))) continue;
                    hl->list[m_list++] = hl->list[ii];
                }
                for (ii = m_snp_stat0; ii < m_snp_stat; ii++) {
                    hl->snp_stat.a[ii].homopolymer_num = m_list;
                }
                
                i = i0;
            }

            l = k;
        }
    }
    hl->snp_stat.n = m_snp_stat; hl->length = m_list;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %xmm0, 0xa0(%rsp)
cmpl $0x0, 0x10(%rdi)
je 0x26c74
movq %rcx, %rbp
movq %rsi, %rax
movq %rdi, %rbx
movq %r8, 0xc0(%rsp)
movq 0x120(%rsp), %rdi
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %r12
subq $0x8, %rsp
pushq $-0x1
popq %rcx
xorl %esi, %esi
movq %r9, %r15
movq %rcx, %r8
xorl %r9d, %r9d
pushq $0x2
movq %rax, 0x18(%rsp)
callq 0x7638
movq 0x18(%rsp), %r14
addq $0x10, %rsp
movq %r15, 0x78(%rsp)
andq $0x0, (%r15)
movq 0x10(%r14), %rdx
cmpq %rdx, 0x8(%r12)
jae 0x25f98
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r12)
movq 0x10(%r12), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r12)
movq 0x10(%r14), %rdx
jmp 0x25f9d
movq 0x10(%r12), %rdi
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x20e0
movq 0x10(%r14), %rax
movq %rax, (%r12)
pushq $0x1
popq %r8
xorl %r10d, %r10d
xorl %r12d, %r12d
xorl %esi, %esi
xorl %edi, %edi
movq %r14, %r11
movq %rbp, 0x58(%rsp)
cmpq 0x220(%rbx), %r8
ja 0x266af
je 0x25fff
movq 0x218(%rbx), %rax
imulq $0x28, %r8, %rcx
movl 0x20(%rax,%rcx), %ecx
imulq $0x28, %r10, %rdx
cmpl 0x20(%rax,%rdx), %ecx
jne 0x25fff
movq %r12, %r15
movq %rsi, %r13
movq %rdi, %r14
jmp 0x2669e
movq %rdi, 0x28(%rsp)
movq %rsi, 0x40(%rsp)
movl 0x10(%rbx), %ecx
imulq $0x18, %r12, %r13
leaq 0xc(%r13), %r14
imulq $0x28, %r10, %r9
cmpq %rcx, %r12
jae 0x26c86
movq (%rbx), %rdx
movl (%rdx,%r13), %esi
movq 0x218(%rbx), %rax
cmpl 0x20(%rax,%r9), %esi
je 0x26043
incq %r12
addq $0x18, %r13
addq $0x18, %r14
jmp 0x26018
leaq 0x22d70e(%rip), %rdi    # 0x253758
movq 0x210(%rdi), %r11
movq %r11, 0x50(%rsp)
movq 0x218(%rdi), %rdi
movq %rdi, 0x30(%rsp)
movq %r9, 0x80(%rsp)
addq %rax, %r9
addq $0xc, %r9
movq %r10, (%rsp)
movq %r10, %r11
xorl %r10d, %r10d
movq %r8, 0x10(%rsp)
cmpq %r8, %r11
jae 0x2610f
movl -0x4(%r9), %edi
cmpq $0x2, %rdi
jb 0x260d0
movl (%r9), %r15d
cmpq $0x2, %r15
jb 0x260cb
cmpq $-0x1, %rbp
je 0x260b1
movq %rbp, %r8
movl -0x8(%r9), %ebp
addq %rbp, %r8
cmpq %rdi, %r8
jae 0x260d9
cmpq %rdi, 0x30(%rsp)
jg 0x260c6
xorl %edi, %edi
cmpq %r15, 0x50(%rsp)
setle %dil
addq %rdi, %r10
movq 0x58(%rsp), %rbp
movq 0x10(%rsp), %r8
incq %r11
addq $0x28, %r9
jmp 0x26080
cvtsi2sd %rdi, %xmm0
movl %ebp, %r8d
cvtsi2sd %r8, %xmm1
movapd %xmm0, %xmm2
mulsd 0xa0(%rsp), %xmm2
addsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
setae %r8b
cmpq %rdi, 0x30(%rsp)
setg %dil
orb %r8b, %dil
je 0x260b8
jmp 0x260c6
testq %r10, %r10
je 0x2634e
pxor %xmm0, %xmm0
movdqa %xmm0, 0x60(%rsp)
andl $0x0, 0x70(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x90(%rsp)
addq %r13, %rdx
pxor %xmm3, %xmm3
movq %r12, %r15
movq 0x8(%rsp), %r11
movq (%rsp), %r10
cmpq %rcx, %r15
jae 0x261ed
cmpl %esi, (%rdx)
jne 0x261ed
orl $-0x1, (%rdx)
movzbl 0xc(%rdx), %edi
testb $0x1, %dil
jne 0x26198
movq (%r11), %r8
movl 0x4(%rdx), %r9d
imulq $0xa8, %r9, %r9
xorl %r10d, %r10d
cmpl $0x0, 0x1c(%r8,%r9)
sete %r10b
movd %r10d, %xmm0
movq (%rsp), %r10
movaps 0x1bd300(%rip), %xmm1   # 0x1e3490
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
paddd %xmm1, %xmm3
cmpq $0x0, 0x120(%rsp)
je 0x261e1
testb $0x1, %dil
jne 0x261b5
testb $0x28, %dil
je 0x261e1
incl 0x70(%rsp)
jmp 0x261e1
movl 0x8(%rdx), %r9d
movzbl 0x14(%rdx), %r8d
leaq 0x22d46b(%rip), %r10    # 0x253630
movzbl (%r10,%r8), %r8d
movq (%rsp), %r10
movl %r9d, 0x90(%rsp,%r8,4)
testb $0x28, %dil
je 0x261e1
incl 0x60(%rsp,%r8,4)
incq %r15
addq $0x18, %rdx
jmp 0x26147
cmpq %r12, %r15
jbe 0x26d02
cmpq $0x0, 0x120(%rsp)
je 0x26368
movl 0x90(%rsp), %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpq %r8, %rcx
setne %dl
movl 0x60(%rsp), %edi
movl %edi, 0x8c(%rsp)
cmpl $0x2, %edi
setb %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x2623c
imulq $0x28, %rcx, %rcx
andl $0x0, 0xc(%rax,%rcx)
movl 0x94(%rsp), %ecx
cmpq %r8, %rcx
setne %dl
movl 0x64(%rsp), %edi
movl %edi, 0x50(%rsp)
cmpl $0x2, %edi
setb %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x2626a
imulq $0x28, %rcx, %rcx
andl $0x0, 0xc(%rax,%rcx)
movl 0x98(%rsp), %ecx
cmpq %r8, %rcx
setne %dl
movl 0x68(%rsp), %edi
movl %edi, 0x4c(%rsp)
cmpl $0x2, %edi
setb %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x26298
imulq $0x28, %rcx, %rcx
andl $0x0, 0xc(%rax,%rcx)
movdqa %xmm3, 0x30(%rsp)
movl 0x9c(%rsp), %ecx
cmpq %r8, %rcx
setne %dl
movl 0x6c(%rsp), %edi
movl %edi, 0x48(%rsp)
cmpl $0x2, %edi
setb %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x262cc
imulq $0x28, %rcx, %rcx
andl $0x0, 0xc(%rax,%rcx)
movq 0x120(%rsp), %rax
movq 0x10(%rax), %r8
movq 0x118(%rsp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
pushq $0x5
popq %r9
leaq 0xc8(%rsp), %rax
pushq %rax
leaq 0xd8(%rsp), %rax
pushq %rax
callq 0x25d2c
popq %rax
popq %rcx
cmpq $0x1, 0xd0(%rsp)
movl 0x70(%rsp), %eax
ja 0x2631b
cmpq $0x2, 0xc8(%rsp)
jb 0x26321
incl %eax
movl %eax, 0x70(%rsp)
movq 0x8(%rsp), %r11
movq (%rsp), %r10
movdqa 0x30(%rsp), %xmm3
movl 0x50(%rsp), %ecx
movl 0x4c(%rsp), %edx
movl 0x48(%rsp), %esi
cmpl $0x2, %eax
jb 0x2653a
movl 0x8c(%rsp), %eax
jmp 0x26380
movq %r8, %r10
movq %r12, %r15
movq 0x40(%rsp), %r13
movq 0x28(%rsp), %r14
movq 0x8(%rsp), %r11
jmp 0x2669e
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x60(%rsp)
orl $-0x1, 0x70(%rsp)
pushq $-0x1
popq %rax
movl %eax, %esi
movl %eax, %edx
movl %eax, %ecx
cmpl $0x2, %eax
setae %al
cmpl $0x2, %ecx
setae %cl
orb %al, %cl
cmpl $0x2, %edx
setae %al
cmpl $0x2, %esi
setae %dl
orb %al, %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x2653a
psubd 0x1bd0f1(%rip), %xmm3   # 0x1e34a0
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %r11
cmpq 0x10(%rsp), %r10
jae 0x26554
movq 0x218(%rbx), %rdx
imulq $0x28, %r10, %rax
movl 0x8(%rdx,%rax), %edi
cmpq $0x2, %rdi
jb 0x26532
leaq (%rdx,%rax), %rsi
movl 0xc(%rsi), %ecx
cmpq $0x2, %rcx
jb 0x26532
cmpq $-0x1, %rbp
je 0x2641f
movq %rbp, %r8
movq %r10, %rbp
movl 0x4(%rsi), %r9d
leaq (%r9,%r8), %r10
leaq 0x22d34d(%rip), %r8     # 0x253758
movq 0x218(%r8), %r8
cmpq %rdi, %r10
jae 0x26437
movq %rbp, %r10
movq %r11, %rbp
jmp 0x2642d
leaq 0x22d332(%rip), %r8     # 0x253758
movq 0x218(%r8), %r8
cmpq %rdi, %r8
jle 0x26473
jmp 0x26532
cvtsi2sd %rdi, %xmm0
movl %r9d, %r9d
cvtsi2sd %r9, %xmm1
movapd %xmm0, %xmm2
mulsd 0xa0(%rsp), %xmm2
addsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
setae %r9b
cmpq %rdi, %r8
setg %dil
orb %r9b, %dil
movq %rbp, %r10
movq %r11, %rbp
jne 0x26532
leaq 0x22d2de(%rip), %rdi    # 0x253758
cmpq %rcx, 0x210(%rdi)
jg 0x26532
imulq $0x28, (%rsp), %rcx
movq 0x20(%rsi), %rdi
movq %rdi, 0x20(%rdx,%rcx)
movdqu (%rsi), %xmm0
movupd 0x10(%rsi), %xmm1
movupd %xmm1, 0x10(%rdx,%rcx)
movdqu %xmm0, (%rdx,%rcx)
xorl %edx, %edx
movq %r14, %rsi
movq %r12, %rdi
cmpq %r15, %rdi
jae 0x2650f
movq (%rbx), %r8
movl -0x4(%r8,%rsi), %r9d
cmpq %r9, %r10
jne 0x264cb
cmpl $-0x1, -0xc(%r8,%rsi)
je 0x264d7
xorl %r9d, %r9d
testb $0x1, (%r8,%rsi)
je 0x264e0
jmp 0x26506
movzbl (%r8,%rsi), %r9d
andl $0x1, %r9d
movq (%rsp), %rbp
movl %ebp, -0x4(%r8,%rsi)
movq %r10, %rbp
movq 0x218(%rbx), %r10
movl 0x20(%r10,%rax), %r10d
movl %r10d, -0xc(%r8,%rsi)
movq %rbp, %r10
movq %r11, %rbp
addl %r9d, %edx
incq %rdi
addq $0x18, %rsi
jmp 0x264b1
movq 0x218(%rbx), %rax
movl %edx, 0xc(%rax,%rcx)
movq %xmm3, 0x4(%rax,%rcx)
movq 0x28(%rsp), %rdx
movl %edx, 0x18(%rax,%rcx)
incq (%rsp)
orl $-0x1, 0x1c(%rax,%rcx)
incq %r10
jmp 0x263bb
movq 0x10(%rsp), %r8
movq %r8, %r10
movq %r12, %r15
movq 0x40(%rsp), %r13
movq 0x28(%rsp), %r14
jmp 0x2669e
movq 0x28(%rsp), %r14
imulq $0x18, %r14, %rbp
movq 0x80(%rsp), %rdx
movq (%rbx), %rax
cmpq %r15, %r12
jae 0x265e9
movl (%rax,%r13), %ecx
cmpl $-0x1, %ecx
jne 0x2658b
orl $-0x1, 0x8(%rax,%r13)
movq 0x218(%rbx), %rcx
movl 0x20(%rcx,%rdx), %ecx
movl %ecx, (%rax,%r13)
movl 0x4(%rax,%r13), %esi
movl %ecx, %edx
movq 0x78(%rsp), %rax
movq (%rax), %r8
movq 0x10(%rax), %rcx
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl (%rax), %r9d
movq 0x110(%rsp), %rdi
callq 0x53c1f
movq 0x80(%rsp), %rdx
movq (%rbx), %rax
incq %r14
movq 0x10(%rax,%r13), %rcx
movq %rcx, 0x10(%rax,%rbp)
movdqu (%rax,%r13), %xmm0
movdqu %xmm0, (%rax,%rbp)
incq %r12
addq $0x18, %r13
addq $0x18, %rbp
jmp 0x26565
imulq $0x18, 0x28(%rsp), %rdi
addq %rax, %rdi
addq %rax, %rbp
movq %rbp, %rsi
callq 0x19538
movq 0x40(%rsp), %rsi
imulq $0x28, %rsi, %rax
addq $0x14, %rax
movq 0x78(%rsp), %rdx
movq 0x58(%rsp), %rbp
movq (%rsp), %r13
cmpq %r13, %rsi
jae 0x26631
movq 0x218(%rbx), %rcx
movl %r14d, (%rcx,%rax)
incq %rsi
addq $0x28, %rax
jmp 0x26618
movq (%rdx), %rcx
movq 0x10(%rdx), %rax
cmpq 0x8(%rdx), %rcx
jne 0x2666f
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x3, %rsi
movq %rax, %rdi
movq %rdx, %r12
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movq 0x8(%rsp), %r11
jmp 0x26677
movq 0x8(%rsp), %r11
movq %rdx, %r12
movq 0x218(%rbx), %rdx
movq 0x80(%rsp), %rsi
movl 0x20(%rdx,%rsi), %edx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %r8
movq %r8, %r10
incq %r8
movq %r15, %r12
movq %r13, %rsi
movq %r14, %rdi
jmp 0x25fc9
movq %rsi, 0x220(%rbx)
movl %edi, 0x10(%rbx)
testq %rsi, %rsi
movq 0x110(%rsp), %rax
je 0x26c74
testl %edi, %edi
je 0x26c74
movq (%rax), %rax
movq 0x10(%r11), %r14
cmpq %r14, %rax
jbe 0x2698c
xorl %r15d, %r15d
leaq 0xa8(%rsp), %r12
cmpq %rax, %r14
jae 0x26750
movb %r15b, 0xbc(%rsp)
movq 0x110(%rsp), %r13
movq 0x10(%r13), %rax
movq (%rax,%r14,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
movl %ecx, 0xac(%rsp)
movl %eax, 0xa8(%rsp)
orl $-0x1, 0xb0(%rsp)
movb %r15b, 0xb4(%rsp)
movl $0x1, 0xb8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x532ee
incq %r14
movq (%r13), %rax
jmp 0x266ed
movq (%rbx), %rdi
movl 0x10(%rbx), %eax
imulq $0x18, %rax, %rsi
addq %rdi, %rsi
callq 0x192d4
pushq $0x1
popq %r9
xorl %r14d, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
pcmpeqd %xmm2, %xmm2
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x8(%rsp), %r11
movq 0x220(%rbx), %rsi
cmpq %rsi, %r9
ja 0x2698c
je 0x267ad
movq 0x218(%rbx), %rax
imulq $0x28, %r9, %rcx
movl 0x20(%rax,%rcx), %ecx
imulq $0x28, %r13, %rdx
cmpl 0x20(%rax,%rdx), %ecx
je 0x26984
movl 0x10(%rbx), %ebp
imulq $0x18, %r15, %rdi
leaq 0x14(%rdi), %rax
leaq 0xc(%rdi), %r10
imulq $0x28, %r13, %rcx
cmpq %rbp, %r15
jae 0x26cc4
movq (%rbx), %rsi
movl (%rsi,%rdi), %r8d
movq 0x218(%rbx), %rdx
cmpl 0x20(%rdx,%rcx), %r8d
je 0x267ef
incq %r15
addq $0x18, %rdi
addq $0x18, %rax
addq $0x18, %r10
jmp 0x267c0
movq %r10, (%rsp)
movq %r9, 0x30(%rsp)
addq %rsi, %rdi
pxor %xmm3, %xmm3
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x0, 0x10(%rsp)
movq %rdi, %r10
movq %r15, %r9
cmpq %rbp, %r9
jae 0x2688a
cmpl %r8d, (%r10)
jne 0x26887
testb $0x1, 0xc(%r10)
jne 0x2686b
movq (%r11), %r14
movl 0x4(%r10), %ecx
movl 0x8(%r10), %r11d
imulq $0xa8, %rcx, %rcx
xorl %r12d, %r12d
cmpl $0x0, 0x1c(%r14,%rcx)
sete %r12b
movd %r12d, %xmm0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movaps 0x1bcc3c(%rip), %xmm1   # 0x1e3490
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
paddd %xmm1, %xmm3
cmpq %r12, %r11
je 0x26870
movb 0x14(%r10), %cl
movl %ecx, 0x10(%rsp)
jmp 0x26873
movq %rdx, %r11
jmp 0x26876
movq %rdx, %r11
xorl %r14d, %r14d
incq %r9
addq $0x18, %r10
movq %r11, %rdx
movq 0x8(%rsp), %r11
jmp 0x26812
movq %r9, %rbp
cmpq %r15, %rbp
movq (%rsp), %r10
jbe 0x26d7e
cmpq %r12, %rdx
je 0x26d5f
cmpb $0x0, 0x10(%rsp)
je 0x26d40
addq %rsi, %rax
movq %r15, %r9
pushq $0x1
popq %r8
cmpq %rbp, %r9
jae 0x268f7
testb $0x1, -0x8(%rax)
jne 0x268df
movl -0xc(%rax), %r10d
cmpq %r12, %r10
je 0x268d2
cmpq %r10, %rdx
jne 0x26ce3
movl %edx, -0xc(%rax)
movl 0x10(%rsp), %ecx
movb %cl, (%rax)
movq (%rsp), %r10
cmpq %r15, %r9
jbe 0x268ee
movl -0x10(%rax), %ecx
cmpl -0x28(%rax), %ecx
cmovbel %r14d, %r8d
incq %r9
addq $0x18, %rax
jmp 0x268b5
testl %r8d, %r8d
jne 0x26921
imulq $0x18, %rbp, %rax
addq %rax, %rsi
movdqa %xmm3, 0x10(%rsp)
callq 0x19538
movdqa 0x10(%rsp), %xmm3
movq (%rsp), %r10
pcmpeqd %xmm2, %xmm2
movq 0x8(%rsp), %r11
psubd %xmm2, %xmm3
movq 0x30(%rsp), %r9
cmpq %r9, %r13
jae 0x2697e
movq 0x218(%rbx), %rax
xorl %ecx, %ecx
movq %r10, %rdx
movq %r15, %rsi
cmpq %rbp, %rsi
jae 0x26962
movq (%rbx), %rdi
movl -0x4(%rdi,%rdx), %r8d
cmpq %r8, %r13
jne 0x26959
movzbl (%rdi,%rdx), %edi
andl $0x1, %edi
addl %edi, %ecx
incq %rsi
addq $0x18, %rdx
jmp 0x2693e
imulq $0x28, %r13, %rdx
movl %ecx, 0xc(%rax,%rdx)
movq %xmm3, 0x4(%rax,%rdx)
movl %r15d, 0x18(%rax,%rdx)
movl %ebp, 0x14(%rax,%rdx)
incq %r13
jmp 0x2692a
movq %r9, %r13
movq %rbp, %r15
incq %r9
jmp 0x2677e
movq 0x218(%rbx), %rdi
movq (%rbx), %rdx
leaq 0x22cdbb(%rip), %rcx    # 0x253758
movslq 0xd4(%rcx), %r9
movslq 0xd0(%rcx), %rax
movslq 0x1bc(%rcx), %r10
subq $0x8, %rsp
movq 0x1bcb32(%rip), %xmm0   # 0x1e34f0
movq 0xc8(%rsp), %rcx
movq 0x80(%rsp), %r8
movq 0x128(%rsp), %r11
pushq 0x10(%r11)
pushq 0x120(%rsp)
pushq $0x6
pushq %r10
pushq %rax
callq 0x25642
addq $0x30, %rsp
pushq $0x1
popq %r13
xorl %edi, %edi
pcmpeqd %xmm0, %xmm0
xorl %esi, %esi
movq $0x0, 0x30(%rsp)
xorl %r9d, %r9d
cmpq 0x220(%rbx), %r13
ja 0x26c64
je 0x26a34
movq 0x218(%rbx), %rax
imulq $0x28, %r13, %rdx
movl 0x20(%rax,%rdx), %edx
imulq $0x28, %rdi, %r8
cmpl 0x20(%rax,%r8), %edx
je 0x26c5c
movq %r9, (%rsp)
movl 0x10(%rbx), %r11d
imulq $0x18, %rsi, %r8
leaq 0xc(%r8), %r9
imulq $0x28, %rdi, %r10
cmpq %r11, %rsi
jae 0x26ca5
movq (%rbx), %r15
movl (%r15,%r8), %ebp
movq 0x218(%rbx), %r14
cmpl 0x20(%r14,%r10), %ebp
je 0x26a73
incq %rsi
addq $0x18, %r8
addq $0x18, %r9
jmp 0x26a48
movq %r13, 0x10(%rsp)
addq %r14, %r10
addq $0x1c, %r10
movq %rdi, %r13
xorl %r12d, %r12d
cmpq 0x10(%rsp), %r13
jae 0x26aa1
xorl %eax, %eax
cmpl $-0x1, (%r10)
setne %al
addq %rax, %r12
incq %r13
addq $0x28, %r10
jmp 0x26a85
testq %r12, %r12
je 0x26c50
addq %r8, %r15
pxor %xmm1, %xmm1
movq %rsi, %r10
movq 0x10(%rsp), %r13
cmpq %r11, %r10
jae 0x26b0a
cmpl %ebp, (%r15)
jne 0x26b0a
orl $-0x1, (%r15)
testb $0x1, 0xc(%r15)
jne 0x26b01
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x4(%r15), %edx
imulq $0xa8, %rdx, %rdx
xorl %r12d, %r12d
cmpl $0x0, 0x1c(%rax,%rdx)
sete %r12b
movd %r12d, %xmm2
movaps 0x1bc997(%rip), %xmm3   # 0x1e3490
movss %xmm2, %xmm3            # xmm3 = xmm2[0],xmm3[1,2,3]
paddd %xmm3, %xmm1
incq %r10
addq $0x18, %r15
jmp 0x26ab9
cmpq %rsi, %r10
jbe 0x26d21
psubd %xmm0, %xmm1
movq 0x30(%rsp), %r11
cmpq %r13, %rdi
jae 0x26be4
imulq $0x28, %rdi, %r12
cmpl $-0x1, 0x1c(%r14,%r12)
je 0x26bdc
leaq (%r14,%r12), %rax
imulq $0x28, %r11, %r15
movq 0x20(%rax), %rdx
movq %rdx, 0x20(%r14,%r15)
movdqu (%rax), %xmm2
movdqu 0x10(%rax), %xmm3
movdqu %xmm3, 0x10(%r14,%r15)
movdqu %xmm2, (%r14,%r15)
xorl %ebp, %ebp
movq %r9, %r14
movq %rsi, %r13
cmpq %r10, %r13
jae 0x26bb2
movq (%rbx), %rax
movl -0x4(%rax,%r14), %edx
cmpq %rdx, %rdi
jne 0x26b7e
cmpl $-0x1, -0xc(%rax,%r14)
je 0x26b89
xorl %edx, %edx
testb $0x1, (%rax,%r14)
je 0x26b91
jmp 0x26ba9
movzbl (%rax,%r14), %edx
andl $0x1, %edx
movl %r11d, -0x4(%rax,%r14)
movq 0x218(%rbx), %rcx
movl 0x20(%rcx,%r12), %ecx
movl %ecx, -0xc(%rax,%r14)
addl %edx, %ebp
incq %r13
addq $0x18, %r14
jmp 0x26b64
movq 0x218(%rbx), %r14
movl %ebp, 0xc(%r14,%r15)
movq %xmm1, 0x4(%r14,%r15)
movq (%rsp), %rax
movl %eax, 0x18(%r14,%r15)
incq %r11
orl $-0x1, 0x1c(%r14,%r15)
movq 0x10(%rsp), %r13
incq %rdi
jmp 0x26b1c
movq (%rsp), %r9
cmpq %r10, %rsi
jae 0x26c1d
movq (%rbx), %rax
cmpl $-0x1, (%rax,%r8)
je 0x26c14
leaq (%rax,%r8), %rcx
imulq $0x18, %r9, %rdx
incq %r9
movq 0x10(%rcx), %rdi
movq %rdi, 0x10(%rax,%rdx)
movdqu (%rcx), %xmm1
movdqu %xmm1, (%rax,%rdx)
incq %rsi
addq $0x18, %r8
jmp 0x26be8
movq 0x30(%rsp), %rdx
imulq $0x28, %rdx, %rax
addq $0x14, %rax
cmpq %r11, %rdx
jae 0x26c43
movq 0x218(%rbx), %rcx
movl %r9d, (%rcx,%rax)
incq %rdx
addq $0x28, %rax
jmp 0x26c2a
movq %r13, %rdi
movq %r10, %rsi
movq %r11, 0x30(%rsp)
jmp 0x26c5c
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq (%rsp), %r9
incq %r13
jmp 0x26a07
movq 0x30(%rsp), %rax
movq %rax, 0x220(%rbx)
movl %r9d, 0x10(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bd21e(%rip), %rdi    # 0x1e3eab
leaq 0x1bca0f(%rip), %rsi    # 0x1e36a3
leaq 0x1bd24d(%rip), %rcx    # 0x1e3ee8
movl $0x25bc, %edx           # imm = 0x25BC
callq 0x2110
leaq 0x1bd1ff(%rip), %rdi    # 0x1e3eab
leaq 0x1bc9f0(%rip), %rsi    # 0x1e36a3
leaq 0x1bd22e(%rip), %rcx    # 0x1e3ee8
movl $0x267d, %edx           # imm = 0x267D
callq 0x2110
leaq 0x1bd1e0(%rip), %rdi    # 0x1e3eab
leaq 0x1bc9d1(%rip), %rsi    # 0x1e36a3
leaq 0x1bd20f(%rip), %rcx    # 0x1e3ee8
movl $0x263c, %edx           # imm = 0x263C
callq 0x2110
leaq 0x1bd2be(%rip), %rdi    # 0x1e3fa8
leaq 0x1bc9b2(%rip), %rsi    # 0x1e36a3
leaq 0x1bd1f0(%rip), %rcx    # 0x1e3ee8
movl $0x2652, %edx           # imm = 0x2652
callq 0x2110
leaq 0x1bd27b(%rip), %rdi    # 0x1e3f84
leaq 0x1bc993(%rip), %rsi    # 0x1e36a3
leaq 0x1bd1d1(%rip), %rcx    # 0x1e3ee8
movl $0x25da, %edx           # imm = 0x25DA
callq 0x2110
leaq 0x1bd25c(%rip), %rdi    # 0x1e3f84
leaq 0x1bc974(%rip), %rsi    # 0x1e36a3
leaq 0x1bd1b2(%rip), %rcx    # 0x1e3ee8
movl $0x268c, %edx           # imm = 0x268C
callq 0x2110
leaq 0x1bd259(%rip), %rdi    # 0x1e3fa0
leaq 0x1bc955(%rip), %rsi    # 0x1e36a3
leaq 0x1bd193(%rip), %rcx    # 0x1e3ee8
movl $0x264d, %edx           # imm = 0x264D
callq 0x2110
leaq 0x1bd225(%rip), %rdi    # 0x1e3f8b
leaq 0x1bc936(%rip), %rsi    # 0x1e36a3
leaq 0x1bd174(%rip), %rcx    # 0x1e3ee8
movl $0x264c, %edx           # imm = 0x264C
callq 0x2110
leaq 0x1bd1ff(%rip), %rdi    # 0x1e3f84
leaq 0x1bc917(%rip), %rsi    # 0x1e36a3
leaq 0x1bd155(%rip), %rcx    # 0x1e3ee8
movl $0x264b, %edx           # imm = 0x264B
callq 0x2110