// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Hash_Table.cpp
// Function: lchain_qdp_mcopy(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(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 enable_mcopy, 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, bw, max_ii, ovl, movl, plus = 0, min_sc, ch_n; 
    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);
    t = dp->tmp; f = dp->score; p = dp->pre; ii = dp->occ;
    bw = ((xl < yl)?xl:yl); bw *= bw_rate;
    msc = msc_i = INT32_MIN; movl = INT32_MAX; ch_n = 1;
    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]);
    // }

    memset(t, 0, (a_n*sizeof((*t))));
    for (i = st = plus = 0, max_ii = -1; i < a_n; ++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(&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) {///just have a try with a[i]<->a[max_ii]
            tmp = comput_sc_ch(&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 == 0) {
        //     fprintf(stderr, "i::%ld[M::%s::utg%.6dl::%c] x::%u, y::%u, st::%ld, max_ii::%ld, f[i]::%d, p[i]::%ld, msc_i::%ld, msc::%ld, movl::%ld\n", 
        //                     i, __func__, (int32_t)a[i].readID+1, "+-"[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((movl < xl) && enable_mcopy/**(movl < yl)**/) {
        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)) {
                    t[ch_n] = ((uint64_t)f[i])<<32; t[ch_n] += (i<<1); ch_n++;
                }
            }
            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; --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(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]]));
                        ///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))) {
                            z->align_length = n_v-n_v0; z->x_id = n_v0;
                            n_u++;
                        } else {///non-best is too long
                            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 $0x118, %rsp            # imm = 0x118
movq %rcx, 0x80(%rsp)
testq %rdx, %rdx
jle 0x41488
movq %r8, %rbx
movq %rdx, %r13
movq %rsi, %rax
movq %rdi, %r12
movsd %xmm2, 0x100(%rsp)
movsd %xmm3, 0xb8(%rsp)
movq %r9, 0x58(%rsp)
movq %r8, %rdi
movq %rdx, %rsi
xorl %edx, %edx
movq %rax, %r14
movsd %xmm1, 0xe0(%rsp)
movsd %xmm0, 0xd8(%rsp)
callq 0x3ecb0
movq 0x28(%rbx), %rdi
movq (%rbx), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rbx), %rbp
movq 0x20(%rbx), %r15
movq %r12, 0xd0(%rsp)
movq (%r12), %rbx
shlq $0x4, %r14
leaq (%rbx,%r14), %r12
movq %r13, 0x90(%rsp)
leaq (,%r13,8), %rdx
movq %rdi, 0x40(%rsp)
xorl %esi, %esi
callq 0x20e0
movsd 0xd8(%rsp), %xmm6
movsd 0xe0(%rsp), %xmm5
movq %r15, %rsi
movq 0x170(%rsp), %rax
decq %rax
movq %rax, 0xe8(%rsp)
movq 0x158(%rsp), %rcx
movq %rcx, %rax
notq %rax
movq %rax, 0xf8(%rsp)
movq %rcx, %rax
negq %rax
movq %rax, 0xf0(%rsp)
movq %rbx, 0x70(%rsp)
movq %r14, 0xb0(%rsp)
leaq (%rbx,%r14), %rdi
addq $-0x8, %rdi
movq $-0x80000000, %r13      # imm = 0x80000000
movq $-0x1, 0xc8(%rsp)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x78(%rsp)
xorl %r8d, %r8d
xorl %r11d, %r11d
xorl %r15d, %r15d
movq $-0x80000000, 0xc0(%rsp) # imm = 0x80000000
movq %rsi, 0x18(%rsp)
movq %r12, 0x88(%rsp)
movq %rbp, 0x38(%rsp)
movsd 0x100(%rsp), %xmm4
movq %r8, %rcx
shlq $0x4, %rcx
leaq (%r12,%rcx), %rax
movq %rax, 0x20(%rsp)
movl (%r12,%rcx), %eax
movl 0xc(%r12,%rcx), %r9d
movzbl %r9b, %ecx
movq %rcx, 0x28(%rsp)
movq %r8, %rcx
subq %r11, %rcx
movq 0x158(%rsp), %rdx
cmpq %rcx, %rdx
cmovgq %rdx, %rcx
movq 0xf8(%rsp), %rdx
addq %r11, %rdx
addq %rcx, %rdx
addq 0xf0(%rsp), %r11
addq %rcx, %r11
shlq $0x4, %r11
addq %r12, %r11
movq %r11, %rcx
movq %rdx, %r11
incq %r11
movl (%rcx), %edx
addq $0x10, %rcx
xorl %eax, %edx
js 0x40ea1
movq %r15, 0x50(%rsp)
movq %r13, 0x110(%rsp)
leaq -0x1(%r8), %r14
cmpq %r11, %r8
movq %r8, 0x10(%rsp)
movq %rdi, 0x60(%rsp)
movq %r9, 0x108(%rsp)
jle 0x410b2
movq 0x20(%rsp), %r13
movl 0x8(%r13), %ebx
leal 0x1(%rbx), %ecx
movq 0x170(%rsp), %rdx
movq %rcx, 0xa0(%rsp)
subq %rcx, %rdx
movq %rdx, 0x98(%rsp)
movl %r9d, %r12d
shrl $0x8, %r12d
movslq %r8d, %rax
movq %rax, 0x68(%rsp)
movq $-0x1, 0x30(%rsp)
movq %rdi, %rsi
movq 0x28(%rsp), %r15
movq %r14, %rbp
xorl %r8d, %r8d
movl (%rsi), %r9d
movl %ebx, %ecx
subl %r9d, %ecx
testl %ecx, %ecx
jle 0x40fbf
movl 0x4(%r13), %edx
movl -0x4(%rsi), %r10d
movl %edx, %eax
subl %r10d, %eax
testl %eax, %eax
jle 0x40fbf
movl %ecx, %edi
subl %eax, %edi
negl %edi
movl %ecx, %r13d
subl %eax, %r13d
cmovbl %edi, %r13d
cmpl $0x11, %r13d
jl 0x40fc7
incl %edx
movq 0x178(%rsp), %rdi
subq %rdx, %rdi
movq %r10, %rdx
subq %r9, %rdx
cmpl %r10d, %r9d
movl $0x0, %r9d
cmovbeq %r9, %rdx
movq 0xa0(%rsp), %r9
addq %rdi, %r9
cmpq %rdi, 0x98(%rsp)
cmovleq 0x170(%rsp), %r9
addq %rdx, %r9
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
mulsd %xmm4, %xmm0
cvttsd2si %xmm0, %edx
cmpl %edx, %r13d
jle 0x40fc7
movq %r15, %rdi
movq 0x20(%rsp), %r13
jmp 0x41099
movq %r15, %rdi
jmp 0x41099
cmpl %ecx, %eax
cmovbl %eax, %ecx
movq 0x28(%rsp), %rax
cmpl %ecx, %eax
movl %ecx, %edx
cmovbl %eax, %edx
movl $0x1, %eax
cmpl %r12d, %edx
jb 0x40feb
movzbl %dl, %eax
divb %r12b
movzbl %al, %eax
cmpl %ecx, 0x28(%rsp)
jb 0x40ff6
testl %r13d, %r13d
je 0x4102f
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movapd %xmm0, %xmm1
cvtsi2sd %eax, %xmm2
mulsd %xmm6, %xmm1
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
divsd %xmm3, %xmm0
divsd %xmm4, %xmm0
mulsd %xmm2, %xmm0
minsd %xmm1, %xmm0
mulsd %xmm5, %xmm3
addsd %xmm0, %xmm3
cvttsd2si %xmm3, %ecx
subl %ecx, %eax
movq 0x20(%rsp), %r13
cltq
movq 0x48(%rsp), %rcx
movslq (%rcx,%rbp,4), %rdi
addq %rax, %rdi
cmpq %r15, %rdi
jle 0x41059
xorl %eax, %eax
testq %r8, %r8
setg %al
subq %rax, %r8
movq %rbp, 0x30(%rsp)
jmp 0x4107d
movq 0x40(%rsp), %rax
movq 0x68(%rsp), %rcx
cmpq %rcx, (%rax,%rbp,8)
jne 0x4107a
cmpq 0x150(%rsp), %r8
jge 0x4142b
incq %r8
movq %r15, %rdi
movq 0x38(%rsp), %rax
movq (%rax,%rbp,8), %rax
testq %rax, %rax
js 0x41099
movq 0x40(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
leaq -0x1(%rbp), %rax
addq $-0x10, %rsi
movq %rdi, %r15
cmpq %r11, %rbp
movq %rax, %rbp
jg 0x40f27
jmp 0x410c8
movq $-0x1, 0x30(%rsp)
movq %r14, %rax
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r13
movq 0xc8(%rsp), %rbx
testq %rbx, %rbx
movq 0x88(%rsp), %r12
movq 0x160(%rsp), %rbp
js 0x41108
movl 0x8(%r13), %edx
movq %rbx, %rcx
shlq $0x4, %rcx
movl 0x8(%r12,%rcx), %esi
addq %rbp, %rsi
cmpq %rdx, %rsi
jl 0x41108
addq %r12, %rcx
movl (%rcx), %ecx
xorl (%r13), %ecx
jns 0x41162
movq 0x10(%rsp), %r8
cmpq %r11, %r8
jle 0x41229
movl 0x8(%r13), %ecx
movq $-0x1, %rbx
movl $0x80000000, %esi       # imm = 0x80000000
movq 0x60(%rsp), %r8
movl (%r8), %edx
addq %rbp, %rdx
cmpq %rcx, %rdx
jl 0x41162
movl -0x8(%r8), %edx
xorl (%r13), %edx
js 0x41162
movq 0x48(%rsp), %rdx
movl (%rdx,%r14,4), %edx
cmpl %edx, %esi
cmovlq %r14, %rbx
cmovlel %edx, %esi
leaq -0x1(%r14), %rdx
addq $-0x10, %r8
cmpq %r11, %r14
movq %rdx, %r14
jg 0x4112b
testq %rbx, %rbx
sets %cl
cmpq %rax, %rbx
setge %al
orb %cl, %al
jne 0x4124d
movq %rbx, %rdx
shlq $0x4, %rdx
movl 0x8(%r13), %eax
movl 0x8(%r12,%rdx), %r9d
movl %eax, %ecx
subl %r9d, %ecx
testl %ecx, %ecx
jle 0x41215
addq %r12, %rdx
movl 0x4(%r13), %r15d
movl 0x4(%rdx), %r14d
movl %r15d, %r8d
subl %r14d, %r8d
testl %r8d, %r8d
jle 0x41215
movl %ecx, %edx
subl %r8d, %edx
negl %edx
movl %ecx, %esi
subl %r8d, %esi
cmovbl %edx, %esi
cmpl $0x11, %esi
jl 0x4127f
incl %eax
incl %r15d
movq 0x170(%rsp), %r13
movq %r13, %rdx
subq %rax, %rdx
movq 0x178(%rsp), %r10
subq %r15, %r10
movq %r14, %r15
subq %r9, %r15
cmpl %r14d, %r9d
movl $0x0, %r9d
cmovbeq %r9, %r15
addq %r10, %rax
cmpq %r10, %rdx
cmovleq %r13, %rax
movq 0x20(%rsp), %r13
addq %r15, %rax
cvtsi2sd %rax, %xmm0
mulsd %xmm4, %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %esi
jle 0x4127f
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %r8
movq 0x50(%rsp), %r9
jmp 0x41322
movq 0x48(%rsp), %rax
movl %edi, (%rax,%r8,4)
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %rax
movq %rax, (%r14,%r8,8)
movq %r8, %rax
movq 0x50(%rsp), %r9
jmp 0x41366
movq 0x48(%rsp), %rax
movq 0x10(%rsp), %r8
movl %edi, (%rax,%r8,4)
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %rax
movq %rax, (%r14,%r8,8)
movq %r8, %rax
testq %rbx, %rbx
movq 0x50(%rsp), %r9
jns 0x41334
jmp 0x41366
cmpl %ecx, %r8d
cmovbl %r8d, %ecx
movq 0x28(%rsp), %rax
cmpl %ecx, %eax
movl %ecx, %edx
cmovbl %eax, %edx
movq 0x108(%rsp), %r8
shrl $0x8, %r8d
movl $0x1, %eax
cmpl %r8d, %edx
jb 0x412b1
movzbl %dl, %eax
divb %r8b
movzbl %al, %eax
cmpl %ecx, 0x28(%rsp)
jb 0x412bb
testl %esi, %esi
je 0x412f0
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movapd %xmm0, %xmm1
cvtsi2sd %eax, %xmm2
mulsd %xmm6, %xmm1
cvtsi2sd %ecx, %xmm3
divsd %xmm3, %xmm0
divsd %xmm4, %xmm0
mulsd %xmm2, %xmm0
minsd %xmm1, %xmm0
mulsd %xmm5, %xmm3
addsd %xmm0, %xmm3
cvttsd2si %xmm3, %ecx
subl %ecx, %eax
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %r8
movq 0x50(%rsp), %r9
movq 0x48(%rsp), %rcx
movslq (%rcx,%rbx,4), %rcx
cltq
addq %rcx, %rax
cmpq %rax, %rdi
movq 0x30(%rsp), %rcx
cmovlq %rbx, %rcx
movq %rcx, 0x30(%rsp)
cmovleq %rax, %rdi
movq 0x48(%rsp), %rax
movl %edi, (%rax,%r8,4)
movq 0x30(%rsp), %rax
movq %rax, (%r14,%r8,8)
movl 0x8(%r13), %ecx
movq %rbx, %rax
shlq $0x4, %rax
movl 0x8(%r12,%rax), %edx
addq %rbp, %rdx
cmpq %rcx, %rdx
jl 0x41363
addq %r12, %rax
movl (%rax), %eax
xorl (%r13), %eax
js 0x41363
movq 0x48(%rsp), %rax
cmpl %edi, (%rax,%rbx,4)
cmovlq %r8, %rbx
movq %rbx, %rax
movq %rax, 0xc8(%rsp)
movslq %edi, %r15
movq 0x110(%rsp), %r13
cmpq %r15, %r13
jle 0x4138a
movq 0x18(%rsp), %rsi
movq 0x60(%rsp), %rdi
jmp 0x41405
movq 0x20(%rsp), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %edx
movq %rcx, %rax
subq %rdx, %rax
incq %rax
movq %rdx, %rsi
notq %rsi
addq 0x170(%rsp), %rsi
movq %rcx, %rdi
notq %rdi
addq 0x178(%rsp), %rdi
movq %rdx, %r8
addq %rdi, %r8
cmpq %rdi, %rsi
cmovleq 0xe8(%rsp), %r8
cmpl %ecx, %edx
movl $0x1, %ecx
cmovbeq %rcx, %rax
addq %r8, %rax
movq 0x10(%rsp), %r8
cmpq %r15, %r13
movq 0x18(%rsp), %rsi
movq 0x60(%rsp), %rdi
jl 0x413f5
cmpq 0x78(%rsp), %rax
jge 0x41405
movq %r8, 0xc0(%rsp)
movq %r15, %r13
movq %rax, 0x78(%rsp)
cmpq %r15, %r9
cmovlq %r9, %r15
movl $0x0, (%rsi,%r8,4)
incq %r8
addq $0x10, %rdi
cmpq 0x90(%rsp), %r8
jne 0x40e44
jmp 0x41436
movq %rbp, %rax
movq %r15, %rdi
jmp 0x410c8
movq 0x80(%rsp), %r11
shlq $0x4, %r11
movq 0xc0(%rsp), %r10
xorl %ebp, %ebp
testq %r10, %r10
js 0x4148f
movq %r10, %rax
movq 0x70(%rsp), %rdx
movq 0x40(%rsp), %rdi
movq 0x90(%rsp), %r9
movsd 0xb8(%rsp), %xmm1
movl $0x1, (%rsi,%rax,4)
movq %rax, (%rdi,%rbp,8)
incq %rbp
movq (%r14,%rax,8), %rax
testq %rax, %rax
jns 0x4146f
jmp 0x414aa
xorl %ebp, %ebp
jmp 0x41b95
movq 0x70(%rsp), %rdx
movq 0x40(%rsp), %rdi
movq 0x90(%rsp), %r9
movsd 0xb8(%rsp), %xmm1
addq %r11, %rdx
movq 0x78(%rsp), %rax
cmpq 0x170(%rsp), %rax
setge %al
cmpq $0x0, 0x198(%rsp)
sete %cl
orb %al, %cl
cmpq 0x1a0(%rsp), %rbp
setl %al
orb %cl, %al
movq %rdx, 0x70(%rsp)
je 0x4163c
movq 0x58(%rsp), %r15
movq (%r15), %r12
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rax
jne 0x41555
imulq $0x150, %rax, %rcx      # imm = 0x150
testq %rax, %rax
movl $0x150, %esi            # imm = 0x150
cmovneq %rcx, %rsi
movq %r12, %rdi
callq 0x2370
movq %rax, %r12
movq %rax, (%r15)
movq 0x8(%r15), %rax
imulq $0xa8, %rax, %rdi
addq %r12, %rdi
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %ebx
cmovneq %rcx, %rbx
movq %rbx, %rcx
subq %rax, %rcx
imulq $0xa8, %rcx, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x40(%rsp), %rdi
movq %rbx, 0x8(%r15)
movq 0x10(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r15)
imulq $0xa8, %rax, %r14
addq %r12, %r14
movq -0x8(%rdi,%rbp,8), %r9
shlq $0x4, %r9
movq 0x88(%rsp), %rbx
addq %rbx, %r9
movq (%rdi), %rax
shlq $0x4, %rax
addq %rbx, %rax
movq %rax, (%rsp)
movq %r14, %rdi
movl 0x168(%rsp), %esi
movq 0x170(%rsp), %rdx
movq 0x178(%rsp), %rcx
movq %r13, %r8
callq 0x408f3
movq 0x40(%rsp), %r9
testq %rbp, %rbp
movq 0x70(%rsp), %rcx
je 0x415f7
movl $0x80000000, %eax       # imm = 0x80000000
movq %rcx, %r8
movq %rbp, %rdx
movq -0x8(%r9,%rdx,8), %rsi
shlq $0x4, %rsi
movupd (%rbx,%rsi), %xmm0
movupd %xmm0, (%r8)
movl 0x10(%r15), %esi
decl %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl (%r8), %edi
andl %eax, %edi
orl %esi, %edi
movl %edi, (%r8)
addq $0x10, %r8
decq %rdx
jne 0x415c5
movq 0x80(%rsp), %rax
movl %eax, 0x30(%r14)
cmpq $0x0, 0x190(%rsp)
je 0x41624
leaq 0x38(%r14), %rdi
movl 0x188(%rsp), %edx
movq %r14, %rsi
movq %rbp, %r8
callq 0x3d133
cmpq $0x0, 0x1a8(%rsp)
je 0x41b95
movl %ebp, 0x28(%r14)
jmp 0x41b95
movq %r13, %rax
subq %r15, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rbx
movl $0x0, (%rsi,%r10,4)
xorl %eax, %eax
xorl %r12d, %r12d
movq 0x48(%rsp), %r8
movl (%r8,%rax,4), %ecx
subl %r15d, %ecx
movl %ecx, (%r8,%rax,4)
cmpq %r12, %rax
jl 0x4167d
movq $0x0, (%rdi,%rax,8)
cmpl $0x0, (%rsi,%rax,4)
jne 0x4169a
movslq %ecx, %rcx
cmpq %rbx, %rcx
jl 0x4169a
shlq $0x20, %rcx
leaq (%rcx,%rax,2), %rcx
movq %rcx, (%rdi,%r12,8)
incq %r12
incq %rax
cmpq %r9, %rax
jne 0x41665
cmpq $0x1, %r12
jle 0x41abe
movq %r11, 0x60(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x68(%rsp)
leaq (%rdi,%r12,8), %rsi
callq 0x3c6fd
movq 0x40(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq $0x0, 0xa8(%rsp)
shlq $0x2, 0x78(%rsp)
movq $0x0, 0x30(%rsp)
xorl %esi, %esi
movq %rbx, 0x10(%rsp)
leaq -0x1(%r12), %rax
movq %rax, 0x28(%rsp)
movl -0x8(%rcx,%r12,8), %ebp
shrl %ebp
movq %rsi, %r13
movq (%rcx,%rbp,8), %rax
testb $0x1, %al
jne 0x41728
movl %ebp, (%rdx,%r13,4)
incq %r13
orq $0x1, %rax
movq %rax, (%rcx,%rbp,8)
movq (%r14,%rbp,8), %rbp
testq %rbp, %rbp
jns 0x41708
cmpq %rsi, %r13
je 0x418ab
movq 0x28(%rsp), %rax
movslq 0x4(%rcx,%rax,8), %r8
testq %rbp, %rbp
js 0x4174c
movq 0x48(%rsp), %rax
movslq (%rax,%rbp,4), %rax
subq %rax, %r8
cmpq %rbx, %r8
jl 0x418ab
movq 0x58(%rsp), %r14
movq (%r14), %rdi
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
movq %rsi, 0x20(%rsp)
jne 0x417eb
imulq $0x150, %rax, %rsi      # imm = 0x150
testq %rax, %rax
movl $0x150, %eax            # imm = 0x150
cmoveq %rax, %rsi
movq %r8, 0xa0(%rsp)
callq 0x2370
movq %rax, 0x98(%rsp)
movq %rax, (%r14)
movq 0x8(%r14), %rdx
imulq $0xa8, %rdx, %rdi
addq %rax, %rdi
leaq (%rdx,%rdx), %rbx
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rbx
movq %rbx, %rcx
subq %rdx, %rcx
imulq $0xa8, %rcx, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x98(%rsp), %rdi
movq 0xa0(%rsp), %r8
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbx, 0x8(%r14)
movq 0x10(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r14)
imulq $0xa8, %rax, %rbx
addq %rdi, %rbx
addq %r15, %r8
movslq -0x4(%rdx,%r13,4), %r9
shlq $0x4, %r9
movq 0x88(%rsp), %rcx
addq %rcx, %r9
movslq (%rdx,%rsi,4), %rax
shlq $0x4, %rax
addq %rcx, %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movl 0x168(%rsp), %esi
movq 0x170(%rsp), %rdx
movq 0x178(%rsp), %rcx
callq 0x408f3
cmpq $0x2, 0x1a0(%rsp)
jl 0x41880
movl 0x8(%rbx), %eax
subl 0x4(%rbx), %eax
incl %eax
cmpq %rax, 0x78(%rsp)
jge 0x41880
movq 0x58(%rsp), %rax
decq 0x10(%rax)
movq 0x18(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %rsi
jmp 0x418ab
movl %r13d, %eax
movq 0x20(%rsp), %rcx
subl %ecx, %eax
movl %eax, 0x28(%rbx)
movl %ecx, (%rbx)
incq 0x30(%rsp)
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %rbx
cmpq $0x1, %r12
movq 0x28(%rsp), %r12
jg 0x416f4
movq %rsi, 0xa8(%rsp)
movq 0x30(%rsp), %r12
cmpq $0x2, %r12
movq 0x58(%rsp), %r15
movq 0x68(%rsp), %rbx
jl 0x418e9
imulq $0xa8, %rbx, %rsi
addq (%r15), %rsi
movq %r12, %rdi
callq 0x3cbb4
imulq $0xa8, %rbx, %r14
movq (%r15), %rdi
addq %r14, %rdi
leaq 0xa8(%rsp), %rdx
movq %r12, %rsi
callq 0x40b77
leaq (%rax,%rbx), %rcx
movq %rcx, 0x28(%rsp)
movq %rcx, 0x10(%r15)
cmpq $0x2, %rax
jl 0x41ad6
movq 0xd0(%rsp), %r14
movq (%r14), %rax
movq 0x8(%r14), %rbx
movq 0xa8(%rsp), %rcx
addq %rbx, %rcx
cmpq %rcx, 0x10(%r14)
jge 0x4198b
decq %rcx
movq %rcx, %rdx
sarq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
sarq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
sarq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
sarq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rsi
sarq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x10(%r14)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%r14), %rbx
movq 0xb0(%rsp), %r11
movq 0x18(%rsp), %rcx
movq 0x68(%rsp), %r12
addq %rax, %r11
addq %rax, 0x60(%rsp)
shlq $0x4, %rbx
addq %rax, %rbx
addq $-0x4, %rcx
movq %rcx, 0x18(%rsp)
xorl %ebp, %ebp
movl $0x80000000, %r13d      # imm = 0x80000000
movq (%r15), %r15
imulq $0xa8, %r12, %rax
movq 0x80(%rsp), %rcx
addl %ebp, %ecx
movl %ecx, 0x30(%r15,%rax)
movl 0x28(%r15,%rax), %r8d
testq %r8, %r8
je 0x41a3a
movl (%r15,%rax), %esi
movl %r12d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %r8, %rdx
negq %rdx
shlq $0x2, %rsi
leaq (%rsi,%r8,4), %rsi
addq 0x18(%rsp), %rsi
movq %rbp, %rdi
shlq $0x4, %rdi
addq %rbx, %rdi
xorl %r9d, %r9d
movslq (%rsi,%r9,4), %r10
shlq $0x4, %r10
movupd (%r11,%r10), %xmm0
movupd %xmm0, (%rdi)
movl (%rdi), %r10d
andl %r13d, %r10d
orl %ecx, %r10d
movl %r10d, (%rdi)
decq %r9
addq $0x10, %rdi
cmpq %r9, %rdx
jne 0x41a0d
subq %r9, %rbp
addq %rax, %r15
movl 0x168(%rsp), %eax
movl %eax, (%r15)
cmpq $0x0, 0x190(%rsp)
je 0x41a7f
leaq 0x38(%r15), %rdi
movq %rbp, %rcx
shlq $0x4, %rcx
addq %rbx, %rcx
movq %r8, %rax
shlq $0x4, %rax
subq %rax, %rcx
movq %r15, %rsi
movl 0x188(%rsp), %edx
movq %r11, %r14
callq 0x3d133
movq %r14, %r11
cmpq $0x0, 0x1a8(%rsp)
jne 0x41a92
movl $0x0, 0x28(%r15)
incq %r12
cmpq 0x28(%rsp), %r12
movq 0x58(%rsp), %r15
jl 0x419bd
movq %rbp, %rdx
shlq $0x4, %rdx
movq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x2160
jmp 0x41b95
xorl %ebp, %ebp
testq %r10, %r10
js 0x414e3
movq %r10, (%rdi,%rbp,8)
incq %rbp
movq (%r14,%r10,8), %r10
jmp 0x41ac0
cmpq $0x1, %rax
movq 0x18(%rsp), %rdx
jne 0x41b95
movq (%r15), %rax
leaq (%rax,%r14), %rbx
movq 0x80(%rsp), %rcx
movl %ecx, 0x30(%rax,%r14)
movl 0x28(%rax,%r14), %ebp
testq %rbp, %rbp
movq 0x70(%rsp), %rcx
movq 0x88(%rsp), %r9
movq 0x68(%rsp), %r10
je 0x41b59
movl (%rax,%r14), %eax
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
leaq (%rdx,%rax,4), %rax
addq $-0x4, %rax
movl $0x80000000, %r8d       # imm = 0x80000000
movq %rbp, %rdx
movq %rcx, %rsi
movslq (%rax,%rdx,4), %rdi
shlq $0x4, %rdi
movupd (%r9,%rdi), %xmm0
movupd %xmm0, (%rsi)
movl (%rsi), %edi
andl %r8d, %edi
orl %r10d, %edi
movl %edi, (%rsi)
addq $0x10, %rsi
decq %rdx
jne 0x41b34
movl 0x168(%rsp), %eax
movl %eax, (%rbx)
cmpq $0x0, 0x190(%rsp)
je 0x41b83
leaq 0x38(%rbx), %rdi
movl 0x188(%rsp), %edx
movq %rbx, %rsi
movq %rbp, %r8
callq 0x3d133
cmpq $0x0, 0x1a8(%rsp)
jne 0x41b95
movl $0x0, 0x28(%rbx)
movq %rbp, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq