// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movl %ecx, 0x28(%rsp)
movl %edx, %r15d
movq %rsi, %r12
movq 0x88(%rsp), %r13
movl (%r13), %ebx
movl $0x1, %eax
leaq 0x40(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x3c(%rsp), %rdx
movl %eax, (%rdx)
xorl %r14d, %r14d
cmpl $0x0, 0x80(%rsp)
cmoveq %r14, %rcx
cmoveq %r14, %rdx
movq %r13, 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 0x202015
movq %r13, %r10
movq (%r13), %rax
movq %rax, %rcx
movl $0x0, %r13d
subq %rbx, %rcx
jbe 0x202486
movq 0x10(%r10), %rdx
movq 0x30(%rsp), %rsi
movq 0x258(%rsi), %rsi
leal 0x1(%rbx), %edi
xorl %r13d, %r13d
movabsq $0x1fffffffe, %r8       # imm = 0x1FFFFFFFE
movq %rbx, %r9
movq (%rdx,%r9,8), %r9
andq %r8, %r9
addl (%rsi,%r9,2), %r13d
movl %edi, %r9d
incl %edi
cmpq %r9, %rax
ja 0x202471
cmpl 0x28(%rsp), %r13d
ja 0x202736
movq 0x90(%rsp), %r8
movl %ebp, 0x2c(%rsp)
movl %ebp, %esi
leaq (,%rbx,8), %rdx
addq 0x10(%r10), %rdx
leaq 0x38(%rsp), %r9
movq 0x30(%rsp), %rdi
movq %r10, %rbp
callq 0x22129a
testq %rax, %rax
je 0x202609
movq %rbx, (%rbp)
movl 0x24(%rsp), %r9d
testl %r9d, %r9d
movq %rbp, %r10
je 0x202611
cmpl $0x0, 0x80(%rsp)
je 0x202503
cmpl $0x0, 0x40(%rsp)
jne 0x202503
cmpl $0x0, 0x3c(%rsp)
jne 0x202503
testl %r13d, %r13d
je 0x202503
cmpl $0x0, 0x38(%rsp)
jne 0x202736
movq 0x18(%r12), %rax
movq 0x28(%rax), %rcx
xorl $0x1, %r15d
movq (%rcx,%r15,8), %rcx
movq %rcx, %rdx
shlq $0x20, %rdx
setne %r15b
je 0x202629
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r14
shlq $0x3, %r14
addq 0x8(%rax), %r14
movl %ecx, %ebp
xorl %r13d, %r13d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
leaq (,%r13,2), %rax
addq %r13, %rax
cmpl $0x0, 0xc(%r14,%rax,8)
js 0x2025f7
leaq (%r14,%rax,8), %rax
movq 0x18(%r12), %rdi
movl 0x8(%rax), %edx
movq %rdx, %rax
xorq $0x1, %rax
movq 0x28(%rdi), %rcx
movq (%rcx,%rax,8), %rcx
xorl %eax, %eax
movq %rcx, %rsi
andq %r11, %rsi
je 0x2025ab
shrq $0x20, %rcx
movq 0x8(%rdi), %rdi
movl %ecx, %r8d
leaq (%r8,%r8,2), %r8
movl 0xc(%rdi,%r8,8), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %eax
incq %rcx
decq %rsi
jne 0x202587
cmpl $0x2, %eax
setae %al
cmpl $0x2, %r9d
jne 0x2025b5
testb %al, %al
jne 0x2025f7
cmpl $0x1, %r9d
jne 0x20261c
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 0x20135b
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl 0x24(%rsp), %r9d
movq 0x88(%rsp), %r10
testl %eax, %eax
je 0x20261c
incq %r13
cmpq %rbp, %r13
setb %r15b
jne 0x202543
jmp 0x202629
movq %rbp, %r10
jmp 0x202736
movl $0x1, %r14d
jmp 0x202736
xorl %r14d, %r14d
testb $0x1, %r15b
jne 0x202736
movq 0x18(%r12), %rax
movq 0x28(%rax), %rcx
movl 0x44(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
testl %ecx, %ecx
sete %r14b
je 0x20272e
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r15
shlq $0x3, %r15
addq 0x8(%rax), %r15
movl %ecx, %r11d
xorl %ebp, %ebp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq (,%rbp,2), %rax
addq %rbp, %rax
cmpl $0x0, 0xc(%r15,%rax,8)
js 0x20271e
leaq (%r15,%rax,8), %rax
movq 0x18(%r12), %rdi
movl 0x8(%rax), %edx
movq %rdx, %rax
xorq $0x1, %rax
movq 0x28(%rdi), %rcx
movq (%rcx,%rax,8), %rcx
xorl %eax, %eax
movq %rcx, %rsi
andq %r13, %rsi
je 0x2026cc
shrq $0x20, %rcx
movq 0x8(%rdi), %rdi
movl %ecx, %r8d
leaq (%r8,%r8,2), %r8
movl 0xc(%rdi,%r8,8), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %eax
incq %rcx
decq %rsi
jne 0x2026a8
cmpl $0x2, %eax
setae %al
cmpl $0x2, %r9d
jne 0x2026d6
testb %al, %al
jne 0x20271e
cmpl $0x1, %r9d
jne 0x20272e
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
movq %r11, %r13
callq 0x20135b
movq %r13, %r11
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x24(%rsp), %r9d
movq 0x88(%rsp), %r10
testl %eax, %eax
je 0x20272e
incq %rbp
cmpq %r11, %rbp
setae %r14b
jne 0x202664
movzbl %r14b, %r14d
andl $0x1, %r14d
movq %rbx, (%r10)
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq