// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_triangular_advance(asg_t*, long long)
int asg_arc_del_triangular_advance(asg_t *g, long long max_dist)
{
    double startTime = Get_T();
    ///the reason is that each read has two direction (query->target, target->query)
	uint32_t v, n_vtx = g->n_seq * 2, n_reduced = 0, n_reduced_a = 0;


    if (!g->is_symm) asg_symm(g);


    buf_t b;
	memset(&b, 0, sizeof(buf_t));
	b.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));


    buf_t bub;
    memset(&bub, 0, sizeof(buf_t));
    bub.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));

    for (v = 0; v < n_vtx; ++v) 
    {
        uint32_t nv = asg_arc_n(g, v);
        if (g->seq[v>>1].del)
        {
            continue;
        } 

        if(nv < 2)
        {
            continue;
        }


        ///if this is a bubble
        if(asg_bub_finder_with_del_advance(g, v, max_dist, &b) == 1)
        {
            n_reduced += test_triangular_exact(g, b.b.a, b.b.n, v, b.S.a[0], max_dist, &bub);
            n_reduced_a += test_triangular_addition_exact(g, b.b.a, b.b.n, v, b.S.a[0],max_dist, &bub);
        }

    }

    free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
    free(bub.a); free(bub.S.a); free(bub.T.a); free(bub.b.a); free(bub.e.a);

    if (n_reduced + n_reduced_a) {
		asg_cleanup(g);
		asg_symm(g);
	}

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %d/%d triangular/triangular_a overlaps\n", 
        __func__, n_reduced, n_reduced_a);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }

    return n_reduced + n_reduced_a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x2510
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xd7404
movq -0x8(%rbp), %rdi
callq 0xce020
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl -0x20(%rbp), %eax
movl %eax, %edi
movl $0x1c, %esi
callq 0x2140
movq %rax, -0x90(%rbp)
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl -0x20(%rbp), %eax
movl %eax, %edi
movl $0x1c, %esi
callq 0x2140
movq %rax, -0xf8(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0xd7544
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xfc(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd749d
jmp 0xd7536
cmpl $0x2, -0xfc(%rbp)
jae 0xd74ab
jmp 0xd7536
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x10(%rbp), %rax
movl %eax, %edx
leaq -0x90(%rbp), %rcx
callq 0xd75e0
cmpq $0x1, %rax
jne 0xd7534
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rax
movl %eax, %edx
movl -0x1c(%rbp), %ecx
movq -0x78(%rbp), %rax
movl (%rax), %r8d
movq -0x10(%rbp), %rax
movl %eax, %r9d
leaq -0xf8(%rbp), %rax
movq %rax, (%rsp)
callq 0xd5670
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rax
movl %eax, %edx
movl -0x1c(%rbp), %ecx
movq -0x78(%rbp), %rax
movl (%rax), %r8d
movq -0x10(%rbp), %rax
movl %eax, %r9d
leaq -0xf8(%rbp), %rax
movq %rax, (%rsp)
callq 0xd6be0
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0xd7536
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd745d
movq -0x90(%rbp), %rdi
callq 0x2210
movq -0x78(%rbp), %rdi
callq 0x2210
movq -0x60(%rbp), %rdi
callq 0x2210
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0x30(%rbp), %rdi
callq 0x2210
movq -0xf8(%rbp), %rdi
callq 0x2210
movq -0xe0(%rbp), %rdi
callq 0x2210
movq -0xc8(%rbp), %rdi
callq 0x2210
movq -0xb0(%rbp), %rdi
callq 0x2210
movq -0x98(%rbp), %rdi
callq 0x2210
movl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
cmpl $0x0, %eax
je 0xd75cd
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x8(%rbp), %rdi
callq 0xce020
movl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)