// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/cluster.cc
// Function: nearest_largest_diameter_ha_vornet(VORONOI_NETWORK*, VORONOI_NETWORK*, ATOM_NETWORK*, VORONOI_NETWORK*, float)
void nearest_largest_diameter_ha_vornet(VORONOI_NETWORK* ha_vornet, VORONOI_NETWORK* vornet, 
        ATOM_NETWORK* atmnet, VORONOI_NETWORK* red_vornet, float cutoff)
{
    cout << "vornet size " << ha_vornet->nodes.size() << endl;
    for (VnIt vit = vornet->nodes.begin(); vit != vornet->nodes.end(); ++vit){
        VOR_NODE* biggest_near_vornode = NULL;
        double x2 = vit->x;
        double y2 = vit->y;
        double z2 = vit->z;
        for (VnIt vh_it = ha_vornet->nodes.begin(); vh_it != ha_vornet->nodes.end(); ++vh_it){
            double x1 = vh_it->x;
            double y1 = vh_it->y;
            double z1 = vh_it->z;
            double dist = atmnet->calcDistanceXYZ(x1,y1,z1,x2,y2,z2);
            //cout << dist << endl;
            if (dist <= cutoff){
                if (!biggest_near_vornode)
                    biggest_near_vornode = &*vh_it;
                else{
                    if (vh_it->rad_stat_sphere > biggest_near_vornode->rad_stat_sphere) {
                        biggest_near_vornode = &*vh_it;
                    }
                }
                //cout << "Size of vornode " << sizeof(biggest_near_vornode) << endl;
            }
        }
        //cout << "Reduced vornet nodes size " << red_vornet->nodes.size() << endl;
        //cout << "Size of vornode " << sizeof(biggest_near_vornode) << endl;
        if (biggest_near_vornode){
            red_vornet->nodes.push_back(*biggest_near_vornode);
        }
        else{
            cout << "Not able to find closest ha node" << endl;
            //throw 10;
        }
        //cout << "Size of vornode " << sizeof(biggest_near_vornode) << endl;
    }

    /* Ignoring edges at the moment as they are not needed */
    // Now that the voronoi nodes in reduced voronoi network are in the order 
    // of low accuracy vornet, generate the edges connecting the nodes in the order corresponding
    // to that in the low accuracy voronoi network. 
    // Adjust parameters of edges such as length, radius etc
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movss %xmm0, (%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
movq 0xf9248(%rip), %r15     # 0x194fc0
leaq 0xba8c9(%rip), %rsi     # 0x156648
movl $0xc, %edx
movq %r15, %rdi
callq 0x44e0
movq 0x50(%r12), %rsi
subq 0x48(%r12), %rsi
sarq $0x6, %rsi
movq %r15, %rdi
callq 0x42b0
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
movq 0x48(%rbx), %rbp
cmpq 0x50(%rbx), %rbp
je 0x9bee5
movq %rbx, %r13
xorps %xmm0, %xmm0
cvtss2sd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0x48, 0x8(%rsp)
movq 0x48(%r12), %rbx
cmpq 0x50(%r12), %rbx
je 0x9be95
movsd (%rbp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x8(%rbp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %esi, %esi
movq %rsi, %r15
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
movsd 0x10(%rbx), %xmm2
movq %r14, %rdi
movsd (%rsp), %xmm3
movsd 0x20(%rsp), %xmm4
movsd 0x18(%rsp), %xmm5
callq 0x5364c
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x9be5e
movq %r15, %rsi
jmp 0x9be79
movq %rbx, %rsi
testq %r15, %r15
je 0x9be79
movsd 0x18(%rbx), %xmm0
ucomisd 0x18(%r15), %xmm0
movq %r15, %rsi
jbe 0x9be79
movq %rbx, %rsi
addq $0x40, %rbx
cmpq 0x50(%r12), %rbx
jne 0x9be23
testq %rsi, %rsi
je 0x9be95
movq 0x8(%rsp), %rdi
callq 0xe9d4
jmp 0x9bed7
movl $0x20, %edx
movq 0xf911f(%rip), %rbx     # 0x194fc0
movq %rbx, %rdi
leaq 0xba7aa(%rip), %rsi     # 0x156655
callq 0x44e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
addq $0x40, %rbp
cmpq 0x50(%r13), %rbp
jne 0x9bdf1
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq