// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x20(%rbp)
ja 0x326743
movq $0x0, -0x8(%rbp)
jmp 0x326e40
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
shrq $0x21, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
andq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x32679e
leaq -0x4c(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x3267a6
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x3267a6
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0x3267c2
leaq -0x4c(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x3267cd
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x3267cd
movq -0x80(%rbp), %rdx
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
movq -0x88(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x1c4b20
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
andq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0x32685d
leaq -0x4c(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x326868
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
jmp 0x326868
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x32688a
leaq -0x4c(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x326895
xorl %eax, %eax
movq %rax, -0xb0(%rbp)
jmp 0x326895
movq -0xa8(%rbp), %rdx
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdi
movq -0xb0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x1c4b20
movl -0x4c(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x326a1a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0xe0(%rax), %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0xe0(%rax), %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0xe0(%rax), %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0xe0(%rax), %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0xe0(%rax), %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xe8(%rax)
jmp 0x326a1c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %r8
movl -0x50(%rbp), %r9d
movl -0x54(%rbp), %r10d
movq -0x10(%rbp), %rax
addq $0x38, %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x325f30
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x60, %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %r8
movl -0x50(%rbp), %r9d
movl -0x54(%rbp), %r10d
movq -0x10(%rbp), %rax
addq $0x38, %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x325f30
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x326b82
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x326b34
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xb8(%rbp)
jmp 0x326b42
movl $0x2, %eax
movq %rax, -0xb8(%rbp)
jmp 0x326b42
movq -0xb8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x28, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x60(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x60(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x60(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x60(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x60(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x326c73
movq -0x60(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x326c34
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movl %eax, -0xbc(%rbp)
jmp 0x326c41
movl $0x2, %eax
movl %eax, -0xbc(%rbp)
jmp 0x326c41
movl -0xbc(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x50(%rbp), %eax
movl %eax, %edx
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x60(%rbp), %rsi
movl 0x10(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x10(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x326c97
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x326d25
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x326cd7
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xc8(%rbp)
jmp 0x326ce5
movl $0x2, %eax
movq %rax, -0xc8(%rbp)
jmp 0x326ce5
movq -0xc8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x28, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x60(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x60(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x60(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x60(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x60(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x326e16
movq -0x60(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x326dd7
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movl %eax, -0xcc(%rbp)
jmp 0x326de4
movl $0x2, %eax
movl %eax, -0xcc(%rbp)
jmp 0x326de4
movl -0xcc(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x54(%rbp), %eax
movl %eax, %edx
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x60(%rbp), %rsi
movl 0x10(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x10(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)