// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/cycle.cc
// Function: compute_4cycle(DIJKSTRA_NETWORK*, std::vector<CYCLE, std::allocator<CYCLE>>*, bool, int)
bool compute_4cycle(DIJKSTRA_NETWORK* dnet, vector<CYCLE> *cycles,
                    bool weight_flag, int weight_range)
{
    /* Algorithm (Shortest cycle):
     * 1) For each Dijkstra node, identifiy all the edges from the node.
     * 2) For each edge from the node remove the edge and compute the
     * shortest path between the pair of nodes in the removed edge
     * using the Dijkstra's algorithm.
     */
    // First clear the active flag for each Dijkstra node
    // Set the max_radius of each connection to 1. Used in enabling or
    // disabling a connection without deleting the connection
    // Adds an additional check
    DnIt it = dnet->nodes.begin();
    int count = 0;
    for (; it != dnet->nodes.end(); ++it, ++count) {
        it->active = false;
        CnIt cit = it->connections.begin();
        for (; cit != it->connections.end(); ++cit) cit->max_radius = 1;
    }
    cout << "Length of vornet: " << count << endl;

    it = dnet->nodes.begin();
    for (; it != dnet->nodes.end(); ++it) {
        //cout << "x: " << it->x << " y: " << it->y << " z: " <<  it->z << endl;
        ;
    }
    
    for (int i = 0; i < dnet->nodes.size(); ++i){
        DIJKSTRA_NODE org_node = dnet->nodes.at(i);
        if (i == 0) cout << "org_node: "<< org_node.x << " " << org_node.y << " " << org_node.z << endl;
        CnIt it = org_node.connections.begin();
        int conn_ind = 0;
        for (; it != org_node.connections.end(); ++it, ++conn_ind){
            int path_length = 0;
            int org_node_id = it->from;
            int end_node_id = it->to;
            if (i == 0) cout << "end_node_id: " << end_node_id << endl;
            DIJKSTRA_NODE end_node = dnet->nodes.at(end_node_id);
            
            if (end_node.active) continue;

            CnIt oit = it + 1;       //Check the other connections of begin node
            int oconn_ind=conn_ind + 1;
            for (; oit != org_node.connections.end(); ++oit, ++oconn_ind) {
                int inter_node_id = oit->to;
                if (inter_node_id==org_node_id || inter_node_id==end_node_id) continue;
		if (i==0) cout << "    inter_node_id: " << inter_node_id << endl;
                DIJKSTRA_NODE inter_node = dnet->nodes.at(inter_node_id);
                if (inter_node.active) continue;
                for (CnIt iit = inter_node.connections.begin(); iit != inter_node.connections.end(); ++iit) 
                    if (i==0) cout << "        to: "<< iit->to << endl;
                CnIt eit = end_node.connections.begin();
                int econn_ind=0;
                for (; eit != end_node.connections.end(); ++eit, ++econn_ind) {
                    int final_node_id = eit->to;
                    if (final_node_id==end_node_id || final_node_id==org_node_id) continue;
                    if (i==0) cout << "    final_node_id: " << final_node_id << endl;
                    DIJKSTRA_NODE final_node = dnet->nodes.at(final_node_id);
                    if (final_node.active) continue;

                    CnIt iit = inter_node.connections.begin();
                    for (; iit != inter_node.connections.end(); ++iit) {
                        if (iit->to == final_node_id){  //Cycle found
                            CYCLE new_cycle;
                            new_cycle.length=4;
                            new_cycle.nodes.push_back(org_node);
                            new_cycle.nodes.push_back(end_node);
                            new_cycle.nodes.push_back(inter_node);
                            new_cycle.nodes.push_back(dnet->nodes.at(final_node_id));
                            cycles->push_back(new_cycle);
                        }
                    }
                }
            }
        }
        org_node.active = true;
    }
    cout << "No. of cycles: " << cycles->size() << endl;
    if (!cycles->size()) return false;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, 0x28(%rsp)
movq (%rdi), %rcx
movq %rdi, (%rsp)
movq 0x8(%rdi), %rsi
xorl %r15d, %r15d
cmpq %rsi, %rcx
je 0x1087a1
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
movdqa 0x48c4b(%rip), %xmm0    # 0x151320
movdqa 0x48c53(%rip), %xmm1    # 0x151330
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
pcmpeqd %xmm2, %xmm2
movb $0x0, 0x40(%rcx)
movq 0x20(%rcx), %r9
movq 0x28(%rcx), %rax
cmpq %rax, %r9
je 0x108791
subq %r9, %rax
addq $-0x28, %rax
mulq %rdi
movq %rdx, %xmm3
shrq $0x5, %rdx
addq $0x2, %rdx
andq $-0x2, %rdx
pshufd $0x44, %xmm3, %xmm3     # xmm3 = xmm3[0,1,0,1]
psrlq $0x5, %xmm3
addq $0x38, %r9
pxor %xmm1, %xmm3
xorl %eax, %eax
movq %rax, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm0, %xmm4
pxor %xmm1, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm3, %xmm5
pcmpeqd %xmm3, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %r10d
notl %r10d
testb $0x1, %r10b
je 0x108771
movq %r8, -0x28(%r9)
pxor %xmm2, %xmm4
pextrw $0x4, %xmm4, %r10d
testb $0x1, %r10b
je 0x108784
movq %r8, (%r9)
addq $0x2, %rax
addq $0x50, %r9
cmpq %rax, %rdx
jne 0x10872f
addq $0x48, %rcx
incl %r15d
cmpq %rsi, %rcx
jne 0x1086eb
movq 0x8c818(%rip), %r12     # 0x194fc0
leaq 0x4eaf0(%rip), %rsi     # 0x15729f
movl $0x12, %edx
movq %r12, %rdi
callq 0x44e0
movq %r12, %rdi
movl %r15d, %esi
callq 0x4750
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movq (%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x108e96
leaq 0x100(%rsp), %r13
leaq 0x180(%rsp), %r15
xorl %r14d, %r14d
leaq (%r14,%r14,8), %rcx
leaq (%rax,%rcx,8), %r12
addq $0x20, %r12
movdqu -0x20(%r12), %xmm0
movdqu -0x10(%r12), %xmm1
movdqa %xmm1, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x37e9e
movb 0x20(%r12), %al
movb %al, 0x20(%rbx)
movq 0x18(%r12), %rax
movq %rax, 0x18(%rbx)
testq %r14, %r14
jne 0x108903
movl $0xa, %edx
movq 0x8c74f(%rip), %rdi     # 0x194fc0
leaq 0x4ea3a(%rip), %rsi     # 0x1572b2
callq 0x44e0
movq 0x48(%rsp), %xmm0
movq 0x8c736(%rip), %rdi     # 0x194fc0
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4cd35(%rip), %rsi     # 0x1555d6
callq 0x44e0
movq 0x50(%rsp), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4cd10(%rip), %rsi     # 0x1555d6
callq 0x44e0
movq 0x58(%rsp), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movq 0x60(%rsp), %rbp
cmpq 0x68(%rsp), %rbp
je 0x108e4d
movq %r14, 0x10(%rsp)
movl (%rbp), %eax
movl %eax, 0xc(%rsp)
movslq 0x4(%rbp), %rbx
testq %r14, %r14
jne 0x108978
movl $0xd, %edx
movq 0x8c68c(%rip), %rdi     # 0x194fc0
leaq 0x4e982(%rip), %rsi     # 0x1572bd
callq 0x44e0
movq 0x8c679(%rip), %rdi     # 0x194fc0
movl %ebx, %esi
callq 0x4750
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movq (%rsp), %rax
movq %rbx, %rsi
movq (%rax), %rbx
movq 0x8(%rax), %rdx
subq %rbx, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x108f3c
movq %rsi, 0x18(%rsp)
leaq (%rsi,%rsi,8), %r14
leaq (%rbx,%r14,8), %rsi
addq $0x20, %rsi
movdqu -0x20(%rsi), %xmm0
movdqu -0x10(%rsi), %xmm1
movdqa %xmm1, 0xf0(%rsp)
movdqa %xmm0, 0xe0(%rsp)
movq %r13, %rdi
callq 0x37e9e
leaq (%rbx,%r14,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r13)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r13)
leaq 0x28(%rbp), %rdx
movq 0x68(%rsp), %rax
cmpb $0x0, 0x120(%rsp)
movq %rdx, 0x30(%rsp)
jne 0x108e08
movq %rdx, %rcx
cmpq %rax, %rdx
leaq 0xb0(%rsp), %r13
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
je 0x108e0d
movl 0x2c(%rbp), %ebp
movq %rcx, 0x38(%rsp)
cmpl 0xc(%rsp), %ebp
je 0x108df4
cmpl %ebx, %ebp
je 0x108df4
testq %r14, %r14
jne 0x108a95
movl $0x13, %edx
movq 0x8c56f(%rip), %rdi     # 0x194fc0
leaq 0x4e873(%rip), %rsi     # 0x1572cb
callq 0x44e0
movq 0x8c55c(%rip), %rdi     # 0x194fc0
movl %ebp, %esi
callq 0x4750
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movslq %ebp, %rsi
movq (%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rdx
subq %rbx, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x108f2e
leaq (%rsi,%rsi,8), %r14
leaq (%rbx,%r14,8), %rsi
addq $0x20, %rsi
movdqu -0x20(%rsi), %xmm0
movdqu -0x10(%rsi), %xmm1
movdqa %xmm1, 0xa0(%rsp)
movdqa %xmm0, 0x90(%rsp)
movq %r13, %rdi
callq 0x37e9e
leaq (%rbx,%r14,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r13)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r13)
cmpb $0x0, 0xd0(%rsp)
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
jne 0x108dca
movq 0xb0(%rsp), %rbx
movq 0xb8(%rsp), %rax
cmpq %rax, %rbx
movq 0x8c48a(%rip), %r13     # 0x194fc0
je 0x108b97
testq %r14, %r14
jne 0x108b8e
movl $0xc, %edx
movq %r13, %rdi
leaq 0x4e793(%rip), %rsi     # 0x1572df
callq 0x44e0
movl 0x4(%rbx), %esi
movq %r13, %rdi
callq 0x4750
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movq 0xb8(%rsp), %rax
addq $0x28, %rbx
cmpq %rax, %rbx
jne 0x108b38
movq 0x100(%rsp), %r13
movq 0x108(%rsp), %rax
cmpq %rax, %r13
movq 0x18(%rsp), %rbx
je 0x108dca
movl 0x4(%r13), %r12d
cmpl %ebx, %r12d
je 0x108ce9
cmpl 0xc(%rsp), %r12d
je 0x108ce9
testq %r14, %r14
jne 0x108c23
movl $0x13, %edx
movq 0x8c3e2(%rip), %rdi     # 0x194fc0
leaq 0x4e707(%rip), %rsi     # 0x1572ec
callq 0x44e0
movq 0x8c3cf(%rip), %rdi     # 0x194fc0
movl %r12d, %esi
callq 0x4750
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %rbp, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movslq %r12d, %rsi
movq (%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %rdx
subq %r14, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x108f20
movl %r12d, 0x24(%rsp)
movq %r13, %r12
movq %r15, %r13
movq %rsi, %rbp
leaq (%rsi,%rsi,8), %rbx
leaq 0x20(%r14,%rbx,8), %rsi
movdqu -0x20(%rsi), %xmm0
movdqu -0x10(%rsi), %xmm1
movdqa %xmm1, 0x140(%rsp)
movdqa %xmm0, 0x130(%rsp)
leaq 0x150(%rsp), %r15
movq %r15, %rdi
callq 0x37e9e
leaq (%r14,%rbx,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r15)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r15)
cmpb $0x0, 0x170(%rsp)
movq %r13, %r15
movq %r12, %r13
movl 0x24(%rsp), %r12d
je 0x108cfb
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x108cd7
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x108(%rsp), %rax
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
addq $0x28, %r13
cmpq %rax, %r13
jne 0x108bb5
jmp 0x108dca
movq 0xb0(%rsp), %r14
movq 0xb8(%rsp), %rax
cmpq %rax, %r14
je 0x108cba
cmpl %r12d, 0x4(%r14)
jne 0x108dc1
pxor %xmm0, %xmm0
movdqu %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movabsq $0x4010000000000000, %rax # imm = 0x4010000000000000
movq %rax, 0x178(%rsp)
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0x50ea0
movq %r15, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x50ea0
movq %r15, %rdi
leaq 0x90(%rsp), %rsi
callq 0x50ea0
movq (%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rdx
cmpq %rbp, %rdx
jbe 0x108f0f
leaq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x50ea0
movq 0x28(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x109318
movq %r15, %rdi
callq 0xf10e
movq 0xb8(%rsp), %rax
addq $0x28, %r14
jmp 0x108d0b
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x108de7
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x68(%rsp), %rax
leaq 0xb0(%rsp), %r13
movq 0x38(%rsp), %rbp
leaq 0x28(%rbp), %rcx
cmpq %rax, %rcx
jne 0x108a26
jmp 0x108e0d
movq 0x10(%rsp), %r14
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x108e2f
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x68(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, %rbp
cmpq %rax, %rcx
leaq 0x100(%rsp), %r13
jne 0x108918
movq 0x60(%rsp), %rbp
movb $0x1, 0x80(%rsp)
testq %rbp, %rbp
je 0x108e6a
movq 0x70(%rsp), %rsi
subq %rbp, %rsi
movq %rbp, %rdi
callq 0x4470
incq %r14
movq (%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
imulq %rdx, %rcx
cmpq %r14, %rcx
ja 0x108815
movq 0x8c123(%rip), %r14     # 0x194fc0
leaq 0x4e45c(%rip), %rsi     # 0x157300
movl $0xf, %edx
movq %r14, %rdi
callq 0x44e0
movq 0x28(%rsp), %rbx
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x5, %rsi
movq %r14, %rdi
callq 0x42b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
setne %al
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x447df(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0x447ce(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x447c0(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x447b2(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
jmp 0x108f50
jmp 0x108f50
jmp 0x108f50
movq %rax, %rbx
jmp 0x108fcd
jmp 0x108f59
jmp 0x108f59
movq %rax, %rbx
jmp 0x108fb0
jmp 0x108f64
jmp 0x108f64
jmp 0x108f64
movq %rax, %rbx
jmp 0x108f93
jmp 0x108f6b
movq %rax, %rbx
movq %r15, %rdi
callq 0xf10e
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x108f93
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x108fb0
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x108fcd
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x108fe4
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780