// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_too_short_overlaps(asg_t*, long long, float, ma_hit_t_alloc*, long long, R_to_U*)
int asg_arc_del_too_short_overlaps(asg_t *g, long long dropLen, float drop_ratio, 
ma_hit_t_alloc* reverse_sources, long long min_edge_length, R_to_U* ruIndex)
{
    double startTime = Get_T();

	uint32_t v, v_max, v_maxLen, n_vtx = g->n_seq * 2, n_short = 0;
    long long drop_ratio_Len = 0;
    
    for (v = 0; v < n_vtx; ++v) 
    {
        if (g->seq[v>>1].del) continue;
        if (g->seq_vis[v] != 0) continue;

        uint32_t i, n_arc = 0, nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        ///some node could be deleted
        if (nv < 2 || g->seq[v>>1].del) continue;



        n_arc = get_real_length(g, v, NULL);
        if (n_arc < 2) continue;
        v_max = (uint32_t)-1;

        for (i = 0, n_arc = 0; i < nv; i++)
        {
            if (!av[i].del)
            {
                if(v_max == (uint32_t)-1)
                {
                    v_max = av[i].v;
                    v_maxLen = av[i].ol;
                    if(v_maxLen < dropLen) break;
                    drop_ratio_Len = v_maxLen * drop_ratio;
                    if(dropLen < drop_ratio_Len)
                    {
                        drop_ratio_Len = dropLen;
                    }
                }
                else if(av[i].ol < drop_ratio_Len && 
                check_if_diploid(v_max, av[i].v, g, reverse_sources, min_edge_length, ruIndex) != 1)
                {
                    // av[i].ol = 1;///should be a bug
                    av[i].del = 1;
                    asg_arc_del(g, av[i].v^1, av[i].ul>>32^1, 1);
                    ++n_short;
                }
            }
        }
    }


    asg_cleanup(g);
    asg_symm(g);
	
    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %d short overlaps\n", __func__, n_short);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }

	return n_short;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movss %xmm0, 0x24(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
callq 0x251c
movq %r14, %rdx
movl 0x14(%rbx), %r12d
addl %r12d, %r12d
xorl %r14d, %r14d
movl $0x0, 0x14(%rsp)
xorl %esi, %esi
movq %rdx, 0x18(%rsp)
movq %r12, 0x28(%rsp)
cmpq %r12, %r14
je 0x7191d
movq 0x20(%rbx), %rax
movl %r14d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x7180c
movq 0x30(%rbx), %rax
cmpb $0x0, (%rax,%r14)
je 0x71811
incq %r14
jmp 0x717e9
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %r15
testl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
je 0x7180c
movq %rsi, 0x8(%rsp)
movq 0x8(%rbx), %r13
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jae 0x71844
movq 0x8(%rsp), %rsi
jmp 0x7180c
movq %r15, %rax
shrq $0x20, %rax
movl %r15d, %ecx
imulq $0x18, %rcx, %r12
imulq $0x18, %rax, %rax
addq %rax, %r13
addq $0xc, %r13
xorl %ebp, %ebp
pushq $-0x1
popq %r15
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rsi
cmpq %rbp, %r12
je 0x71913
movslq (%r13,%rbp), %rax
testq %rax, %rax
js 0x7190a
cmpl $-0x1, %r15d
je 0x718ea
cmpq %rax, %rsi
jle 0x7190a
movq %rsi, 0x8(%rsp)
movl -0x4(%r13,%rbp), %esi
movl %r15d, %edi
movq %rbx, %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x40(%rsp), %r9
callq 0x70fd8
cmpq $0x1, %rax
je 0x718de
orb $-0x80, 0x3(%r13,%rbp)
movl -0x8(%r13,%rbp), %edx
movl -0x4(%r13,%rbp), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %rbx, %rdi
pushq $0x1
popq %rcx
callq 0x6db50
incl 0x14(%rsp)
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rsi
jmp 0x7190a
cmpq %rdx, %rax
jl 0x71913
cvtsi2ss %eax, %xmm0
mulss 0x24(%rsp), %xmm0
cvttss2si %xmm0, %rsi
movl -0x4(%r13,%rbp), %r15d
cmpq %rdx, %rsi
cmovgeq %rdx, %rsi
addq $0x18, %rbp
jmp 0x7186d
movq 0x28(%rsp), %r12
jmp 0x7180c
movq %rbx, %rdi
callq 0x694eb
movq %rbx, %rdi
callq 0x69638
movl 0x14(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq