// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
cmpl $0x0, 0x10(%rdi)
je 0x56da8
movq %rdi, %r14
movq 0x220(%rdi), %r9
testq %r9, %r9
movq %rsi, 0x18(%rsp)
je 0x563fa
movl $0x1, %edx
movq $-0x1, %rsi
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %edi, %edi
cmpq %r9, %rdx
je 0x56228
movq 0x218(%r14), %r10
leaq (%rdx,%rdx,4), %r11
movl 0x20(%r10,%r11,8), %r11d
leaq (%r8,%r8,4), %rbx
cmpl 0x20(%r10,%rbx,8), %r11d
je 0x563e2
testq %r8, %r8
je 0x56246
movq 0x218(%r14), %r10
leaq (%r8,%r8,4), %r11
movl -0x8(%r10,%r11,8), %ebx
incl %ebx
cmpl %ebx, 0x20(%r10,%r11,8)
je 0x56269
cmpq %r9, %rdx
jae 0x56271
movq 0x218(%r14), %r9
leaq (%r8,%r8,4), %r10
movl 0x20(%r9,%r10,8), %r10d
incl %r10d
leaq (%rdx,%rdx,4), %r11
cmpl 0x20(%r9,%r11,8), %r10d
jne 0x56271
movq %rdx, %r8
jmp 0x563e2
movl 0x10(%r14), %r10d
cmpq %r10, %rdi
setb %bl
jae 0x56db7
movq (%r14), %r15
movq 0x218(%r14), %r11
leaq (%r8,%r8,4), %r9
movl 0x20(%r11,%r9,8), %r11d
leaq (%rdi,%rdi,2), %r12
cmpl %r11d, (%r15,%r12,8)
je 0x562c8
leaq (%r15,%r12,8), %r15
addq $0x18, %r15
leaq -0x1(%r10), %rbx
cmpq %rdi, %rbx
je 0x56db7
leaq 0x18(%r15), %r12
incq %rdi
cmpl %r11d, (%r15)
movq %r12, %r15
jne 0x562aa
cmpq %r10, %rdi
setb %bl
testb %bl, %bl
je 0x56db7
movq (%r14), %r10
leaq (%rdi,%rdi,2), %r11
movl (%r10,%r11,8), %r10d
movq 0x218(%r14), %r11
cmpl 0x20(%r11,%r9,8), %r10d
jne 0x56db7
movl 0x10(%r14), %r10d
cmpq %r10, %rdi
jae 0x5637d
movl %ecx, %r10d
subl %r8d, %r10d
leaq (,%rax,8), %r11
leaq (%r11,%r11,2), %r11
leaq (,%rdi,8), %rbx
leaq (%rbx,%rbx,2), %rbx
movq (%r14), %r15
movl (%r15,%rbx), %ebp
movq 0x218(%r14), %r12
cmpl 0x20(%r12,%r9,8), %ebp
jne 0x5637d
movl 0x8(%r15,%rbx), %r12d
cmpq %r12, %r8
ja 0x56df5
cmpq %r12, %rdx
jbe 0x56df5
leaq (%r15,%rbx), %r12
movq 0x10(%r12), %r13
movq %r13, 0x10(%r15,%r11)
movupd (%r12), %xmm0
movupd %xmm0, (%r15,%r11)
movq (%r14), %r15
incq %rax
addl %r10d, 0x8(%r15,%r11)
incq %rdi
movl 0x10(%r14), %r15d
addq $0x18, %r11
addq $0x18, %rbx
cmpq %r15, %rdi
jb 0x56318
cmpq %rdx, %r8
jae 0x563e2
leaq (%r8,%rsi), %r9
leaq (,%rcx,8), %r10
leaq (%r10,%r10,4), %r10
leaq (,%r8,8), %r11
leaq (%r11,%r11,4), %rbx
xorl %r11d, %r11d
movq 0x218(%r14), %r15
movq 0x20(%r15,%rbx), %r12
movq %r12, 0x20(%r15,%r10)
movupd (%r15,%rbx), %xmm0
movupd 0x10(%r15,%rbx), %xmm1
movupd %xmm1, 0x10(%r15,%r10)
movupd %xmm0, (%r15,%r10)
decq %r11
addq $0x28, %r10
addq $0x28, %rbx
cmpq %r11, %r9
jne 0x563a1
subq %r11, %rcx
subq %r11, %r8
incq %rdx
movq 0x220(%r14), %r9
decq %rsi
cmpq %r9, %rdx
jbe 0x56204
jmp 0x563fe
xorl %ecx, %ecx
xorl %eax, %eax
movq %rcx, 0x220(%r14)
movl %eax, 0x10(%r14)
testq %rcx, %rcx
je 0x56da8
testl %eax, %eax
je 0x56da8
movq $0x0, 0x238(%r14)
movq (%r14), %rdi
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x46275
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x565fb
movl $0x1, %ebx
xorl %r12d, %r12d
leaq 0x234305(%rip), %r15    # 0x28a758
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
xorl %ebp, %ebp
cmpq %rax, %rbx
je 0x56484
movq (%r14), %rax
leaq (%rbx,%rbx,2), %rcx
movl 0x4(%rax,%rcx,8), %ecx
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
cmpl 0x4(%rax,%rdx,8), %ecx
je 0x565e5
cmpq %rbx, %rbp
jae 0x56522
movq (%r14), %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 0x56514
movq 0x218(%r14), %rdi
movl -0x4(%rdx), %r8d
leaq (%r8,%r8,4), %r8
movl 0x20(%rdi,%r8,8), %r9d
cmpl -0xc(%rdx), %r9d
jne 0x56e14
leaq (%rdi,%r8,8), %r12
movl 0x8(%r12), %edi
cmpq $0x2, %rdi
jb 0x56514
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, %rbx
jne 0x564b7
jmp 0x56525
xorl %r13d, %r13d
testq %r13, %r13
je 0x565e2
movq 0x238(%r14), %rax
cmpq $0x0, 0x20(%rsp)
je 0x56577
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x565bb
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x240(%r14)
movq 0x248(%r14), %rsi
shlq $0x3, %rdx
movq 0x20(%rsp), %rdi
callq 0x1e3800
jmp 0x565aa
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x565bb
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x240(%r14)
movq 0x248(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
movq %rax, 0x248(%r14)
shlq $0x20, %r13
subq %r13, %rbp
addq %r10, %rbp
movq 0x238(%r14), %rax
movq 0x248(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x238(%r14)
movq %rbp, (%rcx,%rax,8)
movq %rbx, %rbp
leaq 0x1(%rbx), %rcx
movl 0x10(%r14), %eax
cmpq %rax, %rbx
movq %rcx, %rbx
jb 0x5645f
jmp 0x565fe
xorl %r12d, %r12d
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x567cf
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45d47
movq 0x238(%r14), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq 0x18(%rsp), %rbp
je 0x567dc
movq 0x248(%r14), %rax
movq %rax, 0x10(%rsp)
movl 0x10(%r14), %esi
xorl %r13d, %r13d
xorl %edi, %edi
movq 0x10(%rsp), %rax
movl (%rax,%rdi,8), %r8d
movb $0x1, %dl
leaq (%r8,%r8,2), %rax
cmpl %r8d, %esi
jbe 0x566ff
movq (%r14), %rcx
movq %rax, 0x30(%rsp)
leaq (%rcx,%rax,8), %r9
addq $0xc, %r9
movl -0x8(%r9), %r11d
leaq 0x2340d8(%rip), %rax    # 0x28a758
movq 0x210(%rax), %rbx
movq 0x218(%rax), %rbp
movq %rsi, %rdx
subq %r8, %rdx
xorl %r15d, %r15d
cmpl %r11d, -0x8(%r9)
jne 0x566ef
cmpb $0x1, (%r9)
jne 0x566e6
movq 0x218(%r14), %rcx
movl -0x4(%r9), %r12d
leaq (%r12,%r12,4), %r12
leaq (%rcx,%r12,8), %r12
movl 0x8(%r12), %ecx
cmpq $0x2, %rcx
jb 0x566e6
movl 0xc(%r12), %eax
cmpl $0x2, %eax
setae %r10b
cmpq %rcx, %rbp
setle %cl
movl %eax, %eax
cmpq %rax, %rbx
setle %al
andb %r10b, %cl
andb %al, %cl
movzbl %cl, %eax
addq %rax, %r15
addq $0x18, %r9
decq %rdx
jne 0x56697
testq %r15, %r15
sete %dl
movq 0x18(%rsp), %rbp
movq 0x30(%rsp), %rax
testb %dl, %dl
jne 0x567bf
movq (%r14), %r9
movl 0x4(%r9,%rax,8), %r10d
movq (%rbp), %rcx
imulq $0xa8, %r10, %rdx
cmpb $0x1, 0x2c(%rcx,%rdx)
jne 0x5672c
leaq (%rcx,%rdx), %rax
addq $0x2c, %rax
movb $0x2, (%rax)
cmpl %r8d, %esi
jbe 0x567bf
leaq (%r8,%r8,2), %r15
cmpl %r10d, 0x4(%r9,%r15,8)
jne 0x567bf
leaq (%r9,%r15,8), %rdx
movzbl 0xc(%rdx), %ecx
testl %ecx, %ecx
je 0x5676e
cmpl $0x1, %ecx
jne 0x567b3
movq 0x218(%r14), %rax
movl 0x8(%rdx), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %r12
movl $0x1, 0x1c(%r12)
jmp 0x567b3
movl 0x8(%rdx), %r11d
movq 0x218(%r14), %rdx
leaq (%r11,%r11,4), %rax
leaq (%rdx,%rax,8), %r12
movl 0x20(%r12), %ebx
leaq (%r9,%r15,8), %r15
addq $0x10, %r15
incq %r11
movq %r12, %r13
cmpl 0x20(%r13), %ebx
jne 0x567b3
movl (%r15), %eax
subl %eax, 0x8(%r13)
je 0x56dd6
addq $-0x28, %r13
decq %r11
jg 0x56794
movq %rdx, %r13
incq %r8
cmpq %rsi, %r8
jne 0x56735
incq %rdi
cmpq 0x8(%rsp), %rdi
jne 0x5664d
jmp 0x567df
xorl %r13d, %r13d
movq 0x18(%rsp), %rbp
jmp 0x56958
xorl %r13d, %r13d
cmpq $0x0, 0x8(%rsp)
je 0x568a9
movq 0x248(%r14), %rcx
movl 0x10(%r14), %edx
movq (%r14), %rsi
movq (%rbp), %rdi
xorl %r8d, %r8d
movl (%rcx,%r8,8), %r11d
leaq (%r11,%r11,2), %r9
cmpl %r11d, %edx
jbe 0x56874
movq (%r14), %rax
leaq (%rax,%r9,8), %r10
addq $0xc, %r10
movl -0x8(%r10), %ebx
movq %rdx, %r15
subq %r11, %r15
xorl %r11d, %r11d
cmpl %ebx, -0x8(%r10)
jne 0x5686b
cmpb $0x1, (%r10)
jne 0x56862
movq 0x218(%r14), %rax
movl -0x4(%r10), %r12d
leaq (%r12,%r12,4), %r12
leaq (%rax,%r12,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x56862
cmpl $0x2, 0xc(%r12)
jb 0x56862
xorl %eax, %eax
cmpl $0x1, 0x1c(%r12)
sete %al
addq %rax, %r11
addq $0x18, %r10
decq %r15
jne 0x56825
testq %r11, %r11
setne %r10b
jmp 0x56877
xorl %r10d, %r10d
movl 0x4(%rsi,%r9,8), %eax
imulq $0xa8, %rax, %r9
cmpb $0x1, 0x2c(%rdi,%r9)
jne 0x5689b
testb %r10b, %r10b
je 0x5689b
leaq (%rdi,%r9), %rax
addq $0x2c, %rax
movb $0x2, (%rax)
incq %r8
cmpq 0x8(%rsp), %r8
jne 0x56800
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x56958
movl $0x1, %ecx
xorl %edx, %edx
cmpq %rax, %rcx
je 0x568dd
movq (%r14), %rsi
leaq (%rcx,%rcx,2), %rdi
movl 0x4(%rsi,%rdi,8), %edi
leaq (%rdx,%rdx,2), %r8
cmpl 0x4(%rsi,%r8,8), %edi
jne 0x568dd
movq %rdx, %r8
jmp 0x56945
movq (%r14), %rsi
leaq (%rdx,%rdx,2), %rdi
movl 0x4(%rsi,%rdi,8), %r8d
movq (%rbp), %r9
imulq $0xa8, %r8, %r8
cmpb $0x1, 0x2c(%r9,%r8)
sete %r8b
cmpq %rcx, %rdx
setb %r9b
andb %r8b, %r9b
movq %rcx, %r8
cmpb $0x1, %r9b
jne 0x56945
leaq (%rsi,%rdi,8), %rsi
addq $0xc, %rsi
cmpb $0x1, (%rsi)
jne 0x56936
movq 0x218(%r14), %rdi
movl -0x4(%rsi), %r8d
leaq (%r8,%r8,4), %r8
movl $0xffffffff, 0x1c(%rdi,%r8,8) # imm = 0xFFFFFFFF
incq %rdx
addq $0x18, %rsi
cmpq %rdx, %rcx
jne 0x56919
movq %rcx, %r8
leaq 0x1(%rcx), %rsi
movq %r8, %rdx
cmpq %rax, %rcx
movq %rsi, %rcx
jne 0x568bd
movq $0x0, 0x238(%r14)
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x56c97
movl $0x1, %ebx
xorl %r15d, %r15d
leaq 0x233dd9(%rip), %rdi    # 0x28a758
cmpq %rax, %rbx
je 0x5699d
movq (%r14), %rax
leaq (%rbx,%rbx,2), %rcx
movl 0x4(%rax,%rcx,8), %ecx
leaq (%r15,%r15,2), %rdx
cmpl 0x4(%rax,%rdx,8), %ecx
je 0x56c83
movq (%rbp), %rax
movq (%r14), %rcx
leaq (%r15,%r15,2), %r9
movl 0x4(%rcx,%r9,8), %ecx
imulq $0xa8, %rcx, %rcx
cmpb $0x2, 0x2c(%rax,%rcx)
je 0x56b85
cmpq %rbx, %r15
jae 0x56b1d
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rbp
xorl %r8d, %r8d
movq (%r14), %rax
cmpb $0x1, 0xc(%rax,%rbp)
jne 0x56b0b
movq 0x218(%r14), %rcx
movl 0x8(%rax,%rbp), %eax
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r12
movl 0x8(%r12), %eax
cmpq $0x2, %rax
jb 0x56b0b
movl 0xc(%r12), %ecx
cmpq $0x2, %rcx
jb 0x56b0b
cmpq %rax, 0x218(%rdi)
jg 0x56a2c
cmpq %rcx, 0x210(%rdi)
jle 0x56b0b
cmpl $0x1, 0x1c(%r12)
je 0x56b0b
movq 0x238(%r14), %rax
cmpq $0x0, 0x20(%rsp)
je 0x56a8f
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x56ae4
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x240(%r14)
movq 0x248(%r14), %rsi
shlq $0x3, %rdx
movq 0x20(%rsp), %rdi
movq %r8, 0x8(%rsp)
movq %r9, 0x10(%rsp)
callq 0x1e3800
jmp 0x56acc
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x56ae4
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x240(%r14)
movq 0x248(%r14), %rdi
shlq $0x3, %rsi
movq %r8, 0x8(%rsp)
movq %r9, 0x10(%rsp)
callq 0x2370
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
leaq 0x233c7b(%rip), %rdi    # 0x28a758
movq %rax, 0x248(%r14)
incq %r8
movq (%r14), %rax
movl 0x8(%rax,%rbp), %eax
movq 0x248(%r14), %rcx
movq 0x238(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x238(%r14)
movq %rax, (%rcx,%rdx,8)
incq %r15
addq $0x18, %rbp
cmpq %r15, %rbx
jne 0x569d7
jmp 0x56b20
xorl %r8d, %r8d
movq 0x238(%r14), %rax
movq %rax, %rcx
subq %r8, %rcx
movq %rcx, 0x238(%r14)
movq %r8, %xmm0
punpckldq 0x1ce6ff(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1ce707(%rip), %xmm0   # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movq 0x18(%rsp), %rbp
movq (%rbp), %rdx
movq (%r14), %rsi
movl 0x4(%rsi,%r9,8), %esi
imulq $0xa8, %rsi, %rsi
movl 0x28(%rdx,%rsi), %edx
xorps %xmm2, %xmm2
cvtsi2sd %rdx, %xmm2
addsd %xmm0, %xmm1
mulsd 0x28(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jae 0x56b8d
movq %rbx, %r15
jmp 0x56c83
movq 0x248(%r14), %rdx
leaq (%rdx,%rcx,8), %rdi
leaq (%rdx,%rax,8), %rsi
movq %r8, %r15
callq 0x45d47
testq %r15, %r15
je 0x56c6a
movq %r15, %r10
movq 0x238(%r14), %rax
shlq $0x3, %rax
addq 0x248(%r14), %rax
movq %r15, %rdx
negq %rdx
movl $0x1, %esi
xorl %ecx, %ecx
cmpq $0x1, %rsi
je 0x56be9
movq -0x10(%rax,%rsi,8), %rdi
leaq (%rdi,%rdi,4), %r12
shlq $0x3, %r12
addq 0x218(%r14), %r12
cmpq %r10, %rsi
jae 0x56c01
movq (%rax,%rsi,8), %rdi
leaq (%rdi,%rdi,4), %r13
shlq $0x3, %r13
addq 0x218(%r14), %r13
testq %r12, %r12
je 0x56c25
movl 0x20(%r12), %edi
addl $0x20, %edi
movq 0x218(%r14), %r8
movq -0x8(%rax,%rsi,8), %r9
leaq (%r9,%r9,4), %r9
cmpl 0x20(%r8,%r9,8), %edi
ja 0x56c54
testq %r13, %r13
je 0x56c48
movq 0x218(%r14), %rdi
movq -0x8(%rax,%rsi,8), %r8
leaq (%r8,%r8,4), %r8
movl 0x20(%rdi,%r8,8), %edi
addl $0x20, %edi
cmpl 0x20(%r13), %edi
ja 0x56c54
movq -0x8(%rax,%rsi,8), %rdi
movq %rdi, (%rax,%rcx,8)
incq %rcx
leaq (%rdx,%rsi), %rdi
incq %rdi
incq %rsi
cmpq $0x1, %rdi
jne 0x56bcf
jmp 0x56c6c
xorl %ecx, %ecx
cmpq $0x2, %rcx
jl 0x56c79
addq %rcx, 0x238(%r14)
movq %rbx, %r15
leaq 0x233ad5(%rip), %rdi    # 0x28a758
leaq 0x1(%rbx), %rcx
movl 0x10(%r14), %eax
cmpq %rax, %rbx
movq %rcx, %rbx
jb 0x5697f
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x56cb3
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45d47
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x56da8
movl $0x1, %ecx
xorl %edx, %edx
cmpq %rax, %rcx
je 0x56cea
movq (%r14), %rsi
leaq (%rcx,%rcx,2), %rdi
movl 0x4(%rsi,%rdi,8), %edi
leaq (%rdx,%rdx,2), %r8
cmpl 0x4(%rsi,%r8,8), %edi
jne 0x56cea
movq %rdx, %r9
jmp 0x56d8b
movq (%r14), %r10
leaq (%rdx,%rdx,2), %r11
movl 0x4(%r10,%r11,8), %esi
movq (%rbp), %rdi
imulq $0xa8, %rsi, %r8
leaq (%rdi,%r8), %rsi
movzbl 0x2c(%rdi,%r8), %ebx
cmpl $0x2, %ebx
je 0x56d78
movq %rcx, %r9
cmpl $0x1, %ebx
jne 0x56d8b
movq %rcx, %r9
cmpq %rcx, %rdx
jae 0x56d8b
leaq (%rdi,%r8), %r9
addq $0x2e, %r9
leaq (%r10,%r11,8), %r10
addq $0xc, %r10
movb (%r10), %r11b
cmpb $0x1, %r11b
ja 0x56d6a
movq 0x218(%r14), %rbx
movl -0x4(%r10), %r15d
leaq (%r15,%r15,4), %r15
cmpl $0x1, 0x1c(%rbx,%r15,8)
jne 0x56d6a
leaq (%rbx,%r15,8), %rbx
cmpl $0x2, 0x8(%rbx)
jb 0x56d6a
cmpl $0x2, 0xc(%rbx)
jb 0x56d6a
movb $0x1, (%r9)
cmpb $0x1, %r11b
je 0x56da0
incq %rdx
addq $0x18, %r10
cmpq %rdx, %rcx
jne 0x56d30
jmp 0x56d88
movb $0x1, 0x2e(%rsi)
movl 0x8(%rsi), %edx
subl 0x4(%rsi), %edx
incl %edx
subq %rdx, 0x18(%rbp)
movq %rcx, %r9
leaq 0x1(%rcx), %rsi
movq %r9, %rdx
cmpq %rax, %rcx
movq %rsi, %rcx
jne 0x56cc7
jmp 0x56da8
movb $0x2, 0x2c(%rdi,%r8)
jmp 0x56d7c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cee3a(%rip), %rdi    # 0x225bf8
leaq 0x1ce87e(%rip), %rsi    # 0x225643
leaq 0x1cf1c9(%rip), %rcx    # 0x225f95
movl $0x26c9, %edx           # imm = 0x26C9
callq 0x2110
leaq 0x1ced5d(%rip), %rdi    # 0x225b3a
leaq 0x1ce85f(%rip), %rsi    # 0x225643
leaq 0x1cf1aa(%rip), %rcx    # 0x225f95
movl $0x2706, %edx           # imm = 0x2706
callq 0x2110
leaq 0x1ceec3(%rip), %rdi    # 0x225cbf
leaq 0x1ce840(%rip), %rsi    # 0x225643
leaq 0x1cf18b(%rip), %rcx    # 0x225f95
movl $0x26cc, %edx           # imm = 0x26CC
callq 0x2110
leaq 0x1ceee0(%rip), %rdi    # 0x225cfb
leaq 0x1ce821(%rip), %rsi    # 0x225643
leaq 0x1cf16c(%rip), %rcx    # 0x225f95
movl $0x26de, %edx           # imm = 0x26DE
callq 0x2110