// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_short_diploi_by_suspect_edge(asg_t*, int)
int asg_arc_del_short_diploi_by_suspect_edge(asg_t *g, int max_ext)
{
    double startTime = Get_T();
    kvec_t(uint64_t) b;
    memset(&b, 0, sizeof(b));

	uint32_t v, n_vtx = g->n_seq * 2;
    long long n_cut = 0;
    
    for (v = 0; v < n_vtx; ++v) 
    {
        ///if(g->seq_vis[v] == 0)
        {
            asg_arc_t *av = asg_arc_a(g, v);
            uint32_t nv = asg_arc_n(g, v);
            if (nv < 2) continue;

            long long i;
            for (i = 0; i < nv; ++i)
            {
                ///means there is a large indel at this edge
                if(av[i].no_l_indel == 0)
                {
                    kv_push(uint64_t, b, (uint64_t)((uint64_t)av[i].ol << 32 | (av - g->arc + i)));   
                }
            }
        }
	}


    radix_sort_arch64(b.a, b.a + b.n);


    uint64_t k;
    for (k = 0; k < b.n; k++)
    {
        
        asg_arc_t *a = &g->arc[(uint32_t)b.a[k]];
		///v is self id, w is the id of another end
		uint32_t i, iv, iw, v = (a->ul)>>32, w = a->v^1, to_del = 0;
		uint32_t nv = asg_arc_n(g, v), nw = asg_arc_n(g, w), kv, kw;
		asg_arc_t *av, *aw;
		///nv must be >= 2
		if (nv == 1 && nw == 1) continue;
        av = asg_arc_a(g, v);
		aw = asg_arc_a(g, w);

        ///calculate the longest edge for v and w
		for (i = 0, kv = 0; i < nv; ++i) 
        {
			if (av[i].del) continue;
			++kv;
		}

		for (i = 0, kw = 0; i < nw; ++i) 
        {
			if (aw[i].del) continue;
			++kw;
		}

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

        ///to see which one is the current edge (from v and w)
		for (iv = 0; iv < nv; ++iv)
			if (av[iv].v == (w^1)) break;
		for (iw = 0; iw < nw; ++iw)
			if (aw[iw].v == (v^1)) break;

        ///if one edge has been deleted, it should be deleted in both direction
        if (av[iv].del && aw[iw].del) continue;

        
        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)
			av[iv].del = aw[iw].del = 1, ++n_cut;
    }
    
    free(b.a);
	if (n_cut) 
    {
		asg_cleanup(g);
		asg_symm(g);
	}
    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %lld suspect overlaps\n", __func__, n_cut);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }
	return n_cut;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
callq 0x2510
movsd %xmm0, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0xe4938
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
cmpl $0x2, -0x4c(%rbp)
jae 0xe482b
jmp 0xe492a
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jge 0xe4928
movq -0x48(%rbp), %rax
imulq $0x18, -0x58(%rbp), %rcx
addq %rcx, %rax
movw 0x10(%rax), %ax
shrw $0xf, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xe4915
jmp 0xe4865
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0xe48b4
cmpq $0x0, -0x28(%rbp)
je 0xe4886
movq -0x28(%rbp), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0xe4894
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0xe4894
movq -0xa8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
imulq $0x18, -0x58(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
shlq $0x20, %rax
movq %rax, -0xb0(%rbp)
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movq -0xb0(%rbp), %rdx
addq -0x58(%rbp), %rax
orq %rax, %rdx
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0xe4915
jmp 0xe4917
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xe4833
jmp 0xe492a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xe47dc
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0xc90e0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xe4c92
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x78(%rbp)
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x78(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x84(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x7c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x88(%rbp)
cmpl $0x1, -0x84(%rbp)
jne 0xe49ea
cmpl $0x1, -0x88(%rbp)
jne 0xe49ea
jmp 0xe4c81
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x78(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x7c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x84(%rbp), %eax
jae 0xe4a90
movq -0x98(%rbp), %rax
movl -0x6c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xe4a76
jmp 0xe4a85
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xe4a4d
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x90(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x88(%rbp), %eax
jae 0xe4ae4
movq -0xa0(%rbp), %rax
movl -0x6c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xe4aca
jmp 0xe4ad9
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xe4aa1
cmpl $0x1, -0x8c(%rbp)
jne 0xe4afb
cmpl $0x1, -0x90(%rbp)
jne 0xe4afb
jmp 0xe4c81
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x84(%rbp), %eax
jae 0xe4b3a
movq -0x98(%rbp), %rax
movl -0x70(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x7c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe4b2d
jmp 0xe4b3a
jmp 0xe4b2f
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xe4b02
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x88(%rbp), %eax
jae 0xe4b79
movq -0xa0(%rbp), %rax
movl -0x74(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x78(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe4b6c
jmp 0xe4b79
jmp 0xe4b6e
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xe4b41
movq -0x98(%rbp), %rax
movl -0x70(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xe4bb6
movq -0xa0(%rbp), %rax
movl -0x74(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xe4bb6
jmp 0xe4c81
cmpl $0x1, -0x8c(%rbp)
jbe 0xe4bd1
cmpl $0x1, -0x90(%rbp)
jbe 0xe4bd1
movl $0x1, -0x80(%rbp)
jmp 0xe4c27
cmpl $0x1, -0x90(%rbp)
jne 0xe4bfa
movq -0x8(%rbp), %rdi
movl -0x7c(%rbp), %esi
xorl $0x1, %esi
movl -0xc(%rbp), %edx
callq 0xdd220
cmpl -0xc(%rbp), %eax
jge 0xe4bf8
movl $0x1, -0x80(%rbp)
jmp 0xe4c25
cmpl $0x1, -0x8c(%rbp)
jne 0xe4c23
movq -0x8(%rbp), %rdi
movl -0x78(%rbp), %esi
xorl $0x1, %esi
movl -0xc(%rbp), %edx
callq 0xdd220
cmpl -0xc(%rbp), %eax
jge 0xe4c21
movl $0x1, -0x80(%rbp)
jmp 0xe4c23
jmp 0xe4c25
jmp 0xe4c27
cmpl $0x0, -0x80(%rbp)
je 0xe4c7f
movq -0xa0(%rbp), %rax
movl -0x74(%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)
movq -0x98(%rbp), %rax
movl -0x70(%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)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xe4c81
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xe4958
movq -0x20(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x40(%rbp)
je 0xe4cb4
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x8(%rbp), %rdi
callq 0xce020
movq -0x40(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)