// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movss %xmm0, 0xc(%rsp)
movq %rdi, %r14
callq 0x300fc
movss 0xc(%rsp), %xmm2
movsd %xmm0, 0x10(%rsp)
movl 0x14(%r14), %eax
xorl %ebx, %ebx
addl %eax, %eax
je 0x692f
movl %eax, %eax
xorl %ecx, %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movsd 0x21b7bc(%rip), %xmm0   # 0x222010
xorl %ebx, %ebx
movq 0x20(%r14), %rdi
movl %ecx, %r8d
shrl %r8d
cmpl $0x0, (%rdi,%r8,8)
js 0x6923
movq 0x28(%r14), %rdi
movq (%rdi,%rcx,8), %r8
cmpl $0x2, %r8d
jb 0x6923
movq 0x8(%r14), %r9
movq %r8, %rdi
shrq $0x20, %rdi
imulq $0x18, %rdi, %r15
leaq (%r9,%r15), %rdi
movl 0xc(%rdi), %r10d
andl %edx, %r10d
cvtsi2ss %r10d, %xmm1
mulss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r12
movl %r8d, %r10d
leal 0x1(%r8), %r11d
imulq $0x18, %r10, %r13
leaq (%r9,%r15), %rbp
addq $-0xc, %rbp
cmpq $0x18, %r13
je 0x68db
movl (%rbp,%r13), %esi
andl %edx, %esi
decl %r11d
addq $-0x18, %r13
cmpl %r12d, %esi
jb 0x68c0
jmp 0x68df
pushq $0x1
popq %r11
cmpl %r8d, %r11d
jae 0x690d
movl %r11d, %esi
addl %r8d, %ebx
imulq $0x18, %rsi, %r8
addq %r8, %r15
leaq (%r9,%r15), %r8
addq $0xc, %r8
subq %rsi, %r10
orb $-0x80, 0x3(%r8)
addq $0x18, %r8
decq %r10
jne 0x68fc
subl %r11d, %ebx
movl 0x24(%rdi), %r8d
testl %r8d, %r8d
jns 0x6923
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl %r8d, 0x24(%rdi)
decl %ebx
incq %rcx
cmpq %rax, %rcx
jne 0x6856
movq %r14, %rdi
callq 0xa02fa
movq %r14, %rdi
callq 0xa0333
movq %r14, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%r14)
movq 0x28368d(%rip), %r15    # 0x289fe0
movq (%r15), %rdi
leaq 0x22364d(%rip), %rsi    # 0x229faa
leaq 0x22367b(%rip), %r14    # 0x229fdf
movq %r14, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x22b0
movq (%r15), %r15
callq 0x300fc
subsd 0x10(%rsp), %xmm0
leaq 0x22367c(%rip), %rsi    # 0x22a001
movq %r15, %rdi
movq %r14, %rdx
movb $0x1, %al
callq 0x22b0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq