// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_cut_tip(asg_t*, int)
int asg_cut_tip(asg_t *g, int max_ext)
{
    double startTime = Get_T();

	asg64_v a = {0,0,0};
	uint32_t n_vtx = g->n_seq * 2, v, i, cnt = 0;
    
	for (v = 0; v < n_vtx; ++v) {
		//if this seq has been deleted
		if (g->seq[v>>1].del) continue;
		///check if the another direction of v has no overlaps
		///if the self direction of v has no overlaps, we don't have the overlaps of them
		///here is check if the reverse direction of v 
		/**
		 the following first line is to find (means v is a node has no prefix):
		        (v)--->()---->()---->()----->....
         another case is:
            ......()---->()---->()----->()------>(v)
         this case can be found by (v^1), so we don't need to process this case here
		**/
		if (asg_is_utg_end(g, v, 0) != ASG_ET_TIP) continue; // not a tip
        /**
         the following second line is: 
		 (v)--->()---->()---->()----->()
		        |--------max_ext-------|
        **/
       ///that means here is a long tip, which is longer than max_ext
		if (asg_extend(g, v, max_ext, &a) == ASG_ET_MERGEABLE) continue; // not a short unitig

		/**
		 * so combining the last two lines, they are designed to reomve(n(0), n(1), n(2)):
		 *                  		    ----->n(4)
		 *                  		   |
		 * n(0)--->n(1)---->n(2)---->n(3)
		 *                             |
		 *                              ----->n(5)
		**/
		for (i = 0; i < a.n; ++i)
			asg_seq_del(g, (uint32_t)a.a[i]>>1);
		++cnt;
	}
	free(a.a);
	if (cnt > 0) asg_cleanup(g);
    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] cut %d tips\n", __func__, cnt);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }
	return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
callq 0x2f3fc
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x14(%rbx), %ebp
addl %ebp, %ebp
je 0xaa2ae
xorl %r14d, %r14d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl %ebp, 0x8(%rsp)
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xaa289
movq 0x28(%rbx), %rax
movl %r12d, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
jle 0xaa165
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0xc, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xaa14b
testl %ecx, %ecx
jne 0xaa289
movq %rbx, %rdi
movl %r12d, %esi
movl 0xc(%rsp), %edx
leaq 0x10(%rsp), %rcx
callq 0xa3ac7
testl %eax, %eax
je 0xaa289
movq %r14, 0x28(%rsp)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xaa27d
movq 0x20(%rsp), %rcx
movq %rcx, 0x30(%rsp)
xorl %edx, %edx
movq 0x30(%rsp), %rcx
movq (%rcx,%rdx,8), %rsi
movl %esi, %edi
shrl %edi
movq 0x20(%rbx), %r8
orl $0x80000000, (%r8,%rdi,8) # imm = 0x80000000
andl $-0x2, %esi
movb $0x1, %dil
xorl %r8d, %r8d
orq %rsi, %r8
movq 0x28(%rbx), %r9
movq (%r9,%r8,8), %r10
movq %r10, %r9
andq %r15, %r9
je 0xaa25a
shrq $0x20, %r10
leaq (%r10,%r10,2), %r10
shlq $0x3, %r10
addq 0x8(%rbx), %r10
xorl %r11d, %r11d
leaq (%r11,%r11,2), %r14
orb $-0x80, 0xf(%r10,%r14,8)
movl 0x8(%r10,%r14,8), %r14d
xorq $0x1, %r14
movq 0x28(%rbx), %r13
movq (%r13,%r14,8), %r14
movq %r14, %r13
andq %r15, %r13
je 0xaa252
movq 0x8(%rbx), %rcx
shrq $0x20, %r14
shlq $0x3, %r13
leaq (,%r13,2), %rbp
addq %r13, %rbp
leaq (%r14,%r14,2), %r14
leaq (%rcx,%r14,8), %r14
addq $0xc, %r14
xorl %r13d, %r13d
movl -0x4(%r14,%r13), %ecx
xorl %r8d, %ecx
cmpl $0x1, %ecx
jne 0xaa249
orb $-0x80, 0x3(%r14,%r13)
addq $0x18, %r13
cmpq %r13, %rbp
jne 0xaa236
incq %r11
cmpq %r9, %r11
jne 0xaa1ec
movl $0x1, %r8d
testb $0x1, %dil
movl $0x0, %edi
jne 0xaa1c2
incq %rdx
movl %edx, %ecx
cmpq %rcx, %rax
ja 0xaa1a0
movq 0x28(%rsp), %r14
incl %r14d
movl 0x8(%rsp), %ebp
incl %r12d
cmpl %ebp, %r12d
jne 0xaa108
movq 0x20(%rsp), %rdi
callq 0x2220
testl %r14d, %r14d
je 0xaa2ae
movq %rbx, %rdi
callq 0xa0a7d
jmp 0xaa2b1
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq