// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: determine_containment_chain(ug_opt_t const*, unsigned long*, unsigned long*, kv_ul_ov_t*, int, long*, long, long, double, unsigned int, All_reads*, ma_ug_t*)
int64_t determine_containment_chain(const ug_opt_t *uopt, uint64_t *track, uint64_t *flag, kv_ul_ov_t *res, int32_t nc, int64_t *nsc, int64_t mm_idx, int64_t bw, double diff_ec_ul, uint32_t el, All_reads *ridx, ma_ug_t *ug)
{
	int64_t i, k, pk, ak, e, off = 128, qo, tt = 0, ii; ul_ov_t *li = NULL, *lk = NULL;
	uint32_t li_v, lk_v, is_c;
	if(nc<=0) return 0;
	for (k = tt = ak = 0; k < nc; k++) {
		if(!(flag[res->a[k].sec]&((uint64_t)0x80000000))) {
			flag[res->a[k].sec] |= ((uint64_t)0x80000000); tt++;
		} else {
			res->a[ak++].sec = res->a[k].sec;
		}
	}
	if(tt==nc) return nsc[0] - nsc[1];
	assert(ak>0);
	e = res->a[res->a[ak-1].sec].qe;//e is the smallest qe
	for (i = mm_idx, pk = 0; i >= 0;) {///i++, li->qe--
		li = &(res->a[i]); li_v = (li->tn<<1)|li->rev;
		if((track[i]&((uint64_t)0x7FFFFFFF)) == ((uint64_t)0x7FFFFFFF)) i = -1;
		else i = track[i]&((uint64_t)0x7FFFFFFF);
		if(li->qe + off < e || tt == nc) break;//128 is used to tolerate indels; 
		for (k = pk, ii = 0; k < ak; k++) {///k++, lk->qe--
			if(res->a[k].sec == ((uint32_t)0x3FFFFFFF)) continue;
			lk = &(res->a[res->a[k].sec]); lk_v = (lk->tn<<1)|lk->rev;
			if(li->qe + off >= lk->qe) {
				if(ii == 0) pk = k;
				if(li->qs <= lk->qs + off) {
					qo = infer_rovlp(li, lk, NULL, NULL, ridx, ug); ///overlap length in query (UL read)
					if(li_v != lk_v && get_ecov_adv_back(NULL, uopt, li_v^1, lk_v^1, bw, diff_ec_ul, qo, &is_c)) {
						if(is_c) {
							tt++; res->a[k].sec = ((uint32_t)0x3FFFFFFF);
							if(el) nsc[0] -= ((int64_t)(lk->te-lk->ts));
							else nsc[!(lk->el)] -= ((int64_t)(lk->te-lk->ts));
						}
					}
				}
				ii = 1;
			}
		}
	}

	assert(nsc[0]>=0 && nsc[1]>=0);
	return nsc[0] - nsc[1];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movsd %xmm0, 0x58(%rsp)
movq %r9, 0x8(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
testl %r8d, %r8d
jle 0x1aba8c
movq %rcx, %r11
movq 0xa0(%rsp), %r14
movl %r8d, %ecx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
movq %rcx, 0x30(%rsp)
addq %rcx, %rax
xorl %ecx, %ecx
movl $0xc0000000, %esi       # imm = 0xC0000000
xorl %r15d, %r15d
xorl %ebp, %ebp
movq (%r11), %r8
movl 0x18(%r8,%rcx), %edi
andl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movq (%rdx,%rdi,8), %r9
testl %r9d, %r9d
js 0x1aba46
btsq $0x1f, %r9
movq %r9, (%rdx,%rdi,8)
incq %r15
jmp 0x1aba6b
leaq (,%rbp,8), %r9
addq %rbp, %r9
leaq (%r9,%r9,2), %r9
addq %rbp, %r9
incq %rbp
movl 0x18(%r8,%r9), %r10d
andl %esi, %r10d
orl %edi, %r10d
movl %r10d, 0x18(%r8,%r9)
addq $0x1c, %rcx
cmpq %rcx, %rax
jne 0x1aba21
cmpq 0x30(%rsp), %r15
jne 0x1aba93
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
subq 0x8(%rcx), %rax
jmp 0x1abce5
xorl %eax, %eax
jmp 0x1abce5
testq %rbp, %rbp
jle 0x1abd13
testq %r14, %r14
js 0x1abccc
movq (%r11), %rax
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbp, %rcx
movl -0x4(%rax,%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl 0x8(%rax,%rdx), %eax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movq %r11, 0x10(%rsp)
movq (%r11), %rax
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
movl 0x8(%rax,%rcx), %edx
subq $-0x80, %rdx
cmpq 0x40(%rsp), %rdx
jb 0x1abccc
cmpq 0x30(%rsp), %r15
je 0x1abccc
movq %r15, 0x38(%rsp)
movq 0x50(%rsp), %rdx
movq (%rdx,%r14,8), %r14
movq %r14, 0x60(%rsp)
cmpq %rbp, %rbx
jge 0x1abca8
movl 0xc(%rax,%rcx), %edx
movl 0x18(%rax,%rcx), %esi
shrdl $0x1f, %edx, %esi
leaq (%rax,%rcx), %r13
movl %esi, 0x28(%rsp)
xorl $0x1, %esi
movl %esi, 0x24(%rsp)
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax), %r14
addq $0x18, %r14
xorl %r9d, %r9d
movq %rbx, %r8
movq (%r11), %rax
movl (%rax,%r14), %edx
andq %rdi, %rdx
cmpq %rdi, %rdx
je 0x1abc96
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movl 0x8(%rax,%rcx), %edx
movl 0x8(%r13), %esi
subq $-0x80, %rsi
cmpq %rdx, %rsi
jb 0x1abc96
leaq (%rax,%rcx), %r15
testq %r9, %r9
cmoveq %rbx, %r8
movl 0x4(%r13), %edx
movl 0x4(%r15), %esi
subq $-0x80, %rsi
movl $0x1, %r9d
cmpq %rdx, %rsi
jb 0x1abc96
movq %r8, 0x18(%rsp)
movl 0xc(%rax,%rcx), %edx
movl 0x18(%rax,%rcx), %r12d
shrdl $0x1f, %edx, %r12d
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0xb8(%rsp), %r8
movq 0xc0(%rsp), %r9
callq 0x6ea22
cmpl %r12d, 0x28(%rsp)
jne 0x1abc09
movq 0x10(%rsp), %r11
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movq 0x18(%rsp), %r8
movl $0x1, %r9d
jmp 0x1abc96
xorl $0x1, %r12d
leaq 0x2c(%rsp), %rcx
movq %rcx, (%rsp)
xorl %edi, %edi
movq 0x48(%rsp), %rsi
movl 0x24(%rsp), %edx
movl %r12d, %ecx
movq 0xa8(%rsp), %r8
movsd 0x58(%rsp), %xmm0
movq %rax, %r9
callq 0x1ab134
testq %rax, %rax
je 0x1abbef
cmpl $0x0, 0x2c(%rsp)
movq 0x10(%rsp), %r11
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movq 0x18(%rsp), %r8
movl $0x1, %r9d
je 0x1abc96
movq (%r11), %rax
orl $0x3fffffff, (%rax,%r14) # imm = 0x3FFFFFFF
movq 0x8(%rsp), %rcx
movq %rcx, %rax
cmpl $0x0, 0xb0(%rsp)
jne 0x1abc86
xorl %eax, %eax
testb $0x40, 0x1b(%r15)
sete %al
leaq (%rcx,%rax,8), %rax
movl 0x14(%r15), %ecx
subl 0x10(%r15), %ecx
incq 0x38(%rsp)
subq %rcx, (%rax)
incq %rbx
addq $0x1c, %r14
cmpq %rbx, %rbp
jne 0x1abb5d
jmp 0x1abcab
movq %rbx, %r8
movq 0x60(%rsp), %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq %r8, %rbx
cmpl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq 0x38(%rsp), %r15
jne 0x1abae4
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
testq %rax, %rax
js 0x1abcf4
movq 0x8(%rcx), %rcx
testq %rcx, %rcx
js 0x1abcf4
subq %rcx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x94a07(%rip), %rdi     # 0x240702
leaq 0x93f59(%rip), %rsi     # 0x23fc5b
leaq 0x9494d(%rip), %rcx     # 0x240656
movl $0xe6d, %edx            # imm = 0xE6D
callq 0x2110
leaq 0x94937(%rip), %rdi     # 0x240651
leaq 0x93f3a(%rip), %rsi     # 0x23fc5b
leaq 0x9492e(%rip), %rcx     # 0x240656
movl $0xe52, %edx            # imm = 0xE52
callq 0x2110