// File: 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
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xd0d0
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0x263c0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0x26230
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x59a50
testb $0x1, %al
jne 0x10bf88
jmp 0x10c00a
leaq -0x38(%rbp), %rdi
callq 0x59a90
cmpl $0x0, 0x10(%rax)
jne 0x10bfb5
leaq -0x38(%rbp), %rdi
callq 0x59a90
cmpl $0x0, 0x14(%rax)
jne 0x10bfb5
leaq -0x38(%rbp), %rdi
callq 0x59a90
cmpl $0x0, 0x14(%rax)
je 0x10bffa
leaq -0x38(%rbp), %rdi
callq 0x59a90
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0xd1b0
jmp 0x10bfcc
leaq -0x38(%rbp), %rdi
callq 0x59a90
movq %rax, %rsi
addq $0x4, %rsi
leaq -0x30(%rbp), %rdi
callq 0xd1b0
jmp 0x10bfe7
jmp 0x10bffa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x10c35f
jmp 0x10bffc
leaq -0x38(%rbp), %rdi
callq 0x10cee0
jmp 0x10bf61
leaq -0x30(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x15890
movq -0x138(%rbp), %rdi
movq %rax, -0x58(%rbp)
callq 0x15720
movq -0x138(%rbp), %rdi
movq %rax, -0x60(%rbp)
callq 0x10090
movl %eax, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movslq -0x64(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x18ae0
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x10cf70
jmp 0x10c065
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x10d040
movq %rax, -0x140(%rbp)
jmp 0x10c097
movq -0x140(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x10d080
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x10d080
movq -0x80(%rbp), %rsi
movq -0xa0(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x10cfb0
movq %rax, -0x148(%rbp)
jmp 0x10c0e2
movq -0x148(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
addq $0x308, %rax            # imm = 0x308
movq %rax, -0xb0(%rbp)
movl $0x0, -0xb4(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x25230
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x250b0
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x599b0
testb $0x1, %al
jne 0x10c14f
jmp 0x10c34d
movq -0x58(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0xb4(%rbp), %rdx
callq 0x10cc40
movq %rax, -0x150(%rbp)
jmp 0x10c188
movq -0x150(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x10d0c0
testb $0x1, %al
jne 0x10c1ac
jmp 0x10c1dd
movq -0x18(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x158(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xaed90
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0xf440
jmp 0x10c1d8
jmp 0x10c32b
leaq -0x110(%rbp), %rdi
callq 0xf690
leaq -0xc0(%rbp), %rdi
callq 0x599f0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x15890
movq %rax, -0x118(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x599f0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x15720
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x10d0c0
testb $0x1, %al
jne 0x10c243
jmp 0x10c2df
movq -0xb0(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x29910
movq -0x168(%rbp), %rdi
movslq (%rax), %rsi
callq 0x101d0
movq %rax, -0x160(%rbp)
jmp 0x10c275
movq -0x160(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0xf300
movb %dl, -0x171(%rbp)
movq %rax, -0x170(%rbp)
jmp 0x10c297
movb -0x171(%rbp), %al
movq -0x170(%rbp), %rcx
movq %rcx, -0x130(%rbp)
movb %al, -0x128(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x10d100
jmp 0x10c208
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xf880
jmp 0x10c35f
leaq -0x110(%rbp), %rdi
callq 0x10d120
cmpq $0x4, %rax
jb 0x10c31f
movq -0x18(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x180(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xaed90
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0xf440
jmp 0x10c31d
jmp 0x10c31f
leaq -0x110(%rbp), %rdi
callq 0xf880
jmp 0x10c32d
leaq -0xc0(%rbp), %rdi
callq 0xb4bd0
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x10c11f
leaq -0x30(%rbp), %rdi
callq 0xec80
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0xec80
movq -0x48(%rbp), %rdi
callq 0x58f0
nopw %cs:(%rax,%rax)