// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_arc_cut_complex_bub_links(asg_t*, asg64_v*, float, float, unsigned int, bub_label_t*)
void asg_arc_cut_complex_bub_links(asg_t *g, asg64_v *in, float len_rat, float ou_rat, uint32_t is_ou, bub_label_t *b_mask_t)
{
    asg64_v tx = {0,0,0}, *b = NULL;
    uint32_t v, w, t, k, i, n_vtx = g->n_seq<<1, nv, nw, kv, kw, kol, me, mu, cnt = 0, bn;
    asg_arc_t *av, *aw;

    if(in) b = in;
    else b = &tx;
    b->n = 0;

    for (v = 0; v < n_vtx; ++v) {
        if (g->seq[v>>1].del) continue;
        if(g->seq_vis[v] == 0) {
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
            if (nv < 2) continue;

            for (i = kv = kol = 0; i < nv; ++i) {
                if(av[i].del) continue;
                kv++; kol += av[i].ol; 
            }
            if(kv < 2) continue;//must have at least one exact and one inexact

            kv_push(uint64_t, *b, ((((uint64_t)(kol))<<32) | v));  
        }
    }

    radix_sort_srt64(b->a, b->a + b->n); bn = b->n;
    for (k = 0; k < bn; k++) {
        v = (uint32_t)b->a[k];
        if (g->seq[v>>1].del) continue;
        nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
        if (nv < 2 || get_arcs(g, v, NULL, 0) < 2) continue;

        for (i = 0; i < nv; i++) {
            if (av[i].del) continue;

            w = av[i].v^1; nw = asg_arc_n(g, w); aw = asg_arc_a(g, w);
            if(nw < 2) break;

            for (t = kw = 0, me = mu = (uint32_t)-1; t < nw; t++) {
                if(aw[t].del) continue;
                kw++; 
                if(aw[t].v == (v^1)) continue;//note: me is the shortest edge except aw[t], so here is continue
                if(aw[t].ol < me) me = aw[t].ol;
                if(aw[t].ou < mu) mu = aw[t].ou;
            }
            if(kw < 2) break;

            if(av[i].ol > me*len_rat) break;
            if(is_ou && av[i].ou > mu*ou_rat) break;
        }

        if(i < nv) continue;

        for (i = 0; i < nv; ++i) {
            if (av[i].del) continue;
            av[i].del = 1; asg_arc_del(g, av[i].v^1, (av[i].ul>>32)^1, 1);
            kv_push(uint64_t, *b, ((uint64_t)(av-g->arc+i)));
        }
        // b->a[cnt++] = v;
    }

    if(b->n > bn) {
        asg_arc_identify_simple_bubbles_multi(g, b_mask_t, 0);
        for (k = bn, cnt = 0; k < b->n; k++) {
            // if(g->arc[b->a[k]].del) continue;
            v = g->arc[b->a[k]].ul>>32; w = g->arc[b->a[k]].v; 
            if(g->seq_vis[v] || g->seq_vis[v^1] || g->seq_vis[w] || g->seq_vis[w^1]) {
                cnt++; continue;
            }
            g->arc[b->a[k]].del = 0; asg_arc_del(g, g->arc[b->a[k]].v^1, (g->arc[b->a[k]].ul>>32)^1, 0);
        }
    }
    // stats_sysm(g);
    if(!in) free(tx.a);
    if(cnt > 0) asg_cleanup(g);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x38(%rsp)
movl %edx, 0x30(%rsp)
movss %xmm1, 0x2c(%rsp)
movss %xmm0, 0x34(%rsp)
movq %rsi, %r14
movl 0x14(%rdi), %eax
addl %eax, %eax
testq %rsi, %rsi
je 0x1ecd47
movq $0x0, (%r14)
xorl %ebp, %ebp
testl %eax, %eax
movq %rdi, (%rsp)
je 0x1ecec0
movl %eax, %r15d
xorl %r12d, %r12d
xorl %r8d, %r8d
xorl %eax, %eax
xorl %r10d, %r10d
movq 0x20(%rdi), %rcx
movl %r12d, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1ecd7d
movq 0x30(%rdi), %rcx
cmpb $0x0, (%rcx,%r12)
je 0x1ecd90
movq %rax, %rbx
incq %r12
movq %rbx, %rax
cmpq %r15, %r12
jne 0x1ecd63
jmp 0x1ecec8
movq 0x28(%rdi), %rcx
movq (%rcx,%r12,8), %rcx
testl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
je 0x1ecd7d
movq %r8, 0x8(%rsp)
movq 0x8(%rdi), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
movl %ecx, %ecx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
xorl %r13d, %r13d
xorl %esi, %esi
movl (%rdx), %r9d
xorl %r8d, %r8d
testl %r9d, %r9d
setns %r8b
cmovsl %ebp, %r9d
addl %r8d, %esi
addl %r9d, %r13d
addq $0x18, %rdx
decq %rcx
jne 0x1ecdc3
cmpl $0x2, %esi
jae 0x1ecdf2
movq %rax, %rbx
movq 0x8(%rsp), %r8
jmp 0x1ecd80
movq %r10, %rcx
testq %r14, %r14
movq 0x8(%rsp), %r8
je 0x1ece02
movq (%r14), %rcx
movq %rax, %rdx
testq %r14, %r14
je 0x1ece0e
movq 0x8(%r14), %rdx
cmpq %rdx, %rcx
jne 0x1ece35
movq %rax, %rcx
testq %r14, %r14
je 0x1ece1f
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0x1ece3a
movq %rax, %rsi
testq %r14, %r14
je 0x1ece30
movq 0x8(%r14), %rsi
addq %rsi, %rsi
jmp 0x1ece3f
movq %rax, %rbx
jmp 0x1ece88
movl $0x2, %esi
movq %rsi, %rbx
testq %r14, %r14
je 0x1ece4e
movq %rsi, 0x8(%r14)
movq %rax, %rbx
movq %r10, 0x10(%rsp)
movq %r8, %rdi
testq %r14, %r14
je 0x1ece5f
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
testq %r14, %r14
je 0x1ece7c
movq %rax, 0x10(%r14)
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
jmp 0x1ece83
movq %rax, %r8
movq (%rsp), %rdi
movq 0x10(%rsp), %r10
movq %r8, %rax
testq %r14, %r14
je 0x1ece94
movq 0x10(%r14), %rax
movq %r10, %rcx
testq %r14, %r14
je 0x1ece9f
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
testq %r14, %r14
je 0x1ecead
movq %rdx, (%r14)
jmp 0x1eceb0
movq %rdx, %r10
shlq $0x20, %r13
orq %r12, %r13
movq %r13, (%rax,%rcx,8)
jmp 0x1ecd80
xorl %r10d, %r10d
xorl %ebx, %ebx
xorl %r8d, %r8d
movq %r8, %rdi
testq %r14, %r14
je 0x1eced4
movq 0x10(%r14), %rdi
movq %r8, %r15
testq %r14, %r14
je 0x1ecef3
movq (%r14), %rax
leaq (%rdi,%rax,8), %rsi
movq %r10, %r12
callq 0x1e3b6a
movq %r12, %r10
movl (%r14), %eax
jmp 0x1ecf05
leaq (%rdi,%r10,8), %rsi
movq %r10, %r12
callq 0x1e3b6a
movq %r12, %r10
movq %r12, %rax
testl %eax, %eax
movq (%rsp), %rdi
movq %r15, %r9
movq %rax, 0x40(%rsp)
je 0x1ed28e
movl %eax, %eax
movq %rax, 0x50(%rsp)
xorl %r12d, %r12d
movq %r9, %rax
testq %r14, %r14
je 0x1ecf2f
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %rax
movq 0x20(%rdi), %rcx
movl %eax, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1ecf52
movq 0x28(%rdi), %r13
movl %eax, %ecx
movq (%r13,%rcx,8), %r11
cmpl $0x2, %r11d
jae 0x1ecf57
movq %rbx, %rbp
jmp 0x1ecfb2
movq %r9, 0x8(%rsp)
movl %eax, %ecx
movq (%r13,%rcx,8), %rsi
movq %rsi, %r9
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rcx, %r9
je 0x1ecfaa
movq 0x8(%rdi), %rdx
movq %r11, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %r15
shrq $0x20, %rsi
xorl %r8d, %r8d
movl %esi, %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0xc(%rdx,%rcx,8), %ecx
notl %ecx
shrl $0x1f, %ecx
addl %ecx, %r8d
incq %rsi
decq %r9
jne 0x1ecf8a
cmpl $0x2, %r8d
jae 0x1ecfc8
movq %rbx, %rbp
movq 0x8(%rsp), %r9
incq %r12
movq %rbp, %rbx
cmpq 0x50(%rsp), %r12
jne 0x1ecf23
jmp 0x1ed28e
cmpl $0x1, %r11d
adcl $0x0, %r11d
addq $0x10, %rdx
xorl %esi, %esi
movq %r11, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r10, 0x10(%rsp)
movq %r13, 0x48(%rsp)
leaq (%rsi,%rsi,2), %rcx
movl 0xc(%r15,%rcx,8), %r8d
testl %r8d, %r8d
js 0x1ed0e0
leaq (%r15,%rcx,8), %rdi
movl 0x8(%rdi), %ecx
xorq $0x1, %rcx
movq (%r13,%rcx,8), %rcx
testl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
je 0x1ed26c
movq %rcx, %r9
shrq $0x20, %r9
movl %ecx, %r10d
leaq (%r9,%r9,2), %rcx
leaq (%rdx,%rcx,8), %r15
xorl %r11d, %r11d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl -0x4(%r15), %ecx
testl %ecx, %ecx
js 0x1ed066
incl %r11d
movl -0x8(%r15), %r13d
xorl %eax, %r13d
cmpl $0x1, %r13d
je 0x1ed066
cmpl %ebp, %ecx
cmovbl %ecx, %ebp
movzwl (%r15), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpl %ecx, %r9d
cmovael %ecx, %r9d
addq $0x18, %r15
decq %r10
jne 0x1ed038
cmpl $0x2, %r11d
jb 0x1ed278
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
movl %ebp, %ecx
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
mulss 0x34(%rsp), %xmm1
ucomiss %xmm1, %xmm0
movq 0x10(%rsp), %r10
ja 0x1ed26c
cmpl $0x0, 0x30(%rsp)
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %r15
movq 0x48(%rsp), %r13
je 0x1ed0e0
movzwl 0x10(%rdi), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movl %r9d, %ecx
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
mulss 0x2c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
ja 0x1ed26c
incq %rsi
cmpq %r11, %rsi
jne 0x1ecfea
xorl %r15d, %r15d
movq (%rsp), %rdi
movq 0x8(%rsp), %r9
leaq (%r15,%r15,2), %rax
movq 0x20(%rsp), %rdx
movl 0xc(%rdx,%rax,8), %ecx
testl %ecx, %ecx
js 0x1ed1b1
leaq (%rdx,%rax,8), %rax
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movl 0x8(%rax), %ecx
xorq $0x1, %rcx
movq 0x28(%rdi), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0x1ed173
movl 0x4(%rax), %eax
movq 0x8(%rdi), %rsi
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
movl -0x4(%rdx,%rsi), %r8d
xorl %eax, %r8d
cmpl $0x1, %r8d
jne 0x1ed16a
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x1ed157
movq %r10, %rax
testq %r14, %r14
je 0x1ed17e
movq (%r14), %rax
movq %rbx, %rcx
testq %r14, %r14
je 0x1ed18a
movq 0x8(%r14), %rcx
cmpq %rcx, %rax
jne 0x1ed1b9
movq %rbx, %rax
testq %r14, %r14
je 0x1ed19b
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x1ed1be
movq %rbx, %rsi
testq %r14, %r14
je 0x1ed1ac
movq 0x8(%r14), %rsi
addq %rsi, %rsi
jmp 0x1ed1c3
movq %rbx, %rbp
jmp 0x1ed25b
movq %rbx, %rbp
jmp 0x1ed20e
movl $0x2, %esi
movq %rsi, %rbp
testq %r14, %r14
je 0x1ed1d2
movq %rsi, 0x8(%r14)
movq %rbx, %rbp
movq %r10, %r13
movq %r9, %rbx
testq %r14, %r14
je 0x1ed1e1
movq 0x10(%r14), %r9
shlq $0x3, %rsi
movq %r9, %rdi
callq 0x2370
testq %r14, %r14
je 0x1ed1ff
movq %rax, 0x10(%r14)
movq (%rsp), %rdi
movq %rbx, %r9
jmp 0x1ed206
movq %rax, %r9
movq (%rsp), %rdi
movq %r13, %r10
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %rax
subq 0x8(%rdi), %rax
movq %r9, %rcx
testq %r14, %r14
je 0x1ed223
movq 0x10(%r14), %rcx
movq %r10, %rdx
testq %r14, %r14
je 0x1ed22e
movq (%r14), %rdx
leaq 0x1(%rdx), %rsi
testq %r14, %r14
je 0x1ed23c
movq %rsi, (%r14)
jmp 0x1ed23f
movq %rsi, %r10
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rax
addq %r15, %rax
movq %rax, (%rcx,%rdx,8)
movq %rbp, %rbx
incq %r15
cmpq %r11, %r15
jne 0x1ed0f8
jmp 0x1ecfb2
movq %rbx, %rbp
movq (%rsp), %rdi
jmp 0x1ecfad
movq %rbx, %rbp
movq (%rsp), %rdi
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r10
jmp 0x1ecfb2
movq %r10, %rax
testq %r14, %r14
je 0x1ed299
movq (%r14), %rax
movq 0x40(%rsp), %r8
movl %r8d, %ecx
movb $0x1, %bl
cmpq %rcx, %rax
jbe 0x1ed3e3
xorl %ebx, %ebx
movq 0x38(%rsp), %rsi
xorl %edx, %edx
movq %r9, %r15
movq %r8, %r13
movq %r10, %r12
callq 0xa6dbe
movq %r12, %r10
movq %r13, %r11
movq %r15, %r9
movq (%rsp), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r10, %rcx
testq %r14, %r14
je 0x1ed2e0
movq (%r14), %rcx
movl %r11d, %r11d
cmpq %r11, %rcx
jbe 0x1ed3de
movq %r9, %rsi
testq %r14, %r14
je 0x1ed2f8
movq 0x10(%r14), %rsi
movq %r9, %rdx
testq %r14, %r14
je 0x1ed304
movq 0x10(%r14), %rdx
movq 0x8(%rdi), %rcx
movq (%rsi,%r11,8), %rsi
leaq (%rsi,%rsi,2), %rsi
movl 0x4(%rcx,%rsi,8), %r8d
movq 0x30(%rdi), %rsi
cmpb $0x0, (%rsi,%r8)
jne 0x1ed347
xorq $0x1, %r8
cmpb $0x0, (%rsi,%r8)
jne 0x1ed347
movq (%rdx,%r11,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rcx,%rdx,8), %edx
cmpb $0x0, (%rsi,%rdx)
jne 0x1ed347
xorq $0x1, %rdx
cmpb $0x0, (%rsi,%rdx)
je 0x1ed34e
incl %ebx
incl %r11d
jmp 0x1ed2d5
movq %r9, %rdx
testq %r14, %r14
je 0x1ed35a
movq 0x10(%r14), %rdx
movq (%rdx,%r11,8), %rdx
leaq (%rdx,%rdx,2), %rdx
andl $0x7fffffff, 0xc(%rcx,%rdx,8) # imm = 0x7FFFFFFF
movq %r9, %rcx
testq %r14, %r14
je 0x1ed376
movq 0x10(%r14), %rcx
movq 0x8(%rdi), %rsi
movq (%rcx,%r11,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rsi,%rcx,8), %edx
xorq $0x1, %rdx
movq 0x28(%rdi), %r8
movq (%r8,%rdx,8), %r8
movq %r8, %rdx
andq %rax, %rdx
je 0x1ed349
movl 0x4(%rsi,%rcx,8), %ecx
shrq $0x20, %r8
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%r8,%r8,2), %r8
leaq (%rsi,%r8,8), %rsi
addq $0xc, %rsi
xorl %r9d, %r9d
movl -0x4(%rsi,%r9), %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
jne 0x1ed3cd
andb $0x7f, 0x3(%rsi,%r9)
addq $0x18, %r9
cmpq %r9, %rdx
jne 0x1ed3b9
movq %r15, %r9
jmp 0x1ed349
testl %ebx, %ebx
sete %bl
testq %r14, %r14
jne 0x1ed3f4
movq %r9, %rdi
callq 0x2220
movq (%rsp), %rdi
addq $0x58, %rsp
testb %bl, %bl
je 0x1ed407
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa02fa