// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_arc_cut_chimeric_cmk(asg_t*, asg64_v*, int, float, float, unsigned int, unsigned int, unsigned int, unsigned int, unsigned char*, unsigned int)
void asg_arc_cut_chimeric_cmk(asg_t *g, asg64_v *in, int32_t max_ext, float len_rat, float ou_rat, uint32_t is_ou, uint32_t is_topo, uint32_t min_ou, uint32_t test_bub, uint8_t *cmk, uint32_t cmk_cut)
{
    asg64_v tx = {0,0,0}, *b = NULL; asg_arc_t *av, *aw, *ve, *we; 
    uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
    
    if(in) b = in;
    else b = &tx;
	b->n = 0;

    for (v = 0; v < n_vtx; ++v) {
        // if((v>>1)==17078) fprintf(stderr, "[M::%s::] v:%u, del:%u, seq_vis:%u\n", __func__, v, g->seq[v>>1].del, g->seq_vis[v]);
        if (g->seq[v>>1].del) continue;
        if (cmk[v>>1] > cmk_cut) continue;
        if((test_bub == 0) || (g->seq_vis[v] == 0)) {
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
            if (nv < 2) continue;

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

            for (i = 0; i < nv; ++i) {
                if(av[i].del) continue;
                kv_push(uint64_t, *b, (((uint64_t)av[i].ol)<<32) | ((uint64_t)(av-g->arc+i)));
            }
        }
	}

    radix_sort_srt64(b->a, b->a + b->n);
    for (k = 0; k < b->n; k++) {
        if(g->arc[(uint32_t)b->a[k]].del) continue;

        v = g->arc[(uint32_t)b->a[k]].ul>>32; w = g->arc[(uint32_t)b->a[k]].v^1;
        if(g->seq[v>>1].del || g->seq[w>>1].del) continue;
        nv = asg_arc_n(g, v); nw = asg_arc_n(g, w);
        av = asg_arc_a(g, v); aw = asg_arc_a(g, w);
        if(nv<=1 && nw <= 1) continue;

        ve = &(g->arc[(uint32_t)b->a[k]]);
        for (i = 0; i < nw; ++i) {
            if (aw[i].v == (v^1)) {
                we = &(aw[i]);
                break;
            }
        }
        ///mm_ol and mm_ou are used to make edge with long indel more easy to be cutted
        mm_ol = MIN(ve->ol, we->ol); mm_ou = MIN(ve->ou, we->ou);

        for (i = kv = ol_max = ou_max = 0; i < nv; ++i) {
            if(av[i].del) continue;
            kv++;
            
            if(ol_max < av[i].ol) ol_max = av[i].ol;
            if(ou_max < av[i].ou) ou_max = av[i].ou;
        }
        if (kv < 1) continue;
        if (kv >= 2) {
            if (mm_ol > ol_max*len_rat) continue;
            if (is_ou && mm_ou > ou_max*ou_rat && mm_ou > min_ou) continue;
        }
        

        for (i = kw = ol_max = ou_max = 0; i < nw; ++i) {
            if(aw[i].del) continue;
            kw++;

            if(ol_max < aw[i].ol) ol_max = aw[i].ol;
            if(ou_max < aw[i].ou) ou_max = aw[i].ou;
        }
        if (kw < 1) continue;
        if (kw >= 2) {
            if (mm_ol > ol_max*len_rat) continue;
            if (is_ou && mm_ou > ou_max*ou_rat && mm_ou > min_ou) continue;
        }

        if (kv <= 1 && kw <= 1) continue;

        to_del = 0;
        if(is_topo) {
            if (kv > 1 && kw > 1) {
                to_del = 1;
            } else if (kw == 1) {
                if (asg_topocut_aux(g, w^1, max_ext) < max_ext) to_del = 1;
            } else if (kv == 1) {
                if (asg_topocut_aux(g, v^1, max_ext + 1) < max_ext + 1) to_del = 1;
            }
        }

        if (to_del) {
            asg_seq_del(g, v>>1); ++cnt;
        }
    }
    // stats_sysm(g);
    if(!in) free(tx.a);
    if (cnt > 0) asg_cleanup(g);

    // fprintf(stderr, "[M::%s::] cnt:%u\n", __func__, cnt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x30(%rsp)
movl %r8d, 0x60(%rsp)
movl %ecx, 0x38(%rsp)
movss %xmm1, 0x34(%rsp)
movss %xmm0, 0x3c(%rsp)
movq %rdx, 0x48(%rsp)
movl 0xb0(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0x64(%rsp)
movq %rdi, 0x10(%rsp)
movl 0x14(%rdi), %eax
addl %eax, %eax
movq %rsi, 0x20(%rsp)
testq %rsi, %rsi
je 0x1f4229
movq 0x20(%rsp), %rcx
movq $0x0, (%rcx)
testl %eax, %eax
je 0x1f4434
movl %eax, %ebx
xorl %r15d, %r15d
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
xorl %r9d, %r9d
xorl %r13d, %r13d
xorl %r8d, %r8d
movq %rbx, 0x50(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
movl %r15d, %eax
shrl %eax
cmpl $0x0, (%rcx,%rax,8)
js 0x1f4426
movq 0x40(%rsp), %rcx
movzbl (%rcx,%rax), %eax
cmpl 0x2c(%rsp), %eax
ja 0x1f4426
cmpl $0x0, 0x64(%rsp)
je 0x1f429a
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rax
cmpb $0x0, (%rax,%r15)
jne 0x1f4426
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r15,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1f4426
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rsi
movq %rsi, 0x18(%rsp)
movl %eax, %esi
leaq (%rcx,%rdx,8), %rbp
addq $0xc, %rbp
xorl %eax, %eax
movq %rsi, 0x8(%rsp)
movq %rsi, %rcx
movq %rbp, %rdx
movl (%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %eax
addq $0x18, %rdx
decq %rcx
jne 0x1f42e6
cmpl $0x2, %eax
jb 0x1f4426
xorl %r14d, %r14d
cmpl $0x0, (%rbp)
js 0x1f4414
cmpq $0x0, 0x20(%rsp)
je 0x1f437f
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
cmpq 0x8(%rcx), %rax
jne 0x1f43c4
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq 0x20(%rsp), %rbx
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
movq %r8, %r12
movq %r13, 0x58(%rsp)
movq %r9, %r13
callq 0x2370
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq %r13, %r9
movq 0x58(%rsp), %r13
movq %r12, %r8
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movq %rax, 0x10(%rbx)
movq 0x50(%rsp), %rbx
jmp 0x1f43c4
cmpq %r13, %r8
jne 0x1f43c4
leaq (,%r13,2), %r12
testq %r13, %r13
movl $0x2, %eax
cmoveq %rax, %r12
leaq (,%r12,8), %rsi
movq %r9, %rdi
movq %r8, %r13
callq 0x2370
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq %r13, %r8
movq %rax, %r9
movq %r12, %r13
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movl (%rbp), %eax
andl %r11d, %eax
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdx
subq 0x8(%rdx), %rcx
cmpq $0x0, 0x20(%rsp)
je 0x1f43f5
movq 0x20(%rsp), %r10
movq (%r10), %rdx
movq 0x10(%r10), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%r10)
jmp 0x1f43fe
movq %r8, %rdx
incq %r8
movq %r9, %rsi
shlq $0x20, %rax
sarq $0x3, %rcx
imulq %r12, %rcx
addq %r14, %rcx
orq %rax, %rcx
movq %rcx, (%rsi,%rdx,8)
incq %r14
addq $0x18, %rbp
cmpq %r14, 0x8(%rsp)
jne 0x1f4304
incq %r15
cmpq %rbx, %r15
jne 0x1f4254
jmp 0x1f443a
xorl %r8d, %r8d
xorl %r9d, %r9d
movq %r9, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq %r8, %rax
cmpq $0x0, 0x20(%rsp)
je 0x1f445b
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x10(%rcx), %r9
leaq (%r9,%rax,8), %rsi
movq %r9, %rdi
callq 0x1ee586
movq 0x48(%rsp), %rax
incl %eax
movl %eax, 0x50(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x40(%rsp)
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rdi
movl %r12d, %r12d
cmpq $0x0, 0x20(%rsp)
je 0x1f44b8
movq 0x20(%rsp), %rax
cmpq %r12, (%rax)
jbe 0x1f48e4
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl (%rcx,%r12,8), %ecx
jmp 0x1f44ce
cmpq %r12, %r8
jbe 0x1f48df
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rdi,%r12,8), %ecx
leaq (%rcx,%rcx,2), %rdx
cmpl $0x0, 0xc(%rax,%rdx,8)
js 0x1f4874
leaq (%rax,%rdx,8), %rdx
movq (%rdx), %rbp
movq 0x10(%rsp), %rdx
movq 0x20(%rdx), %rdx
movq %rbp, %r15
shrq $0x21, %r15
cmpl $0x0, (%rdx,%r15,8)
js 0x1f4874
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %r13d
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rdx,%rcx,8)
js 0x1f4874
shrq $0x20, %rbp
movq %r13, %rdx
xorq $0x1, %rdx
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rsi
movq (%rsi,%rbp,8), %rcx
movq (%rsi,%rdx,8), %r10
cmpl $0x1, %ecx
ja 0x1f4542
cmpl $0x2, %r10d
jb 0x1f4874
movq %rdi, %rdx
cmpq $0x0, 0x20(%rsp)
je 0x1f4556
movq 0x20(%rsp), %rdx
movq 0x10(%rdx), %rdx
movq %r10, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r11
testl %r10d, %r10d
je 0x1f4588
leaq (%rax,%r11,8), %rsi
movl %r10d, %r8d
movl 0x8(%rsi), %r9d
xorl %ebp, %r9d
cmpl $0x1, %r9d
je 0x1f4585
addq $0x18, %rsi
decq %r8
jne 0x1f456d
jmp 0x1f4588
movq %rsi, %rbx
movl (%rdx,%r12,8), %edx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
movl 0xc(%rdx), %esi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %esi
movl 0xc(%rbx), %r8d
andl %r9d, %r8d
cmpl %r8d, %esi
cmovbl %esi, %r8d
movzwl 0x10(%rdx), %edx
movl $0x3fff, %esi           # imm = 0x3FFF
andl %esi, %edx
movzwl 0x10(%rbx), %r9d
andl %esi, %r9d
cmpw %r9w, %dx
cmovbl %edx, %r9d
testl %ecx, %ecx
je 0x1f486f
movq %r11, 0x58(%rsp)
movq %r10, %rdi
movl %r9d, 0x2c(%rsp)
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r9
addq $0x10, %r9
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r14
xorl %edx, %edx
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %ecx, %ecx
movl -0x4(%r9,%rdx), %esi
testl %esi, %esi
js 0x1f4629
incl %ecx
cmpl %esi, %r11d
cmovbel %esi, %r11d
movzwl (%r9,%rdx), %esi
andl $0x3fff, %esi           # imm = 0x3FFF
cmpl %esi, %r10d
cmovbel %esi, %r10d
addq $0x18, %rdx
cmpq %rdx, %r14
jne 0x1f4605
testl %ecx, %ecx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
je 0x1f47cd
cmpl $0x1, %ecx
jne 0x1f47b8
testl %edi, %edi
je 0x1f47cd
movl %edi, %r10d
movq 0x58(%rsp), %rdx
leaq (%rax,%rdx,8), %r11
addq $0x10, %r11
xorl %esi, %esi
xorl %r9d, %r9d
xorl %eax, %eax
movl -0x4(%r11), %edx
testl %edx, %edx
js 0x1f4688
incl %eax
cmpl %edx, %r9d
cmovbel %edx, %r9d
movzwl (%r11), %edx
andl $0x3fff, %edx           # imm = 0x3FFF
cmpl %edx, %esi
cmovbel %edx, %esi
addq $0x18, %r11
decq %r10
jne 0x1f4668
testl %eax, %eax
je 0x1f47cd
cmpl $0x1, %eax
movq 0x18(%rsp), %rdi
jne 0x1f481c
movl %ecx, %edx
xorl $0x1, %edx
movl %eax, %esi
xorl $0x1, %esi
orl %edx, %esi
sete %dl
cmpl $0x0, 0x60(%rsp)
je 0x1f486f
testb %dl, %dl
movq 0x8(%rsp), %r8
jne 0x1f4874
cmpl $0x1, %ecx
setne %dl
cmpl $0x1, %eax
setne %sil
testb %sil, %dl
je 0x1f487c
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
orl $0x80000000, (%rax,%r15,8) # imm = 0x80000000
andl $-0x2, %ebp
movb $0x1, %al
xorl %ecx, %ecx
orq %rbp, %rcx
movq 0x10(%rsp), %rdx
movq 0x28(%rdx), %rdx
movq (%rdx,%rcx,8), %rsi
movq %rsi, %rdx
andq %r14, %rdx
je 0x1f47a0
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x3, %rsi
movq 0x10(%rsp), %rdi
addq 0x8(%rdi), %rsi
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r8
orb $-0x80, 0xf(%rsi,%r8,8)
movl 0x8(%rsi,%r8,8), %r8d
xorq $0x1, %r8
movq 0x10(%rsp), %r9
movq 0x28(%r9), %r9
movq (%r9,%r8,8), %r9
movq %r9, %r8
andq %r14, %r8
je 0x1f4798
movq 0x10(%rsp), %r10
movq 0x8(%r10), %r10
shrq $0x20, %r9
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
leaq (%r9,%r9,2), %r9
leaq (%r10,%r9,8), %r9
addq $0xc, %r9
xorl %r10d, %r10d
movl -0x4(%r9,%r10), %r11d
xorl %ecx, %r11d
cmpl $0x1, %r11d
jne 0x1f478f
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0x1f477b
incq %rdi
cmpq %rdx, %rdi
jne 0x1f472f
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x1f46fc
incl 0x40(%rsp)
jmp 0x1f47cd
cvtsi2ss %r11d, %xmm0
cvtsi2ss %r8d, %xmm1
mulss 0x3c(%rsp), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1f47dc
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rdi
jmp 0x1f4874
cmpl $0x0, 0x38(%rsp)
je 0x1f4649
xorps %xmm0, %xmm0
cvtsi2ss %r10d, %xmm0
movl 0x2c(%rsp), %esi
movswl %si, %edx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
mulss 0x34(%rsp), %xmm0
ucomiss %xmm0, %xmm1
seta %dl
cmpl 0x30(%rsp), %esi
seta %sil
testb %sil, %dl
je 0x1f4649
jmp 0x1f47cd
xorps %xmm0, %xmm0
cvtsi2ss %r9d, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r8d, %xmm1
mulss 0x3c(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x1f486f
cmpl $0x0, 0x38(%rsp)
je 0x1f46a7
xorps %xmm0, %xmm0
cvtsi2ss %esi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x2c(%rsp), %xmm1
mulss 0x34(%rsp), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1f46a7
movl 0x2c(%rsp), %edx
cmpl 0x30(%rsp), %edx
jbe 0x1f46a7
movq 0x8(%rsp), %r8
incl %r12d
jmp 0x1f4487
cmpl $0x1, %eax
jne 0x1f48b1
movq 0x10(%rsp), %rdi
movl %r13d, %esi
movq 0x48(%rsp), %r14
movl %r14d, %edx
callq 0xab75d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r8
cmpl %r14d, %eax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jl 0x1f46e4
jmp 0x1f4874
cmpl $0x1, %ecx
jne 0x1f4874
movl %ebp, %esi
xorl $0x1, %esi
movq 0x10(%rsp), %rdi
movl 0x50(%rsp), %edx
callq 0xab75d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r8
cmpl 0x48(%rsp), %eax
jle 0x1f46e4
jmp 0x1f4874
callq 0x2220
cmpl $0x0, 0x40(%rsp)
je 0x1f4903
movq 0x10(%rsp), %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0a7d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq