// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x409a6
jmp 0x419d1
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq $0x0, 0x238(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x2e440
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
ja 0x40cc8
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
je 0x40a44
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
je 0x40cb5
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x40b07
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
je 0x40a7c
jmp 0x40af6
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jb 0x40ab8
movq -0x58(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jae 0x40aba
jmp 0x40af6
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
leaq 0x383d30(%rip), %rcx    # 0x3c47f8
cmpq 0x218(%rcx), %rax
jl 0x40af4
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
leaq 0x383d19(%rip), %rcx    # 0x3c47f8
cmpq 0x210(%rcx), %rax
jl 0x40af4
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x40af6
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x40a54
cmpq $0x0, -0x38(%rbp)
jbe 0x40cad
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x40bf6
jmp 0x40b44
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x240(%rcx), %rax
jne 0x40bc5
movq -0x8(%rbp), %rax
cmpq $0x0, 0x240(%rax)
je 0x40b7e
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x40b89
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x40b89
movq -0x68(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x240(%rax)
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x238(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x238(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x40cab
jmp 0x40bf8
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x240(%rcx), %rax
jne 0x40c7d
movq -0x8(%rbp), %rax
cmpq $0x0, 0x240(%rax)
je 0x40c32
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x40c3d
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x40c3d
movq -0x70(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x240(%rax)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rdx
shlq $0x3, %rdx
callq 0x30e740
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x238(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x238(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x40cab
jmp 0x40cad
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x40cb7
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x409f6
movq -0x8(%rbp), %rax
cmpq $0x0, 0x238(%rax)
jbe 0x411ff
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x238(%rcx), %rax
jae 0x41050
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x71(%rbp)
jae 0x40d8e
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x40d9a
jmp 0x40e3f
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
je 0x40db4
jmp 0x40e2e
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jb 0x40df0
movq -0x58(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jae 0x40df2
jmp 0x40e2e
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
leaq 0x3839f8(%rip), %rcx    # 0x3c47f8
cmpq 0x218(%rcx), %rax
jl 0x40e2c
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
leaq 0x3839e1(%rip), %rcx    # 0x3c47f8
cmpq 0x210(%rcx), %rax
jl 0x40e2c
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x40e2e
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x40d4d
cmpq $0x0, -0x38(%rbp)
jne 0x40e4b
jmp 0x4103f
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x40e92
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movb $0x2, 0x2c(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x72(%rbp)
jae 0x40edb
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
sete %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x40ee7
jmp 0x4103d
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
jne 0x40f37
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl $0x1, 0x1c(%rax)
jmp 0x4102a
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x41028
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x50(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jl 0x41026
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
imulq $0x28, -0x50(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x20(%rcx), %eax
je 0x40fca
jmp 0x41026
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
movq -0x60(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x60(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jb 0x40ff4
jmp 0x41013
leaq 0x341817(%rip), %rdi    # 0x382812
leaq 0x341319(%rip), %rsi    # 0x38231b
movl $0x21e0, %edx           # imm = 0x21E0
leaq 0x341812(%rip), %rcx    # 0x382820
callq 0x2130
jmp 0x41015
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x40f96
jmp 0x41028
jmp 0x4102a
jmp 0x4102c
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x40e9a
jmp 0x4103f
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x40d0f
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x238(%rcx), %rax
jae 0x411fd
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x73(%rbp)
jae 0x410d7
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
sete %al
movb %al, -0x73(%rbp)
movb -0x73(%rbp), %al
testb $0x1, %al
jne 0x410e3
jmp 0x41164
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
je 0x410fd
jmp 0x41153
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jb 0x41139
movq -0x58(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jae 0x4113b
jmp 0x41153
movq -0x58(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x41151
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x41153
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x41096
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x2, %eax
jne 0x411b2
cmpq $0x0, -0x38(%rbp)
jne 0x411b2
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x411ea
cmpq $0x0, -0x38(%rbp)
jbe 0x411ea
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movb $0x2, 0x2c(%rax)
jmp 0x411ec
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x41058
jmp 0x411ff
movq -0x8(%rbp), %rax
movq $0x0, 0x238(%rax)
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
ja 0x416c6
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
je 0x4126c
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
je 0x416b3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x2, %eax
jne 0x412a5
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x416b5
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x414ec
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
je 0x412e0
jmp 0x414db
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jb 0x4131c
movq -0x58(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jae 0x41321
jmp 0x414db
movq -0x58(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x41330
jmp 0x414db
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4140b
jmp 0x41349
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x240(%rcx), %rax
jne 0x413ca
movq -0x8(%rbp), %rax
cmpq $0x0, 0x240(%rax)
je 0x41383
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x4138e
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x4138e
movq -0x80(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x240(%rax)
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x238(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x238(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x414d9
jmp 0x4140d
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x240(%rcx), %rax
jne 0x4149b
movq -0x8(%rbp), %rax
cmpq $0x0, 0x240(%rax)
je 0x4144a
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x41458
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x41458
movq -0x88(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x240(%rax)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rdx
shlq $0x3, %rdx
callq 0x30e740
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x238(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x238(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x414d9
jmp 0x414db
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x412b5
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x238(%rax)
cmpq $0x2, -0x38(%rbp)
jb 0x416ab
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x238(%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x4168c
cmpq $0x0, -0x30(%rbp)
jbe 0x415c3
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
imulq $0x28, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
cmpq -0x38(%rbp), %rax
jae 0x415f1
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq $0x28, 0x8(%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x41624
movq -0x58(%rbp), %rax
movl 0x20(%rax), %eax
addl $0x20, %eax
movq -0x8(%rbp), %rcx
movq 0x218(%rcx), %rcx
movq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rsi
imulq $0x28, (%rdx,%rsi,8), %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jbe 0x41624
jmp 0x4167b
cmpq $0x0, -0x60(%rbp)
je 0x41657
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq $0x28, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
addl $0x20, %eax
movq -0x60(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jbe 0x41657
jmp 0x4167b
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x4158b
cmpq $0x2, -0x50(%rbp)
jl 0x416a9
movq -0x50(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0x238(%rax), %rcx
movq %rcx, 0x238(%rax)
jmp 0x416ab
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x416b5
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x4121e
movq -0x8(%rbp), %rax
cmpq $0x0, 0x238(%rax)
jbe 0x417b7
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x238(%rcx), %rax
ja 0x417b5
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x238(%rcx), %rax
je 0x41763
movq -0x8(%rbp), %rax
movq 0x248(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movq 0x248(%rcx), %rcx
movq -0x28(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
je 0x4179c
movq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
cmpq $0x2, %rax
jb 0x4179a
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x248(%rcx), %rcx
movq -0x28(%rbp), %rdx
imulq $0x28, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl $0x1, 0x1c(%rax)
jmp 0x4179c
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x41715
jmp 0x417b7
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
ja 0x419d1
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
je 0x41815
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
je 0x419be
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x2, %eax
jne 0x4185c
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x419b6
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x419b4
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
je 0x418c5
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x419a1
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x4199f
movq -0x58(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jb 0x4199f
movq -0x58(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jb 0x4199f
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x2e(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
jne 0x4199d
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movb $0x2, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x48(%rbp), %rdx
addq %rdx, %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x18(%rax)
jmp 0x419b4
jmp 0x4199f
jmp 0x419a1
jmp 0x419a3
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x41883
jmp 0x419b6
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x419c0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x417c7
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)