// File: realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyDetector::BuildCycle(unsigned int, PolyCycle)
bool PolyDetector::BuildCycle(uint32_t id, PolyCycle cycle) // as value!
{
    //if (cycle.startIdx != id && cycle.idx.size() > 2)
    //    return true;
    
    //if (cycle.idx.size() >= 7)
    //    return true;
    
    auto l = findLine(id);
    if (!l)
        return true;
    
    if (_neighbors[id].size() < 2)
    {
        return true;
    }
    
    if (verbose > 2)
        cycle.print((std::string("[PROC:") + std::to_string(id) + std::string("]")).c_str());
    
    if (cycle.canBeClosed(*this, id))
    {
        cycle.isClosed = true;
        
        if (verbose > 2)
            cycle.print("[CLOSED] ");
        
        if (!similarCycle(_cycles, cycle))
        {
            if (cycle.accepted(*this))
            {
                _cycles.push_back(cycle);
                if (verbose > 2)
                    cycle.print("[ACCEPTED] ");
                //logoutf("nCycles:%u", uint32_t(_cycles.size()));
                //return false;
            }
            else
            {
                if (verbose > 2)
                    cycle.print("[NOT ACCEPTED] ");
            }
        }
        else
        {
            if (verbose > 2)
                cycle.print("[CYCLE_EXISTS] ");
        }
        
        return true;
    }
    
    if (!cycle.AddLineId(*this, l->id))
    {
        return true;
    }
    
#if 0 // disable entire process checking
#if 0
    if (l->processed + 1 == cycle.startIdx)
    {
        if (verbose > 2)
        {
            logoutf("line %s can't be added to cycle %s! processed: %u!", l->toString(*this).c_str(), cycle.toString().c_str(), l->processed - 1);
        }
        //printf("procHit for %u!\n", l->id);
        return true;
    }
#else
    if (cycleProcessed(cycle))
    {
        if (verbose > 2)
            cycle.print("[PROCESSED!] ");
        return true;
    }
    processed.push_back(cycle.idx);
#endif
#endif

    for (auto &nid : _neighbors[id])
    {
        if (_neighbors[nid].size() < 2) continue;
        if (cycle.canBeClosed(*this, nid) || !cycle.contains(nid))
        {
            if (verbose > 2)
                cycle.print((std::string("[NEIGN:") + std::to_string(nid) + std::string("]")).c_str());
            if (!BuildCycle(nid, cycle))
            {
                return false;
                //break;
            }
        }
    }
    
    return true;
}

// Assembly:
subq $0x248, %rsp            # imm = 0x248
movq %rdx, 0x40(%rsp)
movq %rdi, 0x238(%rsp)
movl %esi, 0x234(%rsp)
movq %rdx, 0x228(%rsp)
movq 0x238(%rsp), %rdi
movq %rdi, 0x48(%rsp)
movl 0x234(%rsp), %esi
movl $0x1, %edx
callq 0x7240
movq %rax, 0x220(%rsp)
cmpq $0x0, 0x220(%rsp)
jne 0xad11
movb $0x1, 0x247(%rsp)
jmp 0xb414
movq 0x48(%rsp), %rdi
addq $0x68, %rdi
leaq 0x234(%rsp), %rsi
callq 0x12dd0
movq %rax, %rdi
callq 0x12b80
cmpq $0x2, %rax
jae 0xad42
movb $0x1, 0x247(%rsp)
jmp 0xb414
movq 0x48(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jbe 0xaf63
leaq 0x1bf(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x2290
movq 0x38(%rsp), %rdx
leaq 0x1bd10(%rip), %rsi     # 0x26a7f
leaq 0x1c0(%rsp), %rdi
callq 0x2210
jmp 0xad7e
movl 0x234(%rsp), %esi
leaq 0x188(%rsp), %rdi
callq 0x132c0
jmp 0xad94
leaq 0x1e0(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
leaq 0x188(%rsp), %rdx
callq 0x145b0
jmp 0xadb3
leaq 0x167(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x2290
movq 0x30(%rsp), %rdx
leaq 0x1b962(%rip), %rsi     # 0x26733
leaq 0x168(%rsp), %rdi
callq 0x2210
jmp 0xade0
leaq 0x200(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x168(%rsp), %rdx
callq 0x145b0
jmp 0xadff
leaq 0x200(%rsp), %rdi
callq 0x20b0
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x14500
jmp 0xae1b
leaq 0x200(%rsp), %rdi
callq 0x2100
leaq 0x168(%rsp), %rdi
callq 0x2100
leaq 0x167(%rsp), %rdi
callq 0x21c0
leaq 0x1e0(%rsp), %rdi
callq 0x2100
leaq 0x188(%rsp), %rdi
callq 0x2100
leaq 0x1c0(%rsp), %rdi
callq 0x2100
leaq 0x1bf(%rsp), %rdi
callq 0x21c0
jmp 0xaf63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xaf51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xaf44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xaf37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xaf1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xaf10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x2100
leaq 0x168(%rsp), %rdi
callq 0x2100
leaq 0x167(%rsp), %rdi
callq 0x21c0
leaq 0x1e0(%rsp), %rdi
callq 0x2100
leaq 0x188(%rsp), %rdi
callq 0x2100
leaq 0x1c0(%rsp), %rdi
callq 0x2100
leaq 0x1bf(%rsp), %rdi
callq 0x21c0
jmp 0xb425
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
movl 0x234(%rsp), %edx
callq 0xb440
testb $0x1, %al
jne 0xaf82
jmp 0xb047
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
movb $0x1, 0x38(%rcx)
cmpl $0x2, 0x60(%rax)
jbe 0xafa7
movq 0x40(%rsp), %rdi
leaq 0x1bae4(%rip), %rsi     # 0x26a86
callq 0x14500
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x9e30
testb $0x1, %al
jne 0xb01c
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0xab20
testb $0x1, %al
jne 0xafcf
jmp 0xaffc
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x146a0
movq 0x48(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jbe 0xaffa
movq 0x40(%rsp), %rdi
leaq 0x1ba9b(%rip), %rsi     # 0x26a90
callq 0x14500
jmp 0xb01a
movq 0x48(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jbe 0xb018
movq 0x40(%rsp), %rdi
leaq 0x1ba89(%rip), %rsi     # 0x26a9c
callq 0x14500
jmp 0xb01a
jmp 0xb03a
movq 0x48(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jbe 0xb038
movq 0x40(%rsp), %rdi
leaq 0x1ba79(%rip), %rsi     # 0x26aac
callq 0x14500
jmp 0xb03a
movb $0x1, 0x247(%rsp)
jmp 0xb414
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
movq 0x220(%rsp), %rax
movl 0x60(%rax), %edx
callq 0xa0d0
testb $0x1, %al
jne 0xb072
movb $0x1, 0x247(%rsp)
jmp 0xb414
movq 0x48(%rsp), %rdi
addq $0x68, %rdi
leaq 0x234(%rsp), %rsi
callq 0x12dd0
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rdi
callq 0x128b0
movq %rax, 0x150(%rsp)
movq 0x158(%rsp), %rdi
callq 0x128e0
movq %rax, 0x148(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x134e0
testb $0x1, %al
jne 0xb0d8
jmp 0xb40c
leaq 0x150(%rsp), %rdi
callq 0x13520
movq 0x48(%rsp), %rdi
movq %rax, 0x140(%rsp)
addq $0x68, %rdi
movq 0x140(%rsp), %rsi
callq 0x12dd0
movq %rax, %rdi
callq 0x12b80
cmpq $0x2, %rax
jae 0xb116
jmp 0xb3fa
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
movq 0x140(%rsp), %rax
movl (%rax), %edx
callq 0xb440
testb $0x1, %al
jne 0xb14f
movq 0x40(%rsp), %rdi
movq 0x140(%rsp), %rax
movl (%rax), %esi
callq 0x14490
testb $0x1, %al
jne 0xb3f8
movq 0x48(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jbe 0xb373
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x2290
movq 0x28(%rsp), %rdx
leaq 0x1b940(%rip), %rsi     # 0x26abc
leaq 0xe0(%rsp), %rdi
callq 0x2210
jmp 0xb18b
movq 0x140(%rsp), %rax
movl (%rax), %esi
leaq 0xb8(%rsp), %rdi
callq 0x132c0
jmp 0xb1a4
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x145b0
jmp 0xb1c3
leaq 0x97(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x2290
movq 0x20(%rsp), %rdx
leaq 0x1b552(%rip), %rsi     # 0x26733
leaq 0x98(%rsp), %rdi
callq 0x2210
jmp 0xb1f0
leaq 0x120(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x145b0
jmp 0xb20f
leaq 0x120(%rsp), %rdi
callq 0x20b0
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x14500
jmp 0xb22b
leaq 0x120(%rsp), %rdi
callq 0x2100
leaq 0x98(%rsp), %rdi
callq 0x2100
leaq 0x97(%rsp), %rdi
callq 0x21c0
leaq 0x100(%rsp), %rdi
callq 0x2100
leaq 0xb8(%rsp), %rdi
callq 0x2100
leaq 0xe0(%rsp), %rdi
callq 0x2100
leaq 0xdf(%rsp), %rdi
callq 0x21c0
jmp 0xb373
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xb361
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xb354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xb347
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xb32d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
jmp 0xb320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x2100
leaq 0x98(%rsp), %rdi
callq 0x2100
leaq 0x97(%rsp), %rdi
callq 0x21c0
leaq 0x100(%rsp), %rdi
callq 0x2100
leaq 0xb8(%rsp), %rdi
callq 0x2100
leaq 0xe0(%rsp), %rdi
callq 0x2100
leaq 0xdf(%rsp), %rdi
callq 0x21c0
jmp 0xb425
movq 0x40(%rsp), %rsi
movq 0x140(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
leaq 0x50(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x14710
movq 0x48(%rsp), %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
callq 0xacb0
movb %al, 0x1f(%rsp)
jmp 0xb3ae
movb 0x1f(%rsp), %al
xorb $-0x1, %al
movb %al, 0xb(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x14750
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0xb3cc
jmp 0xb3f6
movb $0x0, 0x247(%rsp)
jmp 0xb414
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x14750
jmp 0xb425
jmp 0xb3f8
jmp 0xb3fa
leaq 0x150(%rsp), %rdi
callq 0x13530
jmp 0xb0ba
movb $0x1, 0x247(%rsp)
movb 0x247(%rsp), %al
andb $0x1, %al
addq $0x248, %rsp            # imm = 0x248
retq
movq 0x1b0(%rsp), %rdi
callq 0x2280
nopw %cs:(%rax,%rax)