// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movl 0x10(%rdi), %eax
testq %rax, %rax
je 0x23ae2
movq %rdi, %r14
andq $0x0, 0x238(%rdi)
movq (%rdi), %rdi
imulq $0x18, %rax, %rsi
addq %rdi, %rsi
callq 0x19538
pushq $0x1
popq %rbx
xorl %r15d, %r15d
leaq 0x2303c7(%rip), %r12    # 0x253758
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
xorl %r13d, %r13d
movl 0x10(%r14), %eax
cmpq %rax, %rbx
ja 0x234fa
je 0x233c6
movq (%r14), %rax
imulq $0x18, %rbx, %rcx
movl 0x4(%rax,%rcx), %ecx
imulq $0x18, %r15, %rdx
cmpl 0x4(%rax,%rdx), %ecx
je 0x234f2
movq 0x210(%r12), %rax
movq 0x218(%r12), %rcx
imulq $0x18, %r15, %rdx
addq $0xc, %rdx
movq %r15, %rsi
xorl %ebp, %ebp
cmpq %rbx, %rsi
jae 0x23442
movq (%r14), %rdi
cmpb $0x1, (%rdi,%rdx)
jne 0x23439
movq 0x218(%r14), %r8
movl -0x4(%rdi,%rdx), %edi
imulq $0x28, %rdi, %rdi
leaq (%r8,%rdi), %r13
movl 0x8(%r8,%rdi), %edi
cmpq $0x2, %rdi
jb 0x23439
movl 0xc(%r13), %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, %rbp
incq %rsi
addq $0x18, %rdx
jmp 0x233e3
testq %rbp, %rbp
je 0x234ef
movq 0x238(%r14), %rcx
movq 0x240(%r14), %rdx
movq 0x248(%r14), %rax
cmpq $0x0, 0x10(%rsp)
je 0x23495
cmpq %rdx, %rcx
jne 0x234d3
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x240(%r14)
shlq $0x3, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1a3acc
jmp 0x234bb
cmpq %rdx, %rcx
jne 0x234d3
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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, %rbp
subq %rbp, %r15
addq %r10, %r15
movq %r15, (%rax)
movq %rbx, %r15
incq %rbx
jmp 0x2339e
movq 0x238(%r14), %rax
testq %rax, %rax
je 0x2377e
movq 0x248(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1905d
movq 0x238(%r14), %r15
xorl %eax, %eax
xorl %ebp, %ebp
cmpq %r15, %rax
je 0x236b7
movq %r15, %rcx
movq 0x248(%r14), %rdx
movq %rax, (%rsp)
movl (%rdx,%rax,8), %edx
movl 0x10(%r14), %esi
movq 0x210(%r12), %rdi
movq 0x218(%r12), %r9
imulq $0x18, %rdx, %r8
leaq 0xc(%r8), %r10
movq %rdx, %rbx
xorl %r11d, %r11d
cmpq %rsi, %rbx
jae 0x235cd
movq (%r14), %r15
movl -0x8(%r15,%r10), %r12d
cmpl 0x4(%r15,%r8), %r12d
jne 0x235cd
cmpb $0x1, (%r15,%r10)
jne 0x235c4
movq 0x218(%r14), %r12
movl -0x4(%r15,%r10), %r15d
imulq $0x28, %r15, %r15
leaq (%r12,%r15), %r13
movl 0x8(%r12,%r15), %r15d
cmpq $0x2, %r15
jb 0x235c4
movl 0xc(%r13), %r12d
cmpl $0x2, %r12d
setae %al
cmpq %r15, %r9
setle %r15b
movl %r12d, %r12d
cmpq %r12, %rdi
setle %r12b
andb %al, %r15b
andb %r12b, %r15b
movzbl %r15b, %eax
addq %rax, %r11
incq %rbx
addq $0x18, %r10
jmp 0x23561
testq %r11, %r11
je 0x236a1
movq (%r14), %rdi
movl 0x4(%rdi,%r8), %r8d
movq 0x8(%rsp), %rax
movq (%rax), %r9
imulq $0xa8, %r8, %r10
cmpb $0x1, 0x2c(%r9,%r10)
movq %rcx, %r15
jne 0x23603
leaq (%r9,%r10), %rax
addq $0x2c, %rax
movb $0x2, (%rax)
leaq 0x23014e(%rip), %r12    # 0x253758
cmpq %rsi, %rdx
jae 0x236ab
imulq $0x18, %rdx, %r10
cmpl %r8d, 0x4(%rdi,%r10)
jne 0x236ab
leaq (%rdi,%r10), %r9
movzbl 0xc(%r9), %r11d
testl %r11d, %r11d
je 0x23654
cmpl $0x1, %r11d
jne 0x23699
movq 0x218(%r14), %rax
movl 0x8(%r9), %r9d
imulq $0x28, %r9, %r9
leaq (%rax,%r9), %r13
movl $0x1, 0x1c(%rax,%r9)
jmp 0x23699
movl 0x8(%r9), %r9d
imulq $0x28, %r9, %r13
addq 0x218(%r14), %r13
addq %rdi, %r10
addq $0x10, %r10
incq %r9
movq %r13, %rbx
decq %r9
js 0x23699
movq %rbx, %r11
movl 0x20(%r13), %eax
cmpl 0x20(%rbx), %eax
jne 0x23696
leaq -0x28(%r11), %rbx
movl (%r10), %eax
subl %eax, 0x8(%r11)
movq %r11, %rbp
jne 0x23670
jmp 0x23af1
movq %r11, %rbp
incq %rdx
jmp 0x2360a
leaq 0x2300b0(%rip), %r12    # 0x253758
movq %rcx, %r15
movq (%rsp), %rax
incq %rax
jmp 0x23525
xorl %ecx, %ecx
cmpq %r15, %rcx
je 0x23780
movq 0x248(%r14), %rax
movl (%rax,%rcx,8), %esi
movl 0x10(%r14), %edi
movq (%r14), %r8
imulq $0x18, %rsi, %r9
leaq (%r8,%r9), %r10
addq $0x4, %r10
leaq (%r8,%r9), %r11
addq $0xc, %r11
xorl %edx, %edx
cmpq %rdi, %rsi
jae 0x23734
movl (%r10), %ebx
cmpl %ebx, -0x8(%r11)
jne 0x23739
cmpb $0x1, (%r11)
jne 0x2372b
movq 0x218(%r14), %rax
movl -0x4(%r11), %ebx
imulq $0x28, %rbx, %rbx
leaq (%rax,%rbx), %r13
cmpl $0x2, 0x8(%rax,%rbx)
jb 0x2372b
cmpl $0x2, 0xc(%r13)
jb 0x2372b
xorl %eax, %eax
cmpl $0x1, 0x1c(%r13)
sete %al
addq %rax, %rdx
incq %rsi
addq $0x18, %r11
jmp 0x236e9
movl 0x4(%r8,%r9), %ebx
movl %ebx, %eax
movq 0x8(%rsp), %rsi
movq (%rsi), %rsi
imulq $0xa8, %rax, %rdi
movb 0x2c(%rsi,%rdi), %r9b
cmpb $0x2, %r9b
jne 0x2375d
movb $0x1, %r8b
testq %rdx, %rdx
je 0x2376b
cmpb $0x1, %r9b
jne 0x23776
movb $0x2, %r8b
testq %rdx, %rdx
je 0x23776
leaq (%rsi,%rdi), %rax
addq $0x2c, %rax
movb %r8b, (%rax)
incq %rcx
jmp 0x236b9
xorl %ebp, %ebp
andq $0x0, 0x238(%r14)
pushq $0x1
popq %rbx
xorl %r12d, %r12d
movl 0x10(%r14), %eax
cmpq %rax, %rbx
ja 0x239d1
movq (%r14), %rcx
jne 0x237aa
imulq $0x18, %r12, %rax
movl 0x4(%rcx,%rax), %eax
jmp 0x237c0
imulq $0x18, %rbx, %rdx
imulq $0x18, %r12, %rax
movl 0x4(%rcx,%rax), %eax
cmpl %eax, 0x4(%rcx,%rdx)
je 0x239c9
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movl %eax, %eax
imulq $0xa8, %rax, %rax
cmpb $0x2, 0x2c(%rdx,%rax)
je 0x239c6
imulq $0x18, %r12, %r15
xorl %r8d, %r8d
cmpq %rbx, %r12
jae 0x238dd
cmpb $0x1, 0xc(%rcx,%r15)
jne 0x238d1
movq 0x218(%r14), %rax
movl 0x8(%rcx,%r15), %edx
imulq $0x28, %rdx, %rdx
leaq (%rax,%rdx), %r13
cmpl $0x2, 0x8(%rax,%rdx)
jb 0x238d1
cmpl $0x2, 0xc(%r13)
jb 0x238d1
cmpl $0x1, 0x1c(%r13)
je 0x238d1
incq %r8
movq 0x238(%r14), %rdi
movq 0x240(%r14), %rdx
movq 0x248(%r14), %rax
cmpq $0x0, 0x10(%rsp)
je 0x2387e
cmpq %rdx, %rdi
jne 0x238bd
leaq (%rdi,%rdi), %rdx
testq %rdi, %rdi
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x240(%r14)
shlq $0x3, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r8, (%rsp)
callq 0x1a3acc
jmp 0x238a8
cmpq %rdx, %rdi
jne 0x238bd
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rcx
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 %r12
addq $0x18, %r15
jmp 0x237e3
movq 0x238(%r14), %rax
movq %rax, %rcx
subq %r8, %rcx
movq %rcx, 0x238(%r14)
cmpq $0x2, %r8
jb 0x239c6
movq 0x248(%r14), %rdx
leaq (%rdx,%rcx,8), %rdi
leaq (%rdx,%rax,8), %rsi
movq %r8, %r15
callq 0x1905d
movq %r15, %r10
movq 0x238(%r14), %rax
shlq $0x3, %rax
addq 0x248(%r14), %rax
movq %r15, %rdx
negq %rdx
xorl %esi, %esi
xorl %ecx, %ecx
incq %rsi
leaq (%rdx,%rsi), %rdi
cmpq $0x1, %rdi
je 0x239b9
cmpq $0x1, %rsi
je 0x23951
imulq $0x28, -0x10(%rax,%rsi,8), %r13
addq 0x218(%r14), %r13
cmpq %r10, %rsi
jae 0x23962
imulq $0x28, (%rax,%rsi,8), %rbp
addq 0x218(%r14), %rbp
testq %r13, %r13
je 0x23982
movl 0x20(%r13), %edi
addl $0x20, %edi
movq 0x218(%r14), %r8
imulq $0x28, -0x8(%rax,%rsi,8), %r9
cmpl 0x20(%r8,%r9), %edi
ja 0x23931
testq %rbp, %rbp
je 0x239a8
movq 0x218(%r14), %r8
movq -0x8(%rax,%rsi,8), %rdi
imulq $0x28, %rdi, %r9
movl 0x20(%r8,%r9), %r8d
addl $0x20, %r8d
cmpl 0x20(%rbp), %r8d
ja 0x23931
jmp 0x239ad
movq -0x8(%rax,%rsi,8), %rdi
movq %rdi, (%rax,%rcx,8)
incq %rcx
jmp 0x23931
cmpq $0x2, %rcx
jb 0x239c6
addq %rcx, 0x238(%r14)
movq %rbx, %r12
incq %rbx
jmp 0x2378e
movq 0x238(%r14), %rcx
testq %rcx, %rcx
je 0x239f1
movq 0x248(%r14), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x1905d
movl 0x10(%r14), %eax
leaq 0x1(%rax), %rcx
pushq $0x1
popq %rdx
xorl %esi, %esi
cmpq %rcx, %rdx
je 0x23ae2
movq (%r14), %r11
cmpq %rax, %rdx
jne 0x23a16
imulq $0x18, %rsi, %rdi
movl 0x4(%r11,%rdi), %edi
jmp 0x23a32
imulq $0x18, %rdx, %r8
imulq $0x18, %rsi, %rdi
movl 0x4(%r11,%rdi), %edi
cmpl %edi, 0x4(%r11,%r8)
jne 0x23a32
movq %rsi, %r10
jmp 0x23ad7
movl %edi, %r8d
movq 0x8(%rsp), %rdi
movq (%rdi), %rdi
imulq $0xa8, %r8, %r8
leaq (%rdi,%r8), %r9
addq $0x2c, %r9
movzbl (%r9), %ebx
cmpl $0x1, %ebx
je 0x23a61
movq %rdx, %r10
cmpl $0x2, %ebx
jne 0x23ad7
movb $0x1, (%r9)
leaq (%rdi,%r8), %r10
addq $0x2e, %r10
imulq $0x18, %rsi, %rbx
addq %rbx, %r11
addq $0xc, %r11
cmpq %rdx, %rsi
jae 0x23ad4
movb (%r11), %bl
cmpb $0x1, %bl
ja 0x23ab2
movq 0x218(%r14), %r15
movl -0x4(%r11), %r12d
imulq $0x28, %r12, %r12
cmpl $0x1, 0x1c(%r15,%r12)
jne 0x23ab2
addq %r12, %r15
cmpl $0x2, 0x8(%r15)
jb 0x23ab2
cmpl $0x2, 0xc(%r15)
jb 0x23ab2
movb $0x1, (%r10)
cmpb $0x1, %bl
je 0x23abb
incq %rsi
addq $0x18, %r11
jmp 0x23a74
movb $0x2, (%r9)
movl 0x8(%rdi,%r8), %esi
subl 0x4(%rdi,%r8), %esi
incl %esi
movq 0x8(%rsp), %rdi
subq %rsi, 0x18(%rdi)
movq %rdx, %r10
incq %rdx
movq %r10, %rsi
jmp 0x239fa
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c00a2(%rip), %rdi    # 0x1e3b9a
leaq 0x1bfba4(%rip), %rsi    # 0x1e36a3
leaq 0x1c00a2(%rip), %rcx    # 0x1e3ba8
movl $0x21e0, %edx           # imm = 0x21E0
callq 0x2110