// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: linear_ctg_trans_chain_dp(unsigned int, ul_ov_t*, long, ul_idx_t const*, ug_opt_t const*, long, double, double, double, long, long, long, long, long, Chain_Data*, ul_ov_t*, asg64_v*)
uint64_t linear_ctg_trans_chain_dp(uint32_t qid, ul_ov_t *ch, int64_t ch_n, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, double ovlp_max, double unmatch_max, int64_t qlen, int64_t tlen, int64_t max_skip, int64_t max_iter, int64_t max_dis, Chain_Data* dp, ul_ov_t *res, asg64_v *ea)
{
	memset(res, 0, sizeof((*res)));
	if(ch_n == 0) return 0;
    int64_t i, j, k, l, sc, csc, se, cse, mm_sc, mm_se, mm_idx, max, max_e, peak_sc, peak_e, peak_i, rts, rte, rqs, rqe;
    ul_ov_t *li = NULL, *lj = NULL; int64_t *f, *e, st, plus, max_ii, n_skip, end_j; int32_t *p, *t;
    resize_Chain_Data(dp, ch_n, NULL);
    e = dp->tmp; f = dp->pre; p = dp->score; t = dp->indels;

	i = 0;
	if(i < ch_n) {
		ch[i].tn >>= 1;
		if(ch[i].rev) {
			adjust_rev_tse(&(ch[i]), tlen, &rts, &rte);
			ch[i].ts = rts; ch[i].te = rte; 
		}
	}

	for (i = 1, j = 0; i <= ch_n; i++) {
		if(i < ch_n) {
			ch[i].tn >>= 1;
			if(ch[i].rev) {
				adjust_rev_tse(&(ch[i]), tlen, &rts, &rte);
				ch[i].ts = rts; ch[i].te = rte; 
			}
		}
        if (i == ch_n || ch[i].rev != ch[j].rev) {
            if(i - j > 1) {
				radix_sort_ul_ov_srt_qe(ch+j, ch+i);
				for (k = j + 1, l = j; k <= i; k++) {
					if(k == i || ch[k].qe != ch[l].qe) {
						if(k - l > 1) radix_sort_ul_ov_srt_qs(ch+l, ch+k);
						l = k;
					}
				}
			}
            j = i;
        }
    }

    // fprintf(stderr, "[M::%s::] ch_n:%ld\n", __func__, ch_n);
    memset(t, 0, (ch_n*sizeof((*t)))); peak_sc = peak_e = peak_i = INT32_MIN;
    for (i = st = plus = 0, max_ii = -1; i < ch_n; ++i) {
        li = &(ch[i]); csc = li->sec; cse = 0; 
		if(li->el || li->qn == RC_0 || li->qn == RC_1) cse = li->qe - li->qs;

        mm_sc = csc; mm_se = cse; mm_idx = -1; n_skip = 0; end_j = -1; 
        st = (i<max_iter)?(0):(i-max_iter);
		while (ch[i].rev != ch[st].rev) ++st;

		// if(qid == 2 && qlen == 112183461 && ch[i].tn == 30 && tlen == 24761445) {
		// 	 fprintf(stderr, "+(%ld)[M::%s] h2tg%.6u%c\t%ld\t%u\t%u\t%c\th1tg%.6u%c\t%ld\t%u\t%u\tsec(%u)\tel(%u)\tf(%u)\n", i, __func__,
        //     	qid+1, "lc"[0], qlen, ch[i].qs, ch[i].qe, "+-"[ch[i].rev], ch[i].tn+1, "lc"[0], tlen, ch[i].ts, ch[i].te, ch[i].sec, ch[i].el, ch[i].qn);
		// } else if(ch[i].tn == 2 && tlen == 112183461 && ch[i].qn == 30 && qlen == 24761445) {
		// 	fprintf(stderr, "+(%ld)[M::%s] h1tg%.6u%c\t%ld\t%u\t%u\t%c\th2tg%.6u%c\t%ld\t%u\t%u\tsec(%u)\tel(%u)\tf(%u)\n", i, __func__,
        //     	qid+1, "lc"[0], qlen, ch[i].qs, ch[i].qe, "+-"[ch[i].rev], ch[i].tn+1, "lc"[0], tlen, ch[i].ts, ch[i].te, ch[i].sec, ch[i].el, ch[i].qn);
		// }

        for (j = i-1; j >= st; --j) {
            lj = &(ch[j]); 
            sc = comput_linear_ctg_trans_sc(li, lj, diff_ec_ul, ovlp_max, bw); ///should allow contain
            if(sc == INT32_MIN) continue;
            sc += f[j]; se = cse + e[j];
            if((sc > mm_sc) || (sc == mm_sc && se > mm_se)) {
                mm_sc = sc, mm_se = se, mm_idx = j;
                if (n_skip > 0) --n_skip;
            } else if (t[j] == i) {
                if (++n_skip > max_skip)
                    break;
            }
            if (p[j] >= 0) t[p[j]] = i;
        }


        end_j = j;
        if (max_ii < 0 || (ch[i].qe>(ch[max_ii].qe+max_dis))) {//too long
            max = INT32_MIN; max_e = INT32_MIN; max_ii = -1;
            for (j = i - 1; (j >= st) && (ch[i].qe<=(max_dis+ch[j].qe)); --j) {
                if ((max < f[j]) || (max == f[j] && max_e < e[j])) {
                    max = f[j], max_e = e[j], max_ii = j;
                }
            }
        }
        
        if (max_ii >= 0 && max_ii < end_j) {///just have a try with a[i]<->a[max_ii]
            lj = &(ch[max_ii]); 
            sc = comput_linear_ctg_trans_sc(li, lj, diff_ec_ul, ovlp_max, bw); ///should allow contain
            if(sc != INT32_MIN) {
                sc += f[max_ii];
				se = cse + e[max_ii];
                if((sc > mm_sc) || (sc == mm_sc && se > mm_se)) {
                    mm_sc = sc; mm_se = se; mm_idx = max_ii;
                }
            }
        }
		
        f[i] = mm_sc; e[i] = mm_se; p[i] = mm_idx; 
        if ((max_ii < 0) || ((ch[i].qe<=max_dis+ch[max_ii].qe) && ((f[max_ii]<f[i]) || (f[max_ii] == f[i] && e[max_ii] < e[i])))) {
            max_ii = i;
        }

		if((f[i] > peak_sc) || (f[i] == peak_sc || e[i] > peak_e)) {
			peak_sc = f[i]; peak_e = e[i]; peak_i = i;
		}
        // li->sec = (mm_idx<0?0x3FFFFFFF:i-mm_idx); 
        // sv[i] = *li;
        // fprintf(stderr, "##(%ld) %u\t%u\t%c\tutg%.6d%c(%u)\t%u\t%u\tmm_idx:%ld\tmm_sc:%ld\n", i, li->qs, li->qe, "+-"[li->rev], 
        // (int32_t)(li->tn)+1, "lc"[uref->ug->u.a[li->tn].circ], uref->ug->u.a[li->tn].len, li->ts, li->te, mm_idx, mm_sc);
        // track[i] = push_sc_pre(mm_sc, mm_idx); 
        // li->sec = (mm_idx<0?0x3FFFFFFF:i-mm_idx); sv[i] = *li;
    }

	if(peak_i < 0) return 0;

	uint64_t qs, qgap = 0, ts, tgap = 0, eqs = (uint64_t)-1, eqe = (uint64_t)-1, ea_n = ea->n;
	i = peak_i; *res = ch[i]; 
	res->qn = ((peak_sc>UINT32_MAX)?(UINT32_MAX):(peak_sc));
	res->sec = 0; qs = res->qs; ts = res->ts; 

	// memset(er, 0, sizeof((*er))); er->qs = er->qe = er->ts = er->te = (uint32_t)-1;
	// er->qn = ((peak_e>UINT32_MAX)?(UINT32_MAX):(peak_e));
    
	///has been sorted by qe && te
	while (i >= 0) {
		if(ch[i].qe >= qs) {
			if(ch[i].qs < qs) qs = ch[i].qs;
		} else {
			qgap += qs - ch[i].qe;
			qs = ch[i].qs; 
		}

		if(ch[i].te >= ts) {
			if(ch[i].ts < ts) ts = ch[i].ts;
		} else {
			tgap += ts - ch[i].te;
			ts = ch[i].ts; 
		} 

		if(ch[i].el || ch[i].qn == RC_0 || ch[i].qn == RC_1) {///reliable
			if ((ea->n > ea_n) && (ch[i].qe >= (ea->a[ea->n-1]>>32))) {
				if(ch[i].qs < (ea->a[ea->n-1]>>32)) {
					eqs = ch[i].qs; eqe = (uint32_t)(ea->a[ea->n-1]);
					ea->a[ea->n-1] = eqs << 32; ea->a[ea->n-1] |= eqe;
				}
			} else {
				eqs = ch[i].qs; eqe = ch[i].qe; eqs <<= 32; eqs |= eqe;
				kv_push(uint64_t, *ea, eqs);
				// ea->a[ea->n-1] = eqs << 32; ea->a[ea->n-1] |= eqe;
			}
		}

		if(ch[i].qs < res->qs) res->qs = ch[i].qs;
		if(ch[i].qe > res->qe) res->qe = ch[i].qe;
		if(ch[i].ts < res->ts) res->ts = ch[i].ts;
		if(ch[i].te > res->te) res->te = ch[i].te;
		// if(qid == 2 && qlen == 112183461 && ch[i].tn == 30 && tlen == 24761445) {
		// 	 fprintf(stderr, "-(%ld)[M::%s] h2tg%.6u%c\t%ld\t%u\t%u\t%c\th1tg%.6u%c\t%ld\t%u\t%u\tsec(%u)\tel(%u)\tf(%u)\n", i, __func__,
        //     	qid+1, "lc"[0], qlen, ch[i].qs, ch[i].qe, "+-"[ch[i].rev], ch[i].tn+1, "lc"[0], tlen, ch[i].ts, ch[i].te, ch[i].sec, ch[i].el, ch[i].qn);
		// } else if(ch[i].tn == 2 && tlen == 112183461 && ch[i].qn == 30 && qlen == 24761445) {
		// 	fprintf(stderr, "-(%ld)[M::%s] h1tg%.6u%c\t%ld\t%u\t%u\t%c\th2tg%.6u%c\t%ld\t%u\t%u\tsec(%u)\tel(%u)\tf(%u)\n", i, __func__,
        //     	qid+1, "lc"[0], qlen, ch[i].qs, ch[i].qe, "+-"[ch[i].rev], ch[i].tn+1, "lc"[0], tlen, ch[i].ts, ch[i].te, ch[i].sec, ch[i].el, ch[i].qn);
		// }
        i = p[i];
    }
	////0x3fffffff
	// if(qgap > 0x3fffffff || tgap > 0x3fffffff) {
	// 	ea->n = ea_n; return 0;
	// }

	adjust_rev_tse(res, tlen, &rts, &rte);
	res->ts = rts; res->te = rte; 
	extend_end_coord(NULL, res, qlen, tlen, &rqs, &rqe, &rts, &rte);
	qgap += (rqe - rqs) - (res->qe - res->qs);
	tgap += (rte - rts) - (res->te - res->ts);

	// if(qid == 2 && qlen == 112183461 && ch[0].tn == 30 && tlen == 24761445) {
	// 	fprintf(stderr, "+(%ld)[M::%s] h2tg%.6u%c\t%ld\t%ld(%u)\t%ld(%u)\t%c\th1tg%.6u%c\t%ld\t%ld(%u)\t%ld(%u)\tqgap(%ld)\ttgap(%ld)\n", i, __func__,
	// 	qid+1, "lc"[0], qlen, rqs, res->qs, rqe, res->qe, "+-"[ch[0].rev], ch[0].tn+1, "lc"[0], tlen, rts, res->ts, rte, res->te, qgap, tgap);
	// } else if(ch[i].tn == 2 && tlen == 112183461 && ch[0].qn == 30 && qlen == 24761445) {
	// 	fprintf(stderr, "+(%ld)[M::%s] h2tg%.6u%c\t%ld\t%ld(%u)\t%ld(%u)\t%c\th1tg%.6u%c\t%ld\t%ld(%u)\t%ld(%u)\tqgap(%ld)\ttgap(%ld)\n", i, __func__,
	// 	qid+1, "lc"[0], qlen, rqs, res->qs, rqe, res->qe, "+-"[ch[0].rev], ch[0].tn+1, "lc"[0], tlen, rts, res->ts, rte, res->te, qgap, tgap);
	// }

	// if(qgap > 0x3fffffff || tgap > 0x3fffffff) {
	// 	ea->n = ea_n; return 0;
	// }
	if((qgap > ((rqe-rqs)*unmatch_max)) || (tgap > ((rte-rts)*unmatch_max))) {
		ea->n = ea_n; return 0;
	}

	double qrate = ((double)((rqe-rqs)-qgap))/((double)(rqe-rqs));
	double trate = ((double)((rte-rts)-tgap))/((double)(rte-rts));
	double mrate = MIN(qrate, trate); if(mrate < 0) mrate = 0;
	res->qn *= mrate; 
	if(res->qn <= 0) {
		ea->n = ea_n; return 0;
	}

	res->qs = rqs; res->qe = rqe; res->ts = rts; res->te = rte;
	res->sec = (0x3fffffff);
	if(ea->n > ea_n) {
		uint64_t *a = ea->a + ea_n, an = ea->n - ea_n, ai, an1 = an>>1;
		for(ai = 0; ai < an1; ai++) {
			qs = a[ai]; a[ai] = a[an - ai - 1]; a[an - ai - 1] = qs;
		}
		res->sec = ea->n; kv_push(uint64_t, *ea, an);
	}

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x170(%rsp), %rax
xorpd %xmm3, %xmm3
movupd %xmm3, 0xc(%rax)
movupd %xmm3, (%rax)
testq %rdx, %rdx
je 0x1cf11d
movq %rsi, %rcx
movq %r9, 0x10(%rsp)
movsd %xmm0, 0xa8(%rsp)
movsd %xmm1, 0xb0(%rsp)
movsd %xmm2, 0xb8(%rsp)
movq 0x168(%rsp), %rbx
movq %rbx, %rdi
movq %rdx, %rsi
movq %rdx, 0x30(%rsp)
xorl %edx, %edx
movq %rcx, 0x8(%rsp)
callq 0x3f828
movq 0x30(%rsp), %rdx
movq 0x8(%rsp), %r8
movq 0x28(%rbx), %rax
movq %rax, 0x40(%rsp)
movq (%rbx), %rax
movq %rax, 0x68(%rsp)
movq 0x8(%rbx), %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x80(%rsp)
testq %rdx, %rdx
jle 0x1ce393
shrl 0xc(%r8)
cmpl $0x0, 0x18(%r8)
jns 0x1ce393
movl 0x10(%r8), %eax
movq %rax, 0x50(%rsp)
movl 0x14(%r8), %ecx
movq 0x148(%rsp), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
movq %rdx, 0x50(%rsp)
movq %rsi, %rcx
subq %rax, %rcx
movq %rcx, 0x70(%rsp)
movl %edx, 0x10(%r8)
movq 0x30(%rsp), %rdx
movl %ecx, 0x14(%r8)
testq %rdx, %rdx
jle 0x1ce507
leaq 0x1c(%r8), %r15
movl $0x1, %ebp
xorl %r12d, %r12d
xorl %r14d, %r14d
leaq (,%rbp,8), %rax
addq %rbp, %rax
cmpq %rdx, %rbp
jge 0x1ce40b
leaq (%rax,%rax,2), %rcx
addq %rbp, %rcx
shrl 0xc(%r8,%rcx)
cmpl $0x0, 0x18(%r8,%rcx)
jns 0x1ce40b
addq %r8, %rcx
movl 0x10(%rcx), %edx
movq %rdx, 0x50(%rsp)
movl 0x14(%rcx), %esi
movq 0x148(%rsp), %r8
movq %r8, %rdi
subq %rsi, %rdi
movq %rdi, 0x50(%rsp)
movq %r8, %rsi
movq 0x8(%rsp), %r8
subq %rdx, %rsi
movq 0x30(%rsp), %rdx
movq %rsi, 0x70(%rsp)
movl %edi, 0x10(%rcx)
movl %esi, 0x14(%rcx)
cmpq %rdx, %rbp
je 0x1ce436
leaq (%rax,%rax,2), %rcx
addq %rbp, %rcx
leaq (%r14,%r14,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %r14, %rdx
movl 0x18(%r8,%rdx), %edx
xorl 0x18(%r8,%rcx), %edx
js 0x1ce436
movq %r14, %rcx
jmp 0x1ce4ec
movq %rbp, %rdx
subq %r14, %rdx
movq %rbp, %rcx
cmpq $0x2, %rdx
jl 0x1ce4ec
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rbx
leaq (%r8,%r14), %rdi
addq %rbx, %rdi
leaq (%rax,%rax,2), %rsi
addq %r8, %rsi
addq %rbp, %rsi
callq 0x195511
movq 0x8(%rsp), %r8
movq %rbp, %rcx
cmpq %r14, %rbp
jle 0x1ce4ec
leaq 0x1(%r14), %r13
addq %r15, %rbx
addq %r14, %rbx
leaq (%r12,%r13), %rax
cmpq $0x1, %rax
je 0x1ce4a2
movl 0x8(%rbx), %eax
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
cmpl 0x8(%r8,%rcx), %eax
jne 0x1ce4a2
movq %r14, %rax
jmp 0x1ce4d2
movq %r13, %rcx
subq %r14, %rcx
movq %r13, %rax
cmpq $0x2, %rcx
jl 0x1ce4d2
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r8, %r14
addq %rax, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1957bd
movq 0x8(%rsp), %r8
movq %r13, %rax
leaq (%r12,%r13), %rcx
incq %rcx
incq %r13
addq $0x1c, %rbx
movq %rax, %r14
cmpq $0x2, %rcx
jne 0x1ce47e
movq %rbp, %rcx
leaq 0x1(%rbp), %rax
decq %r12
movq %rcx, %r14
movq 0x30(%rsp), %rdx
cmpq %rdx, %rbp
movq %rax, %rbp
jne 0x1ce3ab
movq 0x30(%rsp), %rax
leaq (,%rax,4), %rdx
movq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x20e0
cmpq $0x0, 0x30(%rsp)
jle 0x1cec67
movq 0x158(%rsp), %rcx
movq %rcx, %rax
notq %rax
movq %rax, 0xc8(%rsp)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
negq %rax
movq 0x8(%rsp), %r8
addq %r8, %rax
addq $0x18, %rax
movq %rax, 0xc0(%rsp)
leaq -0x4(%r8), %r15
leaq -0x14(%r8), %rax
movq %rax, 0x88(%rsp)
movq $-0x80000000, %r9       # imm = 0x80000000
movq $-0x1, 0x58(%rsp)
xorl %r12d, %r12d
movq $-0x80000000, %rdi      # imm = 0x80000000
movq $-0x80000000, %rsi      # imm = 0x80000000
movsd 0xb0(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm2
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %rbx
movq 0x158(%rsp), %rax
cmpq %r12, %rax
movq %r12, %rcx
cmovgq %rax, %rcx
leaq (%r12,%r12,8), %rax
leaq (%rax,%rax,2), %rax
addq %r12, %rax
leaq (%r8,%rax), %rbp
movl 0x18(%r8,%rax), %edx
btl $0x1e, %edx
movq %r9, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
jb 0x1ce5f6
cmpl $0x1, (%rbp)
ja 0x1ce600
movl 0x8(%rbp), %r8d
subl 0x4(%rbp), %r8d
jmp 0x1ce603
xorl %r8d, %r8d
movq 0xc8(%rsp), %rax
leaq (%rax,%rcx), %r9
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq 0xc0(%rsp), %rcx
addq %rax, %rcx
movl %edx, %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
incq %r9
movl (%rcx), %esi
addq $0x1c, %rcx
xorl %edx, %esi
js 0x1ce629
leaq -0x1(%r12), %r13
cmpq %r9, %r12
movq %r12, 0x60(%rsp)
movq %r8, 0x78(%rsp)
movq %r15, 0xd0(%rsp)
movq %rdi, 0x90(%rsp)
jle 0x1ce8fb
movq $-0x1, 0x18(%rsp)
movq %r13, %rsi
xorl %r14d, %r14d
movq %r8, %rdx
movq %rbp, 0x48(%rsp)
movq %r13, 0x28(%rsp)
movl 0x18(%rbp), %r10d
movq $-0x80000000, %rdi      # imm = 0x80000000
movl (%r15), %ecx
xorl %r10d, %ecx
js 0x1ce7c2
movl 0x14(%rbp), %r13d
movl -0x4(%r15), %ecx
cmpl %r13d, %ecx
jbe 0x1ce6a8
movq 0x28(%rsp), %r13
jmp 0x1ce7c2
movq %r14, 0x20(%rsp)
movq %rbp, %rdi
movl 0x4(%rbp), %r14d
movl 0x8(%rbp), %ebp
movl -0x14(%r15), %r11d
movl -0x10(%r15), %r8d
movl 0x10(%rdi), %edi
movl -0x8(%r15), %r12d
movq %rdi, 0xd8(%rsp)
leaq (%r8,%rdi), %rbx
movq %r14, 0xe8(%rsp)
movq %r14, %rdi
subq %rbx, %rdi
addq %rcx, %rdi
movq %rdi, %r14
negq %r14
cmovsq %rdi, %r14
movq %rbp, 0xf0(%rsp)
subq %r11, %rbp
movq %r13, %rbx
movq %r12, 0xe0(%rsp)
subq %r12, %rbx
cmpq %rbx, %rbp
cmovgq %rbp, %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rbx
cmpq 0x10(%rsp), %rbx
jg 0x1ce72a
movq 0x10(%rsp), %rbx
cmpq %rbx, %r14
jg 0x1ce798
movq 0xf0(%rsp), %r12
movq %r12, %rdi
movq 0xe8(%rsp), %rbp
subq %rbp, %rdi
movq %r8, %rbx
subq %r11, %rbx
cmpq %rbx, %rdi
cmovlq %rdi, %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14
cmpq 0x10(%rsp), %r14
jg 0x1ce76f
movq 0x10(%rsp), %r14
cmpq %r11, %rbp
cmovaq %rbp, %r11
cmpq %r8, %r12
cmovbq %r12, %r8
movl $0x0, %edi
subq %r11, %r8
cmovaeq %r8, %rdi
jbe 0x1ce85d
cmpq %r14, %rdi
jle 0x1ce85d
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %rbx
movq 0x60(%rsp), %r12
movq 0x48(%rsp), %rbp
movq 0x78(%rsp), %r8
movq $-0x80000000, %rdi      # imm = 0x80000000
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %r14
cmpq $-0x80000000, %rdi      # imm = 0x80000000
jne 0x1ce7d3
movq %rdx, %r10
movq %rax, %rdi
jmp 0x1ce83e
addq (%rbx,%rsi,8), %rdi
movq (%r11,%rsi,8), %r10
addq %r8, %r10
cmpq %rax, %rdi
jg 0x1ce7ea
jne 0x1ce7fc
cmpq %rdx, %r10
jle 0x1ce7fc
xorl %eax, %eax
testq %r14, %r14
setg %al
subq %rax, %r14
movq %rsi, 0x18(%rsp)
jmp 0x1ce824
movq 0x80(%rsp), %rcx
movslq (%rcx,%rsi,4), %rcx
cmpq %rcx, %r12
jne 0x1ce81e
cmpq 0x150(%rsp), %r14
jge 0x1cec59
incq %r14
movq %rdx, %r10
movq %rax, %rdi
movq 0x68(%rsp), %rax
movslq (%rax,%rsi,4), %rax
testq %rax, %rax
js 0x1ce83e
movq 0x80(%rsp), %rcx
movl %r12d, (%rcx,%rax,4)
leaq -0x1(%rsi), %rcx
addq $-0x1c, %r15
movq %rdi, %rax
movq %r10, %rdx
cmpq %r9, %rsi
movq %rcx, %rsi
jg 0x1ce67a
jmp 0x1ce90d
movq %r13, %rdi
movq 0xd8(%rsp), %rbx
subq %rbx, %rdi
movq %rcx, %r8
movq 0xe0(%rsp), %r11
subq %r11, %r8
cmpq %r8, %rdi
cmovlq %rdi, %r8
xorps %xmm0, %xmm0
cvtsi2sd %r8, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdi
movq 0x10(%rsp), %r8
cmpq %r8, %rdi
movq 0x60(%rsp), %r12
movq 0x48(%rsp), %rbp
jg 0x1ce8a8
movq %r8, %rdi
cmpq %r11, %rbx
cmovaq %rbx, %r11
cmpq %rcx, %r13
cmovbq %r13, %rcx
subq %r11, %rcx
movl $0x0, %r8d
cmovaeq %rcx, %r8
cmpq %rdi, %r8
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %rbx
movq 0x78(%rsp), %r8
movq $-0x80000000, %rdi      # imm = 0x80000000
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %r14
jg 0x1ce7c2
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movq %r10, %rdi
jmp 0x1ce7c2
movq $-0x1, 0x18(%rsp)
movq %r8, %r10
movq %rax, %rdi
movq %r13, %rcx
movq %rdi, 0x20(%rsp)
movq 0x58(%rsp), %r15
testq %r15, %r15
movq 0x160(%rsp), %r14
js 0x1ce943
movl 0x8(%rbp), %eax
leaq (%r15,%r15,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %r15, %rdx
movq 0x8(%rsp), %rsi
movl 0x8(%rsi,%rdx), %edx
addq %r14, %rdx
cmpq %rax, %rdx
jge 0x1ce9a0
movq $-0x1, %r15
cmpq %r9, %r12
jle 0x1ce9a0
movl 0x8(%rbp), %eax
movq $-0x80000000, %rdx      # imm = 0x80000000
movq 0x88(%rsp), %rsi
movq $-0x80000000, %rdi      # imm = 0x80000000
movl (%rsi), %r8d
addq %r14, %r8
cmpq %rax, %r8
jl 0x1ce9a0
movq (%rbx,%r13,8), %r8
cmpq %r8, %rdi
jge 0x1ce988
movq (%r11,%r13,8), %rdx
movq %r8, %rdi
movq %r13, %r15
jmp 0x1ce990
jne 0x1ce990
cmpq (%r11,%r13,8), %rdx
jl 0x1ce97c
leaq -0x1(%r13), %r8
addq $-0x1c, %rsi
cmpq %r9, %r13
movq %r8, %r13
jg 0x1ce968
testq %r15, %r15
sets %al
cmpq %rcx, %r15
setge %cl
orb %al, %cl
leaq (%r15,%r15,8), %rax
jne 0x1ceb1c
leaq (%rax,%rax,2), %r9
addq %r15, %r9
movl 0x18(%rbp), %edx
movq $-0x80000000, %rcx      # imm = 0x80000000
movq 0x8(%rsp), %r8
movl 0x18(%r8,%r9), %esi
xorl %edx, %esi
js 0x1cead1
addq %r8, %r9
movl 0x14(%rbp), %edi
movl 0x14(%r9), %esi
cmpl %edi, %esi
ja 0x1cead1
movq %r15, 0x58(%rsp)
movl 0x4(%rbp), %r15d
movl 0x8(%rbp), %r14d
movl 0x4(%r9), %r8d
movl 0x8(%r9), %r11d
movq %rbp, 0x48(%rsp)
movl 0x10(%rbp), %ebx
movl 0x10(%r9), %r9d
movq %r15, %r13
subq %r11, %r13
subq %rbx, %r13
addq %rsi, %r13
movq %r13, %r12
negq %r12
cmovsq %r13, %r12
movq %r14, %r13
subq %r8, %r13
movq %rdi, %rbp
subq %r9, %rbp
cmpq %rbp, %r13
cmovgq %r13, %rbp
cvtsi2sd %rbp, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r13
movq 0x10(%rsp), %rbp
cmpq %rbp, %r13
cmovleq %rbp, %r13
cmpq %r13, %r12
jg 0x1ceaab
movq %r14, %r12
subq %r15, %r12
movq %r11, %r13
subq %r8, %r13
cmpq %r13, %r12
cmovlq %r12, %r13
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12
cmpq %rbp, %r12
cmovleq %rbp, %r12
cmpq %r8, %r15
cmovaq %r15, %r8
cmpq %r11, %r14
cmovbq %r14, %r11
movl $0x0, %r14d
subq %r8, %r11
cmovaeq %r11, %r14
jbe 0x1cebd2
cmpq %r12, %r14
jle 0x1cebd2
movq 0x8(%rsp), %r8
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %rbx
movq 0x160(%rsp), %r14
movq 0x60(%rsp), %r12
movq 0x58(%rsp), %r15
movq 0x48(%rsp), %rbp
cmpq $-0x80000000, %rcx      # imm = 0x80000000
movq 0xa0(%rsp), %r9
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rdi
je 0x1ceb39
addq (%rbx,%r15,8), %rcx
movq 0x78(%rsp), %rdx
addq (%r11,%r15,8), %rdx
cmpq 0x20(%rsp), %rcx
jg 0x1ceb0d
jne 0x1ceb39
cmpq %r10, %rdx
jle 0x1ceb39
movq %r15, 0x18(%rsp)
movq %rdx, %r10
movq %rcx, 0x20(%rsp)
jmp 0x1ceb39
movq 0x8(%rsp), %r8
movq 0xa0(%rsp), %r9
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq %rcx, (%rbx,%r12,8)
movq %r10, (%r11,%r12,8)
movq 0x68(%rsp), %rcx
movq 0x18(%rsp), %rdx
movl %edx, (%rcx,%r12,4)
testq %r15, %r15
js 0x1ceb7a
movl 0x8(%rbp), %ecx
leaq (%rax,%rax,2), %rax
addq %r15, %rax
movl 0x8(%r8,%rax), %eax
addq %r14, %rax
cmpq %rcx, %rax
jl 0x1ceb7d
movq (%rbx,%r12,8), %rax
cmpq %rax, (%rbx,%r15,8)
jge 0x1cebc8
movq %r12, %r15
movq %r15, 0x58(%rsp)
movq (%rbx,%r12,8), %rax
cmpq %rsi, %rax
setge %cl
cmpq %rdi, %r10
setg %dl
orb %cl, %dl
cmovneq %rax, %rsi
cmovneq %r10, %rdi
cmovneq %r12, %r9
incq %r12
movq 0xd0(%rsp), %r15
addq $0x1c, %r15
addq $0x1c, 0x88(%rsp)
cmpq 0x30(%rsp), %r12
jne 0x1ce5b4
jmp 0x1cec7a
jne 0x1ceb7d
cmpq %r10, (%r11,%r15,8)
jl 0x1ceb7a
jmp 0x1ceb7d
movq %rdi, %r8
subq %rbx, %r8
movq %rsi, %r11
subq %r9, %r11
cmpq %r11, %r8
cmovlq %r8, %r11
xorps %xmm0, %xmm0
cvtsi2sd %r11, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r8
movq 0x10(%rsp), %r11
cmpq %r11, %r8
cmovleq %r11, %r8
cmpq %r9, %rbx
cmovaq %rbx, %r9
cmpq %rsi, %rdi
cmovbq %rdi, %rsi
subq %r9, %rsi
movl $0x0, %edi
cmovaeq %rsi, %rdi
cmpq %r8, %rdi
movq 0x8(%rsp), %r8
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %rbx
movq 0x160(%rsp), %r14
movq 0x60(%rsp), %r12
movq 0x58(%rsp), %r15
movq 0x48(%rsp), %rbp
jg 0x1cead1
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movq %rdx, %rcx
jmp 0x1cead1
movq %rdx, %r10
movq %rax, %rdi
movq %rsi, %rcx
jmp 0x1ce90d
movq $-0x80000000, %rsi      # imm = 0x80000000
movq $-0x80000000, %r9       # imm = 0x80000000
movq 0x8(%rsp), %r8
testq %r9, %r9
js 0x1cf11d
movq 0x178(%rsp), %r12
movq (%r12), %r10
leaq (%r9,%r9,8), %rax
leaq (%rax,%rax,2), %rax
addq %r9, %rax
movups (%r8,%rax), %xmm0
movups 0xc(%r8,%rax), %xmm1
movq 0x170(%rsp), %rcx
movups %xmm0, (%rcx)
movups %xmm1, 0xc(%rcx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
cmovlq %rsi, %rax
movl %eax, (%rcx)
andl $0xc0000000, 0x18(%rcx) # imm = 0xC0000000
movl 0x4(%rcx), %ebp
movl 0x10(%rcx), %r15d
xorl %r11d, %r11d
xorl %r14d, %r14d
movq %r10, 0x18(%rsp)
leaq (%r9,%r9,8), %rax
leaq (%rax,%rax,2), %rax
addq %r9, %rax
leaq (%r8,%rax), %r13
movl 0x8(%r8,%rax), %ebx
cmpq %rbx, %rbp
jbe 0x1ced00
addq %rbp, %r14
subq %rbx, %r14
movl 0x4(%r13), %ebp
jmp 0x1ced0b
movl 0x4(%r13), %eax
cmpq %rax, %rbp
cmovaeq %rax, %rbp
movl 0x14(%r13), %eax
cmpq %rax, %r15
jbe 0x1ced20
addq %r15, %r11
subq %rax, %r11
movl 0x10(%r13), %r15d
jmp 0x1ced2b
movl 0x10(%r13), %eax
cmpq %rax, %r15
cmovaeq %rax, %r15
testb $0x40, 0x1b(%r13)
jne 0x1ced3d
cmpl $0x1, (%r13)
ja 0x1cedec
movq (%r12), %rax
cmpq %r10, %rax
jbe 0x1ced60
movq 0x10(%r12), %rcx
movq -0x8(%rcx,%rax,8), %rdx
movq %rdx, %rdi
shrq $0x20, %rdi
cmpq %rbx, %rdi
jbe 0x1cee38
movq %r15, 0x10(%rsp)
movl 0x4(%r13), %r15d
movq 0x8(%r12), %rcx
cmpq %rcx, %rax
jne 0x1cedcb
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
movq %r14, 0x28(%rsp)
movq %r12, %r14
movq %r9, %r12
movq %rbp, 0x20(%rsp)
movq %r11, %rbp
callq 0x2370
movq %rbp, %r11
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r10
movq %r12, %r9
movq %r14, %r12
movq 0x28(%rsp), %r14
movq 0x8(%rsp), %r8
movq %rax, 0x10(%r12)
shlq $0x20, %r15
orq %rbx, %r15
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r12)
movq %r15, (%rcx,%rax,8)
movq 0x10(%rsp), %r15
movl 0x4(%r13), %eax
movq 0x170(%rsp), %rsi
cmpl 0x4(%rsi), %eax
jae 0x1cee00
movl %eax, 0x4(%rsi)
movl 0x8(%r13), %eax
cmpl 0x8(%rsi), %eax
jbe 0x1cee0c
movl %eax, 0x8(%rsi)
movl 0x10(%r13), %eax
cmpl 0x10(%rsi), %eax
jae 0x1cee18
movl %eax, 0x10(%rsi)
movl 0x14(%r13), %eax
cmpl 0x14(%rsi), %eax
jbe 0x1cee24
movl %eax, 0x14(%rsi)
movq 0x68(%rsp), %rax
movslq (%rax,%r9,4), %r9
testq %r9, %r9
jns 0x1cecdb
jmp 0x1cee56
movl 0x4(%r13), %esi
cmpl %esi, %edi
jbe 0x1cedec
movl %edx, %edx
shlq $0x20, %rsi
movq %rsi, -0x8(%rcx,%rax,8)
movq (%r12), %rax
orq %rdx, -0x8(%rcx,%rax,8)
jmp 0x1cedec
movq %r14, 0x28(%rsp)
movq %r11, 0x10(%rsp)
movl 0x10(%rsi), %eax
movq %rax, 0x50(%rsp)
movl 0x14(%rsi), %ecx
movq %rcx, 0x70(%rsp)
movl 0x18(%rsi), %edx
movl %edx, 0x68(%rsp)
testl %edx, %edx
jns 0x1cee99
movq 0x148(%rsp), %rdi
movq %rdi, %rdx
subq %rcx, %rdx
movq %rdx, 0x50(%rsp)
movq %rdi, %rcx
subq %rax, %rcx
movq %rcx, 0x70(%rsp)
leaq 0x50(%rsp), %rax
movl (%rax), %r13d
movl %r13d, 0x10(%rsi)
leaq 0x70(%rsp), %r10
movl (%r10), %ebp
movl %ebp, 0x14(%rsi)
leaq 0x100(%rsp), %rbx
leaq 0xf8(%rsp), %r14
xorl %edi, %edi
movq %rsi, %r15
movq 0x140(%rsp), %rdx
movq 0x148(%rsp), %rcx
movq %rbx, %r8
movq %r14, %r9
pushq %r10
pushq %rax
callq 0x1c62a4
addq $0x10, %rsp
movq (%r14), %rax
movq (%rbx), %rcx
movq %rax, %rdi
subq %rcx, %rdi
movl 0x8(%r15), %edx
subl 0x4(%r15), %edx
movq %rdi, %r8
subq %rdx, %r8
addq 0x28(%rsp), %r8
movq %r8, %xmm0
punpckldq 0x5632d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x56335(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
movapd %xmm0, %xmm2
movsd 0xb8(%rsp), %xmm4
mulsd %xmm4, %xmm2
ucomisd %xmm2, %xmm1
ja 0x1cf114
movq 0x70(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq %rdx, %r9
subq %rsi, %r9
subl %r13d, %ebp
movq %r9, %r10
subq %rbp, %r10
addq 0x10(%rsp), %r10
movq %r10, %xmm2
punpckldq 0x562cb(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x562d3(%rip), %xmm2    # 0x225250
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
xorps %xmm1, %xmm1
cvtsi2sd %r9, %xmm1
addsd %xmm2, %xmm3
mulsd %xmm1, %xmm4
ucomisd %xmm4, %xmm3
ja 0x1cf114
subq %r8, %rdi
movq %rdi, %xmm2
movq 0x56291(%rip), %xmm3    # 0x225240
punpckldq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
movapd 0x56295(%rip), %xmm4    # 0x225250
subpd %xmm4, %xmm2
movapd %xmm2, %xmm5
unpckhpd %xmm2, %xmm5            # xmm5 = xmm5[1],xmm2[1]
addsd %xmm2, %xmm5
divsd %xmm0, %xmm5
subq %r10, %r9
movq %r9, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
divsd %xmm1, %xmm2
movapd %xmm5, %xmm0
cmplesd %xmm2, %xmm0
andpd %xmm0, %xmm5
andnpd %xmm2, %xmm0
orpd %xmm5, %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movq 0x170(%rsp), %r8
movl (%r8), %edi
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdi
movl %edi, (%r8)
testl %edi, %edi
je 0x1cf114
movl %ecx, 0x4(%r8)
movl %eax, 0x8(%r8)
movl %esi, 0x10(%r8)
movl %edx, 0x14(%r8)
movl 0x68(%rsp), %eax
orl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, 0x18(%r8)
movq (%r12), %rdx
movl $0x1, %r14d
movq %rdx, %rbx
movq 0x18(%rsp), %rax
subq %rax, %rbx
jbe 0x1cf120
cmpq $0x2, %rbx
jb 0x1cf0ac
movq 0x10(%r12), %rsi
leaq (%rsi,%rax,8), %rax
movq %rbx, %rcx
shrq %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
leaq (%rsi,%rdx,8), %rdx
addq $-0x8, %rdx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movq (%rdx), %r8
movq %r8, (%rax,%rsi,8)
movq %rdi, (%rdx)
incq %rsi
addq $-0x8, %rdx
cmpq %rsi, %rcx
jne 0x1cf092
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl (%r12), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
movq 0x170(%rsp), %rdx
andl 0x18(%rdx), %ecx
orl %eax, %ecx
movl %ecx, 0x18(%rdx)
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x1cf0fd
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r12)
movq %rbx, (%rcx,%rax,8)
jmp 0x1cf120
movq 0x18(%rsp), %rax
movq %rax, (%r12)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq