// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/tovlp.cpp
// Function: asg_bub_collect_ovlp(ma_ug_t*, unsigned int, buf_t*, utg_trans_t*)
void asg_bub_collect_ovlp(ma_ug_t *ug, uint32_t v0, buf_t *b, utg_trans_t *o)
{
    uint32_t i, uId;
    ///b->S.a[0] is the sink of this bubble
    if(get_real_length(ug->g, v0, NULL) == 2 && get_real_length(ug->g, b->S.a[0]^1, NULL) == 2)
    {
        long long tmp, max_stop_nodeLen, max_stop_baseLen, bch_occ[2], len[2];
        uint32_t bch[2], convex[2];
        get_real_length(ug->g, v0, bch);

        ///in rare cases, one side of a bubble might be empty
        if((bch[0]>>1)!=(b->S.a[0]>>1) && (bch[1]>>1)!=(b->S.a[0]>>1))
        {
            get_unitig(ug->g, NULL, bch[0], &convex[0], &bch_occ[0], &tmp, 
                                                &max_stop_nodeLen, &max_stop_baseLen, 1, NULL);
            get_unitig(ug->g, NULL, bch[1], &convex[1], &bch_occ[1], &tmp, 
                                                &max_stop_nodeLen, &max_stop_baseLen, 1, NULL);
            if(((bch_occ[0] + bch_occ[1] + 1) == (uint32_t)b->b.n) && 
                    get_real_length(ug->g, convex[0], NULL) == 1 && get_real_length(ug->g, convex[1], NULL) == 1)
            {
                get_real_length(ug->g, convex[0], &convex[0]);
                get_real_length(ug->g, convex[1], &convex[1]);
                if(convex[0] == b->S.a[0] && convex[1] == b->S.a[0])
                {
                    o->b0.b.n = 0;
                    get_unitig(ug->g, NULL, bch[0], &convex[0], &bch_occ[0], &len[0], &max_stop_nodeLen, &max_stop_baseLen, 1, &(o->b0));
                    o->b1.b.n = 0;
                    get_unitig(ug->g, NULL, bch[1], &convex[1], &bch_occ[1], &len[1], &max_stop_nodeLen, &max_stop_baseLen, 1, &(o->b1));
                    
                    chain_bubble(&(o->b0), len[0], &(o->b1), len[1], v0, b->S.a[0]^1, ug, o);
                    return;
                }
            }
        }
    }

    tpSort(ug->g, o, v0, b->S.a[0]);
    ///if(o->topo_res.n != b->b.n - 1) fprintf(stderr, "ERROR-4\n");
    if(o->topo_res.n == 0) return;
    for (i = 0; i < o->topo_res.n; ++i)
    {
        uId = o->topo_res.a[i]>>1;
        if(uId == (b->S.a[0]>>1)) continue;

        dfs_trans_chain(ug->g, o, uId, v0>>1, b->S.a[0]>>1);

        if(o->b0.b.n == 0) continue;
        chain_c_bubble(o->topo_res.a[i], &(o->b0), b, ug, o);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r14
movq 0x18(%rdi), %rdi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jne 0x151b59
movq 0x18(%r14), %rdi
movq 0x18(%r15), %rax
movl (%rax), %esi
xorl $0x1, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jne 0x151b59
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %r12
movl %ebp, %esi
movq %r12, %rdx
callq 0xc2e7a
movl (%r12), %edx
movl %edx, %ecx
shrl %ecx
movq 0x18(%r15), %rax
movl (%rax), %eax
shrl %eax
cmpl %eax, %ecx
je 0x151b59
movl 0xc(%rsp), %ecx
shrl %ecx
cmpl %eax, %ecx
je 0x151b59
movq 0x18(%r14), %rdi
subq $0x20, %rsp
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x20(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x70(%rsp), %r13
xorl %esi, %esi
movq %r13, %r9
callq 0xc2ebf
addq $0x20, %rsp
movq 0x18(%r14), %rdi
movl 0xc(%rsp), %edx
leaq 0x4(%rsp), %rcx
leaq 0x28(%rsp), %r12
xorl %esi, %esi
movq %r12, %r8
movq %r13, %r9
pushq $0x0
pushq $0x1
popq %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
movq -0x8(%r12), %rax
movq (%r12), %rcx
addq %rcx, %rax
incq %rax
movl 0x38(%r15), %ecx
cmpq %rcx, %rax
jne 0x151b59
movq 0x18(%r14), %rdi
movl (%rsp), %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x1, %eax
jne 0x151b59
movq 0x18(%r14), %rdi
movl 0x4(%rsp), %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x1, %eax
jne 0x151b59
movq 0x18(%r14), %rdi
movq %rsp, %r13
movl (%r13), %esi
movq %r13, %rdx
callq 0xc2e7a
movq 0x18(%r14), %rdi
movl 0x4(%r13), %esi
leaq 0x4(%rsp), %rdx
callq 0xc2e7a
movq 0x18(%r15), %rax
movl (%rax), %eax
cmpl %eax, (%r13)
jne 0x151b59
cmpl %eax, 0x4(%rsp)
jne 0x151b59
andq $0x0, 0x198(%rbx)
leaq 0x160(%rbx), %rax
movq %rax, 0x38(%rsp)
movq 0x18(%r14), %rdi
movl 0x8(%rsp), %edx
movq %rsp, %rcx
leaq 0x20(%rsp), %r8
leaq 0x40(%rsp), %r9
xorl %esi, %esi
pushq %rax
pushq $0x1
popq %r12
pushq %r12
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
andq $0x0, 0x200(%rbx)
leaq 0x1c8(%rbx), %r13
movq 0x18(%r14), %rdi
movl 0xc(%rsp), %edx
leaq 0x48(%rsp), %r9
xorl %esi, %esi
leaq 0x4(%rsp), %rcx
leaq 0x28(%rsp), %r8
pushq %r13
pushq %r12
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
leaq 0x48(%rsp), %rax
movq -0x8(%rax), %rsi
movq (%rax), %rcx
movq 0x18(%r15), %rax
xorl (%rax), %r12d
movq 0x38(%rsp), %rdi
movq %r13, %rdx
movl %ebp, %r8d
movl %r12d, %r9d
pushq %rbx
pushq %r14
callq 0x150eff
popq %rax
popq %rcx
jmp 0x151be9
movq 0x18(%r14), %rdi
movq 0x18(%r15), %rax
movl (%rax), %ecx
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1512c5
movq 0xf0(%rbx), %rax
testq %rax, %rax
je 0x151be9
shrl %ebp
leaq 0x160(%rbx), %r12
xorl %r13d, %r13d
movl %r13d, %r13d
cmpq %r13, %rax
jbe 0x151be9
movq 0x100(%rbx), %rax
movl (%rax,%r13,4), %edx
shrl %edx
movq 0x18(%r15), %rax
movl (%rax), %r8d
shrl %r8d
cmpl %r8d, %edx
je 0x151bdd
movq 0x18(%r14), %rdi
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x151578
cmpq $0x0, 0x198(%rbx)
je 0x151bdd
movq 0x100(%rbx), %rax
movl (%rax,%r13,4), %edi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x151197
incl %r13d
movq 0xf0(%rbx), %rax
jmp 0x151b85
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq