// File: /workspace/github_cpp_makefile_star2_O1/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, (%rsp)
movq %rcx, %r13
movl %edx, %ebx
movl %esi, 0x10(%rsp)
movq %rdi, %r12
movq 0x98(%rsp), %rbp
movq 0x90(%rsp), %r15
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rbp, %rdi
xorl %esi, %esi
callq 0x20e0
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r14
movq (%rax), %rax
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq %rcx, %rax
btsq $0x3b, %rax
movq %rax, (%r14)
movq $0x3, 0x10(%r14)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x48(%rsp)
movq %rax, 0x18(%r14)
movq $0x0, 0x38(%r15)
leaq 0x30(%rsp), %rax
leaq 0x38(%rsp), %r10
leaq 0x4(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x40(%rsp), %r9
movq %r12, 0x8(%rsp)
movq %r12, %rdi
movl 0x10(%rsp), %r12d
movq 0xa0(%rsp), %rsi
movl %r12d, %edx
pushq %r15
pushq $0x1
pushq %rax
pushq %r10
callq 0x10109f
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0xecf96
movq 0x48(%rsp), %rdi
callq 0x2220
movq %r14, %rdi
callq 0x2220
movq 0x38(%r15), %rdi
testq %rdi, %rdi
je 0xed21b
movq 0x48(%r15), %rdx
movl $0x1, %esi
xorl %ecx, %ecx
cmpl %ebx, (%rdx,%rcx,4)
je 0xed21d
movl %esi, %ecx
incl %esi
cmpq %rcx, %rdi
ja 0xecf7f
jmp 0xed21d
cmpq $0x0, 0x38(%r15)
je 0xecfc2
movl $0x1, %eax
xorl %ecx, %ecx
movq 0x48(%r15), %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, %edx
shrl %edx
andb $0x1, %cl
incb %cl
orb %cl, (%rbp,%rdx)
movl %eax, %ecx
incl %eax
cmpq %rcx, 0x38(%r15)
ja 0xecfa4
testq %r13, %r13
sete %al
movl (%rsp), %edx
testl %edx, %edx
sete %cl
orb %al, %cl
jne 0xecff2
movl %edx, %eax
xorl %ecx, %ecx
movl (%r13,%rcx,4), %edx
movl %edx, %esi
shrl %esi
andb $0x1, %dl
incb %dl
orb %dl, (%rbp,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0xecfd8
movq %r14, %rdi
movl %r12d, %esi
callq 0xe8be3
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xed227
xorl %r12d, %r12d
movl %ebx, 0x24(%rsp)
movq %r14, 0x28(%rsp)
movq 0x18(%r14), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
movq (%r14), %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
addq %rdx, %rax
decq %rax
andq 0x10(%r14), %rax
movl (%rcx,%rax,4), %edx
movq $0x0, 0x38(%r15)
movq 0x8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
leaq 0x4(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq %r15
pushq $0x1
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xed0a0
movq 0x48(%r15), %rdx
movl $0x1, %esi
xorl %edi, %edi
cmpl %ebx, (%rdx,%rdi,4)
je 0xed0a2
movl %esi, %edi
incl %esi
cmpq %rdi, %rcx
ja 0xed090
jmp 0xed0a2
xorl %edi, %edi
cmpq %rdi, %rcx
jne 0xed230
movl $0x0, (%rsp)
cmpl $0x7, %eax
je 0xed237
addq 0x18(%rsp), %r12
cmpq 0x50(%rsp), %r12
jg 0xed237
movq %r12, 0x10(%rsp)
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xed1fe
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r12
shlq $0x3, %r12
movq 0x8(%rsp), %rcx
addq 0x8(%rcx), %r12
movl %eax, %r14d
xorl %r13d, %r13d
leaq (,%r13,2), %rax
addq %r13, %rax
cmpl $0x0, 0xc(%r12,%rax,8)
js 0xed1f2
leaq (%r12,%rax,8), %rbx
movl 0x8(%rbx), %edx
movl %edx, %eax
shrl %eax
movzbl (%rbp,%rax), %eax
movl %edx, %ecx
andl $0x1, %ecx
incl %ecx
testl %eax, %ecx
jne 0xed1f2
movq $0x0, 0x38(%r15)
movq 0x8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
leaq 0x4(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq %r15
pushq $0x1
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x38(%r15), %rax
testq %rax, %rax
je 0xed1b2
movq 0x48(%r15), %rcx
movl $0x1, %edx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
movl %edi, %r8d
shrl %r8d
movzbl (%rbp,%r8), %r8d
andl $0x1, %edi
incl %edi
testl %r8d, %edi
jne 0xed1b4
movl %edx, %esi
incl %edx
cmpq %rsi, %rax
ja 0xed18e
jmp 0xed1b4
xorl %esi, %esi
cmpq %rsi, %rax
jne 0xed1f2
movl 0x8(%rbx), %esi
movq 0x28(%rsp), %rdi
callq 0xe8be3
cmpq $0x0, 0x38(%r15)
je 0xed1f2
movl $0x1, %eax
xorl %ecx, %ecx
movq 0x48(%r15), %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, %edx
shrl %edx
andb $0x1, %cl
incb %cl
orb %cl, (%rbp,%rdx)
movl %eax, %ecx
incl %eax
cmpq %rcx, 0x38(%r15)
ja 0xed1d4
incq %r13
cmpq %r14, %r13
jne 0xed107
movq 0x28(%rsp), %r14
movq 0x8(%r14), %rax
testq %rax, %rax
movl 0x24(%rsp), %ebx
movq 0x10(%rsp), %r12
jne 0xed016
jmp 0xed237
xorl %ecx, %ecx
xorl %eax, %eax
cmpq %rcx, %rdi
setne %al
jmp 0xed24b
movl $0x0, (%rsp)
jmp 0xed237
movl $0x1, (%rsp)
movq 0x18(%r14), %rdi
callq 0x2220
movq %r14, %rdi
callq 0x2220
movl (%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq