// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: old_path_ext(ul_resolve_t*, usg_t*, asg64_v*, asg64_v*, unsigned long, unsigned long, unsigned long*, unsigned long*, unsigned char*, unsigned int*, unsigned int)
uint64_t old_path_ext(ul_resolve_t *uidx, usg_t *ng, asg64_v *b64, asg64_v *ub64, uint64_t a_n, uint64_t n_clus, uint64_t *i_idx, uint64_t *int_a, 
uint8_t *ff, uint32_t *ng_occ, uint32_t max_ext)
{
    uint64_t k, i, z, /**s, e,**/ mm, tip_l;
    /**
    for (k = a_n + 1, i = a_n, mm = a_n; k <= b64->n; k++) {
        if(k == b64->n || (b64->a[k]>>32) != (b64->a[i]>>32)) {
            for (z = i; z < k; z++) {///all intger seqs within the same cluster
                s = b64->a[((uint32_t)b64->a[z])]>>32; 
                e = ((uint32_t)b64->a[((uint32_t)b64->a[z])]); assert(e > s);
                ///[s, e]:: available interval
                if(!ava_pass_unique_bridge(i_idx, int_a, s, e)) break;
            }
            if(z >= k) {///all arcs in this cluster is fine -> each of arch is reliable
                for (z = i; z < k; z++) b64->a[mm++] = b64->a[z];
            }
            i = k; n_clus--;
        }
    }
    assert(n_clus == 0);
    b64->n = mm; 
    **/
    // prt_thread_info(b64.a, a_n, NULL, 0, "tt5");
    // fprintf(stderr, "**4**[M::%s::] a_n::%lu, n_clus::%lu\n", __func__, a_n, n_clus);
    n_clus = 0;
    for (k = a_n + 1, i = a_n, mm = a_n; k <= b64->n; k++) {
        if(k == b64->n || (b64->a[k]>>32) != (b64->a[i]>>32)) {
            tip_l = ava_pass_unique_bridge_tips(ng, b64, i, k, int_a, ff, max_ext, 0.03, 16);
            if(tip_l < max_ext) {///no long tip
                if(/**(!tip_l) || (**/ava_pass_unique_bridge_cov(uidx, ng, b64, i, k, int_a, tip_l)) {
                    for (z = i; z < k; z++) {
                        b64->a[mm++] = b64->a[z];
                    }
                    n_clus++;
                }
            }
            i = k; 
        }
    }
    // prt_thread_info(b64.a, a_n, NULL, 0, "tt6");
    b64->n = mm;
    // fprintf(stderr, "**5**[M::%s::] a_n::%lu, n_clus::%lu, ng->n::%lu\n", __func__, a_n, n_clus, ng->n);
    // prt_thread_info(b64.a, a_n, b64.a + a_n, b64.n - a_n, "thred");
    if(n_clus > 0) {
        update_usg_t_threading(uidx, ng, b64->a, b64->a + a_n, b64->n - a_n, int_a, ng_occ, ub64);
    }
    // fprintf(stderr, "**6**[M::%s::] a_n::%lu, n_clus::%lu, ng->n::%lu\n", __func__, a_n, n_clus, ng->n);
    return n_clus;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
movq %rdi, 0x20(%rsp)
leaq 0x1(%r8), %rbx
movq (%rdx), %rax
cmpq %rax, %rbx
jbe 0x21bf19
movq %r8, (%r13)
jmp 0x21c045
movq %rsi, %r12
movq %rcx, 0x18(%rsp)
movq 0x68(%rsp), %rbp
movq $0x0, (%rsp)
movq %r8, %r14
movq %r8, 0x10(%rsp)
movq %r8, %r15
movq %rsi, 0x8(%rsp)
cmpq %rax, %rbx
je 0x21bf59
movq 0x10(%r13), %rax
movq (%rax,%r15,8), %rcx
xorq (%rax,%rbx,8), %rcx
shrq $0x20, %rcx
je 0x21bff9
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq 0x70(%rsp), %r9
movsd 0x29553(%rip), %xmm0    # 0x2454c8
pushq $0x10
movl 0x88(%rsp), %eax
pushq %rax
callq 0x218faa
addq $0x10, %rsp
cmpl 0x80(%rsp), %eax
jae 0x21bfdd
movl %eax, %eax
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rbp, %r12
movq %rbp, %r9
pushq %rax
callq 0x21bd08
addq $0x10, %rsp
testl %eax, %eax
je 0x21bfe2
cmpq %rbx, %r15
jae 0x21bfea
movq 0x10(%r13), %rax
movq %r12, %rbp
movq (%rax,%r15,8), %rcx
movq %rcx, (%rax,%r14,8)
incq %r14
incq %r15
cmpq %rbx, %r15
jb 0x21bfc8
jmp 0x21bfed
movq %rbx, %r15
jmp 0x21bff9
movq %rbx, %r15
movq %r12, %rbp
jmp 0x21bff4
movq %r12, %rbp
incq (%rsp)
movq %rbx, %r15
movq 0x8(%rsp), %r12
incq %rbx
movq (%r13), %rax
cmpq %rax, %rbx
jbe 0x21bf3e
movq %r14, (%r13)
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x21c045
movq 0x10(%r13), %rdx
movq 0x10(%rsp), %rax
leaq (%rdx,%rax,8), %rcx
subq %rax, %r14
movq %r12, %rsi
movq %r14, %r8
movq %rbp, %r9
pushq 0x18(%rsp)
pushq 0x80(%rsp)
callq 0x21a306
addq $0x10, %rsp
jmp 0x21c047
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq