// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x80(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x31c8b5
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x31c8bd
leaq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x60(%rbp), %eax
jae 0x31ca82
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31c8fa
jmp 0x31ca74
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x4c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x31ca72
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x4c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x64(%rbp)
cmpl $0x2, -0x64(%rbp)
jae 0x31c958
jmp 0x31ca74
movl $0x0, -0x74(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x31c9c6
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31c993
jmp 0x31c9bb
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x31c96d
cmpl $0x2, -0x6c(%rbp)
jae 0x31c9d1
jmp 0x31ca74
jmp 0x31c9d3
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x31ca44
movq -0x48(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x31ca03
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x31ca11
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x31ca11
movq -0xa0(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x74(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0x4c(%rbp), %eax
orq %rax, %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x31ca72
jmp 0x31ca74
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x31c8cf
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x48(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x84(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x84(%rbp), %eax
jae 0x31cedd
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31caf9
jmp 0x31cecf
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x4c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
cmpl $0x2, -0x64(%rbp)
jb 0x31cb51
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
cmpl $0x2, %eax
jae 0x31cb56
jmp 0x31cecf
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x31cd63
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31cb8a
jmp 0x31cd55
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x50(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
cmpl $0x2, -0x68(%rbp)
jae 0x31cbea
jmp 0x31cd63
movl $0x0, -0x70(%rbp)
movl $0x0, -0x54(%rbp)
movl $0xffffffff, -0x7c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x78(%rbp) # imm = 0xFFFFFFFF
movl -0x54(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x31cce6
movq -0x98(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31cc33
jmp 0x31ccd8
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movq -0x98(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x4c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x31cc5c
jmp 0x31ccd8
movq -0x98(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x78(%rbp), %eax
jae 0x31cc96
movq -0x98(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x78(%rbp)
movq -0x98(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
cmpl -0x7c(%rbp), %eax
jae 0x31ccd6
movq -0x98(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
movl %eax, -0x7c(%rbp)
jmp 0x31ccd8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x31cc06
cmpl $0x2, -0x70(%rbp)
jae 0x31ccee
jmp 0x31cd63
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0xc(%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2ss %eax, %xmm0
movl -0x78(%rbp), %eax
cvtsi2ss %rax, %xmm1
mulss -0x14(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x31cd1d
jmp 0x31cd63
cmpl $0x0, -0x1c(%rbp)
je 0x31cd53
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
movzwl 0x10(%rax,%rcx,8), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cvtsi2ss %eax, %xmm0
movl -0x7c(%rbp), %eax
cvtsi2ss %rax, %xmm1
mulss -0x18(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x31cd53
jmp 0x31cd63
jmp 0x31cd55
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x31cb5d
movl -0x5c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x31cd70
jmp 0x31cecf
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x31cecd
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31cda4
jmp 0x31cebf
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x90(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0x31bd30
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x31ce7b
movq -0x48(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x31ce3a
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x31ce48
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x31ce48
movq -0xa8(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x90(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movq %rax, %rdx
movl -0x5c(%rbp), %eax
addq %rax, %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x31cebf
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x31cd77
jmp 0x31cecf
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x31cab9
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl -0x84(%rbp), %ecx
cmpq %rcx, %rax
jbe 0x31d04f
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0xd8550
movl -0x84(%rbp), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x80(%rbp)
movl -0x58(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x31d04d
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x4c(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
jne 0x31cfb6
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x4c(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
jne 0x31cfb6
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
jne 0x31cfb6
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x31cfc1
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x31d03f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x31bd30
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x31cf12
jmp 0x31d04f
cmpq $0x0, -0x10(%rbp)
jne 0x31d05f
movq -0x30(%rbp), %rdi
callq 0x2210
cmpl $0x0, -0x80(%rbp)
jbe 0x31d06e
movq -0x8(%rbp), %rdi
callq 0xcdd10
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)