// File: chhylp123[P]hifiasm/inter.cpp
// Function: gl_chain_advance_back(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*, float, All_reads*, ma_ug_t*, void*)
int64_t gl_chain_advance_back(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, float trans_allow, 
All_reads *ridx, ma_ug_t *ug, void *km)
{
	uint32_t li_v, lj_v, rev_n, is_c, nc, s_nc;
	int64_t mm_ovlp, x, i, j, k, sc, csc, mm_sc, mm_idx, qo, trans_scl = (int64_t)(((float)(1))/trans_allow), nsc[2];
	ul_ov_t *li = NULL, *lj = NULL, rev_t;
	radix_sort_ul_ov_srt_qe(res->a, res->a + res->n);
	for (i = s_nc = 0; i < (int64_t)res->n; ++i) {
		li = &(res->a[i]); li_v = (li->tn<<1)|li->rev;
		mm_ovlp = uref?max_ovlp(uref->ug->g, li_v^1):max_ovlp_src(uopt, 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); 
		csc = uref?retrieve_u_cov_region(uref, li->tn, 0, li->ts, li->te, NULL):li->te-li->ts;
		if(!(li->el)) {
			csc *= -trans_scl; //trans overlaps
			if(csc >= 0) csc = -1;
		}
		mm_sc = csc; mm_idx = -1; nc = nsc[0] = nsc[1] = 0;
		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 <= li->qs) break;//even this pair has a overlap, its length will be very small; just ignore
			// if(lj->qs >= li->qs) continue; // lj is contained in li on the query coordinate
			qo = infer_rovlp(li, lj, NULL, NULL, ridx, ug); ///overlap length in query (UL read)
			if(li_v != lj_v && get_ecov_adv_back(uref, uopt, li_v^1, lj_v^1, bw, diff_ec_ul, qo, &is_c)) {
				if(!is_c) {
					sc = csc + pop_sc(track[j]);
					if(sc > mm_sc) mm_sc = sc, mm_idx = j;
				} else if(!uref) {///with uref, retrieve_u_cov_region has already consider contained reads
					res->a[nc++].sec = j; 
					if(li->el) nsc[0] += lj->te-lj->ts;
					else nsc[!(lj->el)] += lj->te-lj->ts;
				}
			}
		}
		
		if(nc && (!uref) && mm_idx>=0) {///deal with containments
			mm_sc += determine_containment_chain(uopt, track, srt, res, nc, nsc, mm_idx, bw, diff_ec_ul, li->el, ridx, ug);
			s_nc++;
		}

		track[i] = push_sc_pre(mm_sc, mm_idx);
		srt[i] = track[i]>>32; srt[i] <<= 32; srt[i] |= i;
		// fprintf(stderr, "[M::utg%.6d%c] qs->%u; qe->%u\n\n", li->tn+1, "lc"[uref->ug->u.a[li->tn].circ], li->qs, li->qe);
	}

	if(s_nc) {
		for (i = 0; i < (int64_t)res->n; ++i) {
			if(srt[i]&((uint64_t)0x80000000)) srt[i]-=((uint64_t)0x80000000);
		}
	}
	
	int64_t n_v, n_u, n_v0, le, lnv; 
	radix_sort_gfa64(srt, srt+res->n); //ex->n = 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];
		if(i>=0 && (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]);
			}
		}
		if(n_v0 == n_v) continue;
		if(le >= 0) {
			i = le; n_v = lnv;
		}
		if(n_v0 == n_v) continue;
		///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])));
		if(sc < 0) {
			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);	
	}

	for (k = 0, n_v = n_v0 = 0; k < n_u; k++) {
		n_v0 = n_v; n_v += (uint32_t)idx[k];
		res->a[k].qn = idx[k]>>32;
		res->a[k].ts = n_v0; res->a[k].te = n_v;
		
		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_v0+rev_n-i-1];
			ex[n_v0+rev_n-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_v0+rev_n-i-1].qs) res->a[k].qs = ex[n_v0+rev_n-i-1].qs;
		}
		if(i < ((uint32_t)idx[k]) && res->a[k].qs < ex[n_v0+i].qs) {
			res->a[k].qs = ex[n_v0+i].qs;
		}
	}
	res->n = n_u;
	radix_sort_ul_ov_srt_qn(res->a, res->a + res->n);
	return n_v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
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, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movss %xmm1, -0x4c(%rbp)
movss 0xeb678(%rip), %xmm0    # 0x37f08c
divss -0x4c(%rbp), %xmm0
cvttss2si %xmm0, %rax
movq %rax, -0xc0(%rbp)
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27b350
movl $0x0, -0x64(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x293f9e
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0xd8(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x50(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x293ad5
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
movl -0x50(%rbp), %esi
xorl $0x1, %esi
callq 0x287d20
movq %rax, -0x130(%rbp)
jmp 0x293aeb
movq -0x30(%rbp), %rdi
movl -0x50(%rbp), %esi
xorl $0x1, %esi
callq 0x287de0
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0xd8(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x70(%rbp), %rax
cvtsi2sd %rax, %xmm0
mulsd -0x40(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x293b29
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0xd8(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x70(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jle 0x293b5c
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
movl %eax, %edi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x78(%rbp), %rax
movl %eax, %edx
callq 0x28cf00
cltq
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x293bbf
movq -0x28(%rbp), %rdi
movq -0xd8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
movq -0xd8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %r8d
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r9d
callq 0x110c0
movq %rax, -0x138(%rbp)
jmp 0x293bdc
movq -0xd8(%rbp), %rax
movl 0x14(%rax), %eax
movq -0xd8(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xd8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x293c2e
xorl %eax, %eax
subq -0xc0(%rbp), %rax
imulq -0xa0(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jl 0x293c2c
movq $-0x1, -0xa0(%rbp)
jmp 0x293c2e
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq $-0x1, -0xb0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jl 0x293e8e
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x88(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0xe0(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0xe0(%rbp), %rax
movl 0x8(%rax), %eax
movq -0xd8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x293ccf
jmp 0x293e8e
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq 0x30(%rbp), %r8
movq 0x38(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x71a90
movq %rax, -0xb8(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
je 0x293e75
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x50(%rbp), %edx
xorl $0x1, %edx
movl -0x54(%rbp), %ecx
xorl $0x1, %ecx
movq -0x38(%rbp), %r8
movsd -0x40(%rbp), %xmm0
movq -0xb8(%rbp), %r9
leaq -0x5c(%rbp), %rax
movq %rax, (%rsp)
callq 0x2918c0
cmpq $0x0, %rax
je 0x293e75
cmpl $0x0, -0x5c(%rbp)
jne 0x293dac
movq -0xa0(%rbp), %rax
movq %rax, -0x140(%rbp)
movq 0x28(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, %rcx
movq -0x140(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jle 0x293da7
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x293e73
cmpq $0x0, -0x28(%rbp)
jne 0x293e71
movq -0x88(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x60(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x60(%rbp)
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0xd8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x293e2a
movq -0xe0(%rbp), %rax
movl 0x14(%rax), %eax
movq -0xe0(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
addq -0xd0(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x293e6f
movq -0xe0(%rbp), %rax
movl 0x14(%rax), %eax
movq -0xe0(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addq -0xd0(%rbp,%rax,8), %rcx
movq %rcx, -0xd0(%rbp,%rax,8)
jmp 0x293e71
jmp 0x293e73
jmp 0x293e75
jmp 0x293e77
movq -0x88(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x293c6f
cmpl $0x0, -0x60(%rbp)
je 0x293f27
cmpq $0x0, -0x28(%rbp)
jne 0x293f27
cmpq $0x0, -0xb0(%rbp)
jl 0x293f27
movq -0x30(%rbp), %rdi
movq 0x28(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x60(%rbp), %r8d
leaq -0xd0(%rbp), %r9
movq -0xb0(%rbp), %r14
movq -0x38(%rbp), %rbx
movsd -0x40(%rbp), %xmm0
movq -0xd8(%rbp), %rax
movl 0x18(%rax), %r11d
shrl $0x1e, %r11d
andl $0x1, %r11d
movq 0x30(%rbp), %r10
movq 0x38(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x292570
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x292ac0
movq %rax, %rdx
movq 0x28(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq 0x18(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x80(%rbp), %rdx
movq 0x18(%rbp), %rax
movq -0x80(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x293a69
cmpl $0x0, -0x64(%rbp)
je 0x294005
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x294003
movq 0x18(%rbp), %rcx
movq -0x80(%rbp), %rdx
movabsq $0x80000000, %rax       # imm = 0x80000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x293ff3
movq 0x18(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movabsq $0x80000000, %rsi       # imm = 0x80000000
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x293ff5
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x293fac
jmp 0x294005
movq 0x18(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x110(%rbp)
movq $0x0, -0x108(%rbp)
cmpq $0x0, -0x90(%rbp)
jl 0x294316
movq -0x108(%rbp), %rax
movq %rax, -0x118(%rbp)
movq 0x18(%rbp), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jl 0x2941ed
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x80(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2941ed
movq $-0x1, -0x120(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x80(%rbp)
movb %al, -0x141(%rbp)
jl 0x2940e4
movq 0x28(%rbp), %rcx
movq -0x80(%rbp), %rdx
movabsq $0x80000000, %rax       # imm = 0x80000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
sete %al
movb %al, -0x141(%rbp)
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x2940f3
jmp 0x2941eb
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x80(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x29411d
movq $-0x1, -0x120(%rbp)
jmp 0x29416c
movq -0x108(%rbp), %rax
cmpq -0x118(%rbp), %rax
jle 0x29416a
movq -0x20(%rbp), %rax
movq -0x108(%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 0x29416a
movq -0x80(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x128(%rbp)
jmp 0x29416c
movq -0x18(%rbp), %rax
movq (%rax), %rcx
imulq $0x1c, -0x80(%rbp), %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq -0x108(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x108(%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 -0x80(%rbp), %rcx
movabsq $0x80000000, %rdx       # imm = 0x80000000
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292ba0
movq %rax, -0x80(%rbp)
jmp 0x2940b2
jmp 0x2941ed
movq -0x118(%rbp), %rax
cmpq -0x108(%rbp), %rax
jne 0x294202
jmp 0x2942ff
cmpq $0x0, -0x120(%rbp)
jl 0x294225
movq -0x120(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x118(%rbp), %rax
cmpq -0x108(%rbp), %rax
jne 0x29423a
jmp 0x2942ff
cmpq $0x0, -0x80(%rbp)
jge 0x29425e
movq 0x18(%rbp), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, -0x150(%rbp)
jmp 0x29429e
movq 0x18(%rbp), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, -0x158(%rbp)
movq 0x28(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x292b40
movq %rax, %rcx
movq -0x158(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jge 0x2942c6
movq -0x118(%rbp), %rax
movq %rax, -0x108(%rbp)
jmp 0x2942ff
movq -0x98(%rbp), %rdx
shlq $0x20, %rdx
movq -0x108(%rbp), %rax
subq -0x118(%rbp), %rax
orq %rax, %rdx
movq 0x20(%rbp), %rax
movq -0x110(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x110(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x29404a
movq $0x0, -0x90(%rbp)
movq $0x0, -0x118(%rbp)
movq $0x0, -0x108(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x110(%rbp), %rax
jge 0x294697
movq -0x108(%rbp), %rax
movq %rax, -0x118(%rbp)
movq 0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x108(%rbp), %rax
movq %rax, -0x108(%rbp)
movq 0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x118(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x108(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq 0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrl %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
imulq $0x1c, -0x118(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl -0x58(%rbp), %ecx
cmpq %rcx, %rax
jge 0x294606
movq -0x20(%rbp), %rax
movq -0x118(%rbp), %rcx
addq -0x80(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xfc(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xf4(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0xec(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0xe4(%rbp)
movq -0x20(%rbp), %rcx
movq -0x118(%rbp), %rax
movl -0x58(%rbp), %edx
addq %rdx, %rax
subq -0x80(%rbp), %rax
subq $0x1, %rax
imulq $0x1c, %rax, %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq -0x118(%rbp), %rdx
addq -0x80(%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 -0x20(%rbp), %rax
movq -0x118(%rbp), %rcx
movl -0x58(%rbp), %edx
addq %rdx, %rcx
subq -0x80(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0xfc(%rbp), %rcx
movq %rcx, (%rax)
movq -0xf4(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xec(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0xe4(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
movq -0x118(%rbp), %rdx
addq -0x80(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x294581
movq -0x20(%rbp), %rax
movq -0x118(%rbp), %rcx
addq -0x80(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
movq -0x118(%rbp), %rdx
movl -0x58(%rbp), %esi
addq %rsi, %rdx
subq -0x80(%rbp), %rdx
subq $0x1, %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2945f3
movq -0x20(%rbp), %rax
movq -0x118(%rbp), %rcx
movl -0x58(%rbp), %edx
addq %rdx, %rcx
subq -0x80(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
jmp 0x2945f5
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x294439
movq -0x80(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x90(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jge 0x29467e
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
movq -0x118(%rbp), %rdx
addq -0x80(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jae 0x29467e
movq -0x20(%rbp), %rax
movq -0x118(%rbp), %rcx
addq -0x80(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x90(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
jmp 0x294680
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x294337
movq -0x110(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27c310
movq -0x108(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax,%rax)