// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/network.cc
// Function: extendVorNet(VORONOI_NETWORK*, VORONOI_NETWORK*, DELTA_POS, std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int>>>*, std::set<int, std::less<int>, std::allocator<int>>*)
void extendVorNet(VORONOI_NETWORK *vornet, VORONOI_NETWORK *newNet, DELTA_POS direction, map<int,int> *idAliases, set<int> *sourceNodes){
  idAliases->clear();
  sourceNodes->clear();

  DELTA_POS filter = DELTA_POS(1,1,1) - direction;
  int numIDs = vornet->nodes.size();
  
  for(unsigned int i = 0; i < vornet->edges.size(); i++){
    VOR_EDGE curEdge = vornet->edges.at(i);
    DELTA_POS dirComp = DELTA_POS(curEdge.delta_uc_x, curEdge.delta_uc_y, curEdge.delta_uc_z)*direction;
    if(dirComp.isZero())
      continue;
    else if ((dirComp.x < 0) || (dirComp.y < 0) || (dirComp.z < 0)){
      sourceNodes->insert(curEdge.to);
    }
  }

  newNet->nodes.clear();
  newNet->edges.clear();
  int factor = 10;
  newNet->v_a = vornet->v_a.scale(direction.x * factor);
  newNet->v_b = vornet->v_b.scale(direction.y * factor);
  newNet->v_c = vornet->v_c.scale(direction.z * factor);

  //Repeat copy process for each additional unit cell
  int idCount = 0;
  for(int i = 0; i <= factor; i++){
    
    //Translate all of the Voronoi nodes and assign them new id's
    for(int j = 0; j < numIDs; j++){
      VOR_NODE oldNode = vornet->nodes.at(j);
      VOR_NODE newNode; 
      newNode.x = oldNode.x + i*direction.x*vornet->v_a.x + i*direction.y*vornet->v_b.x + i*direction.z*vornet->v_c.x; 
      newNode.y = oldNode.y + i*direction.x*vornet->v_a.y + i*direction.y*vornet->v_b.y + i*direction.z*vornet->v_c.y; 
      newNode.z = oldNode.z + i*direction.x*vornet->v_a.z + i*direction.y*vornet->v_b.z + i*direction.z*vornet->v_c.z; 
      newNode.rad_stat_sphere = oldNode.rad_stat_sphere;
      newNet->nodes.push_back(newNode);
      if(sourceNodes->find(j) != sourceNodes->end()){
	sourceNodes->insert(idCount);
	idAliases->insert(pair<int,int> (idCount,j));
      }
      idCount++;
    }

    //Translate all of the Voronoi edges, modifying the connectivity information as is appropriate
    for(unsigned int j = 0; j < vornet->edges.size(); j++){
      VOR_EDGE oldEdge = vornet->edges.at(j);
      DELTA_POS oldDirection = DELTA_POS(oldEdge.delta_uc_x, oldEdge.delta_uc_y, oldEdge.delta_uc_z);
      DELTA_POS newDirection = oldDirection*filter;
      DELTA_POS dirComp = oldDirection*direction;

      int changeInTo;
      if(dirComp.isZero())
	changeInTo = 0;
      else if ((dirComp.x < 0) || (dirComp.y < 0) || (dirComp.z < 0))
	changeInTo = -1;
      else
	changeInTo = 1;
     
      int newTo = i + changeInTo;
      if(newTo < 0){
	newDirection = newDirection + (direction*(-1));
	newTo = factor;
      }
      else if (newTo > factor){
	newDirection = newDirection + direction;
	newTo = 0;
      }
 
      VOR_EDGE newEdge;
      newEdge.from = oldEdge.from + i*numIDs; 
      newEdge.to = oldEdge.to + newTo*numIDs; 
      newEdge.rad_moving_sphere = oldEdge.rad_moving_sphere; 
    
      newEdge.delta_uc_x = newDirection.x;
      newEdge.delta_uc_y = newDirection.y; 
      newEdge.delta_uc_z = newDirection.z;
      newEdge.length = oldEdge.length;
      newNet->edges.push_back(newEdge);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r9, %rbx
movq %rsi, 0x38(%rsp)
movq %rdi, %r15
leaq 0x20(%rsp), %r14
movq %rdx, (%r14)
movl %ecx, 0x8(%r14)
movq %r8, 0xe8(%rsp)
movq %r8, %rdi
callq 0x116a8
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x132c8
leaq 0x50(%rsp), %r12
movl $0x1, %ebx
movq %r12, %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x509d8
movq %r12, %rdi
movq %r14, %rsi
callq 0x50a48
movq %rax, 0x108(%rsp)
movl %edx, 0x110(%rsp)
movq 0x50(%r15), %rax
subq 0x48(%r15), %rax
movq %rax, 0x18(%rsp)
movq 0x60(%r15), %rax
cmpq %rax, 0x68(%r15)
je 0x81af
xorl %ecx, %ecx
leaq 0x50(%rsp), %r13
leaq 0x9c(%rsp), %rbp
leaq 0x20(%rsp), %r12
leaq 0xa8(%rsp), %r14
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r13, %rdi
callq 0x5552c
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
movq %rbp, %rdi
callq 0x509d8
movq %rbp, %rdi
movq %r12, %rsi
callq 0x50a14
movq %rax, 0xa8(%rsp)
movl %edx, 0xb0(%rsp)
movq %r14, %rdi
callq 0x50a86
testb %al, %al
jne 0x8185
cmpl $0x0, 0xa8(%rsp)
js 0x8176
cmpl $0x0, 0xac(%rsp)
js 0x8176
cmpl $0x0, 0xb0(%rsp)
jns 0x8185
movq 0x30(%rsp), %rdi
leaq 0x54(%rsp), %rsi
callq 0x132f6
movl %ebx, %ecx
movq 0x60(%r15), %rax
movq 0x68(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %ebx
cmpq %rcx, %rdx
ja 0x810e
shrq $0x6, 0x18(%rsp)
movq 0x38(%rsp), %r12
leaq 0x48(%r12), %rdi
movq 0x48(%r12), %rsi
movq %rdi, 0xf8(%rsp)
callq 0x13406
movq 0x60(%r12), %rax
cmpq %rax, 0x68(%r12)
je 0x81e2
movq %rax, 0x68(%r12)
leaq 0x60(%r12), %rax
movq %rax, 0x100(%rsp)
leaq 0x20(%rsp), %rbx
movl (%rbx), %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
cvtsi2sd %eax, %xmm0
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x85a34
movq 0x10(%r14), %rax
movq %rax, 0x10(%r12)
movups (%r14), %xmm0
movups %xmm0, (%r12)
leaq 0x18(%r15), %rsi
movl 0x4(%rbx), %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x85a34
movq 0x10(%r14), %rax
movq %rax, 0x28(%r12)
movups (%r14), %xmm0
movups %xmm0, 0x18(%r12)
leaq 0x30(%r15), %rsi
movl 0x8(%rbx), %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x85a34
movq 0x10(%r14), %rax
movq %rax, 0x40(%r12)
movups (%r14), %xmm0
movups %xmm0, 0x30(%r12)
leaq 0x4(%rsp), %rax
movl $0x0, (%rax)
movq 0x30(%rsp), %r14
leaq 0x8(%r14), %rbx
movq 0x18(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0xf0(%rsp)
xorl %ebp, %ebp
cmpl $0x0, 0x18(%rsp)
jle 0x84c3
xorl %r12d, %r12d
movq 0x48(%r15), %rax
movq 0x50(%r15), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r12, %rdx
jbe 0x869e
movq %r12, %rcx
shlq $0x6, %rcx
leaq (%rax,%rcx), %r13
addq $0x20, %r13
movups -0x20(%r13), %xmm0
movupd -0x10(%r13), %xmm1
movapd %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0xe886
movb 0x18(%r13), %al
leaq 0xa8(%rsp), %r13
movb %al, 0x88(%rsp)
movq %r13, %rdi
callq 0x55554
movl 0x20(%rsp), %eax
imull %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%r15), %xmm2
mulsd %xmm0, %xmm2
addsd 0x50(%rsp), %xmm2
movl 0x24(%rsp), %eax
imull %ebp, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x18(%r15), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movl 0x28(%rsp), %eax
imull %ebp, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movsd 0x30(%r15), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
movsd %xmm4, 0xa8(%rsp)
movsd 0x8(%r15), %xmm3
mulsd %xmm0, %xmm3
addsd 0x58(%rsp), %xmm3
movsd 0x20(%r15), %xmm4
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movsd 0x38(%r15), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, 0xb0(%rsp)
mulsd 0x10(%r15), %xmm0
addsd 0x60(%rsp), %xmm0
mulsd 0x28(%r15), %xmm1
addsd %xmm0, %xmm1
mulsd 0x40(%r15), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0xb8(%rsp)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
movq 0xf8(%rsp), %rdi
movq %r13, %rsi
callq 0xe962
movq 0x10(%r14), %rcx
movq %rbx, %rax
testq %rcx, %rcx
je 0x8427
movq %rbx, %rax
movslq 0x20(%rcx), %rdx
xorl %esi, %esi
cmpq %rdx, %r12
setg %sil
cmovleq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x840c
movq %rbx, %rcx
cmpq %rbx, %rax
je 0x843d
movslq 0x20(%rax), %rcx
cmpq %rcx, %r12
cmovlq %rbx, %rax
movq %rax, %rcx
cmpq %rbx, %rcx
je 0x8477
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
callq 0x132f6
movl 0x4(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl %r12d, 0xa0(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0x9c(%rsp), %rsi
callq 0x13690
incl 0x4(%rsp)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x8498
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x84b2
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incq %r12
cmpq 0xf0(%rsp), %r12
jne 0x82bd
movq 0x60(%r15), %rax
cmpq %rax, 0x68(%r15)
je 0x867c
movl %ebp, %ecx
imull 0x18(%rsp), %ecx
movl %ecx, 0x38(%rsp)
movl $0x1, %r13d
xorl %ecx, %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x50(%rsp), %rdi
callq 0x5552c
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
leaq 0x9c(%rsp), %r14
movq %r14, %rdi
callq 0x509d8
movq %r14, %rdi
leaq 0x108(%rsp), %rsi
callq 0x50a14
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x50a14
movq %rax, 0x40(%rsp)
movl %edx, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x50a86
xorl %r14d, %r14d
testb %al, %al
jne 0x8569
movl 0x44(%rsp), %r14d
orl 0x40(%rsp), %r14d
orl 0x48(%rsp), %r14d
sarl $0x1f, %r14d
orl $0x1, %r14d
addl %ebp, %r14d
js 0x8591
cmpl $0xb, %r14d
jl 0x85d8
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x50a30
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
xorl %r14d, %r14d
jmp 0x85d8
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %rdi
leaq 0x4c(%rsp), %rsi
callq 0x509fa
movq %rax, 0xa8(%rsp)
movl %edx, 0xb0(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x50a30
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
movl $0xa, %r14d
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
callq 0x5550e
movl 0x50(%rsp), %eax
addl 0x38(%rsp), %eax
movl %eax, 0xa8(%rsp)
imull 0x18(%rsp), %r14d
addl 0x54(%rsp), %r14d
movl %r14d, 0xac(%rsp)
movsd 0x58(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
movsd %xmm0, 0xb0(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0xb8(%rsp)
movq 0xc(%rsp), %rax
movq %rax, 0xbc(%rsp)
movsd %xmm1, 0xc8(%rsp)
movq 0x100(%rsp), %rdi
movq %r12, %rsi
callq 0xe9ba
movl %r13d, %ecx
movq 0x60(%r15), %rax
movq 0x68(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %r13d
cmpq %rcx, %rdx
ja 0x84e4
incl %ebp
cmpl $0xb, %ebp
movq 0x30(%rsp), %r14
jne 0x82af
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x147000(%rip), %rdi    # 0x14f6a5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x86b6
movq %rax, %rbx
jmp 0x86d6
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x86d6
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x86f0
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780