// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: double_check_tangle(unsigned int, unsigned int, unsigned int*, unsigned int, asg_t*)
int double_check_tangle(uint32_t vBeg, uint32_t vEnd, uint32_t* u_vecs, uint32_t n, asg_t *nsg)
{
    uint32_t v, nv, k, i, j;
    asg_arc_t *av = NULL;
    if(vBeg != (uint32_t)-1)
    {
        v = vBeg;
        nv = asg_arc_n(nsg, v);
        av = asg_arc_a(nsg, v);
        for(k = 0; k < nv; k++)
        {
            if(av[k].del) continue;
            for (i = 0; i < n; i++)
            {
                if((av[k].v>>1)==(u_vecs[i]>>1)) break;
            }
            ///haven't found
            if(i == n) return 0;
        }
    }

    if(vEnd != (uint32_t)-1)
    {
        v = vEnd^1;
        nv = asg_arc_n(nsg, v);
        av = asg_arc_a(nsg, v);
        for(k = 0; k < nv; k++)
        {
            if(av[k].del) continue;
            for (i = 0; i < n; i++)
            {
                if((av[k].v>>1)==(u_vecs[i]>>1)) break;
            }
            ///haven't found
            if(i == n) return 0;
        }
    }

    ///scan tangles
    for (j = 0; j < n; j++)
    {
        v = u_vecs[j];
        nv = asg_arc_n(nsg, v);
        av = asg_arc_a(nsg, v);
        for(k = 0; k < nv; k++)
        {
            if(av[k].del) continue;
            for (i = 0; i < n; i++)
            {
                if((av[k].v>>1)==(u_vecs[i]>>1)) break;
            }
            if(i == n && av[k].v != (vBeg^1) && av[k].v != vEnd) return 0;
        }



        v = v^1;
        nv = asg_arc_n(nsg, v);
        av = asg_arc_a(nsg, v);
        for(k = 0; k < nv; k++)
        {
            if(av[k].del) continue;
            for (i = 0; i < n; i++)
            {
                if((av[k].v>>1)==(u_vecs[i]>>1)) break;
            }
            if(i == n && av[k].v != (vBeg^1) && av[k].v != vEnd) return 0;
        }
    }
    
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $-0x1, %edi
je 0xe9a98
movq 0x28(%r8), %rax
movl %edi, %r9d
movq (%rax,%r9,8), %rax
testl %eax, %eax
je 0xe9a98
movq %rax, %r9
shrq $0x20, %r9
leaq (%r9,%r9,2), %r9
shlq $0x3, %r9
addq 0x8(%r8), %r9
movl %eax, %r10d
movl %ecx, %r11d
xorl %ebx, %ebx
xorl %eax, %eax
leaq (%rbx,%rbx,2), %r15
cmpl $0x0, 0xc(%r9,%r15,8)
js 0xe9a90
movl $0x0, %r14d
testl %ecx, %ecx
je 0xe9a87
leaq (%r9,%r15,8), %r14
movl 0x8(%r14), %ebp
xorl %r14d, %r14d
movl (%rdx,%r14,4), %r15d
xorl %ebp, %r15d
cmpl $0x2, %r15d
jb 0xe9a87
incq %r14
cmpq %r14, %r11
jne 0xe9a6d
jmp 0xe9c2e
cmpl %ecx, %r14d
je 0xe9c30
incq %rbx
cmpq %r10, %rbx
jne 0xe9a4c
cmpl $-0x1, %esi
je 0xe9b17
movl %esi, %eax
xorl $0x1, %eax
movq 0x28(%r8), %r9
movq (%r9,%rax,8), %rax
testl %eax, %eax
je 0xe9b17
movq %rax, %r9
shrq $0x20, %r9
leaq (%r9,%r9,2), %r9
shlq $0x3, %r9
addq 0x8(%r8), %r9
movl %eax, %r10d
movl %ecx, %r11d
xorl %ebx, %ebx
xorl %eax, %eax
leaq (%rbx,%rbx,2), %r15
cmpl $0x0, 0xc(%r9,%r15,8)
js 0xe9b0f
movl $0x0, %r14d
testl %ecx, %ecx
je 0xe9b06
leaq (%r9,%r15,8), %r14
movl 0x8(%r14), %ebp
xorl %r14d, %r14d
movl (%rdx,%r14,4), %r15d
xorl %ebp, %r15d
cmpl $0x2, %r15d
jb 0xe9b06
incq %r14
cmpq %r14, %r11
jne 0xe9aec
jmp 0xe9c2e
cmpl %ecx, %r14d
je 0xe9c30
incq %rbx
cmpq %r10, %rbx
jne 0xe9acb
movl $0x1, %eax
testl %ecx, %ecx
je 0xe9c30
movq 0x8(%r8), %r9
movq 0x28(%r8), %r8
movl %ecx, %ecx
xorl %r10d, %r10d
movl (%rdx,%r10,4), %r11d
movq (%r8,%r11,8), %r14
testl %r14d, %r14d
je 0xe9bac
movq %r14, %rbx
shrq $0x20, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r9,%rbx,8), %rbx
movl %r14d, %r14d
xorl %r15d, %r15d
leaq (%r15,%r15,2), %r12
cmpl $0x0, 0xc(%rbx,%r12,8)
js 0xe9ba4
leaq (%rbx,%r12,8), %r12
movl 0x8(%r12), %ebp
xorl %r12d, %r12d
movl (%rdx,%r12,4), %r13d
xorl %ebp, %r13d
cmpl $0x2, %r13d
jb 0xe9b82
incq %r12
cmpq %r12, %rcx
jne 0xe9b6b
jmp 0xe9b87
cmpl %r12d, %ecx
jne 0xe9ba4
movl %ebp, %r12d
xorl %edi, %r12d
cmpl $0x1, %r12d
setne %r12b
cmpl %esi, %ebp
setne %bpl
testb %r12b, %bpl
jne 0xe9c2e
incq %r15
cmpq %r14, %r15
jne 0xe9b53
xorq $0x1, %r11
movq (%r8,%r11,8), %rbx
testl %ebx, %ebx
je 0xe9c20
movq %rbx, %r11
shrq $0x20, %r11
leaq (%r11,%r11,2), %r11
leaq (%r9,%r11,8), %r11
movl %ebx, %ebx
xorl %r14d, %r14d
leaq (%r14,%r14,2), %r15
cmpl $0x0, 0xc(%r11,%r15,8)
js 0xe9c18
leaq (%r11,%r15,8), %r15
movl 0x8(%r15), %ebp
xorl %r15d, %r15d
movl (%rdx,%r15,4), %r12d
xorl %ebp, %r12d
cmpl $0x2, %r12d
jb 0xe9bfa
incq %r15
cmpl %r15d, %ecx
jne 0xe9be3
jmp 0xe9bff
cmpl %r15d, %ecx
jne 0xe9c18
movl %ebp, %r15d
xorl %edi, %r15d
cmpl $0x1, %r15d
setne %r15b
cmpl %esi, %ebp
setne %bpl
testb %r15b, %bpl
jne 0xe9c2e
incq %r14
cmpq %rbx, %r14
jne 0xe9bcc
incq %r10
cmpq %rcx, %r10
jne 0xe9b31
jmp 0xe9c30
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq