// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x2c(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x344d01
leaq -0x34(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x344d09
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x344d09
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x344d24
leaq -0x38(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x344d2f
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x344d2f
movq -0x80(%rbp), %r11
movl -0x60(%rbp), %edx
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
movq -0x88(%rbp), %r10
movq 0x18(%rbp), %rax
leaq -0x30(%rbp), %rcx
xorl %r8d, %r8d
movl %r8d, %r9d
movq %r9, %r8
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x344830
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x24(%rbp), %eax
movq 0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x344dbb
movq -0x8(%rbp), %rdi
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
movl %eax, %esi
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x37beb0
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x344d76
movl -0x3c(%rbp), %eax
cmpl -0x18(%rbp), %eax
ja 0x345063
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x2c(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdx
movq 0x18(%rbp), %rax
movq (%rax), %rcx
movl -0x2c(%rbp), %eax
subq %rax, %rcx
movq 0x20(%rbp), %r8
leaq -0x44(%rbp), %r9
callq 0x37bf20
cmpq $0x0, %rax
je 0x345063
movl -0x2c(%rbp), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x20(%rbp)
jne 0x344e24
movl $0x1, -0x48(%rbp)
jmp 0x345061
cmpl $0x0, 0x10(%rbp)
je 0x344e46
cmpl $0x0, -0x34(%rbp)
ja 0x344e46
cmpl $0x0, -0x38(%rbp)
ja 0x344e46
cmpl $0x0, -0x3c(%rbp)
je 0x344e46
cmpl $0x0, -0x44(%rbp)
jne 0x34505f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x14(%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, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x344f48
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x344ec2
jmp 0x344f3a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
movl %eax, -0x4c(%rbp)
cmpl $0x2, -0x20(%rbp)
jne 0x344efa
cmpl $0x1, -0x4c(%rbp)
jbe 0x344efa
jmp 0x344f3a
cmpl $0x1, -0x20(%rbp)
jne 0x344f38
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movl -0x18(%rbp), %ecx
movl -0x1c(%rbp), %r8d
movq 0x18(%rbp), %r9
movq 0x20(%rbp), %rax
movq %rax, (%rsp)
callq 0x343240
cmpl $0x0, %eax
je 0x344f38
jmp 0x344f3a
jmp 0x344f48
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x344e9b
movl -0x28(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jb 0x34505d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x34504c
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x344fc6
jmp 0x34503e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
movl %eax, -0x4c(%rbp)
cmpl $0x2, -0x20(%rbp)
jne 0x344ffe
cmpl $0x1, -0x4c(%rbp)
jbe 0x344ffe
jmp 0x34503e
cmpl $0x1, -0x20(%rbp)
jne 0x34503c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movl -0x18(%rbp), %ecx
movl -0x1c(%rbp), %r8d
movq 0x18(%rbp), %r9
movq 0x20(%rbp), %rax
movq %rax, (%rsp)
callq 0x343240
cmpl $0x0, %eax
je 0x34503c
jmp 0x34503e
jmp 0x34504c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x344f9f
movl -0x28(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jb 0x34505b
movl $0x1, -0x48(%rbp)
jmp 0x34505d
jmp 0x34505f
jmp 0x345061
jmp 0x345063
movl -0x2c(%rbp), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x48(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)