// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: ctg_trans_gp_chain(unsigned int, kv_ul_ov_t*, ul_idx_t const*, ug_opt_t const*, long, double, long, Chain_Data*, ma_ug_t*, unsigned int, asg64_v*, double)
void ctg_trans_gp_chain(uint32_t qid, kv_ul_ov_t *res, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, int64_t qlen, Chain_Data* dp, ma_ug_t *ref, uint32_t is_self, asg64_v *b, double unmatch_max)
{
	uint64_t k, l, m = 0, rn = res->n; ul_ov_t rr; uint32_t avid = ((is_self)?(qid):((uint32_t)-1));
	for (k = 0; k < rn; k++) {
		res->a[k].tn <<= 1; res->a[k].tn |= res->a[k].rev;
	}
	radix_sort_ul_ov_srt_tn(res->a, res->a + rn);

	for (k = 1, l = 0, b->n = 0; k <= rn; k++) {
		if((k == rn) || ((res->a[l].tn>>1) != (res->a[k].tn>>1))) {
			// fprintf(stderr, "+[M::%s]\tutg%.6ul\n", __func__, (res->a[l].tn>>1) + 1);
			if(((res->a[l].tn>>1) != avid) && (linear_ctg_trans_chain_dp(qid, res->a+l, k-l, uref, uopt, bw, diff_ec_ul, /**0.333333**/0.4, unmatch_max, qlen, ref->u.a[(res->a[l].tn>>1)].len, UG_SKIP_N, UG_ITER_N, UG_DIS_N, dp, &rr, b))) {
				res->a[m++] = rr; 
				// fprintf(stderr, "-[M::%s]\tutg%.6ul\n", __func__, rr.tn + 1);
			}
			l = k;
		}
	}
	res->n = m;

	// for (k = 0; k < res->n; k++) {
    //     fprintf(stderr, "[M::%s]\tutg%.6ul(len::%ld)\tq::[%u, %u)\t%c\tutg%.6ul(len::%u)\tt::[%u, %u)\tel::%u\ttp::%u\n", __func__, qid + 1, qlen, res->a[k].qs, res->a[k].qe, "+-"[res->a[k].rev], res->a[k].tn+1, ref->u.a[res->a[k].tn].len, res->a[k].ts, res->a[k].te, res->a[k].el, res->a[k].qn);
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm1, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movq %r8, 0x8(%rsp)
movq %rsi, %rbx
movl %edi, 0x4(%rsp)
movq 0x8(%rsi), %r13
testq %r13, %r13
je 0x1cf183
movq (%rbx), %rax
addq $0xc, %rax
movq %r13, %rcx
movl 0xc(%rax), %edx
shldl $0x1, %edx, (%rax)
addq $0x1c, %rax
decq %rcx
jne 0x1cf173
movq (%rbx), %rdi
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %r13, %rsi
callq 0x195abc
movq 0x98(%rsp), %rax
movq $0x0, (%rax)
testq %r13, %r13
je 0x1cf2bc
movl 0x90(%rsp), %ebp
movl $0x1, %r14d
movl $0x28, %r15d
xorl %eax, %eax
xorl %r12d, %r12d
cmpq %r14, %r13
je 0x1cf1f4
movq (%rbx), %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
movl (%rcx,%r15), %esi
xorl 0xc(%rcx,%rdx), %esi
cmpl $0x2, %esi
jb 0x1cf2aa
movq (%rbx), %rsi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rax, %rdx
movl 0xc(%rsi,%rdx), %ecx
shrl %ecx
testl %ebp, %ebp
je 0x1cf216
cmpl 0x4(%rsp), %ecx
je 0x1cf2a7
addq %rdx, %rsi
movq %r14, %rdx
subq %rax, %rdx
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r9
movsd 0x10(%rsp), %xmm0
movsd 0x56276(%rip), %xmm1    # 0x2254c0
movsd 0x20(%rsp), %xmm2
pushq 0x98(%rsp)
leaq 0x34(%rsp), %rcx
pushq %rcx
pushq 0x90(%rsp)
pushq $0xc350                 # imm = 0xC350
pushq $0x1388                 # imm = 0x1388
pushq $0x64
pushq %rax
pushq 0x50(%rsp)
callq 0x1ce2aa
addq $0x40, %rsp
testq %rax, %rax
je 0x1cf2a7
movq (%rbx), %rax
leaq (%r12,%r12,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r12, %rcx
incq %r12
movups 0x2c(%rsp), %xmm0
movups 0x38(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movq %r14, %rax
incq %r14
addq $0x1c, %r15
cmpq %r13, %r14
jbe 0x1cf1d0
jmp 0x1cf2bf
xorl %r12d, %r12d
movq %r12, 0x8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq