// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: debug_ll_chains(ul_idx_t const*, unsigned long*, long, long, long, mg_lchain_t*, kv_ul_ov_t*, kv_ul_ov_t*, unsigned long*, long, double, long)
void debug_ll_chains(const ul_idx_t *uref, uint64_t *ix, int64_t ix_n, int64_t p_sidx, int64_t p_eidx, mg_lchain_t *chain_a,
kv_ul_ov_t *raw_idx, kv_ul_ov_t *raw_chn, uint64_t *b, int64_t bw, double diff_ec_ul, int64_t qlen)
{
	int64_t k, i, z, a_n, ss, ee, b_n; uint64_t qs, qe, ts, te; uint32_t mk = 0x80000000; mg_lchain_t nn;
	int64_t iqs, iqe, its, ite, tsc;
	
	for (k = p_sidx; k < p_eidx; k++) {
		i = raw_idx->a[chain_a[k].off].qn; 
		qs = raw_chn->a[i].qs; qe = raw_chn->a[i].qe;
		ts = raw_chn->a[i].ts; te = raw_chn->a[i].te;
		// fprintf(stderr, "++++++++++++[M::%s::idx:%ld]\n", __func__, i);
		for (;i>=0;) {
			// fprintf(stderr, "--[M::%s::i->%ld]\n", __func__, i);
			if(raw_chn->a[i].qs < qs) qs = raw_chn->a[i].qs;
        	if(raw_chn->a[i].ts < ts) ts = raw_chn->a[i].ts;
        	if(raw_chn->a[i].qe > qe) qe = raw_chn->a[i].qe;
        	if(raw_chn->a[i].te > te) te = raw_chn->a[i].te;
			raw_chn->a[i].qs |= mk;

			if(raw_chn->a[i].tn == (uint32_t)-1) i = -1;
			else i = raw_chn->a[i].tn;
		}
		assert(raw_idx->a[chain_a[k].off].qs == qs && raw_idx->a[chain_a[k].off].qe == qe && 
				raw_idx->a[chain_a[k].off].ts == ts && raw_idx->a[chain_a[k].off].te == te);
	}


	///dedup
	for (z = a_n = 0; z < ix_n; ++z) {
		ss = a_n; ee = a_n + ((uint32_t)ix[z]); tsc = 0;
		/**if(ss != p_sidx || ee != p_eidx)**/ {
			for (k = ss; k < ee; k++) {
				i = raw_idx->a[chain_a[k].off].qn; b_n = 0;
				qs = ((raw_chn->a[i].qs<<1)>>1); qe = raw_chn->a[i].qe;
				ts = raw_chn->a[i].ts; te = raw_chn->a[i].te;
				// fprintf(stderr, "++++++++++++[M::%s::idx:%ld]\n", __func__, i);
				for (;i>=0;) {
					// fprintf(stderr, "--[M::%s::i->%ld]\n", __func__, i);
					if(((raw_chn->a[i].qs<<1)>>1) < qs) qs = ((raw_chn->a[i].qs<<1)>>1);
					if(raw_chn->a[i].ts < ts) ts = raw_chn->a[i].ts;
					if(raw_chn->a[i].qe > qe) qe = raw_chn->a[i].qe;
					if(raw_chn->a[i].te > te) te = raw_chn->a[i].te;
					// raw_chn->a[i].qs |= mk;
					//update here!!!!!!!
					// if(!(raw_chn->a[i].qs&mk)) b[b_n++] = i;
					b[b_n++] = i;
					if(raw_chn->a[i].tn == (uint32_t)-1) i = -1;
					else i = raw_chn->a[i].tn;
				}
				assert(raw_idx->a[chain_a[k].off].qs == qs && raw_idx->a[chain_a[k].off].qe == qe && 
						raw_idx->a[chain_a[k].off].ts == ts && raw_idx->a[chain_a[k].off].te == te);
				
				update_exist_chain(uref, raw_chn->a, b, b_n, raw_idx->a[chain_a[k].off].tn, bw, diff_ec_ul, &nn);
				nn.v = (raw_idx->a[chain_a[k].off].tn<<1)|raw_idx->a[chain_a[k].off].rev;
				extend_end_coord(&nn, NULL, qlen, uref->ug->g->seq[raw_idx->a[chain_a[k].off].tn].len, 
				&iqs, &iqe, &its, &ite);
				nn.qs = iqs; nn.qe = iqe; nn.rs = its; nn.re = ite;
				if(!(chain_a[k].score == nn.score && chain_a[k].qs == nn.qs && chain_a[k].qe == nn.qe 
															&& chain_a[k].rs == nn.rs && chain_a[k].re == nn.re)){
					fprintf(stderr, "[M::%s::] chain_a[k].score->%d, nn.score->%d\n", __func__, chain_a[k].score, nn.score);
					fprintf(stderr, "[M::%s::] chain_a[k].qs->%d, nn.qs->%d, chain_a[k].qe->%d, nn.qe->%d, chain_a[k].rs->%d, nn.rs->%d, chain_a[k].re->%d, nn.re->%d\n", __func__, 
					chain_a[k].qs, nn.qs, chain_a[k].qe, nn.qe, chain_a[k].rs, nn.rs, chain_a[k].re, nn.re);
				}
				assert(chain_a[k].score == nn.score && chain_a[k].qs == nn.qs && chain_a[k].qe == nn.qe 
															&& chain_a[k].rs == nn.rs && chain_a[k].re == nn.re);
				tsc += nn.score;
			}
			assert(tsc >= ((int64_t)(ix[z]>>32)));
		}

		a_n += ((uint32_t)ix[z]);
	}



	for (k = p_sidx; k < p_eidx; k++) {
		i = raw_idx->a[chain_a[k].off].qn; 
		qs = ((raw_chn->a[i].qs<<1)>>1); qe = raw_chn->a[i].qe;
		ts = raw_chn->a[i].ts; te = raw_chn->a[i].te;
		for (;i>=0;) {
			// fprintf(stderr, "--[M::%s::i->%ld]\n", __func__, i);
			if(raw_chn->a[i].qs&mk) raw_chn->a[i].qs -= mk;
			if(raw_chn->a[i].qs < qs) qs = raw_chn->a[i].qs;
        	if(raw_chn->a[i].ts < ts) ts = raw_chn->a[i].ts;
        	if(raw_chn->a[i].qe > qe) qe = raw_chn->a[i].qe;
        	if(raw_chn->a[i].te > te) te = raw_chn->a[i].te;
			

			if(raw_chn->a[i].tn == (uint32_t)-1) i = -1;
			else i = raw_chn->a[i].tn;
		}
		assert(raw_idx->a[chain_a[k].off].qs == qs && raw_idx->a[chain_a[k].off].qe == qe && 
				raw_idx->a[chain_a[k].off].ts == ts && raw_idx->a[chain_a[k].off].te == te);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm0, 0x78(%rsp)
movq %r9, 0x8(%rsp)
movq %r8, 0x40(%rsp)
movq %rdx, %rbp
movq %rsi, 0x38(%rsp)
movq %rdi, 0x70(%rsp)
movq 0x100(%rsp), %r13
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq $-0x1
popq %r14
movq %rcx, 0x48(%rsp)
cmpq 0x40(%rsp), %rcx
jge 0x1856d4
movq 0xf0(%rsp), %rdx
movq (%rdx), %rsi
imulq $0x28, %rcx, %rdx
movq 0x8(%rsp), %rdi
movslq (%rdi,%rdx), %rdx
imulq $0x1c, %rdx, %rdi
leaq (%rsi,%rdi), %rdx
movl (%rsi,%rdi), %r11d
movq 0xf8(%rsp), %rsi
movq (%rsi), %r10
imulq $0x1c, %r11, %rsi
movl 0x4(%r10,%rsi), %r9d
movl 0x8(%r10,%rsi), %r8d
movl 0x10(%r10,%rsi), %edi
movl 0x14(%r10,%rsi), %esi
testq %r11, %r11
js 0x18568b
imulq $0x1c, %r11, %r11
movl 0x4(%r10,%r11), %ebx
movl 0x8(%r10,%r11), %r15d
cmpq %rbx, %r9
cmovaeq %rbx, %r9
movl 0x10(%r10,%r11), %r12d
cmpq %r12, %rdi
cmovaeq %r12, %rdi
cmpq %r15, %r8
cmovbeq %r15, %r8
movl 0x14(%r10,%r11), %r15d
cmpq %r15, %rsi
cmovbeq %r15, %rsi
orl $0x80000000, %ebx       # imm = 0x80000000
movl %ebx, 0x4(%r10,%r11)
movl 0xc(%r10,%r11), %r11d
cmpq %rax, %r11
cmoveq %r14, %r11
jmp 0x185639
movl 0x4(%rdx), %r10d
cmpq %r10, %r9
jne 0x1856b5
movl 0x8(%rdx), %r9d
cmpq %r9, %r8
jne 0x1856b5
movl 0x10(%rdx), %r8d
cmpq %r8, %rdi
jne 0x1856b5
movl 0x14(%rdx), %edx
incq %rcx
cmpq %rdx, %rsi
je 0x1855e7
leaq 0x6efd0(%rip), %rdi     # 0x1f468c
leaq 0x6c460(%rip), %rsi     # 0x1f1b23
leaq 0x6f05b(%rip), %rcx     # 0x1f4725
movl $0x39c5, %edx           # imm = 0x39C5
callq 0x2110
xorl %eax, %eax
testq %rbp, %rbp
cmovleq %rax, %rbp
movq %rbp, 0x50(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
xorl %edx, %edx
cmpq 0x50(%rsp), %rdx
je 0x185a02
movq 0x38(%rsp), %rax
movq %rdx, 0x60(%rsp)
movl (%rax,%rdx,8), %eax
addq %rcx, %rax
movq %rax, 0x80(%rsp)
movq %rcx, 0x58(%rsp)
movq %rcx, %rdx
xorl %esi, %esi
cmpq 0x80(%rsp), %rdx
jae 0x1859d2
movq %rsi, 0x90(%rsp)
movq 0xf0(%rsp), %rax
movq (%rax), %rcx
movq %rdx, 0x88(%rsp)
imulq $0x28, %rdx, %rax
movq 0x8(%rsp), %rdx
leaq (%rdx,%rax), %rbp
movslq (%rdx,%rax), %rax
imulq $0x1c, %rax, %rdx
leaq (%rcx,%rdx), %rax
movl (%rcx,%rdx), %r10d
movq 0xf8(%rsp), %rcx
movq (%rcx), %rsi
imulq $0x1c, %r10, %rcx
movl 0x4(%rsi,%rcx), %r9d
movl 0x8(%rsi,%rcx), %edi
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl 0x10(%rsi,%rcx), %r8d
movl 0x14(%rsi,%rcx), %edx
xorl %ecx, %ecx
testq %r10, %r10
js 0x1857de
imulq $0x1c, %r10, %r11
movl 0x4(%rsi,%r11), %ebx
movl 0x8(%rsi,%r11), %r15d
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cmpq %rbx, %r9
cmovaeq %rbx, %r9
movl 0x10(%rsi,%r11), %ebx
cmpq %rbx, %r8
cmovaeq %rbx, %r8
cmpq %r15, %rdi
cmovbeq %r15, %rdi
movl 0x14(%rsi,%r11), %ebx
cmpq %rbx, %rdx
cmovbeq %rbx, %rdx
movq %r10, (%r13,%rcx,8)
incq %rcx
movl 0xc(%rsi,%r11), %r10d
cmpq %r12, %r10
cmoveq %r14, %r10
jmp 0x185789
movl 0x4(%rax), %r10d
cmpq %r10, %r9
jne 0x185b3f
movl 0x8(%rax), %r9d
cmpq %r9, %rdi
jne 0x185b3f
movl 0x10(%rax), %edi
cmpq %rdi, %r8
jne 0x185b3f
movl 0x14(%rax), %edi
cmpq %rdi, %rdx
jne 0x185b3f
movl 0xc(%rax), %r8d
subq $0x8, %rsp
movq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rdx
movq 0x110(%rsp), %r9
movsd 0x80(%rsp), %xmm0
leaq 0x18(%rsp), %r15
pushq %r15
callq 0x1852e6
popq %rax
popq %rcx
movq 0xf0(%rsp), %rax
movq (%rax), %rax
movslq (%rbp), %rcx
imulq $0x1c, %rcx, %rcx
movl 0xc(%rax,%rcx), %edx
movl 0x18(%rax,%rcx), %eax
shrdl $0x1f, %edx, %eax
movl %eax, 0x18(%rsp)
movq (%rbx), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %r15, %rdi
xorl %esi, %esi
movq 0x110(%rsp), %rdx
leaq 0xb0(%rsp), %r8
leaq 0xa8(%rsp), %r9
leaq 0x98(%rsp), %rax
pushq %rax
leaq 0xa8(%rsp), %rax
pushq %rax
callq 0x184214
popq %rax
popq %rcx
movl 0xb0(%rsp), %edi
movl %edi, 0x24(%rsp)
movl 0xa8(%rsp), %esi
movl %esi, 0x28(%rsp)
movl 0xa0(%rsp), %edx
movl %edx, 0x1c(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x1c(%rbp), %ecx
movl 0x2c(%rsp), %r8d
cmpl %r8d, %ecx
jne 0x185900
cmpl %edi, 0x14(%rbp)
jne 0x185900
cmpl %esi, 0x18(%rbp)
jne 0x185900
cmpl %edx, 0xc(%rbp)
jne 0x185900
cmpl %eax, 0x10(%rbp)
je 0x185980
movq 0xcd6d9(%rip), %rbx     # 0x252fe0
movq (%rbx), %rdi
leaq 0x6eeb3(%rip), %rsi     # 0x1f47c4
leaq 0x6eeda(%rip), %rdx     # 0x1f47f2
xorl %eax, %eax
callq 0x22b0
movq (%rbx), %rdi
movl 0x14(%rbp), %ecx
movl 0x24(%rsp), %r8d
movl 0x18(%rbp), %r9d
movl 0x28(%rsp), %eax
movq %rax, 0x68(%rsp)
movl 0xc(%rbp), %r11d
movl 0x10(%rbp), %ebx
movl 0x1c(%rsp), %r15d
movl 0x20(%rsp), %r10d
subq $0x8, %rsp
leaq 0x6eeaf(%rip), %rsi     # 0x1f4802
leaq 0x6ee98(%rip), %rdx     # 0x1f47f2
xorl %eax, %eax
pushq %r10
pushq %rbx
pushq %r15
pushq %r11
pushq 0x90(%rsp)
callq 0x22b0
addq $0x30, %rsp
movl 0x2c(%rsp), %ecx
cmpl %ecx, 0x1c(%rbp)
jne 0x185b20
movl 0x14(%rbp), %eax
cmpl 0x24(%rsp), %eax
jne 0x185b20
movl 0x18(%rbp), %eax
cmpl 0x28(%rsp), %eax
jne 0x185b20
movl 0xc(%rbp), %eax
cmpl 0x1c(%rsp), %eax
jne 0x185b20
movl 0x10(%rbp), %eax
cmpl 0x20(%rsp), %eax
jne 0x185b20
movslq %ecx, %rax
movq 0x90(%rsp), %rsi
addq %rax, %rsi
movq 0x88(%rsp), %rdx
incq %rdx
jmp 0x185719
movq 0x38(%rsp), %rax
movq 0x60(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
cmpq %rcx, %rsi
jl 0x185b5e
movl %eax, %eax
movq 0x58(%rsp), %rcx
addq %rax, %rcx
incq %rdx
jmp 0x1856ec
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x48(%rsp), %r15
cmpq 0x40(%rsp), %r15
jge 0x185b0e
movq 0xf0(%rsp), %rcx
movq (%rcx), %rdx
imulq $0x28, %r15, %rcx
movq 0x8(%rsp), %rsi
movslq (%rsi,%rcx), %rcx
imulq $0x1c, %rcx, %rsi
leaq (%rdx,%rsi), %rcx
movl (%rdx,%rsi), %r10d
movq 0xf8(%rsp), %rdx
movq (%rdx), %r9
imulq $0x1c, %r10, %rdx
movl 0x4(%r9,%rdx), %r8d
movl 0x8(%r9,%rdx), %esi
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl 0x10(%r9,%rdx), %edi
movl 0x14(%r9,%rdx), %edx
testq %r10, %r10
js 0x185ac6
imulq $0x1c, %r10, %r10
movl 0x4(%r9,%r10), %r11d
testl %r11d, %r11d
jns 0x185a8a
leaq (%r9,%r10), %rbx
addq $0x4, %rbx
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl %r11d, (%rbx)
movl %r11d, %r11d
cmpq %r11, %r8
cmovaeq %r11, %r8
movl 0x10(%r9,%r10), %r11d
cmpq %r11, %rdi
cmovaeq %r11, %rdi
movl 0x8(%r9,%r10), %r11d
cmpq %r11, %rsi
cmovbeq %r11, %rsi
movl 0x14(%r9,%r10), %r11d
cmpq %r11, %rdx
cmovbeq %r11, %rdx
movl 0xc(%r9,%r10), %r10d
cmpq %rax, %r10
cmoveq %r14, %r10
jmp 0x185a65
movl 0x4(%rcx), %r9d
cmpq %r9, %r8
jne 0x185aef
movl 0x8(%rcx), %r8d
cmpq %r8, %rsi
jne 0x185aef
movl 0x10(%rcx), %esi
cmpq %rsi, %rdi
jne 0x185aef
movl 0x14(%rcx), %ecx
incq %r15
cmpq %rcx, %rdx
je 0x185a0c
leaq 0x6eb96(%rip), %rdi     # 0x1f468c
leaq 0x6c026(%rip), %rsi     # 0x1f1b23
leaq 0x6ec21(%rip), %rcx     # 0x1f4725
movl $0x3a0a, %edx           # imm = 0x3A0A
callq 0x2110
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ed5d(%rip), %rdi     # 0x1f4884
leaq 0x6bff5(%rip), %rsi     # 0x1f1b23
leaq 0x6ebf0(%rip), %rcx     # 0x1f4725
movl $0x39ee, %edx           # imm = 0x39EE
callq 0x2110
leaq 0x6eb46(%rip), %rdi     # 0x1f468c
leaq 0x6bfd6(%rip), %rsi     # 0x1f1b23
leaq 0x6ebd1(%rip), %rcx     # 0x1f4725
movl $0x39e0, %edx           # imm = 0x39E0
callq 0x2110
leaq 0x6eda4(%rip), %rdi     # 0x1f4909
leaq 0x6bfb7(%rip), %rsi     # 0x1f1b23
leaq 0x6ebb2(%rip), %rcx     # 0x1f4725
movl $0x39f1, %edx           # imm = 0x39F1
callq 0x2110