// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_linear_chains_backup(kv_ul_ov_t*, kv_ul_ov_t*, ul_idx_t const*, ug_opt_t const*, long, double, long, long, glchain_t*, st_mt_t*)
void gen_linear_chains_backup(kv_ul_ov_t *res, kv_ul_ov_t *buf, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, int64_t qlen, int64_t max_skip, glchain_t *bufg, st_mt_t *bufs)
{
    uint64_t k, l, z, an, m;
    radix_sort_ul_ov_srt_tn(res->a, res->a + res->n);
    kv_resize(ul_ov_t, *buf, res->n); buf->n = res->n;
    for (k = 1, l = m = 0; k <= res->n; k++) {
        if(k == res->n || res->a[k].tn != res->a[l].tn) {///qn <- (tn|rev)
            kv_resize(uint64_t, bufg->srt.a, k-l); 
            kv_resize(uint64_t, *bufs, k-l); 
            for (z = l; z < k; z++) res->a[z].tn>>=1;
            // fprintf(stderr, "\n*[M::%s::] %c\tutg%.6d%c(%u)\tocc:[%lu, %lu)\n", __func__, "+-"[res->a[l].rev], (int32_t)(res->a[l].tn)+1, 
            // "lc"[uref->ug->u.a[res->a[l].tn].circ], uref->ug->u.a[res->a[l].tn].len, l, k);
            an = l + linear_chain_dp(res->a+l, k-l, buf->a+l, uref, uopt, bw, diff_ec_ul, qlen, max_skip, bufg->srt.a.a, bufs->a, uref->ug, l);
            for (z = l; z < an; z++) res->a[m++] = res->a[z];
            // fprintf(stderr, "#occ:[%lu, %lu)\n", l, an);
            l = k;
        }
    }
    res->n = m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm0, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
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
cmpq %rax, 0x10(%r14)
jae 0x1c5728
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(%r14)
movq (%r14), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r14)
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1c5934
movq %r14, 0x38(%rsp)
movl $0x1, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq %rax, %r13
je 0x1c5780
movq (%rbx), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r13, %rcx
movl 0xc(%rax,%rcx), %ecx
leaq (%r15,%r15,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %r15, %rdx
cmpl 0xc(%rax,%rdx), %ecx
je 0x1c5922
movq %r13, %r12
subq %r15, %r12
movq 0x98(%rsp), %rax
cmpq %r12, 0x50(%rax)
jae 0x1c57ef
leaq -0x1(%r12), %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 0x98(%rsp), %r14
movq %rax, 0x50(%r14)
movq 0x58(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x58(%r14)
movq 0xa0(%rsp), %rax
cmpq %r12, 0x8(%rax)
jae 0x1c5858
leaq -0x1(%r12), %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 0xa0(%rsp), %r14
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
cmpq %r15, %r13
jbe 0x1c5883
movq (%rbx), %rax
leaq (%r15,%r15,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r15, %rcx
addq %rcx, %rax
addq $0xc, %rax
movq %r15, %rcx
shrl (%rax)
incq %rcx
addq $0x1c, %rax
cmpq %rcx, %r13
jne 0x1c5875
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %r14
addq %r15, %r14
movq (%rbx), %rdi
addq %r14, %rdi
movq 0x38(%rsp), %rax
movq (%rax), %rdx
addq %r14, %rdx
movq 0xa0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rsi
movq %r15, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %r12, %rsi
movq 0x48(%rsp), %r9
movsd 0x50(%rsp), %xmm0
callq 0x1c47b9
leaq (%rax,%r15), %rcx
cmpq %rcx, %r15
jae 0x1c591f
negq %rax
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbp, %rcx
xorl %edx, %edx
movq (%rbx), %rsi
movups (%rsi,%r14), %xmm0
movups 0xc(%rsi,%r14), %xmm1
movups %xmm1, 0xc(%rsi,%rcx)
movups %xmm0, (%rsi,%rcx)
decq %rdx
addq $0x1c, %rcx
addq $0x1c, %r14
cmpq %rdx, %rax
jne 0x1c58f5
subq %rdx, %rbp
movq %r13, %r15
incq %r13
movq 0x8(%rbx), %rax
cmpq %rax, %r13
jbe 0x1c574d
jmp 0x1c5936
xorl %ebp, %ebp
movq %rbp, 0x8(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq