// File: chhylp123[P]hifiasm/inter.cpp
// Function: clean_ul_g(asg_t*)
void clean_ul_g(asg_t *xg)
{
	uint32_t n_vtx = xg->n_seq * 2, v, i, nv, ie = 0, ike = 0;
	asg_arc_t *av = NULL;
	uint8_t* bs_flag = NULL; CALLOC(bs_flag, n_vtx);
	buf_t b; memset(&b, 0, sizeof(buf_t)); b.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));
    uint64_t max_dist = get_bub_pop_max_dist_advance(xg, &b);
	for (v = 0; v < xg->n_seq; v++) xg->seq[v].c = 0;
	for (v = 0; v < n_vtx; ++v) {
		if(bs_flag[v] != 0) continue;
		if (asg_arc_n(xg, v) < 2 || xg->seq[v>>1].del) continue;
		if(asg_bub_pop1_primary_trio(xg, 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;
		}
	}

	for (v = 0; v < n_vtx; ++v) {
		if(bs_flag[v] != 0) continue;
		nv = asg_arc_n(xg, v);
		if (nv >= 2) {
			av = asg_arc_a(xg, v);
			for (i = 0; i < nv; ++i){
				if (av[i].ol == 0) {
					av[i].del = 1;
					asg_arc_del(xg, av[i].v^1, (av[i].ul>>32)^1, 1);
					// fprintf(stderr, "---q0-utg%.6d%c, q1-utg%.6d%c\n", 
					// (int32_t)((av[i].ul>>33)+1), "lc"[ug->u.a[av[i].ul>>33].circ], 
					// (int32_t)((av[i].v)>>1)+1, "lc"[ug->u.a[av[i].v].circ]);
				}

				// fprintf(stderr, "xxxx-nv: %u, q0-utg%.6d%c, q1-utg%.6d%c\n", nv, 
				// 	(int32_t)((av[i].ul>>33)+1), "lc"[ug->u.a[av[i].ul>>33].circ], 
				// 	(int32_t)((av[i].v)>>1)+1, "lc"[ug->u.a[av[i].v].circ]);
			}
		}
	}

	for (i = 0; i < xg->n_arc; i++) {
		if(xg->arc[i].ol == 0) {
			ie++;
			if(!xg->arc[i].del) ike++;
		}
	}
	
	fprintf(stderr, "[M::%s::] ==> # fill gaps: %u, # keep gaps: %u\n", __func__, ie, ike);
	free(bs_flag); free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0xc(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x30(%rbp)
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl -0xc(%rbp), %eax
movl %eax, %edi
movl $0x1c, %esi
callq 0x2140
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xfde50
movq %rax, -0xa0(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x2f5487
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x10(%rbp), %ecx
movb $0x0, 0x4(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2f5458
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x2f55ea
movq -0x30(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2f54af
jmp 0x2f55dc
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
jb 0x2f54dd
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x10(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2f54e2
jmp 0x2f55dc
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %edx
movq -0xa0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x98(%rbp), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
callq 0xfe040
cmpq $0x0, %rax
je 0x2f55da
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpq -0x60(%rbp), %rax
jae 0x2f55bc
movq -0x50(%rbp), %rax
movl -0x14(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x10(%rbp), %eax
je 0x2f5586
movq -0x50(%rbp), %rax
movl -0x14(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x80(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x2f5588
jmp 0x2f55b1
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movl -0x14(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movl -0x14(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movb $0x1, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f555c
movq -0x30(%rbp), %rax
movl -0x10(%rbp), %ecx
movb $0x2, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq -0x80(%rbp), %rcx
movl (%rcx), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movb $0x3, (%rax,%rcx)
jmp 0x2f55dc
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2f548e
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x2f5701
movq -0x30(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2f5612
jmp 0x2f56f3
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x18(%rbp)
cmpl $0x2, -0x18(%rbp)
jb 0x2f56f1
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x10(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x2f56ef
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x0, %eax
jne 0x2f56df
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %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 -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0x2efac0
jmp 0x2f56e1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f565b
jmp 0x2f56f1
jmp 0x2f56f3
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2f55f1
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x2f5779
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x0, %eax
jne 0x2f576c
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x2f576a
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2f576c
jmp 0x2f576e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f5708
movq 0xce860(%rip), %rax     # 0x3c3fe0
movq (%rax), %rdi
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
leaq 0x9f9e9(%rip), %rsi     # 0x39517a
leaq 0x9fa12(%rip), %rdx     # 0x3951aa
movb $0x0, %al
callq 0x22a0
movq -0x30(%rbp), %rdi
callq 0x2210
movq -0x98(%rbp), %rdi
callq 0x2210
movq -0x80(%rbp), %rdi
callq 0x2210
movq -0x68(%rbp), %rdi
callq 0x2210
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x38(%rbp), %rdi
callq 0x2210
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)