// File: /workspace/github_cpp_makefile_star2_O3/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 0x1fe0f1
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq 0x38(%rdi), %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movq %rbp, 0x40(%rdi)
movq (%rsi), %rax
movq %rax, %rsi
shrq $0x21, %rsi
movq 0x28(%rdi), %rdi
movq %rax, %rcx
shlq $0x1f, %rcx
sarq $0x3f, %rcx
btq $0x20, %rax
leaq 0x14(%rsp), %r13
movl $0x0, %edx
cmovaeq %r13, %rdx
andq %r13, %rcx
subq $0x8, %rsp
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbp
callq 0x13df01
addq $0x10, %rsp
movl (%r13), %ebx
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 %r13, %rdx
btq $0x20, %rax
movl $0x0, %ecx
cmovaeq %r13, %rcx
subq $0x8, %rsp
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbp
callq 0x13df01
addq $0x10, %rsp
movl (%r13), %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 0x1fdf81
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 0x1fdf88
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
movl %ebx, %r9d
movq 0x8(%rsp), %r13
pushq %r13
pushq %r12
callq 0x1fd972
addq $0x10, %rsp
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rdi
movq 0x18(%rdx), %rsi
movq 0x30(%r14), %r8
movq %r15, %rcx
movl %ebx, %r9d
pushq %r13
pushq %r12
callq 0x1fd972
addq $0x10, %rsp
movq 0x38(%r14), %rax
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x1fe023
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x2370
movq %rax, %r14
movq (%r13), %rax
movq %r14, 0x10(%rax)
movq (%rax), %rcx
jmp 0x1fe027
movq 0x10(%rax), %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
leaq (%rcx,%rcx,4), %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14,%r15,8)
movaps 0x474ae(%rip), %xmm0    # 0x2454f0
movups %xmm0, (%r14,%r15,8)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x18(%r14,%r15,8)
movl $0x1, 0x10(%r14,%r15,8)
movq %rbx, (%rax)
movq (%r13), %rax
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x1fe0a4
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x2370
movq %rax, %rbx
movq (%r13), %rax
movq %rbx, 0x10(%rax)
movq (%rax), %rcx
jmp 0x1fe0a8
movq 0x10(%rax), %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
leaq (%rcx,%rcx,4), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx,%r14,8)
movaps 0x4742d(%rip), %xmm0    # 0x2454f0
movups %xmm0, (%rbx,%r14,8)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x18(%rbx,%r14,8)
movl $0x1, 0x10(%rbx,%r14,8)
movq %r12, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq