// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/cluster.cc
// Function: cluster_partition(ATOM_NETWORK*, float)
vector< vector<XYZ> > cluster_partition(ATOM_NETWORK* atmnet, const float cutoff_dist)
{
    //Algorithm:
    
    // Partition a high accuracy voronoi net into clusters.
    ATOM_NETWORK ha_atmnet = *atmnet;
    string acc_setting = "S30";
    setupHighAccuracyAtomNetwork(&ha_atmnet, acc_setting);

    vector<VOR_CELL> vcell;
    vector<BASIC_VCELL> bvcell;
    VORONOI_NETWORK vornet, ha_vornet;
    performVoronoiDecomp(true, atmnet, &vornet, &vcell, false, &bvcell);
    vcell.clear();
    bvcell.clear();
    performVoronoiDecomp(true, &ha_atmnet, &ha_vornet, &vcell, false, &bvcell);
    DIJKSTRA_NETWORK dnet;
    DIJKSTRA_NETWORK::buildDijkstraNetwork(&ha_vornet, &dnet);

    for (DnIt it = dnet.nodes.begin(); it != dnet.nodes.end(); ++it)
        it->active = false;
    
    for (VnIt it = vornet.nodes.begin(); it != vornet.nodes.end(); ++it)
        cout << it->x << " " << it->y << " " << it->z << endl;

    vector <vector<XYZ> > clusters;
    
    for (VnIt nodeit = vornet.nodes.begin(); nodeit != vornet.nodes.end(); ++nodeit) {
        // Get the first non assigned high accuracy voronoi node within the 
        // cutoff distance to current low accuracy voronoi node
        XYZ low_acc_node_loc(nodeit->x, nodeit->y, nodeit->z);
        pair<DnIt, DnIt> p = get_first_closer_nonassigned_node(   // Highaccuracy dijkstra
                low_acc_node_loc, *atmnet, dnet.nodes, cutoff_dist);

        // Initialize cluster and tovisit_nodes
        vector<XYZ> cluster;
        vector<int> tovisit_ids;
        vector<int> visited_ids;

        // Add the current high accuracy node to tovisit ids
        tovisit_ids.push_back(p.first->id);

        // Populate the cluster
        while (!tovisit_ids.empty()){
            //Work on the current node
            int curr_id = tovisit_ids.back();
            DIJKSTRA_NODE curr_nd = dnet.nodes.at(curr_id);
            cluster.push_back(XYZ(curr_nd.x, curr_nd.y, curr_nd.z));
            visited_ids.push_back(curr_nd.id);
            tovisit_ids.pop_back();

            //If any connected nodes are unvisited and are within cutoff distance,
            //push them to tovisit_ids
            vector<CONN>::iterator connit = curr_nd.connections.begin();
            for (; connit != curr_nd.connections.end(); ++connit){
                int to_nodeid = connit->to;
                DIJKSTRA_NODE to_node = dnet.nodes.at(to_nodeid);
                double dist_to_low_acc_node = atmnet->calcDistanceXYZ(
                        nodeit->x, nodeit->y, nodeit->z,
                        to_node.x, to_node.y, to_node.z);
                if (find(visited_ids.begin(), visited_ids.end(), to_nodeid) == visited_ids.end() 
                        && dist_to_low_acc_node < cutoff_dist)
                    tovisit_ids.push_back(to_nodeid); 
            }
        }
        
        clusters.push_back(cluster);
        tovisit_ids.clear();
        visited_ids.clear();
        cluster.clear();
        
    }
    // assert (clusters.size() == vornet.nodes.size());

    return clusters;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7a8, %rsp            # imm = 0x7A8
movss %xmm0, 0x38(%rsp)
movq %rdi, 0x58(%rsp)
leaq 0x348(%rsp), %rdi
movq %rsi, 0x78(%rsp)
callq 0x9e04c
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xbbaa4(%rip), %rsi     # 0x157c17
leaq 0xbbaa0(%rip), %rdx     # 0x157c1a
leaq 0x80(%rsp), %rdi
callq 0x2263c
leaq 0x100(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf0(%rsp), %rdi
callq 0xf32a
leaq 0x348(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x94c4f
movq 0xf0(%rsp), %rdi
cmpq %r15, %rdi
je 0x9c1e5
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x4470
xorpd %xmm0, %xmm0
movapd %xmm0, 0xc0(%rsp)
xorl %eax, %eax
movq %rax, 0xd0(%rsp)
movq %rax, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x555c0
leaq 0x2d0(%rsp), %rdi
callq 0x555c0
leaq 0x258(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
leaq 0xa0(%rsp), %r9
movl $0x1, %edi
movq 0x78(%rsp), %rsi
xorl %r8d, %r8d
callq 0x77c4
leaq 0xc0(%rsp), %rbx
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0xfa26
leaq 0xa0(%rsp), %r15
movq (%r15), %rsi
movq %r15, %rdi
callq 0xf9f6
leaq 0x348(%rsp), %rsi
leaq 0x2d0(%rsp), %rdx
movl $0x1, %edi
movq %rbx, %rcx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x77c4
leaq 0x1f8(%rsp), %rdi
callq 0x50e9e
leaq 0x2d0(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x50fc8
movq 0x1f8(%rsp), %rax
movq 0x200(%rsp), %rcx
cmpq %rcx, %rax
je 0x9c2db
movb $0x0, 0x40(%rax)
addq $0x48, %rax
jmp 0x9c2cc
movq 0x2a0(%rsp), %r13
cmpq 0x2a8(%rsp), %r13
je 0x9c38b
movq 0xfacc8(%rip), %rbx     # 0x196fc0
leaq 0xbb187(%rip), %r15     # 0x157486
movsd (%r13), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x44e0
movsd 0x8(%r13), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x44e0
movsd 0x10(%r13), %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
addq $0x40, %r13
cmpq 0x2a8(%rsp), %r13
jne 0x9c2ff
xorpd %xmm0, %xmm0
movq 0x58(%rsp), %rax
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq 0x2a0(%rsp), %r15
cmpq 0x2a8(%rsp), %r15
je 0x9c7fd
leaq 0x180(%rsp), %r12
xorps %xmm0, %xmm0
cvtss2sd 0x38(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
leaq 0x1c8(%rsp), %r14
leaq 0x3c(%rsp), %rbx
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd 0x10(%r15), %xmm2
leaq 0x1e0(%rsp), %rdi
callq 0x85982
movq 0x1f0(%rsp), %rax
movq %rax, 0x1c0(%rsp)
movupd 0x1e0(%rsp), %xmm0
movapd %xmm0, 0x1b0(%rsp)
movq %r14, %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x38ec6
movq 0x1c0(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x1b0(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x78(%rsp), %rdi
movq %r14, %rsi
movss 0x38(%rsp), %xmm0
callq 0x9c093
movq %rax, %r13
movq %r14, %rdi
callq 0xf07c
xorl %eax, %eax
movq %rax, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq %rax, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movq %rax, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x9c4a9
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x9c751
leaq 0x20(%rsp), %rdi
movq %r13, %rdx
callq 0xf7b4
jmp 0x9c751
movslq -0x4(%rax), %rsi
movq 0x1f8(%rsp), %r13
movq 0x200(%rsp), %rdx
subq %r13, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x9c8ce
leaq (%rsi,%rsi,8), %rbp
leaq 0x20(,%rbp,8), %rsi
addq %r13, %rsi
movupd -0x20(%rsi), %xmm0
movups -0x10(%rsi), %xmm1
movaps %xmm1, 0x120(%rsp)
movapd %xmm0, 0x110(%rsp)
leaq 0x130(%rsp), %r14
movq %r14, %rdi
callq 0x38318
leaq (,%rbp,8), %rax
addq %r13, %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r14)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r14)
movsd 0x118(%rsp), %xmm0
movsd 0x120(%rsp), %xmm1
movsd 0x128(%rsp), %xmm2
leaq 0x160(%rsp), %rdi
callq 0x85982
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x9c595
movq 0x170(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x160(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x68(%rsp)
jmp 0x9c5a7
leaq 0x60(%rsp), %rdi
leaq 0x160(%rsp), %rdx
callq 0x9eb8a
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x9c5c7
movl 0x110(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x9c5d9
leaq 0x40(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0xf7b4
addq $-0x4, 0x28(%rsp)
movq 0x130(%rsp), %r13
cmpq 0x138(%rsp), %r13
je 0x9c734
movslq 0x4(%r13), %rsi
movl %esi, 0x3c(%rsp)
movq 0x1f8(%rsp), %rbp
movq 0x200(%rsp), %rdx
subq %rbp, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x9c8c0
leaq (%rsi,%rsi,8), %r14
leaq 0x20(,%r14,8), %rsi
addq %rbp, %rsi
movupd -0x20(%rsi), %xmm0
movups -0x10(%rsi), %xmm1
movaps %xmm1, 0x170(%rsp)
movapd %xmm0, 0x160(%rsp)
movq %r12, %rdi
callq 0x38318
leaq (,%r14,8), %rax
addq %rbp, %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r12)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r12)
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd 0x10(%r15), %xmm2
movsd 0x168(%rsp), %xmm3
movsd 0x170(%rsp), %xmm4
movsd 0x178(%rsp), %xmm5
movq 0x78(%rsp), %rdi
callq 0x5394a
movsd %xmm0, 0xe8(%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rbx, %rdx
callq 0x9eca8
movsd 0xe0(%rsp), %xmm0
ucomisd 0xe8(%rsp), %xmm0
jbe 0x9c70e
cmpq 0x48(%rsp), %rax
jne 0x9c70e
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x9c701
movl 0x3c(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x9c70e
leaq 0x20(%rsp), %rdi
movq %rbx, %rdx
callq 0xf7b4
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x9c72b
movq 0x190(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x28, %r13
jmp 0x9c5e7
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x9c751
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x28(%rsp), %rax
cmpq %rax, 0x20(%rsp)
jne 0x9c4bb
movq 0x58(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x6826c
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
leaq 0x1c8(%rsp), %r14
je 0x9c789
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rdi
cmpq %rdi, 0x48(%rsp)
je 0x9c79a
movq %rdi, 0x48(%rsp)
movq 0x60(%rsp), %rax
cmpq %rax, 0x68(%rsp)
je 0x9c7ab
movq %rax, 0x68(%rsp)
testq %rdi, %rdi
je 0x9c7bd
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9c7d4
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9c7eb
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x40, %r15
cmpq 0x2a8(%rsp), %r15
jne 0x9c3dd
leaq 0x1f8(%rsp), %rdi
callq 0xf07c
movq 0x330(%rsp), %rdi
testq %rdi, %rdi
je 0x9c827
movq 0x340(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x2a0(%rsp), %rbx
leaq 0x318(%rsp), %rdi
callq 0xf1b8
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x9c855
movq 0x2c8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0xf1b8
leaq 0xa0(%rsp), %rdi
callq 0xebe4
leaq 0xc0(%rsp), %rdi
callq 0xebb4
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x9c89c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x348(%rsp), %rdi
callq 0xec14
movq 0x58(%rsp), %rax
addq $0x7a8, %rsp            # imm = 0x7A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb2dde(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
leaq 0xb2dd0(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
jmp 0x9c954
jmp 0x9c929
movq %rax, %rbx
jmp 0x9ca31
movq %rax, %rbx
jmp 0x9ca5b
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r15, %rdi
je 0x9ca75
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x9ca75
movq %rax, %rbx
jmp 0x9ca75
movq %rax, %rbx
jmp 0x9ca9a
movq %rax, %rbx
jmp 0x9ca07
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0xf07c
jmp 0x9c9f0
jmp 0x9c948
movq %rax, %rbx
jmp 0x9c9f0
jmp 0x9c95e
jmp 0x9c969
movq %rax, %rbx
jmp 0x9c9fa
jmp 0x9c95e
movq %rax, %rbx
jmp 0x9c9ab
jmp 0x9c969
jmp 0x9c96e
jmp 0x9c969
movq %rax, %rbx
jmp 0x9c98e
movq %rax, %rbx
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x9c98e
movq 0x190(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x9c9ab
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9c9c2
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9c9d9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9c9f0
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x58(%rsp), %rdi
callq 0x68298
leaq 0x1f8(%rsp), %rdi
callq 0xf07c
movq 0x330(%rsp), %rdi
testq %rdi, %rdi
je 0x9ca24
movq 0x340(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x318(%rsp), %rdi
callq 0xf1b8
movq 0x2b8(%rsp), %rdi
testq %rdi, %rdi
je 0x9ca4e
movq 0x2c8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x2a0(%rsp), %rdi
callq 0xf1b8
leaq 0xa0(%rsp), %rdi
callq 0xebe4
leaq 0xc0(%rsp), %rdi
callq 0xebb4
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x9ca9a
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x348(%rsp), %rdi
callq 0xec14
movq %rbx, %rdi
callq 0x4780