// File: chhylp123[P]hifiasm/inter.cpp
// Function: push_trans_aln(ul_idx_t const*, ug_opt_t const*, long, double, All_reads*, ul_ov_t*, long, long, long*, int*)
int64_t push_trans_aln(const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, 
All_reads *ridx, ul_ov_t *a, int64_t ai0, int64_t aj, int64_t *vis, int32_t *c_n)
{
	int64_t k, qo, is_c, ai = ai0, m = 0; ul_ov_t *li, *lj; uint32_t li_v, lj_v;
	for (k = ai + 1; k < aj; k++) {
		if(vis[k]&1) continue;
		if(!(a[k].el)) continue;
		// if(a[ai0].tn == 1053 || a[aj].tn == 1053) {
		// 	fprintf(stderr, "**0**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev]);
		// }
		lj = &(a[ai]); li = &(a[k]); 
		li_v = (li->tn<<1)|li->rev; 
		lj_v = (lj->tn<<1)|lj->rev;
		if(lj->qe <= li->qs) continue;//even this pair has a overlap, its length will be very small; just ignore
		if(lj->qs > li->qs) continue;///no contain
		if(li_v == lj_v) continue;
		qo = infer_rovlp(li, lj, NULL, NULL, ridx, NULL); ///overlap length in query (UL read)
		if(!get_ecov_contain_adv(uref, uopt, li_v^1, lj_v^1, bw, diff_ec_ul, qo, &is_c)) continue;
		// if(a[ai0].tn == 1053 || a[aj].tn == 1053) {
		// 	fprintf(stderr, "**1**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev]);
		// }
		if(is_c)  continue;
		// if(a[ai0].tn == 1053 || a[aj].tn == 1053) {
		// 	fprintf(stderr, "**2**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev]);
		// }
			

		lj = &(a[k]); li = &(a[aj]);
		li_v = (li->tn<<1)|li->rev; 
		lj_v = (lj->tn<<1)|lj->rev;
		if(lj->qe <= li->qs) continue;//even this pair has a overlap, its length will be very small; just ignore
		if(lj->qs > li->qs) continue;///no contain
		if(li_v == lj_v) continue;
		qo = infer_rovlp(li, lj, NULL, NULL, ridx, NULL); ///overlap length in query (UL read)
		// if(a[ai0].tn == 1053 || a[aj].tn == 1053) {
		// 	fprintf(stderr, "**2-a**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c, qo::%ld\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev], qo);
		// }
		if(!get_ecov_contain_adv(uref, uopt, li_v^1, lj_v^1, bw, diff_ec_ul, qo, &is_c)) continue;
		// if(a[ai0].tn == 1053 || a[aj].tn == 1053) {
		// 	fprintf(stderr, "**3**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev]);
		// }
		if(is_c)  continue;
		// if(a[ai0].tn == 1053 || a[aj].tn == 1053) 
		// {
		// 	fprintf(stderr, "**4**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev]);
		// }

		// res[m] = a[k]; vis[k] |= 1;
		// if(res[m].qs < idx->qs) idx->qs = res[m].qs;
		// if(res[m].qe > idx->qe) idx->qe = res[m].qe;
		// if(res[m].tn == 1032)  {
		// 	fprintf(stderr, "**5**[k::%ld] ai0::%ld, ai::%ld, aj::%ld, (id::%u)%.*s\t%c\n", 
		// 		k, ai0, ai, aj, a[k].tn, (int)Get_NAME_LENGTH(R_INF, a[k].tn), Get_NAME(R_INF, a[k].tn), 
		// 		"+-"[a[k].rev]);
		// }
		// m++; ai = k;
		c_n[m++] = k; vis[k] |= 1; ai = k;
	}
	return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x10(%rbp), %rax
jge 0x2b3d33
movq 0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x2b3af9
jmp 0x2b3d22
movq -0x30(%rbp), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x2b3b18
jmp 0x2b3d22
movq -0x30(%rbp), %rax
imulq $0x1c, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x68(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x74(%rbp)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x70(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x68(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x2b3b7d
jmp 0x2b3d22
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x68(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2b3b92
jmp 0x2b3d22
movl -0x74(%rbp), %eax
cmpl -0x78(%rbp), %eax
jne 0x2b3b9f
jmp 0x2b3d22
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rdx
movq %r9, %rcx
callq 0x71a90
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x74(%rbp), %edx
xorl $0x1, %edx
movl -0x78(%rbp), %ecx
xorl $0x1, %ecx
movq -0x18(%rbp), %r8
movsd -0x20(%rbp), %xmm0
movq -0x48(%rbp), %r9
leaq -0x50(%rbp), %rax
movq %rax, (%rsp)
callq 0x2b0c90
cmpq $0x0, %rax
jne 0x2b3bf8
jmp 0x2b3d22
cmpq $0x0, -0x50(%rbp)
je 0x2b3c04
jmp 0x2b3d22
movq -0x30(%rbp), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
imulq $0x1c, 0x10(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x68(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x74(%rbp)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x70(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x68(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x2b3c69
jmp 0x2b3d22
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x68(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2b3c7e
jmp 0x2b3d22
movl -0x74(%rbp), %eax
cmpl -0x78(%rbp), %eax
jne 0x2b3c8b
jmp 0x2b3d22
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rdx
movq %r9, %rcx
callq 0x71a90
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x74(%rbp), %edx
xorl $0x1, %edx
movl -0x78(%rbp), %ecx
xorl $0x1, %ecx
movq -0x18(%rbp), %r8
movsd -0x20(%rbp), %xmm0
movq -0x48(%rbp), %r9
leaq -0x50(%rbp), %rax
movq %rax, (%rsp)
callq 0x2b0c90
cmpq $0x0, %rax
jne 0x2b3ce1
jmp 0x2b3d22
cmpq $0x0, -0x50(%rbp)
je 0x2b3cea
jmp 0x2b3d22
movq -0x40(%rbp), %rax
movl %eax, %edx
movq 0x20(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
movl %edx, (%rax,%rcx,4)
movq 0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
orq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2b3ad0
movq -0x60(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq