// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_bub_clean0(usg_t*, unsigned int*, unsigned int, unsigned int, unsigned int, unsigned int, int, float, unsigned char*, asg64_v*, asg64_v*)
uint64_t usg_bub_clean0(usg_t *g, uint32_t *a, uint32_t a_n, uint32_t sid, uint32_t eid, 
uint32_t is_topo, int32_t max_ext, float len_rat, uint8_t *f, asg64_v *in_0, asg64_v *in_1)
{
    uint32_t i, k, v, w, nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, tip_v, mm_ol; 
    asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL; int32_t n_tip, r_tip;
    uint64_t kocc[2]; usg_arc_t *av, *aw, *ve, *we;
    b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz));

    for (k = b->n = ub->n = 0; k < a_n; ++k) {
        extracr_clean_arc(g, a[k], b, ub); 
        extracr_clean_arc(g, a[k]^1, b, ub);
    }
    extracr_clean_arc(g, sid, b, ub); 
    extracr_clean_arc(g, eid, b, ub);
    

    radix_sort_srt64(b->a, b->a + b->n);
    for (k = 0; k < b->n; k++) {
        v = ub->a[(uint32_t)b->a[k]]>>32; 
        ve = &(usg_arc_a(g, v)[(uint32_t)(ub->a[(uint32_t)b->a[k]])]);
        w = ve->v^1;
        if(ve->del || g->a[v>>1].del || g->a[w>>1].del || ve->ou) continue;
        nv = usg_arc_n(g, v); nw = usg_arc_n(g, w);
        av = usg_arc_a(g, v); aw = usg_arc_a(g, w);
        if(nv<=1 && nw <= 1) continue;    

        // if(is_trio) {
        //     if(get_arcs(g, v, NULL, 0)<=1 && get_arcs(g, w, NULL, 0)<=1) continue;///speedup
        //     trioF = get_tip_trio_infor(g, v^1);
        //     ntrioF = (trioF==FATHER? MOTHER : (trioF==MOTHER? FATHER : (uint32_t)-1));
        // }    
        for (i = 0; i < nw; ++i) {
            if (aw[i].v == (v^1)) {
                we = &(aw[i]);
                break;
            }
        }
        mm_ol = MIN(ve->ol, we->ol); kocc[0] = kocc[1] = 0;

        for (i = kv = ol_max = ou_max = 0; i < nv; ++i) {
            if(av[i].del) continue;
            kv++; 
            if(av[i].ou != 1) kocc[!!(av[i].ou)]++; ///if av[i].ou == 1, ignore it
            // if(is_trio && get_tip_trio_infor(g, av[i].v) == ntrioF) continue;
            if(ol_max < av[i].ol) ol_max = av[i].ol;
        }
        if (kv < 1 || kocc[0] < 1 || kocc[1] < 1) continue;
        if (kv >= 2) {
            if (mm_ol > ol_max*len_rat) continue;
        }

        
        for (i = kw = ol_max = ou_max = 0; i < nw; ++i) {
            if(aw[i].del) continue;
            kw++;
            // if(is_trio && get_tip_trio_infor(g, aw[i].v) == ntrioF) continue;
            if(ol_max < aw[i].ol) ol_max = aw[i].ol;
        }
        if (kw < 1) continue;
        if (kw >= 2) {
            if (mm_ol > ol_max*len_rat) continue;
        }

        if (kv <= 1 && kw <= 1) continue;

        to_del = 1; n_tip = 0; tip_v = (uint32_t)-1;
        if(is_topo) {
            to_del = 0;
            if (kv > 1 && kw > 1) {
                to_del = 1;
            } else if (kw == 1) {
                n_tip = usg_naive_topocut_aux(g, w^1, max_ext, f, b, ub);
                if (n_tip < max_ext) to_del = 1; tip_v = w^1;
            } else if (kv == 1) {
                n_tip = usg_naive_topocut_aux(g, v^1, max_ext, f, b, ub);
                if (n_tip < max_ext) to_del = 1; tip_v = v^1;
            }
        } 

        if (to_del) {
            // ve->del = we->del = 1; 
            if(n_tip > 0 && tip_v != ((uint32_t)-1)) {
                r_tip = usg_tip_del(g, tip_v, b, ub);
                assert(n_tip == r_tip);
            }
            cnt++;
        }
    }

    if(in_0) free(tx.a); if(in_1) free(tz.a);
    return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movss %xmm0, 0x28(%rsp)
movl %r9d, 0x24(%rsp)
movl %r8d, 0x18(%rsp)
movl %ecx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, %r14
movq 0xd8(%rsp), %r12
movq 0xd0(%rsp), %r15
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rcx
movaps %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x50(%rsp), %rsi
movq %rax, 0x10(%rsi)
testq %r15, %r15
cmoveq %rcx, %r15
testq %r12, %r12
cmoveq %rsi, %r12
movaps %xmm0, (%rsi)
movq %rax, (%r12)
movq %rax, (%r15)
testl %edx, %edx
je 0x226154
movl %edx, %ebp
xorl %ebx, %ebx
movl (%r13,%rbx,4), %esi
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x225c05
movl (%r13,%rbx,4), %esi
xorl $0x1, %esi
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x225c05
incq %rbx
cmpq %rbx, %rbp
jne 0x226123
movq %r14, %rdi
movl 0x8(%rsp), %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x225c05
movq %r14, %rdi
movl 0x18(%rsp), %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x225c05
movq 0xd0(%rsp), %rax
testq %rax, %rax
leaq 0x70(%rsp), %rcx
cmovneq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rcx), %rdi
movq (%r15), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1ee586
xorl %r13d, %r13d
cmpq $0x0, (%r15)
je 0x2264db
movq 0xd8(%rsp), %rbx
testq %rbx, %rbx
leaq 0x50(%rsp), %r10
cmovneq %rbx, %r10
xorps %xmm2, %xmm2
movl $0x0, 0x2c(%rsp)
movq 0x8(%rsp), %r11
movq 0x10(%r10), %rax
movq 0x10(%r11), %rcx
movl (%rcx,%r13,8), %ecx
movq (%rax,%rcx,8), %rbp
movq %rbp, %rdx
movl %ebp, %ecx
shrq $0x20, %rbp
movq (%r14), %rax
shrq $0x21, %rdx
imulq $0x78, %rdx, %rsi
addq %rax, %rsi
movl %ebp, %edx
andl $0x1, %edx
leaq (%rdx,%rdx,2), %r8
movq 0x20(%rsi,%r8,8), %rdx
shlq $0x5, %rcx
movl 0xc(%rdx,%rcx), %edi
testl %edi, %edi
js 0x22636f
cmpb $0x0, 0x70(%rsi)
jne 0x22636f
movl 0x8(%rdx,%rcx), %ebx
movl %ebx, %r9d
shrl %r9d
imulq $0x78, %r9, %r9
cmpb $0x0, 0x70(%rax,%r9)
jne 0x22636f
movq %rbx, 0x18(%rsp)
addq %rdx, %rcx
cmpl $0x0, 0x10(%rcx)
jne 0x22636f
leaq (%rsi,%r8,8), %rcx
addq $0x10, %rcx
addq %r9, %rax
movq (%rcx), %r9
movq 0x18(%rsp), %rcx
notl %ecx
andl $0x1, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rbx
movq 0x20(%rax,%rcx,8), %rax
cmpl $0x1, %r9d
ja 0x226282
cmpl $0x2, %ebx
jb 0x22636f
movq %r10, 0x10(%rsp)
movl %ebx, %ecx
movq %rcx, %r10
movq %rax, %rsi
testl %ebx, %ebx
je 0x2262a9
movl 0x8(%rsi), %r8d
xorl %ebp, %r8d
cmpl $0x1, %r8d
je 0x2262ae
addq $0x20, %rsi
decq %r10
jne 0x226293
movq 0x38(%rsp), %rsi
movq %rsi, 0x38(%rsp)
movl 0xc(%rsi), %r8d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %r8d
cmpl %r8d, %edi
cmovbl %edi, %r8d
movaps %xmm2, 0x40(%rsp)
testl %r9d, %r9d
je 0x226365
movq %rbx, 0x30(%rsp)
movl %r8d, 0x20(%rsp)
movl %r9d, %r10d
shlq $0x5, %r10
xorl %r11d, %r11d
xorl %edi, %edi
xorl %r9d, %r9d
movl 0xc(%rdx,%r11), %ebx
testl %ebx, %ebx
js 0x226318
movl 0x10(%rdx,%r11), %r8d
cmpl $0x1, %r8d
je 0x22630f
xorl %esi, %esi
testl %r8d, %r8d
setne %sil
incq 0x40(%rsp,%rsi,8)
incl %edi
cmpl %ebx, %r9d
cmovbel %ebx, %r9d
addq $0x20, %r11
cmpq %r11, %r10
jne 0x2262ed
testl %edi, %edi
je 0x226365
cmpq $0x0, 0x40(%rsp)
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
je 0x22636f
cmpq $0x0, 0x48(%rsp)
je 0x22636f
cmpl $0x2, %edi
jb 0x226380
cvtsi2ss %r9d, %xmm0
movl 0x20(%rsp), %ebx
cvtsi2ss %ebx, %xmm1
mulss 0x28(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x22636f
cmpl $0x0, 0x30(%rsp)
jne 0x22638b
jmp 0x22636f
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
incl %r13d
cmpq %r13, (%r15)
ja 0x2261d2
jmp 0x2264d6
cmpl $0x0, 0x30(%rsp)
movl 0x20(%rsp), %ebx
je 0x22636f
addq $0xc, %rax
xorl %edx, %edx
xorl %r8d, %r8d
movl %r8d, %esi
movl (%rax), %r9d
cmpl %r9d, %r8d
movl %r9d, %r8d
cmoval %esi, %r8d
xorl %r10d, %r10d
testl %r9d, %r9d
cmovsl %esi, %r8d
setns %r10b
addl %r10d, %edx
addq $0x20, %rax
decq %rcx
jne 0x226394
testl %edx, %edx
je 0x22636a
cmpl $0x1, %edx
movq 0x10(%rsp), %r10
jne 0x22641e
cmpl $0x2, %edi
jb 0x22636f
cmpl $0x0, 0x24(%rsp)
movq 0x18(%rsp), %rsi
je 0x2264bb
movq %r14, %rdi
movl 0xc0(%rsp), %ebp
movl %ebp, %edx
movq 0xc8(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0x21478a
cmpl %ebp, %eax
jge 0x2264c4
movl %eax, %ebx
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
xorps %xmm2, %xmm2
movq 0x18(%rsp), %rsi
jmp 0x226493
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
mulss 0x28(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x22636f
cmpl $0x2, %edi
setae %al
cmpl $0x0, 0x24(%rsp)
sete %cl
orb %al, %cl
jne 0x2264bb
cmpl $0x1, %edi
jne 0x22636f
xorl $0x1, %ebp
movq %r14, %rdi
movl %ebp, %esi
movl 0xc0(%rsp), %edx
movq 0xc8(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0x21478a
cmpl 0xc0(%rsp), %eax
jge 0x2264c4
movl %eax, %ebx
movl %ebp, %esi
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
xorps %xmm2, %xmm2
testl %ebx, %ebx
jle 0x2264bb
cmpl $-0x1, %esi
je 0x2264bb
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x225d61
xorps %xmm2, %xmm2
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r11
cmpl %eax, %ebx
jne 0x22651f
incl 0x2c(%rsp)
jmp 0x22636f
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
xorps %xmm2, %xmm2
jmp 0x22636f
movl 0x2c(%rsp), %r13d
movq 0xd8(%rsp), %rbx
cmpq $0x0, 0xd0(%rsp)
je 0x2264fb
movq 0x80(%rsp), %rdi
callq 0x2220
testq %rbx, %rbx
je 0x22650a
movq 0x60(%rsp), %rdi
callq 0x2220
movq %r13, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x239c0(%rip), %rdi     # 0x249ee6
leaq 0x1f0dc(%rip), %rsi     # 0x245609
leaq 0x239c1(%rip), %rcx     # 0x249ef5
movl $0x3e23, %edx           # imm = 0x3E23
callq 0x2110