// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %r9, %rbx
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdx, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %r13
shrl %r14d
shrl %ebp
movq $0x0, 0x18(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %ebp, 0x24(%rsp)
movl %r14d, 0x20(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0xecad2
xorl %esi, %esi
movl $0x0, 0x4(%rsp)
movq 0x30(%rsp), %rax
movq (%rax,%rsi,8), %rdx
movl %edx, %eax
movq 0x20(%r13), %rcx
cmpl $0x0, (%rcx,%rax,8)
movq %rsi, 0x38(%rsp)
js 0xecab6
cmpb $0x1, 0x4(%rcx,%rax,8)
je 0xecab6
addl %edx, %edx
xorl %r9d, %r9d
orl %r9d, %edx
movl %edx, %eax
xorl $0x1, %eax
movq 0x28(%r13), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
andq %r12, %rcx
je 0xec8d1
movq 0x8(%r13), %rsi
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsi,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %r8d, %r8d
xorl %esi, %esi
movl (%rax,%r8), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %r8
cmpq %r8, %rcx
jne 0xec8b5
testl %esi, %esi
jne 0xecaa6
movq %r9, 0x8(%rsp)
movq $0x0, 0x38(%rbx)
movq %r13, %rdi
xorl %esi, %esi
movq %rdx, 0x10(%rsp)
leaq 0x44(%rsp), %rcx
leaq 0x60(%rsp), %r8
leaq 0x58(%rsp), %r9
pushq %rbx
pushq $0x1
leaq 0x58(%rsp), %rax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x7, %eax
je 0xeca9c
cmpl $0x4, %eax
jne 0xec921
incl 0x4(%rsp)
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %r9
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xec959
movq 0x48(%rbx), %r8
movl $0x1, %esi
xorl %ecx, %ecx
movl (%r8,%rcx,4), %edi
shrl %edi
cmpl %r14d, %edi
je 0xec95b
cmpl %ebp, %edi
je 0xec95b
movl %esi, %ecx
incl %esi
cmpq %rcx, %rax
ja 0xec93f
jmp 0xec95b
xorl %ecx, %ecx
cmpq %rcx, %rax
jne 0xecaa6
testq %rax, %rax
je 0xec987
movq 0x20(%r13), %rcx
movq 0x48(%rbx), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movb $0x1, 0x4(%rcx,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0xec973
cmpq $0x0, 0x38(%rbx)
je 0xeca87
xorl %eax, %eax
movq 0x48(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %edx
shrl %edx
movq 0x20(%r13), %rsi
cmpb $0x1, 0x4(%rsi,%rdx,8)
jne 0xeca7b
andl $-0x2, %ecx
xorl %edx, %edx
leaq (%rdx,%rcx), %rsi
movq 0x28(%r13), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
andq %r12, %rdi
je 0xeca6b
shrq $0x20, %r8
leaq (%r8,%r8,2), %r8
shlq $0x3, %r8
addq 0x8(%r13), %r8
xorl %r9d, %r9d
leaq (%r9,%r9,2), %r11
movl 0xc(%r8,%r11,8), %r10d
testl %r10d, %r10d
js 0xeca5f
leaq (%r8,%r11,8), %r14
movq 0x20(%r13), %r15
movl 0x8(%r14), %ebp
movl %ebp, %r11d
shrl %r11d
cmpb $0x1, 0x4(%r15,%r11,8)
je 0xeca5f
orl $0x80000000, %r10d      # imm = 0x80000000
movl %r10d, 0xc(%r14)
xorq $0x1, %rbp
movq 0x28(%r13), %r10
movq (%r10,%rbp,8), %r11
movq %r11, %r10
andq %r12, %r10
je 0xeca5f
movq 0x8(%r13), %r14
shrq $0x20, %r11
shlq $0x3, %r10
leaq (%r10,%r10,2), %r10
leaq (%r11,%r11,2), %r11
leaq (%r14,%r11,8), %r11
addq $0xc, %r11
xorl %r14d, %r14d
movl -0x4(%r11,%r14), %ebp
xorl %esi, %ebp
cmpl $0x1, %ebp
jne 0xeca56
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xeca44
incq %r9
cmpq %rdi, %r9
jne 0xec9de
leaq 0x1(%rdx), %rsi
testq %rdx, %rdx
movq %rsi, %rdx
je 0xec9b3
incl %eax
cmpq %rax, 0x38(%rbx)
ja 0xec994
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movl 0x24(%rsp), %ebp
movl 0x20(%rsp), %r14d
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %r9
leal 0x1(%r9), %eax
testl %r9d, %r9d
movl %eax, %r9d
je 0xec87c
movq 0x38(%rsp), %rsi
incl %esi
cmpq 0x28(%rsp), %rsi
jb 0xec84e
cmpl $0x0, 0x4(%rsp)
sete %al
jmp 0xecad4
movb $0x1, %al
testb %al, %al
je 0xec838
movq 0x18(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq