// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_bridge_topocut_aux(ul_resolve_t*, ma_ug_t*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, asg64_v*, asg64_v*)
uint32_t usg_bridge_topocut_aux(ul_resolve_t *uidx, ma_ug_t *ug, uint32_t v, uint32_t max_ext, uint32_t max_ext_hifi, uint32_t topo_level, uint32_t double_check, asg64_v *b, asg64_v *ub)
{
    uint32_t k, z, bn = b->n, w, bridge_w = 1, bridge_am = 1, raw_ul, ul, del_occ, is_del = 0, kk;
    asg_arc_t *av; uint32_t nv;
    get_ul_path_info(uidx, ug, v, &w, NULL, NULL, (double_check?(&bridge_w):(NULL)), 
                                                                    (double_check?(&bridge_am):(NULL)), b);
    for (k = bn, raw_ul = 0; k < b->n; k++) {
        get_iug_u_raw_occ(uidx, b->a[k]>>1, &ul, NULL); raw_ul += ul;
    }
    
    if(raw_ul <= max_ext && get_remove_hifi_occ(uidx, max_ext_hifi, b->a + bn, b->n - bn, ub, &del_occ)) {
        b->n = bn;
        if(topo_level == 0) {
            is_del = 1;
        } else if(double_check == 0 || bridge_w > 0 || bridge_am > 0 || raw_ul == 0 || del_occ == 0) {
            av = asg_arc_a(ug->g, v^1); nv = asg_arc_n(ug->g, v^1);
            for (z = 0; z < nv; z++) {
                if(av[z].del) continue;
                kk = get_arcs(ug->g, av[z].v^1, NULL, 0);
                if(topo_level == 2 && kk > 1) continue;
                ///==1, might be a tip
                if (topo_level == 1 && usg_topocut_aux(uidx, ug, av[z].v, max_ext, max_ext_hifi, b, ub)) continue;
                break;
            }

            if(z >= nv) {
                av = asg_arc_a(ug->g, w); nv = asg_arc_n(ug->g, w);
                for (z = 0; z < nv; z++) {
                    if(av[z].del) continue;
                    kk = get_arcs(ug->g, av[z].v^1, NULL, 0);
                    if(topo_level == 2 && kk > 1) continue;
                    ///==1, might be a tip
                    if (topo_level == 1 && usg_topocut_aux(uidx, ug, av[z].v, max_ext, max_ext_hifi, b, ub)) continue;
                    break;
                }

                if(z >= nv) is_del = 1;
            }
        }
    }
    b->n = bn;

    return is_del;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, 0x2c(%rsp)
movl %ecx, 0x28(%rsp)
movl %edx, %r15d
movq %rsi, %r12
movq 0x88(%rsp), %rbx
movl (%rbx), %ebp
movl $0x1, %eax
leaq 0x40(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x3c(%rsp), %rdx
movl %eax, (%rdx)
xorl %eax, %eax
cmpl $0x0, 0x80(%rsp)
cmoveq %rax, %rcx
cmoveq %rax, %rdx
movq %rbx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rcx, (%rsp)
leaq 0x44(%rsp), %rcx
movq %rdi, 0x30(%rsp)
movl %r15d, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20d67b
movq %rbx, %r10
movq (%rbx), %rax
movq %rax, %rcx
movl $0x0, %ebx
subq %rbp, %rcx
jbe 0x20daa1
movq 0x10(%r10), %rdx
movq 0x30(%rsp), %rsi
movq 0x258(%rsi), %rsi
leal 0x1(%rbp), %edi
xorl %ebx, %ebx
movabsq $0x1fffffffe, %r8       # imm = 0x1FFFFFFFE
movq %rbp, %r9
movq (%rdx,%r9,8), %r9
andq %r8, %r9
addl (%rsi,%r9,2), %ebx
movl %edi, %r9d
incl %edi
cmpq %r9, %rax
ja 0x20da7f
xorl %r14d, %r14d
cmpl 0x28(%rsp), %ebx
ja 0x20dd09
movq 0x90(%rsp), %r8
movl 0x2c(%rsp), %esi
leaq (,%rbp,8), %rdx
addq 0x10(%r10), %rdx
leaq 0x38(%rsp), %r9
movq 0x30(%rsp), %rdi
movq %r10, %r13
callq 0x22c98c
testq %rax, %rax
je 0x20dd03
movq %rbp, (%r13)
movl $0x1, %r14d
cmpl $0x0, 0x24(%rsp)
movq %r13, %r10
je 0x20dd09
cmpl $0x0, 0x80(%rsp)
je 0x20db19
cmpl $0x0, 0x40(%rsp)
jne 0x20db19
cmpl $0x0, 0x3c(%rsp)
jne 0x20db19
testl %ebx, %ebx
je 0x20db19
cmpl $0x0, 0x38(%rsp)
movl $0x0, %r14d
jne 0x20dd09
movq 0x18(%r12), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
xorl $0x1, %r15d
movq (%rcx,%r15,8), %rdx
testl %edx, %edx
je 0x20dc19
movq %rdx, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r15
movl %edx, %ebx
xorl %r13d, %r13d
xorl %r14d, %r14d
leaq (,%r13,2), %rax
addq %r13, %rax
cmpl $0x0, 0xc(%r15,%rax,8)
js 0x20dc00
leaq (%r15,%rax,8), %rax
movq 0x18(%r12), %rsi
movl 0x8(%rax), %edx
movq %rdx, %rax
xorq $0x1, %rax
movq 0x28(%rsi), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rcx
je 0x20dbc0
shrq $0x20, %rax
movq 0x8(%rsi), %rdi
xorl %esi, %esi
movl %eax, %r8d
leaq (%r8,%r8,2), %r8
movl 0xc(%rdi,%r8,8), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %esi
incq %rax
decq %rcx
jne 0x20db96
cmpl $0x2, 0x24(%rsp)
jne 0x20dbc0
cmpl $0x1, %esi
ja 0x20dc00
cmpl $0x1, 0x24(%rsp)
jne 0x20dd09
movq 0x90(%rsp), %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movl 0x28(%rsp), %ecx
movl 0x2c(%rsp), %r8d
movq %r10, %r9
callq 0x20ca09
movq 0x88(%rsp), %r10
testl %eax, %eax
je 0x20dd09
incq %r13
cmpq %rbx, %r13
jne 0x20db4d
movq 0x18(%r12), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movl 0x44(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
movl $0x1, %r14d
testl %ecx, %ecx
je 0x20dd09
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r14
movl %ecx, %r13d
xorl %r15d, %r15d
xorl %ebx, %ebx
leaq (%r15,%r15,2), %rax
cmpl $0x0, 0xc(%r14,%rax,8)
js 0x20dcea
leaq (%r14,%rax,8), %rax
movq 0x18(%r12), %rsi
movl 0x8(%rax), %edx
movq %rdx, %rax
xorq $0x1, %rax
movq 0x28(%rsi), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rcx
je 0x20dcb2
shrq $0x20, %rax
movq 0x8(%rsi), %rdi
xorl %esi, %esi
movl %eax, %r8d
leaq (%r8,%r8,2), %r8
movl 0xc(%rdi,%r8,8), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %esi
incq %rax
decq %rcx
jne 0x20dc88
cmpl $0x2, 0x24(%rsp)
jne 0x20dcb2
cmpl $0x1, %esi
ja 0x20dcea
cmpl $0x1, 0x24(%rsp)
jne 0x20dcf9
movq 0x90(%rsp), %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movl 0x28(%rsp), %ecx
movl 0x2c(%rsp), %r8d
movq %r10, %r9
callq 0x20ca09
movq 0x88(%rsp), %r10
testl %eax, %eax
je 0x20dcf9
incq %r15
cmpq %r13, %r15
setae %bl
jne 0x20dc46
movzbl %bl, %r14d
andl $0x1, %r14d
jmp 0x20dd09
xorl %r14d, %r14d
movq %r13, %r10
movq %rbp, (%r10)
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq