// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %cl
shrb $0x6, %cl
andb $0x1, %cl
xorl %eax, %eax
cmpb $0x0, %cl
movb %al, -0x89(%rbp)
jne 0x2f2541
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x89(%rbp)
jne 0x2f2541
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
setne %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x2f254d
jmp 0x2f254f
jmp 0x2f256e
leaq 0xa2928(%rip), %rdi     # 0x394e7e
leaq 0x9e2d2(%rip), %rsi     # 0x39082f
movl $0x4da4, %edx           # imm = 0x4DA4
leaq 0xa2955(%rip), %rcx     # 0x394ebe
callq 0x2130
cmpl $0x0, -0x1c(%rbp)
ja 0x2f2579
jmp 0x2f28ef
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
jne 0x2f2599
jmp 0x2f28ef
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
jne 0x2f25b6
jmp 0x2f28ef
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
shll %eax
movq -0x50(%rbp), %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
leaq 0xd2cb7(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movl (%rdx), %edx
cmpq (%rcx,%rdx,8), %rax
jae 0x2f262e
jmp 0x2f28ef
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x50(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x2f28ef
movq -0x58(%rbp), %rax
movl (%rax), %eax
shll %eax
movq -0x58(%rbp), %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x58(%rbp), %rax
movb 0x20(%rax), %cl
shrb $0x6, %cl
andb $0x1, %cl
xorl %eax, %eax
cmpb $0x0, %cl
movb %al, -0x8a(%rbp)
jne 0x2f26f4
movq -0x58(%rbp), %rax
movb 0x20(%rax), %cl
andb $0x1f, %cl
xorl %eax, %eax
cmpb $0x0, %cl
movb %al, -0x8a(%rbp)
je 0x2f26f4
movq -0x58(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
setne %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x2f2700
jmp 0x2f2702
jmp 0x2f2721
leaq 0xa2821(%rip), %rdi     # 0x394f2a
leaq 0x9e11f(%rip), %rsi     # 0x39082f
movl $0x4db2, %edx           # imm = 0x4DB2
leaq 0xa27a2(%rip), %rcx     # 0x394ebe
callq 0x2130
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
leaq 0xd2b98(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x58(%rbp), %rdx
movl (%rdx), %edx
cmpq (%rcx,%rdx,8), %rax
jb 0x2f28ad
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f2855
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x40(%rbp)
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl -0x34(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x2f2845
movl -0x44(%rbp), %eax
movl -0x38(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x2f2845
movq -0x78(%rbp), %rax
movq (%rax), %rdi
movl -0x3c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq 0xd2b03(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0xd2aeb(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x38(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x88(%rbp), %rax
movl %eax, %ecx
leaq 0xd1ff2(%rip), %rax     # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x80(%rbp), %rax
movl %eax, %r8d
leaq -0x70(%rbp), %r9
callq 0x287f40
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jge 0x2f2829
jmp 0x2f2847
movq -0x70(%rbp), %rax
shrq $0x20, %rax
movl -0x34(%rbp), %ecx
cmpq %rcx, %rax
jne 0x2f2841
movl -0x68(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x2f2843
jmp 0x2f2847
jmp 0x2f2855
jmp 0x2f2847
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f2753
movl -0x3c(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f28ab
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
shrq $0x20, %rcx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
addl $0x1, %ecx
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
shlq $0x20, %rdx
movabsq $-0x7fffffff00000001, %rsi # imm = 0x80000000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
jmp 0x2f28ad
movq -0x58(%rbp), %rax
cmpl $-0x1, 0x14(%rax)
jne 0x2f28c2
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0x2f28df
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x58(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x2f267d
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)