// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ulg_bub_pop_cut_aux(ul_resolve_t*, ma_ug_t*, unsigned int, buf_t*, unsigned int, unsigned int, asg64_v*, asg64_v*)
uint64_t ulg_bub_pop_cut_aux(ul_resolve_t *uidx, ma_ug_t *ug, uint32_t v0, buf_t *x, uint32_t max_ext, uint32_t max_ext_hifi, asg64_v *b, asg64_v *ub)
{
    uint32_t i, v, u, bn = b->n, n_ext, ul_occ, r = 0; binfo_t *t;
    v = x->S.a[0]; 
    do {
		u = x->a[v].p; // u->v
        x->a[v].d = (uint32_t)-1;
		v = u;
	} while (v != v0);

    for (i = n_ext = 0; i < x->b.n; ++i) { // clear the states of visited vertices
		t = &x->a[x->b.a[i]];
        if(t->d == (uint32_t)-1) continue;
        get_iug_u_raw_occ(uidx, x->b.a[i]>>1, &ul_occ, NULL); 
        n_ext += ul_occ; kv_push(uint64_t, *b, x->b.a[i]);
	}

    if(n_ext <= max_ext) {
        if(get_remove_hifi_occ(uidx, max_ext_hifi, b->a + bn, b->n - bn, ub, NULL)) r = 1;
    }
    b->n = bn;
    return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x349db5
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x349f0e
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x2c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
jne 0x349e3f
jmp 0x349f00
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shrl %esi
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x37beb0
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x349ed1
movq 0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x349e96
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x58(%rbp)
jmp 0x349ea1
movl $0x2, %eax
movq %rax, -0x58(%rbp)
jmp 0x349ea1
movq -0x58(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %edx
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x349f00
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x349dff
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
ja 0x349f5b
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x38(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdx
movq 0x10(%rbp), %rax
movq (%rax), %rcx
movl -0x38(%rbp), %eax
subq %rax, %rcx
movq 0x18(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x37bf20
cmpq $0x0, %rax
je 0x349f59
movl $0x1, -0x44(%rbp)
jmp 0x349f5b
movl -0x38(%rbp), %eax
movl %eax, %ecx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x44(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq