// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
callq 0x2510
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0xdb0d2
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xdaf7d
jmp 0xdb0c4
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
cmpl $0x2, -0x4c(%rbp)
jae 0xdafc0
jmp 0xdb0c4
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2ss %eax, %xmm0
movss -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2a405b(%rip), %xmm1   # 0x37f040
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x44(%rbp)
movb %al, -0x4d(%rbp)
jb 0xdb024
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x48(%rbp), %eax
setb %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
testb $0x1, %al
jne 0xdb02d
jmp 0xdb03a
jmp 0xdb02f
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xdaffa
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0xdb088
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xdb04c
cmpl $0x2, -0x4c(%rbp)
jb 0xdb0c2
movq -0x40(%rbp), %rax
movl 0x24(%rax), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xdb0c2
movq -0x40(%rbp), %rax
movl 0x24(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x24(%rax)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xdb0c4
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xdaf52
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x8(%rbp), %rdi
callq 0xce020
movq 0x2e8ef5(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x34(%rbp), %ecx
leaq 0x2abace(%rip), %rsi    # 0x386bc6
leaq 0x2abafc(%rip), %rdx    # 0x386bfb
movb $0x0, %al
callq 0x22a0
movq 0x2e8ed3(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x2510
movq -0x58(%rbp), %rdi
subsd -0x28(%rbp), %xmm0
leaq 0x2abaf4(%rip), %rsi    # 0x386c1d
leaq 0x2abacb(%rip), %rdx    # 0x386bfb
movb $0x1, %al
callq 0x22a0
movl -0x34(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq