// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: collect_nc_ovlps(ul_vec_t*, unsigned int, kv_ul_ov_t*, ug_opt_t const*, asg_t const*, R_to_U*, long, unsigned long*, unsigned long*)
void collect_nc_ovlps(ul_vec_t *rch, uint32_t rch_i, kv_ul_ov_t *res, const ug_opt_t *uopt, const asg_t *rg, R_to_U *ri, int64_t ulid, uint64_t *mqs, uint64_t *mqe)
{
	uint64_t i, occ, nc, k; ma_hit_t_alloc* src; 
	int64_t min_ovlp = uopt->min_ovlp, max_hang = uopt->max_hang; ul_ov_t p;
	res->n = occ = nc = 0; (*mqs) = (*mqe) = (uint64_t)-1;
	i = rch_i;
	// for (i = rch_i; (i != (uint32_t)-1) && (!rg->seq[rch->bb.a[i].hid].del); i = rch->bb.a[i].pidx) {
	while(i != (uint32_t)-1) {
		if(rg->seq[rch->bb.a[i].hid].del) break;
		// if(ulid == 442462) {		
		// 	fprintf(stderr, "\n>>>[M::%s::i->%lu::id->%u::%.*s]\n", __func__, i, rch->bb.a[i].hid, 
		// 		(int)Get_NAME_LENGTH(R_INF, rch->bb.a[i].hid), Get_NAME(R_INF, rch->bb.a[i].hid));
		// 	fprintf(stderr, "*[M::%s::id->%u::%.*s]\tq::[%u, %u),\tt::[%u, %u),\tis_rev::%u,\tis_cr::%u\n", 
		// 			__func__, rch->bb.a[i].hid, 
		// 			(int)Get_NAME_LENGTH(R_INF, rch->bb.a[i].hid), Get_NAME(R_INF, rch->bb.a[i].hid), 
		// 			rch->bb.a[i].qs, rch->bb.a[i].qe, rch->bb.a[i].ts, rch->bb.a[i].te, rch->bb.a[i].rev,
		// 			!!(is_contain_r((*(ri)), rch->bb.a[i].hid)));
		// }
		
		if(is_contain_r((*ri), rch->bb.a[i].hid)) {
			src = &(uopt->sources[rch->bb.a[i].hid]);
			for (k = 0; k < src->length; k++) {
				if(rg->seq[Get_tn(src->buffer[k])].del) continue;///tn must exist
				// if(!extract_ccov(&(src->buffer[k]), &(rch->bb.a[i]), rg, &p, 1, min_ovlp, max_hang)) continue;
				// if(ulid == 442462) {	
				// 	fprintf(stderr, "+[M::%s::id->%u::%.*s]\tq::[%u, %u),\tql::%u,\tt::[%u, %u),\ttl::%u,\tis_rev::%u,\tis_cr::%u\n", 
				// 	__func__, src->buffer[k].tn, 
				// 	(int)Get_NAME_LENGTH(R_INF, src->buffer[k].tn), Get_NAME(R_INF, src->buffer[k].tn), 
				// 	Get_qs(src->buffer[k]), Get_qe(src->buffer[k]), rg->seq[Get_qn(src->buffer[k])].len,
				// 	Get_ts(src->buffer[k]), Get_te(src->buffer[k]), rg->seq[Get_tn(src->buffer[k])].len,
				// 	src->buffer[k].rev, !!(is_contain_r((*(ri)), src->buffer[k].tn)));
				// }
				if(!extract_nccov(&(src->buffer[k]), &(rch->bb.a[i]), rg, &p, 1, min_ovlp, max_hang)) continue;
				// if(ulid == 442462) {	
				// 	fprintf(stderr, "-[M::%s::id->%u::%.*s]\tq::[%u, %u),\tt::[%u, %u),\tis_rev::%u,\tis_cr::%u\n", 
				// 	__func__, p.tn, (int)Get_NAME_LENGTH(R_INF, p.tn), Get_NAME(R_INF, p.tn), 
				// 	p.qs, p.qe, p.ts, p.te, p.rev, !!(is_contain_r((*(ri)), p.tn)));
				// 	// fprintf(stderr, "cc[M::%s::id->%u::%.*s] q::[%u, %u), t::[%u, %u), is_cr::%u, del::%u\n", 
				// 	// __func__, p.tn, (int)Get_NAME_LENGTH(R_INF, p.tn), Get_NAME(R_INF, p.tn), 
				// 	// p.qs, p.qe, p.ts, p.te, !!(is_contain_r((*(ri)), p.tn)), rg->seq[p.tn].del);
				// }
				p.el = 0; p.tn <<= 1; p.tn |= p.rev; p.qn = i;//for linear chain
            	kv_push(ul_ov_t, *res, p);
			}
			nc++;
		}
		///push itself into the chain
		memset(&p, 0, sizeof(p));
		p.qn = 0; p.qs = rch->bb.a[i].qs; p.qe = rch->bb.a[i].qe; 
    	p.tn = rch->bb.a[i].hid; p.ts = rch->bb.a[i].ts; p.te = rch->bb.a[i].te; 
    	p.el = 1; p.rev = rch->bb.a[i].rev;
		if(p.rev) {///for linear chaining
			p.ts = rg->seq[p.tn].len - rch->bb.a[i].te;
			p.te = rg->seq[p.tn].len - rch->bb.a[i].ts;
		}
		p.el = 1; p.tn <<= 1; p.tn |= p.rev; p.qn = i;//for linear chain
		kv_push(ul_ov_t, *res, p);
		if(((*mqs) == ((uint64_t)-1)) || ((*mqs) > rch->bb.a[i].qs)) (*mqs) = rch->bb.a[i].qs;
		if(((*mqe) == ((uint64_t)-1)) || ((*mqe) < rch->bb.a[i].qe)) (*mqe) = rch->bb.a[i].qe;
		occ++; 

		i = rch->bb.a[i].pidx;
		if(i != ((uint32_t)-1)) {
			if(!is_rg_connect(rg, (uint64_t)((rch->bb.a[i].hid<<1)|(rch->bb.a[i].rev)), 
					(uint64_t)((rch->bb.a[rch->bb.a[i].aidx].hid<<1)|(rch->bb.a[rch->bb.a[i].aidx].rev)))) {
				i = ((uint32_t)-1);
			}
		}
	}
	assert(occ > 1 && nc > 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, 0x58(%rsp)
movq 0xb0(%rsp), %r13
movq 0xa8(%rsp), %rbp
movq $0x0, 0x8(%rdx)
movq $-0x1, %rax
movq %rax, (%r13)
movq %rax, (%rbp)
cmpl $-0x1, %esi
je 0x1d10ef
movq %r9, %r14
movq %r8, %r10
movq %rdx, %r12
movq %rdi, %r15
movl %esi, %r9d
xorl %edx, %edx
movq $0x0, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %r14, 0x50(%rsp)
movq %rdi, 0x40(%rsp)
movq 0x20(%r10), %rcx
movq 0x30(%r15), %rax
movq %r9, 0x48(%rsp)
leaq (%r9,%r9,8), %rbx
movl (%rax,%rbx,4), %eax
cmpl $0x0, (%rcx,%rax,8)
js 0x1d10d2
cmpq %rax, (%r14)
movq %rdx, 0x60(%rsp)
jbe 0x1d0ecb
movq 0x8(%r14), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x1d0ecb
movq 0x58(%rsp), %rcx
movq 0x8(%rcx), %rcx
leaq (%rax,%rax,2), %rax
cmpl $0x0, 0xc(%rcx,%rax,8)
je 0x1d0eac
leaq (%rcx,%rax,8), %r15
leaq (,%rbx,4), %r13
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x20(%r10), %rax
movq (%r15), %rdi
movl 0xc(%rdi,%rbp), %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1d0e98
addq %rbp, %rdi
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rsi
addq %r13, %rsi
movq %r10, %rdx
leaq 0x10(%rsp), %rcx
movl $0x1, %r8d
callq 0x1d0b1b
movq 0x30(%rsp), %r10
testl %eax, %eax
je 0x1d0e98
movl 0x28(%rsp), %eax
movl %eax, %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
movl %ecx, 0x28(%rsp)
shldl $0x1, %eax, 0x1c(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x10(%rsp)
movq 0x10(%r12), %rax
cmpq %rax, 0x8(%r12)
jne 0x1d0e68
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r12)
movq (%r12), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x30(%rsp), %r10
movq %rax, (%r12)
movq (%r12), %rax
movq 0x8(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r12)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x10(%rsp), %xmm0
movups 0x1c(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %r14
movl 0xc(%r15), %eax
addq $0x28, %rbp
cmpq %rax, %r14
jb 0x1d0dc7
incq 0x38(%rsp)
movq 0x50(%rsp), %r14
movq 0x40(%rsp), %r15
movq 0xb0(%rsp), %r13
movq 0xa8(%rsp), %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x30(%r15), %rsi
movl 0x4(%rsi,%rbx,4), %eax
movl %eax, 0x14(%rsp)
movl 0x8(%rsi,%rbx,4), %eax
movl %eax, 0x18(%rsp)
movl (%rsi,%rbx,4), %eax
movl %eax, 0x1c(%rsp)
movl 0xc(%rsi,%rbx,4), %ecx
movl %ecx, 0x20(%rsp)
movl 0x10(%rsi,%rbx,4), %edi
movl %edi, 0x24(%rsp)
movl 0x28(%rsp), %edx
movl $0x40000000, %r8d       # imm = 0x40000000
orl %r8d, %edx
movl %edx, 0x28(%rsp)
movl 0x20(%rsi,%rbx,4), %r8d
movl %r8d, %esi
andl $-0x20, %esi
shll $0x1a, %esi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl %esi, %edx
movl %edx, 0x28(%rsp)
btl $0x5, %r8d
jae 0x1d0f59
movq 0x20(%r10), %r8
movl (%r8,%rax,8), %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %r8d
movl %r8d, %r9d
subl %edi, %r9d
movl %r9d, 0x20(%rsp)
subl %ecx, %r8d
movl %r8d, 0x24(%rsp)
movl %edx, 0x28(%rsp)
shldl $0x1, %esi, %eax
movl %eax, 0x1c(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x10(%rsp)
movq 0x10(%r12), %rax
cmpq %rax, 0x8(%r12)
jne 0x1d0fac
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r12)
movq (%r12), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x30(%rsp), %r10
movq %rax, (%r12)
movq (%r12), %rax
movq 0x8(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r12)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x1c(%rsp), %xmm0
movups %xmm0, 0xc(%rax,%rdx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rdx)
movq (%rbp), %rax
cmpq $-0x1, %rax
je 0x1d0ff3
movq 0x30(%r15), %rcx
movl 0x4(%rcx,%rbx,4), %ecx
cmpq %rcx, %rax
jbe 0x1d0fff
movq 0x30(%r15), %rax
movl 0x4(%rax,%rbx,4), %eax
movq %rax, (%rbp)
movq (%r13), %rax
cmpq $-0x1, %rax
je 0x1d1016
movq 0x30(%r15), %rcx
movl 0x8(%rcx,%rbx,4), %ecx
cmpq %rcx, %rax
jae 0x1d1022
movq 0x30(%r15), %rax
movl 0x8(%rax,%rbx,4), %eax
movq %rax, (%r13)
movq 0x30(%r15), %rcx
movl 0x14(%rcx,%rbx,4), %eax
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rax
je 0x1d10c0
leaq (%rax,%rax,8), %rdi
movl 0x20(%rcx,%rdi,4), %edx
shrl $0x5, %edx
andl $0x1, %edx
movl (%rcx,%rdi,4), %esi
leal (%rdx,%rsi,2), %edx
movq 0x28(%r10), %rsi
movq (%rsi,%rdx,8), %rdx
movq %rdx, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x1d10c0
movl 0x1c(%rcx,%rdi,4), %edi
leaq (%rdi,%rdi,8), %rdi
movl (%rcx,%rdi,4), %r8d
movl 0x20(%rcx,%rdi,4), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%r8,2), %ecx
movq 0x8(%r10), %rdi
shrq $0x20, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %edi, %edi
cmpl $0x0, (%rdx,%rdi)
js 0x1d10ac
cmpl %ecx, -0x4(%rdx,%rdi)
je 0x1d10bd
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0x1d10a0
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
jmp 0x1d10c0
movq %rax, %r9
movq 0x60(%rsp), %rdx
incq %rdx
cmpl $-0x1, %r9d
jne 0x1d0d64
cmpq $0x2, %rdx
jb 0x1d10ef
cmpq $0x0, 0x38(%rsp)
je 0x1d10ef
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x66372(%rip), %rdi     # 0x237468
leaq 0x6288e(%rip), %rsi     # 0x23398b
leaq 0x66376(%rip), %rcx     # 0x23747a
movl $0x45df, %edx           # imm = 0x45DF
callq 0x2110