// File: chhylp123[P]hifiasm/inter.cpp
// Function: gl_chain_advance(kv_ul_ov_t*, ul_ov_t*, ul_idx_t const*, ug_opt_t const*, long, double, long, long, unsigned long*, unsigned long*, unsigned long*, long, unsigned long, All_reads*, ma_ug_t*, long, void*)
int64_t gl_chain_advance(kv_ul_ov_t *res, ul_ov_t *ex, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, int64_t qlen, int64_t max_skip, uint64_t *srt, uint64_t *idx, uint64_t *track, int64_t trans_sc, 
uint64_t mode, All_reads *ridx, ma_ug_t *ug, int64_t debug_i, void *km)
{
	// fprintf(stderr, "\n+++[M::%s] res->n:%u\n", __func__, (uint32_t)res->n);
	if(res->n == 0) return 0;
	uint32_t li_v, lj_v, rev_n;
	int64_t mm_ovlp, x, i, j, k, sc, csc, mm_sc, mm_idx, qo, share, n_el = 0;
	ul_ov_t *li = NULL, *lj = NULL, rev_t;
	radix_sort_ul_ov_srt_qe(res->a, res->a + res->n);
	for (i = 1, j = 0; i <= (int64_t)res->n; i++) {
        if (i == (int64_t)res->n || res->a[i].qe != res->a[j].qe) {
            if(i - j > 1) {
                radix_sort_ul_ov_srt_qs(res->a+j, res->a+i);
            }
            j = i;
        }
    }
	for (i = 0; i < (int64_t)res->n; ++i) {
		li = &(res->a[i]); li_v = (li->tn<<1)|li->rev;
		mm_ovlp = mode?max_ovlp_src(uopt, li_v^1):max_ovlp(uref->ug->g, li_v^1);		
		x = (li->qs + mm_ovlp)*diff_ec_ul; 
		if(x < bw) x = bw; 
		x += li->qs + mm_ovlp;
		if (x > qlen+1) x = qlen+1;
		x = find_ul_ov_max(i, res->a, x+G_CHAIN_INDEL); 
		if(li->el) csc = mode?retrieve_r_cov_region(uref, li->tn, 0, li->ts, li->te, NULL):retrieve_u_cov_region(uref, li->tn, 0, li->ts, li->te, NULL);
		else csc = (trans_sc*li->sec); //trans overlaps
		mm_sc = csc; mm_idx = -1; 
		// if(i == 37 || i == 36 || i == 35 || i == 32) fprintf(stderr, "*i:%ld, x:%ld, mm_sc:%ld\n", i, x, mm_sc);
		for (j = x; j >= 0; --j) { // collect potential destination vertices
			lj = &(res->a[j]); lj_v = (lj->tn<<1)|lj->rev;
			// if((lj->qe+gapLen) <= li->qs) break; 
			if(lj->qe+G_CHAIN_INDEL <= li->qs) break;//even this pair has a overlap, its length will be very small; just ignore
			// if(lj->qs >= li->qs+G_CHAIN_INDEL) continue; // lj is contained in li on the query coordinate; 128 for indel offset
			if(lj->qs >= li->qs) continue;
			qo = infer_rovlp(li, lj, NULL, NULL, ridx, ug); ///overlap length in query (UL read)
			// if(i == 37 || i == 36 || i == 35 || i == 32) fprintf(stderr, ">i:%ld, j:%ld, qo:%ld\n", i, j, qo);
			if(li_v != lj_v && get_ecov_adv(uref, uopt, li_v^1, lj_v^1, bw, diff_ec_ul, qo, mode, &share)) {
				// if(i == 37 || i == 36 || i == 35 || i == 32) fprintf(stderr, "#i:%ld, j:%ld, share:%ld\n", i, j, share);
				sc = csc + pop_sc(track[j]);
				// if((!mode)&&i==11&&j==10) {
				// 	fprintf(stderr,"+share:%ld, i:%ld, j:%ld, li_v^1:%u, lj_v^1:%u\n", 
				// 															share, i, j, li_v^1, lj_v^1);
				// }
				// if((mode&&i==21&&j==20) || (mode&&i==22&&j==21) || (mode&&i==23&&j==22)) {
				// 	fprintf(stderr,"-share:%ld, i:%ld, j:%ld, li_v^1:%u, lj_v^1:%u\n", 
				// 															share, i, j, li_v^1, lj_v^1);
				// }
				if(li->el && lj->el) sc -= (share>=csc?csc:share);///csc must be larger than 0
				// if((!li->el) && (!lj->el)) sc -= ((share>=o_csc?o_csc:share)*(-trans_scl));
				if(sc > mm_sc) mm_sc = sc, mm_idx = j;
			}
		}

		track[i] = push_sc_pre(mm_sc, mm_idx);
		srt[i] = track[i]>>32; srt[i] <<= 32; srt[i] |= i;
		n_el += li->el;

		// if(mode) {
		// 	fprintf(stderr, "[M::%.*s] i:%ld, li->el:%u, li->score:%ld (raw_sc:%u), mm_idx:%ld, mm_sc:%ld, q[%u, %u), t[%u, %u), rev:%c\n", 
		// 		(int32_t)Get_NAME_LENGTH(R_INF, li->tn), Get_NAME(R_INF, li->tn), i, li->el, csc, li->te - li->ts, mm_idx, mm_sc, li->qs, li->qe, li->ts, li->te, "+-"[li->rev]);
		// } else {
		// 	fprintf(stderr, "[M::utg%.6u%c] i:%ld, li->el:%u, li->score:%ld (raw_sc:%u), mm_idx:%ld, mm_sc:%ld, q[%u, %u), t[%u, %u), rev:%c\n", 
		// 		li->tn+1, "lc"[uref->ug->u.a[li->tn].circ], i, li->el, csc, li->te - li->ts, mm_idx, mm_sc, li->qs, li->qe, li->ts, li->te, "+-"[li->rev]);
		// }
		// if(!mode) {
		// 	fprintf(stderr, "[M::utg%.6d%c] qs->%u; qe->%u\n", li->tn+1, "lc"[uref->ug->u.a[li->tn].circ], li->qs, li->qe);
		// }
		// fprintf(stderr, "[M::utg%.6d%c] qs->%u; qe->%u; sc->%ld; pre->%ld; el->%u;\n", 
		// li->tn+1, "lc"[uref->ug->u.a[li->tn].circ], li->qs, li->qe, pop_sc(track[i]), pop_pre(track[i]), li->el);
	}
	
	int64_t n_v, n_u, n_v0, le, lnv; 
	radix_sort_gfa64(srt, srt+res->n); 
	for (k = (int64_t)res->n-1, n_v = n_u = 0; k >= 0; --k) {
		n_v0 = n_v; i = (uint32_t)srt[k];
		// fprintf(stderr, "+[M::utg%.6d%c] n_v0->%ld;\n", res->a[i].tn+1, "lc"[uref->ug->u.a[res->a[i].tn].circ], n_v0);
		if(res->a[i].el) { ///chain must start from cis alignments
			for (le = -1; i >= 0 && (track[i]&((uint64_t)0x80000000)) == 0;) {
				if(res->a[i].el) {
					le = -1;
				}else if(n_v>n_v0 && ex[n_v-1].el) {
					le = i; lnv = n_v;///cut the cis alignments in the end
				}
				ex[n_v++] = res->a[i]; track[i] |= ((uint64_t)0x80000000);
				// fprintf(stderr, "[M::utg%.6d%c] qs->%u; qe->%u\n", res->a[i].tn+1, "lc"[uref->ug->u.a[res->a[i].tn].circ], res->a[i].qs, res->a[i].qe);
				i = pop_pre(track[i]);
			}
		}
		// fprintf(stderr, "-[M::] n_v->%ld;\n", n_v);
		if(n_v0 == n_v) continue;
		if(le >= 0) {
			i = le; n_v = lnv;
		}
		if(n_v0 == n_v) continue;
		// fprintf(stderr, "[++chain::] beg_idx->%u, end_idx->%ld, le->%ld, chain_n->%ld\n", (uint32_t)srt[k], i, le, n_v - n_v0);
		///keep the whole score; do not cut score like minigraph
		// sc = pop_sc(srt[k]);
		sc = (i<0?(pop_sc(srt[k])):(pop_sc(srt[k])-pop_sc(track[i])));
		// fprintf(stderr, "++[M::%s] k:%ld, n_v0:%ld, n_v:%ld, le:%ld, sc:%ld, beg:%u, end:%ld, p_score:%ld, cut_score:%ld\n", 
		// __func__, k, n_v0, n_v, le, sc, (uint32_t)srt[k], i, pop_sc(srt[k]), i<0?0:pop_sc(track[i]));
		if(sc /**<=**/< 0) {///sc might be 0, if the UL alignment cannot cover the whole overlap between two HiFi reads
			n_v = n_v0;
			continue;
		}
		// idx[n_u++] = push_sc_pre(sc, n_v-n_v0);	
		idx[n_u++] = ((uint64_t)sc<<32)|(n_v-n_v0);	
	}
	// fprintf(stderr, "[M::%s] n_u:%ld, n_v:%ld\n", __func__, n_u, n_v);
	for (k = 0, n_v = n_v0 = 0; k < n_u; k++) {
		n_v0 = n_v; n_v += (uint32_t)idx[k];
		// fprintf(stderr, "[M::%s] k:%ld, n_v0:%ld, n_v:%ld\n", __func__, k, n_v0, n_v);
		res->a[k].qn = idx[k]>>32;//score
		res->a[k].ts = n_v0; res->a[k].te = n_v;///idx
		
		rev_n = ((uint32_t)idx[k])>>1; 
		///we need to consider contained reads; so determining qs is not such easy
		res->a[k].qs = (uint32_t)-1; res->a[k].qe = ex[n_v0].qe;
		for (i = 0; i < rev_n; i++) {
			rev_t = ex[n_v0+i]; ex[n_v0+i] = ex[n_v-i-1]; ex[n_v-i-1] = rev_t;
			
			if(res->a[k].qs > ex[n_v0+i].qs) res->a[k].qs = ex[n_v0+i].qs;
			if(res->a[k].qs > ex[n_v-i-1].qs) res->a[k].qs = ex[n_v-i-1].qs;
			n_el -= ex[n_v0+i].el; n_el -= ex[n_v-i-1].el;
			ex[n_v0+i].sec = ex[n_v-i-1].sec = SEC_MODE; 
		}
		if(((uint32_t)idx[k])&1) {
			if(res->a[k].qs > ex[n_v0+i].qs) res->a[k].qs = ex[n_v0+i].qs;
			n_el -= ex[n_v0+i].el; ex[n_v0+i].sec = SEC_MODE; 
		}
		assert(ex[n_v0].el && ex[n_v-1].el);
		// fprintf(stderr, "[M::%s] k:%ld, qs:%u, qe:%u, chain_occ:%u, chain_score:%u\n", __func__, k, 
		// 					res->a[k].qs, res->a[k].qe, res->a[k].te - res->a[k].ts, res->a[k].qn);
	}
	// if(n_el) {
	// 	fprintf(stderr, "[M::%s] debug_i->%ld, n_el->%ld, n_u->%ld, n_v->%ld\n", __func__, debug_i, n_el, n_u, n_v);
	// }
	assert(n_el == 0);
	res->n = n_u;
	radix_sort_ul_ov_srt_qn(res->a, res->a + res->n);//sort by score
	// fprintf(stderr, "---[M::%s] n_u:%ld, n_v:%ld\n", __func__, n_u, n_v);
	return n_v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x292c48
movq $0x0, -0x8(%rbp)
jmp 0x2939a8
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27b350
movq $0x1, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jg 0x292d2a
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x292cde
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x70(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
je 0x292d17
movq -0x68(%rbp), %rax
subq -0x70(%rbp), %rax
cmpq $0x1, %rax
jle 0x292d0f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x1c, -0x70(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
imulq $0x1c, -0x68(%rbp), %rax
addq %rax, %rsi
callq 0x27b890
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x292d19
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x292c98
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x293194
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0xb8(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
cmpq $0x0, 0x38(%rbp)
je 0x292d97
movq -0x28(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
callq 0x287de0
movq %rax, -0x110(%rbp)
jmp 0x292db4
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
callq 0x287d20
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x58(%rbp), %rax
cvtsi2sd %rax, %xmm0
mulsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x292df2
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jle 0x292e25
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rax
movl %eax, %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x60(%rbp), %rax
addq $0x80, %rax
movl %eax, %edx
callq 0x28cf00
cltq
movq %rax, -0x60(%rbp)
movq -0xb8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x292ef3
cmpq $0x0, 0x38(%rbp)
je 0x292ea7
movq -0x20(%rbp), %rdi
movq -0xb8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
movq -0xb8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %r8d
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r9d
callq 0x114c0
movq %rax, -0x118(%rbp)
jmp 0x292ee3
movq -0x20(%rbp), %rdi
movq -0xb8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
movq -0xb8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %r8d
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r9d
callq 0x110c0
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x292f14
movq 0x30(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
imulq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $-0x1, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jl 0x2930fd
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x70(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0xc0(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0xb8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x292f94
jmp 0x2930fd
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xb8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x292faf
jmp 0x2930ec
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq 0x40(%rbp), %r8
movq 0x48(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x71a90
movq %rax, -0xa0(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x2930ea
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x44(%rbp), %edx
xorl $0x1, %edx
movl -0x48(%rbp), %ecx
xorl $0x1, %ecx
movq -0x30(%rbp), %r8
movsd -0x38(%rbp), %xmm0
movq -0xa0(%rbp), %r9
movq 0x38(%rbp), %r10
leaq -0xa8(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x292000
cmpq $0x0, %rax
je 0x2930ea
movq -0x88(%rbp), %rax
movq %rax, -0x120(%rbp)
movq 0x28(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, %rcx
movq -0x120(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0xb8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2930c5
movq -0xc0(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2930c5
movq -0xa8(%rbp), %rax
cmpq -0x88(%rbp), %rax
jl 0x2930a5
movq -0x88(%rbp), %rax
movq %rax, -0x128(%rbp)
jmp 0x2930b3
movq -0xa8(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rcx
movq -0x80(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x90(%rbp), %rax
jle 0x2930e8
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x2930ea
jmp 0x2930ec
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x292f35
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x292ac0
movq %rax, %rdx
movq 0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq 0x18(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x68(%rbp), %rdx
movq 0x18(%rbp), %rax
movq -0x68(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0xb8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
movl %eax, %eax
addq -0xb0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x292d32
movq 0x18(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0xf0(%rbp)
movq $0x0, -0xe8(%rbp)
cmpq $0x0, -0x78(%rbp)
jl 0x29347c
movq -0xe8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq 0x18(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x293368
movq $-0x1, -0x100(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x68(%rbp)
movb %al, -0x129(%rbp)
jl 0x29325f
movq 0x28(%rbp), %rcx
movq -0x68(%rbp), %rdx
movabsq $0x80000000, %rax       # imm = 0x80000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
sete %al
movb %al, -0x129(%rbp)
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x29326e
jmp 0x293366
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x293298
movq $-0x1, -0x100(%rbp)
jmp 0x2932e7
movq -0xe8(%rbp), %rax
cmpq -0xf8(%rbp), %rax
jle 0x2932e5
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2932e5
movq -0x68(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x108(%rbp)
jmp 0x2932e7
movq -0x10(%rbp), %rax
movq (%rax), %rcx
imulq $0x1c, -0x68(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0xe8(%rbp)
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq 0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movabsq $0x80000000, %rdx       # imm = 0x80000000
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292ba0
movq %rax, -0x68(%rbp)
jmp 0x29322d
jmp 0x293368
movq -0xf8(%rbp), %rax
cmpq -0xe8(%rbp), %rax
jne 0x29337d
jmp 0x29346b
cmpq $0x0, -0x100(%rbp)
jl 0x2933a0
movq -0x100(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xf8(%rbp), %rax
cmpq -0xe8(%rbp), %rax
jne 0x2933b5
jmp 0x29346b
cmpq $0x0, -0x68(%rbp)
jge 0x2933d6
movq 0x18(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, -0x138(%rbp)
jmp 0x293413
movq 0x18(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, -0x140(%rbp)
movq 0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, %rcx
movq -0x140(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jge 0x293435
movq -0xf8(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x29346b
movq -0x80(%rbp), %rdx
shlq $0x20, %rdx
movq -0xe8(%rbp), %rax
subq -0xf8(%rbp), %rax
orq %rax, %rdx
movq 0x20(%rbp), %rax
movq -0xf0(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0xf0(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x2931d6
movq $0x0, -0x78(%rbp)
movq $0x0, -0xf8(%rbp)
movq $0x0, -0xe8(%rbp)
movq -0x78(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jge 0x293944
movq -0xe8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq 0x20(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0xe8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq 0x20(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0xf8(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0xe8(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq 0x20(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrl %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
imulq $0x1c, -0xf8(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jge 0x2937e8
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xdc(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xd4(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0xcc(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x18(%rbp), %rcx
movq -0xe8(%rbp), %rax
subq -0x68(%rbp), %rax
subq $0x1, %rax
imulq $0x1c, %rax, %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rdx
addq -0x68(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq -0x68(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0xdc(%rbp), %rcx
movq %rcx, (%rax)
movq -0xd4(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xcc(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0xc4(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movq -0xf8(%rbp), %rdx
addq -0x68(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2936b7
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movq -0xe8(%rbp), %rdx
subq -0x68(%rbp), %rdx
subq $0x1, %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x293717
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq -0x68(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0xb0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq -0x68(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0xb0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq -0x68(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x293581
movq 0x20(%rbp), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2938b4
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movq -0xf8(%rbp), %rdx
addq -0x68(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x293858
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x78(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0xb0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq -0xf8(%rbp), %rcx
addq -0x68(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
imulq $0x1c, -0xf8(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
shrl $0x1e, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x141(%rbp)
je 0x293904
movq -0x18(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x141(%rbp)
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x293910
jmp 0x293912
jmp 0x293931
leaq 0xfd9d4(%rip), %rdi     # 0x3912ed
leaq 0xfcf0f(%rip), %rsi     # 0x39082f
movl $0xf0e, %edx            # imm = 0xF0E
leaq 0xfd9dd(%rip), %rcx     # 0x391309
callq 0x2130
jmp 0x293933
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x29349a
cmpq $0x0, -0xb0(%rbp)
jne 0x293950
jmp 0x29396f
leaq 0xfda8b(%rip), %rdi     # 0x3913e2
leaq 0xfced1(%rip), %rsi     # 0x39082f
movl $0xf15, %edx            # imm = 0xF15
leaq 0xfd99f(%rip), %rcx     # 0x391309
callq 0x2130
movq -0xf0(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27c310
movq -0xe8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopw %cs:(%rax,%rax)