// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_arc_cut_bub_links(asg_t*, asg64_v*, float, float, float, unsigned int, unsigned long, ma_hit_t_alloc*, R_to_U*, int)
void asg_arc_cut_bub_links(asg_t *g, asg64_v *in, float len_rat, float sec_len_rat, float ou_rat, uint32_t is_ou, uint64_t check_dist, ma_hit_t_alloc *rev, R_to_U* rI, int32_t max_ext)
{
    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, bn, me, mu, cnt = 0, sec_check;
    asg_arc_t *av, *aw, *ref;
    buf_t x; memset(&x, 0, sizeof(x)); x.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));

    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));  
        }
    }

    if(rev && rI) memset(g->seq_vis, 0, g->n_seq*2*sizeof(uint8_t));
    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, b->n = bn, sec_check = 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;
                kv_push(uint64_t, *b, ((uint64_t)(aw-g->arc+t)));                
            }
            if(kw < 2) break;

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

        if(i < nv) continue;

        if(sec_check) {
            for (i = 0, ref = NULL; i < nv; i++) {//forward
                if (av[i].del) continue;
                if(!ref) {
                    ref = &(av[i]);
                } else {
                    if(trans_path_check(ref->v, av[i].v, g, rev, rI, max_ext, b)!=1) break;
                }
            }

            if(i < nv) {
                if (b->n < bn + 2) continue;///less than two edges
                for (i = bn, ref = NULL; i < b->n; i++) {
                    if(g->arc[b->a[i]].del) continue;
                    if(get_arcs(g, g->arc[b->a[i]].ul>>32, NULL, 0)!=2) break;
                    if(!ref) {
                        ref = &(g->arc[b->a[i]]);
                    } else {
                        if(trans_path_check(ref->v, g->arc[b->a[i]].v, g, rev, rI, max_ext, b)!=1) break;
                    }
                }
                if(i < b->n) continue;
            }
        }

        if(if_false_bub_links(v, g, &x, b, bn, check_dist)) {
            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);
            }
            cnt++;
        }
    }

    // stats_sysm(g);
    if(!in) free(tx.a);
    free(x.a); free(x.S.a); free(x.T.a); free(x.b.a); free(x.e.a);
    if(cnt > 0) asg_cleanup(g);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0xa8(%rsp)
movl %edx, 0x60(%rsp)
movss %xmm2, 0x5c(%rsp)
movss %xmm1, 0x58(%rsp)
movss %xmm0, 0x64(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x130(%rsp), %r13
movaps %xmm0, (%r13)
xorl %r15d, %r15d
movq %r15, 0x10(%r13)
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
movq %r15, 0x120(%rsp)
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movl $0x1c, %esi
movq %r14, %rdi
callq 0x2120
movq %r13, %r9
movq %rax, 0xc0(%rsp)
testq %r12, %r12
movq %r12, 0xb0(%rsp)
cmovneq %r12, %r9
movq %r15, (%r9)
testl %r14d, %r14d
movq %rbx, 0x10(%rsp)
movq %r9, 0x18(%rsp)
je 0x1ec6a3
movq %rbx, %r8
movl %r14d, %ebx
movl $0x2, %r14d
xorl %r12d, %r12d
movq 0x20(%r8), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1ec5f7
movq 0x30(%r8), %rax
cmpb $0x0, (%rax,%r12)
je 0x1ec604
incq %r12
cmpq %rbx, %r12
jne 0x1ec5dd
jmp 0x1ec6a3
movq 0x28(%r8), %rax
movq (%rax,%r12,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1ec5f7
movq 0x8(%r8), %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 %edi, %edi
testl %esi, %esi
setns %dil
cmovsl %r15d, %esi
addl %edi, %edx
addl %esi, %r13d
addq $0x18, %rcx
decq %rax
jne 0x1ec631
cmpl $0x2, %edx
jb 0x1ec5f7
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0x1ec685
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rax, 0x10(%r9)
shlq $0x20, %r13
orq %r12, %r13
movq 0x10(%r9), %rax
movq (%r9), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
movq %r13, (%rax,%rcx,8)
jmp 0x1ec5f7
cmpq $0x0, 0x48(%rsp)
sete %al
cmpq $0x0, 0x50(%rsp)
sete %cl
orb %al, %cl
jne 0x1ec6d3
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rdi
movl 0x14(%rax), %edx
addl %edx, %edx
xorl %esi, %esi
callq 0x20e0
movq 0x18(%rsp), %r9
movq 0x10(%r9), %rdi
movq (%r9), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1e3b6a
movq 0x18(%rsp), %r11
movq (%r11), %rax
testl %eax, %eax
je 0x1ecc95
movl %eax, %ecx
movq %rcx, 0x40(%rsp)
movq %rax, 0x68(%rsp)
addl $0x2, %eax
movq %rax, 0xa0(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x3c(%rsp)
movq 0x10(%rsp), %r10
movq 0x10(%r11), %rax
movq (%rax,%r12,8), %rdi
movq 0x20(%r10), %rax
movl %edi, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1ecc7d
movq 0x28(%r10), %rax
movl %edi, %ecx
movq (%rax,%rcx,8), %r13
cmpl $0x2, %r13d
jb 0x1ecc7d
movl %edi, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x1ecc7d
movq 0x8(%r10), %rdx
movq %r13, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rbp
shrq $0x20, %rax
xorl %esi, %esi
movl %eax, %r8d
leaq (%r8,%r8,2), %r8
movl 0xc(%rdx,%r8,8), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %esi
incq %rax
decq %rcx
jne 0x1ec778
cmpl $0x2, %esi
jb 0x1ecc7d
movq 0x40(%rsp), %rax
movq %rax, (%r11)
cmpl $0x1, %r13d
movl %r13d, %r15d
adcl $0x0, %r15d
movl %r13d, %eax
movq %rax, 0xb8(%rsp)
xorl %r8d, %r8d
movb $0x1, %sil
xorl %edx, %edx
movq %rdi, 0x28(%rsp)
movq %r12, 0x88(%rsp)
movq %r13, 0x80(%rsp)
movq %rbp, 0x78(%rsp)
movq %r15, 0x70(%rsp)
leaq (%r8,%r8,2), %rax
cmpl $0x0, 0xc(%rbp,%rax,8)
js 0x1ec9e2
leaq (,%rax,8), %rax
addq %rbp, %rax
movq %rax, 0x98(%rsp)
movl 0x8(%rax), %eax
xorq $0x1, %rax
movq 0x28(%r10), %rcx
movq (%rcx,%rax,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1eca1f
movq %r8, 0x90(%rsp)
movb %sil, 0xf(%rsp)
movl %edx, 0x24(%rsp)
movq 0x8(%r10), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r8
movl %eax, %ebp
leaq (%rcx,%rdx,8), %r12
addq $0x10, %r12
xorl %r13d, %r13d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl -0x4(%r12), %eax
testl %eax, %eax
js 0x1ec914
incl %r15d
movl -0x8(%r12), %ecx
xorl %edi, %ecx
cmpl $0x1, %ecx
je 0x1ec914
cmpl %ebx, %eax
cmovbl %eax, %ebx
movzwl (%r12), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpl %eax, %r9d
cmovael %eax, %r9d
movq 0x8(%r11), %rax
cmpq %rax, (%r11)
jne 0x1ec8e6
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r11)
movq 0x10(%r11), %rdi
shlq $0x3, %rsi
movl %ebx, 0x30(%rsp)
movq %r8, %rbx
movl %r9d, %r14d
callq 0x2370
movl %r14d, %r9d
movq %rbx, %r8
movl 0x30(%rsp), %ebx
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r10
movq %rax, 0x10(%r11)
movq %r8, %rax
subq 0x8(%r10), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq %r13, %rax
movq 0x10(%r11), %rcx
movq (%r11), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r11)
movq %rax, (%rcx,%rdx,8)
incq %r13
addq $0x18, %r12
cmpq %r13, %rbp
jne 0x1ec85f
cmpl $0x2, %r15d
jb 0x1ec9fc
movq 0x98(%rsp), %rax
movl 0xc(%rax), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl %ebx, %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
movaps %xmm2, %xmm1
mulss 0x64(%rsp), %xmm1
ucomiss %xmm1, %xmm0
movq 0x88(%rsp), %r12
movq 0x80(%rsp), %r13
movq 0x78(%rsp), %rbp
movq 0x70(%rsp), %r15
jbe 0x1ec988
mulss 0x58(%rsp), %xmm2
ucomiss %xmm2, %xmm0
ja 0x1eca16
xorl %eax, %eax
ucomiss %xmm1, %xmm0
seta %al
movl 0x24(%rsp), %edx
addl %eax, %edx
cmpl $0x0, 0x60(%rsp)
je 0x1ec9da
movq 0x98(%rsp), %rax
movzwl 0x10(%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl %r9d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
mulss 0x5c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
movb 0xf(%rsp), %sil
movq 0x90(%rsp), %r8
jbe 0x1ec9e2
jmp 0x1eca1f
movq 0x90(%rsp), %r8
incq %r8
cmpq 0xb8(%rsp), %r8
setb %sil
cmpq %r15, %r8
jne 0x1ec7e4
jmp 0x1eca1f
movq 0x88(%rsp), %r12
movq 0x80(%rsp), %r13
movq 0x78(%rsp), %rbp
movq 0x70(%rsp), %r15
movl 0x24(%rsp), %edx
movb 0xf(%rsp), %sil
testb $0x1, %sil
jne 0x1ecc7d
testl %edx, %edx
je 0x1eca91
movq %rbp, %rbx
xorl %r14d, %r14d
cmpl $0x0, 0xc(%rbx)
js 0x1eca82
movq %rbx, %rcx
testq %r14, %r14
je 0x1eca85
movl 0x8(%r14), %edi
movl 0x8(%rbx), %esi
movq %r11, (%rsp)
movq %r10, %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movl 0x180(%rsp), %r9d
callq 0x1e7fa4
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r10
movq %r14, %rcx
cmpl $0x1, %eax
je 0x1eca85
jmp 0x1ecb6a
movq %r14, %rcx
addq $0x18, %rbx
movq %rcx, %r14
decq %r15
jne 0x1eca33
movq %r10, %rsi
leaq 0xc0(%rsp), %rdx
movq %r11, %rcx
movq 0x68(%rsp), %r8
movq 0xa8(%rsp), %r9
callq 0x1ec0b5
testl %eax, %eax
je 0x1ecb5b
cmpl $0x1, %r13d
adcl $0x0, %r13d
xorl %eax, %eax
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r11
leaq (%rax,%rax,2), %rcx
movl 0xc(%rbp,%rcx,8), %edx
testl %edx, %edx
js 0x1ecb46
leaq (,%rcx,8), %rcx
addq %rbp, %rcx
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, 0xc(%rcx)
movl 0x8(%rcx), %edx
xorq $0x1, %rdx
movq 0x28(%r10), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rdx
je 0x1ecb46
movl 0x4(%rcx), %ecx
movq 0x8(%r10), %rdi
shrq $0x20, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
movl -0x4(%rsi,%rdi), %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
jne 0x1ecb3d
orb $-0x80, 0x3(%rsi,%rdi)
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0x1ecb2a
incq %rax
cmpq %r13, %rax
jne 0x1ecacd
incl 0x3c(%rsp)
jmp 0x1ecc7d
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r11
jmp 0x1ecc7d
movq 0xa0(%rsp), %rax
cmpq %rax, (%r11)
jb 0x1ecc7d
movq 0x40(%rsp), %rax
movq %rax, %rbx
cmpq %rax, (%r11)
jbe 0x1ecc74
movq 0x40(%rsp), %rbx
xorl %r15d, %r15d
movq 0x68(%rsp), %r14
movq 0x8(%r10), %rax
movq 0x10(%r11), %rcx
movq (%rcx,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
js 0x1ecc53
movq %rbx, 0x30(%rsp)
movl 0x4(%rax,%rcx,8), %edx
movq 0x28(%r10), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rbx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rbx
je 0x1ecc6f
leaq (%rax,%rcx,8), %rdx
shrq $0x20, %rsi
xorl %r8d, %r8d
movl %esi, %r9d
leaq (%r9,%r9,2), %r9
movl 0xc(%rax,%r9,8), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
incq %rsi
decq %rbx
jne 0x1ecbe1
cmpl $0x2, %r8d
jne 0x1ecc6a
testq %r15, %r15
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rbx
je 0x1ecc56
movl 0x8(%r15), %edi
movl 0x8(%rax,%rcx,8), %esi
movq %r11, (%rsp)
movq %r10, %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movl 0x180(%rsp), %r9d
callq 0x1e7fa4
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r10
movq %r15, %rdx
cmpl $0x1, %eax
je 0x1ecc56
jmp 0x1ecc74
movq %r15, %rdx
incl %r14d
movq %r14, %rbx
movq %rdx, %r15
cmpq %r14, (%r11)
ja 0x1ecb99
jmp 0x1ecc74
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rbx
cmpq %rbx, (%r11)
jbe 0x1eca91
incq %r12
cmpq 0x40(%rsp), %r12
jne 0x1ec71a
cmpl $0x0, 0x3c(%rsp)
sete %bl
jmp 0x1ecc97
movb $0x1, %bl
cmpq $0x0, 0xb0(%rsp)
jne 0x1eccaf
movq 0x140(%rsp), %rdi
callq 0x2220
movq 0xc0(%rsp), %rdi
callq 0x2220
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0xf0(%rsp), %rdi
callq 0x2220
movq 0x108(%rsp), %rdi
callq 0x2220
movq 0x120(%rsp), %rdi
callq 0x2220
testb %bl, %bl
jne 0x1eccfe
movq 0x10(%rsp), %rdi
callq 0xa02fa
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq