// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_topocut_aux(ul_resolve_t*, ma_ug_t*, unsigned int, int, int, asg64_v*, asg64_v*)
int32_t usg_topocut_aux(ul_resolve_t *uidx, ma_ug_t *ug, uint32_t v, int32_t max_ext, int32_t max_ext_hifi, asg64_v *b, asg64_v *ub)
{
    int32_t n_ext; asg_arc_t *av; uint32_t w = v, nv, i, kv, ul_occ, pn = b->n;
    for (n_ext = 0; n_ext < max_ext; v = w) {
        av = asg_arc_a(ug->g, v^1); nv = asg_arc_n(ug->g, v^1);
        for (i = kv = 0; i < nv && kv <= 1; i++) {
            if (av[i].del) continue;
            kv++; 
        }
        if(kv!=1) break;
        get_iug_u_raw_occ(uidx, v>>1, &ul_occ, NULL); n_ext += ul_occ; kv_push(uint64_t, *b, v);

        av = asg_arc_a(ug->g, v); nv = asg_arc_n(ug->g, v);
        for (i = kv = 0; i < nv && kv <= 1; i++) {
            if (av[i].del) continue;
            kv++; w = av[i].v;
        }
        if(kv!=1) break;
    }

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

    b->n = pn;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x3434ae
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0x59(%rbp)
jae 0x3432f8
cmpl $0x1, -0x50(%rbp)
setbe %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x343301
jmp 0x343330
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x34331c
jmp 0x343325
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3432e1
cmpl $0x1, -0x50(%rbp)
je 0x34333b
jmp 0x3434ae
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
shrl %esi
leaq -0x54(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x37beb0
movl -0x54(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3433c2
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x343387
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x343392
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x343392
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x1c(%rbp), %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0x69(%rbp)
jae 0x34344d
cmpl $0x1, -0x50(%rbp)
setbe %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x343456
jmp 0x343499
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x343471
jmp 0x34348e
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x343436
cmpl $0x1, -0x50(%rbp)
je 0x3434a1
jmp 0x3434ae
jmp 0x3434a3
movl -0x44(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x343279
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x343508
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x58(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movl -0x58(%rbp), %eax
subq %rax, %rcx
movq 0x10(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x37bf20
cmpq $0x0, %rax
je 0x343506
movl -0x58(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x34351b
jmp 0x343508
movl -0x58(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)