// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gl_rchain_lin_contain(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(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 *a,
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; 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, rev_t; rtrace_iter tc;
    resize_Chain_Data(dp, res_n, NULL);
    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; a[i] = ((uint64_t)-1); 
        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 == 20171 || li->tn == 20209 || li->tn == 20204) {
		// 	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 || 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\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; 
    radix_sort_gfa64i(t, t + res_n); plus = 0;
    for (k = res_n-1, n_v = n_u = 0; k >= 0; --k) {
        n_v0 = n_v;
        for (i = ((uint32_t)t[k])>>1; i >= 0 && (t[i]&1) == 0; ) {
            ex[n_v++] = res->a[i]; t[i] |= 1; i = p[i];
        }
        if(n_v0 == n_v) continue;
        sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i]));
        c_n[n_u] = n_v-n_v0; c_sc[n_u] = sc; n_u++; if(sc < plus) plus = sc;
    }
    // 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
        // fprintf(stderr, "[M::%s] k:%ld, c_sc:%d\n", __func__, k, c_sc[k]);

        rev_n = c_n[k]>>1; 
        ///we need to consider contained reads; so determining qs is not such easy
        // res->a[k].qs = (uint32_t)-1; res->a[k].qe = ex[n_v0].qe;
        for (i = 0; i < rev_n; i++) {
            rev_t = ex[n_v0+i]; ex[n_v0+i] = ex[n_v-i-1]; ex[n_v-i-1] = rev_t;
            // if(res->a[k].qs > ex[n_v0+i].qs) res->a[k].qs = ex[n_v0+i].qs;
            // if(res->a[k].qs > ex[n_v-i-1].qs) res->a[k].qs = ex[n_v-i-1].qs;
            ex[n_v0+i].sec = ex[n_v-i-1].sec = SEC_MODE; 
        }
        if(c_n[k]&1) {
            // if(res->a[k].qs > ex[n_v0+i].qs) res->a[k].qs = ex[n_v0+i].qs;
            ex[n_v0+i].sec = SEC_MODE; 
        }
		// flat_contain(ex+n_v0, n_v-n_v0);
		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, 0xd8(%rsp)
movsd %xmm0, 0x68(%rsp)
movq %r9, 0x60(%rsp)
movq %r8, 0xd0(%rsp)
movq %rcx, 0xc8(%rsp)
movq %rdi, 0xc0(%rsp)
movq 0x8(%rsi), %rbp
testq %rbp, %rbp
je 0x1b76af
movq %rsi, %rax
movq %rdx, 0x78(%rsp)
movq 0x258(%rsp), %rbx
movq 0x218(%rsp), %r14
xorl %r15d, %r15d
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rax, 0x8(%rsp)
callq 0x3f828
movq 0x8(%rsp), %rax
movq 0x28(%r14), %r12
movq (%r14), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%r14), %rcx
movq %rcx, 0x70(%rsp)
movq 0x20(%r14), %rcx
movq %rcx, 0x58(%rsp)
movq 0x18(%r14), %rcx
movq %rcx, 0x50(%rsp)
movq 0x10(%r14), %rcx
movq %rcx, 0x20(%rsp)
testq %rbx, %rbx
je 0x1b6eac
movq (%rax), %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %rbp, %rsi
callq 0x195511
movq 0x8(%rsp), %rdi
testq %rbp, %rbp
jle 0x1b6eac
movq %rbp, %rbx
negq %rbx
movl $0x1, %r14d
movl $0x1c, %r13d
xorl %eax, %eax
movq (%rdi), %rcx
notl -0x18(%rcx,%r13)
movq %rbx, %rdx
addq %r14, %rdx
je 0x1b6e67
movl 0x8(%rcx,%r13), %edx
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl 0x8(%rcx,%rsi), %edx
jne 0x1b6e67
movq %rax, %rdx
jmp 0x1b6e95
movq %r14, %rsi
subq %rax, %rsi
movq %r14, %rdx
cmpq $0x2, %rsi
jl 0x1b6e95
leaq (%rcx,%r13), %rsi
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdi
addq %rax, %rdi
addq %rcx, %rdi
callq 0x1957bd
movq 0x8(%rsp), %rdi
movq %r14, %rdx
leaq (%rbx,%r14), %rcx
incq %rcx
incq %r14
addq $0x1c, %r13
movq %rdx, %rax
cmpq $0x1, %rcx
jne 0x1b6e3c
leaq (,%rbp,8), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x8(%rsp), %r11
testq %rbp, %rbp
movq 0x70(%rsp), %rbx
movq 0x20(%rsp), %r8
jle 0x1b75bc
movq %rbp, 0xa8(%rsp)
movq 0x1f8(%rsp), %rax
incq %rax
movq %rax, 0xe0(%rsp)
movq $-0x14, 0xb8(%rsp)
xorl %r15d, %r15d
movq $-0x1, 0xb0(%rsp)
xorl %ebp, %ebp
movq $-0x1, %rdi
movq $0x0, 0x30(%rsp)
movq %r12, 0x90(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x30(%rsp), %rbx
movq %r15, 0xf8(%rsp)
movq (%r11), %r14
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %r13
addq %rbp, %r13
movl 0xc(%r14,%r13), %eax
movl 0x18(%r14,%r13), %esi
shrdl $0x1f, %eax, %esi
leaq (%r14,%r13), %rax
movq %rax, 0x80(%rsp)
notl 0x4(%r14,%r13)
movq 0x50(%rsp), %rax
movl $0x7fffffff, (%rax,%rbp,4) # imm = 0x7FFFFFFF
movl $0x80000000, (%r8,%rbp,4) # imm = 0x80000000
movq 0x228(%rsp), %rax
movq $-0x1, %r12
movq %r12, (%rax,%rbp,8)
xorl $0x1, %esi
movq 0x60(%rsp), %rdi
movq %r11, %r15
callq 0x1b4723
movl 0x4(%r14,%r13), %ecx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x1f0(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0xe0(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq (%r15), %rsi
subl $-0x80, %edx
movl %ebp, %edi
callq 0x19f679
movl %eax, 0xa4(%rsp)
cltq
movl 0x8(%r14,%r13), %ecx
subl 0x4(%r14,%r13), %ecx
movq %rcx, 0xf0(%rsp)
movq %r13, 0x88(%rsp)
movl 0x18(%r14,%r13), %ecx
movq %rcx, 0xe8(%rsp)
movq %r12, 0x40(%rsp)
movq $0x0, 0x28(%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, 0x30(%rsp)
cmpq %rax, %rsi
jle 0x1b7082
movq $-0x80000000, %r12      # imm = 0x80000000
movq $-0x1, 0x98(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x14(%rsp)
movq 0x8(%rsp), %r11
jmp 0x1b720b
movq %rax, %r15
shlq $0x4, %r15
subq %rax, %r15
subq %rax, %r15
addq $0x4, %r15
movq $-0x80000000, %r12      # imm = 0x80000000
xorl %ebx, %ebx
movq %rax, %r13
movl $0x0, 0x14(%rsp)
xorl %r14d, %r14d
movq $-0x1, 0x98(%rsp)
movq 0x8(%rsp), %r11
movq (%r11), %rdi
movl (%rdi,%r15,2), %eax
movq 0x80(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1b7205
subq $0x8, %rsp
movq %rbp, %rdx
movq %r13, %rcx
movq 0x240(%rsp), %r8
movq 0x58(%rsp), %r9
movsd 0x70(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
leaq 0x54(%rsp), %rax
pushq %rax
pushq 0x240(%rsp)
pushq 0x238(%rsp)
pushq 0xe0(%rsp)
pushq 0x270(%rsp)
pushq 0x270(%rsp)
pushq 0x100(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0xc0(%rsp)
pushq 0x248(%rsp)
pushq 0xc0(%rsp)
pushq 0x138(%rsp)
callq 0x1b42f9
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1b7170
movq %r14, %rcx
movq 0x8(%rsp), %r11
jmp 0x1b71ea
movq 0x58(%rsp), %rcx
movslq (%rcx,%r13,4), %rcx
incq %rcx
cmpq %r12, %rax
jg 0x1b7188
jne 0x1b71ad
cmpq %rcx, %r14
jge 0x1b71ad
movl 0x4c(%rsp), %edx
movl %edx, 0x14(%rsp)
xorl %edx, %edx
testq %rbx, %rbx
setg %dl
subq %rdx, %rbx
movq %r13, 0x98(%rsp)
movq %rax, %r12
movq 0x8(%rsp), %r11
jmp 0x1b71d0
movq 0x90(%rsp), %rax
cmpq %rbp, (%rax,%r13,8)
movq 0x8(%rsp), %r11
jne 0x1b71cd
cmpq 0x200(%rsp), %rbx
jge 0x1b7205
incq %rbx
movq %r14, %rcx
movq 0x70(%rsp), %rax
movq (%rax,%r13,8), %rax
testq %rax, %rax
js 0x1b71ea
movq 0x90(%rsp), %rdx
movq %rbp, (%rdx,%rax,8)
leaq -0x1(%r13), %rax
addq $-0xe, %r15
movq %rcx, %r14
cmpq 0x30(%rsp), %r13
movq %rax, %r13
jg 0x1b70bb
jmp 0x1b720b
movq %r14, %rcx
movq %r13, %rax
movq %rcx, 0x28(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x40(%rsp)
cmpq $0x0, 0x18(%rsp)
movq 0x70(%rsp), %rbx
movq 0x58(%rsp), %r14
movq 0x210(%rsp), %r15
movq %r12, %r13
movq 0x90(%rsp), %r12
js 0x1b7271
movq (%r11), %rcx
movq 0x88(%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 0x1b72fb
movq $-0x1, 0x18(%rsp)
cmpq 0x30(%rsp), %rbp
jle 0x1b72fb
movq (%r11), %rcx
movq 0x88(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
addq 0xb8(%rsp), %rcx
movq $-0x1, 0x18(%rsp)
movq $-0x80000000, %rsi      # imm = 0x80000000
movq 0xb0(%rsp), %rdi
movq $-0x80000000, %r8       # imm = 0x80000000
movl (%rcx), %r9d
addq %r15, %r9
cmpq %rdx, %r9
jl 0x1b72fb
movq 0x38(%rsp), %r9
movslq (%r9,%rdi,4), %r9
cmpq %r9, %r8
jge 0x1b72de
movslq (%r14,%rdi,4), %rsi
movq %rdi, 0x18(%rsp)
movq %r9, %r8
jmp 0x1b72e9
jne 0x1b72e9
movslq (%r14,%rdi,4), %r10
cmpq %r10, %rsi
jl 0x1b72d0
addq $-0x1c, %rcx
leaq -0x1(%rdi), %r9
cmpq 0x30(%rsp), %rdi
movq %r9, %rdi
jg 0x1b72b7
movq 0x18(%rsp), %r15
testq %r15, %r15
js 0x1b73cb
cmpq %rax, %r15
jge 0x1b73cb
movq (%r11), %rdi
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %rax
addq %r15, %rax
movl 0x8(%rdi,%rax), %eax
movq 0x80(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1b73cb
subq $0x8, %rsp
movq %rbp, %rdx
movq %r15, %rcx
movq 0x240(%rsp), %r8
movq 0x58(%rsp), %r9
movsd 0x70(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
leaq 0x54(%rsp), %rax
pushq %rax
pushq 0x240(%rsp)
pushq 0x238(%rsp)
pushq 0xe0(%rsp)
pushq 0x270(%rsp)
pushq 0x270(%rsp)
pushq 0x100(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq %rbx
pushq 0x248(%rsp)
pushq 0xc0(%rsp)
pushq 0x138(%rsp)
callq 0x1b42f9
addq $0x70, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1b756c
movq 0x8(%rsp), %r11
movl 0x14(%rsp), %r15d
movq 0x20(%rsp), %r8
movq 0xe8(%rsp), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
imulq 0x230(%rsp), %rcx
movq 0xf0(%rsp), %rax
subq %rcx, %rax
cmpq %r13, %rax
jg 0x1b7406
jne 0x1b741e
cmpq $0x0, 0x28(%rsp)
jg 0x1b741e
movq $-0x1, 0x40(%rsp)
movq $0x1, 0x28(%rsp)
xorl %r15d, %r15d
movq %rax, %r13
testq %r13, %r13
jns 0x1b7438
movq $-0x1, 0x40(%rsp)
movq $0x1, 0x28(%rsp)
movq %rax, %r13
cmpq $0x0, 0x40(%rsp)
js 0x1b74bd
movq (%r11), %r8
movl 0xa4(%rsp), %r9d
incl %r9d
subq $0x50, %rsp
leaq 0x78(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r12, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0xb0(%rsp), %rsi
movq 0x288(%rsp), %rdx
movq 0x240(%rsp), %rcx
movsd 0xb8(%rsp), %xmm0
callq 0x1b6b37
movq 0x70(%rsp), %r8
movq 0x58(%rsp), %r11
addq $0x50, %rsp
movq 0x38(%rsp), %rax
movl %r13d, (%rax,%rbp,4)
movq 0x40(%rsp), %rax
movq %rax, (%rbx,%rbp,8)
movl 0x28(%rsp), %ecx
movl %ecx, (%r14,%rbp,4)
testq %rax, %rax
movq 0x18(%rsp), %rdi
js 0x1b74ef
movslq (%r8,%rax,4), %rax
cmpq %rax, %r13
jle 0x1b74f2
testl %r15d, %r15d
jne 0x1b74f2
movl %r13d, %eax
movl %eax, (%r8,%rbp,4)
testq %rdi, %rdi
js 0x1b7533
movq (%r11), %rcx
movq 0x88(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdi, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq 0x210(%rsp), %rcx
cmpq %rdx, %rcx
jl 0x1b7536
movq 0x38(%rsp), %rdx
movl (%rdx,%rdi,4), %ecx
cmpl (%rdx,%rbp,4), %ecx
jge 0x1b7536
movq %rbp, %rdi
movslq %eax, %r15
movq 0xf8(%rsp), %rax
cmpq %r15, %rax
cmovlq %rax, %r15
incq %rbp
addq $0x1c, 0xb8(%rsp)
incq 0xb0(%rsp)
cmpq 0xa8(%rsp), %rbp
jne 0x1b6f26
jmp 0x1b75b4
movslq (%r14,%r15,4), %rcx
incq %rcx
cmpq %r13, %rax
movq 0x8(%rsp), %r11
movl 0x14(%rsp), %r15d
movq 0x20(%rsp), %r8
jg 0x1b7598
jne 0x1b73d5
cmpq %rcx, 0x28(%rsp)
jge 0x1b73d5
movq 0x18(%rsp), %rdx
movq %rdx, 0x40(%rsp)
movq %rcx, 0x28(%rsp)
movl 0x4c(%rsp), %r15d
movq %rax, %r13
jmp 0x1b73d5
movq 0xa8(%rsp), %rbp
testq %rbp, %rbp
jle 0x1b75e5
xorl %eax, %eax
movq %rbp, %rcx
movl (%r8,%rax,2), %edx
subl %r15d, %edx
movl %edx, (%r8,%rax,2)
shlq $0x20, %rdx
addq %rax, %rdx
movq %rdx, (%r12,%rax,4)
addq $0x2, %rax
decq %rcx
jne 0x1b75c6
leaq (%r12,%rbp,8), %rsi
movq %r12, %rdi
callq 0x19525e
testq %rbp, %rbp
jle 0x1b76b7
xorl %r13d, %r13d
xorl %eax, %eax
xorl %r14d, %r14d
movq 0x8(%rsp), %r10
movq 0x78(%rsp), %r11
movq 0x58(%rsp), %r15
movq %rax, %rdx
movq %rbp, %rcx
decq %rbp
movl -0x8(%r12,%rcx,8), %esi
shrl %esi
leaq (%rax,%rax,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %r11, %rdi
addq %rax, %rdi
testb $0x1, (%r12,%rsi,8)
jne 0x1b766d
movq (%r10), %r8
leaq (%rsi,%rsi,8), %r9
leaq (%r9,%r9,2), %r9
addq %rsi, %r9
movupd (%r8,%r9), %xmm0
movups 0xc(%r8,%r9), %xmm1
movups %xmm1, 0xc(%rdi)
movupd %xmm0, (%rdi)
orb $0x1, (%r12,%rsi,8)
incq %rax
movq (%rbx,%rsi,8), %rsi
addq $0x1c, %rdi
testq %rsi, %rsi
jns 0x1b762f
cmpq %rdx, %rax
je 0x1b76a3
movslq 0x4(%r12,%rbp,8), %rdi
testq %rsi, %rsi
js 0x1b7688
movq 0x38(%rsp), %r8
movslq (%r8,%rsi,4), %rsi
subq %rsi, %rdi
movl %eax, %esi
subl %edx, %esi
movl %esi, (%r15,%r13,4)
movq 0x50(%rsp), %rdx
movl %edi, (%rdx,%r13,4)
incq %r13
cmpq %r14, %rdi
cmovlq %rdi, %r14
cmpq $0x1, %rcx
jg 0x1b7611
jmp 0x1b76cc
xorl %r14d, %r14d
jmp 0x1b78b6
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%rsp), %r10
movq 0x78(%rsp), %r11
movq 0x58(%rsp), %r15
testq %r13, %r13
jle 0x1b7892
movq %r14, 0x80(%rsp)
leaq -0x1c(%r11), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
xorl %ebx, %ebx
movq %r13, 0x30(%rsp)
movslq (%r15,%rbx,4), %r14
addq %rax, %r14
movq 0x50(%rsp), %rcx
movl (%rcx,%rbx,4), %ecx
subl 0x80(%rsp), %ecx
movq (%r10), %rdx
leaq (%rbx,%rbx,8), %rsi
leaq (%rsi,%rsi,2), %r13
addq %rbx, %r13
movl %ecx, (%rdx,%r13)
movl %eax, 0x10(%rdx,%r13)
movl %r14d, 0x14(%rdx,%r13)
movl (%r15,%rbx,4), %ecx
cmpl $0x2, %ecx
jae 0x1b773b
xorl %edx, %edx
movq 0x78(%rsp), %r8
jmp 0x1b77bf
sarl %ecx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rsi
movq 0x78(%rsp), %r8
addq %r8, %rsi
addq %rax, %rsi
cmpl $0x1, %ecx
adcl $0x0, %ecx
leaq (%r14,%r14,8), %rdx
leaq (%rdx,%rdx,2), %rdi
movq 0x18(%rsp), %rdx
addq %r14, %rdx
addq %rdx, %rdi
xorl %edx, %edx
movups (%rsi), %xmm0
movups 0xc(%rsi), %xmm1
movups %xmm1, 0x10c(%rsp)
movaps %xmm0, 0x100(%rsp)
movups (%rdi), %xmm0
movups 0xc(%rdi), %xmm1
movups %xmm1, 0xc(%rsi)
movups %xmm0, (%rsi)
movups 0x10c(%rsp), %xmm0
movups %xmm0, 0xc(%rdi)
movapd 0x100(%rsp), %xmm0
movupd %xmm0, (%rdi)
orl %ebp, 0x18(%rdi)
orl %ebp, 0x18(%rsi)
incq %rdx
addq $0x1c, %rsi
addq $-0x1c, %rdi
cmpq %rdx, %rcx
jne 0x1b776b
testb $0x1, (%r15,%rbx,4)
je 0x1b77e7
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r8, %rax
addq %rcx, %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
orl $0x3fffffff, 0x18(%rax,%rcx) # imm = 0x3FFFFFFF
movq (%r10), %rax
leaq (%rax,%r13), %rsi
movl 0x10(%rax,%r13), %r15d
movl 0x14(%rax,%r13), %eax
leaq (%r15,%r15,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %r15, %r10
addq %r8, %r10
addq %rcx, %r10
subl %r15d, %eax
subq $0x8, %rsp
movq 0x240(%rsp), %rdi
movq 0x68(%rsp), %rdx
movq 0x1f8(%rsp), %rcx
movsd 0x70(%rsp), %xmm0
movq 0x200(%rsp), %r8
movq 0x208(%rsp), %r9
pushq %rsi
pushq %r12
pushq 0x88(%rsp)
pushq 0x40(%rsp)
pushq 0x60(%rsp)
pushq %rax
pushq %r10
pushq 0x250(%rsp)
pushq 0x250(%rsp)
callq 0x1b6440
movq 0x58(%rsp), %r10
addq $0x50, %rsp
addl %r15d, %eax
movq (%r10), %rcx
movl %eax, 0x14(%rcx,%r13)
incq %rbx
movq %r14, %rax
movq 0x30(%rsp), %r13
cmpq %r13, %rbx
movq 0x58(%rsp), %r15
jne 0x1b76f4
jmp 0x1b7895
xorl %r14d, %r14d
movq %r13, 0x8(%r10)
movq (%r10), %rdi
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rsi
addq %r13, %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