// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_cut_large_indel(asg_t*, asg64_v*, int, float, unsigned int, unsigned int)
uint32_t asg_cut_large_indel(asg_t *g, asg64_v *in, int32_t max_ext, float ou_rat, uint32_t is_ou, uint32_t min_diff)
{
    asg64_v tx = {0,0,0}, *b = NULL;
    uint32_t v, w, n_vtx = g->n_seq<<1, i, k, kv, kw, nv, nw, ou_max, ol_max, to_del, cnt = 0;
    asg_arc_t *av, *aw, *ve, *we;
    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 || av[i].no_l_indel) continue;
                ///means there is a large indel at this edge
                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;

        for (i = kv = ou_max = ol_max = 0, ve = NULL; i < nv; ++i) {
            if(av[i].del) continue;
            if(av[i].v == (w^1)) ve = &(av[i]);
            kv++;
            if(ou_max < av[i].ou) ou_max = av[i].ou;
            if(ol_max < av[i].ol) ol_max = av[i].ol;
        }
        if (kv < 1) continue;
        if (kv >= 2) {
            if (is_ou && ve->ou > ou_max*ou_rat) continue;
            if ((ve->ol + min_diff) > ol_max) continue;
        }
        

        for (i = kw = ou_max = ol_max = 0, we = NULL; i < nw; ++i) {
            if(aw[i].del) continue;
            if(aw[i].v == (v^1)) we = &(aw[i]);
            kw++;
            if(ou_max < aw[i].ou) ou_max = aw[i].ou;
            if(ol_max < aw[i].ol) ol_max = aw[i].ol;
        }
        if (kw < 1) continue;
        if (kw >= 2) {
            if (is_ou && we->ou > ou_max*ou_rat) continue;
            if ((we->ol + min_diff) > ol_max) continue;
        }

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movss %xmm0, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movq %rsi, %r12
movl 0x14(%rdi), %eax
addl %eax, %eax
testq %rsi, %rsi
je 0x1f8974
movq $0x0, (%r12)
testl %eax, %eax
movq %rdi, 0x8(%rsp)
je 0x1f8b57
movl %eax, %r10d
xorl %r15d, %r15d
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
movq $0x0, (%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
movq %r10, 0x30(%rsp)
movq 0x20(%rdi), %rax
movl %r15d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1f89c4
movq 0x30(%rdi), %rax
cmpb $0x0, (%rax,%r15)
je 0x1f89d1
incq %r15
cmpq %r10, %r15
jne 0x1f89aa
jmp 0x1f8b62
movq 0x28(%rdi), %rax
movq (%rax,%r15,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1f89c4
movq 0x8(%rdi), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rsi
movq %rsi, 0x10(%rsp)
movl %eax, %r13d
leaq (%rcx,%rdx,8), %r14
addq $0xc, %r14
xorl %eax, %eax
movq %r13, %rcx
movq %r14, %rdx
movl (%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %eax
addq $0x18, %rdx
decq %rcx
jne 0x1f8a0b
cmpl $0x2, %eax
jb 0x1f89c4
xorl %ebp, %ebp
movq %r13, 0x28(%rsp)
cmpl $0x0, (%r14)
js 0x1f8b42
cmpw $0x0, 0x4(%r14)
js 0x1f8b42
testq %r12, %r12
je 0x1f8aa3
movq (%r12), %rax
cmpq 0x8(%r12), %rax
jne 0x1f8af0
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
movq %r9, %rbx
movq %r8, %r13
callq 0x2370
movq %r13, %r8
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq 0x30(%rsp), %r10
movq %rbx, %r9
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%r12)
jmp 0x1f8af0
cmpq %r8, %r9
jne 0x1f8af0
leaq (%r8,%r8), %rbx
testq %r8, %r8
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq (%rsp), %rdi
movq %r9, %r13
callq 0x2370
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq 0x30(%rsp), %r10
movq %r13, %r9
movq 0x8(%rsp), %rdi
movq %rax, (%rsp)
movq %rbx, %r8
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
movq %r8, %r13
movl (%r14), %eax
andl %r11d, %eax
movq 0x10(%rsp), %rcx
subq 0x8(%rdi), %rcx
testq %r12, %r12
je 0x1f8b1a
movq (%r12), %rdx
movq 0x10(%r12), %rsi
leaq 0x1(%rdx), %r8
movq %r8, (%r12)
jmp 0x1f8b24
movq %r9, %rdx
incq %r9
movq (%rsp), %rsi
shlq $0x20, %rax
sarq $0x3, %rcx
imulq %rbx, %rcx
addq %rbp, %rcx
orq %rax, %rcx
movq %rcx, (%rsi,%rdx,8)
movq %r13, %r8
movq 0x28(%rsp), %r13
incq %rbp
addq $0x18, %r14
cmpq %rbp, %r13
jne 0x1f8a29
jmp 0x1f89c4
xorl %r9d, %r9d
movq $0x0, (%rsp)
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r9, 0x10(%rsp)
movq %r9, %rax
testq %r12, %r12
je 0x1f8b7f
movq (%r12), %rax
movq 0x10(%r12), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1ee586
xorl %r14d, %r14d
movl $0x0, 0x28(%rsp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %r10
movq %rbx, (%rsp)
movl %r14d, %r14d
testq %r12, %r12
je 0x1f8bc2
cmpq %r14, (%r12)
jbe 0x1f8e1a
movq 0x8(%rdi), %rcx
movq 0x10(%r12), %rax
movl (%rax,%r14,8), %eax
jmp 0x1f8bd3
cmpq %r14, %r10
jbe 0x1f8e0d
movq 0x8(%rdi), %rcx
movl (%rbx,%r14,8), %eax
leaq (%rax,%rax,2), %rdx
cmpl $0x0, 0xc(%rcx,%rdx,8)
js 0x1f8d8b
leaq (%rcx,%rdx,8), %rdx
movq (%rdx), %rsi
movq 0x20(%rdi), %rdx
movq %rsi, %r8
shrq $0x21, %r8
cmpl $0x0, (%rdx,%r8,8)
js 0x1f8d8b
leaq (%rax,%rax,2), %rax
movl 0x8(%rcx,%rax,8), %eax
movl %eax, %r8d
shrl %r8d
cmpl $0x0, (%rdx,%r8,8)
js 0x1f8d8b
shrq $0x20, %rsi
movq %rax, %rdx
xorq $0x1, %rdx
movq 0x28(%rdi), %r9
movq (%r9,%rsi,8), %r8
movq (%r9,%rdx,8), %r15
cmpl $0x2, %r8d
setb %dl
cmpl $0x2, %r15d
setb %r9b
andb %dl, %r9b
testl %r8d, %r8d
sete %dl
orb %r9b, %dl
jne 0x1f8d8b
movq %r8, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r9
movq %r15, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
movl %r8d, %r11d
xorl %r13d, %r13d
xorl %r8d, %r8d
xorl %r10d, %r10d
xorl %ecx, %ecx
movl 0xc(%r9), %ebp
testl %ebp, %ebp
js 0x1f8ca7
cmpl %eax, 0x8(%r9)
cmoveq %r9, %r13
incl %ecx
movzwl 0x10(%r9), %ebx
andl $0x3fff, %ebx           # imm = 0x3FFF
cmpl %ebx, %r10d
cmovbel %ebx, %r10d
cmpl %ebp, %r8d
cmovbel %ebp, %r8d
addq $0x18, %r9
decq %r11
jne 0x1f8c7c
testl %ecx, %ecx
je 0x1f8d7d
cmpl $0x1, %ecx
je 0x1f8cff
cmpl $0x0, 0x24(%rsp)
je 0x1f8ce9
cvtsi2ss %r10d, %xmm0
movzwl 0x10(%r13), %r9d
andl $0x3fff, %r9d           # imm = 0x3FFF
cvtsi2ss %r9d, %xmm1
mulss 0x1c(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x1f8d7d
movl 0xc(%r13), %r9d
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %r9d
addl 0x20(%rsp), %r9d
cmpl %r8d, %r9d
ja 0x1f8d7d
testl %r15d, %r15d
je 0x1f8d7d
movl %r15d, %r9d
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r8d, %r8d
xorl %r10d, %r10d
movl 0xc(%rdx), %r11d
testl %r11d, %r11d
js 0x1f8d42
movl 0x8(%rdx), %ebx
xorl %esi, %ebx
cmpl $0x1, %ebx
cmoveq %rdx, %rbp
incl %r10d
movzwl 0x10(%rdx), %ebx
andl $0x3fff, %ebx           # imm = 0x3FFF
cmpl %ebx, %r8d
cmovbel %ebx, %r8d
cmpl %r11d, %r15d
cmovbel %r11d, %r15d
addq $0x18, %rdx
decq %r9
jne 0x1f8d12
testl %r10d, %r10d
je 0x1f8d7d
cmpl $0x1, %r10d
jne 0x1f8d93
cmpl $0x1, %ecx
movq 0x8(%rsp), %rdi
je 0x1f8d82
movl %eax, %esi
movl 0x18(%rsp), %ebx
movl %ebx, %edx
callq 0xab75d
movq 0x8(%rsp), %rdi
cmpl %ebx, %eax
movq 0x10(%rsp), %r10
jge 0x1f8d87
jmp 0x1f8dfb
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %r10
movq (%rsp), %rbx
incl %r14d
jmp 0x1f8ba1
cmpl $0x0, 0x24(%rsp)
movq 0x8(%rsp), %rdi
je 0x1f8dc2
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
movzwl 0x10(%rbp), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0x1c(%rsp), %xmm0
ucomiss %xmm0, %xmm1
ja 0x1f8d82
movl 0xc(%rbp), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
addl 0x20(%rsp), %eax
cmpl %r15d, %eax
movq 0x10(%rsp), %r10
ja 0x1f8d87
cmpl $0x1, %ecx
jne 0x1f8dfb
xorl $0x1, %esi
movl 0x18(%rsp), %ebx
movl %ebx, %edx
callq 0xab75d
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %rdi
cmpl %ebx, %eax
jge 0x1f8d87
orb $-0x80, 0xf(%rbp)
orb $-0x80, 0xf(%r13)
incl 0x28(%rsp)
jmp 0x1f8d87
movq %rbx, %rdi
callq 0x2220
movq 0x8(%rsp), %rdi
movl 0x28(%rsp), %ebx
testl %ebx, %ebx
je 0x1f8e27
callq 0xa0a7d
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq