// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
callq 0x1412a0
movq %rax, -0x68(%rbp)
movl -0x18(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %esi
shll %esi
andl $0x1, %esi
addl $0x1, %esi
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %esi
shll %esi
andl $0x1, %esi
addl $0x1, %esi
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x141380
movq -0x68(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x141380
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpq 0x10(%rbp), %rax
jae 0x148957
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1488c2
jmp 0x148949
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x1488d9
jmp 0x148949
movl -0x48(%rbp), %eax
shll %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x2, -0x44(%rbp)
jae 0x148947
movl -0x48(%rbp), %eax
orl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x48(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
jne 0x14893a
movl -0x48(%rbp), %esi
shll %esi
andl $0x1, %esi
addl $0x1, %esi
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rdi
movl -0x48(%rbp), %esi
xorl $0x1, %esi
callq 0x141380
jmp 0x14893c
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1488e8
jmp 0x148949
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x14888c
jmp 0x148959
movq -0x68(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x148b46
movq -0x68(%rbp), %rdi
callq 0x141410
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x48(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x48(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x148b41
movq -0x58(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1489df
jmp 0x148b33
movq -0x58(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x148a15
jmp 0x148b33
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl -0x4c(%rbp), %ecx
shll %ecx
andl $0x1, %ecx
addl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x148a3b
jmp 0x148b33
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x4c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x148af7
movq -0x60(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x148aa4
jmp 0x148aec
movq -0x20(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x40(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x60(%rbp), %rcx
movl -0x40(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shll %ecx
andl $0x1, %ecx
addl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x148ae3
jmp 0x148aec
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x148a81
cmpl $0x0, -0x3c(%rbp)
jne 0x148b31
movq -0x68(%rbp), %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
callq 0x141380
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
shll %esi
andl $0x1, %esi
addl $0x1, %esi
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
xorl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x148b33
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1489b5
jmp 0x148959
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpq 0x10(%rbp), %rax
jae 0x148bd5
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x148b7c
jmp 0x148bc7
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x148b93
jmp 0x148bc7
movl -0x48(%rbp), %eax
shll %eax
movl %eax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl -0x48(%rbp), %ecx
shll %ecx
andl $0x1, %ecx
addl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x148bc5
movl $0x1, -0x4(%rbp)
jmp 0x148bdc
jmp 0x148bc7
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x148b4d
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)