// File: 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
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
cmpl $-0x1, -0x8(%rbp)
je 0x14068a
movl -0x8(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x140688
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x140623
jmp 0x14067a
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x140664
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movq -0x18(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x140657
jmp 0x140664
jmp 0x140659
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x14062a
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x140678
movl $0x0, -0x4(%rbp)
jmp 0x1409a5
jmp 0x14067a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1405fc
jmp 0x14068a
cmpl $-0x1, -0xc(%rbp)
je 0x14076a
movl -0xc(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x140768
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x140703
jmp 0x14075a
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x140744
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movq -0x18(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x140737
jmp 0x140744
jmp 0x140739
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x14070a
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x140758
movl $0x0, -0x4(%rbp)
jmp 0x1409a5
jmp 0x14075a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1406dc
jmp 0x14076a
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x14099e
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x140889
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1407f3
jmp 0x14087b
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x140834
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movq -0x18(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x140827
jmp 0x140834
jmp 0x140829
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1407fa
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x140879
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x8(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x140879
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0xc(%rbp), %eax
je 0x140879
movl $0x0, -0x4(%rbp)
jmp 0x1409a5
jmp 0x14087b
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1407c9
movl -0x2c(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x14098e
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1408fb
jmp 0x140980
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x14093c
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movq -0x18(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x14092f
jmp 0x14093c
jmp 0x140931
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x140902
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x14097e
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x8(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x14097e
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0xc(%rbp), %eax
je 0x14097e
movl $0x0, -0x4(%rbp)
jmp 0x1409a5
jmp 0x140980
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1408d1
jmp 0x140990
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x140771
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)