// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movsd %xmm0, 0x58(%rsp)
movq %r9, 0x10(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdi, 0x50(%rsp)
testl %r8d, %r8d
jle 0x1a2847
movq %rcx, %r11
movq 0xb0(%rsp), %r14
movl %r8d, %ecx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
movq %rcx, 0x38(%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 0x1a2801
btsq $0x1f, %r9
movq %r9, (%rdx,%rdi,8)
incq %r15
jmp 0x1a2826
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 0x1a27dc
cmpq 0x38(%rsp), %r15
jne 0x1a284e
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
subq 0x8(%rcx), %rax
jmp 0x1a2abf
xorl %eax, %eax
jmp 0x1a2abf
testq %rbp, %rbp
jle 0x1a2aed
testq %r14, %r14
js 0x1a2aa6
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, 0x48(%rsp)
xorl %ebx, %ebx
movl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
movq %r11, 0x18(%rsp)
movq (%r11), %rax
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
movl 0x8(%rax,%rcx), %edx
movq 0x60(%rsp), %rsi
movq (%rsi,%r14,8), %r9
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andq %rsi, %r9
cmpq %rsi, %r9
movq %r9, %rsi
movq $-0x1, %rdi
cmoveq %rdi, %rsi
subq $-0x80, %rdx
cmpq 0x48(%rsp), %rdx
jb 0x1a2aa6
cmpq 0x38(%rsp), %r15
je 0x1a2aa6
movq %r9, 0x68(%rsp)
movq %r15, 0x40(%rsp)
movq %rsi, 0x70(%rsp)
cmpq %rbp, %rbx
jge 0x1a2a88
movl 0xc(%rax,%rcx), %edx
movl 0x18(%rax,%rcx), %esi
shrdl $0x1f, %edx, %esi
leaq (%rax,%rcx), %r13
movl %esi, 0x30(%rsp)
xorl $0x1, %esi
movl %esi, 0x2c(%rsp)
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax), %r14
addq $0x18, %r14
xorl %r9d, %r9d
movq %rbx, %rdi
movq (%r11), %rax
movl (%rax,%r14), %edx
andq %r8, %rdx
cmpq %r8, %rdx
je 0x1a2a76
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 0x1a2a76
leaq (%rax,%rcx), %r12
testq %r9, %r9
cmoveq %rbx, %rdi
movl 0x4(%r13), %edx
movl 0x4(%r12), %esi
subq $-0x80, %rsi
movl $0x1, %r9d
cmpq %rdx, %rsi
jb 0x1a2a76
movq %rdi, 0x20(%rsp)
movl 0xc(%rax,%rcx), %edx
movl 0x18(%rax,%rcx), %r15d
shrdl $0x1f, %edx, %r15d
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0xc8(%rsp), %r8
movq 0xd0(%rsp), %r9
callq 0x6f050
cmpl %r15d, 0x30(%rsp)
jne 0x1a29e5
movq 0x18(%rsp), %r11
movl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rdi
movl $0x1, %r9d
jmp 0x1a2a76
xorl $0x1, %r15d
leaq 0x34(%rsp), %rcx
movq %rcx, (%rsp)
xorl %edi, %edi
movq 0x50(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl %r15d, %ecx
movq 0xb8(%rsp), %r8
movsd 0x58(%rsp), %xmm0
movq %rax, %r9
callq 0x1a21ba
testq %rax, %rax
je 0x1a29ca
cmpl $0x0, 0x34(%rsp)
movq 0x18(%rsp), %r11
movl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rdi
movl $0x1, %r9d
je 0x1a2a76
movq (%r11), %rax
orl $0x3fffffff, (%rax,%r14) # imm = 0x3FFFFFFF
movq 0x10(%rsp), %rcx
movq %rcx, %rax
cmpl $0x0, 0xc0(%rsp)
jne 0x1a2a64
xorl %eax, %eax
testb $0x40, 0x1b(%r12)
sete %al
leaq (%rcx,%rax,8), %rax
movl 0x14(%r12), %ecx
subl 0x10(%r12), %ecx
incq 0x40(%rsp)
subq %rcx, (%rax)
incq %rbx
addq $0x1c, %r14
cmpq %rbx, %rbp
jne 0x1a2937
jmp 0x1a2a8b
movq %rbx, %rdi
movq %rdi, %rbx
cmpl $0x7fffffff, 0x68(%rsp) # imm = 0x7FFFFFFF
movq 0x70(%rsp), %r14
movq 0x40(%rsp), %r15
jne 0x1a28a0
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
testq %rax, %rax
js 0x1a2ace
movq 0x8(%rcx), %rcx
testq %rcx, %rcx
js 0x1a2ace
subq %rcx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9195d(%rip), %rdi     # 0x234432
leaq 0x90eaf(%rip), %rsi     # 0x23398b
leaq 0x918a3(%rip), %rcx     # 0x234386
movl $0xe6d, %edx            # imm = 0xE6D
callq 0x2110
leaq 0x9188d(%rip), %rdi     # 0x234381
leaq 0x90e90(%rip), %rsi     # 0x23398b
leaq 0x91884(%rip), %rcx     # 0x234386
movl $0xe52, %edx            # imm = 0xE52
callq 0x2110