// File: /workspace/github_cpp_makefile_star2_O1/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 0x1f2be0
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), %r13
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), %rbx
movl $0x0, %edx
cmovaeq %rbx, %rdx
andq %rbx, %rcx
subq $0x8, %rsp
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbp
callq 0x13812e
addq $0x10, %rsp
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
movl $0x0, %ecx
cmovaeq %rbx, %rcx
subq $0x8, %rsp
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbp
callq 0x13812e
addq $0x10, %rsp
movl (%rbx), %r12d
xorq $0x1, %r12
leaq 0x60(%r14), %r15
movq 0x18(%r14), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, 0xe0(%r14)
jae 0x1f2a27
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0xe0(%r14)
movq 0xe8(%r14), %rdi
callq 0x2370
movq %rax, 0xe8(%r14)
movq 0x18(%r14), %rax
movq 0xe8(%r14), %rdi
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
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), %rbp
movl %ebp, %r9d
pushq %r13
pushq %r12
callq 0x1f23f1
addq $0x10, %rsp
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rdi
movq 0x18(%rdx), %rsi
movq 0x30(%r14), %r8
movq %r15, %rcx
movl %ebp, %r9d
pushq %r13
pushq %r12
callq 0x1f23f1
addq $0x10, %rsp
movq 0x38(%r14), %rax
movq 0x8(%rax), %rcx
cmpq %rcx, (%rax)
jne 0x1f2ad2
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 (%r13), %rcx
movq %rax, 0x10(%rcx)
movq (%r13), %rax
movq (%rax), %rcx
movq 0x10(%rax), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rax)
leaq (%rcx,%rcx,4), %rax
leaq (%rdx,%rax,8), %rbx
movl $0x0, 0x10(%rbx)
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
movq %r14, (%rbx)
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
cmpl $0x0, 0xc(%rbx)
jne 0x1f2b29
movl $0x2, 0xc(%rbx)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x18(%rbx)
movq 0x18(%rbx), %rax
movl 0x10(%rbx), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x10(%rbx)
movq %rbp, (%rax,%rcx,8)
movq (%r13), %rax
movq 0x8(%rax), %rcx
cmpq %rcx, (%rax)
jne 0x1f2b74
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 (%r13), %rcx
movq %rax, 0x10(%rcx)
movq (%r13), %rax
movq (%rax), %rcx
movq 0x10(%rax), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rax)
leaq (%rcx,%rcx,4), %rax
leaq (%rdx,%rax,8), %rbx
movl $0x0, 0x10(%rbx)
movq %r14, (%rbx)
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
cmpl $0x0, 0xc(%rbx)
jne 0x1f2bc1
movl $0x2, 0xc(%rbx)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x18(%rbx)
movq 0x18(%rbx), %rax
movl 0x10(%rbx), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x10(%rbx)
movq %r12, (%rax,%rcx,8)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq