// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdx, %r12
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
movq $0x0, 0x8(%r12)
movq $-0x1, %rax
movq %rax, (%rcx)
movq %rax, (%rdx)
cmpl $-0x1, %esi
je 0x1db1cc
movq %r8, %r14
movl %esi, %r10d
movq 0x30(%rdi), %rax
movq 0x20(%r8), %rdx
leaq (%r10,%r10,8), %rcx
movl (%rax,%rcx,4), %ecx
cmpl $0x0, (%rdx,%rcx,8)
js 0x1db1ad
movq %r9, %r13
movq %rdi, 0x38(%rsp)
xorl %ebp, %ebp
xorl %r9d, %r9d
movq %r9, 0x58(%rsp)
cmpq %rcx, (%r13)
movq %r10, 0x30(%rsp)
jbe 0x1dafc1
movq 0x8(%r13), %rdx
cmpl $0x0, (%rdx,%rcx,4)
js 0x1dafc1
movq %rbx, 0x50(%rsp)
movq 0x8(%rbx), %rdx
leaq (%rcx,%rcx,2), %rcx
movl 0xc(%rdx,%rcx,8), %ebx
testl %ebx, %ebx
je 0x1dafb9
movq %rbp, 0x40(%rsp)
movq %r13, 0x48(%rsp)
leaq (%rdx,%rcx,8), %r15
leaq (%r10,%r10,8), %rax
shlq $0x2, %rax
movq %rax, 0x60(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x20(%r14), %rax
movq (%r15), %rdi
movl 0xc(%rdi,%rbp), %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1daf8f
addq %rbp, %rdi
movq 0x38(%rsp), %rax
movq 0x30(%rax), %rsi
addq 0x60(%rsp), %rsi
movq %r14, %rdx
leaq 0x10(%rsp), %rcx
movl $0x1, %r8d
callq 0x1dac2c
testl %eax, %eax
je 0x1daf8f
movl 0x28(%rsp), %eax
movl %eax, %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
movl %ecx, 0x28(%rsp)
shldl $0x1, %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movl %eax, 0x10(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %rcx
cmpq 0x10(%r12), %rcx
jne 0x1daf62
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r12)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r12)
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
movdqu 0x1c(%rsp), %xmm1
movdqu %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movl 0xc(%r15), %ebx
incq %r13
movl %ebx, %eax
addq $0x28, %rbp
cmpq %rax, %r13
jb 0x1daec1
movq 0x38(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x48(%rsp), %r13
movq 0x40(%rsp), %rbp
movq 0x30(%rsp), %r10
incq %rbp
movq 0x50(%rsp), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq (%r10,%r10,8), %r15
movdqu (%rax,%r15,4), %xmm0
pshufd $0xc9, %xmm0, %xmm1     # xmm1 = xmm0[1,2,0,3]
movdqu %xmm1, 0x14(%rsp)
movl 0x10(%rax,%r15,4), %edx
movl %edx, 0x24(%rsp)
movl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x28(%rsp)
movl 0x20(%rax,%r15,4), %eax
btl $0x5, %eax
movd %xmm0, %ecx
jae 0x1db029
movq 0x20(%r14), %rsi
movl (%rsi,%rcx,8), %esi
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %esi
movl %esi, %edi
subl %edx, %edi
movl %edi, 0x20(%rsp)
pshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
movd %xmm0, %edx
subl %edx, %esi
movl %esi, 0x24(%rsp)
andl $-0x20, %eax
shll $0x1a, %eax
shldl $0x1, %eax, %ecx
movl $0x40000000, %edx       # imm = 0x40000000
orl %edx, %eax
movl %eax, 0x28(%rsp)
movl %ecx, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movl %eax, 0x10(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %rcx
cmpq 0x10(%r12), %rcx
jne 0x1db08c
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r12)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r12)
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 0xa8(%rsp), %rax
movq (%rax), %rdx
movq 0x38(%rsp), %rax
movq 0x30(%rax), %rax
movl 0x4(%rax,%r15,4), %ecx
cmpq $-0x1, %rdx
je 0x1db0d7
cmpq %rcx, %rdx
jbe 0x1db0e2
movq 0xa8(%rsp), %rdx
movq %rcx, (%rdx)
movq 0xb0(%rsp), %rcx
movq (%rcx), %rdx
movl 0x8(%rax,%r15,4), %ecx
cmpq $-0x1, %rdx
je 0x1db0fd
cmpq %rcx, %rdx
jae 0x1db108
movq 0xb0(%rsp), %rdx
movq %rcx, (%rdx)
movq 0x58(%rsp), %r9
incq %r9
movl 0x14(%rax,%r15,4), %r10d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpq %r8, %r10
je 0x1db1b2
leaq (%r10,%r10,8), %rcx
movl 0x20(%rax,%rcx,4), %edx
shrl $0x5, %edx
andl $0x1, %edx
movl (%rax,%rcx,4), %esi
leal (%rdx,%rsi,2), %edx
movq 0x28(%r14), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdi
andq %r8, %rdi
je 0x1db1b2
movl 0x1c(%rax,%rcx,4), %edx
leaq (%rdx,%rdx,8), %rdx
movl (%rax,%rdx,4), %r8d
movl 0x20(%rax,%rdx,4), %edx
shrl $0x5, %edx
andl $0x1, %edx
leal (%rdx,%r8,2), %edx
movq 0x8(%r14), %r8
shrq $0x20, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
addq $0xc, %rsi
xorl %r8d, %r8d
cmpl $0x0, (%rsi,%r8)
js 0x1db18f
cmpl %edx, -0x4(%rsi,%r8)
je 0x1db19a
addq $0x18, %r8
cmpq %r8, %rdi
jne 0x1db181
jmp 0x1db1b2
movq 0x20(%r14), %rdx
movl (%rax,%rcx,4), %ecx
cmpl $0x0, (%rdx,%rcx,8)
jns 0x1dae66
jmp 0x1db1b2
xorl %ebp, %ebp
xorl %r9d, %r9d
cmpq $0x2, %r9
jb 0x1db1cc
testq %rbp, %rbp
je 0x1db1cc
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68565(%rip), %rdi     # 0x243738
leaq 0x64a81(%rip), %rsi     # 0x23fc5b
leaq 0x68569(%rip), %rcx     # 0x24374a
movl $0x45df, %edx           # imm = 0x45DF
callq 0x2110