// File: /workspace/github_cpp_makefile_star2_O3/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 %r9, %rbp
movq %rcx, 0x38(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x80(%rsp), %r9
leaq 0x1(%rbp), %r13
cmpq %r9, %r13
jge 0x1bf11b
movq %r8, %rbx
movq 0x88(%rsp), %r8
leaq (%r9,%r9,8), %rax
leaq (%rax,%rax,2), %rdi
addq %rbx, %rdi
addq %r9, %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rax
addq %rbp, %rax
leaq (%rbx,%rax), %r15
addq $0x1c, %r15
movq $0x0, 0x10(%rsp)
movq %rdi, 0x40(%rsp)
testb $0x1, (%r8,%r13,8)
jne 0x1bf109
movl 0x18(%r15), %eax
btl $0x1e, %eax
jae 0x1bf109
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbp, %rcx
movl 0x4(%r15), %edx
cmpl %edx, 0x8(%rbx,%rcx)
jbe 0x1bf109
leaq (%rbx,%rcx), %rsi
cmpl %edx, 0x4(%rsi)
ja 0x1bf109
movl 0xc(%r15), %r12d
shldl $0x1, %eax, %r12d
movl 0xc(%rbx,%rcx), %eax
movl 0x18(%rbx,%rcx), %r14d
shrdl $0x1f, %eax, %r14d
cmpl %r14d, %r12d
je 0x1bf109
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x38(%rsp), %r8
xorl %r9d, %r9d
callq 0x6ea22
xorl $0x1, %r12d
xorl $0x1, %r14d
leaq 0x18(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x20(%rsp), %rsi
movl %r12d, %edx
movl %r14d, %ecx
movq 0x28(%rsp), %r8
movsd 0x30(%rsp), %xmm0
movq %rax, %r9
callq 0x1bcf0f
testq %rax, %rax
je 0x1bf0f9
cmpq $0x0, 0x18(%rsp)
movq 0x80(%rsp), %r9
movq 0x88(%rsp), %r8
movq 0x40(%rsp), %rdi
jne 0x1bf109
movl 0x4(%rdi), %eax
cmpl %eax, 0x8(%r15)
jbe 0x1bf109
cmpl %eax, 0x4(%r15)
ja 0x1bf109
movl 0xc(%rdi), %eax
movl 0x18(%rdi), %r12d
shrdl $0x1f, %eax, %r12d
movl 0xc(%r15), %eax
movl 0x18(%r15), %r14d
shrdl $0x1f, %eax, %r14d
cmpl %r14d, %r12d
je 0x1bf109
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x38(%rsp), %r8
xorl %r9d, %r9d
callq 0x6ea22
xorl $0x1, %r12d
xorl $0x1, %r14d
leaq 0x18(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x20(%rsp), %rsi
movl %r12d, %edx
movl %r14d, %ecx
movq 0x28(%rsp), %r8
movsd 0x30(%rsp), %xmm0
movq %rax, %r9
callq 0x1bcf0f
testq %rax, %rax
je 0x1bf0f9
cmpq $0x0, 0x18(%rsp)
movq 0x80(%rsp), %r9
movq 0x88(%rsp), %r8
jne 0x1bf109
movq 0x90(%rsp), %rax
movq 0x10(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
incq %rcx
movq %rcx, 0x10(%rsp)
orb $0x1, (%r8,%r13,8)
movq %r13, %rbp
jmp 0x1bf109
movq 0x80(%rsp), %r9
movq 0x88(%rsp), %r8
incq %r13
addq $0x1c, %r15
cmpq %r13, %r9
jne 0x1bef6a
jmp 0x1bf124
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq