// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rcx, 0x38(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x88(%rsp), %r8
movq 0x80(%rsp), %r13
imulq $0x1c, %r13, %rdi
addq %rbx, %rdi
leaq 0x1(%r9), %rbp
imulq $0x1c, %r9, %rax
leaq (%rax,%rbx), %r14
addq $0x1c, %r14
movq $0x0, 0x10(%rsp)
movq %rdi, 0x40(%rsp)
cmpq %r13, %rbp
jge 0x1746cb
testb $0x1, (%r8,%rbp,8)
jne 0x1746bf
movl 0x18(%r14), %eax
btl $0x1e, %eax
jae 0x1746bf
imulq $0x1c, %r9, %rcx
movl 0x4(%r14), %edx
cmpl %edx, 0x8(%rbx,%rcx)
jbe 0x1746bf
leaq (%rbx,%rcx), %rsi
cmpl %edx, 0x4(%rsi)
ja 0x1746bf
movl 0xc(%r14), %r15d
shldl $0x1, %eax, %r15d
movl 0xc(%rbx,%rcx), %eax
movl 0x18(%rbx,%rcx), %r12d
shrdl $0x1f, %eax, %r12d
cmpl %r12d, %r15d
je 0x1746bf
movq %r9, 0x8(%rsp)
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x38(%rsp), %r8
xorl %r9d, %r9d
callq 0x3d261
xorl $0x1, %r15d
xorl $0x1, %r12d
leaq 0x18(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x20(%rsp), %rsi
movl %r15d, %edx
movl %r12d, %ecx
movq 0x28(%rsp), %r8
movsd 0x30(%rsp), %xmm0
movq %rax, %r9
callq 0x1728e0
testq %rax, %rax
je 0x1746b2
cmpq $0x0, 0x18(%rsp)
movq 0x8(%rsp), %r9
movq 0x88(%rsp), %r8
movq 0x40(%rsp), %rdi
jne 0x1746bf
movl 0x4(%rdi), %eax
cmpl %eax, 0x8(%r14)
jbe 0x1746bf
cmpl %eax, 0x4(%r14)
ja 0x1746bf
movl 0xc(%rdi), %eax
movl 0x18(%rdi), %r15d
shrdl $0x1f, %eax, %r15d
movl 0xc(%r14), %eax
movl 0x18(%r14), %r12d
shrdl $0x1f, %eax, %r12d
cmpl %r12d, %r15d
je 0x1746bf
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x38(%rsp), %r8
xorl %r9d, %r9d
callq 0x3d261
xorl $0x1, %r15d
xorl $0x1, %r12d
leaq 0x18(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x20(%rsp), %rsi
movl %r15d, %edx
movl %r12d, %ecx
movq 0x28(%rsp), %r8
movsd 0x30(%rsp), %xmm0
movq %rax, %r9
callq 0x1728e0
testq %rax, %rax
je 0x1746b2
cmpq $0x0, 0x18(%rsp)
movq 0x8(%rsp), %r9
movq 0x88(%rsp), %r8
jne 0x1746bf
movq 0x90(%rsp), %rax
movq 0x10(%rsp), %rcx
movl %ebp, (%rax,%rcx,4)
incq %rcx
movq %rcx, 0x10(%rsp)
orb $0x1, (%r8,%rbp,8)
movq %rbp, %r9
jmp 0x1746bf
movq 0x8(%rsp), %r9
movq 0x88(%rsp), %r8
incq %rbp
addq $0x1c, %r14
jmp 0x17452a
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq