// File: /workspace/github_cpp_makefile_star2_O3/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, 0x38(%rsp)
movsd %xmm0, 0x60(%rsp)
movq %r9, 0x18(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, 0x78(%rsp)
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x8(%rcx), %r15
testq %r15, %r15
je 0x1b268a
movq %r8, %r14
movq 0x128(%rsp), %r13
movq %rdx, 0x40(%rsp)
movq 0x18(%rdx), %rdx
movq %rcx, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
jle 0x1b2691
movq (%rcx), %rax
movq 0x20(%rdx), %rcx
addq $0x20, %rax
xorl %edx, %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x18(%rax), %edi
shrl %edi
movl (%rcx,%rdi,8), %edi
andl %esi, %edi
cmpl %edi, -0x10(%rax)
jge 0x1b25c4
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x0, -0x14(%rax)
setg %dil
setle %r8b
shlq $0x3f, %rdi
jmp 0x1b25cc
movl $0x1, %r8d
xorl %edi, %edi
addq %r8, %r12
movl -0x8(%rax), %r8d
shlq $0x20, %r8
orq %rdx, %rdi
orq %r8, %rdi
movq %rdi, (%r13,%rdx,8)
incq %rdx
addq $0x28, %rax
cmpq %rdx, %r15
jne 0x1b2598
leaq (,%r15,8), %rsi
addq %r13, %rsi
movq %r13, %rdi
callq 0x19dd99
movl $0x1, %ebx
xorl %eax, %eax
cmpq %r15, %rbx
je 0x1b2622
movq (%r13,%rax,8), %rcx
xorq (%r13,%rbx,8), %rcx
shrq $0x20, %rcx
jne 0x1b2622
movq %rax, %rcx
jmp 0x1b2679
movq %rbx, %rdx
subq %rax, %rdx
movq %rbx, %rcx
cmpq $0x2, %rdx
jl 0x1b2679
cmpq %rax, %rbx
jle 0x1b265b
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, %rdx
movl (%r13,%rdx,8), %esi
leaq (%rsi,%rsi,4), %rsi
movl 0x14(%rcx,%rsi,8), %esi
movl %esi, 0x4(%r13,%rdx,8)
incq %rdx
cmpq %rdx, %rbx
jne 0x1b2641
leaq (,%rax,8), %rdi
addq %r13, %rdi
leaq (,%rbx,8), %rsi
addq %r13, %rsi
callq 0x19dd99
movq %rbx, %rcx
leaq 0x1(%rbx), %rdx
movq %rcx, %rax
cmpq %r15, %rbx
movq %rdx, %rbx
jne 0x1b2608
jmp 0x1b26a7
xorl %ebp, %ebp
jmp 0x1b3500
leaq (,%r15,8), %rsi
addq %r13, %rsi
movq %r13, %rdi
callq 0x19dd99
xorl %r12d, %r12d
cmpq %r15, 0x10(%r14)
jae 0x1b2701
leaq -0x1(%r15), %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(%r14)
movq (%r14), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%r14)
movq %r12, 0x48(%rsp)
movq %r15, 0x8(%r14)
testq %r15, %r15
movq 0x8(%rsp), %r9
jle 0x1b2753
xorl %eax, %eax
xorl %ecx, %ecx
movq (%r9), %rdx
movl (%r13,%rcx,8), %esi
leaq (%rsi,%rsi,4), %rsi
movq (%r14), %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, %r15
jne 0x1b2718
movq 0x120(%rsp), %rbx
movq 0x110(%rsp), %rax
movq %rax, 0x70(%rsp)
movq (%r9), %rdi
movq %r14, 0x20(%rsp)
movq (%r14), %rsi
movq %r15, 0x68(%rsp)
leaq (,%r15,8), %rax
leaq (%rax,%rax,4), %rdx
callq 0x2160
xorpd %xmm0, %xmm0
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x1b2dea
movq 0x48(%rsp), %r12
testq %r12, %r12
movq 0x8(%rsp), %r8
movq 0x28(%rsp), %r14
jle 0x1b2b0e
movq 0x110(%rsp), %rax
incq %rax
movq %rax, 0x80(%rsp)
xorl %r13d, %r13d
movq (%r8), %rsi
leaq (,%r13,4), %rax
addq %r13, %rax
movl 0x8(%rsi,%rax,8), %ecx
movl %ecx, %edx
shrl %edx
movl %edx, 0xb0(%rsp)
shll $0x1f, %ecx
movl 0xbc(%rsp), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %edx
orl %ecx, %edx
movl %edx, 0xbc(%rsp)
movq 0xc(%rsi,%rax,8), %rcx
movq %rcx, 0xb4(%rsp)
movq 0x14(%rsi,%rax,8), %rcx
movq %rcx, 0xa8(%rsp)
movl 0x8(%rsi,%rax,8), %edx
xorq $0x1, %rdx
movq 0x28(%r14), %rdi
movq (%rdi,%rdx,8), %rdi
movq %rdi, %rdx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rdx
je 0x1b2882
movq 0x8(%r14), %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 0x1b285c
movl %r9d, %edx
jmp 0x1b2884
xorl %edx, %edx
movq %rcx, %xmm0
movd %xmm0, %ecx
movslq %ecx, %rcx
addq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
leaq (%rsi,%rax,8), %rbp
mulsd 0x60(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
cmpq %rbx, %rdx
cmovleq %rbx, %rdx
addq %rcx, %rdx
movq 0x80(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movq %r13, %rdi
callq 0x1b5673
movslq 0x1c(%rbp), %r15
testq %rax, %rax
js 0x1b2ac3
movq %rax, %r12
movq %r13, 0x58(%rsp)
leaq (%rax,%rax,4), %r13
incq %r13
movq $-0x1, %rbx
movq 0x8(%rsp), %r8
movq (%r8), %r14
movl 0x10(%r14,%r13,8), %ecx
subl $-0x80, %ecx
movl 0x14(%rbp), %eax
cmpl %eax, %ecx
jle 0x1b29f8
cmpl %eax, 0xc(%r14,%r13,8)
jge 0x1b29e3
movl (%r14,%r13,8), %eax
movl %eax, %ecx
shrl %ecx
movl %ecx, 0x94(%rsp)
shll $0x1f, %eax
movl 0xa0(%rsp), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, 0xa0(%rsp)
movq 0x4(%r14,%r13,8), %rax
movq %rax, 0x98(%rsp)
movq 0xc(%r14,%r13,8), %rax
movq %rax, 0x8c(%rsp)
leaq 0xa4(%rsp), %rdi
leaq 0x88(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x40(%rsp), %r9
callq 0x6ea22
movl 0x8(%rbp), %edx
movl (%r14,%r13,8), %ecx
cmpl %ecx, %edx
je 0x1b29de
xorl $0x1, %edx
xorl $0x1, %ecx
movq 0x50(%rsp), %rdi
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %r8
movsd 0x38(%rsp), %xmm0
movq %rax, %r9
leaq 0xc0(%rsp), %rax
pushq %rax
pushq $0x0
callq 0x1ab640
addq $0x10, %rsp
testq %rax, %rax
je 0x1b29de
movslq 0x1c(%rbp), %rax
movq 0x138(%rsp), %rcx
addq (%rcx,%r12,8), %rax
cmpq %r15, %rax
cmovgq %rax, %r15
cmovgq %r12, %rbx
movq 0x8(%rsp), %r8
leaq -0x1(%r12), %rax
addq $-0x5, %r13
testq %r12, %r12
movq %rax, %r12
jg 0x1b28f6
movq 0x138(%rsp), %rax
movq 0x58(%rsp), %r13
movq %r15, (%rax,%r13,8)
movq %rbx, %rax
testq %rbx, %rbx
movq $-0x1, %rcx
cmovsq %rcx, %rax
movq 0x140(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x28(%rsp), %r14
js 0x1b2ae4
movl 0x8(%rbp), %r15d
xorl $0x1, %r15d
movq (%r8), %rax
shlq $0x3, %rbx
leaq (%rbx,%rbx,4), %rbx
movl 0x8(%rax,%rbx), %edx
xorl $0x1, %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0x1af06e
movq 0x8(%rsp), %r8
andb $0x7f, 0x7(%rbp)
movl %r15d, %ecx
shll $0xf, %ecx
notl %ecx
addl %r15d, %ecx
movl %ecx, %edx
shrl $0xa, %edx
xorl %ecx, %edx
leal (%rdx,%rdx,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
movq (%r8), %rdx
movl 0x8(%rdx,%rbx), %edx
xorl $0x1, %edx
movl %edx, %esi
shll $0xf, %esi
notl %esi
addl %edx, %esi
movl %esi, %edx
shrl $0xa, %edx
xorl %esi, %edx
leal (%rdx,%rdx,8), %edx
movl %edx, %esi
shrl $0x6, %esi
xorl %edx, %esi
movl %esi, %edi
shll $0xb, %edi
notl %edi
addl %esi, %edi
movl %edi, %edx
shrl $0x10, %edx
xorl %edi, %edx
addl %ecx, %edx
jmp 0x1b2aef
movq 0x138(%rsp), %rax
movq %r15, (%rax,%r13,8)
movq 0x140(%rsp), %rax
movq $-0x1, (%rax,%r13,8)
movq 0x8(%rsp), %r8
andb $0x7f, 0x7(%rbp)
xorl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x20(%rbp)
movl %edx, 0x24(%rbp)
incq %r13
movq 0x48(%rsp), %r12
cmpq %r12, %r13
movq 0x120(%rsp), %rbx
jne 0x1b27cb
movq 0x130(%rsp), %rdx
movq 0x68(%rsp), %r15
cmpq %r15, 0x8(%rdx)
movq 0x20(%rsp), %rbx
movq 0x128(%rsp), %r13
jae 0x1b2b88
leaq -0x1(%r15), %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 %rdx, %r14
movq 0x10(%rdx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %rbp
movq %rax, 0x10(%r14)
jmp 0x1b2b8c
movq 0x10(%rdx), %rbp
movq 0x148(%rsp), %r14
leaq 0x10(%rsp), %rax
leaq 0x30(%rsp), %r10
movq %r12, %rdi
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
movq %r13, %rcx
movq %rbp, %r8
movq %r14, %r9
pushq %rax
pushq %r10
callq 0x1d0e81
addq $0x10, %rsp
cmpq %r12, %r15
movq %rbp, %r13
jle 0x1b2c1e
movq 0x8(%rsp), %rax
movq (%rax), %rax
leaq (%r12,%r12,4), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x1c, %rax
movl (%rax), %edx
shlq $0x20, %rdx
incq %rdx
movq 0x30(%rsp), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x30(%rsp)
movq %rdx, (%r13,%rsi,8)
movq 0x10(%rsp), %rsi
leaq 0x1(%rsi), %rdx
movq %rdx, 0x10(%rsp)
movq %r12, (%r14,%rsi,8)
incq %r12
addq $0x28, %rax
cmpq %r12, %r15
jne 0x1b2be2
jmp 0x1b2c23
movq 0x10(%rsp), %rdx
movq $0x0, 0x8(%rbx)
cmpq %rdx, 0x10(%rbx)
jae 0x1b2c84
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq 0x8(,%rax,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
jle 0x1b2d87
leaq -0x8(%r14), %rax
movq %rax, 0x38(%rsp)
movq $-0x1, %rdx
xorl %edi, %edi
xorl %eax, %eax
movq $-0x1, %r8
movq 0x120(%rsp), %rbx
movq 0x20(%rsp), %rcx
movq 0x8(%rsp), %r12
movq (%r13,%rdi,8), %r9
movslq %r9d, %r10
testq %r10, %r10
jle 0x1b2d57
movq %r13, %rsi
movq %r10, %r9
negq %r9
leaq (,%rax,8), %r11
shlq $0x3, %r10
leaq (%r10,%rax,8), %r10
addq 0x38(%rsp), %r10
leaq (%r11,%r11,4), %rbx
xorl %r11d, %r11d
movq (%r12), %r14
movq (%r10,%r11,8), %r15
leaq (%r15,%r15,4), %r15
movq (%rcx), %r13
movq 0x20(%r14,%r15,8), %rbp
movq %rbp, 0x20(%r13,%rbx)
movupd (%r14,%r15,8), %xmm0
movupd 0x10(%r14,%r15,8), %xmm1
movupd %xmm1, 0x10(%r13,%rbx)
movupd %xmm0, (%r13,%rbx)
decq %r11
addq $0x28, %rbx
cmpq %r11, %r9
jne 0x1b2d05
movq %rsi, %r13
movq (%rsi,%rdi,8), %r9
subq %r11, %rax
movq 0x120(%rsp), %rbx
shrq $0x20, %r9
cmpq %r9, %rdx
cmovleq %r9, %rdx
movq %r8, %rbp
cmovlq %rdi, %rbp
testq %r8, %r8
cmovsq %rdi, %rbp
cmovsq %r9, %rdx
incq %rdi
movq %rbp, %r8
cmpq 0x40(%rsp), %rdi
jne 0x1b2cd3
jmp 0x1b2d98
movq $-0x1, %rbp
xorl %eax, %eax
movq 0x120(%rsp), %rbx
cmpq 0x10(%rsp), %rax
jne 0x1b3534
movq 0x130(%rsp), %rax
movq 0x40(%rsp), %rsi
movq %rsi, (%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq %r13, %rdi
callq 0x1b576d
testq %rax, %rax
je 0x1b2dea
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x10(%rsp), %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
jmp 0x1b34fb
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x48(%rsp), %r13
testq %r13, %r13
movq 0x8(%rsp), %r9
movq 0x138(%rsp), %r14
jle 0x1b325c
incq 0x70(%rsp)
movsd 0x7e4ef(%rip), %xmm1    # 0x231310
movsd 0x60(%rsp), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x40(%rsp)
xorl %edi, %edi
movq (%r9), %rsi
leaq (%rdi,%rdi,4), %rax
movl 0x8(%rsi,%rax,8), %ecx
xorq $0x1, %rcx
movq 0x28(%rsp), %r8
movq 0x28(%r8), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rcx
je 0x1b2eaf
movq 0x8(%r8), %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 %r11d, %r11d
xorl %r8d, %r8d
movl %r8d, %r9d
movl (%rdx,%r11), %r10d
cmpl %r10d, %r8d
movl %r10d, %r8d
cmoval %r9d, %r8d
testl %r10d, %r10d
cmovsl %r9d, %r8d
addq $0x18, %r11
cmpq %r11, %rcx
jne 0x1b2e89
movl %r8d, %ecx
jmp 0x1b2eb1
xorl %ecx, %ecx
leaq (%rsi,%rax,8), %rbp
movslq 0x14(%rbp), %rax
addq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x60(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
cmpq %rbx, %rdx
cmovleq %rbx, %rdx
addq %rax, %rdx
movq 0x70(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movq %rdi, 0x38(%rsp)
callq 0x1b5673
movq 0x18(%rsp), %r8
movq $0x0, 0x8(%r8)
testq %rax, %rax
js 0x1b31d7
movq %rax, %r15
shlq $0x3, %rax
leaq (%rax,%rax,4), %r13
movq $-0x1, %rbx
movq 0x8(%rsp), %r9
movq (%r9), %r14
movl 0x14(%r14,%r13), %eax
cmpl 0x14(%rbp), %eax
jge 0x1b2ff9
leaq (%r14,%r13), %rdx
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x1b56f4
testq %rax, %rax
js 0x1b2fef
movq %rax, %r12
movq 0x18(%rsp), %r8
movq (%r8), %rax
movq 0x8(%r8), %rcx
cmpq 0x10(%r8), %rcx
jne 0x1b2f8f
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r8)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq 0x18(%rsp), %r8
movq %rax, (%r8)
movq 0x8(%r8), %rcx
movq 0x8(%rsp), %r9
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r8)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movl 0x8(%r14,%r13), %edx
xorl $0x1, %edx
movl %edx, (%rax,%rcx)
movl %r15d, %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, 0xc(%rax,%rcx)
movl 0x14(%rbp), %esi
subl 0x18(%r14,%r13), %esi
movl %esi, 0x10(%rax,%rcx)
movl %r12d, 0x4(%rax,%rcx)
movl %edx, 0xc(%rax,%rcx)
cmpq %r12, %rbx
cmovleq %r12, %rbx
jmp 0x1b2ff9
movq 0x8(%rsp), %r9
movq 0x18(%rsp), %r8
leaq -0x1(%r15), %rax
addq $-0x28, %r13
testq %r15, %r15
movq %rax, %r15
jg 0x1b2f1f
movq 0x8(%r8), %rcx
movslq 0x1c(%rbp), %r15
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq $-0x1, %r12
testq %rcx, %rcx
je 0x1b31f3
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
mulsd 0x58(%rsp), %xmm0
cvttsd2si %xmm0, %r9
movq 0x120(%rsp), %rbx
cmpq %rbx, %r9
cmovleq %rbx, %r9
movl 0x8(%rbp), %edx
xorl $0x1, %edx
movq 0x18(%rsp), %rax
movq (%rax), %r8
subq $0x8, %rsp
xorl %eax, %eax
xorpd %xmm0, %xmm0
movq 0x80(%rsp), %rdi
movq 0x30(%rsp), %rsi
pushq %rax
pushq $0x1
pushq %rax
pushq 0x120(%rsp)
pushq 0x150(%rsp)
pushq 0x160(%rsp)
pushq $0xf
callq 0x1b100b
movq 0x58(%rsp), %rax
addq $0x40, %rsp
movq 0x8(%rax), %rcx
testq %rcx, %rcx
movq 0x138(%rsp), %r14
jle 0x1b3209
movq (%rax), %rdx
addq $0x24, %rdx
movq $-0x1, %r12
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x50(%rsp)
testl $0x7fffffff, -0x10(%rdx) # imm = 0x7FFFFFFF
je 0x1b31c0
movl -0x20(%rdx), %r8d
movl -0x8(%rdx), %esi
movl %esi, %r9d
subl %r8d, %r9d
movl %r9d, %edi
negl %edi
cmovsl %r9d, %edi
xorps %xmm1, %xmm1
cvtsi2ss %edi, %xmm1
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
mulss 0x40(%rsp), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1b3115
cmpq %rbx, %rdi
jg 0x1b31c0
movaps %xmm1, %xmm0
mulss 0x82c90(%rip), %xmm0    # 0x235db0
xorps %xmm2, %xmm2
cmpl $0x2, %edi
jb 0x1b3173
movd %xmm1, %edi
movl %edi, %r8d
shrl $0x17, %r8d
addl $-0x80, %r8d
xorps %xmm1, %xmm1
cvtsi2ss %r8, %xmm1
andl $0x7fffff, %edi         # imm = 0x7FFFFF
orl $0x3f800000, %edi       # imm = 0x3F800000
movd %edi, %xmm3
movdqa %xmm3, %xmm2
mulss 0x8ca45(%rip), %xmm2    # 0x23fba0
addss 0x8ca41(%rip), %xmm2    # 0x23fba4
mulss %xmm3, %xmm2
addss 0x8ca39(%rip), %xmm2    # 0x23fba8
addss %xmm1, %xmm2
addss %xmm2, %xmm0
movl 0x1c(%rbp), %r9d
cvttss2si %xmm0, %edi
subl %edi, %r9d
movl -0x18(%rdx), %edi
movl %edi, %r8d
andl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
addl (%r14,%r8,8), %r9d
movslq %r9d, %r9
testl %r9d, %r9d
setns %r10b
cmpq %r9, %r15
setl %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0x1b31c0
movl (%rdx), %eax
shrl $0x1f, %edi
movq %r9, %r15
movq %r8, %r12
movl %esi, %r13d
movq %rdi, 0x50(%rsp)
addq $0x30, %rdx
decq %rcx
jne 0x1b30cf
movq 0x50(%rsp), %rdx
shll $0x1f, %edx
jmp 0x1b31ec
movslq 0x1c(%rbp), %r15
xorl %edx, %edx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq $-0x1, %r12
xorl %eax, %eax
movq 0x8(%rsp), %r9
jmp 0x1b3212
xorl %edx, %edx
xorl %eax, %eax
movq 0x138(%rsp), %r14
movq 0x120(%rsp), %rbx
jmp 0x1b3212
xorl %eax, %eax
movq 0x8(%rsp), %r9
xorl %edx, %edx
movq 0x38(%rsp), %rdi
movq %r15, (%r14,%rdi,8)
testq %r12, %r12
movq $-0x1, %rcx
cmovsq %rcx, %r12
movq 0x140(%rsp), %rcx
movq %r12, (%rcx,%rdi,8)
movl %r13d, 0x20(%rbp)
movl %eax, 0x24(%rbp)
movl 0x4(%rbp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
orl %edx, %eax
movl %eax, 0x4(%rbp)
incq %rdi
movq 0x48(%rsp), %r13
cmpq %r13, %rdi
jne 0x1b2e3d
movq 0x130(%rsp), %rdx
movq 0x68(%rsp), %r15
cmpq %r15, 0x8(%rdx)
movq 0x20(%rsp), %rbx
movq 0x128(%rsp), %rbp
jae 0x1b32de
leaq -0x1(%r15), %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 %rdx, %r14
movq 0x10(%rdx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %r12
movq %rax, 0x10(%r14)
movq 0x138(%rsp), %r14
jmp 0x1b32e2
movq 0x10(%rdx), %r12
leaq 0x10(%rsp), %rax
leaq 0x30(%rsp), %r10
movq %r13, %rdi
movq %r14, %rsi
movq 0x140(%rsp), %rdx
movq %rbp, %rcx
movq %r12, %r8
movq 0x148(%rsp), %r14
movq %r14, %r9
pushq %rax
pushq %r10
callq 0x1d0e81
addq $0x10, %rsp
cmpq %r13, %r15
jle 0x1b3372
movq 0x8(%rsp), %rax
movq (%rax), %rax
leaq (,%r13,4), %rcx
addq %r13, %rcx
leaq (%rax,%rcx,8), %rax
addq $0x1c, %rax
movl (%rax), %ecx
shlq $0x20, %rcx
incq %rcx
movq 0x30(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x30(%rsp)
movq %rcx, (%r12,%rdx,8)
movq 0x10(%rsp), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x10(%rsp)
movq %r13, (%r14,%rdx,8)
incq %r13
addq $0x28, %rax
cmpq %r13, %r15
jne 0x1b3337
jmp 0x1b3377
movq 0x10(%rsp), %rcx
movq $0x0, 0x8(%rbx)
cmpq %rcx, 0x10(%rbx)
jae 0x1b33d8
decq %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq 0x8(,%rax,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x130(%rsp), %rax
movq $0x0, (%rax)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
jle 0x1b34c3
addq $-0x8, %r14
movq %r14, 0x28(%rsp)
movq $-0x1, %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq $-0x1, %rdi
movq 0x8(%rsp), %rax
movq (%r12,%rsi,8), %r8
movslq %r8d, %r9
testq %r9, %r9
jle 0x1b3493
movq %r9, %r8
negq %r8
leaq (,%rcx,8), %r10
shlq $0x3, %r9
leaq (%r9,%rcx,8), %r9
addq 0x28(%rsp), %r9
leaq (%r10,%r10,4), %r11
xorl %r10d, %r10d
movq 0x20(%rsp), %rbp
movq (%rax), %rbx
movq (%r9,%r10,8), %r14
leaq (%r14,%r14,4), %r14
movq (%rbp), %r15
movq 0x20(%rbx,%r14,8), %r13
movq %r13, 0x20(%r15,%r11)
movupd (%rbx,%r14,8), %xmm0
movupd 0x10(%rbx,%r14,8), %xmm1
movupd %xmm1, 0x10(%r15,%r11)
movupd %xmm0, (%r15,%r11)
decq %r10
addq $0x28, %r11
cmpq %r10, %r8
jne 0x1b344d
movq (%r12,%rsi,8), %r8
subq %r10, %rcx
shrq $0x20, %r8
cmpq %r8, %rdx
cmovleq %r8, %rdx
movq %rdi, %rbp
cmovlq %rsi, %rbp
testq %rdi, %rdi
cmovsq %rsi, %rbp
cmovsq %r8, %rdx
incq %rsi
movq %rbp, %rdi
cmpq 0x18(%rsp), %rsi
jne 0x1b341a
jmp 0x1b34cc
movq $-0x1, %rbp
xorl %ecx, %ecx
cmpq 0x10(%rsp), %rcx
jne 0x1b3515
movq 0x130(%rsp), %rax
movq 0x18(%rsp), %rdx
movq %rdx, (%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax), %rsi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rdx
callq 0x2160
movq %rbp, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8c955(%rip), %rdi     # 0x23fe71
leaq 0x8c738(%rip), %rsi     # 0x23fc5b
leaq 0x8efb9(%rip), %rcx     # 0x2424e3
movl $0x38fb, %edx           # imm = 0x38FB
callq 0x2110
leaq 0x8c936(%rip), %rdi     # 0x23fe71
leaq 0x8c719(%rip), %rsi     # 0x23fc5b
leaq 0x8ef9a(%rip), %rcx     # 0x2424e3
movl $0x3878, %edx           # imm = 0x3878
callq 0x2110