// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movq %rdi, %r14
movq 0x18(%rdi), %rdi
movq 0x28(%rdi), %rcx
movl %esi, (%rsp)
movl %esi, %edx
movq (%rcx,%rdx,8), %rax
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rax, %rsi
je 0x190248
movq 0x8(%rdi), %r8
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%r8,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl (%rax,%r8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x18ff16
cmpl $0x2, %r9d
jne 0x190248
movq 0x18(%r15), %rax
movl (%rax), %esi
xorq $0x1, %rsi
movq (%rcx,%rsi,8), %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %rsi, %r8
je 0x190248
movq 0x8(%rdi), %r9
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r9,%rsi,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 0x18ff76
cmpl $0x2, %r10d
jne 0x190248
movq (%rcx,%rdx,8), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x18ffe5
movq 0x8(%rdi), %rsi
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
xorl %r8d, %r8d
cmpl $0x0, (%rdx,%rsi)
js 0x18ffdc
movl -0x4(%rdx,%rsi), %r9d
movl %r8d, %r10d
movl %r9d, 0x18(%rsp,%r10,4)
incl %r8d
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x18ffc6
movl 0x18(%rsp), %r13d
movl %r13d, %ecx
shrl %ecx
movl (%rax), %eax
shrl %eax
cmpl %eax, %ecx
je 0x190248
movl 0x1c(%rsp), %ecx
movl %ecx, 0xc(%rsp)
shrl %ecx
cmpl %eax, %ecx
je 0x190248
xorl %r11d, %r11d
movl $0x1, %r10d
leaq 0x10(%rsp), %rax
leaq 0x40(%rsp), %rbp
leaq 0x4(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x48(%rsp), %r9
xorl %esi, %esi
movl %r13d, %edx
pushq %r11
pushq %r10
pushq %rax
pushq %rbp
callq 0x10109f
addq $0x20, %rsp
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rcx
leaq 0x28(%rsp), %r12
xorl %esi, %esi
movl 0xc(%rsp), %edx
movq %r12, %r8
leaq 0x48(%rsp), %r9
xorl %eax, %eax
pushq %rax
movl $0x1, %eax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
pushq %rbp
callq 0x10109f
addq $0x20, %rsp
movq -0x8(%r12), %rax
movq (%r12), %rcx
addq %rcx, %rax
incq %rax
movl 0x38(%r15), %ecx
cmpq %rcx, %rax
jne 0x190248
movq 0x18(%r14), %rdi
movl 0x4(%rsp), %esi
movq 0x28(%rdi), %rax
movq (%rax,%rsi,8), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rcx, %rdx
je 0x190248
movq 0x8(%rdi), %r8
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%r8,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl (%rcx,%r8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x18, %r8
cmpq %r8, %rdx
jne 0x1900d4
cmpl $0x1, %r9d
jne 0x190248
movl 0x8(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rax, %rcx
je 0x190248
movq 0x8(%rdi), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,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 0x19012c
cmpl $0x1, %r8d
jne 0x190248
leaq 0x4(%rsp), %r12
movq %r12, %rdx
callq 0x101046
movq 0x18(%r14), %rdi
movl 0x4(%r12), %esi
leaq 0x8(%rsp), %rdx
callq 0x101046
movq 0x18(%r15), %rax
movl (%rax), %eax
cmpl %eax, (%r12)
jne 0x190248
cmpl %eax, 0x8(%rsp)
jne 0x190248
leaq 0x160(%rbx), %rax
movq %rax, 0x38(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x198(%rbx)
movq 0x18(%r14), %rdi
movl $0x1, %r10d
leaq 0x4(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x50(%rsp), %r9
xorl %esi, %esi
movl %r13d, %edx
pushq %rax
pushq %r10
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x58(%rsp), %rbp
pushq %rbp
callq 0x10109f
addq $0x20, %rsp
leaq 0x1c8(%rbx), %r12
xorl %eax, %eax
movq %rax, 0x200(%rbx)
movq 0x18(%r14), %rdi
leaq 0x58(%rsp), %r13
xorl %esi, %esi
movl 0xc(%rsp), %edx
leaq 0x8(%rsp), %rcx
leaq 0x28(%rsp), %r8
movq %r13, %r9
pushq %r12
movl $0x1, %eax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
pushq %rbp
callq 0x10109f
addq $0x20, %rsp
movq -0x8(%r13), %rsi
movq (%r13), %rcx
movq 0x18(%r15), %rax
movl $0x1, %r9d
xorl (%rax), %r9d
movq 0x38(%rsp), %rdi
movq %r12, %rdx
movl (%rsp), %r8d
pushq %rbx
pushq %r14
callq 0x18f3f5
addq $0x10, %rsp
jmp 0x1902e1
movq 0x18(%r14), %rdi
movq 0x18(%r15), %rax
movl (%rax), %ecx
movq %rbx, %rsi
movl (%rsp), %edx
callq 0x18f7d3
cmpq $0x0, 0xf0(%rbx)
je 0x1902e1
cmpq $0x0, 0xf0(%rbx)
je 0x1902e1
shrl (%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 0x1902d2
movq 0x18(%r14), %rdi
movq %rbx, %rsi
movl (%rsp), %ecx
callq 0x18fa8f
cmpq $0x0, 0x198(%rbx)
je 0x1902d2
movq 0x100(%rbx), %rax
movl (%rax,%rbp,4), %edi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x18f693
movl %r13d, %ebp
incl %r13d
cmpq %rbp, 0xf0(%rbx)
ja 0x190283
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq