// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq 0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
callq 0x1412a0
movq %rax, -0x48(%rbp)
movl $0x0, -0x5c(%rbp)
movq $0x0, -0x88(%rbp)
movq 0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movq 0x20(%rbp), %rsi
movl -0x14(%rbp), %edx
movq 0x10(%rbp), %rax
leaq -0x4c(%rbp), %rcx
leaq -0x68(%rbp), %r8
leaq -0x70(%rbp), %r9
leaq -0x78(%rbp), %r11
leaq -0x80(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
cmpl $0x7, %eax
jne 0x147da6
movq -0x48(%rbp), %rdi
callq 0x141340
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x147d81
movq 0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x18(%rbp), %eax
jne 0x147d74
jmp 0x147d81
jmp 0x147d76
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x147d52
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
je 0x147d9a
movl $0x1, -0x4(%rbp)
jmp 0x148167
movl $0x0, -0x4(%rbp)
jmp 0x148167
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x147dfb
movq 0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shll $0x0, %esi
andl $0x1, %esi
addl $0x1, %esi
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x50(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x147dad
cmpq $0x0, -0x20(%rbp)
je 0x147e52
cmpl $0x0, -0x24(%rbp)
je 0x147e52
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x147e50
movq -0x20(%rbp), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shll $0x0, %esi
andl $0x1, %esi
addl $0x1, %esi
movq 0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movl -0x50(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x147e0f
jmp 0x147e52
movl -0x14(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x141380
movq -0x48(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x148158
movq -0x48(%rbp), %rdi
callq 0x141410
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movq 0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movq 0x20(%rbp), %rsi
movl -0x58(%rbp), %edx
movq 0x10(%rbp), %rax
leaq -0x4c(%rbp), %rcx
leaq -0x68(%rbp), %r8
leaq -0x70(%rbp), %r9
leaq -0x78(%rbp), %r11
leaq -0x80(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl %eax, -0x60(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x147f04
movq 0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x18(%rbp), %eax
jne 0x147ef7
jmp 0x147f04
jmp 0x147ef9
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x147ed5
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
je 0x147f1d
movl $0x1, -0x5c(%rbp)
jmp 0x148158
cmpl $0x7, -0x60(%rbp)
jne 0x147f28
jmp 0x148158
movq -0x68(%rbp), %rax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x30(%rbp), %rax
jle 0x147f4c
jmp 0x148158
movl -0x4c(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x58(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x148153
movq -0x40(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x147fbb
jmp 0x148145
movq 0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movl -0x54(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x40(%rbp), %rcx
movl -0x54(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shll $0x0, %ecx
andl $0x1, %ecx
addl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x147ffe
jmp 0x148145
movl $0x0, -0x38(%rbp)
movq 0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movq 0x20(%rbp), %rsi
movq -0x40(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq 0x10(%rbp), %rax
leaq -0x4c(%rbp), %rcx
leaq -0x68(%rbp), %r8
leaq -0x70(%rbp), %r9
leaq -0x78(%rbp), %r11
leaq -0x80(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x1480b8
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x50(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq 0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x50(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shll $0x0, %ecx
andl $0x1, %ecx
addl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x1480ab
jmp 0x1480b8
jmp 0x1480ad
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x148064
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x1480cc
movl $0x1, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x148143
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
movl -0x54(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
callq 0x141380
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x148141
movq 0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shll $0x0, %esi
andl $0x1, %esi
addl $0x1, %esi
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x50(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1480f3
jmp 0x148143
jmp 0x148145
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x147f91
jmp 0x147e64
movq -0x48(%rbp), %rdi
callq 0x141340
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)