// File: /workspace/github_cpp_makefile_star2_O2/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 $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x251c
movl 0x14(%rbx), %eax
leal (%rax,%rax), %ebp
testl %eax, %eax
js 0x6e5a8
movq %rbx, %rdi
callq 0x69638
xorps %xmm0, %xmm0
leaq 0x18(%rsp), %r15
movups %xmm0, 0x58(%r15)
movups %xmm0, 0x48(%r15)
movups %xmm0, 0x38(%r15)
movups %xmm0, 0x28(%r15)
movups %xmm0, 0x18(%r15)
movups %xmm0, 0x8(%r15)
movl %ebp, %r12d
pushq $0x1c
popq %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x2120
movq %rax, (%r15)
leaq 0x80(%rsp), %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x58(%rbp)
movups %xmm0, 0x48(%rbp)
movups %xmm0, 0x38(%rbp)
movups %xmm0, 0x28(%rbp)
movups %xmm0, 0x18(%rbp)
movups %xmm0, 0x8(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2120
movq %rax, (%rbp)
xorl %r13d, %r13d
movl $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movq %r12, 0x10(%rsp)
cmpq %r13, %r12
je 0x6e6e4
movq 0x20(%rbx), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x6e6dc
movq 0x28(%rbx), %rax
testl $0xfffffffe, (%rax,%r13,8) # imm = 0xFFFFFFFE
je 0x6e6dc
movq %rbx, %rdi
movl %r13d, %esi
movl %r14d, %edx
movq %r15, %rcx
callq 0x6e781
cmpq $0x1, %rax
jne 0x6e6dc
movq 0x60(%rsp), %r15
movl %ebp, 0xc(%rsp)
movl 0x50(%rsp), %ebp
movq %r14, %r12
movq 0x30(%rsp), %r14
movl (%r14), %r8d
leaq 0x80(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movl %r12d, %r9d
callq 0x6d1a4
addl %eax, 0x8(%rsp)
movl (%r14), %r8d
movq %r12, %r14
movq 0x10(%rsp), %r12
leaq 0x80(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x18(%rsp), %r15
movl %ebp, %edx
movl 0xc(%rsp), %ebp
movl %r13d, %ecx
movl %r14d, %r9d
callq 0x6df9b
addl %eax, %ebp
incq %r13
jmp 0x6e627
movq 0x18(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rdi
callq 0x2220
movq 0x48(%rsp), %rdi
callq 0x2220
movq 0x60(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq 0x98(%rsp), %rdi
callq 0x2220
movq 0xb0(%rsp), %rdi
callq 0x2220
movq 0xc8(%rsp), %rdi
callq 0x2220
movq 0xe0(%rsp), %rdi
callq 0x2220
addl 0x8(%rsp), %ebp
je 0x6e76d
movq %rbx, %rdi
callq 0x694eb
movq %rbx, %rdi
callq 0x69638
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq