// File: /workspace/github_cpp_makefile_star2_O3/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 0x51d35
movq %rdi, %r14
movq $0x0, 0x238(%rdi)
movq (%rdi), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x45897
movl 0x10(%r14), %ecx
testq %rcx, %rcx
je 0x516ee
movl $0x1, %ebx
xorl %r12d, %r12d
leaq 0x2441f2(%rip), %r15    # 0x295758
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
xorl %ebp, %ebp
cmpq %rcx, %rbx
je 0x51597
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 0x516d8
cmpq %rbx, %rbp
jae 0x516d5
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 0x51618
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 0x51618
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 0x515ca
testq %r13, %r13
je 0x516d5
movq 0x238(%r14), %rcx
movq 0x240(%r14), %rdx
movq 0x248(%r14), %rax
cmpq $0x0, 0x10(%rsp)
je 0x51679
cmpq %rdx, %rcx
jne 0x516b9
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x240(%r14)
shlq $0x3, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1ee21d
jmp 0x516a1
cmpq %rdx, %rcx
jne 0x516b9
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x240(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
movq %rax, 0x248(%r14)
movq 0x238(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x238(%r14)
leaq (%rax,%rcx,8), %rax
shlq $0x20, %r13
subq %r13, %rbp
addq %r10, %rbp
movq %rbp, (%rax)
movq %rbx, %rbp
leaq 0x1(%rbx), %rax
movl 0x10(%r14), %ecx
cmpq %rcx, %rbx
movq %rax, %rbx
jb 0x51572
jmp 0x516f3
xorl %ecx, %ecx
xorl %r12d, %r12d
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x51979
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45373
movq 0x238(%r14), %rbp
movl 0x10(%r14), %ecx
testq %rbp, %rbp
je 0x51979
movq 0x248(%r14), %rax
movq %rax, (%rsp)
xorl %r13d, %r13d
xorl %edi, %edi
movq %rbp, 0x18(%rsp)
movq (%rsp), %rax
movl (%rax,%rdi,8), %r8d
cmpl %r8d, %ecx
jbe 0x518ac
movq (%r14), %rax
leaq (%r8,%r8,2), %rdx
movq %rdx, 0x20(%rsp)
leaq (%rax,%rdx,8), %r9
addq $0xc, %r9
movl -0x8(%r9), %r11d
leaq 0x243fec(%rip), %rax    # 0x295758
movq 0x210(%rax), %rbx
movq 0x218(%rax), %rbp
movq %rcx, %rax
subq %r8, %rax
xorl %r15d, %r15d
cmpl %r11d, -0x8(%r9)
jne 0x517de
cmpb $0x1, (%r9)
jne 0x517d5
movq 0x218(%r14), %rsi
movl -0x4(%r9), %r12d
leaq (%r12,%r12,4), %r12
leaq (%rsi,%r12,8), %r12
movl 0x8(%r12), %esi
cmpq $0x2, %rsi
jb 0x517d5
movl 0xc(%r12), %edx
cmpl $0x2, %edx
setae %r10b
cmpq %rsi, %rbp
setle %sil
movl %edx, %edx
cmpq %rdx, %rbx
setle %dl
andb %r10b, %sil
andb %dl, %sil
movzbl %sil, %edx
addq %rdx, %r15
addq $0x18, %r9
decq %rax
jne 0x51783
testq %r15, %r15
movq 0x18(%rsp), %rbp
je 0x518ac
movq (%r14), %r9
movq 0x20(%rsp), %rax
movl 0x4(%r9,%rax,8), %r10d
movq 0x8(%rsp), %rax
movq (%rax), %rax
imulq $0xa8, %r10, %rsi
cmpb $0x1, 0x2c(%rax,%rsi)
jne 0x51819
addq %rsi, %rax
addq $0x2c, %rax
movb $0x2, (%rax)
cmpl %r8d, %ecx
jbe 0x518ac
leaq (%r8,%r8,2), %r15
cmpl %r10d, 0x4(%r9,%r15,8)
jne 0x518ac
leaq (%r9,%r15,8), %rax
movzbl 0xc(%rax), %esi
testl %esi, %esi
je 0x5185b
cmpl $0x1, %esi
jne 0x518a0
movq 0x218(%r14), %rdx
movl 0x8(%rax), %eax
leaq (%rax,%rax,4), %rax
leaq (%rdx,%rax,8), %r12
movl $0x1, 0x1c(%r12)
jmp 0x518a0
movl 0x8(%rax), %r11d
movq 0x218(%r14), %rax
leaq (%r11,%r11,4), %rdx
leaq (%rax,%rdx,8), %r12
movl 0x20(%r12), %ebx
leaq (%r9,%r15,8), %r15
addq $0x10, %r15
incq %r11
movq %r12, %r13
cmpl 0x20(%r13), %ebx
jne 0x518a0
movl (%r15), %edx
subl %edx, 0x8(%r13)
je 0x51d44
addq $-0x28, %r13
decq %r11
jg 0x51881
movq %rax, %r13
incq %r8
cmpq %rcx, %r8
jne 0x51822
incq %rdi
cmpq %rbp, %rdi
jne 0x5173c
movq 0x248(%r14), %rdx
movq (%r14), %rsi
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0xc(%rsi), %r8
xorl %r9d, %r9d
movl (%rdx,%r9,8), %r10d
leaq (%r10,%r10,2), %rbx
movl 0x4(%rsi,%rbx,8), %r11d
cmpl %r10d, %ecx
jbe 0x51939
movq %rcx, %rax
subq %r10, %rax
leaq (%r8,%rbx,8), %rbx
xorl %r10d, %r10d
cmpl %r11d, -0x8(%rbx)
jne 0x5193c
cmpb $0x1, (%rbx)
jne 0x5192e
movq 0x218(%r14), %r15
movl -0x4(%rbx), %r12d
leaq (%r12,%r12,4), %r12
leaq (%r15,%r12,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x5192e
cmpl $0x2, 0xc(%r12)
jb 0x5192e
xorl %r15d, %r15d
cmpl $0x1, 0x1c(%r12)
sete %r15b
addq %r15, %r10
addq $0x18, %rbx
decq %rax
jne 0x518f0
jmp 0x5193c
xorl %r10d, %r10d
imulq $0xa8, %r11, %rax
movb 0x2c(%rdi,%rax), %bl
cmpb $0x2, %bl
jne 0x51954
movb $0x1, %r11b
testq %r10, %r10
je 0x51961
cmpb $0x1, %bl
jne 0x5196b
movb $0x2, %r11b
testq %r10, %r10
je 0x5196b
addq %rdi, %rax
addq $0x2c, %rax
movb %r11b, (%rax)
incq %r9
cmpq %rbp, %r9
jne 0x518d1
jmp 0x5197c
xorl %r13d, %r13d
movq $0x0, 0x238(%r14)
testl %ecx, %ecx
je 0x51c2b
movl %ecx, %eax
movl $0x1, %ebx
xorl %ebp, %ebp
movq (%r14), %rcx
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
cmpq %rax, %rbx
jne 0x519b1
movl 0x4(%rcx,%rdx,8), %eax
jmp 0x519c3
leaq (%rbx,%rbx,2), %rsi
movl 0x4(%rcx,%rdx,8), %eax
cmpl %eax, 0x4(%rcx,%rsi,8)
je 0x51bfb
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movl %eax, %eax
imulq $0xa8, %rax, %rax
cmpb $0x2, 0x2c(%rdx,%rax)
setne %al
cmpq %rbx, %rbp
setb %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x51bf8
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %r15
xorl %r8d, %r8d
cmpb $0x1, 0xc(%rcx,%r15)
jne 0x51ae8
movq 0x218(%r14), %rax
movl 0x8(%rcx,%r15), %edx
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x51ae8
cmpl $0x2, 0xc(%r12)
jb 0x51ae8
cmpl $0x1, 0x1c(%r12)
je 0x51ae8
incq %r8
movq 0x238(%r14), %rdi
movq 0x240(%r14), %rdx
movq 0x248(%r14), %rax
cmpq $0x0, 0x10(%rsp)
je 0x51a93
cmpq %rdx, %rdi
jne 0x51ad4
leaq (%rdi,%rdi), %rdx
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x240(%r14)
shlq $0x3, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r8, (%rsp)
callq 0x1ee21d
jmp 0x51abf
cmpq %rdx, %rdi
jne 0x51ad4
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x240(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r8, (%rsp)
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x248(%r14)
movq (%r14), %rcx
movq 0x238(%r14), %rdi
movl 0x8(%rcx,%r15), %edx
leaq 0x1(%rdi), %rsi
movq %rsi, 0x238(%r14)
movq %rdx, (%rax,%rdi,8)
incq %rbp
addq $0x18, %r15
cmpq %rbp, %rbx
jne 0x519fc
movq 0x238(%r14), %rax
movq %rax, %rcx
subq %r8, %rcx
movq %rcx, 0x238(%r14)
cmpq $0x2, %r8
jb 0x51bf8
movq 0x248(%r14), %rdx
leaq (%rdx,%rcx,8), %rdi
leaq (%rdx,%rax,8), %rsi
movq %r8, %r15
callq 0x45373
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 0x51b69
movq -0x10(%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r12
shlq $0x3, %r12
addq 0x218(%r14), %r12
cmpq %r10, %rdx
jae 0x51b81
movq (%rax,%rdx,8), %rdi
leaq (%rdi,%rdi,4), %r13
shlq $0x3, %r13
addq 0x218(%r14), %r13
testq %r12, %r12
je 0x51ba5
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 0x51bd7
testq %r13, %r13
je 0x51bcb
movq 0x218(%r14), %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 0x51bd0
jmp 0x51bd7
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 0x51b4f
cmpq $0x2, %rsi
jl 0x51bf8
addq %rsi, 0x238(%r14)
movq %rbx, %rbp
leaq 0x1(%rbx), %rcx
movl 0x10(%r14), %eax
cmpq %rax, %rbx
movq %rcx, %rbx
jb 0x51998
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x51c2b
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45373
movl 0x10(%r14), %eax
testq %rax, %rax
je 0x51d35
movq (%r14), %rcx
leaq 0xc(%rcx), %rdx
movl $0x1, %esi
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r11
cmpq %rax, %rsi
jne 0x51c56
movl 0x4(%rcx,%r11,8), %r8d
jmp 0x51c6e
leaq (%rsi,%rsi,2), %r9
movl 0x4(%rcx,%r11,8), %r8d
cmpl %r8d, 0x4(%rcx,%r9,8)
jne 0x51c6e
movq %rdi, %rbx
jmp 0x51d05
movl %r8d, %r9d
movq 0x8(%rsp), %r8
movq (%r8), %r8
imulq $0xa8, %r9, %r9
leaq (%r8,%r9), %r10
addq $0x2c, %r10
movb (%r10), %bl
cmpb $0x2, %bl
jne 0x51c96
movb $0x1, (%r10)
movb $0x1, %bl
cmpb $0x1, %bl
sete %bl
cmpq %rsi, %rdi
setb %bpl
andb %bl, %bpl
movq %rsi, %rbx
cmpb $0x1, %bpl
jne 0x51d05
leaq (%r8,%r9), %rbx
addq $0x2e, %rbx
leaq (%rdx,%r11,8), %r11
movb (%r11), %bpl
cmpb $0x1, %bpl
ja 0x51cf6
movq 0x218(%r14), %r15
movl -0x4(%r11), %r12d
leaq (%r12,%r12,4), %r12
cmpl $0x1, 0x1c(%r15,%r12,8)
jne 0x51cf6
leaq (%r15,%r12,8), %r15
cmpl $0x2, 0x8(%r15)
jb 0x51cf6
cmpl $0x2, 0xc(%r15)
jb 0x51cf6
movb $0x1, (%rbx)
cmpb $0x1, %bpl
je 0x51d1a
incq %rdi
addq $0x18, %r11
cmpq %rdi, %rsi
jne 0x51cbb
movq %rsi, %rbx
leaq 0x1(%rsi), %r8
movq %rbx, %rdi
cmpq %rax, %rsi
movq %r8, %rsi
jne 0x51c46
jmp 0x51d35
movb $0x2, (%r10)
movl 0x8(%r8,%r9), %edi
subl 0x4(%r8,%r9), %edi
incl %edi
movq 0x8(%rsp), %r8
subq %rdi, 0x18(%r8)
jmp 0x51d02
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1dfeff(%rip), %rdi    # 0x231c4a
leaq 0x1dfa01(%rip), %rsi    # 0x231753
leaq 0x1dfeff(%rip), %rcx    # 0x231c58
movl $0x21e0, %edx           # imm = 0x21E0
callq 0x2110