// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, %r12
movq %rdi, %rbx
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 0x19e855
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1de61a
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %r8
movl $0x1, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq (%rbx), %rdi
cmpq %rax, %r13
jne 0x1de44d
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %rax
addq %r15, %rax
movl 0xc(%rdi,%rax), %eax
jmp 0x1de478
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rcx
addq %r13, %rcx
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %rax
addq %r15, %rax
movl 0xc(%rdi,%rax), %eax
cmpl %eax, 0xc(%rdi,%rcx)
je 0x1de608
movq %r13, %rbp
subq %r15, %rbp
jbe 0x1de4a3
leaq (%r15,%r15,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r15, %rcx
addq %rdi, %rcx
addq $0xc, %rcx
movq %r15, %rdx
shrl (%rcx)
incq %rdx
addq $0x1c, %rcx
cmpq %rdx, %r13
jne 0x1de495
cmpq %rsi, %r14
jae 0x1de4c7
shrl %eax
cmpq %rax, (%r8,%r14,8)
jae 0x1de4bd
incq %r14
cmpq %r14, %rsi
jne 0x1de4aa
movq %rsi, %r14
jmp 0x1de4c7
jne 0x1de4c7
movq %r13, %r15
jmp 0x1de608
movq (%r12), %rax
movq 0x18(%rsp), %rcx
subq %r15, %rcx
addq %r13, %rcx
cmpq %rcx, 0x10(%r12)
jae 0x1de538
decq %rcx
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x10, %rdx
orq %rcx, %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x10(%r12)
leaq (%rcx,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx), %rsi
incq %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r12)
movq (%rbx), %rdi
leaq (%r15,%r15,8), %rcx
leaq (%rcx,%rcx,2), %r12
addq %r15, %rdi
addq %r12, %rdi
movq 0x18(%rsp), %rsi
leaq (%rsi,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rsi, %rdx
addq %rax, %rdx
subq $0x8, %rsp
movq %rbp, %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 0x1db1eb
addq $0x30, %rsp
leaq (%rax,%r15), %rcx
cmpq %rcx, %r15
jae 0x1de5f0
movq %rax, %rcx
movq 0x8(%rsp), %rsi
addq %rsi, %rax
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
addq %r15, %r12
movq 0x80(%rsp), %r8
movq (%rbx), %rsi
movups (%rsi,%r12), %xmm0
movups 0xc(%rsi,%r12), %xmm1
movups %xmm1, 0xc(%rsi,%rdx)
movups %xmm0, (%rsi,%rdx)
addq $0x1c, %rdx
addq $0x1c, %r12
decq %rcx
jne 0x1de5b5
movq %rax, 0x8(%rsp)
movq %r13, %r15
movq 0x10(%rsp), %r12
movq 0x88(%rsp), %rsi
jmp 0x1de608
movq %r13, %r15
movq 0x10(%rsp), %r12
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %r8
incq %r13
movq 0x8(%rbx), %rax
cmpq %rax, %r13
jbe 0x1de434
jmp 0x1de623
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq