// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ulg_arc_cut_occ(ul_resolve_t*, ma_ug_t*, int, unsigned int, unsigned int, unsigned int, asg64_v*, asg64_v*)
uint32_t ulg_arc_cut_occ(ul_resolve_t *uidx, ma_ug_t *ug, int32_t max_ext, uint32_t max_ext_hifi, 
uint32_t is_trio, uint32_t topo_level, asg64_v *in, asg64_v *ib)
{
    asg_t *g = ug->g; asg64_v tx = {0,0,0}, tb = {0,0,0}, *b = NULL, *ub = NULL;
    uint32_t v, w, i, z, kv, kw, nv, nw, cnt = 0, n_vtx = g->n_seq<<1, to_del, n_ul, n_ug;
    asg_arc_t *av, *aw; b = (in?(in):(&tx)); ub = (ib?(ib):(&tb));

    for (v = b->n = 0; v < n_vtx; ++v) {
        if (g->seq[v>>1].del) continue;
        av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
        if (nv < 2) continue;
        
        for (i = n_ul = n_ug = kv = 0; i < nv; ++i) {
            if(av[i].del) continue;
            if(is_ul_edge(uidx, av[i].ul>>32, av[i].v)) n_ul++;
            else n_ug++;
            kv++;
        }
        if(n_ul == 0 || n_ug == 0 || kv < 2) continue;

        for (i = 0; i < nv; ++i) {
            if(av[i].del) continue;
            if(is_ul_edge(uidx, av[i].ul>>32, av[i].v)) continue;
            w = av[i].v^1; if(g->seq[w>>1].del) continue;
            kw = get_arcs(g, w, NULL, 0);
            if (kv <= 1 && kw <= 1) continue;

            to_del = 0;
            if(topo_level == 0) {
                to_del = 1;
            } else if(topo_level == 2) {
                if (kv > 1 && kw > 1) to_del = 1;
            } else {
                if (kv > 1 && kw > 1) {
                    to_del = 1;
                } else if (kw == 1) {
                    if (usg_topocut_aux(uidx, ug, w^1, max_ext, max_ext_hifi, b, ub)) to_del = 1;                    
                } else if (kv == 1) {
                    if (usg_topocut_aux(uidx, ug, v^1, max_ext, max_ext_hifi, b, ub)) to_del = 1;   
                }
            }

            if (to_del) {
                ++cnt; av[i].del = 1;
                aw = asg_arc_a(g, w); nw = asg_arc_n(g, w);
                for (z = 0; z < nw; ++z) {
                    if (aw[z].v == (v^1)) {
                        aw[z].del = 1;
                        break;
                    }
                }
                assert(z < nw);
            }
        }
    }

    if(!in) free(tx.a); if(!ib) free(tb.a);
    if (cnt > 0) asg_cleanup(g);

    return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq 0xe0(%rsp), %rax
movq %rsi, 0x60(%rsp)
movq 0x18(%rsi), %r15
leaq 0x90(%rsp), %rsi
andq $0x0, 0x10(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
leaq 0x70(%rsp), %r8
movaps %xmm0, (%r8)
andq $0x0, 0x10(%r8)
movl 0x14(%r15), %r10d
addl %r10d, %r10d
testq %rax, %rax
cmovneq %rax, %rsi
movq 0xe8(%rsp), %rax
testq %rax, %rax
cmovneq %rax, %r8
movq %r8, 0x50(%rsp)
movl %ecx, 0x38(%rsp)
movq %rsi, 0x58(%rsp)
andq $0x0, (%rsi)
movl %edx, 0x34(%rsp)
movq %rdi, 0x28(%rsp)
xorl %edx, %edx
movl $0x0, 0x14(%rsp)
movq %r15, 0x48(%rsp)
movl %r9d, 0x3c(%rsp)
movq %r10, 0x40(%rsp)
cmpq %r10, %rdx
je 0x1c0c03
movq 0x20(%r15), %rax
movl %edx, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1c0ac3
movq 0x28(%r15), %rax
movq (%rax,%rdx,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1c0ac3
movq %rdx, 0x20(%rsp)
movq 0x8(%r15), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
leaq (%rcx,%rdx), %rsi
movq %rsi, 0x18(%rsp)
movl %eax, %eax
movq %rax, 0x68(%rsp)
imulq $0x18, %rax, %r14
leaq (%rcx,%rdx), %r12
addq $0xc, %r12
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %r13, %r14
je 0x1c0a9d
cmpl $0x0, (%r12,%r13)
js 0x1c0a97
movl -0x8(%r12,%r13), %esi
movl -0x4(%r12,%r13), %edx
movq 0x28(%rsp), %rdi
callq 0x1c08fc
addl %eax, %r15d
xorl $0x1, %eax
addl %eax, %ebp
incl %ebx
addq $0x18, %r13
jmp 0x1c0a6d
testl %r15d, %r15d
sete %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
cmpl $0x2, %ebx
setb %al
orb %cl, %al
je 0x1c0acb
movq 0x48(%rsp), %r15
movq 0x40(%rsp), %r10
movq 0x20(%rsp), %rdx
incq %rdx
jmp 0x1c0a05
xorl %ebx, %ebx
movq 0x48(%rsp), %r15
movq 0x18(%rsp), %r14
cmpq 0x68(%rsp), %rbx
je 0x1c0ab9
imulq $0x18, %rbx, %r13
movl 0xc(%r14,%r13), %ebp
testl %ebp, %ebp
js 0x1c0bfb
addq %r14, %r13
movl 0x4(%r13), %esi
movl 0x8(%r13), %r12d
movq 0x28(%rsp), %rdi
movl %r12d, %edx
callq 0x1c08fc
testl %eax, %eax
jne 0x1c0bfb
movq 0x20(%r15), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1c0bfb
movl %r12d, %r14d
xorl $0x1, %r14d
movq %r15, %rdi
movl %r14d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
movl 0x3c(%rsp), %ecx
testl %ecx, %ecx
je 0x1c0b8b
cmpl $0x2, %ecx
jne 0x1c0b4f
cmpl $0x2, %eax
jae 0x1c0b8b
jmp 0x1c0bf6
cmpl $0x1, %eax
ja 0x1c0b8b
jne 0x1c0bf6
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl %r12d, %edx
movl 0x34(%rsp), %ecx
movl 0x38(%rsp), %r8d
movq 0x58(%rsp), %r9
callq 0x1c00c6
testl %eax, %eax
je 0x1c0bf6
movl 0xc(%r13), %ebp
incl 0x14(%rsp)
orl $0x80000000, %ebp       # imm = 0x80000000
movl %ebp, 0xc(%r13)
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl %r14d, %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq %rcx, %rsi
shrq $0x20, %rsi
imulq $0x18, %rdx, %rcx
addq $0x18, %rcx
imulq $0x18, %rsi, %rdx
leaq (%rax,%rdx), %rsi
addq $-0xc, %rsi
xorl %r8d, %r8d
movq 0x20(%rsp), %r10
movq 0x18(%rsp), %r14
leaq 0x18(%r8), %rdi
cmpq %rdi, %rcx
je 0x1c0c58
movl 0x14(%rsi,%r8), %r9d
xorl %r10d, %r9d
movq %rdi, %r8
cmpl $0x1, %r9d
jne 0x1c0bd2
addq %rdx, %rax
orb $-0x80, -0x9(%rdi,%rax)
jmp 0x1c0bfb
movq 0x18(%rsp), %r14
incq %rbx
jmp 0x1c0ad7
cmpq $0x0, 0xe0(%rsp)
jne 0x1c0c1b
movq 0xa0(%rsp), %rdi
callq 0x2220
cmpq $0x0, 0xe8(%rsp)
jne 0x1c0c33
movq 0x80(%rsp), %rdi
callq 0x2220
cmpl $0x0, 0x14(%rsp)
je 0x1c0c42
movq %r15, %rdi
callq 0x694eb
movl 0x14(%rsp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39252(%rip), %rdi     # 0x1f9eb1
leaq 0x36873(%rip), %rsi     # 0x1f74d9
leaq 0x3924b(%rip), %rcx     # 0x1f9eb8
movl $0x2320, %edx           # imm = 0x2320
callq 0x2110