// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movq %rdi, %r14
movq 0x18(%rdi), %rdi
movq 0x28(%rdi), %r8
movl %esi, 0xc(%rsp)
movl %esi, %eax
movq (%r8,%rax,8), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rax, %rcx
je 0x199011
movq 0x8(%rdi), %rsi
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsi,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %r9d, %r9d
movl (%rax,%rdx), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x198d0a
cmpl $0x2, %r9d
jne 0x199011
movq 0x18(%r15), %rdx
movl (%rdx), %edx
movq %rdx, %r9
xorq $0x1, %r9
movq (%r8,%r9,8), %r9
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r9, %r8
je 0x199011
shrq $0x20, %r9
leaq (%r9,%r9,2), %r9
leaq (%rsi,%r9,8), %rsi
addq $0xc, %rsi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl (%rsi,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x18, %r9
cmpq %r9, %r8
jne 0x198d69
cmpl $0x2, %r10d
jne 0x199011
xorl %esi, %esi
xorl %r8d, %r8d
cmpl $0x0, (%rax,%rsi)
js 0x198da5
movl -0x4(%rax,%rsi), %r9d
movl %r8d, %r10d
movl %r9d, 0x28(%rsp,%r10,4)
incl %r8d
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x198d8f
movl 0x28(%rsp), %r13d
movl %r13d, %eax
shrl %eax
shrl %edx
cmpl %edx, %eax
je 0x199011
movl 0x2c(%rsp), %ebp
movl %ebp, %eax
shrl %eax
cmpl %edx, %eax
je 0x199011
xorl %r12d, %r12d
movl $0x1, %r11d
leaq 0x18(%rsp), %r10
leaq 0x50(%rsp), %rax
leaq 0x10(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x58(%rsp), %r9
xorl %esi, %esi
movl %r13d, %edx
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq 0x18(%r14), %rdi
leaq 0x14(%rsp), %rcx
leaq 0x38(%rsp), %r12
xorl %esi, %esi
movl %ebp, 0x24(%rsp)
movl %ebp, %edx
movq %r12, %r8
leaq 0x58(%rsp), %r9
xorl %eax, %eax
pushq %rax
movl $0x1, %eax
pushq %rax
leaq 0x28(%rsp), %rax
pushq %rax
leaq 0x68(%rsp), %rax
movq %rax, %rbp
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq -0x8(%r12), %rax
movq (%r12), %rcx
addq %rcx, %rax
incq %rax
movl 0x38(%r15), %ecx
movq 0x18(%r14), %rdi
cmpq %rcx, %rax
jne 0x199011
movl 0x10(%rsp), %esi
movq 0x28(%rdi), %rcx
movq (%rcx,%rsi,8), %rdx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %rdx, %r8
je 0x199011
movq 0x8(%rdi), %rax
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl (%rdx,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x18, %r9
cmpq %r9, %r8
jne 0x198ea5
cmpl $0x1, %r10d
jne 0x199011
movl 0x14(%rsp), %edx
movq (%rcx,%rdx,8), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x199011
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %r8d, %r8d
movl (%rax,%rdx), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x198ef9
cmpl $0x1, %r8d
jne 0x199011
leaq 0x10(%rsp), %r12
movq %r12, %rdx
callq 0x10534e
movq 0x18(%r14), %rdi
movl 0x4(%r12), %esi
leaq 0x14(%rsp), %rdx
callq 0x10534e
movq 0x18(%r15), %rax
movl (%rax), %eax
movq 0x18(%r14), %rdi
cmpl %eax, (%r12)
jne 0x199011
cmpl %eax, 0x14(%rsp)
jne 0x199011
leaq 0x160(%rbx), %rax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x198(%rbx)
movl $0x1, %r10d
leaq 0x10(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x60(%rsp), %r9
xorl %esi, %esi
movl %r13d, %edx
pushq %rax
pushq %r10
leaq 0x28(%rsp), %rax
pushq %rax
pushq %rbp
callq 0x1053a7
addq $0x20, %rsp
leaq 0x1c8(%rbx), %r12
xorl %eax, %eax
movq %rax, 0x200(%rbx)
movq 0x18(%r14), %rdi
leaq 0x68(%rsp), %r13
xorl %esi, %esi
movl 0x24(%rsp), %edx
leaq 0x14(%rsp), %rcx
leaq 0x38(%rsp), %r8
movq %r13, %r9
pushq %r12
movl $0x1, %eax
pushq %rax
leaq 0x28(%rsp), %rax
pushq %rax
pushq %rbp
callq 0x1053a7
addq $0x20, %rsp
movq -0x8(%r13), %rsi
movq (%r13), %rcx
movq 0x18(%r15), %rax
movl $0x1, %r9d
xorl (%rax), %r9d
movq 0x48(%rsp), %rdi
movq %r12, %rdx
movl 0xc(%rsp), %r8d
pushq %rbx
pushq %r14
callq 0x1981d6
addq $0x10, %rsp
jmp 0x19909f
movq 0x18(%r15), %rax
movl (%rax), %ecx
movq %rbx, %rsi
movl 0xc(%rsp), %edx
callq 0x1985bb
cmpq $0x0, 0xf0(%rbx)
je 0x19909f
shrl 0xc(%rsp)
leaq 0x160(%rbx), %r12
movl $0x1, %r13d
xorl %ebp, %ebp
movq 0x100(%rbx), %rax
movl (%rax,%rbp,4), %edx
shrl %edx
movq 0x18(%r15), %rax
movl (%rax), %r8d
shrl %r8d
cmpl %r8d, %edx
je 0x199090
movq 0x18(%r14), %rdi
movq %rbx, %rsi
movl 0xc(%rsp), %ecx
callq 0x1988b5
cmpq $0x0, 0x198(%rbx)
je 0x199090
movq 0x100(%rbx), %rax
movl (%rax,%rbp,4), %edi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x19847f
movl %r13d, %ebp
incl %r13d
cmpq %rbp, 0xf0(%rbx)
ja 0x199040
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq