// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/cluster.cc
// Function: prune_high_accuracy_voronoi_network(VORONOI_NETWORK*, ATOM_NETWORK*, ATOM_NETWORK*, double, bool)
void prune_high_accuracy_voronoi_network( VORONOI_NETWORK* ha_vor, 
                            ATOM_NETWORK* low_atm_net, ATOM_NETWORK* high_atm_net,
                            double delta, bool print)
{
    double minr, maxr;

    /* Analyze the original atom network*/
    minr = 100000;      // A very big number as initial min. value
    maxr = -100000;     // " " " " "  negative number as init max. value
    for (AtmIt it = low_atm_net->atoms.begin(); it != low_atm_net->atoms.end(); ++it){
        if (it->radius < minr) minr = it->radius;
        if (it->radius > maxr) maxr = it->radius;
    }
    /* Print the high accuracy atom network for debug */
    //vector<int>::iterator id_it;
    //for (id_it = high_atm_net->IDmapping.begin(); id_it != high_atm_net->IDmapping.end(); ++id_it){
    //    cout << *id_it << endl;
    //}

    /* Print the sizes of high accuracy and regular atom networks for debug */
    cout << "Size of regular atom network " << low_atm_net->atoms.size() << endl;
    cout << "Size of high accuracy atom network " << high_atm_net->atoms.size() << endl;

    if (print) {
        cout << "Radii analysis:" << endl;
        cout << "the smallest atom r = " << minr << ", while the largest atom r = " << maxr << endl;

        cout << "Length of vornet nodes before pruning: " << ha_vor->nodes.size() << endl;
        cout << "Length of vornet edges before pruning: " << ha_vor->edges.size() << endl;
    }
    MIN_PER_DISTANCE distcalc = low_atm_net->getDistCalc();
    for (AtmIt it = low_atm_net->atoms.begin(); it != low_atm_net->atoms.end(); ++it){
        double atm_rad = it->radius;
        if (atm_rad == minr) continue;
        if (print) {
            cout << "Atom radius" <<  atm_rad << endl;
            cout << "Atoms locations: " << endl;
            cout << it->x <<  ", " <<  it->y << ", " <<  it->z << ", " <<  endl;
        }

        double a1 = it->a_coord; double b1 = it->b_coord; double c1 = it->c_coord;
        for (VnIt vnit = ha_vor->nodes.begin(); vnit != ha_vor->nodes.end();) {
            double x = vnit->x; double y = vnit->y; double z = vnit->z;
            double dist = low_atm_net->calcDistanceXYZABC(x, y, z, a1, b1, c1);
            if (dist <= atm_rad-delta){       // Delete the voronoi node and associated edges 
                int node_id = vnit - ha_vor->nodes.begin();
                // Delete the edges with the node_id and decrement the node index when its
                // greater than the id of deleted node
                for (VeIt veit = ha_vor->edges.begin(); veit != ha_vor->edges.end();) {
                    int from = veit->from;
                    int to = veit->to;
                    if (from == node_id || to == node_id) {
                        veit = ha_vor->edges.erase(veit);
                        //cout << "current veit index" << veit - ha_vor->edges.begin();
                    }
                    else{
                        if (from > node_id) --(veit->from);
                        if (to > node_id) --(veit->to);
                        ++veit;
                        //cout << "current veit index" << veit - ha_vor->edges.begin();
                    }
                }
                //cout << "Length of vornet edges after deleting node: " << ha_vor->edges.size() << endl;
                vnit = ha_vor->nodes.erase(vnit);
            }
            else
                ++vnit;
        }
        if (print) {
            cout << "Length of vornet nodes after pruning: " << ha_vor->nodes.size() << endl;
            cout << "Length of vornet edges after pruning: " << ha_vor->edges.size() << endl;
        }
    }
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %ecx, 0x4(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r15
movq 0x2f0(%rsi), %rax
movq 0x2f8(%rsi), %rcx
cmpq %rcx, %rax
je 0x9b6bd
movsd 0xbae81(%rip), %xmm0    # 0x156510
movsd 0xb95e1(%rip), %xmm1    # 0x154c78
movsd 0x30(%rax), %xmm3
movapd %xmm3, %xmm2
minsd %xmm1, %xmm2
maxsd %xmm0, %xmm3
addq $0x98, %rax
movapd %xmm2, %xmm1
movapd %xmm3, %xmm0
cmpq %rcx, %rax
jne 0x9b697
jmp 0x9b6cd
movsd 0xb95b3(%rip), %xmm2    # 0x154c78
movsd 0xbae43(%rip), %xmm3    # 0x156510
movsd %xmm3, 0x8(%rsp)
movsd %xmm2, 0x10(%rsp)
movq 0xf98e0(%rip), %r13     # 0x194fc0
leaq 0xbae35(%rip), %rsi     # 0x15651c
movl $0x1d, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x2f8(%rbp), %rsi
subq 0x2f0(%rbp), %rsi
sarq $0x3, %rsi
movabsq $-0x79435e50d79435e5, %r14 # imm = 0x86BCA1AF286BCA1B
imulq %r14, %rsi
movq %r13, %rdi
callq 0x42b0
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
leaq 0xbaded(%rip), %rsi     # 0x15653a
movl $0x23, %edx
movq %r13, %rdi
callq 0x44e0
movq 0x2f8(%rbx), %rsi
subq 0x2f0(%rbx), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
movq %r13, %rdi
callq 0x42b0
movq %rax, %rbx
movq (%rax), %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
cmpb $0x0, 0x4(%rsp)
je 0x9b912
leaq 0xbadaa(%rip), %rsi     # 0x15655e
movl $0xf, %edx
movq 0xf9800(%rip), %r14     # 0x194fc0
movq %r14, %rdi
callq 0x44e0
movq (%r14), %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
leaq 0xba5c8(%rip), %rsi     # 0x155dbe
movl $0x16, %edx
movq %r14, %rdi
callq 0x44e0
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x46b0
movq %rax, %rbx
leaq 0xbad53(%rip), %rsi     # 0x15656e
movl $0x1d, %edx
movq %rax, %rdi
callq 0x44e0
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x46b0
movq %rax, %rbx
movq (%rax), %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
leaq 0xbad25(%rip), %rsi     # 0x15658c
movl $0x27, %edx
movq %r14, %rdi
callq 0x44e0
movq 0x50(%r15), %rsi
subq 0x48(%r15), %rsi
sarq $0x6, %rsi
movq %r14, %rdi
callq 0x42b0
movq %rax, %rbx
movq (%rax), %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
leaq 0xbacfb(%rip), %rsi     # 0x1565b4
movl $0x27, %edx
movq %r14, %rdi
callq 0x44e0
movq 0x68(%r15), %rsi
subq 0x60(%r15), %rsi
sarq $0x3, %rsi
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rsi
movq %r14, %rdi
callq 0x42b0
movq %rax, %rbx
movq (%rax), %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
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x527f2
movq 0x2f0(%rbp), %r14
cmpq 0x2f8(%rbp), %r14
je 0x9bcdb
leaq 0x48(%r15), %r12
movsd 0x30(%r14), %xmm0
ucomisd 0x10(%rsp), %xmm0
jne 0x9b94b
jnp 0x9bcc7
movsd %xmm0, 0x8(%rsp)
cmpb $0x0, 0x4(%rsp)
je 0x9ba93
movl $0xb, %edx
movq 0xf9658(%rip), %rdi     # 0x194fc0
leaq 0xbac6d(%rip), %rsi     # 0x1565dc
callq 0x44e0
movq 0xf9645(%rip), %rdi     # 0x194fc0
movsd 0x8(%rsp), %xmm0
callq 0x46b0
movq %rax, %rbx
movq (%rax), %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
movl $0x11, %edx
movq 0xf9604(%rip), %rdi     # 0x194fc0
leaq 0xbac25(%rip), %rsi     # 0x1565e8
callq 0x44e0
movq 0xf95f1(%rip), %rcx     # 0x194fc0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq 0xf95d3(%rip), %rdi     # 0x194fc0
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movsd (%r14), %xmm0
movq 0xf95ba(%rip), %rdi     # 0x194fc0
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xb3aa7(%rip), %rsi     # 0x14f4c4
callq 0x44e0
movsd 0x8(%r14), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xb3a82(%rip), %rsi     # 0x14f4c4
callq 0x44e0
movsd 0x10(%r14), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xb3a5d(%rip), %rsi     # 0x14f4c4
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
movq 0x48(%r15), %rbx
cmpq 0x50(%r15), %rbx
je 0x9bbfa
movsd 0x18(%r14), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x20(%r14), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x28(%r14), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r14, 0x20(%rsp)
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
movsd 0x10(%rbx), %xmm2
movq %rbp, %rdi
movsd 0x38(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
movsd 0x28(%rsp), %xmm5
callq 0x53538
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x9bb19
addq $0x40, %rbx
jmp 0x9bbf0
movq %r12, %r14
movq %rbp, %r13
movq 0x48(%r15), %rcx
movq 0x60(%r15), %r12
movq %rbx, %rbp
subq %rcx, %rbp
movq 0x68(%r15), %rax
cmpq %rax, %r12
je 0x9bbd4
shrq $0x6, %rbp
movl (%r12), %edx
cmpl %ebp, %edx
je 0x9bb6a
movl 0x4(%r12), %ecx
cmpl %ebp, %ecx
je 0x9bb6a
cmpl %ebp, %edx
jle 0x9bb59
decl %edx
movl %edx, (%r12)
cmpl %ebp, %ecx
jle 0x9bb64
decl %ecx
movl %ecx, 0x4(%r12)
addq $0x28, %r12
jmp 0x9bbbd
movq %r12, %rsi
addq $0x28, %rsi
cmpq %rax, %rsi
je 0x9bbb5
movq %rax, %rcx
subq %rsi, %rcx
testq %rcx, %rcx
jle 0x9bbb5
movq %rcx, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rdx
shrq $0x5, %rdx
cmpq $0x28, %rcx
adcq $-0x1, %rdx
leaq (%rdx,%rdx,4), %rax
leaq 0x28(,%rax,8), %rdx
movq %r12, %rdi
callq 0x46c0
movq 0x68(%r15), %rax
addq $-0x28, %rax
movq %rax, 0x68(%r15)
cmpq %rax, %r12
jne 0x9bb3e
movq %r14, %r12
movq (%r14), %rcx
subq %rcx, %rbx
movq %rbx, %rbp
jmp 0x9bbd7
movq %r14, %r12
addq %rcx, %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x9d1ca
movq %rax, %rbx
movq %r13, %rbp
movq 0x20(%rsp), %r14
cmpq 0x50(%r15), %rbx
jne 0x9badc
cmpb $0x0, 0x4(%rsp)
je 0x9bcc7
movl $0x26, %edx
movq 0xf93af(%rip), %rdi     # 0x194fc0
leaq 0xba9e2(%rip), %rsi     # 0x1565fa
callq 0x44e0
movq 0x50(%r15), %rsi
subq 0x48(%r15), %rsi
sarq $0x6, %rsi
movq 0xf9390(%rip), %rdi     # 0x194fc0
callq 0x42b0
movq %rax, %rbx
movq (%rax), %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
movl $0x26, %edx
movq 0xf9355(%rip), %rdi     # 0x194fc0
leaq 0xba9af(%rip), %rsi     # 0x156621
callq 0x44e0
movq 0x68(%r15), %rsi
subq 0x60(%r15), %rsi
sarq $0x3, %rsi
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rsi
movq 0xf9328(%rip), %rdi     # 0x194fc0
callq 0x42b0
movq %rax, %rbx
movq (%rax), %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 $0x98, %r14
cmpq 0x2f8(%rbp), %r14
jne 0x9b937
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x9bcf5
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x9bd0c
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9bd23
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9bd3b
jmp 0x9bd3b
jmp 0x9bd3b
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x385cc
movq %rbx, %rdi
callq 0x4780