// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_haplotypes_naive_UL(haplotype_evdience_alloc*, overlap_region_alloc*, double, void*)
void generate_haplotypes_naive_UL(haplotype_evdience_alloc* hap, overlap_region_alloc* overlap_list, double up, void *km)
{
    if(hap->length == 0) return;
    uint64_t k, l, i, o, *a, ii, m_snp_stat, m_list, m_off;
    int64_t z; 
    SnpStats *s = NULL, *t = NULL;

    for (k = 1, l = 0, i = m_snp_stat = m_list = 0; k <= hap->snp_stat.n; ++k) {///filter snps
        if(k == hap->snp_stat.n || hap->snp_stat.a[k].site != hap->snp_stat.a[l].site) {
            if((l > 0) && (hap->snp_stat.a[l].site == (hap->snp_stat.a[l-1].site + 1))) {
                l = k; continue;
            }
            if((k < hap->snp_stat.n) && ((hap->snp_stat.a[l].site+1) == hap->snp_stat.a[k].site)) {
                l = k; continue;
            }

            for (; i < hap->length && hap->list[i].site != hap->snp_stat.a[l].site; i++);
            assert(i < hap->length && hap->list[i].site == hap->snp_stat.a[l].site);
            m_off = l - m_snp_stat; 
            for (; i < hap->length && hap->list[i].site == hap->snp_stat.a[l].site; i++) {
                assert(hap->list[i].overlapSite>=l && hap->list[i].overlapSite < k);
                // assert(hap->snp_stat.a[hap->list[i].overlapSite].site==hap->list[i].site);
                hap->list[m_list] = hap->list[i]; hap->list[m_list++].overlapSite -= m_off;
            }
        
            for (; l < k; l++) hap->snp_stat.a[m_snp_stat++] = hap->snp_stat.a[l];
        }
    }
    hap->snp_stat.n = m_snp_stat; hap->length = m_list;
    if(hap->snp_stat.n == 0 || hap->length == 0) return;

    hap->snp_srt.n = 0;
    radix_sort_haplotype_evdience_id_srt(hap->list, hap->list + hap->length);
    for (k = 1, l = 0; k <= hap->length; ++k) {  
        if (k == hap->length || hap->list[k].overlapID != hap->list[l].overlapID) {
            for (i = l, o = 0; i < k; i++) {
                if(hap->list[i].type!=1) continue;///mismatch
                s = &(hap->snp_stat.a[hap->list[i].overlapSite]); 
                assert(s->site == hap->list[i].site);
                if(s->occ_0 < 2 || s->occ_1 < 2) continue;
                if(s->occ_0 >= asm_opt.s_hap_cov && s->occ_1 >= asm_opt.infor_cov) o++;///allels must be real
            }
            if(o > 0) {
                o = ((uint32_t)-1) - o;
                o <<= 32; o += l; 
                if(!km) kv_push(uint64_t, hap->snp_srt, o);
                else kv_push_km(km, uint64_t, hap->snp_srt, o);
            }
            l = k;
        }
    }
    
    if (hap->snp_srt.n > 0) {
        radix_sort_bc64(hap->snp_srt.a, hap->snp_srt.a + hap->snp_srt.n);///sort by how many snps in one overlap
        for (k = 0; k < hap->snp_srt.n; k++) {
            o = 0; l = (uint32_t)hap->snp_srt.a[k];
            for (i = l; i < hap->length && hap->list[i].overlapID == hap->list[l].overlapID; i++) {
                if(hap->list[i].type!=1) continue;
                s = &(hap->snp_stat.a[hap->list[i].overlapSite]);
                if(s->occ_0 < 2 || s->occ_1 < 2) continue;
                if(s->occ_0 >= asm_opt.s_hap_cov && s->occ_1 >= asm_opt.infor_cov) o++;
            }
            if(o == 0) continue;

            ii = hap->list[l].overlapID;
            if(overlap_list->list[ii].is_match == 1) overlap_list->list[ii].is_match = 2;
            for (i = l; i < hap->length && hap->list[i].overlapID == hap->list[l].overlapID; i++) {
                if(hap->list[i].type==1){
                    s = &(hap->snp_stat.a[hap->list[i].overlapSite]);
                    s->score = 1; 
                } ///else if((hap->list[i].type==0) && (o>=(overlap_list->list[ii].align_length*up))) {
                else if(hap->list[i].type==0) {
                    ///not real allels
                    z = hap->list[i].overlapSite; s = &(hap->snp_stat.a[z]);
                    for (z = hap->list[i].overlapSite; z >= 0; z--) {
                        t = &(hap->snp_stat.a[z]);
                        if(s->site!=t->site) break;
                        t->occ_0 -= hap->list[i].cov;
                        assert(t->occ_0 >= 1);
                    }
                }
            }
        }

        for (k = 0; k < hap->snp_srt.n; k++) {///sorted by how many allels in each overlap; more -> less
            o = 0; l = (uint32_t)hap->snp_srt.a[k];
            for (i = l; i < hap->length && hap->list[i].overlapID == hap->list[l].overlapID; i++) {
                if(hap->list[i].type!=1) continue;
                s = &(hap->snp_stat.a[hap->list[i].overlapSite]);
                if(s->occ_0 < 2 || s->occ_1 < 2) continue;
                if(s->score == 1) o++;
            }
            ii = hap->list[l].overlapID;
            ///for HiFi, do not flip trans to cis
            // if(overlap_list->list[ii].is_match == 2 && o == 0) {
            //     overlap_list->list[ii].is_match = 1;
            // }
            if(overlap_list->list[ii].is_match == 1 && o > 0) {
                overlap_list->list[ii].is_match = 2;
            }
        }


        for (k = 1, l = 0; k <= hap->length; ++k) {  ///reset snp_stat
            if (k == hap->length || hap->list[k].overlapID != hap->list[l].overlapID) {
                ii = hap->list[l].overlapID;
                if(overlap_list->list[ii].is_match==1) {
                    for (i = l; i < k; i++) {
                        if(hap->list[i].type==1) {
                            hap->snp_stat.a[hap->list[i].overlapSite].score = -1;
                        }
                    }
                }
                l = k;
            }
        } 
    }

    

    hap->snp_srt.n = 0;
    for (k = 1, l = 0; k <= hap->length; ++k) {  
        if (k == hap->length || hap->list[k].overlapID != hap->list[l].overlapID) {
            if(overlap_list->list[hap->list[l].overlapID].is_match == 2) {
                l = k;
                continue;
            }
            for (i = l, o = 0; i < k; i++) {
                if(hap->list[i].type!=1) continue;
                s = &(hap->snp_stat.a[hap->list[i].overlapSite]);
                if(s->occ_0 < 2 || s->occ_1 < 2) continue;
                if(s->occ_0 >= asm_opt.s_hap_cov && s->occ_1 >= asm_opt.infor_cov) continue;
                if(s->score == 1) continue;
                o++; 
                if(!km) kv_push(uint64_t, hap->snp_srt, hap->list[i].overlapSite);
                else kv_push_km(km, uint64_t, hap->snp_srt, hap->list[i].overlapSite);
            }
            hap->snp_srt.n -= o;
            ///there are at least two variants at one read
            if(o>=(overlap_list->list[hap->list[l].overlapID].align_length*up)) {
                radix_sort_bc64(hap->snp_srt.a + hap->snp_srt.n, hap->snp_srt.a + hap->snp_srt.n + o);
                a = hap->snp_srt.a + hap->snp_srt.n;
                for (i = z = 0; i < o; i++) {
                    if(i > 0) s = &(hap->snp_stat.a[a[i-1]]);
                    if(i + 1 < o) t = &(hap->snp_stat.a[a[i+1]]);
                    if(s && s->site + 32 > hap->snp_stat.a[a[i]].site) continue;
                    if(t && hap->snp_stat.a[a[i]].site + 32 > t->site) continue;
                    a[z] = a[i];
                    z++;
                }
                if(z >= 2) hap->snp_srt.n += z; 
            }
            l = k;
        }
    }
    if (hap->snp_srt.n > 0) {
        radix_sort_bc64(hap->snp_srt.a, hap->snp_srt.a + hap->snp_srt.n);
        for (k = 1, l = 0; k <= hap->snp_srt.n; ++k) {  
            if(k == hap->snp_srt.n || hap->snp_srt.a[k] != hap->snp_srt.a[l]) {
                if(k - l >= 2) hap->snp_stat.a[hap->snp_srt.a[l]].score = 1;
            }
            l = k;
        }
    }

    for (k = 1, l = 0; k <= hap->length; ++k) {  
        if (k == hap->length || hap->list[k].overlapID != hap->list[l].overlapID) {
            ii = hap->list[l].overlapID;
            if(overlap_list->list[ii].is_match==2) {
                overlap_list->list[ii].strong = 1;
                overlap_list->mapped_overlaps_length -= 
                                            overlap_list->list[ii].x_pos_e + 1 - overlap_list->list[ii].x_pos_s;
            } else if(overlap_list->list[ii].is_match==1) {
                for (i = l; i < k; i++) {
                    if(hap->list[i].type==1 || hap->list[i].type==0) {
                        s = &(hap->snp_stat.a[hap->list[i].overlapSite]);
                        if(s->score == 1 && (!(s->occ_0 < 2 || s->occ_1 < 2))) {
                            overlap_list->list[ii].strong = 1;
                            if(hap->list[i].type==1) {
                                overlap_list->list[ii].is_match = 2;
                                overlap_list->mapped_overlaps_length -= 
                                            overlap_list->list[ii].x_pos_e + 1 - overlap_list->list[ii].x_pos_s;
                                break;
                            }
                        }
                    }

                }
            }
            l = k;
        }
    }    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x20(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
cmpl $0x0, 0x10(%rdi)
je 0x56273
movq %rdi, %rbx
movq 0x220(%rdi), %r8
testq %r8, %r8
je 0x55aaf
movl $0x1, %ecx
xorl %eax, %eax
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
cmpq %r8, %rcx
je 0x55749
movq 0x218(%rbx), %r9
leaq (%rcx,%rcx,4), %r10
movl 0x20(%r9,%r10,8), %r10d
leaq (%rsi,%rsi,4), %r11
cmpl 0x20(%r9,%r11,8), %r10d
je 0x558b2
testq %rsi, %rsi
je 0x55768
movq 0x218(%rbx), %r9
leaq (%rsi,%rsi,4), %r10
movl -0x8(%r9,%r10,8), %r11d
incl %r11d
cmpl %r11d, 0x20(%r9,%r10,8)
je 0x5578b
cmpq %r8, %rcx
jae 0x55793
movq 0x218(%rbx), %r8
leaq (%rsi,%rsi,4), %r9
movl 0x20(%r8,%r9,8), %r9d
incl %r9d
leaq (%rcx,%rcx,4), %r10
cmpl 0x20(%r8,%r10,8), %r9d
jne 0x55793
movq %rcx, %rsi
jmp 0x558b2
movl 0x10(%rbx), %r11d
cmpq %r11, %rdx
jae 0x56282
movq (%rbx), %r8
movq 0x218(%rbx), %r10
leaq (%rsi,%rsi,4), %r9
movl 0x20(%r10,%r9,8), %ebp
leaq (,%rdx,8), %r10
leaq (%r10,%r10,2), %r10
leaq (%r8,%r10), %r14
cmpl %ebp, (%r14)
je 0x557dd
incq %rdx
addq $0x18, %r14
addq $0x18, %r10
cmpq %rdx, %r11
jne 0x557c3
jmp 0x56282
cmpq %r11, %rdx
jae 0x55854
movl %edi, %r11d
subl %esi, %r11d
leaq (,%rax,8), %r14
leaq (%r14,%r14,2), %r14
movl (%r8,%r10), %ebp
movq 0x218(%rbx), %r15
cmpl 0x20(%r15,%r9,8), %ebp
jne 0x55854
movl 0x8(%r8,%r10), %r15d
cmpq %r15, %rsi
ja 0x562a1
cmpq %r15, %rcx
jbe 0x562a1
leaq (%r8,%r10), %r15
movq 0x10(%r15), %r12
movq %r12, 0x10(%r8,%r14)
movupd (%r15), %xmm0
movupd %xmm0, (%r8,%r14)
movq (%rbx), %r8
incq %rax
addl %r11d, 0x8(%r8,%r14)
incq %rdx
movl 0x10(%rbx), %r15d
addq $0x18, %r14
addq $0x18, %r10
cmpq %r15, %rdx
jb 0x557f4
cmpq %rcx, %rsi
jae 0x558b2
leaq (%rdi,%rcx), %r8
subq %rsi, %r8
shlq $0x3, %rdi
leaq (%rdi,%rdi,4), %rdi
leaq (,%rsi,8), %r9
leaq (%r9,%r9,4), %r9
movq 0x218(%rbx), %r10
movq 0x20(%r10,%r9), %r11
movq %r11, 0x20(%r10,%rdi)
movupd (%r10,%r9), %xmm0
movupd 0x10(%r10,%r9), %xmm1
movupd %xmm1, 0x10(%r10,%rdi)
movupd %xmm0, (%r10,%rdi)
incq %rsi
addq $0x28, %rdi
addq $0x28, %r9
cmpq %rsi, %rcx
jne 0x55874
movq %r8, %rdi
incq %rcx
movq 0x220(%rbx), %r8
cmpq %r8, %rcx
jbe 0x55725
movq %rdi, 0x220(%rbx)
movl %eax, 0x10(%rbx)
testq %rdi, %rdi
je 0x56273
testl %eax, %eax
je 0x56273
movq $0x0, 0x238(%rbx)
movq (%rbx), %rdi
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x45897
movl 0x10(%rbx), %edx
testq %rdx, %rdx
je 0x55abb
movl $0x1, %r14d
xorl %r12d, %r12d
leaq 0x23fe3f(%rip), %r15    # 0x295758
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
xorl %ebp, %ebp
cmpq %rdx, %r14
je 0x5594a
movq (%rbx), %rax
leaq (%r14,%r14,2), %rcx
movl 0x4(%rax,%rcx,8), %ecx
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
cmpl 0x4(%rax,%rdx,8), %ecx
je 0x55a9a
cmpq %r14, %rbp
jae 0x55a97
movq (%rbx), %rdx
movq 0x210(%r15), %rax
movq 0x218(%r15), %rcx
leaq (,%rbp,2), %rsi
addq %rbp, %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
xorl %r13d, %r13d
movq %rbp, %rsi
cmpb $0x1, (%rdx)
jne 0x559da
movq 0x218(%rbx), %rdi
movl -0x4(%rdx), %r8d
leaq (%r8,%r8,4), %r8
movl 0x20(%rdi,%r8,8), %r9d
cmpl -0xc(%rdx), %r9d
jne 0x562df
leaq (%rdi,%r8,8), %r12
movl 0x8(%r12), %edi
cmpq $0x2, %rdi
jb 0x559da
movl 0xc(%r12), %r8d
cmpl $0x2, %r8d
setae %r9b
cmpq %rdi, %rcx
setle %dil
movl %r8d, %r8d
cmpq %r8, %rax
setle %r8b
andb %r9b, %dil
andb %r8b, %dil
movzbl %dil, %edi
addq %rdi, %r13
incq %rsi
addq $0x18, %rdx
cmpq %rsi, %r14
jne 0x5597d
testq %r13, %r13
je 0x55a97
movq 0x238(%rbx), %rcx
movq 0x240(%rbx), %rdx
movq 0x248(%rbx), %rax
cmpq $0x0, 0x20(%rsp)
je 0x55a3b
cmpq %rdx, %rcx
jne 0x55a7b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x240(%rbx)
shlq $0x3, %rdx
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x1ee21d
jmp 0x55a63
cmpq %rdx, %rcx
jne 0x55a7b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x240(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
movq %rax, 0x248(%rbx)
movq 0x238(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x238(%rbx)
leaq (%rax,%rcx,8), %rax
shlq $0x20, %r13
subq %r13, %rbp
addq %r10, %rbp
movq %rbp, (%rax)
movq %r14, %rbp
leaq 0x1(%r14), %rax
movl 0x10(%rbx), %edx
cmpq %rdx, %r14
movq %rax, %r14
jb 0x55925
jmp 0x55ac0
movl $0x0, 0x10(%rbx)
jmp 0x56273
xorl %edx, %edx
xorl %r12d, %r12d
movq 0x238(%rbx), %rax
testq %rax, %rax
je 0x55d4c
movq 0x248(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45373
movq 0x238(%rbx), %r15
movl 0x10(%rbx), %edx
testq %r15, %r15
je 0x55d54
movq 0x248(%rbx), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
xorl %edi, %edi
movq %r15, 0x8(%rsp)
movq 0x18(%rsp), %rax
movl (%rax,%rdi,8), %r8d
cmpl %r8d, %edx
jbe 0x55c85
movq (%rbx), %rax
leaq (%r8,%r8,2), %rcx
movq %rcx, 0x28(%rsp)
leaq (%rax,%rcx,8), %r9
addq $0xc, %r9
movl -0x8(%r9), %r11d
leaq 0x23fc1e(%rip), %rax    # 0x295758
movq 0x210(%rax), %r14
movq 0x218(%rax), %rbp
movq %rdx, %rax
subq %r8, %rax
xorl %r15d, %r15d
cmpl %r11d, -0x8(%r9)
jne 0x55bac
cmpb $0x1, (%r9)
jne 0x55ba3
movq 0x218(%rbx), %rsi
movl -0x4(%r9), %r12d
leaq (%r12,%r12,4), %r12
leaq (%rsi,%r12,8), %r12
movl 0x8(%r12), %esi
cmpq $0x2, %rsi
jb 0x55ba3
movl 0xc(%r12), %ecx
cmpl $0x2, %ecx
setae %r10b
cmpq %rsi, %rbp
setle %sil
movl %ecx, %ecx
cmpq %rcx, %r14
setle %cl
andb %r10b, %sil
andb %cl, %sil
movzbl %sil, %ecx
addq %rcx, %r15
addq $0x18, %r9
decq %rax
jne 0x55b51
testq %r15, %r15
je 0x55c80
movq (%rbx), %r9
movq 0x28(%rsp), %rax
movl 0x4(%r9,%rax,8), %r10d
movq 0x10(%rsp), %rax
movq (%rax), %rax
imulq $0xa8, %r10, %rsi
cmpb $0x1, 0x2c(%rax,%rsi)
movq 0x8(%rsp), %r15
jne 0x55be7
addq %rsi, %rax
addq $0x2c, %rax
movb $0x2, (%rax)
cmpl %r8d, %edx
jbe 0x55c85
leaq (%r8,%r8,2), %r14
cmpl %r10d, 0x4(%r9,%r14,8)
jne 0x55c85
leaq (%r9,%r14,8), %rax
movzbl 0xc(%rax), %esi
testl %esi, %esi
je 0x55c2d
cmpl $0x1, %esi
jne 0x55c72
movq 0x218(%rbx), %rcx
movl 0x8(%rax), %eax
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r12
movl $0x1, 0x1c(%r12)
jmp 0x55c72
movl 0x8(%rax), %r11d
movq 0x218(%rbx), %rax
leaq (%r11,%r11,4), %rcx
leaq (%rax,%rcx,8), %r12
movl 0x20(%r12), %ebp
leaq (%r9,%r14,8), %r14
addq $0x10, %r14
incq %r11
movq %r12, %r13
cmpl 0x20(%r13), %ebp
jne 0x55c72
movl (%r14), %ecx
subl %ecx, 0x8(%r13)
je 0x562c0
addq $-0x28, %r13
decq %r11
jg 0x55c53
movq %rax, %r13
incq %r8
cmpq %rdx, %r8
jne 0x55bf0
jmp 0x55c85
movq 0x8(%rsp), %r15
incq %rdi
cmpq %r15, %rdi
jne 0x55b09
movq 0x248(%rbx), %rax
movq (%rbx), %rsi
movq 0x10(%rsp), %rcx
movq (%rcx), %rdi
leaq 0xc(%rsi), %r8
xorl %r9d, %r9d
movl (%rax,%r9,8), %r14d
cmpl %r14d, %edx
jbe 0x55d3e
leaq (,%r14,8), %rcx
leaq (%rcx,%rcx,2), %r11
movl 0x4(%rsi,%r11), %r10d
movq %rdx, %r15
subq %r14, %r15
addq %r8, %r11
xorl %r14d, %r14d
cmpl %r10d, -0x8(%r11)
jne 0x55d1a
cmpb $0x1, (%r11)
jne 0x55d11
movq 0x218(%rbx), %rcx
movl -0x4(%r11), %r12d
leaq (%r12,%r12,4), %r12
leaq (%rcx,%r12,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x55d11
cmpl $0x2, 0xc(%r12)
jb 0x55d11
xorl %ecx, %ecx
cmpl $0x1, 0x1c(%r12)
sete %cl
addq %rcx, %r14
addq $0x18, %r11
decq %r15
jne 0x55cd4
imulq $0xa8, %r10, %r10
cmpb $0x1, 0x2c(%rdi,%r10)
movq 0x8(%rsp), %r15
jne 0x55d3e
testq %r14, %r14
je 0x55d3e
leaq (%rdi,%r10), %rcx
addq $0x2c, %rcx
movb $0x2, (%rcx)
incq %r9
cmpq %r15, %r9
jne 0x55caa
jmp 0x55d57
xorl %r13d, %r13d
jmp 0x55e0d
xorl %r13d, %r13d
testl %edx, %edx
je 0x56167
movq (%rbx), %rcx
leaq 0xc(%rcx), %rax
movl $0x1, %esi
xorl %edi, %edi
cmpq %rdx, %rsi
jne 0x55d7d
leaq (%rdi,%rdi,2), %r8
movl 0x4(%rcx,%r8,8), %r8d
jmp 0x55d96
leaq (%rsi,%rsi,2), %r9
leaq (%rdi,%rdi,2), %r8
movl 0x4(%rcx,%r8,8), %r8d
cmpl %r8d, 0x4(%rcx,%r9,8)
jne 0x55d96
movq %rdi, %r8
jmp 0x55dfa
movl %r8d, %r8d
movq 0x10(%rsp), %r9
movq (%r9), %r9
imulq $0xa8, %r8, %r8
cmpb $0x1, 0x2c(%r9,%r8)
sete %r8b
cmpq %rsi, %rdi
setb %r9b
andb %r8b, %r9b
movq %rsi, %r8
cmpb $0x1, %r9b
jne 0x55dfa
leaq (%rdi,%rdi,2), %r8
leaq (%rax,%r8,8), %r8
cmpb $0x1, (%r8)
jne 0x55deb
movq 0x218(%rbx), %r9
movl -0x4(%r8), %r10d
leaq (%r10,%r10,4), %r10
movl $0xffffffff, 0x1c(%r9,%r10,8) # imm = 0xFFFFFFFF
incq %rdi
addq $0x18, %r8
cmpq %rdi, %rsi
jne 0x55dcd
movq %rsi, %r8
leaq 0x1(%rsi), %r9
movq %r8, %rdi
cmpq %rdx, %rsi
movq %r9, %rsi
jne 0x55d6d
movq $0x0, 0x238(%rbx)
testl %edx, %edx
je 0x56172
movl %edx, %eax
movl $0x1, %r15d
xorl %r9d, %r9d
leaq 0x23f926(%rip), %r10    # 0x295758
movq (%rbx), %rcx
cmpq %rax, %r15
jne 0x55e44
leaq (%r9,%r9,2), %rax
movl 0x4(%rcx,%rax,8), %edx
jmp 0x55e5a
leaq (%r15,%r15,2), %rax
leaq (%r9,%r9,2), %rdx
movl 0x4(%rcx,%rdx,8), %edx
cmpl %edx, 0x4(%rcx,%rax,8)
je 0x56128
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl %edx, %edx
imulq $0xa8, %rdx, %rsi
cmpb $0x2, 0x2c(%rax,%rsi)
je 0x56125
cmpq %r15, %r9
jae 0x55fd8
leaq (,%r9,8), %rax
leaq (%rax,%rax,2), %r14
xorl %r8d, %r8d
movq %r9, %rbp
cmpb $0x1, 0xc(%rcx,%r14)
jne 0x55fb6
movq 0x218(%rbx), %rax
movl 0x8(%rcx,%r14), %edx
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %r12
movl 0x8(%r12), %eax
cmpq $0x2, %rax
jb 0x55fb6
movl 0xc(%r12), %edx
cmpq $0x2, %rdx
jb 0x55fb6
cmpq %rax, 0x218(%r10)
jg 0x55ee5
cmpq %rdx, 0x210(%r10)
jle 0x55fb6
cmpl $0x1, 0x1c(%r12)
je 0x55fb6
incq %r8
movq 0x238(%rbx), %rdi
movq 0x240(%rbx), %rdx
movq 0x248(%rbx), %rax
cmpq $0x0, 0x20(%rsp)
je 0x55f4e
cmpq %rdx, %rdi
jne 0x55fa2
leaq (%rdi,%rdi), %rdx
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x240(%rbx)
shlq $0x3, %rdx
movq 0x20(%rsp), %rdi
movq %rax, %rsi
movq %r8, 0x18(%rsp)
movq %r9, 0x8(%rsp)
callq 0x1ee21d
jmp 0x55f80
cmpq %rdx, %rdi
jne 0x55fa2
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x240(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r8, 0x18(%rsp)
movq %r9, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %r9
movq 0x18(%rsp), %r8
leaq 0x23f7c7(%rip), %r10    # 0x295758
movq %rax, 0x248(%rbx)
movq (%rbx), %rcx
movq 0x238(%rbx), %rdi
movl 0x8(%rcx,%r14), %edx
leaq 0x1(%rdi), %rsi
movq %rsi, 0x238(%rbx)
movq %rdx, (%rax,%rdi,8)
incq %rbp
addq $0x18, %r14
cmpq %rbp, %r15
jne 0x55e91
movq 0x10(%rsp), %rax
movq (%rax), %rax
leaq (%r9,%r9,2), %rdx
movl 0x4(%rcx,%rdx,8), %edx
jmp 0x55fdb
xorl %r8d, %r8d
movq 0x238(%rbx), %rcx
movq %rcx, %rsi
subq %r8, %rsi
movq %rsi, 0x238(%rbx)
movq %r8, %xmm0
punpckldq 0x1db284(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1db28c(%rip), %xmm0   # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
imulq $0xa8, %rdx, %rdx
movl 0x28(%rax,%rdx), %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
addsd %xmm0, %xmm1
mulsd 0x30(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jb 0x56125
movq 0x248(%rbx), %rax
leaq (%rax,%rsi,8), %rdi
leaq (%rax,%rcx,8), %rsi
movq %r8, %r14
callq 0x45373
testq %r14, %r14
je 0x5613d
movq %r14, %r11
movq 0x238(%rbx), %rax
shlq $0x3, %rax
addq 0x248(%rbx), %rax
movq %r14, %rcx
negq %rcx
movl $0x1, %edx
xorl %esi, %esi
leaq 0x23f6dc(%rip), %r10    # 0x295758
cmpq $0x1, %rdx
je 0x56096
movq -0x10(%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r12
shlq $0x3, %r12
addq 0x218(%rbx), %r12
cmpq %r11, %rdx
jae 0x560ae
movq (%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r13
shlq $0x3, %r13
addq 0x218(%rbx), %r13
testq %r12, %r12
je 0x560d2
movl 0x20(%r12), %edi
addl $0x20, %edi
movq 0x218(%rbx), %r8
movq -0x8(%rax,%rdx,8), %r9
leaq (%r9,%r9,4), %r9
cmpl 0x20(%r8,%r9,8), %edi
ja 0x56104
testq %r13, %r13
je 0x560f8
movq 0x218(%rbx), %r8
movq -0x8(%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r9
movl 0x20(%r8,%r9,8), %r8d
addl $0x20, %r8d
cmpl 0x20(%r13), %r8d
jbe 0x560fd
jmp 0x56104
movq -0x8(%rax,%rdx,8), %rdi
movq %rdi, (%rax,%rsi,8)
incq %rsi
leaq (%rcx,%rdx), %rdi
incq %rdi
incq %rdx
cmpq $0x1, %rdi
jne 0x5607c
cmpq $0x2, %rsi
jl 0x56125
addq %rsi, 0x238(%rbx)
movq %r15, %r9
leaq 0x1(%r15), %rcx
movl 0x10(%rbx), %eax
cmpq %rax, %r15
movq %rcx, %r15
jb 0x55e32
jmp 0x56149
movq %r15, %r9
leaq 0x23f611(%rip), %r10    # 0x295758
jmp 0x56128
movq 0x238(%rbx), %rax
testq %rax, %rax
je 0x56172
movq 0x248(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45373
jmp 0x56172
movq $0x0, 0x238(%rbx)
movl 0x10(%rbx), %eax
testq %rax, %rax
je 0x56273
movq (%rbx), %rcx
leaq 0xc(%rcx), %rdx
movl $0x1, %esi
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r14
cmpq %rax, %rsi
jne 0x5619c
movl 0x4(%rcx,%r14,8), %r8d
jmp 0x561b4
leaq (%rsi,%rsi,2), %r9
movl 0x4(%rcx,%r14,8), %r8d
cmpl %r8d, 0x4(%rcx,%r9,8)
jne 0x561b4
movq %rdi, %r11
jmp 0x56256
movl %r8d, %r8d
movq 0x10(%rsp), %r9
movq (%r9), %r9
imulq $0xa8, %r8, %r10
leaq (%r9,%r10), %r8
movzbl 0x2c(%r9,%r10), %ebp
cmpl $0x2, %ebp
je 0x5623b
movq %rsi, %r11
cmpl $0x1, %ebp
jne 0x56256
movq %rsi, %r11
cmpq %rsi, %rdi
jae 0x56256
leaq (%r9,%r10), %r11
addq $0x2e, %r11
leaq (%rdx,%r14,8), %r14
movb (%r14), %bpl
cmpb $0x1, %bpl
ja 0x5622d
movq 0x218(%rbx), %r15
movl -0x4(%r14), %r12d
leaq (%r12,%r12,4), %r12
cmpl $0x1, 0x1c(%r15,%r12,8)
jne 0x5622d
leaq (%r15,%r12,8), %r15
cmpl $0x2, 0x8(%r15)
jb 0x5622d
cmpl $0x2, 0xc(%r15)
jb 0x5622d
movb $0x1, (%r11)
cmpb $0x1, %bpl
je 0x5626b
incq %rdi
addq $0x18, %r14
cmpq %rdi, %rsi
jne 0x561f1
jmp 0x56253
movb $0x1, 0x2e(%r8)
movl 0x8(%r8), %edi
subl 0x4(%r8), %edi
incl %edi
movq 0x10(%rsp), %r8
subq %rdi, 0x18(%r8)
movq %rsi, %r11
leaq 0x1(%rsi), %r8
movq %r11, %rdi
cmpq %rax, %rsi
movq %r8, %rsi
jne 0x5618c
jmp 0x56273
movb $0x2, 0x2c(%r9,%r10)
jmp 0x56240
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1dba7f(%rip), %rdi    # 0x231d08
leaq 0x1db4c3(%rip), %rsi    # 0x231753
leaq 0x1dbe0e(%rip), %rcx    # 0x2320a5
movl $0x26c9, %edx           # imm = 0x26C9
callq 0x2110
leaq 0x1dbb27(%rip), %rdi    # 0x231dcf
leaq 0x1db4a4(%rip), %rsi    # 0x231753
leaq 0x1dbdef(%rip), %rcx    # 0x2320a5
movl $0x26cc, %edx           # imm = 0x26CC
callq 0x2110
leaq 0x1db983(%rip), %rdi    # 0x231c4a
leaq 0x1db485(%rip), %rsi    # 0x231753
leaq 0x1dbdd0(%rip), %rcx    # 0x2320a5
movl $0x2706, %edx           # imm = 0x2706
callq 0x2110
leaq 0x1dbb25(%rip), %rdi    # 0x231e0b
leaq 0x1db466(%rip), %rsi    # 0x231753
leaq 0x1dbdb1(%rip), %rcx    # 0x2320a5
movl $0x26de, %edx           # imm = 0x26DE
callq 0x2110