// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_linear_rchains_dedup(kv_ul_ov_t*, kv_ul_ov_t*, asg_t const*, ug_opt_t const*, long, double, long, Chain_Data*, long, unsigned long*, unsigned long)
void gen_linear_rchains_dedup(kv_ul_ov_t *res, kv_ul_ov_t *buf, const asg_t *rg, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, int64_t qlen, Chain_Data* dp, int64_t ulid, uint64_t *flt, uint64_t flt_n)
{
	uint64_t k, l, z, an, m, bn = buf->n, fi, tn; 
    radix_sort_ul_ov_srt_tn(res->a, res->a + res->n);
    ///after this function, res keeps unitig alignment, while buf keeps read alignments
    for (k = 1, l = m = fi = 0; k <= res->n; k++) {
        if(k == res->n || res->a[k].tn != res->a[l].tn) {///qn <- (tn|rev)
			tn = res->a[l].tn>>1;
			for (z = l; z < k; z++) res->a[z].tn>>=1;
			for (; (fi<flt_n) && (flt[fi]<tn); fi++);
			if((fi>=flt_n) || (flt[fi]!=tn)) {
				kv_resize(ul_ov_t, *buf, bn+k-l); 
				an = l + linear_rchain_dp_adv(res->a+l, k-l, buf->a+bn, uopt, bw, diff_ec_ul, qlen, 
				UG_SKIP_N, UG_ITER_N, UG_DIS_N, dp, rg, ulid);
				for (z = l; z < an; z++) res->a[m++] = res->a[z];
			}
			l = k;
		}
    }
    res->n = m; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm0, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
movq 0x8(%rsi), %rax
movq %rax, 0x18(%rsp)
movq (%rdi), %rdi
movq 0x8(%rbx), %rsi
leaq (%rsi,%rsi,8), %rax
leaq (%rax,%rax,2), %rax
addq %rdi, %rsi
addq %rax, %rsi
callq 0x195abc
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1d4632
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %rdi
leaq -0x1(%rcx), %r8
movl $0x1, %r13d
xorl %ebp, %ebp
xorl %r12d, %r12d
movq $0x0, (%rsp)
movq 0x8(%rsp), %rsi
movq %r8, 0x10(%rsp)
cmpq %rax, %r13
je 0x1d446b
movq (%rbx), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r13, %rcx
movl 0xc(%rax,%rcx), %ecx
leaq (%r12,%r12,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %r12, %rdx
cmpl 0xc(%rax,%rdx), %ecx
je 0x1d4620
movq (%rbx), %rcx
leaq (%r12,%r12,8), %rax
leaq (%rax,%rax,2), %rdx
leaq (%rdx,%r12), %r15
movl 0xc(%rcx,%r15), %eax
movq %r13, %r14
subq %r12, %r14
jbe 0x1d44a2
addq %r12, %rdx
addq %rdx, %rcx
addq $0xc, %rcx
movq %r12, %rdx
shrl (%rcx)
incq %rdx
addq $0x1c, %rcx
cmpq %rdx, %r13
jne 0x1d4494
cmpq 0x88(%rsp), %rbp
setb %cl
jae 0x1d44f2
shrl %eax
cmpq %rax, (%rdi,%rbp,8)
jae 0x1d44d8
cmpq %rbp, %r8
je 0x1d44ea
leaq 0x1(%rbp), %rdx
cmpq %rax, 0x8(%rdi,%rbp,8)
movq %rdx, %rbp
jb 0x1d44b7
cmpq 0x88(%rsp), %rdx
setb %cl
movq %rdx, %rbp
testb %cl, %cl
je 0x1d44f2
cmpq %rax, (%rdi,%rbp,8)
jne 0x1d44f2
movq %r13, %r12
jmp 0x1d4620
movq 0x88(%rsp), %rbp
movq 0x18(%rsp), %rax
subq %r12, %rax
addq %r13, %rax
cmpq %rax, 0x10(%rsi)
jae 0x1d455e
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%rsi)
movq (%rsi), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq (%rbx), %rdi
addq %r15, %rdi
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rdx
addq %rcx, %rdx
addq (%rsi), %rdx
subq $0x8, %rsp
movq %r14, %rsi
movq 0x30(%rsp), %r8
movsd 0x38(%rsp), %xmm0
pushq 0x28(%rsp)
pushq 0x80(%rsp)
pushq $0xc350                 # imm = 0xC350
pushq $0x1388                 # imm = 0x1388
pushq $0x64
callq 0x1d110e
addq $0x30, %rsp
leaq (%rax,%r12), %rcx
cmpq %rcx, %r12
jae 0x1d460b
negq %rax
movq (%rsp), %rdi
leaq (%rdi,%rdi,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdi, %rcx
xorl %edx, %edx
movq 0x10(%rsp), %r8
movq (%rbx), %rsi
movups (%rsi,%r15), %xmm0
movups 0xc(%rsi,%r15), %xmm1
movups %xmm1, 0xc(%rsi,%rcx)
movups %xmm0, (%rsi,%rcx)
decq %rdx
addq $0x1c, %rcx
addq $0x1c, %r15
cmpq %rdx, %rax
jne 0x1d45cb
subq %rdx, %rdi
movq %rdi, (%rsp)
movq %r13, %r12
movq 0x8(%rsp), %rsi
movq 0x80(%rsp), %rdi
jmp 0x1d4620
movq %r13, %r12
movq 0x8(%rsp), %rsi
movq 0x80(%rsp), %rdi
movq 0x10(%rsp), %r8
incq %r13
movq 0x8(%rbx), %rax
cmpq %rax, %r13
jbe 0x1d4438
jmp 0x1d463a
movq $0x0, (%rsp)
movq (%rsp), %rax
movq %rax, 0x8(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq