// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %r9, 0x70(%rsp)
movl %r8d, (%rsp)
movq %rcx, %r12
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %rbp
movq 0xb8(%rsp), %r13
movq 0xb0(%rsp), %r15
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movl $0x10, %edi
callq 0x2280
movq %rax, 0x10(%rsp)
movq $0x0, 0x38(%r15)
leaq 0x58(%rsp), %rax
leaq 0x60(%rsp), %r10
leaq 0x1c(%rsp), %rcx
leaq 0x38(%rsp), %r8
leaq 0x68(%rsp), %r9
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
movq 0xc0(%rsp), %rsi
movl %r14d, 0x8(%rsp)
movl %r14d, %edx
pushq %r15
pushq $0x1
pushq %rax
pushq %r10
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0xee87d
movq 0x10(%rsp), %rdi
callq 0x2220
movq 0x38(%r15), %rdi
testq %rdi, %rdi
je 0xeeccd
movq 0x48(%r15), %rdx
movl $0x1, %esi
xorl %ecx, %ecx
cmpl %ebx, (%rdx,%rcx,4)
je 0xeeccf
movl %esi, %ecx
incl %esi
cmpq %rcx, %rdi
ja 0xee866
jmp 0xeeccf
movq 0x10(%rsp), %rbp
cmpq $0x0, 0x38(%r15)
je 0xee8af
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, (%r13,%rdx)
movl %eax, %ecx
incl %eax
cmpq %rcx, 0x38(%r15)
ja 0xee890
testq %r12, %r12
sete %al
movl (%rsp), %edx
testl %edx, %edx
sete %cl
orb %al, %cl
jne 0xee8df
movl %edx, %eax
xorl %ecx, %ecx
movl (%r12,%rcx,4), %edx
movl %edx, %esi
shrl %esi
andb $0x1, %dl
incb %dl
orb %dl, (%r13,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0xee8c5
movl 0x8(%rsp), %eax
movl %eax, (%rbp)
movl $0x1, %r12d
movabsq $0x800000000000000, %rdi # imm = 0x800000000000000
movl $0x3, %esi
movq $0x0, 0x48(%rsp)
movq 0x30(%rsp), %r14
movl %ebx, 0x44(%rsp)
movq %rdi, 0x8(%rsp)
movq %rdi, %rax
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq %rcx, %rax
addq %r12, %rax
decq %rax
movq %rsi, (%rsp)
andq %rsi, %rax
movl (%rbp,%rax,4), %edx
movq $0x0, 0x38(%r15)
movq %r14, %rdi
movq 0xc0(%rsp), %rsi
leaq 0x1c(%rsp), %rcx
leaq 0x38(%rsp), %r8
leaq 0x68(%rsp), %r9
pushq %r15
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xee999
movq 0x48(%r15), %rdx
movl $0x1, %esi
xorl %edi, %edi
cmpl %ebx, (%rdx,%rdi,4)
je 0xee990
movl %esi, %edi
incl %esi
cmpq %rdi, %rcx
ja 0xee982
cmpq %rdi, %rcx
jne 0xeecd9
cmpl $0x7, %eax
je 0xeecc3
movq 0x48(%rsp), %rax
addq 0x38(%rsp), %rax
cmpq 0x70(%rsp), %rax
jg 0xeecc3
movl $0x0, 0x18(%rsp)
movq %rax, 0x48(%rsp)
movq %rbp, 0x10(%rsp)
decq %r12
movl 0x1c(%rsp), %eax
movq 0x28(%r14), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xeeca6
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r8
shlq $0x3, %r8
addq 0x8(%r14), %r8
movl %eax, %r9d
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq %r8, 0x20(%rsp)
movq %r9, 0x28(%rsp)
leaq (,%rbp,2), %rax
addq %rbp, %rax
cmpl $0x0, 0xc(%r8,%rax,8)
js 0xeec98
leaq (%r8,%rax,8), %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 0xeec98
movq %rsi, (%rsp)
movq %rdi, 0x8(%rsp)
movq $0x0, 0x38(%r15)
movq %r14, %rdi
movq 0xc0(%rsp), %rsi
leaq 0x1c(%rsp), %rcx
leaq 0x38(%rsp), %r8
leaq 0x68(%rsp), %r9
pushq %r15
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
callq 0x1053a7
movq 0x48(%rsp), %r9
addq $0x20, %rsp
movq 0x38(%r15), %rdx
testq %rdx, %rdx
je 0xeeac6
movq 0x48(%r15), %rax
movl $0x1, %ecx
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
movl %edi, %r8d
shrl %r8d
movzbl (%r13,%r8), %r8d
andl $0x1, %edi
incl %edi
testl %r8d, %edi
jne 0xeeac1
movl %ecx, %esi
incl %ecx
cmpq %rsi, %rdx
ja 0xeea9f
cmpq %rsi, %rdx
jne 0xeeb41
movl 0x8(%rbx), %ebx
movq 0x8(%rsp), %rdi
movq %rdi, %rax
shrq $0x3a, %rax
movl $0x1, %esi
movl %eax, %ecx
shlq %cl, %rsi
cmpq %rsi, %r12
jne 0xeeb33
leal 0x1(%rax), %r14d
movl $0x1, %esi
movl %r14d, %ecx
shlq %cl, %rsi
cmpq %r12, %rsi
movq %r12, 0x50(%rsp)
movq 0x20(%rsp), %r8
jae 0xeeb64
movq $-0x1, %r14
incq %r14
movq %r12, %rsi
movl %r14d, %ecx
shrq %cl, %rsi
cmpq $0x3f, %r14
ja 0xeeb20
testq %rsi, %rsi
jne 0xeeb09
cmpq %r14, %rax
jne 0xeeb54
movq 0x30(%rsp), %r14
movq (%rsp), %rsi
jmp 0xeec4c
movq (%rsp), %rsi
movq 0x20(%rsp), %r8
jmp 0xeec4c
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq 0x20(%rsp), %r8
jmp 0xeec98
movl $0x1, %esi
movl %r14d, %ecx
shlq %cl, %rsi
cmpq %rax, %r14
jbe 0xeeb8e
movq %rsi, %r12
movl $0x4, %esi
movl %r14d, %ecx
shlq %cl, %rsi
movq 0x10(%rsp), %rdi
callq 0x2370
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %r8
movq %r12, %rsi
movq %rdi, %r12
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rax, %r12
movq 0x50(%rsp), %r13
leaq (%r12,%r13), %rdx
cmpq %r13, %rdx
jbe 0xeebfb
movq %r13, %rdx
subq %r12, %rdx
movq %rsi, %rax
subq %rdx, %rax
movq 0x10(%rsp), %rcx
movl %ebx, 0x8(%rsp)
movq %rdi, %rbx
leaq (%rcx,%rax,4), %rdi
movq %rsi, (%rsp)
leaq (%rcx,%r12,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movq 0x20(%rsp), %r8
subq %r13, %rbx
addq (%rsp), %rbx
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rax, %rbx
movq %rbx, %r12
movl 0x8(%rsp), %ebx
jmp 0xeec17
subq %rsi, %rdx
jbe 0xeec17
movq 0x10(%rsp), %rdi
leaq (%rdi,%rsi,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movq 0x20(%rsp), %r8
movq 0xb8(%rsp), %r13
movq 0x28(%rsp), %r9
movq %r14, %rdi
movq $-0x1, %rsi
movl %r14d, %ecx
shlq %cl, %rsi
shlq $0x3a, %rdi
orq %r12, %rdi
notq %rsi
movq 0x38(%r15), %rdx
movq 0x30(%rsp), %r14
movq 0x50(%rsp), %r12
movq %rdi, %rax
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq %rcx, %rax
addq %r12, %rax
incq %r12
andq %rsi, %rax
movq 0x10(%rsp), %rcx
movl %ebx, (%rcx,%rax,4)
testq %rdx, %rdx
je 0xeec98
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, (%r13,%rdx)
movl %eax, %ecx
incl %eax
cmpq %rcx, 0x38(%r15)
ja 0xeec79
incq %rbp
cmpq %r9, %rbp
jne 0xeea0b
jmp 0xeecaf
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
testq %r12, %r12
movl 0x44(%rsp), %ebx
movq 0x10(%rsp), %rbp
jne 0xee90d
jmp 0xeece1
movl $0x0, 0x18(%rsp)
jmp 0xeece1
xorl %ecx, %ecx
xorl %eax, %eax
cmpq %rcx, %rdi
setne %al
jmp 0xeeced
movl $0x1, 0x18(%rsp)
movq %rbp, %rdi
callq 0x2220
movl 0x18(%rsp), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq