// File: /workspace/github_cpp_makefile_star2_O3/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, 0x28(%rsp)
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 0x9bf9e
movq %rsp, %r12
cmpl $0x0, 0x10(%rbx)
jne 0x9bf36
cmpl $0x0, 0x14(%rbx)
je 0x9bf89
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rax
cmpq %rax, %rsi
je 0x9bf54
movl (%rbx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9bf69
movq %r12, %rdi
movq %rbx, %rdx
callq 0xf864
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rax
leaq 0x4(%rbx), %rdx
cmpq %rax, %rsi
je 0x9bf81
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9bf89
movq %r12, %rdi
callq 0xf864
addq $0x28, %rbx
cmpq 0x68(%r15), %rbx
jne 0x9bf2a
movq (%rsp), %r13
movq 0x8(%rsp), %r12
jmp 0x9bfa4
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r12, %rax
subq %r13, %rax
shlq $0x1e, %rax
je 0x9bfe1
movq %rax, %rbx
sarq $0x1e, %rbx
addq %r13, %rbx
sarq $0x20, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x9d26a
movq %r13, %rdi
movq %rbx, %rsi
callq 0x9d34d
cmpq %r12, %r13
je 0x9c059
leaq 0x4(%r13), %rdx
cmpq %r12, %rdx
je 0x9c059
movl -0x4(%rdx), %eax
leaq 0x4(%rdx), %rcx
cmpl (%rdx), %eax
movq %rcx, %rdx
jne 0x9bfea
leaq -0x8(%rcx), %rbx
cmpq %r12, %rcx
je 0x9c01b
movl %eax, %edx
movl (%rcx), %eax
cmpl %eax, %edx
je 0x9c015
movl %eax, 0x4(%rbx)
addq $0x4, %rbx
addq $0x4, %rcx
jmp 0x9c001
addq $0x4, %rbx
cmpq %r12, %rbx
je 0x9c059
movq 0x8(%rsp), %rdx
subq %r12, %rdx
je 0x9c043
movq %rbx, %rdi
movq %r12, %rsi
callq 0x46c0
movq 0x8(%rsp), %rax
movq %rax, %rcx
jmp 0x9c049
movq %r12, %rax
movq %r12, %rcx
subq %r12, %rax
addq %rax, %rbx
cmpq %rbx, %rcx
je 0x9c059
movq %rbx, 0x8(%rsp)
movl $0x0, 0x24(%rsp)
movq 0x48(%r15), %rbp
cmpq 0x50(%r15), %rbp
je 0x9c141
addq $0x48, 0x28(%rsp)
leaq 0x38(%rsp), %rbx
movq %r15, 0x30(%rsp)
movq %r13, %rdi
movq %r12, %rsi
leaq 0x24(%rsp), %rdx
callq 0x9d124
cmpq %r12, %rax
je 0x9c0a6
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0xe9d4
jmp 0x9c12f
movq %r13, %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), %r13
cmpq 0x28(%rbp), %r13
je 0x9c11f
movslq (%r13), %rsi
movq 0x308(%r14), %rax
movq 0x310(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x9c166
leaq (%rax,%rsi,4), %rsi
movq %rbx, %rdi
callq 0x1329a
addq $0x4, %r13
cmpq 0x28(%rbp), %r13
jne 0x9c0d6
cmpq $0x3, 0x60(%rsp)
jbe 0x9c11f
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0xe9d4
movq %rbx, %rdi
callq 0xf206
movq %r15, %r13
movq 0x30(%rsp), %r15
incl 0x24(%rsp)
addq $0x40, %rbp
cmpq 0x50(%r15), %rbp
jne 0x9c07f
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9c157
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 0xb1588(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
jmp 0x9c17c
jmp 0x9c183
jmp 0x9c17c
jmp 0x9c17c
movq %rax, %rbx
jmp 0x9c190
jmp 0x9c183
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xf206
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9c1a6
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780