// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_short_diploid_unclean(asg_t*, float, ma_hit_t_alloc*, ma_hit_t_alloc*)
int asg_arc_del_short_diploid_unclean(asg_t *g, float drop_ratio, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources)
{
    double startTime = Get_T();

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

		asg_arc_t *av = asg_arc_a(g, v);
		uint32_t i, thres, nv = asg_arc_n(g, v);
		///if there is just one overlap, do nothing
		if (nv < 2) continue;
		//av[0] has the most overlap length
		///remove short overlaps
		thres = (uint32_t)(av[0].ol * drop_ratio + .499);
		///av has been sorted by overlap length
		for (i = nv - 1; i >= 1 && av[i].ol < thres; --i) {}
        last_e = i + 1;

		for (i = i + 1; i < nv; ++i)
			av[i].del = 1, ++n_short;
        
        
        if(nv >= 2 && av[1].del == 1)
        {
            ///second longest
            av[1].del = 0;
            --n_short;
            last_e++;
        }
        
	}
	///if (n_short) 
    {
		asg_cleanup(g);
		asg_symm(g);
	}
	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 %r12
pushq %rbx
subq $0x10, %rsp
movss %xmm0, 0x4(%rsp)
movq %rdi, %r14
callq 0x251c
movss 0x4(%rsp), %xmm2
movsd %xmm0, 0x8(%rsp)
movl 0x14(%r14), %eax
addl %eax, %eax
xorl %ecx, %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movsd 0x16f8d6(%rip), %xmm0   # 0x1e0010
xorl %ebx, %ebx
cmpq %rax, %rcx
je 0x7080f
movq 0x20(%r14), %rsi
movl %ecx, %edi
shrl %edi
cmpl $0x0, (%rsi,%rdi,8)
js 0x70807
movq 0x28(%r14), %rsi
movq (%rsi,%rcx,8), %r8
testl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
je 0x70807
movq 0x8(%r14), %r10
movq %r8, %rsi
shrq $0x20, %rsi
imulq $0x18, %rsi, %r11
leaq (%r10,%r11), %rsi
movl 0xc(%rsi), %edi
andl %edx, %edi
cvtsi2ss %edi, %xmm1
mulss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r9
movl %r8d, %edi
imulq $0x18, %rdi, %r15
addq %r11, %r15
addq %r15, %r10
addq $-0xc, %r10
movq %rdi, %r12
movq %r12, %r11
movl %r8d, %r15d
cmpq $0x1, %r12
je 0x707cf
movl (%r10), %ebp
andl %edx, %ebp
addq $-0x18, %r10
leaq -0x1(%r11), %r12
leal -0x1(%r15), %r8d
cmpl %r9d, %ebp
jb 0x707ad
movl %r11d, %r8d
movl %r15d, %r9d
imulq $0x18, %r9, %r9
addq %rsi, %r9
addq $0xc, %r9
cmpq %rdi, %r8
jae 0x707f5
orb $-0x80, 0x3(%r9)
incl %ebx
incq %r8
addq $0x18, %r9
jmp 0x707e0
movl 0x24(%rsi), %edi
testl %edi, %edi
jns 0x70807
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edi, 0x24(%rsi)
decl %ebx
incq %rcx
jmp 0x7073c
movq %r14, %rdi
callq 0x694eb
movq %r14, %rdi
callq 0x69638
movq 0x1e27ba(%rip), %r15    # 0x252fe0
movq (%r15), %rdi
leaq 0x17786a(%rip), %rsi    # 0x1e809a
leaq 0x177898(%rip), %r14    # 0x1e80cf
movq %r14, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x22b0
movq (%r15), %r15
callq 0x251c
subsd 0x8(%rsp), %xmm0
leaq 0x177899(%rip), %rsi    # 0x1e80f1
movq %r15, %rdi
movq %r14, %rdx
movb $0x1, %al
callq 0x22b0
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq