// File: /workspace/github_cpp_makefile_star2_O1/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
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x60(%rdi), %rbx
cmpq 0x68(%rdi), %rbx
je 0x9daf8
movq %rsp, %r12
cmpl $0x0, 0x10(%rbx)
jne 0x9daa1
cmpl $0x0, 0x14(%rbx)
je 0x9daee
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x9dabc
movl (%rbx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9dac7
movq %r12, %rdi
movq %rbx, %rdx
callq 0xf7b4
leaq 0x4(%rbx), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x9dae6
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9daee
movq %r12, %rdi
callq 0xf7b4
addq $0x28, %rbx
cmpq 0x68(%r15), %rbx
jne 0x9da95
movq (%rsp), %r12
movq 0x8(%rsp), %r13
movq %r13, %rax
subq %r12, %rax
shlq $0x1e, %rax
je 0x9db3e
movq %rax, %rbx
sarq $0x1e, %rbx
addq %r12, %rbx
sarq $0x20, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x9eddf
movq %r12, %rdi
movq %rbx, %rsi
callq 0x9eec2
movq %r12, 0x30(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x9f132
movq %rax, %rbx
cmpq %r13, %rax
movq %rbp, %r12
je 0x9db86
movq 0x8(%rsp), %rdx
subq %r13, %rdx
je 0x9db6e
movq %rbx, %rdi
movq %r13, %rsi
callq 0x46c0
movq 0x8(%rsp), %rax
movq %rax, %rcx
subq %r13, %rcx
addq %rcx, %rbx
cmpq %rbx, %rax
je 0x9db86
movq %rbx, 0x8(%rsp)
movl $0x0, 0x24(%rsp)
movq 0x48(%r15), %rbp
cmpq 0x50(%r15), %rbp
je 0x9dc66
addq $0x48, %r12
leaq 0x38(%rsp), %rbx
movq %r15, 0x28(%rsp)
movq 0x30(%rsp), %rdi
movq %r13, %rsi
leaq 0x24(%rsp), %rdx
callq 0x9eca8
cmpq %r13, %rax
je 0x9dbd1
movq %r12, %rdi
movq %rbp, %rsi
callq 0xe962
jmp 0x9dc54
movq %r12, %r15
movl $0x0, 0x40(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x48(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq %rcx, 0x60(%rsp)
movq 0x20(%rbp), %r12
cmpq 0x28(%rbp), %r12
je 0x9dc31
movslq (%r12), %rsi
movq 0x308(%r14), %rax
movq 0x310(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x9dc8b
leaq (%rax,%rsi,4), %rsi
movq %rbx, %rdi
callq 0x132f6
addq $0x4, %r12
jmp 0x9dbfb
cmpq $0x3, 0x60(%rsp)
movq %r15, %r12
jbe 0x9dc47
movq %r12, %rdi
movq %rbp, %rsi
callq 0xe962
movq %rbx, %rdi
callq 0xf168
movq 0x28(%rsp), %r15
incl 0x24(%rsp)
addq $0x40, %rbp
cmpq 0x50(%r15), %rbp
jne 0x9dbaa
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9dc7c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb1a13(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
jmp 0x9dca3
jmp 0x9dca3
jmp 0x9dcaa
jmp 0x9dca3
jmp 0x9dca3
movq %rax, %rbx
jmp 0x9dcb7
jmp 0x9dcaa
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xf168
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9dccd
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780