// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x20(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq 0x20(%rbp), %rax
movq $-0x1, (%rax)
movq 0x18(%rbp), %rax
movq $-0x1, (%rax)
movl -0xc(%rbp), %eax
movq %rax, -0x38(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x38(%rbp)
je 0x2e5fde
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e5a58
jmp 0x2e5fde
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2e5c73
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x2e5c73
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x2e5c73
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2e5c67
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x58(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x28, -0x50(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e5b2f
jmp 0x2e5c56
movq -0x58(%rbp), %rax
movq (%rax), %rdi
imulq $0x28, -0x50(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
imulq $0x24, -0x38(%rbp), %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
movq -0x60(%rbp), %r9
movq -0x68(%rbp), %rax
leaq -0x84(%rbp), %rcx
movl $0x1, %r8d
movq %rax, (%rsp)
callq 0x2e55e0
cmpl $0x0, %eax
jne 0x2e5b7a
jmp 0x2e5c56
movl -0x6c(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x0, %eax
movl %eax, -0x6c(%rbp)
movl -0x78(%rbp), %eax
shll %eax
movl %eax, -0x78(%rbp)
movl -0x6c(%rbp), %eax
shrl $0x1f, %eax
orl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2e5c13
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2e5bd7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x2e5be5
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x2e5be5
movq -0x90(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x84(%rbp), %rcx
movq %rcx, (%rax)
movq -0x7c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x74(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x6c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2e5c56
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2e5af1
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
leaq -0x84(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movl $0x0, -0x84(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x80(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x6c(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %ecx
movl -0x6c(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e5d98
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x78(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x74(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x78(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x6c(%rbp)
movl -0x78(%rbp), %eax
shll %eax
movl %eax, -0x78(%rbp)
movl -0x6c(%rbp), %eax
shrl $0x1f, %eax
orl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2e5e33
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2e5df7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x2e5e05
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x2e5e05
movq -0x98(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x84(%rbp), %rcx
movq %rcx, (%rax)
movq -0x7c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x74(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x6c(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq 0x18(%rbp), %rax
cmpq $-0x1, (%rax)
je 0x2e5e9d
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x2e5eb9
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq 0x20(%rbp), %rax
cmpq $-0x1, (%rax)
je 0x2e5ee2
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2e5efe
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq %rax, -0x38(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x38(%rbp)
je 0x2e5fd9
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x30(%rdx), %rdx
imulq $0x24, -0x38(%rbp), %r8
addq %r8, %rdx
movl 0x1c(%rdx), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x30dcb0
cmpl $0x0, %eax
jne 0x2e5fd7
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x38(%rbp)
jmp 0x2e5fd9
jmp 0x2e5a1f
xorl %eax, %eax
cmpq $0x1, -0x40(%rbp)
movb %al, -0x99(%rbp)
jbe 0x2e5ffb
cmpq $0x0, -0x48(%rbp)
seta %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x2e6007
jmp 0x2e6009
jmp 0x2e6028
leaq 0xae2fc(%rip), %rdi     # 0x39430c
leaq 0xaa818(%rip), %rsi     # 0x39082f
movl $0x45df, %edx           # imm = 0x45DF
leaq 0xae2fb(%rip), %rcx     # 0x39431e
callq 0x2130
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)