// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movsd %xmm0, 0x28(%rsp)
movq %rdx, %r13
movq %rdi, %r15
movq 0x2f0(%rsi), %rax
movq %rsi, 0x10(%rsp)
movq 0x2f8(%rsi), %rdx
movl %ecx, %ebp
cmpq %rdx, %rax
je 0x9d270
movsd 0xbb10e(%rip), %xmm0    # 0x158350
movsd 0xb9916(%rip), %xmm1    # 0x156b60
movsd 0x30(%rax), %xmm3
movapd %xmm3, %xmm2
minsd %xmm1, %xmm2
maxsd %xmm0, %xmm3
addq $0x98, %rax
movapd %xmm2, %xmm1
movapd %xmm3, %xmm0
cmpq %rdx, %rax
jne 0x9d24a
jmp 0x9d280
movsd 0xb98e8(%rip), %xmm2    # 0x156b60
movsd 0xbb0d0(%rip), %xmm3    # 0x158350
movsd %xmm3, 0x8(%rsp)
movsd %xmm2, 0x20(%rsp)
movq 0xf9d2d(%rip), %r12     # 0x196fc0
leaq 0xbb0c2(%rip), %rsi     # 0x15835c
movl $0x1d, %edx
movq %r12, %rdi
callq 0x44e0
movq 0x10(%rsp), %rax
movq 0x2f8(%rax), %rsi
subq 0x2f0(%rax), %rsi
sarq $0x3, %rsi
movabsq $-0x79435e50d79435e5, %r14 # imm = 0x86BCA1AF286BCA1B
imulq %r14, %rsi
movq %r12, %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 0xbb075(%rip), %rsi     # 0x15837a
movl $0x23, %edx
movq %r12, %rdi
callq 0x44e0
movq 0x2f8(%r13), %rsi
subq 0x2f0(%r13), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
movq %r12, %r14
movq %r12, %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
testb %bpl, %bpl
je 0x9d4c4
leaq 0xbb031(%rip), %rsi     # 0x15839e
movl $0xf, %edx
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 0xba8b6(%rip), %rsi     # 0x157c5e
movl $0x16, %edx
movq %r14, %rdi
callq 0x44e0
movq %r14, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x46b0
movq %rax, %rbx
leaq 0xbafe1(%rip), %rsi     # 0x1583ae
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 0xbafb3(%rip), %rsi     # 0x1583cc
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 0xbaf89(%rip), %rsi     # 0x1583f4
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 0x50(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x52aea
movq 0x2f0(%rbx), %r13
cmpq 0x2f8(%rbx), %r13
je 0x9d843
leaq 0x48(%r15), %rax
movq %rax, 0x30(%rsp)
movl $0x1, %r12d
movl %ebp, 0x1c(%rsp)
movsd 0x30(%r13), %xmm0
ucomisd 0x20(%rsp), %xmm0
jne 0x9d511
jnp 0x9d82a
movsd %xmm0, 0x8(%rsp)
testb %bpl, %bpl
je 0x9d63d
movl $0xb, %edx
movq %r14, %rdi
leaq 0xbaeed(%rip), %rsi     # 0x15841c
callq 0x44e0
movq %r14, %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
movl $0x11, %edx
movq %r14, %rdi
leaq 0xbaead(%rip), %rsi     # 0x158428
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
movsd (%r13), %xmm0
movq %r14, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xb3e8d(%rip), %rsi     # 0x151454
callq 0x44e0
movsd 0x8(%r13), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xb3e68(%rip), %rsi     # 0x151454
callq 0x44e0
movsd 0x10(%r13), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xb3e43(%rip), %rsi     # 0x151454
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), %r14
cmpq 0x50(%r15), %r14
je 0x9d764
movsd 0x18(%r13), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x20(%r13), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x28(%r13), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%rsp), %xmm0
subsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
movq 0x10(%rsp), %rdi
movsd 0x48(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
callq 0x53836
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x9d6c3
addq $0x40, %r14
jmp 0x9d75a
movq 0x60(%r15), %rbx
movq 0x68(%r15), %rax
cmpq %rax, %rbx
je 0x9d74a
movq %r14, %rbp
subq 0x48(%r15), %rbp
shrq $0x6, %rbp
movl (%rbx), %edx
cmpl %ebp, %edx
je 0x9d6ff
movl 0x4(%rbx), %ecx
cmpl %ebp, %ecx
je 0x9d6ff
cmpl %ebp, %edx
jle 0x9d6f0
decl %edx
movl %edx, (%rbx)
cmpl %ebp, %ecx
jle 0x9d6f9
decl %ecx
movl %ecx, 0x4(%rbx)
addq $0x28, %rbx
jmp 0x9d741
movq %rbx, %rsi
addq $0x28, %rsi
cmpq %rax, %rsi
je 0x9d73c
subq %rsi, %rax
testq %rax, %rax
jle 0x9d73c
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
shrq $0x5, %rdx
cmpq $0x2, %rdx
cmovlq %r12, %rdx
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rdx
movq %rbx, %rdi
callq 0x46c0
addq $-0x28, 0x68(%r15)
movq 0x68(%r15), %rax
cmpq %rax, %rbx
jne 0x9d6db
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x9ed42
movq %rax, %r14
cmpq 0x50(%r15), %r14
jne 0x9d681
movl 0x1c(%rsp), %ebp
testb %bpl, %bpl
movq 0xf984e(%rip), %r14     # 0x196fc0
je 0x9d82a
movl $0x26, %edx
movq %r14, %rdi
leaq 0xbacb3(%rip), %rsi     # 0x15843a
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
movl $0x26, %edx
movq %r14, %rdi
leaq 0xbac88(%rip), %rsi     # 0x158461
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
addq $0x98, %r13
movq 0x10(%rsp), %rax
cmpq 0x2f8(%rax), %r13
jne 0x9d4fd
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x9d860
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x9d877
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9d88e
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9d8a6
jmp 0x9d8a6
jmp 0x9d8a6
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x38a78
movq %rbx, %rdi
callq 0x4780