// File: chhylp123[P]hifiasm/inter.cpp
// Function: determine_connective_adv(all_ul_t*, ug_opt_t const*, long, double, ul_vec_t*, unsigned int, unsigned long)
void determine_connective_adv(all_ul_t *m, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, ul_vec_t *p, uint32_t ii, uint64_t rid)
{
	assert((!p->bb.a[ii].base)&&(p->bb.a[ii].hid == rid));
	if(ii <= 0) return;
	if(!(p->bb.a[ii].pchain)) return; ///not a primary chain
	if(!(p->bb.a[ii].el)) return; ///not a cis alignment
	uint32_t li_v, lk_v, ol; int64_t mm_ovlp, k, x; 
	uc_block_t *li = NULL, *lk = NULL;
	ma_hit_t *t = NULL;
	li = &(p->bb.a[ii]); li_v = (((uint32_t)(li->hid))<<1)|((uint32_t)(li->rev));
	mm_ovlp = max_ovlp_src(uopt, li_v^1);
	x = (li->qs + mm_ovlp)*diff_ec_ul; 
	if(x < bw) x = bw; 
	x += li->qs + mm_ovlp;
	if (x > p->rlen+1) x = p->rlen+1;
	x = find_ul_block_max(ii, p->bb.a, x+G_CHAIN_INDEL);
	for (k = x; k >= 0; --k) { // collect potential destination vertices
		lk = &(p->bb.a[k]); lk_v = (((uint32_t)(lk->hid))<<1)|((uint32_t)(lk->rev));
		if(lk->qe+G_CHAIN_INDEL <= li->qs) break;//even this pair has a overlap, its length will be very small; just ignore
		if(lk->base || (!(lk->pchain)) || (!(lk->el))) continue; 
		if(li_v == lk_v) continue;
		// if(li->qs <= 0) continue;///means the UL read does not longer than the overlap between li and lk
		// if(lk->qs <= 0) continue;//the UL read should be cover the whole HiFi reads li and lk
		// if(((li->te - li->ts)*1.05) < Get_READ_LENGTH(R_INF, li->hid)) continue;
		// if(((lk->te - lk->ts)*1.05) < Get_READ_LENGTH(R_INF, lk->hid)) continue;
		if((li->te - li->ts) < Get_READ_LENGTH(R_INF, li->hid)) continue;
		if((lk->te - lk->ts) < Get_READ_LENGTH(R_INF, lk->hid)) continue;
		x = /**((int64_t)(lk->qe))-((int64_t)(li->qs))**/infer_rovlp(NULL, NULL, li, lk, &R_INF, NULL);
		t = query_ovlp_src(uopt, li_v^1, lk_v^1, x, diff_ec_ul, &ol);
		if(t) {
			// sum = t->bl + ol;
			// t->bl = (sum & 0x7fffffffU);
			t->bl++;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x2c(%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, -0x79(%rbp)
jne 0x2f21ab
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpq -0x38(%rbp), %rax
sete %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x2f21b4
jmp 0x2f21b6
jmp 0x2f21d5
leaq 0xa2c26(%rip), %rdi     # 0x394de3
leaq 0x9e66b(%rip), %rsi     # 0x39082f
movl $0x4d7f, %edx           # imm = 0x4D7F
leaq 0xa2c41(%rip), %rcx     # 0x394e11
callq 0x2130
cmpl $0x0, -0x2c(%rbp)
ja 0x2f21e0
jmp 0x2f249c
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
jne 0x2f2200
jmp 0x2f249c
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
jne 0x2f2221
jmp 0x2f249c
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl (%rax), %eax
shll %eax
movq -0x68(%rbp), %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
xorl $0x1, %esi
callq 0x287de0
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x50(%rbp), %rax
cvtsi2sd %rax, %xmm0
mulsd -0x20(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2f22af
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x50(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jle 0x2f22e7
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %edi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x60(%rbp), %rax
addq $0x80, %rax
movl %eax, %edx
callq 0x2f2040
cltq
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jl 0x2f249c
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl (%rax), %eax
shll %eax
movq -0x70(%rbp), %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x40(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0x68(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x2f2367
jmp 0x2f249c
movq -0x70(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x2f2392
movq -0x70(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
je 0x2f2392
movq -0x70(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
jne 0x2f2397
jmp 0x2f248b
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x2f23a4
jmp 0x2f248b
movq -0x68(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x68(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
leaq 0xd2f15(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x68(%rbp), %rdx
movl (%rdx), %edx
cmpq (%rcx,%rdx,8), %rax
jae 0x2f23d0
jmp 0x2f248b
movq -0x70(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x70(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
leaq 0xd2ee9(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x70(%rbp), %rdx
movl (%rdx), %edx
cmpq (%rcx,%rdx,8), %rax
jae 0x2f23fc
jmp 0x2f248b
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
leaq 0xd2ec0(%rip), %r8      # 0x3c52d0
movq %r9, %rdi
movq %r9, %rsi
callq 0x71a90
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
xorl $0x1, %esi
movl -0x40(%rbp), %edx
xorl $0x1, %edx
movq -0x60(%rbp), %rcx
movsd -0x20(%rbp), %xmm0
leaq -0x44(%rbp), %r8
callq 0x28ffe0
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x2f2489
movq -0x78(%rbp), %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 0x2f248b
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x2f2311
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)