// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %rbx
movq %rdi, %r14
movl %esi, 0x4(%rsp)
pushq $0x1
popq %rdx
callq 0x46ec
testq %rax, %rax
je 0x6093
movq %rax, %r12
leaq 0x68(%r14), %rdi
leaq 0x4(%rsp), %rsi
movq %rdi, 0x10(%rsp)
callq 0x875e
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x5, %rcx
jae 0x60a7
movb $0x1, %al
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, 0x60(%r14)
jb 0x615c
leaq 0x7990(%rip), %rsi      # 0xda49
leaq 0x18(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x2090
movl 0x4(%rsp), %esi
leaq 0x78(%rsp), %rdi
callq 0x87e9
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x8ac0
leaq 0x765b(%rip), %rsi      # 0xd74f
leaq 0x58(%rsp), %rdi
leaq 0x2(%rsp), %rdx
callq 0x2090
leaq 0x38(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x8ac0
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x8a74
leaq 0x38(%rsp), %rdi
callq 0x20b0
leaq 0x58(%rsp), %rdi
callq 0x20b0
leaq 0x98(%rsp), %rdi
callq 0x20b0
leaq 0x78(%rsp), %rdi
callq 0x20b0
leaq 0x18(%rsp), %rdi
callq 0x20b0
cmpq $0x3, 0x28(%rbx)
jb 0x61b0
movl 0x4(%rsp), %eax
cmpl %eax, 0x30(%rbx)
jne 0x61b0
movb $0x1, 0x38(%rbx)
cmpl $0x3, 0x60(%r14)
jb 0x6186
leaq 0x78d2(%rip), %rsi      # 0xda50
movq %rbx, %rdi
callq 0x8a74
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5a09
testb %al, %al
je 0x6315
cmpl $0x2, 0x60(%r14)
jbe 0x6093
leaq 0x78bb(%rip), %rsi      # 0xda66
jmp 0x633d
movl 0x60(%r12), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5adc
testb %al, %al
je 0x6093
leaq 0x4(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x875e
movq (%rax), %r12
movq 0x8(%rax), %rbp
leaq 0x78(%rsp), %r13
movq %r14, 0x8(%rsp)
cmpq %rbp, %r12
je 0x6093
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x875e
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x5, %rcx
jb 0x630c
movl (%r12), %esi
cmpq $0x3, 0x28(%rbx)
jb 0x621f
cmpl %esi, 0x30(%rbx)
je 0x622f
movq %rbx, %rdi
callq 0x8a48
testb %al, %al
jne 0x630c
cmpl $0x3, 0x60(%r14)
jb 0x62d8
leaq 0x18(%rsp), %rdi
leaq 0x7830(%rip), %rsi      # 0xda76
leaq 0x3(%rsp), %rdx
callq 0x2090
movl (%r12), %esi
movq %r13, %rdi
callq 0x87e9
leaq 0x98(%rsp), %r14
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x8ac0
leaq 0x58(%rsp), %r15
movq %r15, %rdi
leaq 0x74cc(%rip), %rsi      # 0xd74f
leaq 0x2(%rsp), %rdx
callq 0x2090
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8ac0
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x8a74
leaq 0x38(%rsp), %rdi
callq 0x20b0
leaq 0x58(%rsp), %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x20b0
movq %r13, %rdi
callq 0x20b0
leaq 0x18(%rsp), %rdi
callq 0x20b0
movl (%r12), %r14d
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8b54
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x6048
movq %r15, %rdi
callq 0x96fe
movq 0x8(%rsp), %r14
addq $0x4, %r12
jmp 0x61e8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5fd4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8b28
cmpl $0x2, 0x60(%r14)
jbe 0x6093
leaq 0x771d(%rip), %rsi      # 0xda5a
movq %rbx, %rdi
callq 0x8a74
jmp 0x6093
jmp 0x635b
jmp 0x636a
jmp 0x6379
jmp 0x638b
jmp 0x639a
jmp 0x6356
movq %rax, %rbx
jmp 0x63b9
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x20b0
jmp 0x636d
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20b0
jmp 0x637c
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x20b0
jmp 0x638e
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x20b0
jmp 0x639d
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x20b0
jmp 0x63b9
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x96fe
movq %rbx, %rdi
callq 0x2200
nop