// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rdx, 0x20(%rsp)
movq 0x30(%rdx), %rax
movl %ecx, %edx
leaq (%rdx,%rdx,8), %rdi
movzbl 0x20(%rax,%rdi,4), %edx
testb $0x40, %dl
jne 0x1d79dd
testb %dl, %dl
jns 0x1d79dd
leaq (%rax,%rdi,4), %rdi
movl (%rdi), %ebp
cmpq %r8, %rbp
jne 0x1d79dd
testl %ecx, %ecx
je 0x1d79af
movl %edx, %ecx
andb $0x1f, %cl
je 0x1d79af
movl 0x14(%rdi), %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpq %r8, %rcx
je 0x1d79af
movl 0x10(%rdi), %r8d
subl 0xc(%rdi), %r8d
leaq 0xb3a6a(%rip), %rdi     # 0x28b230
movq 0x18(%rdi), %rdi
cmpq %r8, (%rdi,%rbp,8)
ja 0x1d79af
testq %rax, %rax
je 0x1d79af
shrl $0x5, %edx
andl $0x1, %edx
leal (%rdx,%rbp,2), %edx
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
shlq $0x3, %rdi
addq 0x8(%rsi), %rdi
movq %rdi, 0x8(%rsp)
xorl $0x1, %edx
movl 0x40(%rsi), %edi
movl %edi, 0x18(%rsp)
movl 0x44(%rsi), %esi
movl %esi, 0x14(%rsp)
leaq (%rcx,%rcx,8), %rcx
leaq (%rax,%rcx,4), %rsi
movl %edx, %eax
movq %rax, 0x28(%rsp)
movl 0x20(%rsi), %eax
movl %eax, %ecx
andb $-0x40, %cl
negb %cl
jno 0x1d79be
movl %eax, %ecx
andb $0x1f, %cl
je 0x1d79be
movl 0x10(%rsi), %ecx
subl 0xc(%rsi), %ecx
movq %rsi, 0x30(%rsp)
movl (%rsi), %ebx
leaq 0xb39dd(%rip), %rdx     # 0x28b230
movq 0x18(%rdx), %rdx
movq %rdx, 0x48(%rsp)
cmpq %rcx, (%rdx,%rbx,8)
ja 0x1d7939
movq 0x8(%rsp), %rcx
movl 0xc(%rcx), %ecx
testq %rcx, %rcx
setne %r14b
je 0x1d7939
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%rbx,2), %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %r13
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
leaq 0xb2ebb(%rip), %rax     # 0x28a758
movss 0x158(%rax), %xmm0
movss %xmm0, 0x1c(%rsp)
leaq (,%rcx,8), %rax
leaq (%rax,%rax,4), %rdx
movl $0x1, %r15d
xorl %r12d, %r12d
movq %rcx, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
cmpl 0x4(%r13,%r12), %ebp
jne 0x1d7926
cmpl %ebx, 0xc(%r13,%r12)
jne 0x1d7926
leaq (%r12,%r13), %rdi
movq 0x48(%rsp), %rax
movl (%rax,%rbp,8), %esi
movl (%rax,%rbx,8), %edx
movl 0x18(%rsp), %ecx
movss 0x1c(%rsp), %xmm0
movl 0x14(%rsp), %r8d
leaq 0x50(%rsp), %r9
callq 0x19c0d3
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
testl %eax, %eax
js 0x1d7926
movq 0x28(%rsp), %rax
cmpl %eax, 0x54(%rsp)
jne 0x1d7926
movl 0x58(%rsp), %eax
xorl 0x10(%rsp), %eax
cmpl $0x1, %eax
je 0x1d796b
cmpq %rcx, %r15
setb %r14b
addq $0x28, %r12
incq %r15
cmpq %r12, %rdx
jne 0x1d78ca
movq 0x30(%rsp), %rax
movl 0x14(%rax), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x1d795e
leaq (%rax,%rax,8), %rsi
shlq $0x2, %rsi
movq 0x20(%rsp), %rax
addq 0x30(%rax), %rsi
jmp 0x1d7960
xorl %esi, %esi
testq %rsi, %rsi
jne 0x1d7824
jmp 0x1d79af
testb $0x1, %r14b
je 0x1d7939
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r12), %rcx
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rcx, %rdx
movabsq $0x7fffffff00000000, %rsi # imm = 0x7FFFFFFF00000000
andq %rsi, %rdx
movabsq $-0x7fffffff00000001, %rsi # imm = 0x80000000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax,%r12)
jmp 0x1d7939
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x606c1(%rip), %rdi     # 0x238086
leaq 0x5bfbf(%rip), %rsi     # 0x23398b
leaq 0x60647(%rip), %rcx     # 0x23801a
movl $0x4db2, %edx           # imm = 0x4DB2
callq 0x2110
leaq 0x605f6(%rip), %rdi     # 0x237fda
leaq 0x5bfa0(%rip), %rsi     # 0x23398b
leaq 0x60628(%rip), %rcx     # 0x23801a
movl $0x4da4, %edx           # imm = 0x4DA4
callq 0x2110