// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: find_spec_node(asg_t*, unsigned int, unsigned int, unsigned int*, unsigned int, long long, buf_t*, unsigned char*, ma_ug_t*)
int find_spec_node(asg_t *nsg, uint32_t vBeg, uint32_t vDest, uint32_t* forbidden_nodes, 
uint32_t forbidden_nodes_n, long long max_nodes, buf_t* bb, uint8_t* visit, ma_ug_t *ug)
{
    uint32_t nv, un_visit;
    asg_arc_t *av;

    memset(visit, 0, nsg->n_seq);
    kdq_t(uint32_t) *buf;
    buf = kdq_init(uint32_t);

    uint32_t vEnd, i, k, v, is_found = 0, return_flag;
    long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen, totalNodes = 0;

    bb->b.n = 0;
    if(get_unitig(nsg, ug, vBeg, &vEnd, &nodeLen, &baseLen, 
                                        &max_stop_nodeLen, &max_stop_baseLen, 1, bb)==LOOP)
    {
        kdq_destroy(uint32_t, buf);

        for (i = 0; i < bb->b.n; i++)
        {
            if(bb->b.a[i] == vDest) break;
        }
        if(i != bb->b.n) return 1;

        return 0;
    }
    

    for (i = 0; i < bb->b.n; i++)
    {
        Set_vis(visit, bb->b.a[i], 0);
        ///Set_vis(visit, bb->b.a[i]^1, 0);
    }

    if(forbidden_nodes != NULL && forbidden_nodes_n != 0)
    {
        for (i = 0; i < forbidden_nodes_n; i++)
        {
            Set_vis(visit, forbidden_nodes[i], 0);
        }
    }
    
    

    v = vBeg;
    kdq_push(uint32_t, buf, v);

    while (kdq_size(buf) != 0)
    {

        v = *(kdq_pop(uint32_t, buf));

        bb->b.n = 0;
        return_flag = get_unitig(nsg, ug, v, &vEnd, &nodeLen, &baseLen, 
                                        &max_stop_nodeLen, &max_stop_baseLen, 1, bb);

        for (i = 0; i < bb->b.n; i++)
        {
            if(bb->b.a[i] == vDest) break;
        }

        if(i != bb->b.n) 
        {
            is_found = 1;
            break;
        }
        
        if(return_flag == LOOP) break;

        totalNodes += nodeLen;
        if(totalNodes > max_nodes) break;
        
        v = vEnd;
        nv = asg_arc_n(nsg, v);
        av = asg_arc_a(nsg, v);
        for(k = 0; k < nv; k++)
        {
            if(av[k].del) continue;
        
            if(Get_vis(visit,av[k].v, 0)!=0) continue;

            un_visit = 0;
            bb->b.n = 0;
            get_unitig(nsg, ug, av[k].v, &vEnd, &nodeLen, &baseLen, 
                                        &max_stop_nodeLen, &max_stop_baseLen, 1, bb);
            for (i = 0; i < bb->b.n; i++)
            {
                if(Get_vis(visit, bb->b.a[i], 0) != 0) break;
            }
            if(i == bb->b.n) un_visit = 1;

            if(un_visit)
            {
                kdq_push(uint32_t, buf, av[k].v);
                for (i = 0; i < bb->b.n; i++)
                {
                    Set_vis(visit, bb->b.a[i], 0);
                }
            }
            
        }
    }

    kdq_destroy(uint32_t, buf);
    return is_found;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movl %r8d, 0x30(%rsp)
movq %rcx, %r12
movl %edx, %ebp
movl %esi, 0x10(%rsp)
movq %rdi, %r15
movq 0x98(%rsp), %r13
movq 0x90(%rsp), %r14
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %ebx, %ebx
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
callq 0xabb23
movq %rax, 0x18(%rsp)
andq $0x0, 0x38(%r14)
leaq 0x38(%rsp), %rax
leaq 0x40(%rsp), %r10
leaq 0xc(%rsp), %rcx
leaq 0x28(%rsp), %r8
leaq 0x48(%rsp), %r9
movq %r15, 0x20(%rsp)
movq %r15, %rdi
movq 0xa0(%rsp), %rsi
movl 0x10(%rsp), %edx
pushq %r14
pushq $0x1
pushq %rax
pushq %r10
callq 0xc2ebf
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0xaf742
movq 0x18(%rsp), %rdi
callq 0xabb58
movq 0x38(%r14), %rax
xorl %edx, %edx
movl %edx, %ecx
cmpq %rcx, %rax
jbe 0xaf733
movq 0x48(%r14), %rsi
leal 0x1(%rcx), %edx
cmpl %ebp, (%rsi,%rcx,4)
jne 0xaf720
xorl %r12d, %r12d
cmpq %rcx, %rax
setne %r12b
jmp 0xaf966
movq 0x18(%rsp), %r15
movl 0x30(%rsp), %esi
movl %ebx, %eax
cmpq %rax, 0x38(%r14)
jbe 0xaf76d
movq 0x48(%r14), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %edx
shrl %edx
andb $0x1, %cl
incb %cl
orb %cl, (%r13,%rdx)
leal 0x1(%rax), %ebx
jmp 0xaf74b
testq %r12, %r12
sete %al
testl %esi, %esi
sete %cl
orb %al, %cl
jne 0xaf79c
movl %esi, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xaf79c
movl (%r12,%rcx,4), %edx
movl %edx, %esi
shrl %esi
andb $0x1, %dl
incb %dl
orb %dl, (%r13,%rsi)
incq %rcx
jmp 0xaf780
movq %r15, %rdi
movl 0x10(%rsp), %esi
callq 0xabb74
movq $0x0, 0x10(%rsp)
movl %ebp, 0x34(%rsp)
cmpq $0x0, 0x8(%r15)
je 0xaf955
movq %r15, %rdi
callq 0xabcc1
movl (%rax), %edx
andq $0x0, 0x38(%r14)
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
leaq 0xc(%rsp), %rcx
leaq 0x28(%rsp), %r8
leaq 0x48(%rsp), %r9
pushq %r14
pushq $0x1
leaq 0x48(%rsp), %rax
pushq %rax
leaq 0x58(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
movq 0x38(%r14), %rcx
xorl %esi, %esi
movl %esi, %edx
cmpq %rdx, %rcx
jbe 0xaf81d
movq 0x48(%r14), %rdi
leal 0x1(%rdx), %esi
cmpl %ebp, (%rdi,%rdx,4)
jne 0xaf80a
cmpq %rdx, %rcx
jne 0xaf95a
xorl %r12d, %r12d
cmpl $0x7, %eax
je 0xaf95e
movq 0x10(%rsp), %rcx
addq 0x28(%rsp), %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x50(%rsp), %rcx
jg 0xaf95e
movl 0xc(%rsp), %eax
movq 0x20(%rsp), %rdx
movq 0x28(%rdx), %rcx
movq (%rcx,%rax,8), %rax
movl %eax, %r12d
shrq $0x20, %rax
imulq $0x18, %rax, %rbp
addq 0x8(%rdx), %rbp
xorl %r15d, %r15d
cmpq %r12, %r15
je 0xaf947
imulq $0x18, %r15, %rbx
cmpl $0x0, 0xc(%rbp,%rbx)
js 0xaf93f
addq %rbp, %rbx
movl 0x8(%rbx), %edx
movl %edx, %eax
shrl %eax
movzbl (%r13,%rax), %eax
movl %edx, %ecx
andl $0x1, %ecx
incl %ecx
testl %eax, %ecx
jne 0xaf93f
andq $0x0, 0x38(%r14)
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
leaq 0xc(%rsp), %rcx
leaq 0x28(%rsp), %r8
leaq 0x48(%rsp), %r9
pushq %r14
pushq $0x1
leaq 0x48(%rsp), %rax
pushq %rax
leaq 0x58(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
movq 0x38(%r14), %rax
xorl %edx, %edx
movl %edx, %ecx
cmpq %rcx, %rax
jbe 0xaf90a
movq 0x48(%r14), %rdx
movl (%rdx,%rcx,4), %esi
movl %esi, %edx
shrl %edx
movzbl (%r13,%rdx), %edi
andl $0x1, %esi
incl %esi
leal 0x1(%rcx), %edx
testl %edi, %esi
je 0xaf8e6
cmpq %rcx, %rax
jne 0xaf93f
movl 0x8(%rbx), %esi
movq 0x18(%rsp), %rdi
callq 0xabb74
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, 0x38(%r14)
jbe 0xaf93f
movq 0x48(%r14), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %edx
shrl %edx
andb $0x1, %cl
incb %cl
orb %cl, (%r13,%rdx)
incl %eax
jmp 0xaf91e
incq %r15
jmp 0xaf86f
movl 0x34(%rsp), %ebp
movq 0x18(%rsp), %r15
jmp 0xaf7b5
xorl %r12d, %r12d
jmp 0xaf95e
pushq $0x1
popq %r12
movq %r15, %rdi
callq 0xabb58
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq