// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: gl_chain_refine_advance(overlap_region_alloc*, Correct_dumy*, haplotype_evdience_alloc*, glchain_t*, st_mt_t*, ul_idx_t const*, double, long, long, ug_opt_t const*, long, void*)
int64_t gl_chain_refine_advance(overlap_region_alloc* olist, Correct_dumy* dumy, haplotype_evdience_alloc *hap, glchain_t *ll, st_mt_t *sps, const ul_idx_t *uref, double diff_ec_ul, int64_t winLen, int64_t qlen, const ug_opt_t *uopt, 
int64_t debug_i, void *km)
{
	// ll->tk.n = ll->lo.n = 0;
	kv_ul_ov_t *idx = &(ll->lo);
	ul_contain *ct = uref->ct;
	uint64_t o2 = gl_chain_gen(olist, uref, idx, 0, hap, km);
	if(idx->n == 0) return 0;
	// fprintf(stderr, "[M::%s] qlen:%ld, idx->n:%u\n", __func__, qlen, (uint32_t)idx->n);
	uint64_t k, an, cn, si = 0, ei = 0, resc = 0, resc_tk = 0, tk_pl = 0, f = 0, occ = 0, cis_occ = 0, t_cis = 0;
	ma_utg_t *u = NULL; overlap_region *o = NULL;

	kv_resize_km(km, uint64_t, ll->srt.a, idx->n);
    kv_resize_km(km, uint64_t, hap->snp_srt, idx->n);
	kv_resize_km(km, ul_ov_t, ll->tk, ll->tk.n+idx->n);
	///note: there are three rounds of gl_chain_advance()
	///the first two rounds could reuse dumy->overlapID. But for the last round, dumy->overlapID is not long enough 
	occ = gl_chain_advance(idx, ll->tk.a+ll->tk.n, uref, uopt, G_CHAIN_BW, diff_ec_ul, qlen, UG_SKIP, dumy->overlapID, ll->srt.a.a, hap->snp_srt.a, G_CHAIN_TRANS_WEIGHT, 0, NULL, uref->ug, debug_i, km);
	if(occ) {
		if(ff_chain(idx, qlen, P_CHAIN_COV, -1/**G_CHAIN_TRANS_RATE**/, ll->tk.a+ll->tk.n, NULL, NULL, NULL, diff_ec_ul, winLen, km)) {
			f = 1; //dump_chain(idx, ll->tk.a+ll->tk.n, &(idx->a[idx->n-1]), km); 
			for (k = idx->a[idx->n-1].ts; k < idx->a[idx->n-1].te; k++) {
				olist->list[ll->tk.a[ll->tk.n+k].qn].x_pos_strand = 1;
			}
		} else if(o2) {///means there are trans overlaps
			gl_chain_gen(olist, uref, idx, 1, hap, km);
			kv_resize_km(km, uint64_t, ll->srt.a, idx->n);
    		kv_resize_km(km, uint64_t, hap->snp_srt, idx->n);
			kv_resize_km(km, ul_ov_t, ll->tk, ll->tk.n+idx->n);
			///chain all U-matches
			occ = gl_chain_advance(idx, ll->tk.a+ll->tk.n, uref, uopt, G_CHAIN_BW, diff_ec_ul, qlen, UG_SKIP, dumy->overlapID, ll->srt.a.a, hap->snp_srt.a, G_CHAIN_TRANS_WEIGHT, 0, NULL, uref->ug, debug_i, km);
			if(ff_chain(idx, qlen, P_CHAIN_COV, G_CHAIN_TRANS_RATE, ll->tk.a+ll->tk.n, olist, hap, uref, diff_ec_ul, winLen, km)) {
				f = 1; //dump_chain(idx, ll->tk.a+ll->tk.n, &(idx->a[idx->n-1]), km); 
				for (k = idx->a[idx->n-1].ts; k < idx->a[idx->n-1].te; k++) {
					olist->list[ll->tk.a[ll->tk.n+k].qn].x_pos_strand = 1;
				}
			}
		}
	}

	if(!f) {///if f == 1, only dump primary chain; otherwise dump all chains
		///we can save all data to buffer like ll->srt.a in advance; in case we don't need third round of chaining
		///means no trans overlaps, no need to do third round of chaining
		// if(!o2) {
		// 	;
		// }
		/**
		uint64_t z;
		for (k = 0; k < idx->n; k++) {
			if(check_trans_rate(ll->tk.a+ll->tk.n+idx->a[k].ts, idx->a[k].te-idx->a[k].ts, G_CHAIN_TRANS_RATE)) {
				for (z = idx->a[k].ts; z < idx->a[k].te; z++) {
					olist->list[ll->tk.a[ll->tk.n+z].qn].x_pos_strand = 1;
				}
			} else {
				for (z = idx->a[k].ts; z < idx->a[k].te; z++) {
					if(!(ll->tk.a[ll->tk.n+z].el)) continue;
					olist->list[ll->tk.a[ll->tk.n+z].qn].x_pos_strand = 1;
				}
			}	
		}
		**/
		for (k = 0; k < occ; k++) {
			olist->list[ll->tk.a[ll->tk.n+k].qn].x_pos_strand = 1;
		}
		// kv_resize_km(km, ul_ov_t, *idx, occ); idx->n = occ;
		// memcpy(idx->a, ll->tk.a+ll->tk.n, occ*sizeof((*(idx->a))));
	}
	// for (k = 0; k < idx->n; k++) olist->list[idx->a[k].qn].x_pos_strand = 1;
		
	for (k = 0, idx->n = 0, tk_pl = ll->tk.n, t_cis = 0; k < olist->length; k++) {
		o = &(olist->list[k]);
		///if f == 1, no matter 
		if(o->x_pos_strand && (f || o->is_match == 1)){
			u = &(uref->ug->u.a[o->y_id]);///overlaped reads
			resc_tk += rescue_trans_ul_chains(uref, o, NULL, 0, u, &(ll->tk), -1, -1, 0, NULL, km);
		} else if((!f) && o->is_match == 2) {
			// fprintf(stderr, "###[M::%s] # k:%lu, # o->y_id:%u\n", __func__, k, o->y_id);
			an = update_ava_het_site(hap, k, &si, &ei, 1);
			// if(an != get_het_site(hap, k)) fprintf(stderr, "an->%lu, get_het_site->%lu\n", an, get_het_site(hap, k));
			assert(an > 0);

			cn = ((uint32_t)(ct->idx.a[o->y_id]));		
			if(cn > 0) {
				resc += rescue_contain_ul_chains(uref, o, hap->list+si, an, 
				ct->rids.a + ((ct->idx.a[o->y_id])>>32), cn, idx, diff_ec_ul, winLen, 0, km);
			}

			u = &(uref->ug->u.a[o->y_id]);
			if(u->n > 1 || o->x_pos_strand) {///no redundant items here
				resc_tk += rescue_trans_ul_chains(uref, o, hap->list+si, an, u, 
				&(ll->tk), diff_ec_ul, winLen, o->x_pos_strand, &cis_occ, km);
				t_cis += cis_occ;
			}

			si = ei;
		} 
	}

	assert(ll->tk.n == resc_tk+tk_pl);
	assert(idx->n == resc);
	if(f) assert(resc==0);

		
	if(!f) {///dedup contained alignments
		if(idx->n) {///if some contained alignments have been rescued
			radix_sort_ul_ov_srt_tn(idx->a, idx->a + idx->n);
			idx->n = dedup_sort_ul_ov_t(idx->a, idx->n);///different trans alignments may have the same contained alignment
		}
		resc = idx->n;
		// fprintf(stderr, "***[M::%s] # contain:%lu, # non-contain:%lu\n", __func__, resc, (uint64_t)(ll->tk.n-tk_pl));
		for (k = tk_pl; k < ll->tk.n; k++) {///dump all non-contained reads
			kv_push_km(km, ul_ov_t, *idx, ll->tk.a[k]);
			if(idx->a[idx->n-1].tn&((uint32_t)(0x80000000))) {
				idx->a[idx->n-1].tn -= ((uint32_t)(0x80000000));
			}
		}
		ll->tk.n = tk_pl;

		radix_sort_ul_ov_srt_qe(idx->a, idx->a + idx->n);
		if(resc) {///need to dedup contained alignment again
			// fprintf(stderr, "[M::%s] idx->n:%lu, resc:%lu\n", __func__, (uint64_t)idx->n, resc);
			idx->n = dedup_sort_contains(idx->a, idx->n, ct, uopt);
		}
		
		///note: need sps for third round of gl_chain_advance() as dumy->overlapID might be not long enough
		kv_resize_km(km, uint64_t, *sps, idx->n);
		kv_resize_km(km, uint64_t, ll->srt.a, idx->n);
		kv_resize_km(km, uint64_t, hap->snp_srt, idx->n);
		kv_resize_km(km, ul_ov_t, ll->tk, ll->tk.n+idx->n);
		occ = gl_chain_advance(idx, ll->tk.a+ll->tk.n, uref, uopt, G_CHAIN_BW, diff_ec_ul, qlen, UG_SKIP, sps->a, ll->srt.a.a, hap->snp_srt.a, G_CHAIN_TRANS_WEIGHT, 1, &R_INF, NULL, debug_i, km);
		// fprintf(stderr, "***[M::%s] ll->tk.n:%u, occ:%lu\n", __func__, (uint32_t)ll->tk.n, occ);
		f = dump_all_chain_simple(idx, &(ll->tk), occ, qlen, P_CHAIN_COV, P_FRAGEMENT_CHAIN_COV, 
		P_FRAGEMENT_PRIMARY_CHAIN_COV, 0.1/**P_FRAGEMENT_PRIMARY_SECOND_COV**/, G_CHAIN_TRANS_RATE, PRIMARY_UL_CHAIN_MIN);
		// fprintf(stderr, ">>>[M::%s] ll->tk.n:%u\n", __func__, (uint32_t)ll->tk.n);
		// dump_all_chain(idx, &(ll->tk), occ, qlen, P_CHAIN_COV, P_CHAIN_SCORE);
	} else {
		///for primary chain, each element x: (x->tn & (uint32_t)(0x80000000))
		assgin_primary_chains(ll->tk.a+tk_pl, ll->tk.n-tk_pl, 1, NULL, NULL, NULL, NULL, G_CHAIN_BW, diff_ec_ul, qlen, 1);
		// radix_sort_ul_ov_srt_qe(ll->tk.a+tk_pl, ll->tk.a+ll->tk.n);
	} 

	///if f == 0, results have already been sorted by qe|qs
	if(f) {
		kv_resize_km(km, uint64_t, ll->srt.a, ll->tk.n-tk_pl); kv_resize_km(km, uint64_t, hap->snp_srt, ll->tk.n-tk_pl);
		assgin_primary_chains(ll->tk.a+tk_pl, ll->tk.n-tk_pl, 0, uref, uopt, ll->srt.a.a, hap->snp_srt.a, G_CHAIN_BW, diff_ec_ul, qlen, 1);
	}
	// debug_reverse_chain(ll->tk.a+tk_pl, ll->tk.n-tk_pl);
	/**
	if(idx->n > 0) {
		an = infer_read_ovlp(uref, olist, idx	, &(ll->tk), diff_ec_ul, winLen, uopt, ct, km);
		// if(an) fill_edge_weight(ll->tk.a+ll->tk.n-an, an, uopt, G_CHAIN_BW, diff_ec_ul, qlen);
	}
	**/
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm0, 0x18(%rsp)
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %r8
movq %rsi, %r15
movq 0xd0(%rsp), %rbp
movq 0x20(%r9), %rax
movq %rax, 0x60(%rsp)
xorl %ebx, %ebx
movq %rdi, 0x10(%rsp)
movq %r9, 0x20(%rsp)
movq %r9, %rsi
movq %rcx, %rdx
xorl %ecx, %ecx
movq %r8, 0x8(%rsp)
movq %rbp, %r9
callq 0x1a8167
movq %rax, %r12
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x1aefe0
xorl %ecx, %ecx
movq %rcx, 0x40(%rsp)
movq %rcx, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
cmpq %rax, 0x50(%r13)
movq %r14, 0x50(%rsp)
jae 0x1ae2ff
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, 0x50(%r13)
movq 0x58(%r13), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x58(%r13)
movq 0x8(%r13), %rax
movq 0x20(%rsp), %rbx
movq 0x8(%rsp), %r14
cmpq %rax, 0x240(%r14)
jae 0x1ae373
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, 0x240(%r14)
movq 0x248(%r14), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x248(%r14)
movq 0x8(%r13), %rax
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rcx
addq %rcx, %rax
cmpq %rax, 0x28(%r13)
jae 0x1ae3e2
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, 0x28(%r13)
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rdx
incq %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, %rsi
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rcx
leaq 0x18(%r13), %rax
movq %rax, 0x30(%rsp)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rsi
addq %rax, %rsi
movq %r15, %r14
movq 0x28(%r15), %rax
movq 0x58(%r13), %rcx
movq 0x8(%rsp), %rdx
movq 0x248(%rdx), %rdx
movq (%rbx), %rdi
subq $0x50, %rsp
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq $-0x1, 0x20(%rsp)
movl $0x10, %r8d
movq %r13, %rdi
movq %rbx, %rdx
movq 0x110(%rsp), %rcx
movsd 0x68(%rsp), %xmm0
movq 0x108(%rsp), %r9
callq 0x1abd88
addq $0x50, %rsp
movq %rax, %r15
movq 0x20(%r13), %rax
movq %rax, (%rsp)
movb $0x1, %sil
testq %r15, %r15
je 0x1ae7cc
movq 0x8(%r13), %rdx
testq %rdx, %rdx
movq 0x10(%rsp), %rdi
je 0x1ae522
movq (%r13), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movl -0x14(%rax,%rcx), %edx
subl -0x18(%rax,%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
cvtsi2ssq 0xb8(%rsp), %xmm1
mulss 0x916f7(%rip), %xmm1    # 0x23fbb8
ucomiss %xmm0, %xmm1
jae 0x1ae522
addq %rcx, %rax
movl -0xc(%rax), %esi
movl -0x8(%rax), %eax
cmpl %eax, %esi
jae 0x1ae822
movq (%rdi), %rcx
subq %rsi, %rax
movq (%rsp), %r8
leaq (%r8,%r8,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %r8, %rdx
leaq (%rsi,%rsi,8), %r8
leaq (%r8,%r8,2), %r8
addq %rsi, %r8
addq 0x18(%r13), %rdx
addq %r8, %rdx
movq 0x8(%rsp), %r12
movl (%rdx), %esi
imulq $0xa8, %rsi, %rsi
movl $0x1, 0xc(%rcx,%rsi)
addq $0x1c, %rdx
decq %rax
jne 0x1ae503
jmp 0x1ae7c8
testq %r12, %r12
je 0x1ae7d8
movq %rbx, %rsi
movq %r13, %rdx
movl $0x1, %ecx
movq 0x8(%rsp), %r12
movq %r12, %r8
movq %rbp, %r9
callq 0x1a8167
movq 0x8(%r13), %rax
cmpq %rax, 0x50(%r13)
jae 0x1ae5a8
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, 0x50(%r13)
movq 0x58(%r13), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x58(%r13)
movq 0x8(%r13), %rax
cmpq %rax, 0x240(%r12)
jae 0x1ae616
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, 0x240(%r12)
movq 0x248(%r12), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x248(%r12)
movq 0x8(%r13), %rax
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rcx
addq %rcx, %rax
cmpq %rax, 0x28(%r13)
jae 0x1ae685
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, 0x28(%r13)
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rdx
incq %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, %rsi
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rcx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rsi
addq %rax, %rsi
movq 0x28(%r14), %rax
movq 0x58(%r13), %rcx
movq 0x248(%r12), %rdx
movq (%rbx), %rdi
subq $0x50, %rsp
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq $-0x1, 0x20(%rsp)
movl $0x10, %r8d
movq %r13, %rdi
movq %rbx, %rdx
movq 0x110(%rsp), %rcx
movsd 0x68(%rsp), %xmm0
movq 0x108(%rsp), %r14
movq %r14, %r9
callq 0x1abd88
addq $0x50, %rsp
movq %rax, %r15
movq 0x20(%r13), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rax, %rdx
addq 0x18(%r13), %rdx
movss 0x9149d(%rip), %xmm0    # 0x23fbb8
movss 0x91499(%rip), %xmm1    # 0x23fbbc
movq %r13, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rcx
movq %r12, %r8
movq %rbx, %r9
movsd 0x18(%rsp), %xmm2
pushq %rbp
pushq 0xb8(%rsp)
callq 0x1acef5
addq $0x10, %rsp
movq 0x20(%r13), %rcx
movq %rcx, (%rsp)
testl %eax, %eax
je 0x1ae7df
movq (%r13), %rax
movq 0x8(%r13), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl -0xc(%rax,%rdx), %esi
movl -0x8(%rax,%rdx), %eax
cmpl %eax, %esi
jae 0x1ae82b
movq 0x10(%rsp), %rdi
movq (%rdi), %rcx
subq %rsi, %rax
movq (%rsp), %r8
leaq (%r8,%r8,8), %rdx
leaq (%rdx,%rdx,2), %r9
addq %r8, %r9
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
addq %r9, %rdx
movq 0x30(%rsp), %rsi
addq (%rsi), %rdx
movl (%rdx), %esi
imulq $0xa8, %rsi, %rsi
movl $0x1, 0xc(%rcx,%rsi)
addq $0x1c, %rdx
decq %rax
jne 0x1ae7ae
xorl %esi, %esi
jmp 0x1ae837
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %rdi
jmp 0x1ae837
movq 0x8(%rsp), %r12
jmp 0x1ae7ec
testq %r15, %r15
je 0x1ae82f
movq 0x10(%rsp), %rdi
movb $0x1, %sil
movq (%rdi), %rax
movq (%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movq 0x30(%rsp), %rdx
addq (%rdx), %rcx
movl (%rcx), %edx
imulq $0xa8, %rdx, %rdx
movl $0x1, 0xc(%rax,%rdx)
addq $0x1c, %rcx
decq %r15
jne 0x1ae806
jmp 0x1ae837
xorl %esi, %esi
movq 0x8(%rsp), %r12
jmp 0x1ae837
xorl %esi, %esi
jmp 0x1ae7d1
movq 0x10(%rsp), %rdi
movb $0x1, %sil
movq $0x0, 0x8(%r13)
cmpq $0x0, 0x10(%rdi)
je 0x1aea7f
movq %r13, 0x58(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x48(%rsp)
movq $0x0, 0x38(%rsp)
xorl %r13d, %r13d
movl %esi, 0x2c(%rsp)
movq (%rdi), %r14
leaq (%r14,%rbp), %r15
cmpl $0x0, 0xc(%r14,%rbp)
je 0x1ae8ef
testb %sil, %sil
je 0x1ae887
movb 0x2c(%r14,%rbp), %al
cmpb $0x1, %al
jne 0x1ae8fd
movq (%rbx), %rax
movl 0x10(%r14,%rbp), %ecx
leaq (%rcx,%rcx,4), %r8
shlq $0x3, %r8
addq 0x10(%rax), %r8
subq $0x20, %rsp
movq 0xf0(%rsp), %rax
movq %rax, 0x18(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
movq $-0x1, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x50(%rsp), %r9
movsd 0x82d65(%rip), %xmm0    # 0x231638
callq 0x1a9863
movl 0x4c(%rsp), %esi
movq 0x30(%rsp), %rdi
addq $0x20, %rsp
addq %rax, 0x48(%rsp)
jmp 0x1aea4a
testb %sil, %sil
je 0x1aea4a
movb 0x2c(%r14,%rbp), %al
cmpb $0x2, %al
jne 0x1aea4a
movl $0x1, %r8d
movq %r12, %rdi
movq %r13, %rsi
leaq 0x40(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x1a7f4d
testq %rax, %rax
je 0x1aeff2
movq %rax, %rbx
movq 0x60(%rsp), %rsi
movq 0x10(%rsi), %rcx
movl 0x10(%r14,%rbp), %eax
movq (%rcx,%rax,8), %rcx
movq %rcx, %r9
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %r9
je 0x1ae9ac
movq 0x40(%rsp), %rax
leaq (%rax,%rax,2), %rdx
shlq $0x3, %rdx
addq (%r12), %rdx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r8
shlq $0x2, %r8
addq 0x28(%rsi), %r8
movq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rcx
movsd 0x18(%rsp), %xmm0
pushq 0xd0(%rsp)
pushq $0x0
pushq 0xc0(%rsp)
pushq 0x70(%rsp)
callq 0x1a93d9
addq $0x20, %rsp
movq 0x38(%rsp), %rcx
addq %rax, %rcx
movl 0x10(%r14,%rbp), %eax
jmp 0x1ae9b6
movq 0x20(%rsp), %r12
movq 0x38(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq (%r12), %rcx
movq 0x10(%rcx), %rcx
leaq (%rax,%rax,4), %rdx
cmpl $0x1, 0x10(%rcx,%rdx,8)
movl 0xc(%r14,%rbp), %eax
ja 0x1ae9de
testl %eax, %eax
jne 0x1ae9de
movq 0x8(%rsp), %r12
jmp 0x1aea32
leaq (%rcx,%rdx,8), %r8
movq 0x40(%rsp), %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
movq 0x8(%rsp), %r12
addq (%r12), %rdx
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rcx
movq 0x30(%rsp), %r9
movsd 0x18(%rsp), %xmm0
pushq 0xd0(%rsp)
leaq 0x78(%rsp), %r10
pushq %r10
pushq %rax
pushq 0xc8(%rsp)
callq 0x1a9863
addq $0x20, %rsp
addq %rax, 0x48(%rsp)
movq 0x10(%rsp), %rdi
movl 0x2c(%rsp), %esi
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rbx
incq %r13
addq $0xa8, %rbp
cmpq 0x10(%rdi), %r13
jb 0x1ae86a
movq 0x58(%rsp), %r13
movq 0x20(%r13), %rax
movq 0xd0(%rsp), %rbp
movq (%rsp), %rcx
movq 0x48(%rsp), %rdx
movq 0x38(%rsp), %rdi
jmp 0x1aea8a
xorl %edi, %edi
movq (%rsp), %rcx
movq %rcx, %rax
xorl %edx, %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jne 0x1af011
cmpq %rdi, 0x8(%r13)
jne 0x1af030
testq %rdi, %rdi
sete %cl
orb %sil, %cl
je 0x1af04f
testb %sil, %sil
je 0x1aeaed
testq %rdi, %rdi
je 0x1aeb35
movq %rdi, %rcx
movq (%r13), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
addq %rdi, %rsi
callq 0x19e855
movq (%r13), %rdi
movq 0x8(%r13), %rsi
callq 0x1a9d8a
movq %rax, %r15
movq %rax, 0x8(%r13)
movq 0x20(%r13), %rax
jmp 0x1aeb38
movq (%rsp), %r14
leaq (%r14,%r14,8), %rax
movq %rdx, %rsi
leaq (%rax,%rax,2), %rdi
addq %r14, %rdi
movq 0x30(%rsp), %rax
addq (%rax), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movsd 0x18(%rsp), %xmm0
pushq $0x1
pushq 0xc0(%rsp)
pushq $0x10
pushq $0x0
callq 0x1adda0
addq $0x20, %rsp
jmp 0x1aeeba
xorl %r15d, %r15d
movq (%rsp), %r12
cmpq %rax, %r12
jae 0x1aebf3
movq (%r13), %rax
leaq (%r12,%r12,8), %rcx
leaq (%rcx,%rcx,2), %rbx
addq %r12, %rbx
movl $0x2, %r14d
movq %r15, %rsi
cmpq 0x10(%r13), %rsi
jne 0x1aeb90
leaq (%rsi,%rsi), %rcx
testq %rsi, %rsi
cmoveq %r14, %rcx
movq %rcx, 0x10(%r13)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x1ee21d
movq %rax, (%r13)
movq 0x8(%r13), %rsi
movq 0x18(%r13), %rcx
leaq 0x1(%rsi), %rdx
movq %rdx, 0x8(%r13)
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
movups (%rcx,%rbx), %xmm0
movups 0xc(%rcx,%rbx), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movq (%r13), %rax
movq 0x8(%r13), %rsi
leaq (%rsi,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rsi, %rcx
movl -0x10(%rax,%rcx), %edx
testl %edx, %edx
jns 0x1aebe0
addq %rax, %rcx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edx, -0x10(%rcx)
incq %r12
addq $0x1c, %rbx
cmpq 0x20(%r13), %r12
jb 0x1aeb5d
jmp 0x1aebfa
movq (%r13), %rax
movq %r15, %rsi
movq (%rsp), %rcx
movq %rcx, 0x20(%r13)
leaq (%rsi,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rsi
addq %rcx, %rsi
movq %rax, %rdi
callq 0x19e2b4
movq 0x8(%r13), %rax
testq %r15, %r15
je 0x1aec3e
movq (%r13), %rdi
movq %rax, %rsi
movq 0x60(%rsp), %rdx
movq 0xc0(%rsp), %rcx
callq 0x1ad266
movq %rax, 0x8(%r13)
movq 0x20(%rsp), %rbx
movq 0x8(%rsp), %r12
movq 0x50(%rsp), %r14
cmpq %rax, 0x8(%r14)
jae 0x1aecab
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, 0x8(%r14)
movq 0x10(%r14), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x10(%r14)
movq 0x8(%r13), %rax
cmpq %rax, 0x50(%r13)
jae 0x1aed09
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, 0x50(%r13)
movq 0x58(%r13), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x58(%r13)
movq 0x8(%r13), %rax
cmpq %rax, 0x240(%r12)
jae 0x1aed77
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, 0x240(%r12)
movq 0x248(%r12), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x248(%r12)
movq 0x8(%r13), %rax
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rcx
addq %rcx, %rax
cmpq %rax, 0x28(%r13)
jae 0x1aede6
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, 0x28(%r13)
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rdx
incq %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, %rsi
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rcx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rsi
addq %rax, %rsi
movq 0x10(%r14), %rax
movq 0x58(%r13), %rcx
movq 0x248(%r12), %rdx
subq $0x50, %rsp
leaq 0xe7421(%rip), %rdi     # 0x296230
movq %rdi, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x1, 0x28(%rsp)
movq $-0x1, 0x20(%rsp)
movl $0x10, %r8d
movq %r13, %rdi
movq %rbx, %rdx
movq 0x110(%rsp), %rcx
movsd 0x68(%rsp), %xmm0
movq 0x108(%rsp), %r14
movq %r14, %r9
callq 0x1abd88
addq $0x50, %rsp
movss 0x90d44(%rip), %xmm0    # 0x23fbb8
movss 0x86f44(%rip), %xmm1    # 0x235dc0
movss 0x90d3c(%rip), %xmm2    # 0x23fbc0
movss 0x86f24(%rip), %xmm3    # 0x235db0
movss 0x90d28(%rip), %xmm4    # 0x23fbbc
movl $0x124f8, %r8d          # imm = 0x124F8
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movq %rax, %rdx
movq %r14, %rcx
callq 0x1ad6bf
testq %rax, %rax
movq (%rsp), %r14
je 0x1aefdb
movq 0x20(%r13), %rsi
subq %r14, %rsi
cmpq %rsi, 0x50(%r13)
jae 0x1aef22
decq %rsi
movq %rsi, %rax
shrq %rax
orq %rsi, %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, 0x50(%r13)
movq 0x58(%r13), %rsi
leaq 0x8(,%rax,8), %rdx
movq %rbp, %rdi
callq 0x1ee21d
movq %rax, 0x58(%r13)
movq 0x20(%r13), %rsi
subq %r14, %rsi
movq 0x248(%r12), %rax
cmpq %rsi, 0x240(%r12)
jae 0x1aef9c
decq %rsi
movq %rsi, %rcx
shrq %rcx
orq %rsi, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x240(%r12)
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x1ee21d
movq %rax, 0x248(%r12)
movq 0x20(%r13), %rsi
movq (%rsp), %rdx
subq %rdx, %rsi
jmp 0x1aefa0
movq (%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rdx, %rdi
addq 0x18(%r13), %rdi
movq 0x58(%r13), %r9
xorl %edx, %edx
movq %rbx, %rcx
movq 0xc0(%rsp), %r8
movsd 0x18(%rsp), %xmm0
pushq $0x1
pushq 0xc0(%rsp)
pushq $0x10
pushq %rax
callq 0x1adda0
addq $0x20, %rsp
movl $0x1, %ebx
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x918ea(%rip), %rdi     # 0x2408e3
leaq 0x90c5b(%rip), %rsi     # 0x23fc5b
leaq 0x918e3(%rip), %rcx     # 0x2408ea
movl $0x113d, %edx           # imm = 0x113D
callq 0x2110
leaq 0x9199d(%rip), %rdi     # 0x2409b5
leaq 0x90c3c(%rip), %rsi     # 0x23fc5b
leaq 0x918c4(%rip), %rcx     # 0x2408ea
movl $0x1150, %edx           # imm = 0x1150
callq 0x2110
leaq 0x91998(%rip), %rdi     # 0x2409cf
leaq 0x90c1d(%rip), %rsi     # 0x23fc5b
leaq 0x918a5(%rip), %rcx     # 0x2408ea
movl $0x1151, %edx           # imm = 0x1151
callq 0x2110
leaq 0x91988(%rip), %rdi     # 0x2409de
leaq 0x90bfe(%rip), %rsi     # 0x23fc5b
leaq 0x91886(%rip), %rcx     # 0x2408ea
movl $0x1152, %edx           # imm = 0x1152
callq 0x2110