// File: /workspace/github_cpp_makefile_star2_O2/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 0xab383
movq 0x28(%r8), %rax
movl %edi, %r10d
movq (%rax,%r10,8), %rax
movl %eax, %r10d
shrq $0x20, %rax
imulq $0x18, %rax, %r11
addq 0x8(%r8), %r11
xorl %ebx, %ebx
xorl %eax, %eax
cmpq %r10, %rbx
je 0xab383
imulq $0x18, %rbx, %r14
cmpl $0x0, 0xc(%r11,%r14)
js 0xab37e
addq %r11, %r14
xorl %r15d, %r15d
cmpq %r15, %r9
je 0xab4fe
movl (%rdx,%r15,4), %ebp
xorl 0x8(%r14), %ebp
cmpl $0x2, %ebp
jb 0xab375
incq %r15
jmp 0xab35a
cmpl %r15d, %r9d
je 0xab4fe
incq %rbx
jmp 0xab343
cmpl $-0x1, %esi
je 0xab3e8
movl %esi, %eax
xorl $0x1, %eax
movq 0x28(%r8), %r10
movq (%r10,%rax,8), %rax
movl %eax, %r10d
shrq $0x20, %rax
imulq $0x18, %rax, %r11
addq 0x8(%r8), %r11
xorl %ebx, %ebx
xorl %eax, %eax
cmpq %r10, %rbx
je 0xab3e8
imulq $0x18, %rbx, %r14
cmpl $0x0, 0xc(%r11,%r14)
js 0xab3e3
addq %r11, %r14
xorl %r15d, %r15d
cmpq %r15, %r9
je 0xab4fe
movl (%rdx,%r15,4), %ebp
xorl 0x8(%r14), %ebp
cmpl $0x2, %ebp
jb 0xab3da
incq %r15
jmp 0xab3bf
cmpl %r15d, %r9d
je 0xab4fe
incq %rbx
jmp 0xab3a8
xorl %r10d, %r10d
movl $0x1, %eax
cmpq %r9, %r10
je 0xab4fe
movq %r10, -0x10(%rsp)
movl (%rdx,%r10,4), %ebx
movq 0x8(%r8), %r11
movq 0x28(%r8), %r10
movq %r10, -0x8(%rsp)
movq (%r10,%rbx,8), %r10
movl %r10d, %r15d
shrq $0x20, %r10
imulq $0x18, %r10, %r12
addq %r11, %r12
xorl %r13d, %r13d
cmpq %r15, %r13
je 0xab47d
imulq $0x18, %r13, %rbp
cmpl $0x0, 0xc(%r12,%rbp)
js 0xab478
addq %r12, %rbp
xorl %r10d, %r10d
cmpq %r10, %r9
je 0xab458
movl (%rdx,%r10,4), %r14d
xorl 0x8(%rbp), %r14d
cmpl $0x2, %r14d
jb 0xab453
incq %r10
jmp 0xab43b
cmpl %r10d, %r9d
jne 0xab478
movl 0x8(%rbp), %r10d
movl %r10d, %ebp
xorl %edi, %ebp
cmpl $0x1, %ebp
setne %bpl
cmpl %esi, %r10d
setne %r10b
testb %bpl, %r10b
jne 0xab4fc
incq %r13
jmp 0xab424
xorq $0x1, %rbx
movq -0x8(%rsp), %r10
movq (%r10,%rbx,8), %r10
movl %r10d, %ebx
shrq $0x20, %r10
imulq $0x18, %r10, %r10
addq %r10, %r11
xorl %r14d, %r14d
cmpq %rbx, %r14
je 0xab4ef
imulq $0x18, %r14, %r15
cmpl $0x0, 0xc(%r11,%r15)
js 0xab4ea
addq %r11, %r15
xorl %ebp, %ebp
cmpl %ebp, %ecx
je 0xab4ce
movl %ebp, %r10d
movl (%rdx,%r10,4), %r10d
xorl 0x8(%r15), %r10d
cmpl $0x2, %r10d
jb 0xab4ca
incl %ebp
jmp 0xab4b1
cmpl %ebp, %ecx
jne 0xab4ea
movl 0x8(%r15), %r10d
movl %r10d, %ebp
xorl %edi, %ebp
cmpl $0x1, %ebp
setne %bpl
cmpl %esi, %r10d
setne %r10b
testb %bpl, %r10b
jne 0xab4fc
incq %r14
jmp 0xab49b
movq -0x10(%rsp), %r10
incq %r10
jmp 0xab3f0
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq