// File: /workspace/github_cpp_makefile_star2_O1/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, 0x1c(%rsp)
movl %r8d, 0x5c(%rsp)
movl %ecx, 0x24(%rsp)
movss %xmm1, 0x20(%rsp)
movss %xmm0, 0x2c(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
movl 0xb0(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0x48(%rsp)
movl 0x14(%rdi), %eax
addl %eax, %eax
testq %rsi, %rsi
je 0x1e971c
movq $0x0, (%r12)
testl %eax, %eax
je 0x1e990c
movl %eax, %eax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
xorl %r8d, %r8d
xorl %eax, %eax
xorl %r9d, %r9d
movq %rbx, 0x60(%rsp)
movq 0x20(%rbx), %rdx
movl %r15d, %ecx
shrl %ecx
cmpl $0x0, (%rdx,%rcx,8)
js 0x1e97d1
movq 0x50(%rsp), %rdx
movzbl (%rdx,%rcx), %ecx
cmpl 0x4(%rsp), %ecx
ja 0x1e97d1
cmpl $0x0, 0x48(%rsp)
je 0x1e977b
movq 0x30(%rbx), %rcx
cmpb $0x0, (%rcx,%r15)
jne 0x1e97d1
movq 0x28(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
testl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
je 0x1e97d1
movq 0x8(%rbx), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdi
movq %rdi, 0x8(%rsp)
movl %ecx, %edi
leaq (%rdx,%rsi,8), %r13
addq $0xc, %r13
xorl %ecx, %ecx
movq %rdi, 0x40(%rsp)
movq %rdi, %rdx
movq %r13, %rsi
movl (%rsi), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %ecx
addq $0x18, %rsi
decq %rdx
jne 0x1e97ba
cmpl $0x2, %ecx
jae 0x1e97ea
movq %rax, %r14
incq %r15
movq %r14, %rax
cmpq 0x38(%rsp), %r15
jne 0x1e974b
jmp 0x1e9912
xorl %ebp, %ebp
cmpl $0x0, (%r13)
js 0x1e9835
movq %r9, %rcx
testq %r12, %r12
je 0x1e97ff
movq (%r12), %rcx
movq %rax, %rdx
testq %r12, %r12
je 0x1e980c
movq 0x8(%r12), %rdx
cmpq %rdx, %rcx
jne 0x1e983d
movq %rax, %rcx
testq %r12, %r12
je 0x1e981e
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x1e9842
movq %rax, %rsi
testq %r12, %r12
je 0x1e9830
movq 0x8(%r12), %rsi
addq %rsi, %rsi
jmp 0x1e9847
movq %rax, %r14
jmp 0x1e98f5
movq %rax, %r14
jmp 0x1e98a1
movl $0x2, %esi
movq %rsi, %r14
testq %r12, %r12
je 0x1e9857
movq %rsi, 0x8(%r12)
movq %rax, %r14
movq %r9, %rbx
movq %r8, 0x10(%rsp)
movq %r8, %rdi
testq %r12, %r12
je 0x1e986c
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
testq %r12, %r12
je 0x1e9886
movq %rax, 0x10(%r12)
movq 0x10(%rsp), %r8
jmp 0x1e9889
movq %rax, %r8
movq %rbx, %r9
movq 0x60(%rsp), %rbx
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
movl (%r13), %eax
andl %r10d, %eax
movq 0x8(%rsp), %rcx
subq 0x8(%rbx), %rcx
movq %r8, %rdx
testq %r12, %r12
je 0x1e98be
movq 0x10(%r12), %rdx
movq %r9, %rsi
testq %r12, %r12
je 0x1e98ca
movq (%r12), %rsi
leaq 0x1(%rsi), %rdi
testq %r12, %r12
je 0x1e98d9
movq %rdi, (%r12)
jmp 0x1e98dc
movq %rdi, %r9
shlq $0x20, %rax
sarq $0x3, %rcx
imulq %r11, %rcx
addq %rbp, %rcx
orq %rax, %rcx
movq %rcx, (%rdx,%rsi,8)
movq %r14, %rax
incq %rbp
addq $0x18, %r13
cmpq %rbp, 0x40(%rsp)
jne 0x1e97ec
jmp 0x1e97d4
xorl %r9d, %r9d
xorl %r8d, %r8d
movq %r8, %rdi
testq %r12, %r12
je 0x1e991f
movq 0x10(%r12), %rdi
movq %r8, 0x10(%rsp)
movq %r9, 0x8(%rsp)
movq %r9, %rax
testq %r12, %r12
je 0x1e9935
movq (%r12), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1e3b6a
movq 0x30(%rsp), %rax
incl %eax
movl %eax, 0x58(%rsp)
xorl %r13d, %r13d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0x0, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r9
movq %r9, %rax
testq %r12, %r12
je 0x1e9970
movq (%r12), %rax
movl %r13d, %r13d
cmpq %r13, %rax
jbe 0x1e9daf
movq %rdi, %rcx
testq %r12, %r12
je 0x1e9989
movq 0x10(%r12), %rcx
movq 0x8(%rbx), %rax
movl (%rcx,%r13,8), %ecx
leaq (%rcx,%rcx,2), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
js 0x1e9da7
movq %rdi, %rcx
testq %r12, %r12
je 0x1e99ad
movq 0x10(%r12), %rcx
movq %rdi, %rdx
testq %r12, %r12
je 0x1e99ba
movq 0x10(%r12), %rdx
movl (%rcx,%r13,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r14
movq 0x20(%rbx), %rcx
movq %r14, %rbp
shrq $0x21, %rbp
cmpl $0x0, (%rcx,%rbp,8)
js 0x1e9da7
movl (%rdx,%r13,8), %edx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rax,%rdx,8), %esi
movl %esi, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1e9da7
shrq $0x20, %r14
movq %rsi, %rdx
xorq $0x1, %rdx
movq 0x28(%rbx), %r8
movq (%r8,%r14,8), %rcx
movq (%r8,%rdx,8), %r8
cmpl $0x1, %ecx
ja 0x1e9a1b
cmpl $0x2, %r8d
jb 0x1e9da7
movq %rdi, %rdx
testq %r12, %r12
je 0x1e9a28
movq 0x10(%r12), %rdx
movq %r8, %r9
shrq $0x20, %r9
leaq (%r9,%r9,2), %r9
testl %r8d, %r8d
movq %r8, 0x40(%rsp)
movq %r9, 0x48(%rsp)
je 0x1e9a66
leaq (%rax,%r9,8), %r11
movl %r8d, %r10d
movl 0x8(%r11), %r9d
xorl %r14d, %r9d
cmpl $0x1, %r9d
je 0x1e9a61
addq $0x18, %r11
decl %r10d
jne 0x1e9a49
jmp 0x1e9a66
movq %r11, 0x50(%rsp)
movl (%rdx,%r13,8), %edx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
movl 0xc(%rdx), %r11d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %r11d
movq 0x50(%rsp), %r10
movl 0xc(%r10), %r8d
andl %r9d, %r8d
cmpl %r8d, %r11d
cmovbl %r11d, %r8d
movl %r8d, 0x4(%rsp)
movzwl 0x10(%rdx), %edx
movl $0x3fff, %r9d           # imm = 0x3FFF
andl %r9d, %edx
movzwl 0x10(%r10), %r10d
andl %r9d, %r10d
cmpw %r10w, %dx
cmovbl %edx, %r10d
movl %r10d, (%rsp)
testl %ecx, %ecx
movq %rsi, 0x38(%rsp)
je 0x1e9b29
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r10
addq $0x10, %r10
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r11
xorl %r9d, %r9d
xorl %edx, %edx
xorl %esi, %esi
xorl %ecx, %ecx
movq 0x40(%rsp), %r8
movl -0x4(%r10,%r9), %edi
testl %edi, %edi
js 0x1e9b0c
incl %ecx
cmpl %edi, %esi
cmovbel %edi, %esi
movzwl (%r10,%r9), %edi
andl $0x3fff, %edi           # imm = 0x3FFF
cmpl %edi, %edx
cmovbel %edi, %edx
addq $0x18, %r9
cmpq %r9, %r11
jne 0x1e9aec
cvtsi2ss %esi, %xmm1
cvtsi2ss %edx, %xmm0
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
jmp 0x1e9b36
xorps %xmm1, %xmm1
xorl %ecx, %ecx
xorps %xmm0, %xmm0
movq 0x40(%rsp), %r8
testl %ecx, %ecx
movq 0x8(%rsp), %r9
je 0x1e9da7
cmpl $0x1, %ecx
jne 0x1e9bbb
testl %r8d, %r8d
je 0x1e9c04
movl %r8d, %edx
movq 0x48(%rsp), %rsi
leaq (%rax,%rsi,8), %r8
addq $0x10, %r8
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r9
xorl %r10d, %r10d
xorl %edx, %edx
xorl %esi, %esi
xorl %eax, %eax
movl -0x4(%r8,%r10), %r11d
testl %r11d, %r11d
js 0x1e9b98
incl %eax
cmpl %r11d, %esi
cmovbel %r11d, %esi
movzwl (%r8,%r10), %r11d
andl $0x3fff, %r11d          # imm = 0x3FFF
cmpl %r11d, %edx
cmovbel %r11d, %edx
addq $0x18, %r10
cmpq %r10, %r9
jne 0x1e9b72
xorps %xmm1, %xmm1
cvtsi2ss %esi, %xmm1
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
movq 0x8(%rsp), %r9
movq 0x38(%rsp), %rsi
jmp 0x1e9c0c
cvtsi2ssl 0x4(%rsp), %xmm2
mulss 0x2c(%rsp), %xmm1
ucomiss %xmm1, %xmm2
ja 0x1e9da7
cmpl $0x0, 0x24(%rsp)
je 0x1e9b48
xorps %xmm1, %xmm1
cvtsi2ssl (%rsp), %xmm1
mulss 0x20(%rsp), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1e9b48
movl (%rsp), %edx
cmpl 0x1c(%rsp), %edx
ja 0x1e9da7
jmp 0x1e9b48
xorps %xmm1, %xmm1
xorl %eax, %eax
xorps %xmm0, %xmm0
testl %eax, %eax
je 0x1e9da7
cmpl $0x1, %eax
jne 0x1e9c6f
movl %ecx, %edx
xorl $0x1, %edx
movl %eax, %r8d
xorl $0x1, %r8d
orl %edx, %r8d
sete %dl
cmpl $0x0, 0x5c(%rsp)
je 0x1e9da7
testb %dl, %dl
jne 0x1e9da7
cmpl $0x1, %ecx
setne %dl
cmpl $0x1, %eax
setne %r8b
testb %r8b, %dl
jne 0x1e9ceb
cmpl $0x1, %eax
jne 0x1e9cb7
movq %rbx, %rdi
movq 0x30(%rsp), %rdx
callq 0xaa77e
cmpl 0x30(%rsp), %eax
setge %al
jmp 0x1e9cd9
xorps %xmm2, %xmm2
cvtsi2ssl 0x4(%rsp), %xmm2
mulss 0x2c(%rsp), %xmm1
ucomiss %xmm1, %xmm2
ja 0x1e9da7
cmpl $0x0, 0x24(%rsp)
je 0x1e9c19
xorps %xmm1, %xmm1
cvtsi2ssl (%rsp), %xmm1
mulss 0x20(%rsp), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1e9c19
movl (%rsp), %edx
cmpl 0x1c(%rsp), %edx
ja 0x1e9da7
jmp 0x1e9c19
cmpl $0x1, %ecx
jne 0x1e9da7
movl %r14d, %esi
xorl $0x1, %esi
movq %rbx, %rdi
movl 0x58(%rsp), %edx
callq 0xaa77e
cmpl 0x30(%rsp), %eax
setg %al
testb %al, %al
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r9
jne 0x1e9da7
movq 0x20(%rbx), %rax
orl $0x80000000, (%rax,%rbp,8) # imm = 0x80000000
andl $-0x2, %r14d
xorl %eax, %eax
leaq (%rax,%r14), %rcx
movq 0x28(%rbx), %rdx
movq (%rdx,%rcx,8), %rsi
movq %rsi, %rdx
andq %r15, %rdx
je 0x1e9d89
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x3, %rsi
addq 0x8(%rbx), %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 0x28(%rbx), %r9
movq (%r9,%r8,8), %r9
movq %r9, %r8
andq %r15, %r8
je 0x1e9d81
movq 0x8(%rbx), %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 0x1e9d78
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0x1e9d64
incq %rdi
cmpq %rdx, %rdi
jne 0x1e9d22
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0x1e9cfc
incl 0x28(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r9
incl %r13d
jmp 0x1e9964
testq %r12, %r12
jne 0x1e9db9
callq 0x2220
cmpl $0x0, 0x28(%rsp)
je 0x1e9dd6
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa02fa
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq