// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x1, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
cmpl $0x0, -0x44(%rbp)
jbe 0x1478f4
movl $0x0, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpq -0x18(%rbp), %rax
jae 0x1478ef
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x14772e
jmp 0x1478e1
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x147748
jmp 0x1478e1
movl -0x30(%rbp), %eax
shll %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x2, -0x34(%rbp)
jae 0x1478df
movl -0x30(%rbp), %eax
orl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0x147787
jmp 0x1478d1
movq -0x28(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
movq -0x28(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %esi
leaq -0x3c(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x58(%rbp), %r9
leaq -0x60(%rbp), %r11
leaq -0x68(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl %eax, -0x40(%rbp)
cmpl $0x7, -0x40(%rbp)
jne 0x1477df
jmp 0x1478d1
cmpl $0x4, -0x40(%rbp)
jne 0x1477ee
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x147843
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0x147834
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl -0x20(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x147836
jmp 0x147843
jmp 0x147838
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1477f5
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x38(%rcx), %rax
je 0x147852
jmp 0x1478d1
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x147890
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x1, 0x4(%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x147859
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x1478c8
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shrl %esi
callq 0xf6800
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x147897
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x147757
jmp 0x1478e1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1476f8
jmp 0x1476e0
movl -0x48(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq