// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x300fc
movl 0x14(%rbx), %eax
leal (%rax,%rax), %ebp
testl %eax, %eax
js 0xa61f4
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
xorl %r14d, %r14d
movq %r14, 0x80(%rsp)
movl %ebp, %r12d
movl $0x1c, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x20(%rsp)
movq %r14, 0xf0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movl $0x1c, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x90(%rsp)
testl %ebp, %ebp
je 0xa6368
xorl %r13d, %r13d
leaq 0x20(%rsp), %rbp
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movq %r12, 0x10(%rsp)
movq 0x20(%rbx), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xa6357
movq 0x28(%rbx), %rax
testl $0xfffffffe, (%rax,%r13,8) # imm = 0xFFFFFFFE
je 0xa6357
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
movq %rbp, %rcx
callq 0xa6414
cmpq $0x1, %rax
jne 0xa6357
movq 0x68(%rsp), %rbp
movq %r14, 0x18(%rsp)
movl 0x58(%rsp), %r14d
movq %r15, %r12
movq 0x38(%rsp), %r15
movl (%r15), %r8d
leaq 0x90(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movl %r14d, %edx
movl %r13d, %ecx
movl %r12d, %r9d
callq 0xa429f
addl %eax, 0xc(%rsp)
movl (%r15), %r8d
movq %r12, %r15
movq 0x10(%rsp), %r12
leaq 0x90(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x20(%rsp), %rbp
movl %r14d, %edx
movq 0x18(%rsp), %r14
movl %r13d, %ecx
movl %r15d, %r9d
callq 0xa59e2
addl %eax, %r14d
incq %r13
cmpq %r13, %r12
jne 0xa62a5
addl 0xc(%rsp), %r14d
movq 0x20(%rsp), %rdi
callq 0x2220
movq 0x38(%rsp), %rdi
callq 0x2220
movq 0x50(%rsp), %rdi
callq 0x2220
movq 0x68(%rsp), %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq 0x90(%rsp), %rdi
callq 0x2220
movq 0xa8(%rsp), %rdi
callq 0x2220
movq 0xc0(%rsp), %rdi
callq 0x2220
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0xf0(%rsp), %rdi
callq 0x2220
testl %r14d, %r14d
je 0xa63ff
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
movl %r14d, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq