// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gl_rchain_lin_contain_adv(overlap_region_alloc*, kv_ul_ov_t*, ul_ov_t*, kv_rtrace_t*, ul_idx_t const*, ug_opt_t const*, long, double, long, long, long, long, Chain_Data*, bit_extz_t*, unsigned long*, long, All_reads*, char*, UC_Read*, long, double, long)
int64_t gl_rchain_lin_contain_adv(overlap_region_alloc* ol, kv_ul_ov_t *res, ul_ov_t *ex, kv_rtrace_t *trace, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, int64_t qlen, int64_t max_skip, int64_t max_iter, int64_t max_dis, Chain_Data* dp, bit_extz_t *exz, uint64_t *id,
int64_t trans_sc, All_reads *ridx, char* qstr, UC_Read *tu, int64_t rid, double e_rate, int64_t need_srt)
{
	if(res->n == 0) return 0;
    uint32_t li_v, rev_n, is_fc, cc, idn, mqs, mqe; int32_t *f, *c_n, *c_sc, *rch, *ssc; int64_t *p, *t, res_n = res->n, st, max_ii, max, max_n; 
    int64_t mm_ovlp, x, i, j, k, sc, csc, mm_sc, mm_idx, mm_n, sn, n_skip, end_j, plus; ul_ov_t *li, *lj, rr, mrr; rtrace_iter tc; uint64_t ovlp;
    resize_Chain_Data(dp, res_n<<1, NULL);///res_n<<1
    t = dp->tmp; f = dp->score; p = dp->pre; c_n = dp->occ; 
	c_sc = rch = dp->self_length; ssc = dp->indels;
	if(need_srt) {
        radix_sort_ul_ov_srt_qe(res->a, res->a + res_n);
        for (i = 1, j = 0; i <= res_n; i++) {
			res->a[i-1].qs = ((uint32_t)-1)-res->a[i-1].qs;
            if (i == res_n || res->a[i].qe != res->a[j].qe) {
                if(i - j > 1) radix_sort_ul_ov_srt_qs(res->a+j, res->a+i);
                j = i;
            }
        }
    }

	memset(t, 0, (res_n*sizeof((*t)))); 
	for (i = st = plus = 0, max_ii = -1; i < res_n; ++i) {
        li = &(res->a[i]); li_v = (li->tn<<1)|li->rev; li->qs = ((uint32_t)-1)-li->qs;
		rch[i] = INT32_MAX; ssc[i] = INT32_MIN; 
        mm_ovlp = max_ovlp_src_contain(uopt, li_v^1);        
        x = (li->qs + mm_ovlp)*diff_ec_ul; 
        if(x < bw) x = bw; 
        x += li->qs + mm_ovlp;
        if (x > qlen+1) x = qlen+1;
		// if(li->tn == 20171 || li->tn == 20209 || li->tn == 20204) {
		// 	fprintf(stderr, "\n[i::%ld] (id::%u)%.*s\t%c\tq::[%u, %u)\tt::[%u, %u)\tc::%u\tmax_d::%ld\n", i, li->tn,
        //             (int)Get_NAME_LENGTH(R_INF, res->a[i].tn), Get_NAME(R_INF, res->a[i].tn), 
		// 			"+-"[res->a[i].rev], res->a[i].qs, res->a[i].qe, res->a[i].ts, res->a[i].te,
		// 			!res->a[i].el, x+G_CHAIN_INDEL);
		// }
        x = find_ul_ov_max(i, res->a, x+G_CHAIN_INDEL); 
		// if(li->tn == 6312) {
		// 	fprintf(stderr, "[i::%ld] (id::%u)%.*s\t%c\tq::[%u, %u)\tt::[%u, %u)\tc::%u\tmax_j::%ld\n", i, li->tn,
        //             (int)Get_NAME_LENGTH(R_INF, res->a[i].tn), Get_NAME(R_INF, res->a[i].tn), 
		// 			"+-"[res->a[i].rev], res->a[i].qs, res->a[i].qe, res->a[i].ts, res->a[i].te,
		// 			!res->a[i].el, x);
		// }
        csc = li->qe - li->qs; csc -= (((int64_t)li->sec)*trans_sc);
        // mm_sc = csc; mm_idx = -1; mm_n = 1;
		mm_sc = INT32_MIN; mm_idx = -1; mm_n = 0; is_fc = 0;
        n_skip = 0; end_j = -1; tc.k = INT32_MAX;
        if ((x-st) > max_iter) st = x-max_iter;
        for (j = x; j >= st; --j) { // collect potential destination vertices
            lj = &(res->a[j]); 
			if(lj->qe <= li->qs) break;//even this pair has a overlap, its length will be very small; just ignore
			sc = connect_detect(res->a, res->n, i, j, ridx, rch, uref, uopt, bw, diff_ec_ul, p, f, &tc,
																trace, qstr, tu, ol, exz, e_rate, trans_sc, &cc);
			if(sc == INT32_MIN) continue;
			sn = c_n[j] + 1;
			// if(li->tn == 6312) {
			// 	fprintf(stderr, "(id::%u)%.*s\t%c\t(id::%u)%.*s\t%c\tsc::%ld\tsn::%ld\tc_n[j]::%d\tmsc::%ld\ti::%ld\tj::%ld\tm_idx::%ld\n", 
			// 		li->tn,	(int)Get_NAME_LENGTH(R_INF, li->tn), Get_NAME(R_INF, li->tn), "+-"[li->rev],
			// 		lj->tn,	(int)Get_NAME_LENGTH(R_INF, lj->tn), Get_NAME(R_INF, lj->tn), "+-"[lj->rev], 
			// 		sc, sn, c_n[j], mm_sc, i, j, mm_idx);
			// }
			// if(li->tn == 20209) {
			// 	fprintf(stderr, "[i::%ld] (id::%u)%.*s\t%c\tj::%ld\tsc::%ld\tsn::%ld\n", i, li->tn,
            //         (int)Get_NAME_LENGTH(R_INF, res->a[i].tn), Get_NAME(R_INF, res->a[i].tn), 
			// 		"+-"[res->a[i].rev], j, sc, sn);
			// }
			if((sc > mm_sc) || ((sc == mm_sc) && (sn > mm_n))) {
				mm_sc = sc, mm_idx = j; mm_n = sn; is_fc = cc;
				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 || (res->a[i].qe>(res->a[max_ii].qe+max_dis))) {//too long
            max = INT32_MIN; max_n = INT32_MIN; max_ii = -1;
            for (j = i - 1; (j >= st) && (res->a[i].qe<=(max_dis+res->a[j].qe)); --j) {
                if ((max < f[j]) || ((max == f[j]) && (max_n < c_n[j]))) {
                    max = f[j]; max_n = c_n[j]; max_ii = j;
                }
            }
        }

        if (max_ii >= 0 && max_ii < end_j) {///just have a try with a[i]<->a[max_ii]
            lj = &(res->a[max_ii]); 
            if(lj->qe > li->qs/** && lj->qs < li->qs**/) {
				///as max_ii < end_j, get_rid_backward_cigar_err still works
				sc = connect_detect(res->a, res->n, i, max_ii, ridx, rch, uref, uopt, bw, diff_ec_ul, p, f, &tc,
																trace, qstr, tu, ol, exz, e_rate, trans_sc, &cc);
				if(sc != INT32_MIN) {
					sn = c_n[max_ii] + 1;
					// if(li->tn == 6312 || li->tn == 6322 || li->tn == 6317 || li->tn == 6319/** && lj->tn == 6329**/) {
					// 	fprintf(stderr, "(id::%u)%.*s\t%c\t(id::%u)%.*s\t%c\tsc::%ld\tsn::%ld\tc_n[j]::%d\tmsc::%ld\ti::%ld\tmax_ii::%ld\tm_idx::%ld\n", 
					// 		li->tn,	(int)Get_NAME_LENGTH(R_INF, li->tn), Get_NAME(R_INF, li->tn), "+-"[li->rev],
					// 		lj->tn,	(int)Get_NAME_LENGTH(R_INF, lj->tn), Get_NAME(R_INF, lj->tn), "+-"[lj->rev], 
					// 		sc, sn, c_n[j], mm_sc, i, max_ii, mm_idx);
					// }
					if((sc > mm_sc) || ((sc == mm_sc) && (sn > mm_n))) {
                        mm_sc = sc; mm_idx = max_ii; mm_n = sn; is_fc = cc;
                    }
				}
            }
        }

		sc = csc; sn = 1;///for i itself
		if((sc > mm_sc) || ((sc == mm_sc) && (sn > mm_n))) {
			mm_sc = sc, mm_idx = -1; mm_n = sn; is_fc = 0;
		}

        if(mm_sc < 0) {
            mm_sc = csc; mm_idx = -1; mm_n = 1;
        }

		// if(li->tn == 6317) {
		// 	fprintf(stderr, "+(id::%u)%.*s\t%c\tmm_idx::%ld\tmm_sc::%ld\tmm_n::%ld\n", 
		// 		li->tn,	(int)Get_NAME_LENGTH(R_INF, li->tn), Get_NAME(R_INF, li->tn), "+-"[li->rev], mm_idx, mm_sc, mm_n);
		// }

		if(mm_idx >= 0) {
			///mo meed to update mm_sc and is_fc
			propagate_transitive_reduction(uref, uopt, ridx, bw, diff_ec_ul, res->a, x+1, i, rch, f, p, c_n, t, &mm_sc, &mm_idx, &mm_n);
		}
		// if(li->tn == 6317) {
		// 	fprintf(stderr, "-(id::%u)%.*s\t%c\tmm_idx::%ld\tmm_sc::%ld\tmm_n::%ld\n", 
		// 		li->tn,	(int)Get_NAME_LENGTH(R_INF, li->tn), Get_NAME(R_INF, li->tn), "+-"[li->rev], mm_idx, mm_sc, mm_n);
		// }
		// collapse_contain(res->a, res_n, i, &mm_idx, &mm_sc, p, c_sc, end_j);

        f[i] = mm_sc; p[i] = mm_idx; c_n[i] = mm_n; 
		if(mm_idx < 0 || ((ssc[mm_idx] < mm_sc) && (is_fc == 0))) ssc[i] = mm_sc;
		else ssc[i] = ssc[mm_idx];

        if ((max_ii < 0) || ((res->a[i].qe<=max_dis+res->a[max_ii].qe) && (f[max_ii]<f[i]))) {
            max_ii = i;
        }
        if(ssc[i] < plus) plus = ssc[i];//minmun negative
		// if(li->tn == 20171 || li->tn == 20209 || li->tn == 20204) {
		// 	fprintf(stderr, "[i::%ld]\tf::%d\tp::%ld\n", i, f[i], p[i]);
		// }
        
    }

	for (i = 0; i < res_n; ++i) {///make all f[] positive
        ssc[i] -= plus; t[i] = ((uint64_t)ssc[i])<<32; t[i] += (i<<1);
    }

	int64_t n_v, n_u, n_v0; mrr.qn = (uint32_t)-1; mrr.qe = mrr.qs = 0;
	int32_t *f0, *c_n0, *c_sc0, *rch0, *ssc0; int64_t *p0, *t0;
	f0 = f + res_n; c_n0 = c_n + res_n; c_sc0 = c_sc + res_n;
	rch0 = rch + res_n; ssc0 = ssc + res_n; p0 = p + res_n; t0 = t + res_n;
    radix_sort_gfa64i(t, t + res_n); plus = 0; mqs = UINT32_MAX; mqe = 0;
    for (k = res_n-1, n_v = n_u = 0; k >= 0; --k) {
        n_v0 = n_v; idn = 0;
        for (i = ((uint32_t)t[k])>>1; i >= 0 && (t[i]&1) == 0; ) {
			if(res->a[i].qs < mqs) mqs = res->a[i].qs;
			if(res->a[i].qe > mqe) mqe = res->a[i].qe;
            // ex[n_v] = res->a[i]; ex[n_v].sec = i;
			id[idn++] = i; t[i] |= 1; i = p[i]; n_v++;
        }
        if(n_v0 == n_v) continue;
        sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i]));


		if((mrr.qn != (uint32_t)-1) && (sc < (c_sc[mrr.qn]*0.98))) {
			ovlp = ((MIN(mrr.qe, mqe) > MAX(mrr.qs, mqs))? (MIN(mrr.qe, mqe) - MAX(mrr.qs, mqs)):0);
			if(ovlp >= ((mqe-mqs)*0.95)) {
				n_v = n_v0; continue;
			}
		}

		rev_n = idn>>1;
		for (i = 0; i < rev_n; i++) {
			st = id[i]; id[i] = id[idn-i-1]; id[idn-i-1] = st;
		}
		n_v = n_v0 + gen_trans_aln(ol, ridx, uref, uopt, bw, diff_ec_ul, qlen, id, idn, res->a, res_n, mqs, mqe, t, 
		f0, c_n0, c_sc0, rch0, ssc0, p0, t0, max_skip, max_iter, max_dis, exz, trans_sc, qstr, tu, e_rate, trace, 1000, ex + n_v0, &rr);
		assert(n_v > n_v0);
        c_n[n_u] = n_v-n_v0; c_sc[n_u] = sc; n_u++; if(sc < plus) plus = sc;
		if((mrr.qn == (uint32_t)-1) || (sc > c_sc[mrr.qn]) || 
						((sc == c_sc[mrr.qn]) && ((rr.qe - rr.qs) > (mrr.qe - mrr.qs)))) {
			mrr = rr; mrr.qn = n_u - 1;
		}
    }

    // fprintf(stderr, "---[M::%s] n_u:%ld, n_v:%ld\n", __func__, n_u, n_v);
    for (k = 0, n_v = n_v0 = 0; k < n_u; k++) {
        n_v0 = n_v; n_v += c_n[k];
        res->a[k].qn = c_sc[k]-plus;//score
        res->a[k].ts = n_v0; res->a[k].te = n_v;///idx
		res->a[k].qs = ex[n_v0].qs; res->a[k].qe = ex[n_v-1].qe;
        // fprintf(stderr, "[M::%s] k:%ld, c_sc:%d\n", __func__, k, c_sc[k]);
		// res->a[k].te = res->a[k].ts + flat_contain(ridx, uref, uopt, bw, diff_ec_ul, qlen, max_skip, max_iter, max_dis, 
		// ex + res->a[k].ts, res->a[k].te - res->a[k].ts, f, ssc, p, t, &(res->a[k]));
    }
    res->n = n_u; 
    radix_sort_ul_ov_srt_qn(res->a, res->a + res->n);//sort by score

	// if(res->n > 0) {
	// 	fprintf(stderr, "[M::%s::rid->%ld] qlen::%ld, q::[%u, %u), sc::%u\n", 
	// 	__func__, rid, qlen, res->a[res->n-1].qs, res->a[res->n-1].qe, res->a[res->n-1].qn);
	// }
    return n_v;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movsd %xmm1, 0xe8(%rsp)
movsd %xmm0, 0x88(%rsp)
movq %r9, 0x80(%rsp)
movq %r8, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq %rdi, 0xd0(%rsp)
movq 0x8(%rsi), %rbp
testq %rbp, %rbp
je 0x1b8ee5
movq %rsi, %r13
movq %rdx, 0xf0(%rsp)
movq 0x258(%rsp), %r15
movq 0x218(%rsp), %r14
leaq (,%rbp,2), %rsi
xorl %ebx, %ebx
movq %r14, %rdi
xorl %edx, %edx
callq 0x3f828
movq 0x28(%r14), %rax
movq %rax, 0x10(%rsp)
movq (%r14), %rax
movq %rax, 0x58(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%r14), %rax
movq %rax, 0x78(%rsp)
movq 0x18(%r14), %rax
movq %rax, 0x38(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x90(%rsp)
testq %r15, %r15
je 0x1b839a
movq (%r13), %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %rbp, %rsi
callq 0x195511
testq %rbp, %rbp
jle 0x1b839a
movq %rbp, %r14
negq %r14
movl $0x1, %r15d
movl $0x1c, %r12d
xorl %eax, %eax
movq (%r13), %rcx
notl -0x18(%rcx,%r12)
movq %r14, %rdx
addq %r15, %rdx
je 0x1b835a
movl 0x8(%rcx,%r12), %edx
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl 0x8(%rcx,%rsi), %edx
jne 0x1b835a
movq %rax, %rdx
jmp 0x1b8383
movq %r15, %rsi
subq %rax, %rsi
movq %r15, %rdx
cmpq $0x2, %rsi
jl 0x1b8383
leaq (%rcx,%r12), %rsi
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdi
addq %rax, %rdi
addq %rcx, %rdi
callq 0x1957bd
movq %r15, %rdx
leaq (%r14,%r15), %rcx
incq %rcx
incq %r15
addq $0x1c, %r12
movq %rdx, %rax
cmpq $0x1, %rcx
jne 0x1b832e
leaq (,%rbp,8), %rdx
movq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
testq %rbp, %rbp
movq 0x90(%rsp), %rdi
movq %rbp, 0xb0(%rsp)
jle 0x1b8a96
movq 0x1f8(%rsp), %rax
incq %rax
movq %rax, 0xf8(%rsp)
movq $-0x14, 0xa0(%rsp)
movq $-0x1, 0x98(%rsp)
movq $0x0, 0x28(%rsp)
movq $-0x1, %r8
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %r8, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
movq (%r13), %r15
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %r12
addq %rbp, %r12
movl 0xc(%r15,%r12), %eax
movl 0x18(%r15,%r12), %esi
shrdl $0x1f, %eax, %esi
movq 0x28(%rsp), %rbx
notl 0x4(%r15,%r12)
leaq (%r15,%r12), %rax
movq %rax, 0xa8(%rsp)
movq 0x38(%rsp), %rax
movl $0x7fffffff, (%rax,%rbp,4) # imm = 0x7FFFFFFF
movl $0x80000000, (%rdi,%rbp,4) # imm = 0x80000000
xorl $0x1, %esi
movq 0x80(%rsp), %rdi
callq 0x1b4723
movl 0x4(%r15,%r12), %ecx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x88(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x1f0(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0xf8(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq %r13, %r14
movq (%r13), %rsi
subl $-0x80, %edx
movl %ebp, %edi
callq 0x19f679
movl %eax, 0xb8(%rsp)
cltq
movl 0x8(%r15,%r12), %ecx
subl 0x4(%r15,%r12), %ecx
movq %rcx, 0xc8(%rsp)
movq %r12, 0x48(%rsp)
movl 0x18(%r15,%r12), %ecx
movq %rcx, 0xc0(%rsp)
movq $-0x1, 0x60(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x7fffffff, 0x120(%rsp) # imm = 0x7FFFFFFF
movq %rax, %rcx
subq %rbx, %rcx
movq %rax, %rsi
movq 0x208(%rsp), %rdx
subq %rdx, %rsi
cmpq %rdx, %rcx
cmovleq %rbx, %rsi
movq %rsi, 0x28(%rsp)
cmpq %rax, %rsi
jle 0x1b8557
movq $-0x80000000, 0x8(%rsp) # imm = 0x80000000
movq $-0x1, 0x70(%rsp)
xorl %ecx, %ecx
movq $0x0, 0x50(%rsp)
movq 0x20(%rsp), %r11
jmp 0x1b86dc
movq %rax, %r15
shlq $0x4, %r15
subq %rax, %r15
subq %rax, %r15
addq $0x4, %r15
movq $-0x80000000, 0x8(%rsp) # imm = 0x80000000
movq $0x0, 0x50(%rsp)
xorl %ebx, %ebx
movq %rax, %r12
xorl %r13d, %r13d
movq $-0x1, 0x70(%rsp)
movq 0x20(%rsp), %r11
movq (%r14), %rdi
movl (%rdi,%r15,2), %eax
movq 0xa8(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1b86d6
subq $0x8, %rsp
movq %rbp, %rdx
movq %r12, %rcx
movq 0x240(%rsp), %r8
movq 0x40(%rsp), %r9
movsd 0x90(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
leaq 0x74(%rsp), %rax
pushq %rax
pushq 0x240(%rsp)
pushq 0x238(%rsp)
pushq 0xf0(%rsp)
pushq 0x270(%rsp)
pushq 0x270(%rsp)
pushq 0x110(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
pushq %r11
pushq 0x248(%rsp)
pushq 0xe0(%rsp)
pushq 0x148(%rsp)
callq 0x1b42f9
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1b8643
movq %r13, %rcx
movq 0x20(%rsp), %r11
jmp 0x1b86ba
movq 0x78(%rsp), %rcx
movslq (%rcx,%r12,4), %rcx
incq %rcx
movq 0x8(%rsp), %rdx
cmpq %rdx, %rax
jg 0x1b8660
jne 0x1b8683
cmpq %rcx, %r13
jge 0x1b8683
movl 0x6c(%rsp), %edx
movq %rdx, 0x50(%rsp)
xorl %edx, %edx
testq %rbx, %rbx
setg %dl
subq %rdx, %rbx
movq %r12, 0x70(%rsp)
movq %rax, %rdx
movq 0x20(%rsp), %r11
jmp 0x1b86a3
movq 0x10(%rsp), %rax
cmpq %rbp, (%rax,%r12,8)
movq 0x20(%rsp), %r11
jne 0x1b86a0
cmpq 0x200(%rsp), %rbx
jge 0x1b86d6
incq %rbx
movq %r13, %rcx
movq %rdx, 0x8(%rsp)
movq (%r11,%r12,8), %rax
testq %rax, %rax
js 0x1b86ba
movq 0x10(%rsp), %rdx
movq %rbp, (%rdx,%rax,8)
leaq -0x1(%r12), %rax
addq $-0xe, %r15
movq %rcx, %r13
cmpq 0x28(%rsp), %r12
movq %rax, %r12
jg 0x1b8590
jmp 0x1b86dc
movq %r13, %rcx
movq %r12, %rax
movq %rcx, 0x40(%rsp)
movq 0x70(%rsp), %rcx
movq %rcx, 0x60(%rsp)
cmpq $0x0, 0x18(%rsp)
movq %r14, %r13
movq 0x78(%rsp), %rbx
movq 0x10(%rsp), %r12
movq 0x210(%rsp), %r15
js 0x1b8735
movq (%r13), %rcx
movq 0x48(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
movq 0x18(%rsp), %rdi
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdi, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq %r15, %rcx
cmpq %rdx, %rcx
jge 0x1b87bd
movq $-0x1, 0x18(%rsp)
cmpq 0x28(%rsp), %rbp
jle 0x1b87bd
movq (%r13), %rcx
movq 0x48(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
addq 0xa0(%rsp), %rcx
movq $-0x80000000, %rdi      # imm = 0x80000000
movq $-0x1, 0x18(%rsp)
movq 0x98(%rsp), %rsi
movq $-0x80000000, %r8       # imm = 0x80000000
movl (%rcx), %r9d
addq %r15, %r9
cmpq %rdx, %r9
jl 0x1b87bd
movq 0x58(%rsp), %r9
movslq (%r9,%rsi,4), %r9
cmpq %r9, %rdi
jge 0x1b87a0
movslq (%rbx,%rsi,4), %r8
movq %r9, %rdi
movq %rsi, 0x18(%rsp)
jmp 0x1b87ab
jne 0x1b87ab
movslq (%rbx,%rsi,4), %r10
cmpq %r10, %r8
jl 0x1b8792
addq $-0x1c, %rcx
leaq -0x1(%rsi), %r9
cmpq 0x28(%rsp), %rsi
movq %r9, %rsi
jg 0x1b8779
movq 0x18(%rsp), %r14
testq %r14, %r14
js 0x1b8892
cmpq %rax, %r14
jge 0x1b8892
movq (%r13), %rdi
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movl 0x8(%rdi,%rax), %eax
movq 0xa8(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1b8892
subq $0x8, %rsp
movq %rbp, %rdx
movq %r14, %rcx
movq 0x240(%rsp), %r8
movq 0x40(%rsp), %r9
movsd 0x90(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
leaq 0x74(%rsp), %rax
pushq %rax
pushq 0x240(%rsp)
pushq 0x238(%rsp)
pushq 0xf0(%rsp)
pushq 0x270(%rsp)
pushq 0x270(%rsp)
pushq 0x110(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
pushq %r11
pushq 0x248(%rsp)
pushq 0xe0(%rsp)
pushq 0x148(%rsp)
callq 0x1b42f9
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1b8a3d
movq 0x20(%rsp), %r11
movq 0x30(%rsp), %r14
movq 0x8(%rsp), %rdi
movq 0xc0(%rsp), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
imulq 0x230(%rsp), %rcx
movq 0xc8(%rsp), %rax
subq %rcx, %rax
cmpq %rdi, %rax
jg 0x1b88cd
jne 0x1b88eb
cmpq $0x0, 0x40(%rsp)
jg 0x1b88eb
movq $-0x1, 0x60(%rsp)
movq $0x1, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq %rax, %rdi
testq %rdi, %rdi
jns 0x1b8905
movq $-0x1, 0x60(%rsp)
movq $0x1, 0x40(%rsp)
movq %rax, %rdi
cmpq $0x0, 0x60(%rsp)
js 0x1b8993
movq (%r13), %r8
movl 0xb8(%rsp), %r9d
incl %r9d
subq $0x50, %rsp
leaq 0x90(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xb0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r12, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x18(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0xd0(%rsp), %rsi
movq 0x288(%rsp), %rdx
movq 0x240(%rsp), %rcx
movsd 0xd8(%rsp), %xmm0
movq %rdi, %r12
callq 0x1b6b37
movq %r12, %rdi
movq 0x70(%rsp), %r11
addq $0x50, %rsp
movq 0x58(%rsp), %rax
movl %edi, (%rax,%rbp,4)
movq 0x60(%rsp), %rax
movq %rax, (%r11,%rbp,8)
movl 0x40(%rsp), %ecx
movl %ecx, (%rbx,%rbp,4)
testq %rax, %rax
movq %rdi, %rcx
movq 0x90(%rsp), %rdi
movq 0x18(%rsp), %r8
js 0x1b89d0
movslq (%rdi,%rax,4), %rax
cmpq %rax, %rcx
jle 0x1b89d2
cmpl $0x0, 0x50(%rsp)
jne 0x1b89d2
movl %ecx, %eax
movl %eax, (%rdi,%rbp,4)
testq %r8, %r8
js 0x1b8a0c
movq (%r13), %rcx
movq 0x48(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
leaq (%r8,%r8,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %r8, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq %r15, %rcx
cmpq %rdx, %rcx
jl 0x1b8a0f
movq 0x58(%rsp), %rdx
movl (%rdx,%r8,4), %ecx
cmpl (%rdx,%rbp,4), %ecx
jge 0x1b8a0f
movq %rbp, %r8
movslq %eax, %rbx
cmpq %rbx, %r14
cmovlq %r14, %rbx
incq %rbp
addq $0x1c, 0xa0(%rsp)
incq 0x98(%rsp)
cmpq 0xb0(%rsp), %rbp
jne 0x1b8409
jmp 0x1b8a89
movslq (%rbx,%r14,4), %rcx
incq %rcx
movq 0x8(%rsp), %rdi
cmpq %rdi, %rax
movq 0x20(%rsp), %r11
movq 0x30(%rsp), %r14
jg 0x1b8a69
jne 0x1b889c
cmpq %rcx, 0x40(%rsp)
jge 0x1b889c
movq 0x18(%rsp), %rdx
movq %rdx, 0x60(%rsp)
movq %rcx, 0x40(%rsp)
movl 0x6c(%rsp), %ecx
movq %rcx, 0x50(%rsp)
movq %rax, %rdi
jmp 0x1b889c
movq 0xb0(%rsp), %rbp
movq 0x10(%rsp), %r15
testq %rbp, %rbp
jle 0x1b8abc
xorl %eax, %eax
movq %rbp, %rcx
movl (%rdi,%rax,2), %edx
subl %ebx, %edx
movl %edx, (%rdi,%rax,2)
shlq $0x20, %rdx
addq %rax, %rdx
movq %rdx, (%r15,%rax,4)
addq $0x2, %rax
decq %rcx
jne 0x1b8aa0
leaq (%r15,%rbp,8), %rsi
movq %r15, %rdi
movq %rsi, 0xc8(%rsp)
callq 0x19525e
testq %rbp, %rbp
jle 0x1b8eed
movq 0x228(%rsp), %r12
movq 0x58(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0xc0(%rsp)
movq 0x78(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0xb8(%rsp)
movq 0x38(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0xa0(%rsp)
movq 0x20(%rsp), %r8
leaq (%r8,%rbp,8), %rax
movq %rax, 0x98(%rsp)
leaq -0x8(%r12), %rax
movq %rax, 0x90(%rsp)
movq %rbp, %rax
xorl %ebp, %ebp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rax, %r9
xorl %ecx, %ecx
xorl %r10d, %r10d
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl $0x0, 0x48(%rsp)
movl $0x0, 0x30(%rsp)
xorl %r11d, %r11d
movq %rcx, 0x28(%rsp)
movq %r9, %rbx
decq %r9
movl -0x8(%r15,%rbx,8), %ecx
shrl %ecx
xorl %eax, %eax
testb $0x1, (%r15,%rcx,8)
jne 0x1b8bb5
movq (%r13), %rdx
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
movl 0x4(%rdx,%rsi), %edi
movl 0x8(%rdx,%rsi), %edx
cmpl %r14d, %edi
cmovbl %edi, %r14d
cmpl %ebp, %edx
cmoval %edx, %ebp
movl %eax, %edx
movq %rcx, (%r12,%rdx,8)
orb $0x1, (%r15,%rcx,8)
movq (%r8,%rcx,8), %rcx
incq %rax
testq %rcx, %rcx
jns 0x1b8b74
movq %rax, %rdx
addq %r10, %rdx
cmpq %rdx, %r10
jne 0x1b8bcd
movq %rdx, %r10
movq 0x28(%rsp), %rcx
jmp 0x1b8eb4
movslq 0x4(%r15,%r9,8), %r15
testq %rcx, %rcx
js 0x1b8be3
movq 0x58(%rsp), %rdx
movslq (%rdx,%rcx,4), %rcx
subq %rcx, %r15
movl 0x8(%rsp), %ecx
movl %ecx, %edi
cmpl $-0x1, %ecx
je 0x1b8c5a
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movq 0x38(%rsp), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx,%rdi,4), %xmm1
mulsd 0x7ac85(%rip), %xmm1    # 0x233890
ucomisd %xmm0, %xmm1
jbe 0x1b8c5a
movl 0x30(%rsp), %edx
cmpl %ebp, %edx
movl %ebp, %ecx
cmovbl %edx, %ecx
movl 0x48(%rsp), %esi
cmpl %r14d, %esi
movl %r14d, %edx
cmoval %esi, %edx
subl %edx, %ecx
ja 0x1b8c33
xorpd %xmm0, %xmm0
jmp 0x1b8c3b
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl %ebp, %ecx
subl %r14d, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x6c848(%rip), %xmm1    # 0x225498
ucomisd %xmm1, %xmm0
jae 0x1b8ede
movq %rdi, 0x70(%rsp)
movq %rbx, 0x50(%rsp)
movq %r9, 0x18(%rsp)
movq %r11, 0xa8(%rsp)
movl %eax, %ecx
cmpl $0x2, %eax
jb 0x1b8ca8
shrl %eax
negq %rax
movq 0x90(%rsp), %rdx
leaq (%rdx,%rcx,8), %rdx
movq %r12, %rsi
xorl %edi, %edi
movq (%rsi), %r8
movq (%rdx,%rdi,8), %r9
movq %r9, (%rsi)
movq %r8, (%rdx,%rdi,8)
decq %rdi
addq $0x8, %rsi
cmpq %rdi, %rax
jne 0x1b8c8e
movq (%r13), %rax
movl %r14d, %edx
movl %ebp, %edi
leaq (%r10,%r10,8), %rsi
leaq (%rsi,%rsi,2), %rsi
movq 0xf0(%rsp), %r8
addq %r10, %r8
addq %r8, %rsi
subq $0xd0, %rsp
movq %rdi, 0x28(%rsp)
leaq 0x1d4(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
movq 0x1a8(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
movq 0x318(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
movq 0x310(%rsp), %rdi
movq %rdi, 0x98(%rsp)
movq 0x300(%rsp), %rdi
movq %rdi, 0x90(%rsp)
movq 0x2f0(%rsp), %rdi
movq %rdi, 0x88(%rsp)
movq 0x2e0(%rsp), %rdi
movq %rdi, 0x80(%rsp)
movq 0x2d8(%rsp), %rdi
movq %rdi, 0x78(%rsp)
movq 0x2d0(%rsp), %rdi
movq %rdi, 0x70(%rsp)
movq 0x198(%rsp), %rdi
movq %rdi, 0x68(%rsp)
movq 0x168(%rsp), %rdi
movq %rdi, 0x60(%rsp)
movq 0x170(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movq 0x188(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movq 0x190(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movq 0xe0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x180(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %r12, (%rsp)
movq %rsi, 0xb8(%rsp)
movl $0x3e8, 0xb0(%rsp) # imm = 0x3E8
movq 0x1a0(%rsp), %rdi
movq 0x308(%rsp), %rsi
movq 0x1b0(%rsp), %rdx
movq 0x150(%rsp), %rcx
movq 0x2c0(%rsp), %r8
movsd 0x158(%rsp), %xmm0
movq 0x2c8(%rsp), %r9
movsd 0x1b8(%rsp), %xmm1
movq %r10, %rbx
callq 0x1b78cb
addq $0xd0, %rsp
testq %rax, %rax
jle 0x1b8f99
addq %rax, %rbx
movq 0xa8(%rsp), %r11
cmpq %r11, %r15
cmovlq %r15, %r11
movq 0x28(%rsp), %rsi
leaq 0x1(%rsi), %rcx
movq 0x78(%rsp), %rdx
movl %eax, (%rdx,%rsi,4)
movq 0x38(%rsp), %rax
movl %r15d, (%rax,%rsi,4)
cmpl $-0x1, 0x8(%rsp)
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
movq %rbx, %r10
movq 0x50(%rsp), %rbx
movq 0x70(%rsp), %rdx
je 0x1b8e90
movq 0x38(%rsp), %rax
movslq (%rax,%rdx,4), %rax
cmpq %rax, %r15
jle 0x1b8ec0
movl 0x108(%rsp), %eax
movl %eax, 0x48(%rsp)
movl 0x10c(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x28(%rsp), %rax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %r15
cmpq $0x1, %rbx
jg 0x1b8b60
jmp 0x1b8ef2
jne 0x1b8eaf
movl 0x10c(%rsp), %eax
subl 0x108(%rsp), %eax
movl 0x30(%rsp), %edx
subl 0x48(%rsp), %edx
cmpl %edx, %eax
ja 0x1b8e90
jmp 0x1b8eaf
movq 0x28(%rsp), %rcx
jmp 0x1b8eaf
xorl %r14d, %r14d
jmp 0x1b8f84
xorl %r11d, %r11d
xorl %ecx, %ecx
testq %rcx, %rcx
movq 0xf0(%rsp), %r9
jle 0x1b8f66
leaq -0x14(%r9), %rax
movq (%r13), %rdx
addq $0x14, %rdx
xorl %edi, %edi
xorl %esi, %esi
movq 0x78(%rsp), %r10
movslq (%r10,%rsi,4), %r14
addq %rdi, %r14
movq 0x38(%rsp), %r8
movl (%r8,%rsi,4), %r8d
subl %r11d, %r8d
movl %r8d, -0x14(%rdx)
movl %edi, -0x4(%rdx)
movl %r14d, (%rdx)
leaq (%rdi,%rdi,8), %r8
leaq (%r8,%r8,2), %r8
addq %rdi, %r8
movl 0x4(%r9,%r8), %edi
movl %edi, -0x10(%rdx)
leaq (%r14,%r14,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %r14, %rdi
movl (%rax,%rdi), %edi
movl %edi, -0xc(%rdx)
incq %rsi
addq $0x1c, %rdx
movq %r14, %rdi
cmpq %rsi, %rcx
jne 0x1b8f14
jmp 0x1b8f69
xorl %r14d, %r14d
movq %rcx, 0x8(%r13)
movq (%r13), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
addq %rdi, %rsi
callq 0x195d3d
movq %r14, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7c80e(%rip), %rdi     # 0x2357ae
leaq 0x7a9e4(%rip), %rsi     # 0x23398b
leaq 0x7c80b(%rip), %rcx     # 0x2357b9
movl $0x2343, %edx           # imm = 0x2343
callq 0x2110