// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detec_circles(asg_t*, unsigned int, unsigned int, unsigned char*, ma_ug_t*, unsigned long*, unsigned long)
int detec_circles(asg_t *nsg, uint32_t vSrc, uint32_t vDest,  
uint8_t* visit, ma_ug_t *ug, uint64_t* nodes, uint64_t nodes_n)
{
    uint32_t nv, nw, knw, i, k, v, w;
    asg_arc_t *av, *aw;

    memset(visit, 0, nsg->n_seq);
    kdq_t(uint32_t) *buf;
    buf = kdq_init(uint32_t);

    vDest = vDest^1;

    Set_vis(visit, vSrc, 1);
    Set_vis(visit, vDest, 1);
    kdq_push(uint32_t, buf, vSrc);
    kdq_push(uint32_t, buf, vDest);

    for (i = 0; i < nodes_n; i++)
    {
        v = (uint32_t)nodes[i];
        if(nsg->seq[v].del) continue;
        if(nsg->seq[v].c == ALTER_LABLE) continue;
        v = v<<1;

        for (k = 0; k < 2; k++)
        {
            v = v|k;
            if(get_real_length(nsg, v, NULL)==0)
            {
                Set_vis(visit, v, 1);
                kdq_push(uint32_t, buf, v^1);
            }
        }
    }



    while (kdq_size(buf) != 0)
    {
        v = *(kdq_pop(uint32_t, buf));
        ///if(Get_vis(visit, v, 1) == 0) fprintf(stderr, "ERROR\n");

        nv = asg_arc_n(nsg, v);
        av = asg_arc_a(nsg, v);
        for(k = 0; k < nv; k++)
        {
            if(av[k].del) continue;
            w = av[k].v^1;
            if(nsg->seq[w>>1].del) continue;
            if(Get_vis(visit, w, 1) != 0) continue;

            ///check indegree
            nw = asg_arc_n(nsg, w);
            aw = asg_arc_a(nsg, w);
            for (i = 0, knw = 0; i < nw; i++)
            {
                if(aw[i].del) continue;
                if(Get_vis(visit, aw[i].v, 1) != 0) continue;
                knw++;
            }

            if(knw == 0)
            {
                kdq_push(uint32_t, buf, w^1);
                Set_vis(visit, (w^1), 1);
            }
        }
    }

    for (i = 0; i < nodes_n; i++)
    {
        v = (uint32_t)nodes[i];
        if(nsg->seq[v].del) continue;
        if(nsg->seq[v].c == ALTER_LABLE) continue;
        v = v<<1;
        if(Get_vis(visit, v, 1) == 0) return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x30(%rsp)
movq %rcx, %r13
movl %edx, %ebp
movl %esi, %ebx
movabsq $0x800000000000000, %r14 # imm = 0x800000000000000
movq %rdi, (%rsp)
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movq %rcx, %rdi
xorl %esi, %esi
callq 0x20e0
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r12
movq %r14, (%rax)
movq $0x3, 0x10(%rax)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x18(%r12)
movl %ebp, %edx
xorl $0x1, %edx
movl %ebx, %ecx
shrl %ecx
orb $0x1, (%r13,%rcx)
shrl %ebp
orb $0x1, (%r13,%rbp)
movq %rax, %rbp
movl %ebx, (%rax)
movq $0x2, 0x8(%r12)
movl %edx, 0x4(%rax)
cmpq $0x0, 0x70(%rsp)
movq %r13, 0x28(%rsp)
je 0xef60d
movq %r12, %r8
movl $0x2, %r12d
movl $0x3, %edx
movq (%rsp), %r10
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movabsq $0x800000000000000, %r9 # imm = 0x800000000000000
movq %r8, 0x8(%rsp)
movq 0x30(%rsp), %rax
movq (%rax,%r15,8), %rax
movl %eax, %ecx
movq 0x20(%r10), %rsi
cmpl $0x0, (%rsi,%rcx,8)
movq %r15, 0x18(%rsp)
js 0xef5f8
cmpb $0x1, 0x4(%rsi,%rcx,8)
je 0xef5f8
addl %eax, %eax
xorl %ecx, %ecx
movb $0x1, %bl
movl %ecx, %r15d
orl %eax, %r15d
movq 0x28(%r10), %rcx
movq (%rcx,%r15,8), %rcx
movq %rcx, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rsi
je 0xef48e
movq %r9, %r14
movq 0x8(%r10), %rdi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdi,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rcx,%rdi), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xef466
testl %r8d, %r8d
movq %r14, %r9
movq 0x8(%rsp), %r8
jne 0xef5e2
shrl %eax
orb $0x1, (%r13,%rax)
movq %r9, %rax
shrq $0x3a, %rax
movl $0x1, %esi
movl %eax, %ecx
shlq %cl, %rsi
cmpq %rsi, %r12
jne 0xef5c5
movq %rbp, %rdi
leal 0x1(%rax), %ebp
movl $0x1, %r14d
movl %ebp, %ecx
shlq %cl, %r14
cmpq %r12, %r14
jae 0xef500
movq $-0x1, %rbp
incq %rbp
movq %r12, %rsi
movl %ebp, %ecx
shrq %cl, %rsi
cmpq $0x3f, %rbp
ja 0xef4e3
testq %rsi, %rsi
jne 0xef4cd
cmpq %rbp, %rax
jne 0xef4f0
movq %rdi, %rbp
jmp 0xef5c5
movl $0x1, %r14d
movl %ebp, %ecx
shlq %cl, %r14
cmpq %rax, %rbp
jbe 0xef52b
movq %r9, %r13
movl $0x4, %esi
movl %ebp, %ecx
shlq %cl, %rsi
callq 0x2370
movq %rax, %rdi
movq 0x8(%rsp), %r8
movq %rax, 0x18(%r8)
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movq %r13, %r9
movq %r9, %r13
andq %r11, %r13
leaq (%r12,%r13), %rdx
cmpq %r12, %rdx
jbe 0xef577
movq %r12, %rdx
subq %r13, %rdx
movq %r14, %rax
subq %rdx, %rax
movq %rdi, %rcx
leaq (%rdi,%rax,4), %rdi
leaq (%rcx,%r13,4), %rsi
shlq $0x2, %rdx
movq %r9, %r13
callq 0x2360
movq 0x8(%rsp), %r8
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
subq %r12, %r13
addq %r14, %r13
andq %r11, %r13
jmp 0xef598
subq %r14, %rdx
jbe 0xef598
leaq (%rdi,%r14,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movq 0x8(%rsp), %r8
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r10
movq %rbp, %r9
shlq $0x3a, %r9
orq %r13, %r9
movq $-0x1, %rdx
movl %ebp, %ecx
shlq %cl, %rdx
movq %r9, (%r8)
notq %rdx
movq %rdx, 0x10(%r8)
movq 0x18(%r8), %rbp
movq 0x28(%rsp), %r13
movl %r15d, %eax
xorl $0x1, %eax
movq %r9, %rcx
andq %r11, %rcx
addq %r12, %rcx
incq %r12
movq %r12, 0x8(%r8)
andq %rdx, %rcx
movl %eax, (%rbp,%rcx,4)
movl $0x1, %ecx
movl %r15d, %eax
testb $0x1, %bl
movl $0x0, %ebx
jne 0xef427
movq 0x18(%rsp), %r15
incl %r15d
cmpq 0x70(%rsp), %r15
jb 0xef3f8
jmp 0xef632
movl $0x3, %edx
movl $0x2, %r12d
movq (%rsp), %r10
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movabsq $0x800000000000000, %r9 # imm = 0x800000000000000
jmp 0xef63b
testq %r12, %r12
je 0xef8b3
movq %r9, %rax
andq %r11, %rax
addq %r12, %rax
decq %rax
decq %r12
andq %rdx, %rax
movl (%rbp,%rax,4), %eax
movq 0x28(%r10), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xef632
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x3, %rdi
addq 0x8(%r10), %rdi
movl %eax, %ecx
xorl %ebx, %ebx
movq %rdi, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
leaq (%rbx,%rbx,2), %rax
cmpl $0x0, 0xc(%rdi,%rax,8)
js 0xef8a2
leaq (%rdi,%rax,8), %rax
movl 0x8(%rax), %r14d
movq 0x20(%r10), %rax
movl %r14d, %r15d
shrl %r15d
cmpl $0x0, (%rax,%r15,8)
js 0xef8a2
testb $0x1, (%r13,%r15)
jne 0xef8a2
movq %r14, %rax
xorq $0x1, %rax
movq 0x28(%r10), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xef722
movq 0x8(%r10), %rcx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %edi
leaq (%rsi,%rsi,2), %rax
leaq (%rcx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rcx
xorl %esi, %esi
xorl %edi, %edi
cmpl $0x0, (%rax,%rsi)
js 0xef70c
movl -0x4(%rax,%rsi), %r8d
shrl %r8d
movzbl (%r13,%r8), %r8d
notl %r8d
andl $0x1, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xef6ee
testl %edi, %edi
movq 0x18(%rsp), %rdi
jne 0xef89d
movq %r9, %rax
shrq $0x3a, %rax
movl $0x1, %esi
movl %eax, %ecx
shlq %cl, %rsi
cmpq %rsi, %r12
jne 0xef883
leal 0x1(%rax), %r13d
movl $0x1, %esi
movl %r13d, %ecx
shlq %cl, %rsi
cmpq %r12, %rsi
jae 0xef787
movq $-0x1, %r13
incq %r13
movq %r12, %rsi
movl %r13d, %ecx
shrq %cl, %rsi
cmpq $0x3f, %r13
ja 0xef76e
testq %rsi, %rsi
jne 0xef757
cmpq %r13, %rax
je 0xef87e
movl $0x1, %esi
movl %r13d, %ecx
shlq %cl, %rsi
cmpq %rax, %r13
jbe 0xef7c0
movq %rsi, 0x10(%rsp)
movq %r9, 0x20(%rsp)
movl $0x4, %esi
movl %r13d, %ecx
shlq %cl, %rsi
movq %rbp, %rdi
callq 0x2370
movq %rax, %rbp
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r9, %rcx
andq %r11, %rcx
leaq (%rcx,%r12), %rdx
cmpq %r12, %rdx
jbe 0xef82b
movq %r12, %rdx
subq %rcx, %rdx
movq %rsi, %rax
subq %rdx, %rax
leaq (,%rax,4), %rdi
addq %rbp, %rdi
movq %rsi, 0x10(%rsp)
leaq (,%rcx,4), %rsi
addq %rbp, %rsi
shlq $0x2, %rdx
movq %rbp, 0x20(%rsp)
movq %r9, %rbp
callq 0x2360
movq 0x18(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
subq %r12, %rbp
addq 0x10(%rsp), %rbp
andq %r11, %rbp
movq %rbp, %rcx
movq 0x20(%rsp), %rbp
jmp 0xef860
subq %rsi, %rdx
jbe 0xef860
leaq (,%rsi,4), %rsi
addq %rbp, %rsi
shlq $0x2, %rdx
movq %rbp, %rdi
movq %rcx, 0x10(%rsp)
callq 0x2360
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r10
movq %r13, %r9
shlq $0x3a, %r9
orq %rcx, %r9
movq $-0x1, %rdx
movl %r13d, %ecx
shlq %cl, %rdx
notq %rdx
movq 0x28(%rsp), %r13
movq %r9, %rax
andq %r11, %rax
addq %r12, %rax
incq %r12
andq %rdx, %rax
movl %r14d, (%rbp,%rax,4)
orb $0x1, (%r13,%r15)
movq 0x8(%rsp), %rcx
incq %rbx
cmpq %rcx, %rbx
jne 0xef67e
jmp 0xef632
cmpq $0x0, 0x70(%rsp)
je 0xef8f4
movq 0x20(%r10), %rax
movl $0x1, %ecx
xorl %edx, %edx
movq 0x30(%rsp), %rsi
movl (%rsi,%rdx,8), %edx
cmpl $0x0, (%rax,%rdx,8)
js 0xef8e9
cmpb $0x1, 0x4(%rax,%rdx,8)
je 0xef8e9
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
testb $0x1, (%r13,%rdx)
je 0xef905
movl %ecx, %edx
incl %ecx
cmpq 0x70(%rsp), %rdx
jb 0xef8cb
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0xef8f6