// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/tovlp.cpp
// Function: asg_pop_bubble_primary_trio(asg_t*, ma_ug_t*, unsigned char*, buf_t*, unsigned long, unsigned int, unsigned int, utg_trans_t*)
int asg_pop_bubble_primary_trio(asg_t *g, ma_ug_t *ug, uint8_t *bs_flag, buf_t *b,
uint64_t max_dist, uint32_t positive_flag, uint32_t negative_flag, utg_trans_t *o)
{
	uint32_t v, n_vtx = g->n_seq * 2, n_arc, nv, i;
	uint64_t n_pop = 0;
    asg_arc_t *av = NULL;

    if(max_dist > 0)
    {
        for (v = 0; v < n_vtx; ++v) 
        {
            if(bs_flag[v] != 0) continue;
            nv = asg_arc_n(g, v);
            av = asg_arc_a(g, v);
            ///some node could be deleted
            if (nv < 2 || g->seq[v>>1].del || g->seq[v>>1].c == ALTER_LABLE) continue;
            ///some edges could be deleted
            for (i = n_arc = 0; i < nv; ++i) // asg_bub_pop1() may delete some edges/arcs
                if (!av[i].del) ++n_arc;
            if (n_arc < 2) continue;
            if(asg_bub_pop1_primary_trio(ug->g, NULL, v, max_dist, b, (uint32_t)-1, (uint32_t)-1, 0, NULL, NULL, NULL, 0, 0, NULL))
            {
                //beg is v, end is b.S.a[0]
                //note b.b include end, does not include beg
                for (i = 0; i < b->b.n; i++)
                {
                    if(b->b.a[i]==v || b->b.a[i]==b->S.a[0]) continue;
                    bs_flag[b->b.a[i]] = bs_flag[b->b.a[i]^1] = 1;
                }
                bs_flag[v] = 2; bs_flag[b->S.a[0]^1] = 3;
            }
        }

        //traverse all node with two directions 
        for (v = 0; v < n_vtx; ++v) {
            if(bs_flag[v] !=2) continue;
            nv = asg_arc_n(g, v);
            av = asg_arc_a(g, v);
            ///some node could be deleted
            if (nv < 2 || g->seq[v>>1].del || g->seq[v>>1].c == ALTER_LABLE) continue;
            ///some edges could be deleted
            for (i = n_arc = 0; i < nv; ++i) // asg_bub_pop1() may delete some edges/arcs
                if (!av[i].del) ++n_arc;
            if (n_arc > 1)
                n_pop += asg_bub_pop1_primary_trio(ug->g, ug, v, max_dist, b, positive_flag, negative_flag, 1, NULL, NULL, NULL, 0, 0, o);
        }
        
        if(VERBOSE >= 1)
        {
            fprintf(stderr, "[M::%s] popped %lu bubbles\n", __func__, (unsigned long)n_pop);
        }
    }
    
    if (n_pop) asg_cleanup(g);
    return n_pop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, 0x44(%rsp)
movq %rsi, 0x48(%rsp)
movq %r8, 0x50(%rsp)
testq %r8, %r8
je 0x1529b1
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %rbx
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
xorl %ebp, %ebp
movb $0x1, %r13b
cmpq %r14, %rbp
je 0x1528be
cmpb $0x0, (%r12,%rbp)
je 0x1527c4
incq %rbp
jmp 0x1527af
movq 0x28(%rbx), %rax
movq (%rax,%rbp,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1527bf
movq 0x20(%rbx), %rcx
movl %ebp, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1527bf
cmpb $0x1, 0x4(%rcx,%rdx,8)
je 0x1527bf
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
imulq $0x18, %rax, %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
addq $0xc, %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rax
je 0x15281d
movl (%rcx,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
jmp 0x152808
cmpl $0x2, %esi
jb 0x1527bf
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
andq $0x0, 0x38(%rsp)
andl $0x0, 0x30(%rsp)
andl $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
xorl %esi, %esi
movl %ebp, %edx
movq 0x50(%rsp), %rcx
movq %r15, %r8
pushq $-0x1
popq %r9
callq 0x84a86
testq %rax, %rax
je 0x1527bf
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, 0x38(%r15)
jbe 0x1528a5
movq 0x48(%r15), %rcx
movl (%rcx,%rax,4), %ecx
cmpq %rcx, %rbp
je 0x1528a1
movq 0x18(%r15), %rdx
cmpl (%rdx), %ecx
je 0x1528a1
xorq $0x1, %rcx
movb %r13b, (%r12,%rcx)
movq 0x48(%r15), %rcx
movl (%rcx,%rax,4), %ecx
movb %r13b, (%r12,%rcx)
incl %eax
jmp 0x152872
movb $0x2, (%r12,%rbp)
movq 0x18(%r15), %rax
movl (%rax), %eax
xorq $0x1, %rax
movb $0x3, (%r12,%rax)
jmp 0x1527bf
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpq %r14, %r13
je 0x1529a2
cmpb $0x2, (%r12,%r13)
jne 0x15299a
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x15299a
movq 0x20(%rbx), %rcx
movl %r13d, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x15299a
cmpb $0x1, 0x4(%rcx,%rdx,8)
je 0x15299a
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
imulq $0x18, %rax, %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
addq $0xc, %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rax
je 0x15293d
movl (%rcx,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
jmp 0x152928
cmpl $0x2, %esi
jb 0x15299a
movq 0x48(%rsp), %rsi
movq 0x18(%rsi), %rdi
movq 0x98(%rsp), %rax
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
andl $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
movl 0x90(%rsp), %eax
movl %eax, (%rsp)
movl $0x1, 0x8(%rsp)
movl %r13d, %edx
movq 0x50(%rsp), %rcx
movq %r15, %r8
movl 0x44(%rsp), %r9d
callq 0x84a86
addq %rax, %rbp
incq %r13
jmp 0x1528c3
testq %rbp, %rbp
je 0x1529b1
movq %rbx, %rdi
callq 0x694eb
jmp 0x1529b3
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq