// File: chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: asg_pop_bubble_purge_graph(asg_t*)
int asg_pop_bubble_purge_graph(asg_t *purge_g)
{
	uint32_t v, n_vtx = purge_g->n_seq * 2;
	uint64_t n_pop = 0;
	buf_t b;
	if (!purge_g->is_symm) asg_symm(purge_g);
	memset(&b, 0, sizeof(buf_t));
	///set information for each node
	b.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));
	//traverse all node with two directions 
	for (v = 0; v < n_vtx; ++v) {
		uint32_t i, n_arc = 0, nv = asg_arc_n(purge_g, v);
		asg_arc_t *av = asg_arc_a(purge_g, v);
		///some node could be deleted
		if (nv < 2 || purge_g->seq[v>>1].del || purge_g->seq[v>>1].c == ALTER_LABLE) continue;
		///some edges could be deleted
		for (i = 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_purge_graph(purge_g, v, purge_g->n_seq, &b);            
	}
	free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
	if (n_pop) asg_cleanup(purge_g);

	if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] popped %lu bubbles\n", __func__, (unsigned long)n_pop);
    }
    return n_pop;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x17cca0
movq -0x8(%rbp), %rdi
callq 0xce020
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl -0x10(%rbp), %eax
movl %eax, %edi
movl $0x1c, %esi
callq 0x2140
movq %rax, -0x80(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x17cdf6
movl $0x0, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x8c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0xc(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
cmpl $0x2, -0x8c(%rbp)
jb 0x17cd5a
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xc(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x17cd5a
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xc(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x17cd5f
jmp 0x17cde8
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jae 0x17cdb8
movq -0x98(%rbp), %rax
movl -0x84(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x17cda5
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x17cda7
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x17cd69
cmpl $0x1, -0x88(%rbp)
jbe 0x17cde6
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq -0x80(%rbp), %rcx
callq 0x17c410
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x17cde8
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x17ccca
movq -0x80(%rbp), %rdi
callq 0x2210
movq -0x68(%rbp), %rdi
callq 0x2210
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x38(%rbp), %rdi
callq 0x2210
movq -0x20(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x18(%rbp)
je 0x17ce33
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x18(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq