// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdi, %r12
movq 0xf96dd(%rip), %rbx     # 0x196fc0
leaq 0xbab9e(%rip), %rsi     # 0x158488
movl $0xc, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x50(%r12), %rsi
subq 0x48(%r12), %rsi
sarq $0x6, %rsi
movq %rbx, %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(%r15), %rbp
cmpq 0x50(%r15), %rbp
je 0x9da52
xorps %xmm0, %xmm0
cvtss2sd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0x48, 0x8(%rsp)
movq 0x48(%r12), %rbx
cmpq 0x50(%r12), %rbx
je 0x9d9ef
movsd (%rbp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x8(%rbp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r13d, %r13d
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 0x5394a
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x9d9c4
movq %r13, %rsi
jmp 0x9d9df
movq %rbx, %rsi
testq %r13, %r13
je 0x9d9df
movsd 0x18(%rbx), %xmm0
ucomisd 0x18(%r13), %xmm0
movq %r13, %rsi
jbe 0x9d9df
movq %rbx, %rsi
addq $0x40, %rbx
movq %rsi, %r13
cmpq 0x50(%r12), %rbx
jne 0x9d98c
jmp 0x9d9f1
xorl %esi, %esi
testq %rsi, %rsi
je 0x9da02
movq 0x8(%rsp), %rdi
callq 0xe962
jmp 0x9da44
movl $0x20, %edx
movq 0xf95b2(%rip), %rbx     # 0x196fc0
movq %rbx, %rdi
leaq 0xbaa7d(%rip), %rsi     # 0x158495
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(%r15), %rbp
jne 0x9d959
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq