// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %rsi, %r14
movq %rdi, %r15
movq 0x2f0(%rsi), %rax
movq 0x2f8(%rsi), %rcx
movsd 0x8fa3e(%rip), %xmm0    # 0x103bd0
movsd %xmm0, 0x10(%rsp)
movsd 0x91250(%rip), %xmm2    # 0x1053f0
cmpq %rcx, %rax
je 0x741ca
movsd 0x30(%rax), %xmm0
movapd %xmm0, %xmm1
minsd 0x10(%rsp), %xmm1
maxsd %xmm2, %xmm0
addq $0x98, %rax
movapd %xmm0, %xmm2
movsd %xmm1, 0x10(%rsp)
jmp 0x741a0
movsd %xmm2, 0x8(%rsp)
movq 0xdbde9(%rip), %r13     # 0x14ffc0
leaq 0x9121e(%rip), %rsi     # 0x1053fc
movq %r13, %rdi
callq 0x4480
movq %rax, %rdi
movq 0x2f8(%r14), %rax
subq 0x2f0(%r14), %rax
movl $0x98, %ebx
cqto
idivq %rbx
movq %rax, %rsi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
leaq 0x91202(%rip), %rsi     # 0x10541a
movq %r13, %rdi
callq 0x4480
movq %rax, %rdi
movq 0x2f8(%r12), %rax
subq 0x2f0(%r12), %rax
cqto
idivq %rbx
movq %rax, %rsi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
cmpb $0x0, 0x4(%rsp)
je 0x74310
movq 0xdbd66(%rip), %r12     # 0x14ffc0
leaq 0x911dd(%rip), %rsi     # 0x10543e
movq %r12, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0x90a86(%rip), %rsi     # 0x104cfe
movq %r12, %rdi
callq 0x4480
movq %rax, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x46c0
leaq 0x911b9(%rip), %rsi     # 0x10544e
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x46c0
movq %rax, %rdi
callq 0x4230
leaq 0x911b2(%rip), %rsi     # 0x10546c
movq %r12, %rdi
callq 0x4480
movq 0x50(%r15), %rsi
subq 0x48(%r15), %rsi
sarq $0x6, %rsi
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
leaq 0x911af(%rip), %rsi     # 0x105494
movq %r12, %rdi
callq 0x4480
movq %rax, %rdi
movq 0x68(%r15), %rax
subq 0x60(%r15), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
movq %rax, %rsi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x3ec9e
movq 0x2f0(%r14), %rbx
leaq 0x48(%r15), %r12
leaq 0x60(%r15), %r13
cmpq 0x2f8(%r14), %rbx
je 0x74563
movsd 0x30(%rbx), %xmm0
ucomisd 0x10(%rsp), %xmm0
jne 0x7434c
jnp 0x74557
movsd %xmm0, 0x8(%rsp)
cmpb $0x0, 0x4(%rsp)
je 0x74400
movq 0xdbc5c(%rip), %rdi     # 0x14ffc0
leaq 0x91151(%rip), %rsi     # 0x1054bc
callq 0x4480
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x46c0
movq %rax, %rdi
callq 0x4230
movq 0xdbc33(%rip), %rdi     # 0x14ffc0
leaq 0x91134(%rip), %rsi     # 0x1054c8
callq 0x4480
movq %rax, %rdi
callq 0x4230
movsd (%rbx), %xmm0
movq 0xdbc14(%rip), %rdi     # 0x14ffc0
callq 0x46c0
movq %rax, %rdi
leaq 0x8a0c5(%rip), %rsi     # 0xfe480
callq 0x4480
movsd 0x8(%rbx), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0x8a0a9(%rip), %rsi     # 0xfe480
callq 0x4480
movsd 0x10(%rbx), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0x8a08d(%rip), %rsi     # 0xfe480
callq 0x4480
movq %rax, %rdi
callq 0x4230
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rbx, 0x20(%rsp)
movsd 0x28(%rbx), %xmm0
movsd %xmm0, 0x28(%rsp)
movq (%r12), %rbx
movsd 0x8(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
cmpq 0x50(%r15), %rbx
je 0x744e6
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
movsd 0x10(%rbx), %xmm2
movq %r14, %rdi
movsd 0x38(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
movsd 0x28(%rsp), %xmm5
callq 0x3f56c
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x74480
addq $0x40, %rbx
jmp 0x7443c
movq %rbx, %rbp
subq (%r12), %rbp
shrq $0x6, %rbp
movq (%r13), %rax
cmpq 0x68(%r15), %rax
je 0x744d3
movl (%rax), %edx
movl 0x4(%rax), %ecx
cmpl %ebp, %edx
sete %sil
cmpl %ebp, %ecx
sete %dil
orb %sil, %dil
cmpb $0x1, %dil
jne 0x744bc
movq %r13, %rdi
movq %rax, %rsi
callq 0x74cb6
jmp 0x7448f
cmpl %ebp, %edx
jle 0x744c4
decl %edx
movl %edx, (%rax)
cmpl %ebp, %ecx
jle 0x744cd
decl %ecx
movl %ecx, 0x4(%rax)
addq $0x28, %rax
jmp 0x7448f
movq %r12, %rdi
movq %rbx, %rsi
callq 0x74cbc
movq %rax, %rbx
jmp 0x7443c
cmpb $0x0, 0x4(%rsp)
movq 0x20(%rsp), %rbx
je 0x74557
movq 0xdbac7(%rip), %rdi     # 0x14ffc0
leaq 0x90fda(%rip), %rsi     # 0x1054da
callq 0x4480
movq 0x50(%r15), %rsi
subq 0x48(%r15), %rsi
sarq $0x6, %rsi
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
movq 0xdba98(%rip), %rdi     # 0x14ffc0
leaq 0x90fd2(%rip), %rsi     # 0x105501
callq 0x4480
movq %rax, %rdi
movq 0x68(%r15), %rax
subq 0x60(%r15), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
movq %rax, %rsi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
addq $0x98, %rbx
jmp 0x7432c
leaq 0x40(%rsp), %rdi
callq 0xb0f0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x74587
jmp 0x74587
jmp 0x74587
jmp 0x74587
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xb0f0
movq %rbx, %rdi
callq 0x4780