// File: /workspace/github_cpp_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2f3fc
movl 0x14(%rbx), %eax
leal (%rax,%rax), %ebp
testl %eax, %eax
js 0xa720c
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movups %xmm0, 0x70(%rsp)
movups %xmm0, 0x60(%rsp)
movups %xmm0, 0x50(%rsp)
movl %ebp, %r15d
movl $0x1c, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, %r13
movq %rax, 0x48(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x108(%rsp)
movups %xmm0, 0xf8(%rsp)
movups %xmm0, 0xe8(%rsp)
movups %xmm0, 0xd8(%rsp)
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xb8(%rsp)
movl $0x1c, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0xb0(%rsp)
testl %ebp, %ebp
je 0xa73de
xorl %r12d, %r12d
leaq 0x48(%rsp), %r13
xorl %ebp, %ebp
movl $0x0, 0x14(%rsp)
movq %r15, 0x18(%rsp)
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xa7367
movq 0x28(%rbx), %rax
testl $0xfffffffe, (%rax,%r12,8) # imm = 0xFFFFFFFE
je 0xa7367
movq %rbx, %rdi
movl %r12d, %esi
movl %r14d, %edx
movq %r13, %rcx
callq 0xa74af
cmpq $0x1, %rax
jne 0xa7367
movq 0x90(%rsp), %r13
movl %ebp, 0x20(%rsp)
movl 0x80(%rsp), %ebp
movq %r14, %r15
movq 0x60(%rsp), %r14
movl (%r14), %r8d
leaq 0xb0(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movl %ebp, %edx
movl %r12d, %ecx
movl %r15d, %r9d
callq 0xa533f
addl %eax, 0x14(%rsp)
movl (%r14), %r8d
movq %r15, %r14
movq 0x18(%rsp), %r15
leaq 0xb0(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x48(%rsp), %r13
movl %ebp, %edx
movl 0x20(%rsp), %ebp
movl %r12d, %ecx
movl %r14d, %r9d
callq 0xa6a35
addl %eax, %ebp
incq %r12
cmpq %r12, %r15
jne 0xa72b5
movq 0x48(%rsp), %r13
movq 0x60(%rsp), %r15
movq 0x78(%rsp), %r14
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xb0(%rsp), %r12
movq 0xc8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x20(%rsp)
addl 0x14(%rsp), %ebp
jmp 0xa741f
movq %rax, %r12
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %r13, %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2220
movq %r14, %rdi
callq 0x2220
movq 0x28(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rdi
callq 0x2220
movq %r12, %rdi
callq 0x2220
movq 0x38(%rsp), %rdi
callq 0x2220
movq 0x40(%rsp), %rdi
callq 0x2220
movq 0x18(%rsp), %rdi
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x2220
testl %ebp, %ebp
je 0xa749b
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
movl %ebp, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq