// File: /workspace/github_cpp_makefile_star2_O1/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
movl %ecx, %r9d
cmpl $-0x1, %edi
je 0xe8286
movq 0x28(%r8), %rax
movl %edi, %r10d
movq (%rax,%r10,8), %rax
testl %eax, %eax
je 0xe8286
movq %rax, %r10
shrq $0x20, %r10
leaq (%r10,%r10,2), %r10
shlq $0x3, %r10
addq 0x8(%r8), %r10
movl %eax, %r11d
xorl %ebx, %ebx
xorl %eax, %eax
leaq (%rbx,%rbx,2), %r15
cmpl $0x0, 0xc(%r10,%r15,8)
js 0xe827e
movl $0x0, %r14d
testl %ecx, %ecx
je 0xe8275
leaq (%r10,%r15,8), %r14
movl 0x8(%r14), %ebp
xorl %r14d, %r14d
movl (%rdx,%r14,4), %r15d
xorl %ebp, %r15d
cmpl $0x2, %r15d
jb 0xe8275
incq %r14
cmpl %r14d, %r9d
jne 0xe825d
movl %r9d, %r14d
cmpl %ecx, %r14d
je 0xe8442
incq %rbx
cmpq %r11, %rbx
jne 0xe823c
cmpl $-0x1, %esi
je 0xe8300
movl %esi, %eax
xorl $0x1, %eax
movq 0x28(%r8), %r10
movq (%r10,%rax,8), %rax
testl %eax, %eax
je 0xe8300
movq %rax, %r10
shrq $0x20, %r10
leaq (%r10,%r10,2), %r10
shlq $0x3, %r10
addq 0x8(%r8), %r10
movl %eax, %r11d
xorl %ebx, %ebx
xorl %eax, %eax
leaq (%rbx,%rbx,2), %r15
cmpl $0x0, 0xc(%r10,%r15,8)
js 0xe82f8
movl $0x0, %r14d
testl %ecx, %ecx
je 0xe82ef
leaq (%r10,%r15,8), %r14
movl 0x8(%r14), %ebp
xorl %r14d, %r14d
movl (%rdx,%r14,4), %r15d
xorl %ebp, %r15d
cmpl $0x2, %r15d
jb 0xe82ef
incq %r14
cmpl %r14d, %r9d
jne 0xe82d7
movl %r9d, %r14d
cmpl %ecx, %r14d
je 0xe8442
incq %rbx
cmpq %r11, %rbx
jne 0xe82b6
movl $0x1, %eax
testl %ecx, %ecx
je 0xe8442
movq 0x8(%r8), %r10
movq %r10, -0x10(%rsp)
movq 0x28(%r8), %r8
movq %r8, -0x8(%rsp)
xorl %r11d, %r11d
movl (%rdx,%r11,4), %ebx
movq -0x8(%rsp), %r8
movq (%r8,%rbx,8), %r10
testl %r10d, %r10d
je 0xe83aa
movq %r10, %r14
shrq $0x20, %r14
leaq (%r14,%r14,2), %r14
movq -0x10(%rsp), %r8
leaq (%r8,%r14,8), %r14
movl %r10d, %r15d
xorl %r12d, %r12d
leaq (%r12,%r12,2), %r10
cmpl $0x0, 0xc(%r14,%r10,8)
js 0xe83a2
leaq (%r14,%r10,8), %r13
movl 0x8(%r13), %r10d
xorl %ebp, %ebp
movl (%rdx,%rbp,4), %r8d
xorl %r10d, %r8d
cmpl $0x2, %r8d
jb 0xe837c
incq %rbp
cmpl %ebp, %r9d
jne 0xe8364
movl %r9d, %ebp
cmpl %ecx, %ebp
jne 0xe83a2
movl 0x8(%r13), %r8d
movl %r8d, %r10d
xorl %edi, %r10d
cmpl $0x1, %r10d
setne %r10b
cmpl %esi, %r8d
setne %r8b
testb %r10b, %r8b
jne 0xe8440
incq %r12
cmpq %r15, %r12
jne 0xe834e
xorq $0x1, %rbx
movq -0x8(%rsp), %r8
movq (%r8,%rbx,8), %r10
testl %r10d, %r10d
je 0xe8432
movq %r10, %r8
shrq $0x20, %r8
leaq (%r8,%r8,2), %r8
movq -0x10(%rsp), %rbx
leaq (%rbx,%r8,8), %rbx
movl %r10d, %r14d
xorl %r15d, %r15d
leaq (%r15,%r15,2), %r10
cmpl $0x0, 0xc(%rbx,%r10,8)
js 0xe842a
leaq (%rbx,%r10,8), %r12
movl 0x8(%r12), %r10d
xorl %r13d, %r13d
movl (%rdx,%r13,4), %r8d
xorl %r10d, %r8d
cmpl $0x2, %r8d
jb 0xe8406
incq %r13
cmpl %r13d, %r9d
jne 0xe83ee
movl %r9d, %r13d
cmpl %ecx, %r13d
jne 0xe842a
movl 0x8(%r12), %r8d
movl %r8d, %r10d
xorl %edi, %r10d
cmpl $0x1, %r10d
setne %r10b
cmpl %esi, %r8d
setne %r8b
testb %r10b, %r8b
jne 0xe8440
incq %r15
cmpq %r14, %r15
jne 0xe83d6
incq %r11
cmpq %r9, %r11
jne 0xe8322
jmp 0xe8442
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq