// File: /workspace/github_cpp_makefile_star2_O1/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 0x300fc
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x14(%rbx), %ebp
xorl %r14d, %r14d
addl %ebp, %ebp
je 0xa91f0
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 0xa91e4
movq 0x28(%rbx), %rax
movl %r12d, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
jle 0xa90c8
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rcx
addq $0xc, %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rcx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
incq %rdx
addq $0x18, %rcx
cmpq %rdx, %rax
jne 0xa90ab
testl %esi, %esi
jne 0xa91e4
movq %rbx, %rdi
movl %r12d, %esi
movl 0xc(%rsp), %edx
leaq 0x10(%rsp), %rcx
callq 0xa2ed8
testl %eax, %eax
je 0xa91e4
movq %r14, 0x28(%rsp)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xa91d8
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
xorl %edi, %edi
leaq (%rdi,%rsi), %r8
movq 0x28(%rbx), %r9
movq (%r9,%r8,8), %r10
movq %r10, %r9
andq %r15, %r9
je 0xa91ba
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 0xa91b2
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 0xa91a9
orb $-0x80, 0x3(%r14,%r13)
addq $0x18, %r13
cmpq %r13, %rbp
jne 0xa9196
incq %r11
cmpq %r9, %r11
jne 0xa914c
leaq 0x1(%rdi), %rcx
testq %rdi, %rdi
movq %rcx, %rdi
je 0xa9121
incq %rdx
movl %edx, %ecx
cmpq %rcx, %rax
ja 0xa9103
movq 0x28(%rsp), %r14
incl %r14d
movl 0x8(%rsp), %ebp
incl %r12d
cmpl %ebp, %r12d
jne 0xa9066
movq 0x20(%rsp), %rdi
callq 0x2220
testl %r14d, %r14d
je 0xa9207
movq %rbx, %rdi
callq 0xa02fa
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq