// File: /workspace/github_cpp_makefile_star2_O3/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, 0x40(%rsp)
movl %edx, 0x28(%rsp)
movss %xmm1, 0x24(%rsp)
movss %xmm0, 0x2c(%rsp)
movq %rsi, %r9
movl 0x14(%rdi), %eax
addl %eax, %eax
testq %rsi, %rsi
je 0x1f7b78
movq $0x0, (%r9)
xorl %r15d, %r15d
testl %eax, %eax
movq %rdi, 0x8(%rsp)
movq %r9, (%rsp)
je 0x1f7ccb
movl %eax, %r12d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %esi, %esi
movq $0x0, 0x10(%rsp)
movq 0x20(%rdi), %rax
movl %ebp, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1f7bb7
movq 0x30(%rdi), %rax
cmpb $0x0, (%rax,%rbp)
je 0x1f7bc4
incq %rbp
cmpq %r12, %rbp
jne 0x1f7b9f
jmp 0x1f7cd9
movq 0x28(%rdi), %rax
movq (%rax,%rbp,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1f7bb7
movq %rsi, %rbx
movq 0x8(%rdi), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rcx
addq $0xc, %rcx
xorl %r13d, %r13d
xorl %edx, %edx
movl (%rcx), %esi
xorl %r8d, %r8d
testl %esi, %esi
setns %r8b
cmovsl %r15d, %esi
addl %r8d, %edx
addl %esi, %r13d
addq $0x18, %rcx
decq %rax
jne 0x1f7bf4
cmpl $0x2, %edx
jae 0x1f7c1c
movq %rbx, %rsi
jmp 0x1f7bb7
testq %r9, %r9
movq %rbx, %rsi
je 0x1f7c63
movq (%r9), %rcx
cmpq 0x8(%r9), %rcx
jne 0x1f7c98
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rbx, %rsi
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%r9)
movq (%r9), %rcx
jmp 0x1f7c9c
cmpq %rsi, 0x10(%rsp)
jne 0x1f7ca5
leaq (%rsi,%rsi), %rbx
testq %rsi, %rsi
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq %r14, %rdi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
jmp 0x1f7ca8
movq 0x10(%r9), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
jmp 0x1f7cbb
movq %r14, %rax
movq 0x10(%rsp), %rdx
movq %rdx, %rcx
incq %rdx
movq %rax, %r14
movq %rdx, 0x10(%rsp)
shlq $0x20, %r13
orq %rbp, %r13
movq %r13, (%rax,%rcx,8)
jmp 0x1f7bb7
movq $0x0, 0x10(%rsp)
xorl %esi, %esi
xorl %r14d, %r14d
movq %rsi, 0x38(%rsp)
testq %r9, %r9
je 0x1f7cfc
movq (%r9), %rax
movq 0x10(%r9), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1ee586
movq (%rsp), %r9
movl (%r9), %ebx
jmp 0x1f7d11
movq 0x10(%rsp), %rbx
leaq (%r14,%rbx,8), %rsi
movq %r14, %rdi
callq 0x1ee586
movq (%rsp), %r9
testl %ebx, %ebx
movq %rbx, 0x30(%rsp)
je 0x1f8047
movl %ebx, %eax
movq %rax, 0x48(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
movq %r14, %rax
testq %r9, %r9
je 0x1f7d38
movq 0x10(%r9), %rax
movq (%rax,%rbp,8), %rax
movq 0x20(%rdi), %rcx
movl %eax, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1f8037
movq 0x28(%rdi), %rcx
movl %eax, %edx
movq %rcx, 0x50(%rsp)
movq (%rcx,%rdx,8), %rsi
testl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
je 0x1f8037
movq %rsi, %r11
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rcx, %r11
je 0x1f8037
movq 0x8(%rdi), %rdx
movq %rsi, %r8
shrq $0x20, %r8
leaq (%r8,%r8,2), %r9
leaq (%rdx,%r9,8), %r12
xorl %r9d, %r9d
movl %r8d, %r10d
leaq (%r10,%r10,2), %r10
movl 0xc(%rdx,%r10,8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
incq %r8
decq %r11
jne 0x1f7d90
cmpl $0x2, %r9d
jae 0x1f7dc2
movq 0x8(%rsp), %rdi
movq (%rsp), %r9
jmp 0x1f8037
movl %esi, %r13d
addq $0x10, %rdx
xorl %esi, %esi
movq %r14, 0x18(%rsp)
leaq (%rsi,%rsi,2), %rdi
movl 0xc(%r12,%rdi,8), %r8d
testl %r8d, %r8d
js 0x1f7ec2
leaq (%r12,%rdi,8), %rdi
movl 0x8(%rdi), %r9d
xorq $0x1, %r9
movq 0x50(%rsp), %rcx
movq (%rcx,%r9,8), %r9
testl $0xfffffffe, %r9d       # imm = 0xFFFFFFFE
je 0x1f7db4
movq %r13, %rcx
movq %r9, %r11
shrq $0x20, %r11
movl %r9d, %r10d
leaq (%r11,%r11,2), %r9
leaq (%rdx,%r9,8), %r15
xorl %r11d, %r11d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl -0x4(%r15), %r14d
testl %r14d, %r14d
js 0x1f7e53
incl %r11d
movl -0x8(%r15), %ebx
xorl %eax, %ebx
cmpl $0x1, %ebx
je 0x1f7e53
cmpl %r13d, %r14d
cmovbl %r14d, %r13d
movzwl (%r15), %ebx
andl $0x3fff, %ebx           # imm = 0x3FFF
cmpl %ebx, %r9d
cmovael %ebx, %r9d
addq $0x18, %r15
decq %r10
jne 0x1f7e24
cmpl $0x2, %r11d
jb 0x1f8029
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
movl %r13d, %r8d
xorps %xmm1, %xmm1
cvtsi2ss %r8, %xmm1
mulss 0x2c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
ja 0x1f8029
cmpl $0x0, 0x28(%rsp)
movq 0x18(%rsp), %r14
movq %rcx, %r13
je 0x1f7ec2
movzwl 0x10(%rdi), %edi
andl $0x3fff, %edi           # imm = 0x3FFF
xorps %xmm0, %xmm0
cvtsi2ss %edi, %xmm0
movl %r9d, %edi
xorps %xmm1, %xmm1
cvtsi2ss %rdi, %xmm1
mulss 0x24(%rsp), %xmm1
ucomiss %xmm1, %xmm0
ja 0x1f7db4
incq %rsi
cmpq %r13, %rsi
jne 0x1f7dd0
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
movq (%rsp), %r9
leaq (%r15,%r15,2), %rax
movl 0xc(%r12,%rax,8), %ecx
testl %ecx, %ecx
js 0x1f801b
leaq (%r12,%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 0x1f7f51
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 0x1f7f48
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x1f7f35
testq %r9, %r9
je 0x1f7f96
movq (%r9), %rcx
cmpq 0x8(%r9), %rcx
jne 0x1f7fed
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x3, %rsi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%r9)
movq (%r9), %rcx
jmp 0x1f7ff1
movq 0x38(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x1f7fd3
leaq (%rax,%rax), %rbx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq %r14, %rdi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rax, %r14
movq %rbx, 0x38(%rsp)
movq 0x8(%rdi), %rdx
movq 0x10(%rsp), %rax
movq %rax, %rcx
leaq 0x1(%rax), %rsi
movq %r14, %rax
movq %rsi, 0x10(%rsp)
jmp 0x1f7ffc
movq 0x10(%r9), %rax
movq 0x8(%rdi), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r9)
movq %r12, %rsi
subq %rdx, %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rsi
addq %r15, %rsi
movq %rsi, (%rax,%rcx,8)
incq %r15
cmpq %r13, %r15
jne 0x1f7eda
jmp 0x1f8037
movq 0x8(%rsp), %rdi
movq (%rsp), %r9
movq 0x18(%rsp), %r14
incq %rbp
cmpq 0x48(%rsp), %rbp
jne 0x1f7d2c
jmp 0x1f804c
movq 0x8(%rsp), %rdi
testq %r9, %r9
je 0x1f8062
movq 0x30(%rsp), %rbx
movl %ebx, %eax
cmpq %rax, (%r9)
ja 0x1f8077
jmp 0x1f81be
movq 0x30(%rsp), %rbx
movl %ebx, %eax
xorl %r15d, %r15d
cmpq %rax, 0x10(%rsp)
jbe 0x1f8199
xorl %r15d, %r15d
movq 0x40(%rsp), %rsi
xorl %edx, %edx
callq 0xa7e08
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebx, %ebx
testq %r9, %r9
je 0x1f80aa
cmpq %rbx, (%r9)
jbe 0x1f81a6
movq 0x10(%r9), %rsi
jmp 0x1f80b8
movq %r14, %rsi
cmpq %rbx, 0x10(%rsp)
jbe 0x1f8199
movq 0x8(%rdi), %rcx
movq 0x30(%rdi), %rdx
movq (%rsi,%rbx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
movq (%rcx,%rsi,8), %r8
shrq $0x20, %r8
cmpb $0x0, (%rdx,%r8)
jne 0x1f80f6
xorq $0x1, %r8
cmpb $0x0, (%rdx,%r8)
jne 0x1f80f6
movl 0x8(%rcx,%rsi,8), %esi
cmpb $0x0, (%rdx,%rsi)
jne 0x1f80f6
xorq $0x1, %rsi
cmpb $0x0, (%rdx,%rsi)
je 0x1f80fd
incl %r15d
incl %ebx
jmp 0x1f8094
testq %r9, %r9
je 0x1f811c
movq 0x10(%r9), %rdx
movq (%rdx,%rbx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
andl $0x7fffffff, 0xc(%rcx,%rdx,8) # imm = 0x7FFFFFFF
movq 0x10(%r9), %rcx
jmp 0x1f812f
movq (%r14,%rbx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
andl $0x7fffffff, 0xc(%rcx,%rdx,8) # imm = 0x7FFFFFFF
movq %r14, %rcx
movq 0x8(%rdi), %rsi
movq 0x28(%rdi), %rdx
movq (%rcx,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rsi,%rcx,8), %r8d
xorq $0x1, %r8
movq (%rdx,%r8,8), %r8
movq %r8, %rdx
andq %rax, %rdx
je 0x1f80f9
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 0x1f8187
andb $0x7f, 0x3(%rsi,%r9)
addq $0x18, %r9
cmpq %r9, %rdx
jne 0x1f8173
movq (%rsp), %r9
jmp 0x1f80f9
movq %r14, %rdi
callq 0x2220
movq 0x8(%rsp), %rdi
testl %r15d, %r15d
je 0x1f81be
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0a7d
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq