// File: /workspace/github_cpp_makefile_star2_O2/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 $0xd8, %rsp
movsd %xmm1, 0x28(%rsp)
movsd %xmm0, 0x20(%rsp)
movq %r9, 0x50(%rsp)
movq 0x140(%rsp), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, 0xc(%rax)
movupd %xmm0, (%rax)
testq %rdx, %rdx
je 0x18c099
movq %rdx, %r12
movq %rsi, %rcx
movsd %xmm2, 0x88(%rsp)
movq 0x138(%rsp), %r14
movq 0x118(%rsp), %rbx
movq %r14, %rdi
movq %rdx, %rsi
xorl %edx, %edx
movq %rcx, 0x8(%rsp)
callq 0x1383e
movq 0x8(%rsp), %r11
movq 0x28(%r14), %rax
movq %rax, 0x18(%rsp)
movq (%r14), %rax
movq %rax, 0x78(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x68(%rsp)
testq %r12, %r12
jle 0x18b6dc
shrl 0xc(%r11)
cmpl $0x0, 0x18(%r11)
jns 0x18b6dc
movl 0x10(%r11), %eax
movl 0x14(%r11), %ecx
movq %rbx, %rdx
subq %rcx, %rdx
movq %rdx, 0x60(%rsp)
movq %rbx, %rcx
subq %rax, %rcx
movq %rcx, 0x58(%rsp)
movl %edx, 0x10(%r11)
movl %ecx, 0x14(%r11)
xorl %ebx, %ebx
testq %r12, %r12
movl $0x0, %eax
cmovgq %r12, %rax
movq %rax, 0xa0(%rsp)
leaq 0x1(%rax), %r14
leaq 0x1c(%r11), %r15
pushq $0x1
popq %r13
xorl %ebp, %ebp
cmpq %r14, %r13
je 0x18b7ec
cmpq %r12, %r13
jge 0x18b73a
imulq $0x1c, %r13, %rax
shrl 0xc(%r11,%rax)
cmpl $0x0, 0x18(%r11,%rax)
jns 0x18b73a
addq %r11, %rax
movq 0x118(%rsp), %rsi
movl %esi, %ecx
subl 0x14(%rax), %ecx
movl 0x10(%rax), %edx
subl %edx, %esi
movl %ecx, 0x10(%rax)
movl %esi, 0x14(%rax)
cmpq %r12, %r13
je 0x18b75b
imulq $0x1c, %r13, %rax
imulq $0x1c, %rbp, %rcx
movl 0x18(%r11,%rcx), %ecx
xorl 0x18(%r11,%rax), %ecx
js 0x18b75b
movq %rbp, %rax
jmp 0x18b7de
movq %r13, %rcx
subq %rbp, %rcx
movq %r13, %rax
cmpq $0x2, %rcx
jl 0x18b7de
imulq $0x1c, %rbp, %rdi
addq %r11, %rdi
imulq $0x1c, %r13, %rsi
addq %r11, %rsi
callq 0x156f5c
movq 0x8(%rsp), %r11
imulq $0x1c, %rbp, %rdi
leaq (%r11,%rdi), %rax
addq $0x8, %rax
leaq (%r15,%rdi), %r8
leaq (%rbx,%rbp), %rcx
xorl %r9d, %r9d
movq %r8, %rsi
leaq (%r9,%rbp), %r8
cmpq %r13, %r8
jge 0x18b7db
movq %r9, %rdx
movq %rcx, %r8
addq %r9, %r8
je 0x18b7c1
movl 0x8(%rsi), %r10d
leaq 0x1(%rdx), %r9
leaq 0x1c(%rsi), %r8
cmpl (%rax), %r10d
je 0x18b799
leaq 0x1(%rdx), %rax
addq %rdx, %rbp
incq %rbp
cmpq $0x2, %rax
jl 0x18b782
addq %r11, %rdi
callq 0x1571fa
jmp 0x18b77d
movq %r13, %rax
incq %r13
decq %rbx
movq %rax, %rbp
jmp 0x18b700
shlq $0x2, %r12
xorl %ebx, %ebx
movq 0x68(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x20e0
movq 0x8(%rsp), %r9
movq 0x128(%rsp), %rax
movq %rax, %rcx
notq %rcx
movq %rcx, 0x98(%rsp)
imulq $0x1c, %rax, %rax
negq %rax
addq %r9, %rax
addq $0x18, %rax
movq %rax, 0x90(%rsp)
leaq -0x1c(%r9), %r14
leaq -0x14(%r9), %r15
pushq $-0x1
popq %r12
movq $-0x80000000, %rdi      # imm = 0x80000000
movq $-0x80000000, %r8       # imm = 0x80000000
movq $-0x80000000, 0x10(%rsp) # imm = 0x80000000
movq 0x140(%rsp), %rsi
movq 0x128(%rsp), %rax
cmpq %rbx, %rax
movq %rbx, %rcx
cmovgq %rax, %rcx
cmpq 0xa0(%rsp), %rbx
je 0x18bc25
imulq $0x1c, %rbx, %rax
leaq (%r9,%rax), %r10
movl 0x18(%r9,%rax), %eax
btl $0x1e, %eax
jb 0x18b896
cmpl $0x1, (%r10)
ja 0x18b8a5
movl 0x8(%r10), %edx
subl 0x4(%r10), %edx
movq %rdx, 0x40(%rsp)
jmp 0x18b8ae
movq $0x0, 0x40(%rsp)
movq %r12, 0xa8(%rsp)
movq %r8, 0x80(%rsp)
movq %r15, 0xb0(%rsp)
movq %rdi, 0xc0(%rsp)
movq 0x98(%rsp), %rdx
leaq (%rdx,%rcx), %rbp
imulq $0x1c, %rcx, %rcx
addq 0x90(%rsp), %rcx
movl %eax, %r11d
andl $0x3fffffff, %r11d      # imm = 0x3FFFFFFF
incq %rbp
movl (%rcx), %edx
addq $0x1c, %rcx
xorl %eax, %edx
js 0x18b8f0
movq %rbx, 0x38(%rsp)
leaq -0x1(%rbx), %r12
movq %r14, 0xb8(%rsp)
pushq $-0x1
popq %rax
movq %rax, 0x70(%rsp)
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x48(%rsp)
movq %r12, %rbx
cmpq %rbp, %rbx
jl 0x18ba21
movq %r12, %r15
movq %r11, %r12
movq %r10, %r13
movq %r10, %rdi
movq %r14, %rsi
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movq 0x50(%rsp), %rdx
callq 0x1a358d
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x18b970
movq (%rsp), %rcx
movq %r12, %rax
movq %r13, %r10
movq %r15, %r12
jmp 0x18b9d2
movq 0x30(%rsp), %rcx
addq (%rcx,%rbx,8), %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rbx,8), %rcx
addq 0x40(%rsp), %rcx
cmpq %r12, %rax
jg 0x18b997
movq %r12, %r11
jne 0x18b9e5
cmpq (%rsp), %rcx
jle 0x18b9e5
xorl %edx, %edx
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
setg %dl
subq %rdx, %rsi
movq %rsi, 0x48(%rsp)
movq %rbx, 0x70(%rsp)
movq %r13, %r10
movq %r15, %r12
movq 0x78(%rsp), %rdx
movslq (%rdx,%rbx,4), %rdx
testq %rdx, %rdx
js 0x18b9d2
movq 0x68(%rsp), %rsi
movq 0x38(%rsp), %rdi
movl %edi, (%rsi,%rdx,4)
decq %rbx
addq $-0x1c, %r14
movq %rcx, (%rsp)
movq %rax, %r11
jmp 0x18b92b
movq 0x68(%rsp), %rax
movslq (%rax,%rbx,4), %rax
cmpq %rax, 0x38(%rsp)
movq %r13, %r10
jne 0x18ba18
movq 0x48(%rsp), %rax
cmpq 0x120(%rsp), %rax
movq %r15, %r12
jge 0x18ba21
incq 0x48(%rsp)
movq (%rsp), %rcx
movq %r11, %rax
jmp 0x18b9b7
movq (%rsp), %rcx
movq %r11, %rax
jmp 0x18b9b4
movq 0xa8(%rsp), %r8
testq %r8, %r8
movq 0x8(%rsp), %r9
movq 0x130(%rsp), %r14
movq 0xb0(%rsp), %r15
js 0x18ba58
movl 0x8(%r10), %eax
imulq $0x1c, %r8, %rcx
movl 0x8(%r9,%rcx), %ecx
addq %r14, %rcx
cmpq %rax, %rcx
jge 0x18bac0
movq $-0x80000000, %rcx      # imm = 0x80000000
movq %r15, %rax
movq $-0x80000000, %rdx      # imm = 0x80000000
pushq $-0x1
popq %r8
cmpq %rbp, %r12
jl 0x18bac0
movl 0x8(%r10), %esi
movl (%rax), %edi
addq %r14, %rdi
cmpq %rsi, %rdi
jl 0x18bac0
movq 0x30(%rsp), %rsi
movq (%rsi,%r12,8), %rsi
cmpq %rsi, %rcx
jge 0x18ba9f
movq 0x18(%rsp), %rcx
movq (%rcx,%r12,8), %rdx
movq %rsi, %rcx
movq %r12, %r8
jmp 0x18bab7
jne 0x18bab7
movq 0x18(%rsp), %rdi
movq (%rdi,%r12,8), %rdi
cmpq %rdi, %rdx
jge 0x18bab7
movq %rsi, %rcx
movq %rdi, %rdx
jmp 0x18ba9a
decq %r12
addq $-0x1c, %rax
jmp 0x18ba6d
testq %r8, %r8
sets %al
cmpq %rbx, %r8
setge %cl
orb %al, %cl
movq %r8, %r12
jne 0x18bb28
movq %r11, %rbp
imulq $0x1c, %r12, %rsi
addq %r9, %rsi
movq %r10, %r13
movq %r10, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movq 0x50(%rsp), %rdx
callq 0x1a358d
cmpq $-0x80000000, %rax      # imm = 0x80000000
movq 0x140(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rdi
jne 0x18bb44
movq 0x8(%rsp), %r9
movq %r13, %r10
movq %rbp, %r11
jmp 0x18bb80
movq 0x140(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rdi
jmp 0x18bb80
movq 0x30(%rsp), %rcx
addq (%rcx,%r12,8), %rax
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %rdx
addq (%rcx,%r12,8), %rdx
movq %rdx, %rcx
cmpq %rbp, %rax
movq 0x8(%rsp), %r9
movq %r13, %r10
jg 0x18bb76
movq %rbp, %r11
jne 0x18bb80
cmpq (%rsp), %rcx
jle 0x18bb80
movq %r12, %rdi
movq %rcx, (%rsp)
movq %rax, %r11
movq 0x30(%rsp), %rcx
movq %r11, (%rcx,%rbx,8)
movq 0x18(%rsp), %rax
movq (%rsp), %rdx
movq %rdx, (%rax,%rbx,8)
movq 0x78(%rsp), %rax
movl %edi, (%rax,%rbx,4)
movq (%rcx,%rbx,8), %rax
testq %r12, %r12
js 0x18bbc7
movl 0x8(%r10), %ecx
imulq $0x1c, %r12, %rdx
movl 0x8(%r9,%rdx), %edx
addq %r14, %rdx
cmpq %rcx, %rdx
jl 0x18bbca
movq 0x30(%rsp), %rcx
cmpq %rax, (%rcx,%r12,8)
jge 0x18bc12
movq %rbx, %r12
movq 0xc0(%rsp), %rdi
cmpq %rdi, %rax
setge %cl
movq (%rsp), %r10
cmpq %r8, %r10
setg %dl
orb %cl, %dl
cmovneq %rax, %rdi
cmovneq %r10, %r8
movq 0x10(%rsp), %rax
cmovneq %rbx, %rax
movq %rax, 0x10(%rsp)
incq %rbx
movq 0xb8(%rsp), %r14
addq $0x1c, %r14
addq $0x1c, %r15
jmp 0x18b85d
jne 0x18bbca
movq 0x18(%rsp), %rcx
movq (%rsp), %rdx
cmpq %rdx, (%rcx,%r12,8)
jl 0x18bbc7
jmp 0x18bbca
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
js 0x18c099
movq 0x148(%rsp), %rax
movq (%rax), %r10
imulq $0x1c, %rdx, %rax
movupd (%r9,%rax), %xmm0
movupd 0xc(%r9,%rax), %xmm1
movupd %xmm0, (%rsi)
movupd %xmm1, 0xc(%rsi)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rdi
cmovlq %rdi, %rax
movl %eax, (%rsi)
andl $0xc0000000, 0x18(%rsi) # imm = 0xC0000000
movl 0x4(%rsi), %ecx
movl 0x10(%rsi), %eax
xorl %r14d, %r14d
movl %ecx, %ebx
movq %rcx, %rdi
movq %rax, %r13
xorl %r11d, %r11d
movq %rdx, %rsi
testq %rsi, %rsi
js 0x18be44
imulq $0x1c, %rsi, %rax
leaq (%r9,%rax), %r12
movl 0x8(%r9,%rax), %ebp
cmpq %rbp, %rdi
jbe 0x18bcaf
addq %rdi, %r14
subq %rbp, %r14
movl 0x4(%r12), %r15d
movq %r15, %rdi
jmp 0x18bcbb
movl 0x4(%r12), %r15d
cmpq %r15, %rdi
cmovaeq %r15, %rdi
movl 0x14(%r12), %eax
cmpq %rax, %r13
jbe 0x18bcd2
addq %r13, %r11
subq %rax, %r11
movl 0x10(%r12), %r13d
jmp 0x18bcde
movl 0x10(%r12), %eax
cmpq %rax, %r13
cmovaeq %rax, %r13
testb $0x40, 0x1b(%r12)
movq 0x148(%rsp), %rax
jne 0x18bcf9
cmpl $0x1, (%r12)
ja 0x18bdbe
movq %rdi, (%rsp)
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq 0x10(%rax), %rax
cmpq %r10, %rdx
jbe 0x18bd23
movq -0x8(%rax,%rdx,8), %rsi
movq %rsi, %rdi
shrq $0x20, %rdi
cmpq %rbp, %rdi
jbe 0x18be14
movq 0x148(%rsp), %r8
cmpq 0x8(%r8), %rdx
jne 0x18bd91
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r14, 0x28(%rsp)
movq %r10, %r14
movq %r13, %rbx
movq %r11, %r13
callq 0x2370
movq 0x148(%rsp), %r8
movq %r13, %r11
movq %rbx, %r13
movq %r14, %r10
movq 0x28(%rsp), %r14
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r8)
movq (%r8), %rdx
movl 0x4(%r12), %esi
movq 0x140(%rsp), %rcx
movl 0x4(%rcx), %ecx
jmp 0x18bd94
movl %r15d, %esi
shlq $0x20, %r15
orq %rbp, %r15
leaq 0x1(%rdx), %rdi
movq %rdi, (%r8)
movq %r15, (%rax,%rdx,8)
movl %ecx, %ebx
movl %esi, %r15d
movq 0x140(%rsp), %r8
movq 0x10(%rsp), %rsi
movq (%rsp), %rdi
jmp 0x18bdc6
movq 0x140(%rsp), %r8
cmpl %ebx, %r15d
jae 0x18bdd5
movl %r15d, 0x4(%r8)
movl %r15d, %ecx
movl %r15d, %ebx
movl 0x8(%r12), %eax
cmpl 0x8(%r8), %eax
jbe 0x18bde4
movl %eax, 0x8(%r8)
movl 0x10(%r12), %edx
movl 0x10(%r8), %eax
cmpl %eax, %edx
jae 0x18bdf7
movl %edx, 0x10(%r8)
movl %edx, %eax
movl 0x14(%r12), %edx
cmpl 0x14(%r8), %edx
jbe 0x18be06
movl %edx, 0x14(%r8)
movq 0x78(%rsp), %rdx
movslq (%rdx,%rsi,4), %rsi
jmp 0x18bc84
cmpl %r15d, %edi
movq 0x140(%rsp), %r8
jbe 0x18bdb3
movl %r15d, %edi
movl %esi, %esi
shlq $0x20, %rdi
movq %rdi, -0x8(%rax,%rdx,8)
movq 0x148(%rsp), %rdx
movq (%rdx), %rdx
orq %rsi, -0x8(%rax,%rdx,8)
jmp 0x18bdb3
movl %eax, %ebp
movq %rbp, 0x60(%rsp)
movq 0x140(%rsp), %rax
movl 0x14(%rax), %r13d
movq %r13, 0x58(%rsp)
movl 0x18(%rax), %eax
testl %eax, %eax
movq %r10, 0x20(%rsp)
movq %r11, (%rsp)
movq %r14, 0x28(%rsp)
movl %eax, 0x50(%rsp)
movq 0x118(%rsp), %rcx
jns 0x18be96
movq %rcx, %rax
subq %r13, %rax
movq %rax, 0x60(%rsp)
movq %rcx, %r13
subq %rbp, %r13
movq %r13, 0x58(%rsp)
movq %rax, %rbp
movq 0x140(%rsp), %r12
movl %ebp, 0x10(%r12)
movl %r13d, 0x14(%r12)
leaq 0x58(%rsp), %rax
leaq 0x60(%rsp), %r10
leaq 0xd0(%rsp), %r14
leaq 0xc8(%rsp), %r15
xorl %edi, %edi
movq %r12, %rsi
movq 0x110(%rsp), %rdx
movq %r14, %r8
movq %r15, %r9
pushq %rax
pushq %r10
callq 0x184214
popq %rax
popq %rcx
movq (%r15), %rax
movq (%r14), %rcx
movq %rax, %rdi
subq %rcx, %rdi
movl 0x8(%r12), %edx
subl %ebx, %edx
movq %rdi, %r8
subq %rdx, %r8
addq 0x28(%rsp), %r8
movq %r8, %xmm0
punpckldq 0x57366(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5736e(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
cvtsi2sd %rdi, %xmm0
movapd %xmm0, %xmm2
movsd 0x88(%rsp), %xmm4
mulsd %xmm4, %xmm2
ucomisd %xmm2, %xmm1
ja 0x18c089
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rsi
movq %rdx, %r9
subq %rsi, %r9
subl %ebp, %r13d
movq %r9, %r10
subq %r13, %r10
addq (%rsp), %r10
movq %r10, %xmm2
punpckldq 0x57308(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x57310(%rip), %xmm2    # 0x1e3280
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
cvtsi2sd %r9, %xmm1
addsd %xmm2, %xmm3
mulsd %xmm1, %xmm4
ucomisd %xmm4, %xmm3
ja 0x18c089
subq %r8, %rdi
movq %rdi, %xmm2
movq 0x572d1(%rip), %xmm3    # 0x1e3270
punpckldq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
movapd 0x572d5(%rip), %xmm4    # 0x1e3280
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 0x140(%rsp), %r9
movl (%r9), %edi
cvtsi2sd %rdi, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdi
movl %edi, (%r9)
testl %edi, %edi
je 0x18c089
movl %ecx, 0x4(%r9)
movl %eax, 0x8(%r9)
movl %esi, 0x10(%r9)
movl %edx, 0x14(%r9)
movl 0x50(%rsp), %eax
orl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, 0x18(%r9)
movq 0x148(%rsp), %rax
movq (%rax), %rdx
pushq $0x1
popq %r14
movq %rdx, %rbx
movq 0x20(%rsp), %rcx
subq %rcx, %rbx
jbe 0x18c09c
movq 0x10(%rax), %rsi
leaq (%rsi,%rcx,8), %rax
movq %rbx, %rcx
shrq %rcx
leaq (%rsi,%rdx,8), %rdx
addq $-0x8, %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x18c0b1
movq (%rax,%rsi,8), %rdi
movq (%rdx), %r8
movq %r8, (%rax,%rsi,8)
movq %rdi, (%rdx)
incq %rsi
addq $-0x8, %rdx
jmp 0x18c06d
movq 0x148(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
xorl %r14d, %r14d
movq %r14, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x148(%rsp), %r15
andl (%r15), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
andl 0x18(%r9), %ecx
orl %eax, %ecx
movl %ecx, 0x18(%r9)
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x18c102
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %rbx, (%rax,%rcx,8)
jmp 0x18c09c