// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ulg_bub_pop_backtrack(ma_ug_t*, unsigned int, buf_t*)
uint32_t ulg_bub_pop_backtrack(ma_ug_t *ug, uint32_t v0, buf_t *b)
{
	uint32_t i, v, u, cnt = b->e.n; asg_t *g = ug->g;

    ///b->S.a[0] is the sink of this bubble
	for (i = 0; i < b->b.n; ++i) g->seq[b->b.a[i]>>1].del = 1;

    ///remove all edges (self/reverse for each edge) in this bubble
	for (i = 0; i < b->e.n; ++i) {
        g->arc[b->e.a[i]].del = 1;
        asg_arc_del(g, g->arc[b->e.a[i]].v^1, (g->arc[b->e.a[i]].ul>>32)^1, 1);
	}

    ///v is the sink of this bubble
	v = b->S.a[0];
	do {
		u = b->a[v].p; // u->v
		g->seq[v>>1].del = 0;
		asg_arc_del(g, u, v, 0);
		asg_arc_del(g, v^1, u^1, 0);
        cnt--;
		v = u;
	} while (v != v0);

    for (i = 0; i < b->b.n; ++i) {
        if(!g->seq[b->b.a[i]>>1].del) continue;
        ulg_seq_del(ug, (b->b.a[i]>>1));
    }

    return cnt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x349fe5
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x1c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x349fa1
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jae 0x34a095
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x1c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x1c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x1c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0x31bd30
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x349fec
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
xorl %ecx, %ecx
callq 0x31bd30
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %esi
xorl $0x1, %esi
movl -0x24(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0x31bd30
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x34a0a2
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x34a174
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x1c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x34a150
jmp 0x34a169
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shrl %esi
callq 0x342d10
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x34a11c
movl -0x28(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)