// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
movsd %xmm0, 0x58(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdi, 0xa8(%rsp)
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x8(%rcx), %r14
testq %r14, %r14
je 0x1a943f
movq %r8, %rbp
movq %r9, 0x50(%rsp)
movq 0x128(%rsp), %r12
movq %rdx, 0x30(%rsp)
movq 0x18(%rdx), %rdx
movq %rdx, 0x18(%rsp)
jle 0x1a9447
movq (%rcx), %rax
movq 0x20(%rdx), %r9
addq $0x20, %rax
xorl %edx, %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x18(%rax), %edi
shrl %edi
movl (%r9,%rdi,8), %edi
andl %esi, %edi
cmpl %edi, -0x10(%rax)
jge 0x1a9414
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x0, -0x14(%rax)
setg %dil
setle %r8b
shlq $0x3f, %rdi
jmp 0x1a941c
movl $0x1, %r8d
xorl %edi, %edi
addq %r8, %r15
movl -0x8(%rax), %r8d
shlq $0x20, %r8
orq %rdx, %rdi
orq %r8, %rdi
movq %rdi, (%r12,%rdx,8)
incq %rdx
addq $0x28, %rax
cmpq %rdx, %r14
jne 0x1a93e7
jmp 0x1a944a
xorl %r12d, %r12d
jmp 0x1aa314
xorl %r15d, %r15d
movq %rcx, 0x8(%rsp)
leaq (%r12,%r14,8), %rsi
movq %r12, %rdi
callq 0x194fef
testq %r14, %r14
jle 0x1a94e4
movl $0x1, %ebx
xorl %eax, %eax
cmpq %r14, %rbx
je 0x1a9483
movq (%r12,%rax,8), %rcx
xorq (%r12,%rbx,8), %rcx
shrq $0x20, %rcx
jne 0x1a9483
movq %rax, %rcx
jmp 0x1a94d5
movq %rbx, %rdx
subq %rax, %rdx
movq %rbx, %rcx
cmpq $0x2, %rdx
jl 0x1a94d5
cmpq %rax, %rbx
jle 0x1a94c5
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, %rdx
movl (%r12,%rdx,8), %esi
movq %rsi, (%r12,%rdx,8)
leaq (%rsi,%rsi,4), %rdi
movl 0x14(%rcx,%rdi,8), %edi
shlq $0x20, %rdi
orq %rsi, %rdi
movq %rdi, (%r12,%rdx,8)
incq %rdx
cmpq %rdx, %rbx
jne 0x1a94a2
leaq (%r12,%rax,8), %rdi
leaq (%r12,%rbx,8), %rsi
callq 0x194fef
movq %rbx, %rcx
leaq 0x1(%rbx), %rdx
movq %rcx, %rax
cmpq %r14, %rbx
movq %rdx, %rbx
jne 0x1a946b
movq %r15, 0x40(%rsp)
cmpq %r14, 0x10(%rbp)
jae 0x1a9545
leaq -0x1(%r14), %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, 0x10(%rbp)
movq (%rbp), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%rbp)
movq %r14, 0x8(%rbp)
testq %r14, %r14
movq 0x8(%rsp), %r9
jle 0x1a9592
xorl %eax, %eax
xorl %ecx, %ecx
movq (%r9), %rdx
movl (%r12,%rcx,8), %esi
leaq (%rsi,%rsi,4), %rsi
movq (%rbp), %rdi
movq 0x20(%rdx,%rsi,8), %r8
movq %r8, 0x20(%rdi,%rax)
movupd (%rdx,%rsi,8), %xmm0
movupd 0x10(%rdx,%rsi,8), %xmm1
movupd %xmm1, 0x10(%rdi,%rax)
movupd %xmm0, (%rdi,%rax)
incq %rcx
addq $0x28, %rax
cmpq %rcx, %r14
jne 0x1a9557
movq 0x110(%rsp), %rax
movq %rax, 0x68(%rsp)
movq (%r9), %rdi
movq (%rbp), %rsi
movq %r14, 0x48(%rsp)
leaq (,%r14,8), %rax
leaq (%rax,%rax,4), %rdx
callq 0x2160
xorpd %xmm0, %xmm0
movsd 0x28(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq %rbp, 0x38(%rsp)
jb 0x1a9c11
movq 0x40(%rsp), %r14
testq %r14, %r14
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rbx
movq 0x128(%rsp), %r15
movq 0x120(%rsp), %r8
jle 0x1a996d
movq 0x110(%rsp), %rax
incq %rax
movq %rax, 0xb0(%rsp)
xorl %r12d, %r12d
movq (%rdi), %rsi
leaq (%r12,%r12,4), %rax
movl 0x8(%rsi,%rax,8), %ecx
movl %ecx, %edx
shrl %edx
movl %edx, 0x98(%rsp)
shll $0x1f, %ecx
movl 0xa4(%rsp), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %edx
orl %ecx, %edx
movl %edx, 0xa4(%rsp)
movl 0xc(%rsi,%rax,8), %ecx
movl %ecx, 0x9c(%rsp)
movl 0x10(%rsi,%rax,8), %ecx
movl %ecx, 0xa0(%rsp)
movslq 0x14(%rsi,%rax,8), %rcx
movl %ecx, 0x90(%rsp)
movl 0x18(%rsi,%rax,8), %edx
movl %edx, 0x94(%rsp)
movl 0x8(%rsi,%rax,8), %edx
xorq $0x1, %rdx
movq 0x18(%rsp), %r9
movq 0x28(%r9), %rdi
movq (%rdi,%rdx,8), %rdi
movq %rdi, %rdx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
andq %r10, %rdx
je 0x1a96e3
movq 0x8(%r9), %r8
shrq $0x20, %rdi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdi,2), %rdi
leaq (%r8,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %r9d, %r10d
movl (%rdi,%r8), %r11d
cmpl %r11d, %r9d
movl %r11d, %r9d
cmoval %r10d, %r9d
testl %r11d, %r11d
cmovsl %r10d, %r9d
addq $0x18, %r8
cmpq %r8, %rdx
jne 0x1a96b5
movl %r9d, %edi
movq 0x120(%rsp), %r8
jmp 0x1a96e5
xorl %edi, %edi
addq %rcx, %rdi
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
leaq (%rsi,%rax,8), %rbp
mulsd 0x58(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
cmpq %r8, %rdx
cmovleq %r8, %rdx
addq %rdi, %rdx
movq 0xb0(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movq %r12, 0xb8(%rsp)
movq %r12, %rdi
callq 0x1ac3e0
movslq 0x1c(%rbp), %r13
testq %rax, %rax
js 0x1a985d
movq %rax, %r12
leaq (%rax,%rax,4), %r15
addq $0x3, %r15
movq $-0x1, %rbx
movq 0x8(%rsp), %rdi
movq (%rdi), %r14
movl (%r14,%r15,8), %ecx
subl $-0x80, %ecx
movl 0x14(%rbp), %eax
cmpl %eax, %ecx
jle 0x1a9869
cmpl %eax, -0x4(%r14,%r15,8)
jge 0x1a9846
movl -0x10(%r14,%r15,8), %eax
movl %eax, %ecx
shrl %ecx
movl %ecx, 0x7c(%rsp)
shll $0x1f, %eax
movl 0x88(%rsp), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, 0x88(%rsp)
movl -0xc(%r14,%r15,8), %eax
movl %eax, 0x80(%rsp)
movl -0x8(%r14,%r15,8), %eax
movl %eax, 0x84(%rsp)
movl -0x4(%r14,%r15,8), %eax
movl %eax, 0x74(%rsp)
movl (%r14,%r15,8), %eax
movl %eax, 0x78(%rsp)
leaq 0x8c(%rsp), %rdi
leaq 0x70(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x30(%rsp), %r9
callq 0x6f050
movl 0x8(%rbp), %edx
movl -0x10(%r14,%r15,8), %ecx
cmpl %ecx, %edx
je 0x1a9841
xorl $0x1, %edx
xorl $0x1, %ecx
movq 0x60(%rsp), %rdi
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %r8
movsd 0x28(%rsp), %xmm0
movq %rax, %r9
leaq 0xc0(%rsp), %rax
pushq %rax
pushq $0x0
callq 0x1a24f3
addq $0x10, %rsp
testq %rax, %rax
je 0x1a9841
movslq 0x1c(%rbp), %rax
movq 0x138(%rsp), %rcx
addq (%rcx,%r12,8), %rax
cmpq %r13, %rax
cmovgq %rax, %r13
cmovgq %r12, %rbx
movq 0x8(%rsp), %rdi
leaq -0x1(%r12), %rax
addq $-0x5, %r15
testq %r12, %r12
movq %rax, %r12
jg 0x1a974f
jmp 0x1a9869
movq $-0x1, %rbx
movq 0x8(%rsp), %rdi
movq 0x138(%rsp), %rax
movq 0xb8(%rsp), %r12
movq %r13, (%rax,%r12,8)
movq %rbx, %rax
testq %rbx, %rbx
movq $-0x1, %rcx
cmovsq %rcx, %rax
movq 0x140(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
js 0x1a9937
movl 0x8(%rbp), %r15d
xorl $0x1, %r15d
movq (%rdi), %rax
shlq $0x3, %rbx
leaq (%rbx,%rbx,4), %rbx
movl 0x8(%rax,%rbx), %edx
xorl $0x1, %edx
movq 0x18(%rsp), %rdi
movl %r15d, %esi
callq 0x1a5df0
movq 0x8(%rsp), %rdi
movl %eax, 0x20(%rbp)
andb $0x7f, 0x7(%rbp)
movl %r15d, %eax
shll $0xf, %eax
notl %eax
addl %r15d, %eax
movl %eax, %ecx
shrl $0xa, %ecx
xorl %eax, %ecx
leal (%rcx,%rcx,8), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %eax, %ecx
movl %ecx, %edx
shll $0xb, %edx
notl %edx
addl %ecx, %edx
movl %edx, %eax
shrl $0x10, %eax
xorl %edx, %eax
movq (%rdi), %rcx
movl 0x8(%rcx,%rbx), %ecx
xorl $0x1, %ecx
movl %ecx, %edx
shll $0xf, %edx
notl %edx
addl %ecx, %edx
movl %edx, %ecx
shrl $0xa, %ecx
xorl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
movl %ecx, %edx
shrl $0x6, %edx
xorl %ecx, %edx
movl %edx, %esi
shll $0xb, %esi
notl %esi
addl %edx, %esi
movl %esi, %ecx
shrl $0x10, %ecx
xorl %esi, %ecx
addl %eax, %ecx
jmp 0x1a9944
movl $0xffffffff, 0x20(%rbp) # imm = 0xFFFFFFFF
andb $0x7f, 0x7(%rbp)
xorl %ecx, %ecx
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %r14
movq 0x128(%rsp), %r15
movq 0x120(%rsp), %r8
movl %ecx, 0x24(%rbp)
incq %r12
cmpq %r14, %r12
jne 0x1a9613
movq 0x130(%rsp), %rdx
cmpq %rbx, 0x8(%rdx)
movq 0x148(%rsp), %r12
jae 0x1a99dd
leaq -0x1(%rbx), %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(%rdx)
movq 0x10(%rdx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x130(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq 0x10(%rdx), %rbp
leaq 0x10(%rsp), %rax
leaq 0x20(%rsp), %r10
movq %r14, %rdi
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r12, %r9
pushq %rax
pushq %r10
callq 0x1c6e58
addq $0x10, %rsp
cmpq %r14, %rbx
movq 0x8(%rsp), %r11
jle 0x1a9a66
movq (%r11), %rax
leaq (%r14,%r14,4), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x1c, %rax
movl (%rax), %edx
shlq $0x20, %rdx
incq %rdx
movq 0x20(%rsp), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x20(%rsp)
movq %rdx, (%rbp,%rsi,8)
movq 0x10(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x10(%rsp)
movq %r14, (%r12,%rdx,8)
incq %r14
addq $0x28, %rax
cmpq %r14, %rbx
jne 0x1a9a2c
movq 0x38(%rsp), %rcx
movq $0x0, 0x8(%rcx)
movq 0x10(%rsp), %rax
cmpq %rax, 0x10(%rcx)
jae 0x1a9adb
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
leaq 0x1(%rcx), %rax
movq 0x38(%rsp), %rbx
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, (%rbx)
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
jle 0x1a9bb7
leaq -0x8(%r12), %rax
movq %rax, 0x28(%rsp)
movq $-0x1, %rsi
xorl %edx, %edx
xorl %eax, %eax
movq $-0x1, %r12
movq 0x38(%rsp), %rcx
movslq (%rbp,%rdx,8), %r9
testq %r9, %r9
jle 0x1a9b91
movq %r9, %r8
negq %r8
leaq (,%rax,8), %r10
shlq $0x3, %r9
leaq (%r9,%rax,8), %r9
addq 0x28(%rsp), %r9
leaq (%r10,%r10,4), %r10
movq %r11, %rdi
xorl %r11d, %r11d
movq (%rdi), %rbx
movq (%r9,%r11,8), %r14
leaq (%r14,%r14,4), %r14
movq (%rcx), %r15
movq 0x20(%rbx,%r14,8), %r13
movq %r13, 0x20(%r15,%r10)
movupd (%rbx,%r14,8), %xmm0
movupd 0x10(%rbx,%r14,8), %xmm1
movupd %xmm1, 0x10(%r15,%r10)
movupd %xmm0, (%r15,%r10)
decq %r11
addq $0x28, %r10
cmpq %r11, %r8
jne 0x1a9b4d
subq %r11, %rax
movq %rdi, %r11
testq %r12, %r12
js 0x1a9ba0
movl 0x4(%rbp,%rdx,8), %r8d
cmpq %r8, %rsi
jge 0x1a9ba7
movl 0x4(%rbp,%rdx,8), %esi
movq %rdx, %r12
incq %rdx
cmpq 0x30(%rsp), %rdx
jne 0x1a9b1e
jmp 0x1a9bc0
movq $-0x1, %r12
xorl %eax, %eax
cmpq 0x10(%rsp), %rax
jne 0x1aa348
movq 0x130(%rsp), %rax
movq 0x30(%rsp), %rsi
movq %rsi, (%rax)
movq 0x38(%rsp), %rax
movq (%rax), %rdx
movq %rbp, %rdi
movq %rax, %rbp
callq 0x1ac4e1
testq %rax, %rax
je 0x1a9c11
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq (%rbp), %rsi
movq 0x10(%rsp), %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
jmp 0x1aa30f
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x40(%rsp), %r14
testq %r14, %r14
movq 0x8(%rsp), %r9
movq 0x120(%rsp), %r11
movq 0x18(%rsp), %r13
jle 0x1aa09a
incq 0x68(%rsp)
movsd 0x7b623(%rip), %xmm1    # 0x225270
movsd 0x58(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm2
movss %xmm2, 0x60(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
xorl %edi, %edi
movq (%r9), %rsi
leaq (%rdi,%rdi,4), %rax
movl 0x8(%rsi,%rax,8), %ecx
xorq $0x1, %rcx
movq 0x28(%r13), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rcx
je 0x1a9cd5
movq 0x8(%r13), %r8
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%r8,%rdx,8), %rdx
addq $0xc, %rdx
xorl %ebx, %ebx
xorl %r8d, %r8d
movl %r8d, %r9d
movl (%rdx,%rbx), %r10d
cmpl %r10d, %r8d
movl %r10d, %r8d
cmoval %r9d, %r8d
testl %r10d, %r10d
cmovsl %r9d, %r8d
addq $0x18, %rbx
cmpq %rbx, %rcx
jne 0x1a9caf
movl %r8d, %ecx
jmp 0x1a9cd7
xorl %ecx, %ecx
leaq (%rsi,%rax,8), %r12
movslq 0x14(%r12), %rax
addq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x58(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
cmpq %r11, %rdx
cmovleq %r11, %rdx
addq %rax, %rdx
movq 0x68(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movq %rdi, 0x30(%rsp)
callq 0x1ac3e0
movq %rax, %r15
movq 0x50(%rsp), %rax
movq $0x0, 0x8(%rax)
movsd 0x7b807(%rip), %xmm0    # 0x225538
testq %r15, %r15
movq 0x8(%rsp), %r9
js 0x1a9e63
movq %r15, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %r13
movq $-0x1, %rbx
movq (%r9), %r14
movl 0x14(%r14,%r13), %eax
cmpl 0x14(%r12), %eax
jge 0x1a9e42
leaq (%r14,%r13), %rdx
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1ac461
testq %rax, %rax
js 0x1a9e3d
movq %rax, %rbp
movq 0x50(%rsp), %rsi
movq 0x10(%rsi), %rax
cmpq %rax, 0x8(%rsi)
jne 0x1a9dbc
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsi)
movq (%rsi), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x50(%rsp), %rsi
movq %rax, (%rsi)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rsi)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movl 0xc(%rax,%rcx), %edx
movl %edx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %esi, 0xc(%rax,%rcx)
movl 0x8(%r14,%r13), %esi
xorl $0x1, %esi
movl %esi, (%rax,%rcx)
movl %r15d, %esi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
andl $0x40000000, %edx       # imm = 0x40000000
orl %esi, %edx
movl %edx, 0xc(%rax,%rcx)
movl 0x14(%r12), %edx
subl 0x18(%r14,%r13), %edx
movl %edx, 0x10(%rax,%rcx)
movl %ebp, 0x4(%rax,%rcx)
movl $0x0, 0x8(%rax,%rcx)
movl %esi, 0xc(%rax,%rcx)
cmpq %rbp, %rbx
cmovleq %rbp, %rbx
movq 0x8(%rsp), %r9
leaq -0x1(%r15), %rax
addq $-0x28, %r13
testq %r15, %r15
movq %rax, %r15
jg 0x1a9d51
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movq 0x18(%rsp), %r13
movslq 0x1c(%r12), %rbp
movq 0x50(%rsp), %r14
movq 0x8(%r14), %rcx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movq $-0x1, %r15
testq %rcx, %rcx
je 0x1aa019
mulsd 0x28(%rsp), %xmm0
cvttsd2si %xmm0, %r9
movq 0x120(%rsp), %rax
cmpq %rax, %r9
cmovleq %rax, %r9
movl 0x8(%r12), %edx
xorl $0x1, %edx
movq (%r14), %r8
subq $0x8, %rsp
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movq 0xb0(%rsp), %rdi
movq %r13, %rsi
pushq %rbx
pushq $0x1
pushq %rbx
pushq 0x120(%rsp)
pushq 0x150(%rsp)
pushq 0x160(%rsp)
pushq $0xf
callq 0x1a7dd4
addq $0x40, %rsp
movq 0x8(%r14), %rcx
testq %rcx, %rcx
jle 0x1aa027
movq (%r14), %rdx
addq $0x24, %rdx
movq $-0x1, %r10
xorl %eax, %eax
xorl %ebx, %ebx
movq $-0x1, %r15
movq 0x8(%rsp), %r9
movq 0x120(%rsp), %r11
movss 0x60(%rsp), %xmm4
movss 0x7fc92(%rip), %xmm5    # 0x229bb8
testl $0x7fffffff, -0x10(%rdx) # imm = 0x7FFFFFFF
je 0x1aa007
movl -0x20(%rdx), %esi
movl -0x8(%rdx), %r8d
subl %esi, %r8d
movl %r8d, %edi
negl %edi
cmovsl %r8d, %edi
xorps %xmm1, %xmm1
cvtsi2ss %edi, %xmm1
xorps %xmm0, %xmm0
cvtsi2ss %esi, %xmm0
mulss %xmm4, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1a9f67
movl $0x80000000, %esi       # imm = 0x80000000
cmpq %r11, %rdi
jg 0x1a9fe2
movaps %xmm1, %xmm0
mulss %xmm5, %xmm0
xorps %xmm2, %xmm2
cmpl $0x2, %edi
jb 0x1a9fbe
movd %xmm1, %esi
movl %esi, %edi
shrl $0x17, %edi
addl $-0x80, %edi
xorps %xmm1, %xmm1
cvtsi2ss %rdi, %xmm1
andl $0x7fffff, %esi         # imm = 0x7FFFFF
orl $0x3f800000, %esi       # imm = 0x3F800000
movd %esi, %xmm3
movdqa %xmm3, %xmm2
mulss 0x8992a(%rip), %xmm2    # 0x2338d0
addss 0x89926(%rip), %xmm2    # 0x2338d4
mulss %xmm3, %xmm2
addss 0x8991e(%rip), %xmm2    # 0x2338d8
addss %xmm1, %xmm2
addss %xmm2, %xmm0
movl 0x1c(%r12), %esi
cvttss2si %xmm0, %edi
subl %edi, %esi
movl -0x18(%rdx), %edi
andl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movq 0x138(%rsp), %r8
addl (%r8,%rdi,8), %esi
testl %esi, %esi
js 0x1aa007
movslq %esi, %rsi
cmpq %rsi, %rbp
jge 0x1aa007
movl -0x18(%rdx), %ebx
movl -0x8(%rdx), %r10d
movl %ebx, %r15d
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
movl (%rdx), %eax
shrl $0x1f, %ebx
movq %rsi, %rbp
addq $0x30, %rdx
decq %rcx
jne 0x1a9f26
shll $0x1f, %ebx
jmp 0x1aa03c
xorl %ebx, %ebx
xorl %eax, %eax
movq 0x120(%rsp), %r11
jmp 0x1aa03c
xorl %eax, %eax
movq 0x8(%rsp), %r9
movq 0x120(%rsp), %r11
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movq 0x138(%rsp), %rcx
movq 0x30(%rsp), %rdi
movq %rbp, (%rcx,%rdi,8)
testq %r15, %r15
movq $-0x1, %rcx
cmovsq %rcx, %r15
movq 0x140(%rsp), %rcx
movq %r15, (%rcx,%rdi,8)
movl %r10d, 0x20(%r12)
movl %eax, 0x24(%r12)
movl 0x4(%r12), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
orl %ebx, %eax
movl %eax, 0x4(%r12)
incq %rdi
movq 0x40(%rsp), %r14
cmpq %r14, %rdi
movq 0x38(%rsp), %rbp
jne 0x1a9c69
movq 0x130(%rsp), %rdx
movq 0x48(%rsp), %rbx
cmpq %rbx, 0x8(%rdx)
movq 0x128(%rsp), %r15
movq 0x148(%rsp), %r12
jae 0x1aa117
leaq -0x1(%rbx), %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(%rdx)
movq 0x10(%rdx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x130(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq 0x10(%rdx), %r13
leaq 0x10(%rsp), %rax
leaq 0x20(%rsp), %r10
movq %r14, %rdi
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
movq %r15, %rcx
movq %r13, %r8
movq %r12, %r9
pushq %rax
pushq %r10
callq 0x1c6e58
addq $0x10, %rsp
cmpq %r14, %rbx
movq 0x8(%rsp), %r11
jle 0x1aa1a0
movq (%r11), %rax
leaq (%r14,%r14,4), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x1c, %rax
movl (%rax), %ecx
shlq $0x20, %rcx
incq %rcx
movq 0x20(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x20(%rsp)
movq %rcx, (%r13,%rdx,8)
movq 0x10(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq %r14, (%r12,%rcx,8)
incq %r14
addq $0x28, %rax
cmpq %r14, %rbx
jne 0x1aa166
movq $0x0, 0x8(%rbp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x10(%rbp)
jae 0x1aa20d
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
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%rbp)
movq (%rbp), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, (%rbp)
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x20(%rsp), %rax
testq %rax, %rax
jle 0x1aa2e2
addq $-0x8, %r12
movq %r12, 0x18(%rsp)
movq $-0x1, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq $-0x1, %r12
movslq (%r13,%rdx,8), %r8
testq %r8, %r8
jle 0x1aa2bd
movq %r8, %rdi
negq %rdi
leaq (,%rcx,8), %r9
shlq $0x3, %r8
leaq (%r8,%rcx,8), %r8
addq 0x18(%rsp), %r8
leaq (%r9,%r9,4), %r9
xorl %r10d, %r10d
movq 0x8(%rsp), %r11
movq (%r11), %r11
movq (%r8,%r10,8), %rbx
leaq (%rbx,%rbx,4), %rbx
movq (%rbp), %r14
movq 0x20(%r11,%rbx,8), %r15
movq %r15, 0x20(%r14,%r9)
movupd (%r11,%rbx,8), %xmm0
movupd 0x10(%r11,%rbx,8), %xmm1
movq 0x8(%rsp), %r11
movupd %xmm1, 0x10(%r14,%r9)
movupd %xmm0, (%r14,%r9)
decq %r10
addq $0x28, %r9
cmpq %r10, %rdi
jne 0x1aa271
subq %r10, %rcx
testq %r12, %r12
js 0x1aa2cc
movl 0x4(%r13,%rdx,8), %edi
cmpq %rdi, %rsi
jge 0x1aa2d4
movl 0x4(%r13,%rdx,8), %esi
movq %rdx, %r12
incq %rdx
cmpq %rax, %rdx
jne 0x1aa245
jmp 0x1aa2eb
movq $-0x1, %r12
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
cmpq %rdx, %rcx
jne 0x1aa329
movq 0x130(%rsp), %rcx
movq %rax, (%rcx)
movq (%r11), %rdi
movq (%rbp), %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rdx
callq 0x2160
movq %r12, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x89871(%rip), %rdi     # 0x233ba1
leaq 0x89654(%rip), %rsi     # 0x23398b
leaq 0x8bed5(%rip), %rcx     # 0x236213
movl $0x38fb, %edx           # imm = 0x38FB
callq 0x2110
leaq 0x89852(%rip), %rdi     # 0x233ba1
leaq 0x89635(%rip), %rsi     # 0x23398b
leaq 0x8beb6(%rip), %rcx     # 0x236213
movl $0x3878, %edx           # imm = 0x3878
callq 0x2110