// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: hc_gchain1_dp(void*, ul_idx_t const*, ma_ug_t const*, vec_mg_lchain_t*, vec_mg_lchain_t*, vec_mg_path_dst_t*, vec_sp_node_t*, vec_mg_pathv_t*, long, ug_opt_t const*, long, double, double, unsigned long*, st_mt_t*, long*, unsigned long*, unsigned long*)
int64_t hc_gchain1_dp(void *km, const ul_idx_t *uref, const ma_ug_t *ug, vec_mg_lchain_t *lc, vec_mg_lchain_t *sw, vec_mg_path_dst_t *dst, vec_sp_node_t *out, vec_mg_pathv_t *path,
int64_t qlen, const ug_opt_t *uopt, int64_t bw, double diff_thre, double ng_diff_thre, uint64_t *srt, st_mt_t *bf, int64_t *f, uint64_t *p, uint64_t *v)
{
	bf->n = 0;
	if(lc->n == 0) return 0;
	int64_t i, j, lc_n = lc->n, n_ext, mm_ovlp, target_dist, max_target_dist, x, m_idx, m_sc, qo, sc; 
	int64_t max_f, max_j = -1, max_d = -1, max_inner = 0, share; uint32_t max_hash = 0; int64_t k, k0, n_u, n_v, ni;
	mg_lchain_t *r, *li, *lj; mg_path_dst_t *q; asg_t *g = ug->g; uint64_t isolated, *u; ul_ov_t ui, uj;
	for (i = n_ext = 0; i < lc_n; i++) {
		r = &lc->a[i]; r->dist_pre = -1; isolated = 0;///dist_pre -> parent in graph chain
		if((r->re < g->seq[r->v>>1].len) && (r->rs > 0)) isolated = 1;///UL contained in one vertice
		if (!isolated) ++n_ext;
		srt[i] = r->qe; srt[i] <<= 32; srt[i] |= (uint64_t)i; srt[i] |= (isolated<<63);
	}
	radix_sort_gfa64(srt, srt+lc_n); 
	for (i = 1, j = 0; i <= lc_n; i++) {
		if (i == lc_n || (srt[i]>>32) != (srt[j]>>32)) {
			if(i - j > 1) {
				for (x = j; x < i; x++) {
					srt[x] <<= 32; srt[x] >>= 32; srt[x] |= ((uint64_t)lc->a[(uint32_t)srt[x]].qs)<<32;
				}
				radix_sort_gfa64(srt+j, srt+i);
			}
			j = i;
		}
	}

	kv_resize(mg_lchain_t, *sw, (uint64_t)lc_n); sw->n = lc_n;
	for (i = 0; i < lc_n; i++) sw->a[i] = lc->a[(uint32_t)srt[i]];
	memcpy(lc->a, sw->a, lc_n *sizeof((*(lc->a))));
	// fprintf(stderr, "[M::%s::] n_ext:%ld, lc_n:%ld\n", __func__, n_ext, lc_n);

	if(ng_diff_thre >= 0) {
		//first non-gap chain
		for (i = 0; i < n_ext; ++i) { // core loop
			li = &lc->a[i]; set_ul_ov_t_by_mg_lchain_t(&ui, li);
			mm_ovlp = max_ovlp(g, li->v^1);
			x = (li->qs + mm_ovlp)*diff_thre; if(x < bw) x = bw; 
			x += li->qs + mm_ovlp;
			if (x > qlen+1) x = qlen+1;
			x = find_mg_lchain_max(i, lc->a, x+G_CHAIN_INDEL);
			// fprintf(stderr, "\nli->(%ld)\tutg%.6d%c(%u)\tqs:%u\tqe:%u\t%c\trs:%u\tre:%u\tsrc:%u\tscore:%d, x:%ld\n", 
			// 	i, (int32_t)(li->v>>1)+1, "lc"[ug->u.a[li->v>>1].circ], ug->u.a[li->v>>1].len,
			// 	li->qs, li->qe, "+-"[li->v&1], li->rs, li->re, li->v^1, li->score, x);
			max_f = li->score, max_j = -1;
			// collect potential destination vertices
			for (j = x; j >= 0; --j) { 
				lj = &lc->a[j]; ///extend_end_coord(lj, qlen, g->seq[lj->v>>1].len, &jqs, &jqe, &jrs, &jre);
				//even this pair has a overlap, its length will be very small; just ignore; only for non-gapped chains
				if(lj->qe+G_CHAIN_INDEL <= li->qs) break;
				if(lj->qs >= li->qs/**+G_CHAIN_INDEL**/) continue;
				set_ul_ov_t_by_mg_lchain_t(&uj, lj);
				qo = infer_rovlp(&ui, &uj, NULL, NULL, NULL, (ma_ug_t *)ug); ///overlap length in query (UL read)
				if(li->v!=lj->v && get_ecov_adv(uref, uopt, li->v^1, lj->v^1, bw, ng_diff_thre, qo, 0, &share)) {
					sc = li->score + f[j];
					if(sc > max_f) {
						max_f = sc; max_j = j;
					}
				}
			}

			f[i] = max_f, p[i] = max_j<0?(uint64_t)-1:max_j;
			li->dist_pre = max_j<0?-1:g_adjacent_dis(g, li->v^1, lc->a[max_j].v^1); li->inner_pre = 0;
			li->hash_pre = max_j<0?0:(__ac_Wang_hash((li->v^1))+__ac_Wang_hash((lc->a[max_j].v^1))); 
			// fprintf(stderr, "i->%ld, utg%.6d%c->utg%.6d%c, max_f:%ld\n", i, (int32_t)(li->v>>1)+1, "lc"[ug->u.a[li->v>>1].circ], 
			// max_j<0?0:(int32_t)(lc->a[max_j].v>>1)+1, max_j<0?'*':"lc"[ug->u.a[lc->a[max_j].v>>1].circ], max_f);
		}

		kv_resize(uint64_t, *bf, (uint64_t)lc_n); u = bf->a;
		hc_chain_backtrack(n_ext, f, p, srt, u, v, &n_u, &n_v);
		for (i = 0; i < lc_n - n_ext; ++i) {
			u[n_u++] = (((uint64_t)lc->a[n_ext + i].score)<<32) | 1;
			v[n_v++] = n_ext + i;
		}

		sw->n = 0; kv_resize(mg_lchain_t, *sw, (uint64_t)n_v); m_idx = m_sc = -1; bf->n = 0;
		for (i = 0, k = 0; i < n_u; ++i) {
			k0 = k, ni = (int32_t)u[i];
			for (j = 0; j < ni; ++j) {
				sw->a[k++] = lc->a[v[k0 + (ni - j - 1)]];
			}
			if(m_idx < 0 || m_sc < ((int64_t)(u[i]>>32))) {
				m_idx = i; m_sc = ((int64_t)(u[i]>>32));
			}
		}
		assert(k == n_v); bf->n = n_u;

		if(primary_chain_check(u, n_u, sw->a)) {
			memcpy(lc->a, sw->a, n_v*sizeof(mg_lchain_t));
			return m_idx;
		} 
	}
	bf->n = 0;

	///then gapped-chaining
	for (i = 0; i < n_ext; ++i) { // core loop
		li = &lc->a[i]; 
		mm_ovlp = max_ovlp(g, li->v^1);
		x = (li->qs + mm_ovlp)*diff_thre; if(x < bw) x = bw; 
        x += li->qs + mm_ovlp;
        if (x > qlen+1) x = qlen+1;
		x = find_mg_lchain_max(i, lc->a, x+G_CHAIN_INDEL);
		// fprintf(stderr, "\nli->(%ld)\tutg%.6d%c(%u)\tqs:%u\tqe:%u\t%c\trs:%u\tre:%u\tsrc:%u\tscore:%d, x:%ld\n", 
		// 	i, (int32_t)(li->v>>1)+1, "lc"[ug->u.a[li->v>>1].circ], ug->u.a[li->v>>1].len,
		// 	li->qs, li->qe, "+-"[li->v&1], li->rs, li->re, li->v^1, li->score, x);

		// collect potential destination vertices
		for (dst->n = 0, max_target_dist= -1, j = x; j >= 0; --j) { 
			///same time for gchain
			// if((p[j]>>33) == ((uint64_t)i)) continue;

			lj = &lc->a[j]; ///extend_end_coord(lj, qlen, g->seq[lj->v>>1].len, &jqs, &jqe, &jrs, &jre);
			//lj contained in li; actually in circle, this might happen; need to deal with it later
			if(lj->qs >= li->qs/**+G_CHAIN_INDEL**/) continue;
			///if there is a circle, the two linear chains might be at the same vertice
			target_dist = hc_target_len(g, li, lj);
			// fprintf(stderr, "j:%ld, target_dist:%ld\n", j, target_dist);
			if(target_dist < 0) continue;
			kv_pushp(mg_path_dst_t, *dst, &q);
			memset(q, 0, sizeof(*q));
			q->inner = 0;//we set q->inner = 0 to allow circles
			q->v = lj->v^1;///must be v^1 instead of v
			q->meta = j;
			///lj->qs************lj->qe
			///			li->qs************li->qe
			q->qlen = li->qs - lj->qe;///might be negative; this is the region that need to be checked in base-level
			q->target_dist = target_dist;///cannot understand the target_dist
			q->target_hash = 0;
			q->check_hash = 0;
			if(max_target_dist < target_dist) max_target_dist = target_dist;
			///not sure how to use this cut-off
			// if (t[j] == i) {
			// 	if (++n_skip > max_skip)
			// 		break;
			// }
			// if (p[j] >= 0) t[p[j]] = i;
			// if((li->v>>1)==10 && ((lj->v>>1)==15||(lj->v>>1)==14)) max_target_dist = 100000;
			// fprintf(stderr, "+++lj->(%ld)\tutg%.6d%c(%u)\t%u\t%u\t%c\ttarget_dist:%d\n", 
			// j, (int32_t)(lj->v>>1)+1, "lc"[ug->u.a[lj->v>>1].circ], ug->u.a[lj->v>>1].len,
			// lj->qs, lj->qe, "+-"[lj->v&1], q->target_dist);

			///j-th has pre, and the pre is good alignment 
			///same time for gchain
			// if((((uint32_t)p[j])!=((uint32_t)-1)) && (p[j]&(uint64_t)(0x100000000))) {
			// 	p[((uint32_t)p[j])] &= (uint64_t)(0x1ffffffff);
			// 	p[((uint32_t)p[j])] |= (((uint64_t)i)<<33);
			// }
		}

		// confirm reach-ability
		max_f = li->score, max_j = -1, max_d = -1, max_inner = 0; max_hash = 0;
		if(dst->n) {
			max_target_dist *= (1+diff_thre); if(max_target_dist < bw) max_target_dist = bw;
			hc_shortest_k(km, g, li->v^1, dst->n, dst->a, max_target_dist, MG_MAX_SHORT_K, bf, srt, out, NULL, 1, 0, 0);
			// remove unreachable destinations
			//TODO: check sequence identity
            for (j = 0; j < (int64_t)dst->n; ++j) {
                mg_path_dst_t *dj = &dst->a[j];
                if (dj->n_path == 0) continue; // unreachable
                sc = cal_gchain_sc(dj, li, lc->a, f, bw, diff_thre, W_CHN_PEN_GAP);		

				// fprintf(stderr, "---dj->(%ld)\tutg%.6d%c(%u)\tsc:%d\tmax_f:%ld\ttarget_dist:%d\tdj->dist:%d\n", 
				// j, (int32_t)(dj->v>>1)+1, "lc"[ug->u.a[dj->v>>1].circ], ug->u.a[dj->v>>1].len, sc, max_f, dj->target_dist, dj->dist);	
                if (sc == INT32_MIN) continue; // out of band
				// fprintf(stderr, "+max_f->%d, max_j->%d\n", max_f, max_j);
				if (sc < 0) continue;// negative score
				// fprintf(stderr, "++max_f->%d, max_j->%d\n", max_f, max_j);
				if (sc > max_f) {
					max_f = sc, max_j = dj->meta, max_d = dj->dist, max_hash = dj->hash, max_inner = dj->inner;
					// fprintf(stderr, "+++max_f->%d, max_j->%d\n", max_f, max_j);
				}
            }
		}

		f[i] = max_f; p[i] = max_j<0?(uint64_t)-1:max_j;
		///same time for gchain
		// if(max_j < 0) {
		// 	p[i] = (uint32_t)-1;
		// } else {
		// 	p[i] = max_j;
		// 	if(ck_hq_chain(li, &(lc->a[max_j]), (ma_ug_t *)ug, uref, uopt, bw, ng_diff_thre)) {
		// 		p[i] |= (uint64_t)(0x100000000);
		// 	}
		// }


		li->dist_pre = max_d;
		li->hash_pre = max_hash;
		li->inner_pre = max_inner;
		// fprintf(stderr, "i->%ld, utg%.6d%c->utg%.6d%c, max_f:%ld\n", i, (int32_t)(li->v>>1)+1, "lc"[ug->u.a[li->v>>1].circ], 
		// max_j<0?0:(int32_t)(lc->a[max_j].v>>1)+1, max_j<0?'*':"lc"[ug->u.a[lc->a[max_j].v>>1].circ], max_f);
	}

	///same time for gchain
	// for (i = 0; i < n_ext; ++i) {
	// 	if(((uint32_t)p[i])==((uint32_t)-1)) p[i] = (uint64_t)-1;
	// 	else p[i] = (uint32_t)p[i];
	// }

	kv_resize(uint64_t, *bf, (uint64_t)lc_n); u = bf->a;
	hc_chain_backtrack(n_ext, f, p, srt, u, v, &n_u, &n_v);
	for (i = 0; i < lc_n - n_ext; ++i) {
        u[n_u++] = (((uint64_t)lc->a[n_ext + i].score)<<32) | 1;
        v[n_v++] = n_ext + i;
    }

	sw->n = 0; kv_resize(mg_lchain_t, *sw, (uint64_t)n_v); m_idx = m_sc = -1; bf->n = 0;
	for (i = 0, k = 0; i < n_u; ++i) {
        k0 = k, ni = (int32_t)u[i];
        for (j = 0; j < ni; ++j) {
			sw->a[k++] = lc->a[v[k0 + (ni - j - 1)]];
		}
		if(m_idx < 0 || m_sc < ((int64_t)(u[i]>>32))) {
			m_idx = i; m_sc = ((int64_t)(u[i]>>32));
		}
    }
    assert(k == n_v); bf->n = n_u;
	memcpy(lc->a, sw->a, n_v*sizeof(mg_lchain_t));
	return m_idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movsd %xmm1, 0x40(%rsp)
movsd %xmm0, 0x68(%rsp)
movq 0x130(%rsp), %rax
andq $0x0, (%rax)
movq %rsi, 0x58(%rsp)
movq %rdi, 0x80(%rsp)
movq %rcx, (%rsp)
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x1699c9
movq %r8, %r15
movq 0x128(%rsp), %rbp
movq 0x110(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x18(%rdx), %rcx
movq %rcx, 0x38(%rsp)
xorl %r13d, %r13d
testq %rax, %rax
movl $0x0, %r12d
movq %rax, 0x18(%rsp)
cmovgq %rax, %r12
pushq $0x4
popq %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
pushq $0x1
popq %rdx
xorl %esi, %esi
cmpq %rsi, %r12
je 0x16963c
movq (%rsp), %rdi
movq (%rdi), %rdi
orl $-0x1, (%rdi,%rax,8)
movl -0x18(%rdi,%rax,8), %r8d
movq 0x38(%rsp), %r10
movq 0x20(%r10), %r10
shrl %r8d
movl (%r10,%r8,8), %r8d
andl %ecx, %r8d
cmpl %r8d, -0x10(%rdi,%rax,8)
jge 0x169617
xorl %r8d, %r8d
xorl %r10d, %r10d
cmpl $0x0, -0x14(%rdi,%rax,8)
setg %r8b
setle %r10b
shlq $0x3f, %r8
jmp 0x16961d
movq %rdx, %r10
xorl %r8d, %r8d
addq %r10, %r13
movl -0x8(%rdi,%rax,8), %edi
shlq $0x20, %rdi
orq %rsi, %r8
orq %rdi, %r8
movq %r8, (%rbp,%rsi,8)
incq %rsi
addq $0x5, %rax
jmp 0x1695cf
movq %r9, 0x20(%rsp)
movq 0x18(%rsp), %rax
leaq (,%rax,8), %rsi
addq %rbp, %rsi
movq %rbp, %rdi
callq 0x156b0d
leaq 0x1(%r12), %rbx
pushq $0x1
popq %r14
xorl %eax, %eax
cmpq %rbx, %r14
je 0x1696de
cmpq 0x18(%rsp), %r14
je 0x169685
movq (%rbp,%rax,8), %rcx
xorq (%rbp,%r14,8), %rcx
shrq $0x20, %rcx
jne 0x169685
movq %rax, %rcx
jmp 0x1696d6
movq %r14, %rdx
subq %rax, %rdx
movq %r14, %rcx
cmpq $0x2, %rdx
jl 0x1696d6
movq %rax, %rcx
cmpq %r14, %rcx
jge 0x1696b8
movl (%rbp,%rcx,8), %edx
movq (%rsp), %rsi
movq (%rsi), %rsi
imulq $0x28, %rdx, %rdx
movl 0x14(%rsi,%rdx), %edx
movl %edx, 0x4(%rbp,%rcx,8)
incq %rcx
jmp 0x169697
leaq (,%rax,8), %rdi
addq %rbp, %rdi
leaq (,%r14,8), %rsi
addq %rbp, %rsi
callq 0x156b0d
movq %r14, %rcx
incq %r14
movq %rcx, %rax
jmp 0x169664
movq %r13, 0x70(%rsp)
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%r15)
jae 0x169742
movq 0x18(%rsp), %rax
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x10(%r15)
movq (%r15), %rdi
imulq $0x28, %rcx, %rsi
callq 0x2370
movq %rax, (%r15)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%r15)
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rsp), %rdx
movq (%rdx), %rdi
cmpq %rcx, %r12
je 0x16978a
movl (%rbp,%rcx,8), %edx
imulq $0x28, %rdx, %rdx
movq (%r15), %rsi
movq 0x20(%rdi,%rdx), %r8
movq %r8, 0x20(%rsi,%rax)
movupd (%rdi,%rdx), %xmm0
movupd 0x10(%rdi,%rdx), %xmm1
movupd %xmm1, 0x10(%rsi,%rax)
movupd %xmm0, (%rsi,%rax)
incq %rcx
addq $0x28, %rax
jmp 0x16974a
movq %r15, 0x10(%rsp)
movq (%r15), %rsi
imulq $0x28, 0x18(%rsp), %rdx
callq 0x2160
incq 0x60(%rsp)
xorpd %xmm0, %xmm0
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x169c4e
xorl %r14d, %r14d
movq 0x70(%rsp), %r13
cmpq %r13, %r14
je 0x1699d1
movq (%rsp), %rax
movq (%rax), %r12
imulq $0x28, %r14, %rbx
leaq (%r12,%rbx), %r13
leaq 0x90(%rsp), %rdi
movq %r13, %rsi
callq 0x16bf75
movl 0x8(%r12,%rbx), %esi
xorl $0x1, %esi
movq 0x38(%rsp), %rdi
callq 0x15d450
movslq 0x14(%r12,%rbx), %rcx
addq %rax, %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x120(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0x60(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movq %r14, 0x50(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x16bfa0
movq %rax, %rbp
movslq 0x1c(%r12,%rbx), %rbx
imulq $0x28, %rax, %r12
pushq $-0x1
popq %rax
movq %rax, 0x48(%rsp)
testq %rbp, %rbp
js 0x16992d
movq (%rsp), %rax
movq (%rax), %r14
movl 0x18(%r14,%r12), %ecx
subl $-0x80, %ecx
movl 0x14(%r13), %eax
cmpl %eax, %ecx
jle 0x16992d
cmpl %eax, 0x14(%r14,%r12)
jge 0x169921
leaq (%r14,%r12), %rsi
leaq 0xac(%rsp), %r15
movq %r15, %rdi
callq 0x16bf75
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x28(%rsp), %r9
callq 0x3d261
movl 0x8(%r13), %edx
movl 0x8(%r14,%r12), %ecx
cmpl %ecx, %edx
je 0x169921
xorl $0x1, %edx
xorl $0x1, %ecx
movq 0x58(%rsp), %rdi
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %r8
movsd 0x40(%rsp), %xmm0
movq %rax, %r9
leaq 0x88(%rsp), %rax
pushq %rax
pushq $0x0
callq 0x1631f5
popq %rcx
popq %rdx
testq %rax, %rax
je 0x169921
movslq 0x1c(%r13), %rax
movq 0x138(%rsp), %rcx
addq (%rcx,%rbp,8), %rax
cmpq %rbx, %rax
cmovgq %rax, %rbx
movq 0x48(%rsp), %rax
cmovgq %rbp, %rax
movq %rax, 0x48(%rsp)
decq %rbp
addq $-0x28, %r12
jmp 0x169855
movq 0x138(%rsp), %rax
movq 0x50(%rsp), %r14
movq %rbx, (%rax,%r14,8)
movq 0x48(%rsp), %rdx
movq %rdx, %rax
testq %rdx, %rdx
pushq $-0x1
popq %rcx
cmovsq %rcx, %rax
movq 0x140(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
js 0x1699ac
movl 0x8(%r13), %ebp
xorl $0x1, %ebp
movq (%rsp), %r14
movq (%r14), %rax
imulq $0x28, %rdx, %rbx
movl 0x8(%rax,%rbx), %edx
xorl $0x1, %edx
movq 0x38(%rsp), %rdi
movl %ebp, %esi
callq 0x1664de
movq %rax, %r12
andb $0x7f, 0x7(%r13)
movl %ebp, %edi
callq 0x15cdd5
movl %eax, %ebp
movq (%r14), %rax
movq 0x50(%rsp), %r14
movl 0x8(%rax,%rbx), %edi
xorl $0x1, %edi
callq 0x15cdd5
addl %ebp, %eax
jmp 0x1699b9
andb $0x7f, 0x7(%r13)
xorl %eax, %eax
pushq $-0x1
popq %rcx
movl %ecx, %r12d
movl %r12d, 0x20(%r13)
movl %eax, 0x24(%r13)
incq %r14
jmp 0x1697b9
xorl %r13d, %r13d
jmp 0x16a1ea
movq 0x130(%rsp), %r14
movq 0x18(%rsp), %rbp
cmpq %rbp, 0x8(%r14)
jae 0x169a3b
leaq -0x1(%rbp), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %r12
movq %rax, 0x10(%r14)
jmp 0x169a3f
movq 0x10(%r14), %r12
movq 0x10(%rsp), %rbx
movq 0x148(%rsp), %r15
leaq 0x8(%rsp), %rax
leaq 0x30(%rsp), %r10
movq %r13, %rdi
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
movq 0x128(%rsp), %rcx
movq %r12, %r8
movq %r15, %r9
pushq %rax
pushq %r10
callq 0x184cdc
addq $0x10, %rsp
movq %rbp, %rcx
subq %r13, %rcx
xorl %eax, %eax
testq %rcx, %rcx
cmovgq %rcx, %rax
imulq $0x28, %r13, %rcx
addq $0x1c, %rcx
subq $0x1, %rax
jb 0x169ade
movq (%rsp), %rsi
movq (%rsi), %rsi
movl (%rsi,%rcx), %esi
shlq $0x20, %rsi
incq %rsi
movq 0x30(%rsp), %rdi
leaq 0x1(%rdi), %r8
movq %r8, 0x30(%rsp)
movq %rsi, (%r12,%rdi,8)
movq 0x8(%rsp), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x8(%rsp)
movq %r13, (%r15,%rsi,8)
addq $0x28, %rcx
incq %r13
jmp 0x169a9a
andq $0x0, 0x8(%rbx)
movq 0x8(%rsp), %rax
cmpq %rax, 0x10(%rbx)
jae 0x169b38
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
imulq $0x28, %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
andq $0x0, (%r14)
movq 0x30(%rsp), %rdx
xorl %eax, %eax
testq %rdx, %rdx
movl $0x0, %ecx
movq %rdx, 0x28(%rsp)
cmovgq %rdx, %rcx
leaq -0x8(%r15), %rsi
pushq $-0x1
popq %r13
movq %r13, %rdi
xorl %r8d, %r8d
cmpq %rcx, %r8
je 0x169c04
movslq (%r12,%r8,8), %r9
testq %r9, %r9
movl $0x0, %r10d
cmovgq %r9, %r10
imulq $0x28, %rax, %r11
negq %r10
shlq $0x3, %r9
leaq (%r9,%rax,8), %rbx
addq %rsi, %rbx
xorl %r9d, %r9d
cmpq %r9, %r10
je 0x169bd8
movq (%rsp), %rdx
movq (%rdx), %r14
imulq $0x28, (%rbx,%r9,8), %r15
movq 0x10(%rsp), %rdx
movq (%rdx), %rbp
movq 0x20(%r14,%r15), %rdx
movq %rdx, 0x20(%rbp,%r11)
movupd (%r14,%r15), %xmm0
movupd 0x10(%r14,%r15), %xmm1
movupd %xmm1, 0x10(%rbp,%r11)
movupd %xmm0, (%rbp,%r11)
decq %r9
addq $0x28, %r11
jmp 0x169b91
movl 0x4(%r12,%r8,8), %edx
cmpq %rdx, %rdi
cmovleq %rdx, %rdi
movq %r13, %r10
cmovlq %r8, %r10
testq %r13, %r13
cmovsq %r8, %r10
cmovsq %rdx, %rdi
incq %r8
subq %r9, %rax
movq %r10, %r13
jmp 0x169b62
cmpq 0x8(%rsp), %rax
jne 0x16a21e
movq 0x130(%rsp), %rax
movq 0x28(%rsp), %rsi
movq %rsi, (%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rdx
movq %r12, %rdi
callq 0x16c091
testq %rax, %rax
je 0x169c4e
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rsi
imulq $0x28, 0x8(%rsp), %rdx
jmp 0x16a1e5
movq 0x130(%rsp), %r14
andq $0x0, (%r14)
movsd 0x7963e(%rip), %xmm1    # 0x1e32a0
movsd 0x68(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm2
movss %xmm2, 0x48(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x78(%rsp)
xorl %r15d, %r15d
pushq $-0x1
popq %rdi
movq 0x70(%rsp), %r13
cmpq %r13, %r15
je 0x169f93
movq (%rsp), %rax
movq (%rax), %r12
imulq $0x28, %r15, %rbx
leaq (%r12,%rbx), %rbp
movl 0x8(%r12,%rbx), %esi
xorl $0x1, %esi
movq %rdi, %r14
movq 0x38(%rsp), %rdi
callq 0x15d450
movslq 0x14(%r12,%rbx), %rcx
addq %rax, %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x120(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0x60(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movq %r15, 0x50(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x16bfa0
movq 0x20(%rsp), %rdi
andq $0x0, 0x8(%rdi)
movq %rax, %r13
imulq $0x28, %rax, %r15
movq %r14, %rbx
testq %r13, %r13
js 0x169df0
movq (%rsp), %rax
movq (%rax), %r14
movl 0x14(%r14,%r15), %eax
cmpl 0x14(%rbp), %eax
jge 0x169de4
leaq (%r14,%r15), %rdx
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x16c018
testq %rax, %rax
js 0x169ddf
movq %rax, %r12
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
jne 0x169d88
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rdi)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
imulq $0x30, %rcx, %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movl 0x8(%r14,%r15), %edx
xorl $0x1, %edx
movl %edx, (%rax,%rcx)
movl %r13d, %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, 0xc(%rax,%rcx)
movl 0x14(%rbp), %esi
subl 0x18(%r14,%r15), %esi
movl %esi, 0x10(%rax,%rcx)
movl %r12d, 0x4(%rax,%rcx)
movl %edx, 0xc(%rax,%rcx)
cmpq %r12, %rbx
cmovleq %r12, %rbx
jmp 0x169de4
movq 0x20(%rsp), %rdi
decq %r13
addq $-0x28, %r15
jmp 0x169d11
movslq 0x1c(%rbp), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x169f36
cvtsi2sd %rbx, %xmm0
mulsd 0x78(%rsp), %xmm0
cvttsd2si %xmm0, %r9
movq 0x120(%rsp), %rax
cmpq %rax, %r9
cmovleq %rax, %r9
movl 0x8(%rbp), %edx
xorl $0x1, %edx
movq (%rdi), %r8
subq $0x8, %rsp
xorpd %xmm0, %xmm0
movq 0x88(%rsp), %rdi
movq 0x40(%rsp), %rsi
pushq $0x0
pushq $0x1
pushq $0x0
pushq 0x120(%rsp)
pushq 0x150(%rsp)
pushq 0x160(%rsp)
pushq $0xf
callq 0x168290
movq 0x60(%rsp), %rsi
addq $0x40, %rsp
xorl %r15d, %r15d
pushq $-0x1
popq %rdi
movq %rdi, %rbx
pushq $-0x1
popq %rax
movl %eax, 0x40(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x58(%rsp)
xorl %r14d, %r14d
cmpq 0x8(%rsi), %r14
jge 0x169f28
movq (%rsi), %r12
testl $0x7fffffff, 0x14(%r12,%r15) # imm = 0x7FFFFFFF
je 0x169f1c
leaq (%r12,%r15), %rdi
movq (%rsp), %rax
movq (%rax), %rdx
movq %rbp, %rsi
movq 0x138(%rsp), %rcx
movq 0x120(%rsp), %r8
movss 0x48(%rsp), %xmm0
movss 0x7dde0(%rip), %xmm1    # 0x1e7cb0
callq 0x1a2f00
pushq $-0x1
popq %rdi
movq 0x20(%rsp), %rsi
cltq
testl %eax, %eax
setns %cl
cmpq %rax, 0x28(%rsp)
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x169f1c
movl 0xc(%r12,%r15), %r13d
movl 0x1c(%r12,%r15), %ecx
movl %ecx, 0x40(%rsp)
movl %r13d, %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
movl 0x24(%r12,%r15), %ecx
movl %ecx, 0x58(%rsp)
shrl $0x1f, %r13d
movq %rax, 0x28(%rsp)
incq %r14
addq $0x30, %r15
jmp 0x169e8c
shll $0x1f, %r13d
movl 0x40(%rsp), %edx
movl 0x58(%rsp), %esi
jmp 0x169f44
xorl %r13d, %r13d
pushq $-0x1
popq %rdi
movq %rdi, %rbx
pushq $-0x1
popq %rdx
xorl %esi, %esi
movq 0x138(%rsp), %rax
movq 0x50(%rsp), %r15
movq 0x28(%rsp), %rcx
movq %rcx, (%rax,%r15,8)
testq %rbx, %rbx
cmovsq %rdi, %rbx
movq 0x140(%rsp), %rax
movq %rbx, (%rax,%r15,8)
movl %edx, 0x20(%rbp)
movl %esi, 0x24(%rbp)
movl 0x4(%rbp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
orl %r13d, %eax
movl %eax, 0x4(%rbp)
incq %r15
movq 0x130(%rsp), %r14
jmp 0x169c82
movq 0x18(%rsp), %rbp
cmpq %rbp, 0x8(%r14)
jae 0x169ff5
leaq -0x1(%rbp), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %r15
movq %rax, 0x10(%r14)
jmp 0x169ff9
movq 0x10(%r14), %r15
movq 0x10(%rsp), %rbx
movq 0x148(%rsp), %r12
leaq 0x8(%rsp), %rax
leaq 0x30(%rsp), %r10
movq %r13, %rdi
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
movq 0x128(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
pushq %rax
pushq %r10
callq 0x184cdc
addq $0x10, %rsp
subq %r13, %rbp
xorl %eax, %eax
testq %rbp, %rbp
cmovgq %rbp, %rax
imulq $0x28, %r13, %rcx
addq $0x1c, %rcx
subq $0x1, %rax
jb 0x16a095
movq (%rsp), %rdx
movq (%rdx), %rdx
movl (%rdx,%rcx), %edx
shlq $0x20, %rdx
incq %rdx
movq 0x30(%rsp), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x30(%rsp)
movq %rdx, (%r15,%rsi,8)
movq 0x8(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rsp)
movq %r13, (%r12,%rdx,8)
addq $0x28, %rcx
incq %r13
jmp 0x16a051
andq $0x0, 0x8(%rbx)
movq 0x8(%rsp), %rax
cmpq %rax, 0x10(%rbx)
jae 0x16a0ef
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
imulq $0x28, %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
andq $0x0, (%r14)
movq 0x30(%rsp), %rcx
xorl %eax, %eax
testq %rcx, %rcx
movl $0x0, %edx
movq %rcx, 0x20(%rsp)
cmovgq %rcx, %rdx
addq $-0x8, %r12
movq %r12, %rcx
pushq $-0x1
popq %r13
movq %r13, %rsi
xorl %edi, %edi
cmpq %rdx, %rdi
je 0x16a1bb
movslq (%r15,%rdi,8), %r8
testq %r8, %r8
movl $0x0, %r9d
cmovgq %r8, %r9
imulq $0x28, %rax, %r10
negq %r9
shlq $0x3, %r8
leaq (%r8,%rax,8), %r11
addq %rcx, %r11
xorl %r8d, %r8d
cmpq %r8, %r9
je 0x16a18f
movq (%rsp), %rbx
movq (%rbx), %rbx
imulq $0x28, (%r11,%r8,8), %r14
movq 0x10(%rsp), %r12
movq (%r12), %r12
movq 0x20(%rbx,%r14), %rbp
movq %rbp, 0x20(%r12,%r10)
movups (%rbx,%r14), %xmm0
movupd 0x10(%rbx,%r14), %xmm1
movupd %xmm1, 0x10(%r12,%r10)
movups %xmm0, (%r12,%r10)
decq %r8
addq $0x28, %r10
jmp 0x16a14a
movl 0x4(%r15,%rdi,8), %r9d
cmpq %r9, %rsi
cmovleq %r9, %rsi
movq %r13, %r10
cmovlq %rdi, %r10
testq %r13, %r13
cmovsq %rdi, %r10
cmovsq %r9, %rsi
incq %rdi
subq %r8, %rax
movq %r10, %r13
jmp 0x16a11b
cmpq 0x8(%rsp), %rax
jne 0x16a1ff
movq 0x130(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rcx, (%rdx)
movq (%rsp), %rcx
movq (%rcx), %rdi
movq 0x10(%rsp), %rcx
movq (%rcx), %rsi
imulq $0x28, %rax, %rdx
callq 0x2160
movq %r13, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x87b33(%rip), %rdi     # 0x1f1d39
leaq 0x87916(%rip), %rsi     # 0x1f1b23
leaq 0x8a197(%rip), %rcx     # 0x1f43ab
movl $0x38fb, %edx           # imm = 0x38FB
callq 0x2110
leaq 0x87b14(%rip), %rdi     # 0x1f1d39
leaq 0x878f7(%rip), %rsi     # 0x1f1b23
leaq 0x8a178(%rip), %rcx     # 0x1f43ab
movl $0x3878, %edx           # imm = 0x3878
callq 0x2110