// File: /workspace/github_cpp_makefile_star2_O3/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, 0xe0(%rsp)
movsd %xmm0, 0x70(%rsp)
movq %r9, 0x68(%rsp)
movq %r8, 0xd8(%rsp)
movq %rcx, 0xd0(%rsp)
movq %rdi, 0xc8(%rsp)
movq 0x8(%rsi), %rbp
testq %rbp, %rbp
je 0x1c27be
movq %rsi, %rax
movq %rdx, 0xf0(%rsp)
movq 0x258(%rsp), %rbx
movq 0x218(%rsp), %r14
leaq (,%rbp,2), %rsi
movq %r14, %rdi
xorl %edx, %edx
movq %rax, (%rsp)
callq 0x3ecb0
movq (%rsp), %rax
movq 0x28(%r14), %rdi
movq (%r14), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%r14), %rcx
movq %rcx, 0x40(%rsp)
movq 0x20(%r14), %r12
movq 0x18(%r14), %r13
movq 0x10(%r14), %rcx
movq %rcx, 0x88(%rsp)
testq %rbx, %rbx
movq %rdi, 0x18(%rsp)
je 0x1c202e
movq (%rax), %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %rbp, %rsi
callq 0x19e2b4
testq %rbp, %rbp
jle 0x1c2c1a
movq %rbp, %rbx
negq %rbx
movl $0x1, %r14d
movl $0x1c, %r15d
xorl %eax, %eax
movq (%rsp), %r8
movq 0x18(%rsp), %rdi
movq (%r8), %rcx
notl -0x18(%rcx,%r15)
movq %rbx, %rdx
addq %r14, %rdx
je 0x1c1fe5
movl 0x8(%rcx,%r15), %edx
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl 0x8(%rcx,%rsi), %edx
jne 0x1c1fe5
movq %rax, %rdx
jmp 0x1c2017
movq %r14, %rsi
subq %rax, %rsi
movq %r14, %rdx
cmpq $0x2, %rsi
jl 0x1c2017
leaq (%rcx,%r15), %rsi
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdi
addq %rax, %rdi
addq %rcx, %rdi
callq 0x19e55c
movq 0x18(%rsp), %rdi
movq (%rsp), %r8
movq %r14, %rdx
leaq (%rbx,%r14), %rcx
incq %rcx
incq %r14
addq $0x1c, %r15
movq %rdx, %rax
cmpq $0x1, %rcx
jne 0x1c1fba
leaq (,%rbp,8), %rdx
xorl %esi, %esi
callq 0x20e0
testq %rbp, %rbp
movq 0x88(%rsp), %r9
jle 0x1c2c2e
movq %rbp, 0xb0(%rsp)
movq 0x1f8(%rsp), %rax
incq %rax
movq %rax, 0xf8(%rsp)
movq $-0x1, 0x98(%rsp)
movq $-0x14, 0x90(%rsp)
movq $0x0, 0x28(%rsp)
movq $-0x1, 0x8(%rsp)
xorl %eax, %eax
xorl %ebp, %ebp
movq (%rsp), %r11
movq %r12, 0xa0(%rsp)
movq %r13, 0x58(%rsp)
movq %rax, 0xc0(%rsp)
movq (%r11), %r12
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %r14
addq %rbp, %r14
movl 0xc(%r12,%r14), %eax
movl 0x18(%r12,%r14), %esi
shrdl $0x1f, %eax, %esi
movq 0x28(%rsp), %rbx
notl 0x4(%r12,%r14)
leaq (%r12,%r14), %rax
movq %rax, 0xa8(%rsp)
movl $0x7fffffff, (%r13,%rbp,4) # imm = 0x7FFFFFFF
movl $0x80000000, (%r9,%rbp,4) # imm = 0x80000000
xorl $0x1, %esi
movq 0x68(%rsp), %rdi
callq 0x1be0f4
movl 0x4(%r12,%r14), %ecx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x70(%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
subl $-0x80, %edx
movl %ebp, %edi
movq %r12, %rsi
callq 0x1a83b5
movl %eax, 0xec(%rsp)
cltq
movl 0x8(%r12,%r14), %ecx
movl 0x18(%r12,%r14), %edx
movq %rdx, 0xb8(%rsp)
movq %r14, 0x60(%rsp)
subl 0x4(%r12,%r14), %ecx
movq %rcx, 0x50(%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 0x1c21d1
movq $-0x80000000, 0x10(%rsp) # imm = 0x80000000
movq $-0x1, 0x20(%rsp)
xorl %ebx, %ebx
movq $0x0, 0x30(%rsp)
movq (%rsp), %r11
jmp 0x1c235d
movq %rax, %r15
shlq $0x4, %r15
subq %rax, %r15
subq %rax, %r15
addq $0x4, %r15
movq $-0x1, 0x20(%rsp)
movq $-0x80000000, 0x10(%rsp) # imm = 0x80000000
movq $0x0, 0x30(%rsp)
xorl %r14d, %r14d
movq %rax, %r12
xorl %r13d, %r13d
movq (%rsp), %r11
movq (%r11), %rdi
movl (%rdi,%r15,2), %eax
movq 0xa8(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1c2357
subq $0x8, %rsp
movq %rbp, %rdx
movq %r12, %rcx
movq 0x240(%rsp), %r8
movq 0x60(%rsp), %r9
movsd 0x78(%rsp), %xmm0
movsd 0xe8(%rsp), %xmm1
leaq 0x54(%rsp), %rax
pushq %rax
pushq 0x240(%rsp)
pushq 0x238(%rsp)
pushq 0xe8(%rsp)
pushq 0x270(%rsp)
pushq 0x270(%rsp)
pushq 0x108(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq 0x248(%rsp)
pushq 0xc8(%rsp)
pushq 0x140(%rsp)
callq 0x1bdcad
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1c22be
movq %r13, %rbx
movq (%rsp), %r11
jmp 0x1c233b
movq 0xa0(%rsp), %rcx
movslq (%rcx,%r12,4), %rbx
incq %rbx
movq 0x10(%rsp), %rcx
cmpq %rcx, %rax
jg 0x1c22de
jne 0x1c2300
cmpq %rbx, %r13
jge 0x1c2300
movl 0x4c(%rsp), %ecx
movq %rcx, 0x30(%rsp)
xorl %ecx, %ecx
testq %r14, %r14
setg %cl
subq %rcx, %r14
movq %r12, 0x20(%rsp)
movq %rax, %rcx
movq (%rsp), %r11
jmp 0x1c231f
movq 0x18(%rsp), %rax
cmpq %rbp, (%rax,%r12,8)
movq (%rsp), %r11
jne 0x1c231c
cmpq 0x200(%rsp), %r14
jge 0x1c2357
incq %r14
movq %r13, %rbx
movq %rcx, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rax
testq %rax, %rax
js 0x1c233b
movq 0x18(%rsp), %rcx
movq %rbp, (%rcx,%rax,8)
leaq -0x1(%r12), %rax
addq $-0xe, %r15
movq %rbx, %r13
cmpq 0x28(%rsp), %r12
movq %rax, %r12
jg 0x1c220a
jmp 0x1c235d
movq %r13, %rbx
movq %r12, %rax
movq %rbx, 0x78(%rsp)
movq 0x20(%rsp), %rcx
movq %rcx, 0x80(%rsp)
cmpq $0x0, 0x8(%rsp)
movq 0xa0(%rsp), %r12
movq 0x58(%rsp), %r15
movq 0x210(%rsp), %r14
js 0x1c23b8
movq (%r11), %rcx
movq 0x60(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
movq 0x8(%rsp), %rdi
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdi, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq %r14, %rcx
cmpq %rdx, %rcx
jge 0x1c243f
cmpq 0x28(%rsp), %rbp
jle 0x1c252d
movq (%r11), %rcx
movq 0x60(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
addq 0x90(%rsp), %rcx
movq $-0x80000000, %rdi      # imm = 0x80000000
movq $-0x1, 0x8(%rsp)
movq 0x98(%rsp), %rsi
movq $-0x80000000, %r8       # imm = 0x80000000
movl (%rcx), %r9d
addq %r14, %r9
cmpq %rdx, %r9
jl 0x1c243f
movq 0x38(%rsp), %r9
movslq (%r9,%rsi,4), %r9
cmpq %r9, %rdi
jge 0x1c241d
movslq (%r12,%rsi,4), %r8
movq %r9, %rdi
movq %rsi, 0x8(%rsp)
jmp 0x1c242d
jne 0x1c242d
movslq (%r12,%rsi,4), %r10
cmpq %r10, %r8
jge 0x1c242d
movq %r10, %r8
jmp 0x1c2413
leaq -0x1(%rsi), %r9
addq $-0x1c, %rcx
cmpq 0x28(%rsp), %rsi
movq %r9, %rsi
jg 0x1c23f6
movq 0x8(%rsp), %r13
testq %r13, %r13
movq 0x50(%rsp), %rsi
js 0x1c2523
cmpq %rax, %r13
jge 0x1c2523
movq (%r11), %rdi
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rax
addq %r13, %rax
movl 0x8(%rdi,%rax), %eax
movq 0xa8(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1c2523
subq $0x8, %rsp
movq %rbp, %rdx
movq %r13, %rcx
movq 0x240(%rsp), %r8
movq %r15, %r9
movsd 0x78(%rsp), %xmm0
movsd 0xe8(%rsp), %xmm1
leaq 0x54(%rsp), %rax
pushq %rax
pushq 0x240(%rsp)
pushq 0x238(%rsp)
pushq 0xe8(%rsp)
pushq 0x270(%rsp)
pushq 0x270(%rsp)
pushq 0x108(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq 0x248(%rsp)
pushq 0xc8(%rsp)
pushq 0x140(%rsp)
callq 0x1bdcad
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1c274f
movq %rbx, %rcx
movq (%rsp), %r11
jmp 0x1c2537
movq %rbx, %rcx
movq 0x10(%rsp), %rdi
jmp 0x1c2541
movq %rbx, %rcx
movq $-0x1, %r13
movq 0x10(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq %r13, 0x8(%rsp)
movq 0xb8(%rsp), %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
imulq 0x230(%rsp), %rax
subq %rax, %rsi
cmpq %rdi, %rsi
movq 0x228(%rsp), %rbx
jg 0x1c2573
jne 0x1c2599
testq %rcx, %rcx
jg 0x1c2599
movq $-0x1, 0x80(%rsp)
movq $0x1, 0x78(%rsp)
testq %rsi, %rsi
movq %r15, %r13
jns 0x1c269d
jmp 0x1c2688
testq %rdi, %rdi
movq %r15, %r13
js 0x1c2688
movq 0x20(%rsp), %r8
testq %r8, %r8
js 0x1c2798
movq (%r11), %r8
movl 0xec(%rsp), %r9d
incl %r9d
subq $0x50, %rsp
leaq 0xc8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r12, 0x20(%rsp)
movq 0x90(%rsp), %rbx
movq %rbx, 0x18(%rsp)
movq %r13, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0xb8(%rsp), %rsi
movq 0x288(%rsp), %rdx
movq 0x240(%rsp), %rcx
movsd 0xc0(%rsp), %xmm0
movq %rdi, %r15
callq 0x1c0730
movq %r15, %rsi
addq $0x50, %rsp
movq 0x80(%rsp), %rcx
movq 0x38(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movl %esi, (%rax)
movq %rcx, (%rbx,%rbp,8)
movl 0x78(%rsp), %edx
movl %edx, (%r12,%rbp,4)
testq %rcx, %rcx
js 0x1c27a0
cmpl $0x0, 0x30(%rsp)
movq 0x88(%rsp), %r9
movslq (%r9,%rcx,4), %rcx
movl %ecx, %edx
cmovel %esi, %edx
cmpq %rcx, %rsi
cmovlel %ecx, %edx
movl %edx, %esi
movq (%rsp), %r11
movq 0x228(%rsp), %rbx
jmp 0x1c26c9
movq $-0x1, 0x80(%rsp)
movq $0x1, 0x78(%rsp)
movq $-0x1, %r8
movl $0x1, %ecx
movq 0x38(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movl %esi, (%rax)
movq 0x40(%rsp), %rdx
movq %r8, (%rdx,%rbp,8)
movl %ecx, (%r12,%rbp,4)
movq 0x88(%rsp), %r9
movl %esi, (%r9,%rbp,4)
cmpq $0x0, 0x8(%rsp)
js 0x1c2714
movq %rsi, %r8
movq (%r11), %rcx
movq 0x60(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
movq 0x8(%rsp), %rdi
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdi, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq %r14, %rcx
cmpq %rdx, %rcx
jge 0x1c2705
movq %r8, %rsi
jmp 0x1c2719
movq 0x38(%rsp), %rcx
movl (%rcx,%rdi,4), %ecx
cmpl (%rax), %ecx
movq %r8, %rsi
jge 0x1c2719
movq %rbp, 0x8(%rsp)
movslq %esi, %rax
movq 0xc0(%rsp), %rcx
cmpq %rax, %rcx
cmovlq %rcx, %rax
incq %rbp
incq 0x98(%rsp)
addq $0x1c, 0x90(%rsp)
cmpq 0xb0(%rsp), %rbp
jne 0x1c20a8
jmp 0x1c27c6
movslq (%r12,%r13,4), %rcx
incq %rcx
movq 0x10(%rsp), %rdi
cmpq %rdi, %rax
movq (%rsp), %r11
movq 0x50(%rsp), %rsi
jg 0x1c2770
jne 0x1c27b1
cmpq %rcx, %rbx
jge 0x1c27b1
movq 0x8(%rsp), %r13
movq %r13, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movl 0x4c(%rsp), %edx
movq %rdx, 0x30(%rsp)
movq %r13, 0x20(%rsp)
movq %rax, %rdi
jmp 0x1c2541
movq %rdi, %rsi
jmp 0x1c26a9
movq (%rsp), %r11
movq 0x228(%rsp), %rbx
jmp 0x1c26c1
movq %rbx, %rcx
movq 0x8(%rsp), %r13
jmp 0x1c2541
xorl %r14d, %r14d
jmp 0x1c2c5f
movq 0xb0(%rsp), %rbp
testq %rbp, %rbp
jle 0x1c2c2e
xorl %ecx, %ecx
movq %rbp, %rdx
movq 0x18(%rsp), %rdi
movl (%r9,%rcx,2), %esi
subl %eax, %esi
movl %esi, (%r9,%rcx,2)
shlq $0x20, %rsi
addq %rcx, %rsi
movq %rsi, (%rdi,%rcx,4)
addq $0x2, %rcx
decq %rdx
jne 0x1c27e1
leaq (%rdi,%rbp,8), %rsi
movq %rsi, 0x60(%rsp)
callq 0x19e008
testq %rbp, %rbp
jle 0x1c2c3c
movq 0x38(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0x50(%rsp)
leaq (%r12,%rbp,4), %rax
movq %rax, 0xc0(%rsp)
leaq (%r13,%rbp,4), %rax
movq %rax, 0xb8(%rsp)
movq 0x40(%rsp), %rax
leaq (%rax,%rbp,8), %rax
movq %rax, 0x98(%rsp)
leaq -0x8(%rbx), %rax
movq %rax, 0x90(%rsp)
xorl %r15d, %r15d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbp, %r8
xorl %esi, %esi
xorl %ebp, %ebp
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0x0, 0x20(%rsp)
movl $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq (%rsp), %r10
movq 0x18(%rsp), %r11
movq %rsi, %r14
movq %r8, %r13
decq %r8
movl -0x8(%r11,%r13,8), %ecx
shrl %ecx
xorl %eax, %eax
testb $0x1, (%r11,%rcx,8)
jne 0x1c28eb
movq (%r10), %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 %r12d, %edi
cmovbl %edi, %r12d
cmpl %r15d, %edx
cmoval %edx, %r15d
movl %eax, %edx
movq %rcx, (%rbx,%rdx,8)
orb $0x1, (%r11,%rcx,8)
movq 0x40(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
incq %rax
testq %rcx, %rcx
jns 0x1c28a4
movq %rax, %rdx
addq %rbp, %rdx
cmpq %rdx, %rbp
jne 0x1c28fe
movq %r14, %rsi
jmp 0x1c2beb
movslq 0x4(%r11,%r8,8), %rbx
testq %rcx, %rcx
js 0x1c2914
movq 0x38(%rsp), %rdx
movslq (%rdx,%rcx,4), %rcx
subq %rcx, %rbx
movl %r9d, %edi
cmpl $-0x1, %r9d
je 0x1c298c
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movq 0x58(%rsp), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx,%rdi,4), %xmm1
mulsd 0x7d226(%rip), %xmm1    # 0x23fb60
ucomisd %xmm0, %xmm1
jbe 0x1c298c
movl 0x30(%rsp), %edx
cmpl %r15d, %edx
movl %r15d, %ecx
cmovbl %edx, %ecx
movl 0x20(%rsp), %esi
cmpl %r12d, %esi
movl %r12d, %edx
cmoval %esi, %edx
subl %edx, %ecx
ja 0x1c2964
xorpd %xmm0, %xmm0
jmp 0x1c296c
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl %r15d, %ecx
subl %r12d, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x6ec16(%rip), %xmm1    # 0x231598
ucomisd %xmm1, %xmm0
jae 0x1c2c15
movq %rdi, 0xa8(%rsp)
movl %r9d, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl %eax, %ecx
cmpl $0x2, %eax
jb 0x1c29da
shrl %eax
negq %rax
movq 0x90(%rsp), %rdx
leaq (%rdx,%rcx,8), %rdx
movq 0x228(%rsp), %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 0x1c29c0
movq (%r10), %rax
movl %r12d, %edx
movl %r15d, %edi
leaq (,%rbp,8), %rsi
addq %rbp, %rsi
leaq (%rsi,%rsi,2), %rsi
movq 0xf0(%rsp), %r8
addq %rbp, %r8
addq %r8, %rsi
subq $0xd0, %rsp
movq %rdi, 0x28(%rsp)
leaq 0x1d4(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
movq 0x1a0(%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 0x130(%rsp), %rdi
movq %rdi, 0x68(%rsp)
movq 0x168(%rsp), %rdi
movq %rdi, 0x60(%rsp)
movq 0x188(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movq 0x190(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movq 0x120(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movq %r11, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x180(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq 0x2f8(%rsp), %rax
movq %rax, (%rsp)
movq %rsi, 0xb8(%rsp)
movl $0x3e8, 0xb0(%rsp) # imm = 0x3E8
movq 0x198(%rsp), %rdi
movq 0x308(%rsp), %rsi
movq 0x1a8(%rsp), %rdx
movq 0x138(%rsp), %rcx
movq 0x2c0(%rsp), %r8
movsd 0x140(%rsp), %xmm0
movq 0x2c8(%rsp), %r9
movsd 0x1b0(%rsp), %xmm1
callq 0x1c1589
addq $0xd0, %rsp
testq %rax, %rax
jle 0x1c2cf7
addq %rax, %rbp
movq 0x28(%rsp), %rcx
cmpq %rcx, %rbx
cmovlq %rbx, %rcx
movq %rcx, 0x28(%rsp)
leaq 0x1(%r14), %rsi
movq 0xa0(%rsp), %rcx
movl %eax, (%rcx,%r14,4)
movq 0x58(%rsp), %rax
movl %ebx, (%rax,%r14,4)
movl 0x8(%rsp), %r9d
cmpl $-0x1, %r9d
movq (%rsp), %r10
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r8
movq 0xa8(%rsp), %rcx
je 0x1c2bca
movq 0x58(%rsp), %rax
movslq (%rax,%rcx,4), %rax
cmpq %rax, %rbx
jle 0x1c2bf7
movl 0x108(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x10c(%rsp), %eax
movl %eax, 0x30(%rsp)
movl %r14d, %r9d
movq 0x228(%rsp), %rbx
cmpq $0x1, %r13
jg 0x1c2892
jmp 0x1c2c74
jne 0x1c2be3
movl 0x10c(%rsp), %eax
subl 0x108(%rsp), %eax
movl 0x30(%rsp), %ecx
subl 0x20(%rsp), %ecx
cmpl %ecx, %eax
ja 0x1c2bca
jmp 0x1c2be3
movq %r14, %rsi
jmp 0x1c2be3
leaq (,%rbp,8), %rdx
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x18(%rsp), %rdi
leaq (%rdi,%rbp,8), %rsi
callq 0x19e008
movq (%rsp), %r10
movq (%r10), %rdi
xorl %esi, %esi
xorl %r14d, %r14d
movq %rsi, 0x8(%r10)
leaq (%rsi,%rsi,8), %rax
leaq (%rax,%rax,2), %rax
addq %rdi, %rsi
addq %rax, %rsi
callq 0x19ead4
movq %r14, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r10), %rdi
testq %rsi, %rsi
jle 0x1c2c45
movq 0xf0(%rsp), %r11
leaq -0x14(%r11), %rax
leaq 0x14(%rdi), %rcx
xorl %r14d, %r14d
xorl %edx, %edx
movq 0xa0(%rsp), %rbx
movq 0x58(%rsp), %r15
movq 0x28(%rsp), %r12
movq %r14, %r8
movslq (%rbx,%rdx,4), %r14
addq %r8, %r14
movl (%r15,%rdx,4), %r9d
subl %r12d, %r9d
movl %r9d, -0x14(%rcx)
movl %r8d, -0x4(%rcx)
movl %r14d, (%rcx)
leaq (%r8,%r8,8), %r9
leaq (%r9,%r9,2), %r9
addq %r8, %r9
movl 0x4(%r11,%r9), %r8d
movl %r8d, -0x10(%rcx)
leaq (%r14,%r14,8), %r8
leaq (%r8,%r8,2), %r8
addq %r14, %r8
movl (%rax,%r8), %r8d
movl %r8d, -0xc(%rcx)
incq %rdx
addq $0x1c, %rcx
cmpq %rdx, %rsi
jne 0x1c2ca3
jmp 0x1c2c48
leaq 0x7ed80(%rip), %rdi     # 0x241a7e
leaq 0x7cf56(%rip), %rsi     # 0x23fc5b
leaq 0x7ed7d(%rip), %rcx     # 0x241a89
movl $0x2343, %edx           # imm = 0x2343
callq 0x2110