// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/cluster.cc
// Function: simplify_high_accuracy_vornet(VORONOI_NETWORK*, ATOM_NETWORK*, VORONOI_NETWORK*)
void simplify_high_accuracy_vornet(VORONOI_NETWORK* ha_vornet, 
                                   ATOM_NETWORK* ha_atmnet, 
                                   VORONOI_NETWORK* red_vornet)
{
    // Identify nodes that belong to unitcell crossing edges
    vector<int> nodes_with_boundary_crossing_edges;
    for (VeIt vit = ha_vornet->edges.begin(); vit != ha_vornet->edges.end(); ++vit){
        if (vit->delta_uc_x || vit->delta_uc_y || vit->delta_uc_y){
            nodes_with_boundary_crossing_edges.push_back(vit->from);
            nodes_with_boundary_crossing_edges.push_back(vit->to);
        }
    }
    // Sort and remove duplicates
    vector<int>::iterator vbeg = nodes_with_boundary_crossing_edges.begin(); 
    vector<int>::iterator vend = nodes_with_boundary_crossing_edges.end(); 
    int size = nodes_with_boundary_crossing_edges.size(); 
    sort(vbeg, vbeg+size);
    nodes_with_boundary_crossing_edges.erase( unique( vbeg, vend ), vend );

    vector<int>* id_map = &(ha_atmnet->IDmapping);
    int i = 0;
    for (VnIt vit = ha_vornet->nodes.begin(); vit != ha_vornet->nodes.end(); ++vit, ++i){

        if (find(vbeg, vend, i) != vend){
            red_vornet->nodes.push_back(*vit);
        }
        else{

            set<int> original_atmnet_ids;
            for (vector<int>::iterator it = vit->atomIDs.begin(); it != vit->atomIDs.end(); ++it){
                original_atmnet_ids.insert(id_map->at(*it));
            }
            
            if (original_atmnet_ids.size() >= 4) {
                red_vornet->nodes.push_back(*vit);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq 0x60(%rdi), %r12
cmpq 0x68(%r15), %r12
je 0x7473f
cmpl $0x0, 0x10(%r12)
jne 0x74721
cmpl $0x0, 0x14(%r12)
je 0x74739
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9434
leaq 0x4(%r12), %rsi
movq %rbx, %rdi
callq 0x9434
addq $0x28, %r12
jmp 0x7470b
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r13
movq %r13, %rsi
subq %rbx, %rsi
shlq $0x1e, %rsi
sarq $0x1e, %rsi
addq %rbx, %rsi
movq %rbx, %rdi
callq 0x7581d
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x75c1d
movq %rbp, %r12
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x74cc2
addq $0x308, %r14            # imm = 0x308
leaq 0xc(%rsp), %rax
andl $0x0, (%rax)
movq 0x48(%r15), %rbx
addq $0x48, %r12
leaq 0x38(%rsp), %rbp
movq %r15, 0x28(%rsp)
cmpq 0x50(%r15), %rbx
je 0x7484e
movq 0x30(%rsp), %rdi
movq %r13, %rsi
leaq 0xc(%rsp), %rdx
callq 0x7565c
cmpq %r13, %rax
je 0x747d4
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa89e
jmp 0x74841
movq %r12, %r15
andl $0x0, 0x40(%rsp)
andq $0x0, 0x48(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %rax, 0x58(%rsp)
andq $0x0, 0x60(%rsp)
movq 0x20(%rbx), %r12
cmpq 0x28(%rbx), %r12
je 0x7481e
movslq (%r12), %rsi
movq %r14, %rdi
callq 0xac00
movq %rbp, %rdi
movq %rax, %rsi
callq 0xf334
addq $0x4, %r12
jmp 0x747fb
cmpq $0x3, 0x60(%rsp)
movq %r15, %r12
jbe 0x74834
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa89e
movq %rbp, %rdi
callq 0xafbe
movq 0x28(%rsp), %r15
addq $0x40, %rbx
incl 0xc(%rsp)
jmp 0x747a6
leaq 0x10(%rsp), %rdi
callq 0xb290
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x74871
jmp 0x74871
jmp 0x74876
jmp 0x74871
jmp 0x74871
movq %rax, %rbx
jmp 0x74883
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xafbe
leaq 0x10(%rsp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780