// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Hash_Table.cpp
// Function: lchain_qdp_mcopy_fast(Candidates_list*, long, long, long, Chain_Data*, overlap_region_alloc*, long, long, long, double, double, double, unsigned int, long, long, long, unsigned int, long, long, double, long, long)
uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n, int64_t des_idx, 
              Chain_Data* dp, overlap_region_alloc* res, int64_t max_skip, int64_t max_iter, 
              int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate, 
              uint32_t xid, int64_t xl, int64_t yl, int64_t quick_check, uint32_t apend_be, 
              int64_t gen_cigar, int64_t mcopy_num, double mcopy_rate, int64_t mcopy_khit_cutoff, 
              int64_t khit_n)
{
    if(a_n <= 0) return 0;
    int64_t *p, *t, max_f, n_skip, st, max_j, end_j, sc, msc, msc_i, max_ii, ovl, movl, plus = 0, min_sc, ch_n, si, ei; 
    int32_t *f, max, tmp, *ii; int64_t i, k, j, cL = 0; k_mer_hit* a; k_mer_hit* des; k_mer_hit *swap; overlap_region *z;
    resize_Chain_Data(dp, a_n, NULL); ch_n = 1; // int64_t bw; bw = ((xl < yl)?xl:yl); bw *= bw_rate;
    t = dp->tmp; f = dp->score; p = dp->pre; ii = dp->occ;
    
    a = cl->list + a_idx; des = cl->list + des_idx;
    // if(a_n && a[0].readID == 0) {
    //     fprintf(stderr, "---[M::%s::utg%.6dl::%c]\n", 
    //                     __func__, (int32_t)a[0].readID+1, "+-"[a[0].strand]);
    // }
    if(quick_check) {
        quick_ck_lchain(a, a_n, xl, yl, chn_pen_gap, chn_pen_skip, bw_rate, p, t, f, ii, &plus, &msc, &msc_i, &movl, &si, &ei);
    } else {
        msc = msc_i = INT32_MIN; movl = INT32_MAX; plus = 0; si = 0; ei = a_n;
        memset(t, 0, (a_n*sizeof((*t))));
    }   
    // if(a_n && a[0].readID == 4412344) {
    //     fprintf(stderr, "[M::%s::] si::%ld, ei::%ld, a_n::%ld\n", __func__, si, ei, a_n);
    // }
    for (i = st = si, max_ii = -1; i < ei; ++i) {
        max_f = a[i].cnt&(0xffu); 
        n_skip = 0; max_j = end_j = -1;
        if ((i-st) > max_iter) st = i-max_iter;
        while (a[i].strand != a[st].strand) ++st;

        for (j = i - 1; j >= st; --j) {
            sc = comput_sc_ch_ec(&a[i], &a[j], bw_rate, chn_pen_gap, chn_pen_skip, xl, yl);
            if (sc == INT32_MIN) continue;
            sc += f[j];
            if (sc > max_f) {
                max_f = sc, max_j = j;
                if (n_skip > 0) --n_skip;
            } else if (t[j] == (int32_t)i) {
                if (++n_skip > max_skip)
                    break;
            }
            if (p[j] >= 0) t[p[j]] = i;
        }
        end_j = j;

        if ((max_ii<0) || (a[i].self_offset>a[max_ii].self_offset+max_dis) || (a[i].strand!=a[max_ii].strand)) {
            max = INT32_MIN; max_ii = -1;
            for (j=i-1; (j>=st) && (a[i].self_offset<=max_dis+a[j].self_offset)&&(a[i].strand==a[j].strand); --j) {
                if (max < f[j]) {
                    max = f[j], max_ii = j;
                }
            }
        }

        if ((max_ii >= 0) && (max_ii < end_j) && (a[i].strand == a[max_ii].strand)) {///just have a try with a[i]<->a[max_ii]
            tmp = comput_sc_ch_ec(&a[i], &a[max_ii], bw_rate, chn_pen_gap, chn_pen_skip, xl, yl);
            if (tmp != INT32_MIN && max_f < tmp + f[max_ii])
                max_f = tmp + f[max_ii], max_j = max_ii;
        }
        f[i] = max_f; p[i] = max_j;
        if ((max_ii < 0) || ((a[i].self_offset<=max_dis+a[max_ii].self_offset)&&(a[i].strand==a[max_ii].strand)&&(f[max_ii]<f[i]))) {
            max_ii = i;
        }
        if(f[i] >= msc) {
            ovl = get_chainLen(a[i].self_offset, a[i].self_offset, xl, a[i].offset, a[i].offset, yl);
            if(f[i] > msc || ovl < movl) {
                msc = f[i]; msc_i = i; movl = ovl;
            }
        }
        if(f[i] < plus) plus = f[i];
        ii[i] = 0;///for mcopy, not here
        // if(a_n && a[0].readID == 4412344) {
        //     fprintf(stderr, "i::%ld[M::%s::%c] q::%u, t::%u, st::%ld, max_ii::%ld, f[i]::%d, p[i]::%ld, msc_i::%ld, msc::%ld, movl::%ld\n", 
        //                     i, __func__, "+-"[a[i].strand], 
        //                     a[i].self_offset, a[i].offset, st, max_ii, f[i], p[i], msc_i, msc, movl);
        // }
    }

    for (i = msc_i, cL = 0; i >= 0; i = p[i]) { ii[i] = 1; t[cL++] = i;}///label the best chain

    if(mcopy_num > 1) {
        // if(a[0].readID == 4412344) {
        //     fprintf(stderr, "[M::%s::] msc::%ld, cL::%ld\n", __func__, msc, cL);
        // }
        if(cL >= mcopy_khit_cutoff) {///if there are too few k-mers, disable mcopy
            msc -= plus; min_sc = msc*mcopy_rate/**0.2**/; ii[msc_i] = 0;
            for (i = ch_n = 0; i < a_n; ++i) {///make all f[] positive
                f[i] -= plus; if(i >= ch_n) t[i] = 0;
                if((!(ii[i])) && (f[i] >= min_sc)) {///!(ii[i]): skip the best chain
                    t[ch_n] = ((uint64_t)f[i])<<32; t[ch_n] += (i<<1); ch_n++;
                }
            }
            // if(a[0].readID == 4412344) {
            //     fprintf(stderr, "[M::%s::] msc::%ld, min_sc::%ld, cL::%ld, ch_n::%ld, mcopy_num::%ld\n", __func__, msc, min_sc, cL, ch_n, mcopy_num);
            // }
            if(ch_n > 1) {
                int64_t n_v, n_v0, ni, n_u, n_u0 = res->length; 
                radix_sort_hc64i(t, t + ch_n);
                for (k = ch_n-1, n_v = n_u = 0; k >= 0 && n_u < mcopy_num; --k) {
                    n_v0 = n_v;
                    for (i = ((uint32_t)t[k])>>1; i >= 0 && (t[i]&1) == 0; ) {
                        ii[n_v++] = i; t[i] |= 1; i = p[i];
                    }
                    if(n_v0 == n_v) continue;
                    sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i]));
                    // if(a[0].readID == 4412344) {
                    //     fprintf(stderr, "+[M::%s::] sc::%ld, n_a::%ld\n", __func__, sc, n_v-n_v0);
                    // }
                    if(sc >= min_sc) {
                        kv_pushp_ol(overlap_region, (*res), &z);
                        push_ovlp_chain_qgen(z, xid, xl, yl, sc+plus, &(a[ii[n_v-1]]), &(a[ii[n_v0]]));
                        // if(a[0].readID == 4412344) {
                        //     fprintf(stderr, "-[M::%s::] sc::%ld, n_a::%ld, q::[%u,%u), t::[%u,%u), %c\n", __func__, sc, n_v-n_v0, z->x_pos_s, z->x_pos_e + 1, z->y_pos_s, z->y_pos_e + 1, "+-"[z->y_pos_strand]);
                        // }
                        ///mcopy_khit_cutoff <= 1: disable the mcopy_khit_cutoff filtering, for the realignment
                        // if((mcopy_khit_cutoff <= 1) || ((z->x_pos_e+1-z->x_pos_s) <= (movl<<2))) {
                        if((!n_u) || (n_v - n_v0 > 1)) {
                            z->align_length = n_v-n_v0; z->x_id = n_v0;
                            n_u++;
                        } else {///non-best is tiny
                            res->length--; n_v = n_v0;
                        }
                    } else {
                        n_v = n_v0;
                    }
                }

                // if(n_u > 1) ks_introsort_or_sss(n_u, res->list + n_u0); 
                // res->length = n_u0 + filter_non_ovlp_xchains(res->list + n_u0, n_u, &n_v);
                n_u = res->length;
                if(n_u > n_u0 + 1) {
                    kv_resize_cl(k_mer_hit, (*cl), (n_v+cl->length));
                    a = cl->list + a_idx; des = cl->list + des_idx; swap = cl->list + cl->length; 
                    for (k = n_u0, i = n_v0 = n_v = 0; k < n_u; k++) {
                        z = &(res->list[k]);
                        z->non_homopolymer_errors = des_idx + i;
                        n_v0 = z->x_id; ni = z->align_length;
                        for (j = 0; j < ni; j++, i++) {
                            ///k0 + (ni - j - 1)
                            swap[i] = a[ii[n_v0 + (ni- j - 1)]]; 
                            swap[i].readID = k; 
                        }
                        z->x_id = xid; 
                        if(gen_cigar) gen_fake_cigar(&(z->f_cigar), z, apend_be, swap+i-ni, ni);
                        if(!khit_n) z->align_length = 0; 
                    }
                    memcpy(des, swap, i*sizeof((*swap))); //assert(i == ch_n);
                    
                    // fprintf(stderr, "[M::%s::msc->%ld] msc_k_hits::%u, cL::%ld, min_sc::%ld, best_sc::%ld, n_u0_sc::%d, mcopy_rate::%f, # chains::%ld\n", 
                    // __func__, msc, res->list[n_u0].align_length, cL, min_sc, msc+plus, res->list[n_u0].shared_seed,
                    // mcopy_rate, n_u-n_u0);
                } else if(n_u == n_u0 + 1) {
                    z = &(res->list[n_u0]); k = n_u0; i = 0;
                    z->non_homopolymer_errors = des_idx + i;
                    n_v0 = z->x_id; ni = z->align_length;
                    for (j = 0; j < ni; j++, i++) {
                        ///k0 + (ni - j - 1)
                        des[i] = a[ii[n_v0 + (ni- j - 1)]]; 
                        des[i].readID = k; 
                    }
                    z->x_id = xid; 
                    if(gen_cigar) gen_fake_cigar(&(z->f_cigar), z, apend_be, des+i-ni, ni);
                    if(!khit_n) z->align_length = 0; 
                }
                return i;
            } else {
                msc += plus; i = msc_i; cL = 0; 
                while (i >= 0) {t[cL++] = i; i = p[i];}
            }
        }
    }



    ///a[] has been sorted by self_offset
    // i = msc_i; cL = 0; 
    // while (i >= 0) {t[cL++] = i; i = p[i];}
    kv_pushp_ol(overlap_region, (*res), &z);
    push_ovlp_chain_qgen(z, xid, xl, yl, msc, &(a[t[cL-1]]), &(a[t[0]]));
    for (i = 0; i < cL; i++) {des[i] = a[t[cL-i-1]]; des[i].readID = res->length-1;}
    z->non_homopolymer_errors = des_idx;
    if(gen_cigar) gen_fake_cigar(&(z->f_cigar), z, apend_be, des, cL);
    if(khit_n) z->align_length = cL;
    return cL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movsd %xmm3, 0xd0(%rsp)
movsd %xmm2, 0x40(%rsp)
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
testq %rdx, %rdx
jle 0x1621f
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbp
movq %r9, 0x38(%rsp)
movq 0x180(%rsp), %r14
andq $0x0, 0x108(%rsp)
movq %r8, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x1383e
movq 0x28(%rbx), %r9
movq (%rbx), %r10
movq 0x8(%rbx), %r8
movq %rbp, %rax
movq 0x20(%rbx), %rbp
movq %rax, 0xc8(%rsp)
movq (%rax), %rbx
shlq $0x4, %r12
movq %r12, 0x98(%rsp)
leaq (%rbx,%r12), %rdi
movq %r15, 0xa0(%rsp)
shlq $0x4, %r15
movq %r15, 0xb0(%rsp)
cmpq $0x0, 0x190(%rsp)
movq %rbp, 0x8(%rsp)
movq %rdi, 0x48(%rsp)
movq %r9, 0x18(%rsp)
movq %r8, 0x70(%rsp)
movq %r10, 0x58(%rsp)
movq %r13, 0x78(%rsp)
je 0x16227
leaq 0xf8(%rsp), %rax
leaq 0x100(%rsp), %r12
leaq 0x110(%rsp), %r11
movq %r13, %rsi
leaq 0x118(%rsp), %r13
leaq 0x120(%rsp), %r15
leaq 0x108(%rsp), %rbp
movq %r14, %rdx
movq 0x188(%rsp), %rcx
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
pushq %rax
movq %rax, %r14
pushq %r12
pushq %r11
pushq %r13
pushq %r15
pushq %rbp
pushq 0x38(%rsp)
pushq %r10
callq 0x15bf2
addq $0x40, %rsp
movq (%r12), %r12
movq (%r14), %rax
movq %rax, 0xb8(%rsp)
movq (%r15), %r14
leaq 0x110(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
movq (%r13), %rax
movq %rax, 0x80(%rsp)
movq (%rbp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rbp
jmp 0x1627e
xorl %r13d, %r13d
jmp 0x16d90
andq $0x0, 0x100(%rsp)
movq %r13, 0xf8(%rsp)
leaq (,%r13,8), %rdx
movq $0x0, 0x50(%rsp)
movq %r9, %rdi
xorl %esi, %esi
callq 0x20e0
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0xa8(%rsp)
movq $-0x80000000, 0x80(%rsp) # imm = 0x80000000
movq $-0x80000000, %r14      # imm = 0x80000000
movq %r13, 0xb8(%rsp)
xorl %r12d, %r12d
movq 0xb0(%rsp), %rax
addq %rbx, %rax
movq %rax, 0x90(%rsp)
movq 0x168(%rsp), %rax
movq %rax, %rcx
notq %rcx
movq %rcx, 0xe0(%rsp)
negq %rax
movq %rax, 0xd8(%rsp)
movq %r12, %rax
shlq $0x4, %rax
addq 0x98(%rsp), %rax
leaq (%rbx,%rax), %rcx
addq $-0x10, %rcx
leaq -0x8(%rbx,%rax), %rax
movq %rax, 0xc0(%rsp)
movq %rcx, %rbx
pushq $-0x1
popq %rax
movq %rax, 0x60(%rsp)
movq %r12, %rcx
movq 0x48(%rsp), %r13
movq 0x58(%rsp), %r15
cmpq 0xb8(%rsp), %rcx
movq 0x70(%rsp), %rdx
movq %r14, 0x88(%rsp)
jge 0x166ee
movq %rcx, %rax
shlq $0x4, %rax
leaq (%rax,%r13), %r8
movzbl 0xc(%r13,%rax), %r9d
movl (%r13,%rax), %eax
movq %rcx, 0x10(%rsp)
subq %r12, %rcx
movq 0x168(%rsp), %rdx
cmpq %rcx, %rdx
cmovgq %rdx, %rcx
movq 0xe0(%rsp), %rdx
addq %r12, %rdx
addq %rcx, %rdx
addq 0xd8(%rsp), %r12
addq %rcx, %r12
shlq $0x4, %r12
addq %r13, %r12
movq %r12, %rcx
movq %rdx, %r12
incq %r12
movl (%rcx), %edx
addq $0x10, %rcx
xorl %eax, %edx
js 0x1635c
movq 0x10(%rsp), %rax
leaq -0x1(%rax), %r10
cltq
movq %rax, 0xf0(%rsp)
movq %rbx, 0xe8(%rsp)
pushq $-0x1
popq %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x20(%rsp)
movq %r10, %r14
cmpq %r12, %r14
jl 0x16484
movq %r10, %r13
movq %r9, %r15
movq %r8, %rbp
movq %r8, %rdi
movq %rbx, %rsi
movsd 0x40(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq 0x180(%rsp), %rdx
movq 0x188(%rsp), %rcx
callq 0x17e4a
movl %eax, %ecx
negl %ecx
jno 0x163eb
movq %r15, %rax
movq %rbp, %r8
movq %r13, %r10
jmp 0x16475
movslq %eax, %rcx
movq 0x58(%rsp), %rax
movslq (%rax,%r14,4), %rax
addq %rcx, %rax
cmpq %r15, %rax
jle 0x1641e
xorl %ecx, %ecx
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
setg %cl
subq %rcx, %rdx
movq %rdx, 0x20(%rsp)
movq %r14, 0x68(%rsp)
movq %rbp, %r8
jmp 0x16456
movq %r15, %r9
movq 0x18(%rsp), %rax
movq 0xf0(%rsp), %rcx
cmpq %rcx, (%rax,%r14,8)
movq %rbp, %r8
jne 0x16453
movq 0x20(%rsp), %rax
cmpq 0x160(%rsp), %rax
movq %r13, %r10
jge 0x16484
incq 0x20(%rsp)
movq %r9, %rax
jmp 0x16459
movq %r9, %rax
movq %r13, %r10
movq 0x70(%rsp), %rcx
movq (%rcx,%r14,8), %rcx
testq %rcx, %rcx
js 0x16475
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq %rsi, (%rdx,%rcx,8)
decq %r14
addq $-0x10, %rbx
movq %rax, %r9
jmp 0x16398
movq 0x60(%rsp), %rbx
testq %rbx, %rbx
movq 0x48(%rsp), %r13
movq 0x170(%rsp), %rdi
js 0x16553
movl 0x8(%r8), %ecx
movq %rbx, %rax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %edx
addq %rdi, %rdx
cmpq %rcx, %rdx
jl 0x16553
addq %r13, %rax
movl (%rax), %eax
xorl (%r8), %eax
js 0x16553
testq %rbx, %rbx
sets %al
cmpq %r14, %rbx
setge %cl
orb %al, %cl
jne 0x165a5
movq %rbx, %rsi
shlq $0x4, %rsi
movl (%r13,%rsi), %eax
xorl (%r8), %eax
movq 0x58(%rsp), %r15
movq 0x88(%rsp), %r14
js 0x16606
movq %r9, %rbp
addq %r13, %rsi
movq %r8, 0x20(%rsp)
movq %r8, %rdi
movsd 0x40(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq 0x180(%rsp), %rdx
movq 0x188(%rsp), %rcx
callq 0x17e4a
movl %eax, %ecx
negl %ecx
jno 0x165d8
movq 0x170(%rsp), %rdi
movq 0x20(%rsp), %r8
movq %rbp, %r9
jmp 0x16606
movl $0x80000000, %eax       # imm = 0x80000000
movq 0xc0(%rsp), %rcx
pushq $-0x1
popq %rbx
cmpq %r12, %r10
jl 0x164c9
movl 0x8(%r8), %edx
movl (%rcx), %esi
addq %rdi, %rsi
cmpq %rdx, %rsi
jl 0x164c9
movl -0x8(%rcx), %edx
xorl (%r8), %edx
js 0x164c9
movq 0x58(%rsp), %rdx
movl (%rdx,%r10,4), %edx
cmpl %edx, %eax
cmovlq %r10, %rbx
cmovlel %edx, %eax
decq %r10
addq $-0x10, %rcx
jmp 0x16563
movq 0x58(%rsp), %r15
movq 0x10(%rsp), %rcx
movl %r9d, (%r15,%rcx,4)
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
movq %rcx, 0x60(%rsp)
testq %rbx, %rbx
movq 0x88(%rsp), %r14
jns 0x1661d
jmp 0x1665d
movslq (%r15,%rbx,4), %rcx
cltq
addq %rcx, %rax
movq %rbp, %r9
cmpq %rax, %rbp
movq 0x68(%rsp), %rcx
cmovlq %rbx, %rcx
movq %rcx, 0x68(%rsp)
cmovleq %rax, %r9
movq 0x170(%rsp), %rdi
movq 0x20(%rsp), %r8
movq 0x10(%rsp), %rcx
movl %r9d, (%r15,%rcx,4)
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
movl 0x8(%r8), %ecx
movq %rbx, %rax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %edx
addq %rdi, %rdx
cmpq %rcx, %rdx
jge 0x16641
movq %rbx, 0x60(%rsp)
movq 0x10(%rsp), %rcx
jmp 0x1665d
addq %r13, %rax
movl (%rax), %eax
xorl (%r8), %eax
movq 0x10(%rsp), %rcx
js 0x16658
cmpl %r9d, (%r15,%rbx,4)
cmovlq %rcx, %rbx
movq %rbx, 0x60(%rsp)
movslq %r9d, %rbx
cmpq %rbx, %r14
jle 0x1666c
movq 0x8(%rsp), %rbp
jmp 0x166bb
movl 0x4(%r8), %ecx
movl 0x8(%r8), %edi
movq %rdi, %rsi
movq 0x180(%rsp), %rdx
movq %rcx, %r8
movq 0x188(%rsp), %r9
callq 0x12ff0
movq 0x10(%rsp), %rcx
cmpq %rbx, %r14
movq 0x8(%rsp), %rbp
jl 0x166a8
cmpq 0xa8(%rsp), %rax
jge 0x166bb
movq %rcx, 0x80(%rsp)
movq %rax, 0xa8(%rsp)
movq %rbx, %r14
movq 0x50(%rsp), %rax
cmpq %rbx, %rax
cmovgeq %rbx, %rax
movq %rax, 0x50(%rsp)
andl $0x0, (%rbp,%rcx,4)
incq %rcx
movq 0xe8(%rsp), %rbx
addq $0x10, %rbx
addq $0x10, 0xc0(%rsp)
jmp 0x162ee
xorl %r13d, %r13d
movq 0x80(%rsp), %rsi
movq %rsi, %rax
movq 0x38(%rsp), %r14
movq 0x18(%rsp), %rcx
testq %rax, %rax
js 0x16720
movl $0x1, (%rbp,%rax,4)
movq %rax, (%rcx,%r13,8)
incq %r13
movq (%rdx,%rax,8), %rax
jmp 0x16706
cmpq $0x2, 0x1a8(%rsp)
setl %al
cmpq 0x1b0(%rsp), %r13
setl %cl
orb %al, %cl
je 0x1689d
movq (%r14), %r15
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jne 0x167a5
imulq $0x150, %rax, %rcx      # imm = 0x150
testq %rax, %rax
movl $0x150, %esi            # imm = 0x150
cmovneq %rcx, %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %rax, (%r14)
movq 0x8(%r14), %rax
imulq $0xa8, %rax, %rdi
addq %r15, %rdi
leaq (%rax,%rax), %rbx
testq %rax, %rax
pushq $0x2
popq %rcx
cmoveq %rcx, %rbx
movq %rbx, %rcx
subq %rax, %rcx
imulq $0xa8, %rcx, %rdx
xorl %esi, %esi
callq 0x20e0
movq %rbx, 0x8(%r14)
movq 0x10(%r14), %rax
movq 0x90(%rsp), %r12
movq 0x188(%rsp), %rcx
movq 0x180(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x10(%r14)
imulq $0xa8, %rax, %rbx
addq %r15, %rbx
movq 0x18(%rsp), %rax
movq -0x8(%rax,%r13,8), %r9
shlq $0x4, %r9
movq 0x48(%rsp), %rsi
addq %rsi, %r9
movq (%rax), %rax
shlq $0x4, %rax
addq %rsi, %rax
subq $0x8, %rsp
movq %rbx, %rdi
movl 0x180(%rsp), %esi
movq 0x90(%rsp), %r8
pushq %rax
callq 0x14b9c
addq $0x10, %rsp
movl $0x80000000, %eax       # imm = 0x80000000
movq %r12, %rcx
movq %r13, %rdx
movq 0xa0(%rsp), %r8
subq $0x1, %rdx
jb 0x1685d
movq 0x18(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
shlq $0x4, %rsi
movq 0x48(%rsp), %rdi
movupd (%rdi,%rsi), %xmm0
movupd %xmm0, (%rcx)
movl 0x10(%r14), %esi
decl %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl (%rcx), %edi
andl %eax, %edi
orl %esi, %edi
movl %edi, (%rcx)
addq $0x10, %rcx
jmp 0x16822
movl %r8d, 0x30(%rbx)
cmpq $0x0, 0x1a0(%rsp)
je 0x16885
leaq 0x38(%rbx), %rdi
movl 0x198(%rsp), %edx
movq %rbx, %rsi
movq %r12, %rcx
movq %r13, %r8
callq 0x11a23
cmpq $0x0, 0x1b8(%rsp)
je 0x16d90
movl %r13d, 0x28(%rbx)
jmp 0x16d90
movq 0x88(%rsp), %rax
subq 0x50(%rsp), %rax
cvtsi2sd %rax, %xmm0
mulsd 0xd0(%rsp), %xmm0
andl $0x0, (%rbp,%rsi,4)
cvttsd2si %xmm0, %rsi
xorl %r12d, %r12d
xorl %eax, %eax
movq 0x78(%rsp), %r13
movq 0x18(%rsp), %r14
cmpq %r13, %rax
je 0x1690f
movl (%r15,%rax,4), %ecx
subl 0x50(%rsp), %ecx
movl %ecx, (%r15,%rax,4)
cmpq %r12, %rax
jl 0x168ec
andq $0x0, (%r14,%rax,8)
cmpl $0x0, (%rbp,%rax,4)
jne 0x1690a
movslq %ecx, %rcx
cmpq %rsi, %rcx
jl 0x1690a
shlq $0x20, %rcx
leaq (%rcx,%rax,2), %rcx
movq %rcx, (%r14,%r12,8)
incq %r12
incq %rax
jmp 0x168d1
cmpq $0x1, %r12
jle 0x16af4
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
movq %rsi, 0x30(%rsp)
leaq (%r14,%r12,8), %rsi
movq %r14, %rdi
callq 0x110ce
movq 0x30(%rsp), %rsi
xorl %eax, %eax
xorl %edi, %edi
movq %rax, 0x28(%rsp)
leaq (%rbp,%rax,4), %rbp
movq %rdi, 0x20(%rsp)
testq %r12, %r12
jle 0x16b1f
cmpq 0x1a8(%rsp), %rdi
jge 0x16b1f
movq %r12, %rax
decq %r12
movl -0x8(%r14,%rax,8), %r13d
shrl %r13d
xorl %r15d, %r15d
movq 0x70(%rsp), %rdx
testq %r13, %r13
js 0x169a1
movq (%r14,%r13,8), %rcx
testb $0x1, %cl
jne 0x169a1
movl %r13d, (%rbp,%r15,4)
orq $0x1, %rcx
movq %rcx, (%r14,%r13,8)
movq (%rdx,%r13,8), %r13
incq %r15
jmp 0x1697d
testq %r15, %r15
je 0x16950
movslq -0x4(%r14,%rax,8), %rbx
testq %r13, %r13
js 0x169bc
movq 0x58(%rsp), %rax
movslq (%rax,%r13,4), %rax
subq %rax, %rbx
cmpq %rsi, %rbx
jl 0x16950
movq %r13, 0x78(%rsp)
movq 0x38(%rsp), %r14
movq (%r14), %rdi
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jne 0x16a35
imulq $0x150, %rax, %rsi      # imm = 0x150
testq %rax, %rax
movl $0x150, %eax            # imm = 0x150
cmoveq %rax, %rsi
callq 0x2370
movq %rax, 0x10(%rsp)
movq %rax, (%r14)
movq 0x8(%r14), %rdx
imulq $0xa8, %rdx, %rdi
addq %rax, %rdi
leaq (%rdx,%rdx), %r13
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %r13
movq %r13, %rcx
subq %rdx, %rcx
imulq $0xa8, %rcx, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x10(%rsp), %rdi
movq %r13, 0x8(%r14)
movq 0x10(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r14)
imulq $0xa8, %rax, %r13
addq %rdi, %r13
addq 0x50(%rsp), %rbx
movslq -0x4(%rbp,%r15,4), %r9
shlq $0x4, %r9
movq 0x48(%rsp), %rcx
addq %rcx, %r9
movq 0x8(%rsp), %rax
movq 0x28(%rsp), %rdx
movslq (%rax,%rdx,4), %rax
shlq $0x4, %rax
addq %rcx, %rax
subq $0x8, %rsp
movq %r13, %rdi
movl 0x180(%rsp), %esi
movq 0x188(%rsp), %rdx
movq 0x190(%rsp), %rcx
movq %rbx, %r8
pushq %rax
callq 0x14b9c
popq %rax
popq %rcx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x16ac8
cmpq $0x2, %r15
jge 0x16ac8
movq 0x38(%rsp), %rax
decq 0x10(%rax)
movq 0x78(%rsp), %r13
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %rsi
jmp 0x16950
movl %r15d, 0x28(%r13)
movq 0x28(%rsp), %rax
movl %eax, (%r13)
incq %rdi
addq %r15, %rax
movq 0x78(%rsp), %r13
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %rsi
jmp 0x16941
xorl %r13d, %r13d
movq 0x38(%rsp), %r14
movq 0x80(%rsp), %rcx
movq 0x18(%rsp), %rax
testq %rcx, %rcx
js 0x1673f
movq %rcx, (%rax,%r13,8)
incq %r13
movq (%rdx,%rcx,8), %rcx
jmp 0x16b09
movq 0x38(%rsp), %rcx
movq 0x10(%rcx), %rdx
movq 0x40(%rsp), %r12
leaq 0x1(%r12), %rax
movq %rdx, 0x30(%rsp)
cmpq %rax, %rdx
jle 0x16cb6
movq 0xc8(%rsp), %rbx
movq (%rbx), %rdi
movq 0x8(%rbx), %r14
movq 0x28(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, 0x10(%rbx)
jge 0x16bab
decq %rcx
movq %rcx, %rax
sarq %rax
orq %rcx, %rax
movq %rax, %rcx
sarq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
sarq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
sarq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
sarq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x10(%rbx)
shlq $0x4, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %r14
movq 0x98(%rsp), %rbp
addq %rdi, %rbp
shlq $0x4, %r14
movq %rdi, 0x28(%rsp)
addq %rdi, %r14
addq $-0x4, 0x8(%rsp)
xorl %r13d, %r13d
movl $0x80000000, %r15d      # imm = 0x80000000
cmpq 0x30(%rsp), %r12
jge 0x16d39
movq 0x38(%rsp), %rax
movq (%rax), %rax
imulq $0xa8, %r12, %rcx
movq %r13, %rdi
leaq (%rax,%rcx), %r13
movq 0xa0(%rsp), %rdx
addl %edi, %edx
movl %edx, 0x30(%rax,%rcx)
movl (%rax,%rcx), %esi
movl 0x28(%rax,%rcx), %r8d
movq %r12, 0x40(%rsp)
movl %r12d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rdi, %r12
movq %rdi, %rcx
shlq $0x4, %rcx
addq %r14, %rcx
movq %r8, %rdx
negq %rdx
shlq $0x2, %rsi
leaq (%rsi,%r8,4), %rsi
addq 0x8(%rsp), %rsi
xorl %ebx, %ebx
cmpq %rbx, %rdx
je 0x16c60
movslq (%rsi,%rbx,4), %rdi
shlq $0x4, %rdi
movupd (%rbp,%rdi), %xmm0
movupd %xmm0, (%rcx)
movl (%rcx), %edi
andl %r15d, %edi
orl %eax, %edi
movl %edi, (%rcx)
decq %rbx
addq $0x10, %rcx
jmp 0x16c37
movl 0x178(%rsp), %eax
movl %eax, (%r13)
cmpq $0x0, 0x1a0(%rsp)
je 0x16c93
leaq 0x38(%r13), %rdi
movq %r8, %rax
shlq $0x4, %rax
subq %rax, %rcx
movq %r13, %rsi
movl 0x198(%rsp), %edx
callq 0x11a23
cmpq $0x0, 0x1b8(%rsp)
jne 0x16ca3
andl $0x0, 0x28(%r13)
movq %r12, %r13
subq %rbx, %r13
movq 0x40(%rsp), %r12
incq %r12
jmp 0x16bd1
movq 0xa0(%rsp), %rdx
movq 0x8(%rsp), %rsi
jne 0x16d90
movq (%rcx), %rax
imulq $0xa8, %r12, %rcx
leaq (%rax,%rcx), %rbx
movl %edx, 0x30(%rax,%rcx)
movl (%rax,%rcx), %edx
movl 0x28(%rax,%rcx), %r13d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
leaq (%rsi,%rdx,4), %rax
addq $-0x4, %rax
movl $0x80000000, %r9d       # imm = 0x80000000
movq 0x90(%rsp), %rcx
movq %rcx, %rdx
movq %r13, %rdi
movq %r13, %rsi
movq 0x48(%rsp), %r8
subq $0x1, %rsi
jb 0x16d57
movslq (%rax,%rdi,4), %rdi
shlq $0x4, %rdi
movupd (%r8,%rdi), %xmm0
movupd %xmm0, (%rdx)
movl (%rdx), %edi
andl %r9d, %edi
orl %r12d, %edi
movl %edi, (%rdx)
addq $0x10, %rdx
movq %rsi, %rdi
jmp 0x16d0e
movq 0x28(%rsp), %rdi
addq 0xb0(%rsp), %rdi
movq %r13, %rdx
shlq $0x4, %rdx
movq %r14, %rsi
callq 0x2160
jmp 0x16d90
movl 0x178(%rsp), %eax
movl %eax, (%rbx)
cmpq $0x0, 0x1a0(%rsp)
je 0x16d81
leaq 0x38(%rbx), %rdi
movl 0x198(%rsp), %edx
movq %rbx, %rsi
movq %r13, %r8
callq 0x11a23
cmpq $0x0, 0x1b8(%rsp)
jne 0x16d90
andl $0x0, 0x28(%rbx)
movq %r13, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq