// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movl %edi, %ebp
movq 0x8(%rsi), %r12
pushq $0xc
popq %rax
movq %r12, %rcx
subq $0x1, %rcx
jb 0x18c15a
movq (%r14), %rdx
movl 0xc(%rdx,%rax), %esi
shldl $0x1, %esi, (%rdx,%rax)
addq $0x1c, %rax
jmp 0x18c142
movq (%r14), %rdi
imulq $0x1c, %r12, %rsi
addq %rdi, %rsi
callq 0x1574e1
movq 0x98(%rsp), %rax
andq $0x0, (%rax)
pushq $0x1
popq %r13
pushq $0x28
popq %r15
xorl %ebx, %ebx
xorl %eax, %eax
cmpq %r12, %r13
ja 0x18c256
imulq $0x1c, %rax, %rdx
movq (%r14), %rsi
movl 0xc(%rsi,%rdx), %ecx
cmpq %r13, %r12
je 0x18c1a9
movl (%rsi,%r15), %edi
xorl %ecx, %edi
cmpl $0x2, %edi
jb 0x18c24a
shrl %ecx
cmpl $0x0, 0x90(%rsp)
je 0x18c1bd
cmpl %ebp, %ecx
je 0x18c247
addq %rdx, %rsi
movq %r13, %rdx
subq %rax, %rdx
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r9
movsd 0x10(%rsp), %xmm0
movsd 0x5731f(%rip), %xmm1    # 0x1e3510
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 0x18b60d
addq $0x40, %rsp
testq %rax, %rax
je 0x18c247
movq (%r14), %rax
imulq $0x1c, %rbx, %rcx
incq %rbx
movups 0x2c(%rsp), %xmm0
movups 0x38(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movq %r13, %rax
incq %r13
addq $0x1c, %r15
jmp 0x18c181
movq %rbx, 0x8(%r14)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq