// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: determine_connective_backtrack(all_ul_t*, ug_opt_t const*, ul_vec_t*, unsigned int, unsigned long, unsigned long)
void determine_connective_backtrack(all_ul_t *m, const ug_opt_t *uopt, ul_vec_t *p, uint32_t ii, uint64_t rid, uint64_t ulid)
{
	assert((!p->bb.a[ii].base)&&(p->bb.a[ii].hid == rid)&&(p->bb.a[ii].el));
	if(ii <= 0) return;
	if(!(p->bb.a[ii].pchain)) return; ///not a primary chain
	if(p->bb.a[ii].pidx == (uint32_t)-1) return; ///not connected
	uint32_t li_v, lk_v, z, qn, tn; int32_t r; uc_block_t *li = NULL, *lk = NULL; asg_arc_t t; 
	li = &(p->bb.a[ii]); li_v = (((uint32_t)(li->hid))<<1)|((uint32_t)(li->rev)); li_v^=1;
	if((li->te - li->ts) < Get_READ_LENGTH(R_INF, li->hid)) return;
	ma_hit_t_alloc *x = &(uopt->sources[li_v>>1]);
    int64_t min_ovlp = uopt->min_ovlp;
    int64_t max_hang = uopt->max_hang;
	// if(rid == 4217) fprintf(stderr, "rid: %lu, p->bb.n: %u\n", rid, p->bb.n);

	for (lk = &(p->bb.a[li->pidx]); lk; ) {
		lk_v = (((uint32_t)(lk->hid))<<1)|((uint32_t)(lk->rev)); lk_v^=1;
		assert((!(lk->base)) && (lk->pchain) && (lk->el));
		if((lk->te - lk->ts) >= Get_READ_LENGTH(R_INF, lk->hid)) {
			for (z = 0; z < x->length; z++) {
				qn = Get_qn(x->buffer[z]);
				tn = Get_tn(x->buffer[z]);
				if(qn == (li_v>>1) && tn == (lk_v>>1)) {
					r = ma_hit2arc(&(x->buffer[z]), Get_READ_LENGTH(R_INF, li_v>>1), Get_READ_LENGTH(R_INF, lk_v>>1),
						max_hang, asm_opt.max_hang_rate, min_ovlp, &t);
					if(r < 0) continue;
					if((t.ul>>32) != li_v || t.v != lk_v) continue;
					break;
				}
			}
			if(z < x->length) {
				x->buffer[z].bl++;
				// if(((li_v>>1) == 1656459) || ((li_v>>1) == 4179430)|| 
				// 	((lk_v>>1) == 1656459) || ((lk_v>>1) == 4179430)) {
				// 	fprintf(stderr, "[M::%s::]\tulid::%lu\n", __func__, ulid);
				// }
			}
		}

		lk = ((lk->pidx==(uint32_t)-1)?NULL:&(p->bb.a[lk->pidx]));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x10(%rsp)
movq 0x30(%rdx), %r9
movl %ecx, %eax
imulq $0x24, %rax, %rdx
movzbl 0x20(%r9,%rdx), %eax
testb $0x40, %al
jne 0x1948dd
testb %al, %al
jns 0x1948dd
addq %r9, %rdx
movl (%rdx), %r15d
cmpq %r8, %r15
jne 0x1948dd
testl %ecx, %ecx
je 0x194740
movl %eax, %ecx
andb $0x1f, %cl
je 0x194740
movl 0x14(%rdx), %ecx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %rdi, %rcx
je 0x194740
movl 0x10(%rdx), %edi
subl 0xc(%rdx), %edi
leaq 0xbfafa(%rip), %rdx     # 0x254230
movq 0x18(%rdx), %rdx
cmpq %rdi, (%rdx,%r8,8)
jbe 0x19474f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%r15,2), %eax
xorl $0x1, %eax
movq %rax, 0x20(%rsp)
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
imulq $0x18, %r15, %rbp
addq 0x8(%rsi), %rbp
movl 0x40(%rsi), %eax
movl %eax, 0x8(%rsp)
movl 0x44(%rsi), %eax
movl %eax, 0x4(%rsp)
imulq $0x24, %rcx, %rax
addq %rax, %r9
testq %r9, %r9
je 0x194740
movl 0x20(%r9), %eax
movl %eax, %ecx
andb $-0x40, %cl
negb %cl
jno 0x1948be
movl %eax, %ecx
andb $0x1f, %cl
je 0x1948be
movl 0x10(%r9), %ecx
subl 0xc(%r9), %ecx
movq %r9, 0x18(%rsp)
movl (%r9), %ebx
leaq 0xbfa73(%rip), %rdx     # 0x254230
movq 0x18(%rdx), %rdx
movq %rdx, 0x28(%rsp)
cmpq %rcx, (%rdx,%rbx,8)
jbe 0x1947f3
movq 0x18(%rsp), %rax
movl 0x14(%rax), %eax
movl $0x0, %r9d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x194785
imulq $0x24, %rax, %r9
movq 0x10(%rsp), %rax
addq 0x30(%rax), %r9
jmp 0x194785
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%rbx,2), %eax
movl %eax, (%rsp)
movl 0xc(%rbp), %eax
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
leaq 0xbef49(%rip), %rcx     # 0x253758
movss 0x158(%rcx), %xmm0
movss %xmm0, 0xc(%rsp)
imulq $0x28, %rax, %r12
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x1947cc
movq (%rbp), %r13
cmpl 0x4(%r13,%r14), %r15d
jne 0x19487f
cmpl %ebx, 0xc(%r13,%r14)
jne 0x19487f
leaq (%r14,%r13), %rdi
movq 0x28(%rsp), %rax
movl (%rax,%r15,8), %esi
movl (%rax,%rbx,8), %edx
movl 0x8(%rsp), %ecx
movss 0xc(%rsp), %xmm0
movl 0x4(%rsp), %r8d
leaq 0x30(%rsp), %r9
callq 0x15d560
testl %eax, %eax
js 0x19487f
movq 0x20(%rsp), %rax
cmpl %eax, 0x34(%rsp)
jne 0x19487f
movl 0x38(%rsp), %eax
xorl (%rsp), %eax
cmpl $0x1, %eax
je 0x194885
addq $0x28, %r14
jmp 0x194824
movq 0x18(%r13,%r14), %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rax, %rcx
movabsq $0x7fffffff00000000, %rdx # imm = 0x7FFFFFFF00000000
andq %rdx, %rcx
movabsq $-0x7fffffff00000001, %rdx # imm = 0x80000000FFFFFFFF
andq %rdx, %rax
orq %rcx, %rax
movq %rax, 0x18(%r13,%r14)
jmp 0x1947cc
leaq 0x61959(%rip), %rdi     # 0x1f621e
leaq 0x5d257(%rip), %rsi     # 0x1f1b23
leaq 0x618df(%rip), %rcx     # 0x1f61b2
movl $0x4db2, %edx           # imm = 0x4DB2
callq 0x2110
leaq 0x6188e(%rip), %rdi     # 0x1f6172
leaq 0x5d238(%rip), %rsi     # 0x1f1b23
leaq 0x618c0(%rip), %rcx     # 0x1f61b2
movl $0x4da4, %edx           # imm = 0x4DA4
callq 0x2110