// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_chain_ul_cov(ul_resolve_t*, unsigned long*, unsigned long, unsigned long, unsigned long)
uint64_t get_chain_ul_cov(ul_resolve_t *uidx, uint64_t *a, uint64_t a_n, uint64_t bub_id, uint64_t inner_beg)
{
    if(a_n <= 0) return 0;
    uint64_t w = 0, bid, rev; uint32_t rt, beg, sink; 
    uidx->path.buf.n = 0;
    // kv_pushp(ul_sub_path_t, uidx->path, &p); memset(p, 0, sizeof((*p)));
    // p->bid = bub_id; p->beg = inner_beg; p->occ = a_n;

    bid = a[0]>>33; rev = (a[0]>>32)&1; 
    get_bubbles(uidx->bub, bid, rev==0?&rt:NULL, rev==1?&rt:NULL, NULL, NULL, NULL); beg = rt;

    bid = a[a_n-1]>>33; rev = (a[a_n-1]>>32)&1; 
    get_bubbles(uidx->bub, bid, rev==1?&rt:NULL, rev==0?&rt:NULL, NULL, NULL, NULL); sink = rt^1;








    // fprintf(stderr, "\n[M::%s::] # bubbles->%lu\n", __func__, a_n);
    // uint64_t k
    // for (k = 0; k < a_n; k++) {
    //     bid = a[k]>>33; rev = (a[k]>>32)&1;
    //     get_bubbles(uidx->bub, bid, rev==0?&rt:NULL, rev==1?&rt:NULL, NULL, NULL, NULL);
    //     // w += get_bub_ul_cov(a[k]>>33, ug, idx);
    //     fprintf(stderr, "[M::%s::] utg%.6d%c(%c)\n", __func__, (rt>>1)+1, "lc"[uidx->l1_ug->u.a[rt>>1].circ], "+-"[rt&1]);
    // }
    // if (a_n > 0) {
    //     bid = a[k-1]>>33; rev = (a[k-1]>>32)&1;
    //     get_bubbles(uidx->bub, bid, rev==1?&rt:NULL, rev==0?&rt:NULL, NULL, NULL, NULL); rt ^= 1;
    //     fprintf(stderr, "[M::%s::] utg%.6d%c(%c)\n", __func__, (rt>>1)+1, "lc"[uidx->l1_ug->u.a[rt>>1].circ], "+-"[rt&1]);
    // }
    // clean_path_g(&(uidx->path), uidx->l1_ug->g);
    ma_utg_t *p; 
    kv_resize(uint8_t, uidx->buf.us, uidx->l1_ug->g->n_seq); uidx->buf.us.n = uidx->l1_ug->g->n_seq; memset(uidx->buf.us.a, 0, uidx->buf.us.n*sizeof(*(uidx->buf.us.a)));
    hc_simple_traversal(uidx->bub, uidx->l1_ug->g, &(uidx->l1_ug->u), &(uidx->buf), uidx->idx, beg, sink, &(uidx->path));
    hc_simple_traversal(uidx->bub, uidx->l1_ug->g, &(uidx->l1_ug->u), &(uidx->buf), uidx->idx, beg, sink, &(uidx->path));
    
    kv_pushp(ma_utg_t, uidx->path.buf_ug->u, &p); p->len = p->circ = p->n = 0; 
    p->start = p->end = UINT32_MAX; p->a = NULL; p->s = NULL; kv_push(uint64_t, *p, beg);

    kv_pushp(ma_utg_t, uidx->path.buf_ug->u, &p); p->len = p->circ = p->n = 0; 
    p->start = p->end = UINT32_MAX; p->a = NULL; p->s = NULL; kv_push(uint64_t, *p, sink);

    return w;
}

// Assembly:
testq %rdx, %rdx
je 0x1b21b2
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
andq $0x0, 0x40(%rdi)
leaq 0x38(%rdi), %rbp
movq (%rsi), %rax
movq %rax, %rsi
shrq $0x21, %rsi
movq 0x28(%rdi), %rdi
movq %rax, %rcx
shlq $0x1f, %rcx
sarq $0x3f, %rcx
xorl %r13d, %r13d
btq $0x20, %rax
leaq 0x14(%rsp), %rbx
movl $0x0, %edx
cmovaeq %rbx, %rdx
andq %rbx, %rcx
subq $0x8, %rsp
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
callq 0xf6ab5
popq %rax
popq %rcx
movl (%rbx), %eax
movq %rax, 0x8(%rsp)
movq -0x8(%r12,%r15,8), %rax
movq %rax, %rsi
shrq $0x21, %rsi
movq 0x28(%r14), %rdi
movq %rax, %rdx
shlq $0x1f, %rdx
sarq $0x3f, %rdx
andq %rbx, %rdx
btq $0x20, %rax
cmovaeq %rbx, %r13
subq $0x8, %rsp
movq %r13, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
callq 0xf6ab5
popq %rax
popq %rcx
movl (%rbx), %r12d
xorq $0x1, %r12
leaq 0x60(%r14), %r15
movq 0x18(%r14), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, 0xe0(%r14)
jae 0x1b205a
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0xe0(%r14)
movq 0xe8(%r14), %rdi
callq 0x2370
movq %rax, %rdi
movq %rax, 0xe8(%r14)
movq 0x18(%r14), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x1b2061
movq 0xe8(%r14), %rdi
movq %rdx, 0xd8(%r14)
xorl %esi, %esi
callq 0x20e0
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rdi
movq 0x18(%rdx), %rsi
movq 0x30(%r14), %r8
movq %r15, %rcx
movq 0x8(%rsp), %r13
movl %r13d, %r9d
pushq %rbp
pushq %r12
callq 0x1b1aeb
popq %rcx
popq %rdx
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rdi
movq 0x18(%rdx), %rsi
movq 0x30(%r14), %r8
movq %r15, %rcx
movl %r13d, %r9d
pushq %rbp
pushq %r12
callq 0x1b1aeb
popq %rcx
popq %rdx
movq 0x38(%r14), %rax
movq (%rax), %rcx
pushq $0x2
popq %r15
cmpq 0x8(%rax), %rcx
jne 0x1b20f1
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r15, %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rax), %rdi
imulq $0x28, %rdx, %rsi
callq 0x2370
movq %rax, %r14
movq (%rbp), %rax
movq %r14, 0x10(%rax)
movq (%rax), %rcx
jmp 0x1b20f5
movq 0x10(%rax), %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
imulq $0x28, %rcx, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14,%rbx)
movaps 0x452b0(%rip), %xmm0    # 0x1f73c0
movups %xmm0, (%r14,%rbx)
pushq $0x10
popq %rdi
callq 0x2280
movq %rax, 0x18(%r14,%rbx)
movl $0x1, 0x10(%r14,%rbx)
movq %r13, (%rax)
movq (%rbp), %rax
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x1b2167
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r15, %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rax), %rdi
imulq $0x28, %rdx, %rsi
callq 0x2370
movq %rax, %rbx
movq (%rbp), %rax
movq %rbx, 0x10(%rax)
movq (%rax), %rcx
jmp 0x1b216b
movq 0x10(%rax), %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
imulq $0x28, %rcx, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx,%r14)
movaps 0x4523a(%rip), %xmm0    # 0x1f73c0
movups %xmm0, (%rbx,%r14)
pushq $0x10
popq %rdi
callq 0x2280
movq %rax, 0x18(%rbx,%r14)
movl $0x1, 0x10(%rbx,%r14)
movq %r12, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq