// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, 0x28(%rsp)
movl %ecx, 0x2c(%rsp)
movl %edx, %r15d
movq %rdi, %r13
movq 0x98(%rsp), %rbx
movq (%rbx), %r12
movl %r12d, %eax
movq %rax, 0x48(%rsp)
pushq $0x1
popq %r14
leaq 0x40(%rsp), %rax
movl %r14d, (%rax)
leaq 0x3c(%rsp), %rcx
movl %r14d, (%rcx)
xorl %ebp, %ebp
cmpl $0x0, 0x90(%rsp)
cmoveq %rbp, %rax
cmoveq %rbp, %rcx
movq %rbx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
leaq 0x44(%rsp), %rcx
movq %rsi, 0x30(%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1c0c77
movq (%rbx), %rcx
movabsq $0x1fffffffe, %rax      # imm = 0x1FFFFFFFE
movl %r12d, %edx
cmpq %rdx, %rcx
jbe 0x1c0fba
movq 0x10(%rbx), %rsi
movq 0x258(%r13), %rdi
movq (%rsi,%rdx,8), %rsi
andq %rax, %rsi
addl (%rdi,%rsi,2), %ebp
leal 0x1(%rdx), %r12d
jmp 0x1c0f97
cmpl 0x2c(%rsp), %ebp
ja 0x1c10e2
movl 0x28(%rsp), %esi
movq 0x48(%rsp), %r12
leaq (,%r12,8), %rdx
addq 0x10(%rbx), %rdx
subq %r12, %rcx
leaq 0x38(%rsp), %r9
movq %r13, %rdi
movq 0xa0(%rsp), %r8
callq 0x1de65f
testq %rax, %rax
je 0x1c10e2
movq %r12, (%rbx)
cmpl $0x0, 0x24(%rsp)
je 0x1c10e5
cmpl $0x0, 0x90(%rsp)
je 0x1c1035
cmpl $0x0, 0x40(%rsp)
jne 0x1c1035
cmpl $0x0, 0x3c(%rsp)
jne 0x1c1035
testl %ebp, %ebp
je 0x1c1035
cmpl $0x0, 0x38(%rsp)
movl $0x0, %r14d
jne 0x1c10e5
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
xorl $0x1, %r15d
movq (%rax,%r15,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rdx
movq %rdx, 0x50(%rsp)
imulq $0x18, %rax, %rax
leaq (%rax,%rcx), %r12
addq $0xc, %r12
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpq %rbp, 0x50(%rsp)
je 0x1c10ff
cmpl $0x0, (%r12,%rbp)
js 0x1c10dc
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movl -0x4(%r12,%rbp), %r15d
movl %r15d, %esi
xorl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x2, 0x24(%rsp)
jne 0x1c10a9
cmpl $0x1, %eax
ja 0x1c10dc
cmpl $0x1, 0x24(%rsp)
jne 0x1c10e5
movq 0xa0(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movl %r15d, %edx
movl 0x2c(%rsp), %ecx
movl 0x28(%rsp), %r8d
movq %rbx, %r9
callq 0x1c00c6
testl %eax, %eax
je 0x1c10e5
addq $0x18, %rbp
jmp 0x1c106e
xorl %r14d, %r14d
movq 0x48(%rsp), %rax
movq %rax, (%rbx)
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movl 0x44(%rsp), %edx
movq (%rax,%rdx,8), %rax
movl %eax, %r12d
shrq $0x20, %rax
imulq $0x18, %rax, %rax
leaq (%rax,%rcx), %r15
addq $0xc, %r15
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x1c119c
cmpl $0x0, (%r15)
js 0x1c1193
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movl -0x4(%r15), %r14d
movl %r14d, %esi
xorl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x2, 0x24(%rsp)
jne 0x1c1160
cmpl $0x1, %eax
ja 0x1c1193
cmpl $0x1, 0x24(%rsp)
jne 0x1c119c
movq 0xa0(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movl %r14d, %edx
movl 0x2c(%rsp), %ecx
movl 0x28(%rsp), %r8d
movq %rbx, %r9
callq 0x1c00c6
testl %eax, %eax
je 0x1c119c
incq %rbp
addq $0x18, %r15
jmp 0x1c112d
xorl %r14d, %r14d
cmpq %r12, %rbp
setae %r14b
jmp 0x1c10e5