// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %r9, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %rcx, 0x90(%rsp)
movl %edx, 0x60(%rsp)
movss %xmm2, 0x5c(%rsp)
movss %xmm1, 0x58(%rsp)
movss %xmm0, 0x64(%rsp)
movq %rsi, %r12
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq 0x120(%rsp), %r13
movaps %xmm0, (%r13)
xorl %ebx, %ebx
movq %rbx, 0x10(%r13)
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
movups %xmm0, 0x110(%rsp)
movups %xmm0, 0x100(%rsp)
movups %xmm0, 0xf0(%rsp)
movups %xmm0, 0xe0(%rsp)
movups %xmm0, 0xd0(%rsp)
movups %xmm0, 0xc0(%rsp)
movl $0x1c, %esi
movq %r14, %rdi
callq 0x2120
movq %r13, %r9
movq %rax, 0xb8(%rsp)
testq %r12, %r12
movq %r12, 0x98(%rsp)
cmovneq %r12, %r9
movq %rbx, (%r9)
testl %r14d, %r14d
movq %r15, 0x20(%rsp)
movq %r9, 0x18(%rsp)
je 0x1f750d
movq %r15, %r8
movl $0x2, %r15d
xorl %r12d, %r12d
movq 0x20(%r8), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1f7463
movq 0x30(%r8), %rax
cmpb $0x0, (%rax,%r12)
je 0x1f7470
incq %r12
cmpq %r14, %r12
jne 0x1f7449
jmp 0x1f750d
movq 0x28(%r8), %rax
movq (%rax,%r12,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1f7463
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 %ebx, %esi
addl %edi, %edx
addl %esi, %r13d
addq $0x18, %rcx
decq %rax
jne 0x1f749d
cmpl $0x2, %edx
jb 0x1f7463
movq (%r9), %rcx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rcx
jne 0x1f74f6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r15, %rsi
movq %rsi, 0x8(%r9)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
movq %rax, 0x10(%r9)
movq (%r9), %rcx
shlq $0x20, %r13
orq %r12, %r13
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
movq %r13, (%rax,%rcx,8)
jmp 0x1f7463
cmpq $0x0, 0x40(%rsp)
sete %al
cmpq $0x0, 0x48(%rsp)
sete %cl
orb %al, %cl
jne 0x1f753d
movq 0x20(%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 0x1ee586
movq 0x18(%rsp), %rcx
movq (%rcx), %rax
testl %eax, %eax
je 0x1f7ac6
movl %eax, %r9d
movq %rax, 0x70(%rsp)
addl $0x2, %eax
movq %rax, 0x88(%rsp)
xorl %r13d, %r13d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0x0, 0x3c(%rsp)
movq 0x20(%rsp), %r11
movq %r9, 0x10(%rsp)
movq 0x10(%rcx), %rax
movq (%rax,%r13,8), %r10
movq 0x20(%r11), %rsi
movl %r10d, %edx
shrl %edx
cmpl $0x0, (%rsi,%rdx,8)
js 0x1f7989
movq 0x28(%r11), %rsi
movl %r10d, %edx
movq (%rsi,%rdx,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x1f7989
movq %rdx, %rdi
andq %r15, %rdi
je 0x1f7989
movq 0x8(%r11), %r9
movq %rdx, 0x78(%rsp)
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rsi
leaq (%r9,%rsi,8), %r12
xorl %esi, %esi
movq %rdi, 0xa0(%rsp)
movl %edx, %r8d
leaq (%r8,%r8,2), %r8
movl 0xc(%r9,%r8,8), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %esi
incq %rdx
decq %rdi
jne 0x1f75e8
cmpl $0x2, %esi
jb 0x1f7984
movq %r13, 0x28(%rsp)
movq 0x10(%rsp), %rdx
movq %rdx, (%rcx)
movl 0x78(%rsp), %edx
movq %rdx, 0xa8(%rsp)
xorl %edi, %edi
xorl %r8d, %r8d
movq %r10, 0x30(%rsp)
movq %r12, 0x50(%rsp)
leaq (%rdi,%rdi,2), %rdx
cmpl $0x0, 0xc(%r12,%rdx,8)
js 0x1f781f
leaq (%r12,%rdx,8), %rbx
movl 0x8(%rbx), %edx
xorq $0x1, %rdx
movq 0x28(%r11), %rsi
movq (%rsi,%rdx,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x1f7968
movq %rbx, 0xb0(%rsp)
movl %r8d, 0x68(%rsp)
movq %rdi, 0x80(%rsp)
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r9,%rsi,8), %r8
movl %edx, %ebx
leaq (%r9,%rsi,8), %r14
addq $0x10, %r14
xorl %ebp, %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl -0x4(%r14), %edx
testl %edx, %edx
js 0x1f7767
incl %r15d
movl -0x8(%r14), %esi
xorl %r10d, %esi
cmpl $0x1, %esi
je 0x1f7767
cmpl %r13d, %edx
cmovbl %edx, %r13d
movzwl (%r14), %edx
andl $0x3fff, %edx           # imm = 0x3FFF
cmpl %edx, %r12d
cmovael %edx, %r12d
movq (%rcx), %rdx
cmpq 0x8(%rcx), %rdx
jne 0x1f7741
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
movl %r15d, 0x6c(%rsp)
movq %rbx, %r15
movl %r13d, %ebx
movl %r12d, %r13d
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movl %r13d, %r12d
movl %ebx, %r13d
movq %r15, %rbx
movl 0x6c(%rsp), %r15d
movq 0x30(%rsp), %r10
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r11
movq %rax, 0x10(%rcx)
movq 0x8(%r11), %r9
movq (%rcx), %rdx
movq %r8, %rsi
subq %r9, %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdi, %rsi
addq %rbp, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx)
movq %rsi, (%rax,%rdx,8)
incq %rbp
addq $0x18, %r14
cmpq %rbp, %rbx
jne 0x1f76a5
cmpl $0x2, %r15d
jb 0x1f7968
movq 0xb0(%rsp), %rdi
movl 0xc(%rdi), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
movl %r13d, %edx
xorps %xmm2, %xmm2
cvtsi2ss %rdx, %xmm2
movaps %xmm2, %xmm1
mulss 0x64(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1f77c2
mulss 0x58(%rsp), %xmm2
ucomiss %xmm2, %xmm0
ja 0x1f7968
xorl %edx, %edx
ucomiss %xmm1, %xmm0
seta %dl
movl 0x68(%rsp), %r8d
addl %edx, %r8d
cmpl $0x0, 0x60(%rsp)
je 0x1f7812
movzwl 0x10(%rdi), %edx
andl $0x3fff, %edx           # imm = 0x3FFF
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
movl %r12d, %edx
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
mulss 0x5c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
movq 0x50(%rsp), %r12
movq 0x80(%rsp), %rdi
jbe 0x1f781f
jmp 0x1f7968
movq 0x50(%rsp), %r12
movq 0x80(%rsp), %rdi
incq %rdi
cmpq 0xa8(%rsp), %rdi
jne 0x1f7637
testl %r8d, %r8d
movq 0x28(%rsp), %r13
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq 0xa0(%rsp), %rax
je 0x1f78b7
movq %r12, %rbx
xorl %r14d, %r14d
cmpl $0x0, 0xc(%rbx)
js 0x1f78a8
movq %rbx, %rdx
testq %r14, %r14
je 0x1f78ab
movl 0x8(%r14), %edi
movl 0x8(%rbx), %esi
movq %rcx, (%rsp)
movq %r11, %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movl 0x170(%rsp), %r9d
movq %rax, %rbp
callq 0x1f2aa9
movq 0x30(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r11
movq %r14, %rdx
cmpl $0x1, %eax
movq %rbp, %rax
je 0x1f78ab
jmp 0x1f799a
movq %r14, %rdx
addq $0x18, %rbx
movq %rdx, %r14
decq %rax
jne 0x1f784e
movl %r10d, %edi
movq %r11, %rsi
leaq 0xb8(%rsp), %rdx
movq 0x70(%rsp), %r8
movq 0x90(%rsp), %r9
callq 0x1f6f1f
testl %eax, %eax
je 0x1f797a
movl 0x78(%rsp), %eax
xorl %ecx, %ecx
movq 0x20(%rsp), %r11
leaq (%rcx,%rcx,2), %rdx
movl 0xc(%r12,%rdx,8), %esi
testl %esi, %esi
js 0x1f795a
leaq (%r12,%rdx,8), %rdx
orl $0x80000000, %esi       # imm = 0x80000000
movl %esi, 0xc(%rdx)
movl 0x8(%rdx), %esi
xorq $0x1, %rsi
movq 0x28(%r11), %rdi
movq (%rdi,%rsi,8), %rdi
movq %rdi, %rsi
andq %r15, %rsi
je 0x1f795a
movl 0x4(%rdx), %edx
movq 0x8(%r11), %r8
shrq $0x20, %rdi
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%r8,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
movl -0x4(%rdi,%r8), %r9d
xorl %edx, %r9d
cmpl $0x1, %r9d
jne 0x1f7951
orb $-0x80, 0x3(%rdi,%r8)
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x1f793d
incq %rcx
cmpq %rax, %rcx
jne 0x1f78ea
incl 0x3c(%rsp)
jmp 0x1f797f
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r13
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x1f7989
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r9
incq %r13
cmpq %r9, %r13
jne 0x1f758b
jmp 0x1f7abc
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%rcx), %r12
cmpq 0x88(%rsp), %r12
jb 0x1f7972
movq %r9, %rbx
cmpq %r9, %r12
jbe 0x1f7aa3
xorl %r15d, %r15d
movq 0x70(%rsp), %r14
movq 0x8(%r11), %rax
movq 0x10(%rcx), %rdx
movq (%rdx,%rbx,8), %rdx
leaq (%rdx,%rdx,2), %rsi
cmpl $0x0, 0xc(%rax,%rsi,8)
js 0x1f7a7d
movl 0x4(%rax,%rsi,8), %edx
movq 0x28(%r11), %rdi
movq (%rdi,%rdx,8), %rdi
movq %rdi, %r8
andq %rbp, %r8
je 0x1f7aa3
leaq (%rax,%rsi,8), %rdx
shrq $0x20, %rdi
xorl %r9d, %r9d
movl %edi, %r10d
leaq (%r10,%r10,2), %r10
movl 0xc(%rax,%r10,8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
incq %rdi
decq %r8
jne 0x1f79fe
cmpl $0x2, %r9d
jne 0x1f7a94
testq %r15, %r15
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r9
movq 0x30(%rsp), %r10
je 0x1f7a80
movl 0x8(%r15), %edi
movl 0x8(%rax,%rsi,8), %esi
movq %rcx, (%rsp)
movq %r11, %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movl 0x170(%rsp), %r9d
callq 0x1f2aa9
movq 0x30(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r11
movq (%rcx), %r12
movq %r15, %rdx
cmpl $0x1, %eax
je 0x1f7a80
jmp 0x1f7aa3
movq %r15, %rdx
incl %r14d
movq %r14, %rbx
movq %rdx, %r15
cmpq %r14, %r12
ja 0x1f79c0
jmp 0x1f7aa3
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r9
movq 0x30(%rsp), %r10
cmpq %rbx, %r12
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq 0x50(%rsp), %r12
jbe 0x1f78b7
jmp 0x1f7989
cmpl $0x0, 0x3c(%rsp)
sete %bl
jmp 0x1f7ac8
movb $0x1, %bl
cmpq $0x0, 0x98(%rsp)
jne 0x1f7ae0
movq 0x130(%rsp), %rdi
callq 0x2220
movq 0xb8(%rsp), %rdi
callq 0x2220
movq 0xd0(%rsp), %rdi
callq 0x2220
movq 0xe8(%rsp), %rdi
callq 0x2220
movq 0x100(%rsp), %rdi
callq 0x2220
movq 0x118(%rsp), %rdi
callq 0x2220
testb %bl, %bl
jne 0x1f7b2f
movq 0x20(%rsp), %rdi
callq 0xa0a7d
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq