// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: drop_tips_at_tangle(asg_t*, unsigned long*, unsigned long, unsigned int, unsigned int, buf_t*)
int drop_tips_at_tangle(asg_t* nsg, uint64_t* nodes, uint64_t n, uint32_t beg, uint32_t end, 
buf_t* bb)
{
    uint32_t i, v, k, m, convex, return_flag, next_tips = 1, reduce = 0;
    long long ll, tmp, max_stop_nodeLen, max_stop_baseLen;
    
    while(next_tips > 0)
    {
        next_tips = 0;

        for (i = 0; i < n; i++)
        {
            v = (uint32_t)nodes[i];
            if(nsg->seq[v].del) continue;
            if(nsg->seq[v].c == ALTER_LABLE) continue;
            v = v<<1;

            for (k = 0; k < 2; k++)
            {
                v = v|k;
                if(get_real_length(nsg, v^1, NULL) != 0) continue;

                bb->b.n = 0;
                return_flag = get_unitig(nsg, NULL, v, &convex, &ll, &tmp, &max_stop_nodeLen, 
                        &max_stop_baseLen, 1, bb);
                if(return_flag == LOOP) continue;
                if(return_flag == MUL_OUTPUT) next_tips++;

                for(m = 0; m < bb->b.n; m++)
                {
                    if(((bb->b.a[m]>>1)==(beg>>1)) || ((bb->b.a[m]>>1)==(end>>1))) break;
                }
                ///means this unitig consists of beg or end 
                if(m != bb->b.n) continue;

                for(m = 0; m < bb->b.n; m++)
                {
                    nsg->seq[(bb->b.a[m]>>1)].c = ALTER_LABLE;
                }

                for(m = 0; m < bb->b.n; m++)
                {
                    asg_seq_drop(nsg, (bb->b.a[m]>>1));
                }
                
                reduce++;
            }
        }
    }
    
    return reduce;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdi, %r13
shrl %r14d
shrl %ebp
movq $0x0, 0x8(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
movl %ebp, 0x14(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0xaf3d8
xorl %edi, %edi
movl $0x0, 0x4(%rsp)
movl %edi, %edi
cmpq %rdx, %rdi
jae 0xaf295
movq (%rsi,%rdi,8), %r15
movl %r15d, %eax
movq 0x20(%r13), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xaf3d1
cmpb $0x1, 0x4(%rcx,%rax,8)
je 0xaf3d1
movq %rdi, 0x28(%rsp)
addl %r15d, %r15d
xorl %r12d, %r12d
cmpl $0x2, %r12d
je 0xaf3c2
orl %r12d, %r15d
movl %r15d, %esi
xorl $0x1, %esi
movq %r13, %rdi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
je 0xaf302
incl %r12d
jmp 0xaf2dc
andq $0x0, 0x38(%rbx)
movq %r13, %rdi
xorl %esi, %esi
movl %r15d, %edx
leaq 0x34(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x48(%rsp), %r9
pushq %rbx
pushq $0x1
leaq 0x48(%rsp), %rax
pushq %rax
leaq 0x58(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
cmpl $0x7, %eax
je 0xaf2fd
cmpl $0x4, %eax
jne 0xaf344
incl 0x4(%rsp)
movq 0x38(%rbx), %rax
xorl %esi, %esi
movl %esi, %ecx
cmpq %rcx, %rax
jbe 0xaf366
movq 0x48(%rbx), %rdx
movl (%rdx,%rcx,4), %edx
shrl %edx
cmpl %r14d, %edx
je 0xaf366
leal 0x1(%rcx), %esi
cmpl %ebp, %edx
jne 0xaf34a
cmpq %rcx, %rax
jne 0xaf2fd
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0xaf38a
movq 0x20(%r13), %rdx
movq 0x48(%rbx), %rsi
movl (%rsi,%rcx,4), %esi
shrl %esi
movb $0x1, 0x4(%rdx,%rsi,8)
incl %ecx
jmp 0xaf36d
xorl %ecx, %ecx
movl %ecx, %ebp
cmpq %rbp, %rax
jbe 0xaf3ad
movq 0x48(%rbx), %rax
movl (%rax,%rbp,4), %esi
shrl %esi
movq %r13, %rdi
callq 0x80870
leal 0x1(%rbp), %ecx
movq 0x38(%rbx), %rax
jmp 0xaf38c
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movl 0x14(%rsp), %ebp
jmp 0xaf2fd
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdi
incl %edi
jmp 0xaf2aa
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq