// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movl %r8d, 0xc(%rsp)
movl %ecx, %r12d
movl %edx, %r14d
movq %rsi, %r13
movq %rdi, %r15
movl (%r9), %eax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
cmpl %r12d, %ebp
jge 0x20cb4b
movq 0x18(%r13), %rax
movq 0x28(%rax), %rdx
movl %r14d, %ecx
xorl $0x1, %ecx
movq (%rdx,%rcx,8), %rsi
testl %esi, %esi
je 0x20cb4b
movq 0x8(%rax), %rcx
movq %rsi, %rdi
shrq $0x20, %rdi
movl %esi, %eax
leaq (%rdi,%rdi,2), %rsi
leaq (%rcx,%rsi,8), %rsi
addq $0xc, %rsi
xorl %r8d, %r8d
movl $0x1, %edi
movl %r8d, %r9d
movl (%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r9d, %r8d
cmpq %rax, %rdi
jae 0x20ca9b
addq $0x18, %rsi
incq %rdi
cmpl $0x2, %r8d
jb 0x20ca79
cmpl $0x1, %r8d
jne 0x20cb4b
movl %r14d, %eax
shrl %eax
movq 0x258(%r15), %rsi
addl (%rsi,%rax,4), %ebp
movq (%rbx), %rdi
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdi
jne 0x20caf4
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
movq 0x18(%r13), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
movl %r14d, %esi
leaq 0x1(%rdi), %r8
movq %r8, (%rbx)
movq %rsi, (%rax,%rdi,8)
movq (%rdx,%rsi,8), %rax
testl %eax, %eax
je 0x20cb4b
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0xc, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
cmpl $0x0, (%rdx)
js 0x20cb31
incl %ecx
movl -0x4(%rdx), %r14d
cmpq %rax, %rsi
jae 0x20cb42
addq $0x18, %rdx
incq %rsi
cmpl $0x2, %ecx
jb 0x20cb26
cmpl $0x1, %ecx
je 0x20ca35
cmpl %r12d, %ebp
jge 0x20cb89
movslq 0xc(%rsp), %rsi
movq 0x10(%rsp), %r14
leaq (,%r14,8), %rdx
addq 0x10(%rbx), %rdx
movq (%rbx), %rcx
subq %r14, %rcx
movq %r15, %rdi
movq 0x50(%rsp), %r8
xorl %r9d, %r9d
callq 0x22c98c
movq %rax, %rcx
xorl %eax, %eax
testq %rcx, %rcx
setne %al
jmp 0x20cb90
xorl %eax, %eax
movq 0x10(%rsp), %r14
movq %r14, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq