// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_haplotypes_naive_advance(haplotype_evdience_alloc*, overlap_region_alloc*, void*)
void generate_haplotypes_naive_advance(haplotype_evdience_alloc* hap, overlap_region_alloc* overlap_list, void *km)
{
    if(hap->length == 0) return;
    uint64_t k, l, i, o, *a, ii;
    int64_t z;
    SnpStats *s = NULL, *t = NULL;
    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].overlapSite == 55) {
                //     fprintf(stderr, "5555555555[M::%s::] utg%.6dl(%c), x_site::%u, x::[%u, %u), misBase::%c, occ_0::%u, occ_1::%u, occ_2::%u, snp_idx::%u\n", __func__, 
                //     ((int32_t)(overlap_list->list[hap->list[i].overlapID].y_id)) + 1,
                //     "+-"[overlap_list->list[hap->list[i].overlapID].y_pos_strand], 
                //     hap->list[i].site, overlap_list->list[hap->list[i].overlapID].x_pos_s,
                //     overlap_list->list[hap->list[i].overlapID].x_pos_e + 1, hap->list[i].misBase, 
                //     s->occ_0, s->occ_1, s->occ_2, hap->list[i].overlapSite);
                // }
                if(hap->list[i].type!=1) continue;///mismatch
                s = &(hap->snp_stat.a[hap->list[i].overlapSite]);
                // if(hap->list[i].overlapID == 125 || hap->list[i].overlapID == 127) {
                //     fprintf(stderr, "[M::%s::] utg%.6dl(%c), x_site::%u, x::[%u, %u), misBase::%c, occ_0::%u, occ_1::%u, occ_2::%u, snp_idx::%u\n", __func__, 
                //     ((int32_t)(overlap_list->list[hap->list[i].overlapID].y_id)) + 1,
                //     "+-"[overlap_list->list[hap->list[i].overlapID].y_pos_strand], 
                //     hap->list[i].site, overlap_list->list[hap->list[i].overlapID].x_pos_s,
                //     overlap_list->list[hap->list[i].overlapID].x_pos_e + 1, hap->list[i].misBase, 
                //     s->occ_0, s->occ_1, s->occ_2, 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++;///allels must be real
            }

            // if(hap->list[l].overlapID == 125 || hap->list[l].overlapID == 127) {
            //     fprintf(stderr, "+++[M::%s::] utg%.6dl(%c), o::%lu\n", __func__, 
            //     ((int32_t)(overlap_list->list[hap->list[l].overlapID].y_id)) + 1,
            //     "+-"[overlap_list->list[hap->list[l].overlapID].y_pos_strand], o);
            // }
            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;
        }
    }
    // fprintf(stderr, "\nhap->snp_srt.n: %u, overlap_list->length: %lu, x_id: %u\n", 
    // (uint32_t)hap->snp_srt.n, overlap_list->length, overlap_list->list[0].x_id);
    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(hap->list[l].overlapID == 125 || hap->list[l].overlapID == 127) {
            //     fprintf(stderr, "sbsbsb[M::%s::] utg%.6dl(%c), o::%lu\n", __func__, 
            //     ((int32_t)(overlap_list->list[hap->list[l].overlapID].y_id)) + 1,
            //     "+-"[overlap_list->list[hap->list[l].overlapID].y_pos_strand], 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) {
                    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);// if(t->occ_0 < 1) fprintf(stderr, "WRONG-CORRECTION\n");
                    }
                }
            }
        }

        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->score == 1) {
                    o++;
                    // if(hap->list[i].overlapID == 125 || hap->list[i].overlapID == 127) {
                    //     fprintf(stderr, "[M::%s::] utg%.6dl(%c), x_site::%u, x::[%u, %u), misBase::%c, occ_0::%u, occ_1::%u, occ_2::%u, snp_idx::%u\n", __func__, 
                    //     ((int32_t)(overlap_list->list[hap->list[i].overlapID].y_id)) + 1,
                    //     "+-"[overlap_list->list[hap->list[i].overlapID].y_pos_strand], 
                    //     hap->list[i].site, overlap_list->list[hap->list[i].overlapID].x_pos_s,
                    //     overlap_list->list[hap->list[i].overlapID].x_pos_e + 1, hap->list[i].misBase, 
                    //     s->occ_0, s->occ_1, s->occ_2, hap->list[i].overlapSite);
                    // }
                }
            }
            ii = hap->list[l].overlapID;
            // if(hap->list[l].overlapID == 125 || hap->list[l].overlapID == 127) {
            //     fprintf(stderr, ">>>[M::%s::] utg%.6dl(%c), o::%lu\n", __func__, 
            //     ((int32_t)(overlap_list->list[hap->list[l].overlapID].y_id)) + 1,
            //     "+-"[overlap_list->list[hap->list[l].overlapID].y_pos_strand], o);
            // }
            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;
            }
        }
    }

    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->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);
            }
            // if(hap->list[l].overlapID == 125 || hap->list[l].overlapID == 127) {
            //     fprintf(stderr, "---[M::%s::] utg%.6dl(%c), o::%lu\n", __func__, 
            //     ((int32_t)(overlap_list->list[hap->list[l].overlapID].y_id)) + 1,
            //     "+-"[overlap_list->list[hap->list[l].overlapID].y_pos_strand], o);
            // }
            hap->snp_srt.n -= o;
            if(o >= 2) {///there are at least two variants at one read
                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].is_match = 1;
            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;
        }
    }

    // for (i = k = 0; i < overlap_list->length; i++) {
    //     if(overlap_list->list[i].is_match == 2) k++;
    // }
    // for (i = l = 0; i < hap->snp_stat.n; i++) {
    //     s = &(hap->snp_stat.a[i]);
    //     if(s->score == 1 && (!(s->occ_0 < 2 || s->occ_1 < 2))) l++;
    // }
    // fprintf(stderr, "#trans ovlp: %lu, # snp:: %lu\n", k, l);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movl 0x10(%rdi), %eax
testq %rax, %rax
je 0x52bc3
movq %rdi, %r14
movq $0x0, 0x238(%rdi)
movq (%rdi), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x46275
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x5254a
movl $0x1, %ebx
xorl %r12d, %r12d
leaq 0x2383a7(%rip), %r15    # 0x28a758
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
xorl %ebp, %ebp
cmpq %rax, %rbx
je 0x523e2
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 0x52534
cmpq %rbx, %rbp
jae 0x52471
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 0x52463
movq 0x218(%r14), %rdi
movl -0x4(%rdx), %r8d
leaq (%r8,%r8,4), %r8
leaq (%rdi,%r8,8), %r12
movl 0x8(%r12), %edi
cmpq $0x2, %rdi
jb 0x52463
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 0x52415
jmp 0x52474
xorl %r13d, %r13d
testq %r13, %r13
je 0x52531
movq 0x238(%r14), %rax
cmpq $0x0, 0x10(%rsp)
je 0x524c6
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x5250a
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 0x10(%rsp), %rdi
callq 0x1e3800
jmp 0x524f9
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x5250a
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 0x523bd
jmp 0x5254d
xorl %r12d, %r12d
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x52719
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45d47
movq 0x238(%r14), %rbp
testq %rbp, %rbp
je 0x52721
movq 0x248(%r14), %rax
movq %rax, (%rsp)
movl 0x10(%r14), %esi
xorl %r13d, %r13d
xorl %edi, %edi
movq %rbp, 0x18(%rsp)
movq (%rsp), %rax
movl (%rax,%rdi,8), %r8d
movb $0x1, %dl
leaq (%r8,%r8,2), %rax
cmpl %r8d, %esi
jbe 0x52647
movq (%r14), %rcx
movq %rax, 0x20(%rsp)
leaq (%rcx,%rax,8), %r9
addq $0xc, %r9
movl -0x8(%r9), %r11d
leaq 0x238190(%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 0x52637
cmpb $0x1, (%r9)
jne 0x5262e
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 0x5262e
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 0x525df
testq %r15, %r15
sete %dl
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rax
testb %dl, %dl
jne 0x5270b
movq (%r14), %r9
movl 0x4(%r9,%rax,8), %r10d
movq 0x8(%rsp), %rax
movq (%rax), %rcx
imulq $0xa8, %r10, %rdx
cmpb $0x1, 0x2c(%rcx,%rdx)
jne 0x52678
leaq (%rcx,%rdx), %rax
addq $0x2c, %rax
movb $0x2, (%rax)
cmpl %r8d, %esi
jbe 0x5270b
leaq (%r8,%r8,2), %r15
cmpl %r10d, 0x4(%r9,%r15,8)
jne 0x5270b
leaq (%r9,%r15,8), %rdx
movzbl 0xc(%rdx), %ecx
testl %ecx, %ecx
je 0x526ba
cmpl $0x1, %ecx
jne 0x526ff
movq 0x218(%r14), %rax
movl 0x8(%rdx), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %r12
movl $0x1, 0x1c(%r12)
jmp 0x526ff
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 0x526ff
movl (%r15), %eax
subl %eax, 0x8(%r13)
je 0x52bd2
addq $-0x28, %r13
decq %r11
jg 0x526e0
movq %rdx, %r13
incq %r8
cmpq %rsi, %r8
jne 0x52681
incq %rdi
cmpq %rbp, %rdi
jne 0x52596
jmp 0x52724
xorl %r13d, %r13d
jmp 0x527f4
xorl %r13d, %r13d
testq %rbp, %rbp
je 0x527f4
movq 0x248(%r14), %rcx
movl 0x10(%r14), %edx
movq (%r14), %rsi
movq 0x8(%rsp), %rax
movq (%rax), %rdi
xorl %r8d, %r8d
movl (%rcx,%r8,8), %r9d
leaq (%r9,%r9,2), %r10
cmpl %r9d, %edx
jbe 0x527b3
movq (%r14), %rax
leaq (%rax,%r10,8), %r11
addq $0xc, %r11
movl -0x8(%r11), %ebx
movq %rdx, %r15
subq %r9, %r15
xorl %r9d, %r9d
cmpl %ebx, -0x8(%r11)
jne 0x527b6
cmpb $0x1, (%r11)
jne 0x527a8
movq 0x218(%r14), %rax
movl -0x4(%r11), %r12d
leaq (%r12,%r12,4), %r12
leaq (%rax,%r12,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x527a8
cmpl $0x2, 0xc(%r12)
jb 0x527a8
xorl %eax, %eax
cmpl $0x1, 0x1c(%r12)
sete %al
addq %rax, %r9
addq $0x18, %r11
decq %r15
jne 0x5276b
jmp 0x527b6
xorl %r9d, %r9d
movl 0x4(%rsi,%r10,8), %eax
imulq $0xa8, %rax, %rax
leaq (%rdi,%rax), %r10
addq $0x2c, %r10
cmpb $0x2, (%r10)
jne 0x527d9
testq %r9, %r9
jne 0x527d9
movb $0x1, (%r10)
cmpb $0x1, (%r10)
jne 0x527e8
testq %r9, %r9
je 0x527e8
movb $0x2, (%r10)
incq %r8
cmpq %rbp, %r8
jne 0x52746
movq $0x0, 0x238(%r14)
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x52aa3
movl $0x1, %ebx
xorl %ebp, %ebp
cmpq %rax, %rbx
je 0x52838
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 0x52a8f
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%r14), %rcx
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
movl 0x4(%rcx,%rdx,8), %ecx
imulq $0xa8, %rcx, %rcx
cmpb $0x2, 0x2c(%rax,%rcx)
je 0x52a8c
cmpq %rbx, %rbp
jae 0x5298c
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %r15
xorl %r8d, %r8d
movq (%r14), %rax
cmpb $0x1, 0xc(%rax,%r15)
jne 0x5297a
movq 0x218(%r14), %rcx
movl 0x8(%rax,%r15), %eax
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x5297a
cmpl $0x2, 0xc(%r12)
jb 0x5297a
cmpl $0x1, 0x1c(%r12)
je 0x5297a
movq 0x238(%r14), %rax
cmpq $0x0, 0x10(%rsp)
je 0x52910
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x52952
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 0x10(%rsp), %rdi
movq %r8, (%rsp)
callq 0x1e3800
jmp 0x52947
movq 0x240(%r14), %rcx
cmpq %rcx, %rax
jne 0x52952
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, (%rsp)
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x248(%r14)
incq %r8
movq (%r14), %rax
movl 0x8(%rax,%r15), %eax
movq 0x248(%r14), %rcx
movq 0x238(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x238(%r14)
movq %rax, (%rcx,%rdx,8)
incq %rbp
addq $0x18, %r15
cmpq %rbp, %rbx
jne 0x5287c
jmp 0x5298f
xorl %r8d, %r8d
movq 0x238(%r14), %rax
movq %rax, %rcx
subq %r8, %rcx
movq %rcx, 0x238(%r14)
cmpq $0x2, %r8
jb 0x52a8c
movq 0x248(%r14), %rdx
leaq (%rdx,%rcx,8), %rdi
leaq (%rdx,%rax,8), %rsi
movq %r8, %r15
callq 0x45d47
movq %r15, %r10
movq 0x238(%r14), %rax
shlq $0x3, %rax
addq 0x248(%r14), %rax
movq %r15, %rcx
negq %rcx
movl $0x1, %edx
xorl %esi, %esi
cmpq $0x1, %rdx
je 0x52a00
movq -0x10(%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r12
shlq $0x3, %r12
addq 0x218(%r14), %r12
cmpq %r10, %rdx
jae 0x52a18
movq (%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r13
shlq $0x3, %r13
addq 0x218(%r14), %r13
testq %r12, %r12
je 0x52a3c
movl 0x20(%r12), %edi
addl $0x20, %edi
movq 0x218(%r14), %r8
movq -0x8(%rax,%rdx,8), %r9
leaq (%r9,%r9,4), %r9
cmpl 0x20(%r8,%r9,8), %edi
ja 0x52a6b
testq %r13, %r13
je 0x52a5f
movq 0x218(%r14), %rdi
movq -0x8(%rax,%rdx,8), %r8
leaq (%r8,%r8,4), %r8
movl 0x20(%rdi,%r8,8), %edi
addl $0x20, %edi
cmpl 0x20(%r13), %edi
ja 0x52a6b
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 0x529e6
cmpq $0x2, %rsi
jl 0x52a8c
addq %rsi, 0x238(%r14)
movq %rbx, %rbp
leaq 0x1(%rbx), %rcx
movl 0x10(%r14), %eax
cmpq %rax, %rbx
movq %rcx, %rbx
jb 0x52813
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x52abf
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45d47
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x52bc3
movl $0x1, %ecx
xorl %edx, %edx
cmpq %rax, %rcx
je 0x52af6
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 0x52af6
movq %rdx, %r9
jmp 0x52b95
movq (%r14), %r10
leaq (%rdx,%rdx,2), %r11
movl 0x4(%r10,%r11,8), %edi
movq 0x8(%rsp), %rsi
movq (%rsi), %rsi
imulq $0xa8, %rdi, %rdi
leaq (%rsi,%rdi), %r8
addq $0x2c, %r8
cmpb $0x2, (%r8)
jne 0x52b23
movb $0x1, (%r8)
cmpb $0x1, (%r8)
sete %r9b
cmpq %rcx, %rdx
setb %bl
andb %r9b, %bl
movq %rcx, %r9
cmpb $0x1, %bl
jne 0x52b95
leaq (%rsi,%rdi), %r9
addq $0x2e, %r9
leaq (%r10,%r11,8), %r10
addq $0xc, %r10
movb (%r10), %r11b
cmpb $0x1, %r11b
ja 0x52b86
movq 0x218(%r14), %rbx
movl -0x4(%r10), %r15d
leaq (%r15,%r15,4), %r15
cmpl $0x1, 0x1c(%rbx,%r15,8)
jne 0x52b86
leaq (%rbx,%r15,8), %rbx
cmpl $0x2, 0x8(%rbx)
jb 0x52b86
cmpl $0x2, 0xc(%rbx)
jb 0x52b86
movb $0x1, (%r9)
cmpb $0x1, %r11b
je 0x52baa
incq %rdx
addq $0x18, %r10
cmpq %rdx, %rcx
jne 0x52b4c
movq %rcx, %r9
leaq 0x1(%rcx), %rsi
movq %r9, %rdx
cmpq %rax, %rcx
movq %rsi, %rcx
jne 0x52ad3
jmp 0x52bc3
movb $0x2, (%r8)
movl 0x8(%rsi,%rdi), %edx
subl 0x4(%rsi,%rdi), %edx
incl %edx
movq 0x8(%rsp), %rsi
subq %rdx, 0x18(%rsi)
jmp 0x52b92
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d2f61(%rip), %rdi    # 0x225b3a
leaq 0x1d2a63(%rip), %rsi    # 0x225643
leaq 0x1d2f61(%rip), %rcx    # 0x225b48
movl $0x21e0, %edx           # imm = 0x21E0
callq 0x2110