// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0xc(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x2, %eax
jne 0x2720e3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x2, %eax
jne 0x2720e3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0xc(%rbp), %esi
leaq -0x68(%rbp), %rdx
callq 0x166b50
movl -0x68(%rbp), %eax
shrl %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl (%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0x2720e1
movl -0x64(%rbp), %eax
shrl %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl (%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0x2720e1
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x68(%rbp), %edx
leaq -0x70(%rbp), %rcx
leaq -0x50(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %r9
leaq -0x38(%rbp), %r10
leaq -0x40(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
callq 0x166c30
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x64(%rbp), %edx
leaq -0x70(%rbp), %rcx
addq $0x4, %rcx
leaq -0x50(%rbp), %r8
addq $0x8, %r8
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %r9
leaq -0x38(%rbp), %r10
leaq -0x40(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
callq 0x166c30
movq -0x50(%rbp), %rax
addq -0x48(%rbp), %rax
addq $0x1, %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x2720df
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x70(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
jne 0x2720df
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x6c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
jne 0x2720df
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x70(%rbp), %esi
leaq -0x70(%rbp), %rdx
callq 0x166b50
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x6c(%rbp), %esi
leaq -0x70(%rbp), %rdx
addq $0x4, %rdx
callq 0x166b50
movl -0x70(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x2720dd
movl -0x6c(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x2720dd
movq -0x20(%rbp), %rax
movq $0x0, 0x198(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x68(%rbp), %edx
leaq -0x70(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x60(%rbp), %r9
movq -0x20(%rbp), %rax
addq $0x160, %rax            # imm = 0x160
xorl %esi, %esi
leaq -0x38(%rbp), %r11
leaq -0x40(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movq -0x20(%rbp), %rax
movq $0x0, 0x200(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x64(%rbp), %edx
leaq -0x70(%rbp), %rcx
addq $0x4, %rcx
leaq -0x50(%rbp), %r8
addq $0x8, %r8
leaq -0x60(%rbp), %r9
addq $0x8, %r9
movq -0x20(%rbp), %rax
addq $0x1c8, %rax            # imm = 0x1C8
xorl %esi, %esi
leaq -0x38(%rbp), %r11
leaq -0x40(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movq -0x20(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
movq -0x60(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x1c8, %rdx            # imm = 0x1C8
movq -0x58(%rbp), %rcx
movl -0xc(%rbp), %r8d
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %r9d
xorl $0x1, %r9d
movq -0x8(%rbp), %r10
movq -0x20(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x270a70
jmp 0x2721cc
jmp 0x2720df
jmp 0x2720e1
jmp 0x2720e3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movl -0xc(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %ecx
callq 0x2712f0
movq -0x20(%rbp), %rax
cmpq $0x0, 0xf0(%rax)
jne 0x272114
jmp 0x2721cc
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0xf0(%rcx), %rax
jae 0x2721cc
movq -0x20(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl (%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x27215a
jmp 0x2721be
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movl -0x28(%rbp), %edx
movl -0xc(%rbp), %ecx
shrl %ecx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %r8d
shrl %r8d
callq 0x2717a0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x198(%rax)
jne 0x272191
jmp 0x2721be
movq -0x20(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %edi
movq -0x20(%rbp), %rsi
addq $0x160, %rsi            # imm = 0x160
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %r8
callq 0x271050
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x27211b
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)