// File: 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
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movsd 0xf043d(%rip), %xmm0    # 0x1fb8c8
movsd %xmm0, -0x30(%rbp)
movsd 0xf1c68(%rip), %xmm0    # 0x1fd100
movsd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xd0f0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xd160
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xd120
testb $0x1, %al
jne 0x10b4d8
jmp 0x10b53c
leaq -0x40(%rbp), %rdi
callq 0xd190
movsd 0x30(%rax), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x10b504
leaq -0x40(%rbp), %rdi
callq 0xd190
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xd190
movsd 0x30(%rax), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x10b52c
leaq -0x40(%rbp), %rdi
callq 0xd190
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x10b52e
leaq -0x40(%rbp), %rdi
callq 0xb16f0
jmp 0x10b4b1
movq 0x167a7d(%rip), %rdi    # 0x272fc0
leaq 0xf1bd2(%rip), %rsi     # 0x1fd11c
callq 0x5540
movq %rax, -0x188(%rbp)
movq -0x10(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xf060
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
movq 0x167a19(%rip), %rsi    # 0x272f98
callq 0x55b0
movq 0x167a35(%rip), %rdi    # 0x272fc0
leaq 0xf1ba8(%rip), %rsi     # 0x1fd13a
callq 0x5540
movq %rax, -0x180(%rbp)
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xf060
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
movq 0x1679d1(%rip), %rsi    # 0x272f98
callq 0x55b0
testb $0x1, -0x21(%rbp)
je 0x10b6cd
movq 0x1679e3(%rip), %rdi    # 0x272fc0
leaq 0xf1b7a(%rip), %rsi     # 0x1fd15e
callq 0x5540
movq %rax, %rdi
movq 0x1679a5(%rip), %rsi    # 0x272f98
callq 0x55b0
movq 0x1679c1(%rip), %rdi    # 0x272fc0
leaq 0xf13b0(%rip), %rsi     # 0x1fc9b6
callq 0x5540
movq %rax, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x5980
movq %rax, %rdi
leaq 0xf1b4c(%rip), %rsi     # 0x1fd16e
callq 0x5540
movq %rax, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x5980
movq %rax, %rdi
movq 0x16795a(%rip), %rsi    # 0x272f98
callq 0x55b0
movq 0x167976(%rip), %rdi    # 0x272fc0
leaq 0xf1b3b(%rip), %rsi     # 0x1fd18c
callq 0x5540
movq %rax, -0x198(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0xf270
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
movq 0x167915(%rip), %rsi    # 0x272f98
callq 0x55b0
movq 0x167931(%rip), %rdi    # 0x272fc0
leaq 0xf1b1e(%rip), %rsi     # 0x1fd1b4
callq 0x5540
movq %rax, -0x190(%rbp)
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0xf290
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
movq 0x1678d0(%rip), %rsi    # 0x272f98
callq 0x55b0
movq -0x10(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x96bf0
movq -0x10(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xd0f0
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xd160
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xd120
testb $0x1, %al
jne 0x10b727
jmp 0x10bccf
leaq -0xc8(%rbp), %rdi
callq 0xd190
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xd8(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jne 0x10b756
jp 0x10b756
jmp 0x10bcbe
testb $0x1, -0x21(%rbp)
je 0x10b8de
movq 0x167859(%rip), %rdi    # 0x272fc0
leaq 0xf1a6e(%rip), %rsi     # 0x1fd1dc
callq 0x5540
movq %rax, -0x1a0(%rbp)
jmp 0x10b77c
movq -0x1a0(%rbp), %rdi
movsd -0xd8(%rbp), %xmm0
callq 0x5980
movq %rax, -0x1a8(%rbp)
jmp 0x10b799
movq -0x1a8(%rbp), %rdi
movq 0x1677f1(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x10b7ae
movq 0x16780b(%rip), %rdi    # 0x272fc0
leaq 0xf1a2c(%rip), %rsi     # 0x1fd1e8
callq 0x5540
movq %rax, -0x1b0(%rbp)
jmp 0x10b7ca
movq -0x1b0(%rbp), %rdi
movq 0x1677c0(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x10b7df
leaq -0xc8(%rbp), %rdi
callq 0xd190
movsd (%rax), %xmm0
movq 0x1677ca(%rip), %rdi    # 0x272fc0
callq 0x5980
movq %rax, -0x1b8(%rbp)
jmp 0x10b804
movq -0x1b8(%rbp), %rdi
leaq 0xe8cf4(%rip), %rsi     # 0x1f4506
callq 0x5540
movq %rax, -0x1c0(%rbp)
jmp 0x10b820
leaq -0xc8(%rbp), %rdi
callq 0xd190
movq -0x1c0(%rbp), %rdi
movsd 0x8(%rax), %xmm0
callq 0x5980
movq %rax, -0x1c8(%rbp)
jmp 0x10b846
movq -0x1c8(%rbp), %rdi
leaq 0xe8cb2(%rip), %rsi     # 0x1f4506
callq 0x5540
movq %rax, -0x1d0(%rbp)
jmp 0x10b862
leaq -0xc8(%rbp), %rdi
callq 0xd190
movq -0x1d0(%rbp), %rdi
movsd 0x10(%rax), %xmm0
callq 0x5980
movq %rax, -0x1d8(%rbp)
jmp 0x10b888
movq -0x1d8(%rbp), %rdi
leaq 0xe8c70(%rip), %rsi     # 0x1f4506
callq 0x5540
movq %rax, -0x1e0(%rbp)
jmp 0x10b8a4
movq -0x1e0(%rbp), %rdi
movq 0x1676e6(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x10b8b9
jmp 0x10b8de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x122d0
jmp 0x10bce4
leaq -0xc8(%rbp), %rdi
callq 0xd190
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0xf0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xd190
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xd190
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x25230
movq %rax, -0x108(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x250b0
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x599b0
testb $0x1, %al
jne 0x10b96d
jmp 0x10bc04
leaq -0x108(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x599f0
movq -0x1f0(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
callq 0x599f0
movq -0x1f0(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x120(%rbp)
callq 0x599f0
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x128(%rbp)
movq -0x10(%rbp), %rdi
movsd -0x118(%rbp), %xmm0
movsd -0x120(%rbp), %xmm1
movsd -0x128(%rbp), %xmm2
movsd -0xf0(%rbp), %xmm3
movsd -0xf8(%rbp), %xmm4
movsd -0x100(%rbp), %xmm5
callq 0x978a0
movsd %xmm0, -0x1e8(%rbp)
jmp 0x10ba01
movsd -0x1e8(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movsd -0x130(%rbp), %xmm1
movsd -0xd8(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x10bbf3
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x25230
movq %rax, -0x140(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x251f0
movl %eax, -0x134(%rbp)
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0x263c0
movq %rax, -0x148(%rbp)
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0x26230
movq %rax, -0x150(%rbp)
leaq -0x148(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x59a50
testb $0x1, %al
jne 0x10baa1
jmp 0x10bb97
leaq -0x148(%rbp), %rdi
callq 0x59a90
movl (%rax), %eax
movl %eax, -0x154(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x59a90
movl 0x4(%rax), %eax
movl %eax, -0x158(%rbp)
movl -0x154(%rbp), %eax
cmpl -0x134(%rbp), %eax
je 0x10bae6
movl -0x158(%rbp), %eax
cmpl -0x134(%rbp), %eax
jne 0x10bb42
movq -0x8(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x200(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x10cea0
movq -0x200(%rbp), %rdi
movq -0x168(%rbp), %rsi
callq 0x10ce30
movq %rax, -0x1f8(%rbp)
jmp 0x10bb24
movq -0x1f8(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x148(%rbp)
jmp 0x10bb92
movl -0x154(%rbp), %eax
cmpl -0x134(%rbp), %eax
jle 0x10bb63
leaq -0x148(%rbp), %rdi
callq 0x59a90
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movl -0x158(%rbp), %eax
cmpl -0x134(%rbp), %eax
jle 0x10bb86
leaq -0x148(%rbp), %rdi
callq 0x59a90
movl 0x4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4(%rax)
leaq -0x148(%rbp), %rdi
callq 0x10cee0
jmp 0x10ba71
movq -0x8(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x210(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x59af0
movq -0x210(%rbp), %rdi
movq -0x178(%rbp), %rsi
callq 0x10cf00
movq %rax, -0x208(%rbp)
jmp 0x10bbd5
movq -0x208(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x108(%rbp)
jmp 0x10bbff
leaq -0x108(%rbp), %rdi
callq 0xb4bd0
jmp 0x10b93d
testb $0x1, -0x21(%rbp)
je 0x10bcbc
movq 0x1673ab(%rip), %rdi    # 0x272fc0
leaq 0xf15de(%rip), %rsi     # 0x1fd1fa
callq 0x5540
movq %rax, -0x218(%rbp)
jmp 0x10bc2a
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0xf270
movq -0x218(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, -0x220(%rbp)
jmp 0x10bc4f
movq -0x220(%rbp), %rdi
movq 0x16733b(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x10bc64
movq 0x167355(%rip), %rdi    # 0x272fc0
leaq 0xf15af(%rip), %rsi     # 0x1fd221
callq 0x5540
movq %rax, -0x228(%rbp)
jmp 0x10bc80
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0xf290
movq -0x228(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, -0x230(%rbp)
jmp 0x10bca5
movq -0x230(%rbp), %rdi
movq 0x1672e5(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x10bcba
jmp 0x10bcbc
jmp 0x10bcbe
leaq -0xc8(%rbp), %rdi
callq 0xb16f0
jmp 0x10b6f4
leaq -0xc0(%rbp), %rdi
callq 0x122d0
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq -0xe0(%rbp), %rdi
callq 0x58f0