// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_arc_cut_length_adv(asg_t*, asg64_v*, int, float, float, unsigned int, unsigned int, unsigned int, unsigned int, ma_hit_t_alloc*, R_to_U*, unsigned int*)
void asg_arc_cut_length_adv(asg_t *g, asg64_v *in, int32_t max_ext, float len_rat, float ou_rat, uint32_t is_ou, uint32_t is_trio, 
uint32_t is_topo, uint32_t min_diff, ma_hit_t_alloc *rev, R_to_U* rI, uint32_t *max_drop_len)
{
    asg64_v tx = {0,0,0}, *b = NULL;
    uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
    asg_arc_t *av, *aw, *ve, *we, *vl_max, *wl_max;

    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 = 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;
                if(max_drop_len && av[i].ol >= (*max_drop_len)) continue;
                kv_push(uint64_t, *b, (((uint64_t)av[i].ol)<<32) | ((uint64_t)(av-g->arc+i)));   
            }
        }
	}

    if(rev && rI) memset(g->seq_vis, 0, g->n_seq*2*sizeof(uint8_t));
    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;

        if(is_trio) {
            if(get_arcs(g, v, NULL, 0)<=1 && get_arcs(g, w, NULL, 0)<=1) continue;///speedup
            trioF = get_tip_trio_infor(g, v^1);
            ntrioF = (trioF==FATHER? MOTHER : (trioF==MOTHER? FATHER : (uint32_t)-1));
        }

        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, /**ve =**/ vl_max = NULL; i < nv; ++i) {
            if(av[i].del) continue;
            kv++;
            if(is_trio && get_tip_trio_infor(g, av[i].v) == ntrioF) continue;
            if(ol_max < av[i].ol) ol_max = av[i].ol, vl_max = &(av[i]);
            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) continue;
            if ((mm_ol + min_diff) > ol_max) continue;
        }
        

        for (i = kw = ol_max = ou_max = 0, wl_max = NULL; i < nw; ++i) {
            if(aw[i].del) continue;
            kw++;
            if(is_trio && get_tip_trio_infor(g, aw[i].v) == ntrioF) continue;
            if(ol_max < aw[i].ol) ol_max = aw[i].ol, wl_max = &(aw[i]);
            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) continue;
            if ((mm_ol + min_diff) > ol_max) 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) < max_ext) to_del = 1;
            }
        }

        if(rev && rI) {
            if((to_del == 0) && vl_max && (ve->v!=vl_max->v) && (trans_path_check(ve->v, vl_max->v, g, rev, rI, max_ext, b)==0)) {
                to_del = 1;
            }
            if((to_del == 0) && wl_max && (we->v!=wl_max->v) && (trans_path_check(we->v, wl_max->v, g, rev, rI, max_ext, b)==0)) {
                to_del = 1;
            }
            if(vl_max && wl_max) assert(ve->v!=vl_max->v||we->v!=wl_max->v);
        }
        

        if (to_del) {
            ve->del = we->del = 1, ++cnt;
        }
    }
    // stats_sysm(g);
    if(!in) free(tx.a);
    if (cnt > 0) asg_cleanup(g);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %r9d, 0x84(%rsp)
movl %r8d, 0x34(%rsp)
movl %ecx, 0x54(%rsp)
movss %xmm1, 0x4c(%rsp)
movss %xmm0, 0x58(%rsp)
movl %edx, 0x30(%rsp)
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %r8
movaps %xmm0, (%r8)
xorl %ecx, %ecx
movq %rcx, 0x10(%r8)
movl 0x14(%rdi), %eax
addl %eax, %eax
testq %rsi, %rsi
movq %rsi, 0x90(%rsp)
cmovneq %rsi, %r8
movq %rcx, (%r8)
testl %eax, %eax
movq %rdi, 0x18(%rsp)
movq %r8, 0x20(%rsp)
je 0x1e9fab
movq 0x108(%rsp), %r10
movl %eax, %r9d
xorl %r12d, %r12d
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
movq 0x20(%rdi), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1e9e8d
movq 0x30(%rdi), %rax
cmpb $0x0, (%rax,%r12)
je 0x1e9e9a
incq %r12
cmpq %r9, %r12
jne 0x1e9e73
jmp 0x1e9fab
movq 0x28(%rdi), %rax
movq (%rax,%r12,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1e9e8d
movq 0x8(%rdi), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r14
movl %eax, %r13d
leaq (%rcx,%rdx,8), %r15
addq $0xc, %r15
xorl %eax, %eax
movq %r13, %rcx
movq %r15, %rdx
movl (%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %eax
addq $0x18, %rdx
decq %rcx
jne 0x1e9ecf
cmpl $0x2, %eax
jb 0x1e9e8d
xorl %ebp, %ebp
movq %r14, 0x10(%rsp)
movq %r13, 0x40(%rsp)
movl (%r15), %eax
testl %eax, %eax
js 0x1e9f96
testq %r10, %r10
je 0x1e9f0b
cmpl (%r10), %eax
jae 0x1e9f96
movq 0x8(%r8), %rax
cmpq %rax, (%r8)
jne 0x1e9f65
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r8)
movq 0x10(%r8), %rdi
shlq $0x3, %rsi
movq %r9, %r14
movq %rbx, %r13
movq %r10, %rbx
callq 0x2370
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq %rbx, %r10
movq %r13, %rbx
movq 0x40(%rsp), %r13
movq %r14, %r9
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%r8)
movl (%r15), %eax
andl %r11d, %eax
shlq $0x20, %rax
movq %r14, %rcx
subq 0x8(%rdi), %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
addq %rbp, %rcx
orq %rax, %rcx
movq 0x10(%r8), %rax
movq (%r8), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r8)
movq %rcx, (%rax,%rdx,8)
incq %rbp
addq $0x18, %r15
cmpq %rbp, %r13
jne 0x1e9ef2
jmp 0x1e9e8d
cmpq $0x0, 0xf8(%rsp)
setne %al
cmpq $0x0, 0x100(%rsp)
setne %bl
andb %al, %bl
cmpb $0x1, %bl
jne 0x1e9fe4
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rdi
movl 0x14(%rax), %edx
addl %edx, %edx
xorl %esi, %esi
callq 0x20e0
movq 0x20(%rsp), %r8
movq 0x10(%r8), %rdi
movq (%r8), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1e3b6a
movq 0x20(%rsp), %r9
cmpq $0x0, (%r9)
je 0x1ea5d5
movb %bl, 0xf(%rsp)
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl $0x0, 0x50(%rsp)
movq 0x18(%rsp), %r8
movq 0x8(%r8), %r12
movq 0x10(%r9), %rax
movl (%rax,%r14,8), %eax
leaq (%rax,%rax,2), %rcx
cmpl $0x0, 0xc(%r12,%rcx,8)
js 0x1ea5bf
movq (%r12,%rcx,8), %r13
movq 0x20(%r8), %rax
movq %r13, %rdx
shrq $0x21, %rdx
cmpl $0x0, (%rax,%rdx,8)
js 0x1ea5bf
movl 0x8(%r12,%rcx,8), %edi
movl %edi, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1ea5bf
shrq $0x20, %r13
movq %rdi, %rcx
xorq $0x1, %rcx
movq 0x28(%r8), %rax
movq (%rax,%r13,8), %r15
movq (%rax,%rcx,8), %rbp
cmpl $0x1, %r15d
ja 0x1ea093
cmpl $0x2, %ebp
jb 0x1ea5bf
movq %rbp, %rbx
shrq $0x20, %rbx
cmpl $0x0, 0x34(%rsp)
je 0x1ea14d
movq (%rax,%r13,8), %rax
movq %rax, %rcx
andq %r11, %rcx
je 0x1ea0d6
shrq $0x20, %rax
xorl %edx, %edx
movl %eax, %esi
leaq (%rsi,%rsi,2), %rsi
movl 0xc(%r12,%rsi,8), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %edx
incq %rax
decq %rcx
jne 0x1ea0b7
cmpl $0x1, %edx
ja 0x1ea10a
movq %rbp, %rax
andq %r11, %rax
je 0x1ea5bf
xorl %ecx, %ecx
movq %rbx, %rdx
movl %edx, %esi
leaq (%rsi,%rsi,2), %rsi
movl 0xc(%r12,%rsi,8), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ecx
incq %rdx
decq %rax
jne 0x1ea0e7
cmpl $0x2, %ecx
jb 0x1ea5bf
movq %r15, 0x10(%rsp)
movq %rdi, 0x70(%rsp)
movl %r13d, %esi
xorl $0x1, %esi
movq %r8, %rdi
callq 0xab815
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
xorl %ecx, %ecx
cmpb $0x2, %al
sete %cl
cmpb $0x1, %al
leal -0x1(%rcx,%rcx), %ecx
movl $0x2, %eax
cmovel %eax, %ecx
movl %ecx, 0x40(%rsp)
jmp 0x1ea157
movq %r15, 0x10(%rsp)
movq %rdi, 0x70(%rsp)
leaq (%rbx,%rbx,2), %rax
movq 0x10(%r9), %rcx
movq %r14, 0x28(%rsp)
movl (%rcx,%r14,8), %ecx
leaq (%rcx,%rcx,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r8), %rsi
leaq (%r12,%rax,8), %r15
movq %r15, %rax
movl %ebp, %ecx
movq %rbp, 0x98(%rsp)
testl %ebp, %ebp
movq 0x10(%rsp), %r10
je 0x1ea1a8
movl 0x8(%rax), %edx
xorl %r13d, %edx
cmpl $0x1, %edx
je 0x1ea1a3
addq $0x18, %rax
decl %ecx
jne 0x1ea18e
jmp 0x1ea1a8
movq %rax, 0x60(%rsp)
movq %r13, 0x88(%rsp)
movl 0xc(%rsi), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movq 0x60(%rsp), %rdx
movl 0xc(%rdx), %edi
andl %ecx, %edi
cmpl %edi, %eax
cmovbl %eax, %edi
movq %rdi, 0x38(%rsp)
movq %rsi, 0x78(%rsp)
movzwl 0x10(%rsi), %eax
movl $0x3fff, %ecx           # imm = 0x3FFF
andl %ecx, %eax
movzwl 0x10(%rdx), %edx
andl %ecx, %edx
cmpw %dx, %ax
cmovbl %eax, %edx
movl %edx, 0x5c(%rsp)
testl %r10d, %r10d
je 0x1ea28a
movq %r10, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%r12,%rax,8), %rbx
movl %r10d, %r12d
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpl $0x0, 0xc(%rbx)
js 0x1ea275
incl %r14d
cmpl $0x0, 0x34(%rsp)
je 0x1ea248
movl 0x8(%rbx), %esi
movq %r8, %rdi
callq 0xab815
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
movzbl %al, %eax
cmpl %eax, 0x40(%rsp)
je 0x1ea275
movl 0xc(%rbx), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %eax, %r13d
cmovbel %eax, %r13d
movq 0x10(%rsp), %rax
cmovbq %rbx, %rax
movq %rax, 0x10(%rsp)
movzwl 0x10(%rbx), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpl %eax, %ebp
cmovbel %eax, %ebp
addq $0x18, %rbx
decq %r12
jne 0x1ea21a
cvtsi2ss %ebp, %xmm0
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
jmp 0x1ea29c
xorps %xmm0, %xmm0
xorl %r14d, %r14d
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
testl %r14d, %r14d
je 0x1ea5ba
movq %r14, 0x68(%rsp)
cmpl $0x1, %r14d
jne 0x1ea33f
movq 0x98(%rsp), %rax
testl %eax, %eax
je 0x1ea397
movl %eax, %r12d
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpl $0x0, 0xc(%r15)
js 0x1ea324
incl %r13d
cmpl $0x0, 0x34(%rsp)
je 0x1ea301
movl 0x8(%r15), %esi
movq %r8, %rdi
callq 0xab815
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
movzbl %al, %eax
cmpl %eax, 0x40(%rsp)
je 0x1ea324
movl 0xc(%r15), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %eax, %ebx
cmovbel %eax, %ebx
cmovbq %r15, %r14
movzwl 0x10(%r15), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpl %eax, %ebp
cmovbel %eax, %ebp
addq $0x18, %r15
decq %r12
jne 0x1ea2d1
movq %r14, %rsi
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
jmp 0x1ea3a1
cvtsi2ssl 0x38(%rsp), %xmm1
cvtsi2ss %r13d, %xmm2
mulss 0x58(%rsp), %xmm2
ucomiss %xmm2, %xmm1
ja 0x1ea5ba
cmpl $0x0, 0x54(%rsp)
je 0x1ea37b
movzwl 0x5c(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0x4c(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x1ea5ba
movl 0xf0(%rsp), %eax
movq 0x38(%rsp), %rcx
addl %ecx, %eax
cmpl %r13d, %eax
jbe 0x1ea2b4
jmp 0x1ea5ba
xorps %xmm0, %xmm0
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %esi, %esi
testl %r13d, %r13d
movq 0x28(%rsp), %r14
je 0x1ea5bf
cmpl $0x1, %r13d
jne 0x1ea40b
movq 0x68(%rsp), %rax
xorl $0x1, %eax
movl %r13d, %ecx
xorl $0x1, %ecx
orl %eax, %ecx
je 0x1ea5bf
movb $0x1, %al
cmpl $0x0, 0x84(%rsp)
je 0x1ea467
cmpl $0x1, 0x68(%rsp)
setne %cl
cmpl $0x1, %r13d
setne %dl
testb %dl, %cl
movq %rsi, %r14
je 0x1ea478
movl $0x1, %ecx
xorl %eax, %eax
movq 0x78(%rsp), %r15
movq 0x10(%rsp), %r12
jmp 0x1ea4d0
xorps %xmm1, %xmm1
cvtsi2ssl 0x38(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtsi2ss %ebx, %xmm2
mulss 0x58(%rsp), %xmm2
ucomiss %xmm2, %xmm1
ja 0x1ea5bf
cmpl $0x0, 0x54(%rsp)
je 0x1ea44c
movzwl 0x5c(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0x4c(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x1ea5bf
movl 0xf0(%rsp), %eax
movq 0x38(%rsp), %rcx
addl %eax, %ecx
cmpl %ebx, %ecx
jbe 0x1ea3b5
jmp 0x1ea5bf
xorl %ecx, %ecx
movq 0x78(%rsp), %r15
movq 0x10(%rsp), %r12
movq %rsi, %r14
jmp 0x1ea4d0
cmpl $0x1, %r13d
movq 0x78(%rsp), %r15
movq 0x10(%rsp), %r12
je 0x1ea49f
cmpl $0x1, 0x68(%rsp)
jne 0x1ea4ce
movq 0x88(%rsp), %rax
xorl $0x1, %eax
movq %rax, 0x70(%rsp)
movq %r8, %rdi
movq 0x70(%rsp), %rsi
movl 0x30(%rsp), %ebx
movl %ebx, %edx
callq 0xaa77e
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
xorl %ecx, %ecx
cmpl %ebx, %eax
setge %al
setl %cl
jmp 0x1ea4d0
xorl %ecx, %ecx
cmpb $0x0, 0xf(%rsp)
je 0x1ea5a4
testq %r12, %r12
setne %dl
andb %dl, %al
cmpb $0x1, %al
jne 0x1ea52e
movl 0x8(%r15), %edi
movl 0x8(%r12), %esi
xorl %ecx, %ecx
cmpl %esi, %edi
je 0x1ea52e
movq %r9, (%rsp)
movq %r8, %rdx
movq 0xf8(%rsp), %rcx
movq 0x100(%rsp), %r8
movl 0x30(%rsp), %r9d
callq 0x1e7fa4
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
testl %ecx, %ecx
jne 0x1ea581
testq %r14, %r14
je 0x1ea581
movq 0x60(%rsp), %rax
movl 0x8(%rax), %edi
movl 0x8(%r14), %esi
xorl %ecx, %ecx
cmpl %esi, %edi
je 0x1ea581
movq %r9, (%rsp)
movq %r8, %rdx
movq 0xf8(%rsp), %rcx
movq 0x100(%rsp), %r8
movl 0x30(%rsp), %r9d
callq 0x1e7fa4
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
testq %r12, %r12
je 0x1ea5a4
testq %r14, %r14
je 0x1ea5a4
movl 0x8(%r15), %eax
cmpl 0x8(%r12), %eax
jne 0x1ea5a4
movq 0x60(%rsp), %rax
movl 0x8(%rax), %eax
cmpl 0x8(%r14), %eax
je 0x1ea617
testl %ecx, %ecx
je 0x1ea5ba
movq 0x60(%rsp), %rax
orb $-0x80, 0xf(%rax)
orb $-0x80, 0xf(%r15)
incl 0x50(%rsp)
movq 0x28(%rsp), %r14
incl %r14d
cmpq %r14, (%r9)
ja 0x1ea025
cmpl $0x0, 0x50(%rsp)
sete %bl
jmp 0x1ea5dc
movb $0x1, %bl
movq 0x18(%rsp), %r8
cmpq $0x0, 0x90(%rsp)
jne 0x1ea5f9
movq 0xb0(%rsp), %rdi
callq 0x2220
movq 0x18(%rsp), %r8
testb %bl, %bl
jne 0x1ea605
movq %r8, %rdi
callq 0xa02fa
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4f00a(%rip), %rdi     # 0x239628
leaq 0x4ed00(%rip), %rsi     # 0x239325
leaq 0x4f161(%rip), %rcx     # 0x23978d
movl $0x6fa, %edx            # imm = 0x6FA
callq 0x2110