// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movsd %xmm0, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movq 0x78(%rsp), %r14
movq 0x70(%rsp), %r12
movq 0x8(%rsi), %rax
movq %rax, 0x8(%rsp)
movq (%rdi), %rdi
imulq $0x1c, 0x8(%r15), %rsi
addq %rdi, %rsi
callq 0x1574e1
movq %r12, %r9
movq %r14, %r8
movq %rbx, %rdi
pushq $0x1
popq %rbp
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %rdi, (%rsp)
cmpq 0x8(%r15), %rbp
ja 0x1908e0
movq (%r15), %rcx
jne 0x19078b
imulq $0x1c, %rbx, %rax
movl 0xc(%rcx,%rax), %eax
jmp 0x1907a1
imulq $0x1c, %rbp, %rdx
imulq $0x1c, %rbx, %rax
movl 0xc(%rcx,%rax), %eax
cmpl %eax, 0xc(%rcx,%rdx)
je 0x1908d8
shrl %eax
imulq $0x1c, %rbx, %r13
leaq (%rcx,%r13), %rdx
addq $0xc, %rdx
movq %rbx, %rsi
cmpq %rbp, %rsi
jae 0x1907c2
shrl (%rdx)
incq %rsi
addq $0x1c, %rdx
jmp 0x1907b2
movl %eax, %eax
cmpq %r8, %r12
movq %r8, %rdx
cmovaq %r12, %rdx
cmpq %r8, %r12
jae 0x1907de
cmpq %rax, (%r9,%r12,8)
jae 0x1907e3
incq %r12
jmp 0x1907ce
movq %rdx, %r12
jmp 0x1907ed
jne 0x1907ed
movq %rbp, %rbx
jmp 0x1908d8
movq (%rdi), %rax
movq 0x8(%rsp), %rdx
subq %rbx, %rdx
addq %rbp, %rdx
cmpq %rdx, 0x10(%rdi)
jae 0x190852
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
incq %rcx
movq %rcx, 0x10(%rdi)
imulq $0x1c, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%r15), %rcx
imulq $0x1c, %rbx, %rdi
addq %rcx, %rdi
movq %rbp, %rsi
subq %rbx, %rsi
imulq $0x1c, 0x8(%rsp), %rdx
addq %rax, %rdx
subq $0x8, %rsp
movq 0x20(%rsp), %r8
movsd 0x28(%rsp), %xmm0
pushq 0x18(%rsp)
pushq 0x70(%rsp)
pushq $0xc350                 # imm = 0xC350
pushq $0x1388                 # imm = 0x1388
pushq $0x64
callq 0x18dcfa
addq $0x30, %rsp
addq %rbx, %rax
imulq $0x1c, %r14, %rcx
movq 0x78(%rsp), %r8
movq 0x70(%rsp), %r9
cmpq %rax, %rbx
jae 0x1908d1
movq (%r15), %rdx
incq %r14
movups (%rdx,%r13), %xmm0
movups 0xc(%rdx,%r13), %xmm1
movups %xmm1, 0xc(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
incq %rbx
addq $0x1c, %r13
addq $0x1c, %rcx
jmp 0x1908a5
movq %rbp, %rbx
movq (%rsp), %rdi
incq %rbp
jmp 0x190772
movq %r14, 0x8(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq