// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movq 0x98(%rsp), %r15
movq 0x8(%rsi), %r14
movq (%rsi), %rdi
testq %r14, %r14
je 0x1d92f7
leaq 0xc(%rdi), %rax
movq %r14, %rcx
movl 0xc(%rax), %edx
shldl $0x1, %edx, (%rax)
addq $0x1c, %rax
decq %rcx
jne 0x1d91dc
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %r14, %rsi
addq %rdi, %rsi
callq 0x19e855
movq $0x0, (%r15)
movl $0x1, %r13d
movl $0x28, %r15d
xorl %eax, %eax
xorl %r12d, %r12d
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movq (%rbx), %rsi
movl 0xc(%rsi,%rcx), %edi
cmpq %r13, %r14
je 0x1d923d
movl (%rsi,%r15), %edx
xorl %edi, %edx
cmpl $0x2, %edx
jb 0x1d92e5
shrl %edi
cmpl $0x0, 0x90(%rsp)
je 0x1d9251
cmpl %ebp, %edi
je 0x1d92e2
addq %rcx, %rsi
movq %r13, %rdx
subq %rax, %rdx
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
leaq (%rdi,%rdi,4), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r9
movsd 0x10(%rsp), %xmm0
movsd 0x5833b(%rip), %xmm1    # 0x2315c0
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 0x1d824a
addq $0x40, %rsp
testq %rax, %rax
je 0x1d92e2
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 %r13, %rax
incq %r13
addq $0x1c, %r15
cmpq %r14, %r13
jbe 0x1d9217
jmp 0x1d9317
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %rdi, %r14
addq %rax, %r14
movq %r14, %rsi
callq 0x19e855
movq $0x0, (%r15)
xorl %r12d, %r12d
movq %r12, 0x8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq