// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1a8, %rsp            # imm = 0x1A8
movsd %xmm1, 0xd0(%rsp)
movsd %xmm0, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq %r8, 0xc8(%rsp)
movq %rcx, 0xc0(%rsp)
movq %rdi, 0xb8(%rsp)
movq 0x8(%rsi), %r13
testq %r13, %r13
je 0x176f29
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq 0x248(%rsp), %rbx
movq 0x208(%rsp), %r14
leaq (,%r13,2), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x1383e
movq 0x28(%r14), %rax
movq %rax, 0x30(%rsp)
movq (%r14), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x50(%rsp)
movq 0x20(%r14), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%r14), %rax
movq %rax, 0x20(%rsp)
movq 0x10(%r14), %r14
testq %rbx, %rbx
movq %r12, 0xd8(%rsp)
movq %r14, 0x60(%rsp)
je 0x176f31
pushq $0x1
popq %rbx
movq 0x8(%rsp), %r14
movq (%r14), %rdi
imulq $0x1c, %r13, %rsi
addq %rdi, %rsi
callq 0x156f5c
movq %r14, %rdi
xorl %eax, %eax
testq %r13, %r13
movl $0x0, %r14d
cmovgq %r13, %r14
movq %r14, %rbp
negq %r14
pushq $0x1c
popq %r15
leaq (%r14,%rbx), %rcx
cmpq $0x1, %rcx
je 0x176f1f
movq (%rdi), %rcx
notl -0x18(%rcx,%r15)
cmpq %rbx, %r13
je 0x176eec
movl 0x8(%rcx,%r15), %edx
imulq $0x1c, %rax, %rsi
cmpl 0x8(%rcx,%rsi), %edx
jne 0x176eec
movq %rax, %rdx
jmp 0x176f13
movq %rbx, %rsi
subq %rax, %rsi
movq %rbx, %rdx
cmpq $0x2, %rsi
jl 0x176f13
leaq (%rcx,%r15), %rsi
imulq $0x1c, %rax, %rdi
addq %rcx, %rdi
callq 0x1571fa
movq 0x8(%rsp), %rdi
movq %rbx, %rdx
incq %rbx
addq $0x1c, %r15
movq %rdx, %rax
jmp 0x176ec1
movq 0x60(%rsp), %r14
movq %rbp, %r15
jmp 0x176f3b
xorl %r14d, %r14d
jmp 0x177a4f
xorl %r15d, %r15d
testq %r13, %r13
cmovgq %r13, %r15
movq %r13, 0xe0(%rsp)
leaq (,%r13,8), %rdx
xorl %ebp, %ebp
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x1e8(%rsp), %rax
incq %rax
movq %rax, 0xe8(%rsp)
pushq $-0x1
popq %rax
xorl %edi, %edi
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movq 0x8(%rsp), %r9
movq %r15, 0xa0(%rsp)
cmpq %r15, %rbp
je 0x1775a5
movq %rdi, 0xb0(%rsp)
movq (%r9), %rbx
imulq $0x1c, %rbp, %r15
movl 0xc(%rbx,%r15), %eax
movl 0x18(%rbx,%r15), %esi
shrdl $0x1f, %eax, %esi
notl 0x4(%rbx,%r15)
leaq (%rbx,%r15), %rax
movq %rax, 0x98(%rsp)
movq 0x20(%rsp), %rax
movl $0x7fffffff, (%rax,%rbp,4) # imm = 0x7FFFFFFF
movl $0x80000000, (%r14,%rbp,4) # imm = 0x80000000
xorl $0x1, %esi
movq 0x78(%rsp), %rdi
callq 0x173810
movl 0x4(%rbx,%r15), %ecx
addq %rax, %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x80(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x1e0(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0xe8(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq 0x8(%rsp), %rax
movq (%rax), %rsi
subl $-0x80, %edx
movl %ebp, %edi
callq 0x160717
movq 0x8(%rsp), %r9
movl %eax, 0xa8(%rsp)
movslq %eax, %r14
movl 0x8(%rbx,%r15), %ecx
movl 0x18(%rbx,%r15), %eax
movq %r15, 0x40(%rsp)
subl 0x4(%rbx,%r15), %ecx
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
imulq 0x220(%rsp), %rax
subq %rax, %rcx
movq %rcx, 0x68(%rsp)
movq %r14, %rax
subq %r12, %rax
movq %r14, %rcx
movq 0x1f8(%rsp), %rdx
subq %rdx, %rcx
cmpq %rdx, %rax
cmovgq %rcx, %r12
movq $0x7fffffff, 0x110(%rsp) # imm = 0x7FFFFFFF
imulq $0xe, %r14, %rbx
addq $0x4, %rbx
xorl %r13d, %r13d
movq $-0x80000000, 0x10(%rsp) # imm = 0x80000000
pushq $-0x1
popq %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
movl $0x0, 0x70(%rsp)
cmpq %r12, %r14
jl 0x1771fa
movq (%r9), %rdi
movl (%rdi,%rbx,2), %eax
movq 0x98(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1771fa
subq $0x8, %rsp
movq %rbp, %rdx
movq %r14, %rcx
movq 0x230(%rsp), %r8
movq 0x28(%rsp), %r9
movsd 0x88(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
leaq 0x64(%rsp), %rax
pushq %rax
pushq 0x230(%rsp)
pushq 0x228(%rsp)
pushq 0xd8(%rsp)
pushq 0x260(%rsp)
pushq 0x260(%rsp)
pushq 0xf8(%rsp)
leaq 0x150(%rsp), %rax
pushq %rax
pushq 0x90(%rsp)
pushq 0xa0(%rsp)
pushq 0x238(%rsp)
pushq 0xd8(%rsp)
pushq 0x130(%rsp)
callq 0x1733e0
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x177176
movq %r13, %rcx
movq 0x8(%rsp), %r9
jmp 0x1771eb
movq 0x18(%rsp), %rcx
movslq (%rcx,%r14,4), %rcx
incq %rcx
cmpq 0x10(%rsp), %rax
jg 0x177190
jne 0x1771b4
cmpq %rcx, %r13
jge 0x1771b4
movl 0x5c(%rsp), %edx
movl %edx, 0x70(%rsp)
xorl %edx, %edx
testq %r15, %r15
setg %dl
subq %rdx, %r15
movq %r14, 0x28(%rsp)
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %r9
jmp 0x1771d4
movq 0x30(%rsp), %rax
cmpq %rbp, (%rax,%r14,8)
movq 0x8(%rsp), %r9
jne 0x1771d1
cmpq 0x1f0(%rsp), %r15
jge 0x1771fa
incq %r15
movq %r13, %rcx
movq 0x50(%rsp), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
js 0x1771eb
movq 0x30(%rsp), %rdx
movq %rbp, (%rdx,%rax,8)
decq %r14
addq $-0xe, %rbx
movq %rcx, %r13
jmp 0x1770b6
movq %r13, 0x88(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x38(%rsp), %rbx
testq %rbx, %rbx
movq 0x200(%rsp), %r15
js 0x17723d
movq (%r9), %rax
movq 0x40(%rsp), %rcx
movl 0x8(%rax,%rcx), %ecx
imulq $0x1c, %rbx, %rdx
movl 0x8(%rax,%rdx), %eax
addq %r15, %rax
cmpq %rcx, %rax
jge 0x1772ba
movq $-0x80000000, %rcx      # imm = 0x80000000
movq %rbp, %rax
movq $-0x80000000, %rdx      # imm = 0x80000000
pushq $-0x1
popq %rbx
imulq $0x7, %rax, %rsi
decq %rax
addq $-0x5, %rsi
leaq 0x1(%rax), %rdi
cmpq %r12, %rdi
jle 0x1772ba
movq (%r9), %rdi
movq 0x40(%rsp), %r8
movl 0x8(%rdi,%r8), %r8d
movl (%rdi,%rsi,4), %edi
addq %r15, %rdi
cmpq %r8, %rdi
jl 0x1772ba
movq 0x48(%rsp), %rdi
movslq (%rdi,%rax,4), %rdi
cmpq %rdi, %rdx
jl 0x1772a4
jne 0x17729b
movq 0x18(%rsp), %r8
movslq (%r8,%rax,4), %r8
cmpq %r8, %rcx
jl 0x1772af
decq %rax
addq $-0x7, %rsi
jmp 0x17725c
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
jmp 0x1772b2
movq %r8, %rcx
movq %rdi, %rdx
movq %rax, %rbx
jmp 0x177251
testq %rbx, %rbx
movq 0x68(%rsp), %rdx
js 0x177398
cmpq %r14, %rbx
jge 0x177398
movq (%r9), %rdi
imulq $0x1c, %rbx, %rax
movl 0x8(%rdi,%rax), %eax
movq 0x98(%rsp), %rcx
cmpl 0x4(%rcx), %eax
movq 0x60(%rsp), %r14
jbe 0x177391
subq $0x8, %rsp
movq %rbp, %rdx
movq %rbx, %rcx
movq 0x230(%rsp), %r8
movq 0x28(%rsp), %r9
movsd 0x88(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
leaq 0x64(%rsp), %rax
pushq %rax
pushq 0x230(%rsp)
pushq 0x228(%rsp)
pushq 0xd8(%rsp)
pushq 0x260(%rsp)
pushq 0x260(%rsp)
pushq 0xf8(%rsp)
leaq 0x150(%rsp), %rax
pushq %rax
pushq 0x90(%rsp)
pushq 0xa0(%rsp)
pushq 0x238(%rsp)
pushq 0xd8(%rsp)
pushq 0x130(%rsp)
callq 0x1733e0
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x17754f
movq 0x8(%rsp), %r9
movq 0x68(%rsp), %rdx
jmp 0x17739d
movq 0x60(%rsp), %r14
movq %rbx, 0x38(%rsp)
cmpq 0x10(%rsp), %rdx
jg 0x1773b0
jne 0x1773d5
testq %r13, %r13
jg 0x1773d5
orq $-0x1, 0x90(%rsp)
movq $0x1, 0x88(%rsp)
movb $0x1, %bl
testq %rdx, %rdx
jns 0x1774b0
jmp 0x17749b
cmpl $0x0, 0x70(%rsp)
sete %bl
cmpq $0x0, 0x10(%rsp)
js 0x17749b
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
js 0x177494
movq (%r9), %r8
movl 0xa8(%rsp), %r9d
incl %r9d
subq $0x50, %rsp
leaq 0xd8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0xc8(%rsp), %rsi
movq 0x278(%rsp), %rdx
movq 0x230(%rsp), %rcx
movsd 0xd0(%rsp), %xmm0
callq 0x175983
movq 0x58(%rsp), %r9
addq $0x50, %rsp
movq 0x90(%rsp), %rcx
movq 0x88(%rsp), %r13
movq 0x10(%rsp), %rdx
jmp 0x1774b7
orq $-0x1, 0x90(%rsp)
movq $0x1, 0x88(%rsp)
pushq $0x1
popq %r13
pushq $-0x1
popq %rcx
movq 0x48(%rsp), %rax
movl %edx, (%rax,%rbp,4)
movq 0x50(%rsp), %rax
movq %rcx, (%rax,%rbp,8)
movq 0x18(%rsp), %rax
movl %r13d, (%rax,%rbp,4)
testq %rcx, %rcx
js 0x1774e7
movslq (%r14,%rcx,4), %rax
cmpq %rax, %rdx
setg %cl
andb %bl, %cl
cmpb $0x1, %cl
jne 0x1774e9
movl %edx, %eax
movl %eax, (%r14,%rbp,4)
cmpq $0x0, 0x38(%rsp)
movq 0x30(%rsp), %rbx
movq 0xb0(%rsp), %rdi
js 0x177531
movq (%r9), %rcx
movq 0x40(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
movq 0x38(%rsp), %r8
imulq $0x1c, %r8, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq %r15, %rcx
cmpq %rdx, %rcx
jl 0x177536
movq 0x48(%rsp), %rdx
movl (%rdx,%r8,4), %ecx
cmpl (%rdx,%rbp,4), %ecx
jge 0x177536
movq %rbp, 0x38(%rsp)
cltq
cmpq %rax, %rdi
cmovgeq %rax, %rdi
incq %rbp
movq 0xa0(%rsp), %r15
jmp 0x176f89
movq 0x18(%rsp), %rcx
movslq (%rcx,%rbx,4), %rcx
incq %rcx
cmpq 0x10(%rsp), %rax
movq 0x8(%rsp), %r9
movq 0x68(%rsp), %rdx
jg 0x17757b
jne 0x17739d
cmpq %rcx, %r13
jge 0x17739d
movq %rbx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movl 0x5c(%rsp), %esi
movl %esi, 0x70(%rsp)
movq %rbx, 0x28(%rsp)
movq %rcx, %r13
movq %rax, 0x10(%rsp)
jmp 0x17739d
xorl %eax, %eax
movq 0xe0(%rsp), %rbp
subq $0x1, %r15
jb 0x1775d0
movl (%r14,%rax,2), %ecx
subl %edi, %ecx
movl %ecx, (%r14,%rax,2)
shlq $0x20, %rcx
addq %rax, %rcx
movq %rcx, (%rbx,%rax,4)
addq $0x2, %rax
jmp 0x1775af
movq 0x48(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0x70(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0x38(%rsp)
movq 0x20(%rsp), %rax
leaq (%rax,%rbp,4), %rax
movq %rax, 0x68(%rsp)
movq 0x50(%rsp), %rax
leaq (%rax,%rbp,8), %rax
movq %rax, 0xb0(%rsp)
leaq (%rbx,%rbp,8), %rsi
movq %rbx, %rdi
movq %rsi, 0xa8(%rsp)
callq 0x156cf6
movq 0x8(%rsp), %r10
movq 0x218(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x60(%rsp)
pushq $-0x1
popq %rsi
movq $0x0, 0x28(%rsp)
movsd 0x7a3e7(%rip), %xmm2    # 0x1f1a30
movsd 0x6be97(%rip), %xmm3    # 0x1e34e8
xorl %edx, %edx
xorl %eax, %eax
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %r12d, %r12d
movl %esi, %r15d
movl %esi, %r14d
movl %edx, 0x10(%rsp)
movl %eax, 0x98(%rsp)
subl %eax, %edx
movl %edx, 0xa0(%rsp)
movq %rcx, 0x40(%rsp)
testq %rbp, %rbp
jle 0x1779b8
movq %rbp, %rdx
decq %rbp
movq 0x30(%rsp), %r11
movl -0x8(%r11,%rdx,8), %esi
shrl %esi
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x218(%rsp), %rbx
testq %rsi, %rsi
js 0x1776e9
testb $0x1, (%r11,%rsi,8)
jne 0x1776e9
movq (%r10), %rdi
imulq $0x1c, %rsi, %r8
movl 0x4(%rdi,%r8), %r9d
movl 0x8(%rdi,%r8), %edi
cmpl %r15d, %r9d
cmovbl %r9d, %r15d
cmpl %r12d, %edi
cmoval %edi, %r12d
movl %ecx, %edi
movq %rsi, (%rbx,%rdi,8)
orb $0x1, (%r11,%rsi,8)
movq 0x50(%rsp), %rdi
movq (%rdi,%rsi,8), %rsi
incq %rcx
incl %eax
jmp 0x1776a3
testq %rcx, %rcx
je 0x17767c
movq 0x30(%rsp), %rdi
movslq -0x4(%rdi,%rdx,8), %rbx
testq %rsi, %rsi
js 0x177709
movq 0x48(%rsp), %rdx
movslq (%rdx,%rsi,4), %rdx
subq %rdx, %rbx
cmpl $-0x1, %r14d
je 0x17776e
cvtsi2sd %rbx, %xmm0
movq 0x20(%rsp), %rdx
cvtsi2sdl (%rdx,%r14,4), %xmm1
mulsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x17776e
movl 0x10(%rsp), %esi
cmpl %r12d, %esi
movl %r12d, %edx
cmovbl %esi, %edx
movl 0x98(%rsp), %edi
cmpl %r15d, %edi
movl %r15d, %esi
cmoval %edi, %esi
subl %esi, %edx
ja 0x177750
xorpd %xmm0, %xmm0
jmp 0x177755
cvtsi2sd %rdx, %xmm0
movl %r12d, %edx
subl %r15d, %edx
cvtsi2sd %rdx, %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jae 0x17767c
movl %ecx, %ecx
movl %eax, %edx
shrl %eax
movq 0x60(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x1777a3
movq 0x218(%rsp), %r9
movq (%r9,%rsi,8), %rdi
movq (%rdx), %r8
movq %r8, (%r9,%rsi,8)
movq %rdi, (%rdx)
incq %rsi
addq $-0x8, %rdx
jmp 0x17777f
movq (%r10), %rax
movl %r15d, %edx
movl %r12d, %esi
imulq $0x1c, %r13, %rdi
addq 0xd8(%rsp), %rdi
subq $0xd0, %rsp
movq %rdi, 0xb8(%rsp)
leaq 0x1c4(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
movq 0x190(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
movq 0x308(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
movq 0x300(%rsp), %rdi
movq %rdi, 0x98(%rsp)
movq 0x2f0(%rsp), %rdi
movq %rdi, 0x90(%rsp)
movq 0x2e0(%rsp), %rdi
movq %rdi, 0x88(%rsp)
movq 0x2d0(%rsp), %rdi
movq %rdi, 0x80(%rsp)
movq 0x2c8(%rsp), %rdi
movq %rdi, 0x78(%rsp)
movq 0x2c0(%rsp), %rdi
movq %rdi, 0x70(%rsp)
movq 0x178(%rsp), %rdi
movq %rdi, 0x68(%rsp)
movq 0x180(%rsp), %rdi
movq %rdi, 0x60(%rsp)
movq 0x138(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movq 0x108(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movq 0x140(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movq 0x100(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x1b0(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq 0x2e8(%rsp), %rax
movq %rax, (%rsp)
movl $0x3e8, 0xb0(%rsp) # imm = 0x3E8
movq 0x188(%rsp), %rdi
movq 0x2f8(%rsp), %rsi
movq 0x198(%rsp), %rdx
movq 0x148(%rsp), %rcx
movq 0x2b0(%rsp), %r8
movsd 0x150(%rsp), %xmm0
movq 0x2b8(%rsp), %r9
movsd 0x1a0(%rsp), %xmm1
callq 0x176593
addq $0xd0, %rsp
testq %rax, %rax
jle 0x177a64
addq %rax, %r13
movq 0x28(%rsp), %rcx
cmpq %rcx, %rbx
cmovlq %rbx, %rcx
movq %rcx, 0x28(%rsp)
movq 0x40(%rsp), %rsi
leaq 0x1(%rsi), %rcx
movq 0x18(%rsp), %rdx
movl %eax, (%rdx,%rsi,4)
movq 0x20(%rsp), %rax
movl %ebx, (%rax,%rsi,4)
cmpl $-0x1, %r14d
movq 0x8(%rsp), %r10
movsd 0x7a0c4(%rip), %xmm2    # 0x1f1a30
movsd 0x6bb74(%rip), %xmm3    # 0x1e34e8
je 0x1779a5
movq 0x20(%rsp), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %rbx
jg 0x1779a5
jne 0x177677
movl 0xfc(%rsp), %eax
subl 0xf8(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jbe 0x177677
movl 0xf8(%rsp), %eax
movl 0xfc(%rsp), %edx
jmp 0x177660
movq 0xd8(%rsp), %r11
leaq -0x14(%r11), %rax
xorl %ecx, %ecx
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
movl $0x0, %edx
cmovgq %rsi, %rdx
pushq $0x5
popq %rsi
xorl %r14d, %r14d
movq 0x28(%rsp), %rbx
cmpq %rcx, %rdx
je 0x177a37
movq 0x18(%rsp), %rdi
movslq (%rdi,%rcx,4), %rdi
addq %r14, %rdi
movq 0x20(%rsp), %r8
movl (%r8,%rcx,4), %r8d
subl %ebx, %r8d
movq (%r10), %r9
movl %r8d, -0x14(%r9,%rsi,4)
movl %r14d, -0x4(%r9,%rsi,4)
movl %edi, (%r9,%rsi,4)
imulq $0x1c, %r14, %r8
movl 0x4(%r11,%r8), %r8d
movl %r8d, -0x10(%r9,%rsi,4)
imulq $0x1c, %rdi, %r8
movl (%rax,%r8), %r8d
movl %r8d, -0xc(%r9,%rsi,4)
incq %rcx
addq $0x7, %rsi
movq %rdi, %r14
jmp 0x1779e2
movq 0x40(%rsp), %rax
movq %rax, 0x8(%r10)
movq (%r10), %rdi
imulq $0x1c, %rax, %rsi
addq %rdi, %rsi
callq 0x15775d
movq %r14, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7bedb(%rip), %rdi     # 0x1f3946
leaq 0x7a0b1(%rip), %rsi     # 0x1f1b23
leaq 0x7bed8(%rip), %rcx     # 0x1f3951
movl $0x2343, %edx           # imm = 0x2343
callq 0x2110