// File: /workspace/github_cpp_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %r9, %r13
movq %rsi, 0x18(%rsp)
movq %rdi, %r15
leaq 0x20(%rsp), %r14
movq %rdx, (%r14)
movl %ecx, 0x8(%r14)
movq %r8, 0xf0(%rsp)
movq %r8, %rdi
callq 0xd678
movq %r13, %rdi
callq 0xf2de
leaq 0x60(%rsp), %rbx
pushq $0x1
popq %rcx
movq %rbx, %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x3d328
movq %rbx, %rdi
movq %r14, %rbx
movq %r14, %rsi
callq 0x3d398
movq %rax, 0x118(%rsp)
movl %edx, 0x120(%rsp)
movq 0x50(%r15), %rax
subq 0x48(%r15), %rax
leaq 0x48(%r15), %rcx
movq %rcx, 0x110(%rsp)
shrq $0x6, %rax
movq %rax, 0x30(%rsp)
leaq 0x60(%r15), %rax
movq %rax, 0x58(%rsp)
xorl %ebp, %ebp
leaq 0x4c(%rsp), %r12
leaq 0xa0(%rsp), %r14
movl %ebp, %ebp
movq 0x68(%r15), %rax
subq 0x60(%r15), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %rbp, %rax
jbe 0x5ef7
movq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0xa822
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x40896
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movl 0x78(%rsp), %ecx
movq %r12, %rdi
callq 0x3d328
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3d364
movq %rax, 0xa0(%rsp)
movl %edx, 0xa8(%rsp)
movq %r14, %rdi
callq 0x3d3d6
testb %al, %al
jne 0x5ef0
cmpl $0x0, 0xa0(%rsp)
js 0x5ee3
cmpl $0x0, 0xa4(%rsp)
js 0x5ee3
cmpl $0x0, 0xa8(%rsp)
jns 0x5ef0
movq %r13, %rdi
leaq 0x64(%rsp), %rsi
callq 0xf334
incl %ebp
jmp 0x5e56
movq 0x18(%rsp), %rbx
leaq 0x48(%rbx), %rdi
movq %rdi, 0x100(%rsp)
callq 0xa840
movq 0x60(%rbx), %rax
cmpq %rax, 0x68(%rbx)
je 0x5f20
movq 0x18(%rsp), %rcx
movq %rax, 0x68(%rcx)
movq 0x18(%rsp), %r12
leaq 0x60(%r12), %rax
movq %rax, 0x108(%rsp)
leaq 0x20(%rsp), %rbx
imull $0xa, (%rbx), %eax
cvtsi2sd %eax, %xmm0
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x640ba
movq 0x10(%rbp), %rax
movq %rax, 0x10(%r12)
movups (%rbp), %xmm0
movups %xmm0, (%r12)
leaq 0x18(%r15), %rsi
imull $0xa, 0x4(%rbx), %eax
cvtsi2sd %eax, %xmm0
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x640ba
movq 0x10(%r14), %rax
movq %rax, 0x28(%r12)
movups (%r14), %xmm0
movups %xmm0, 0x18(%r12)
leaq 0x30(%r15), %rsi
imull $0xa, 0x8(%rbx), %eax
cvtsi2sd %eax, %xmm0
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x640ba
movq 0x10(%r14), %rax
movq %rax, 0x40(%r12)
movups (%r14), %xmm0
movups %xmm0, 0x30(%r12)
leaq 0x14(%rsp), %rax
andl $0x0, (%rax)
leaq 0x8(%r13), %rax
movq %rax, 0xf8(%rsp)
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r12
movq %r13, 0xe8(%rsp)
cmpl $0xb, %ebx
movq 0xf0(%rsp), %r14
je 0x62db
xorl %eax, %eax
movl %eax, 0x8(%rsp)
cmpl 0x30(%rsp), %eax
jge 0x6141
movslq %eax, %rsi
movq 0x110(%rsp), %rdi
callq 0xa848
movq %rbp, %rdi
movq %rax, %rsi
callq 0xa86a
movq %r12, %rdi
callq 0x408b6
movl 0x20(%rsp), %eax
imull %ebx, %eax
cvtsi2sd %eax, %xmm0
movl 0x24(%rsp), %eax
imull %ebx, %eax
cvtsi2sd %eax, %xmm1
movl 0x28(%rsp), %eax
imull %ebx, %eax
cvtsi2sd %eax, %xmm2
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movupd (%r15), %xmm4
mulpd %xmm3, %xmm4
movupd 0x18(%r15), %xmm3
addpd 0x60(%rsp), %xmm4
movupd 0x30(%r15), %xmm5
movapd %xmm1, %xmm6
unpcklpd %xmm1, %xmm6            # xmm6 = xmm6[0],xmm1[0]
mulpd %xmm3, %xmm6
addpd %xmm4, %xmm6
movapd %xmm2, %xmm3
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
mulpd %xmm5, %xmm3
addpd %xmm6, %xmm3
movapd %xmm3, 0xa0(%rsp)
mulsd 0x10(%r15), %xmm0
addsd 0x70(%rsp), %xmm0
mulsd 0x28(%r15), %xmm1
addsd %xmm0, %xmm1
mulsd 0x40(%r15), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0xb0(%rsp)
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0x100(%rsp), %rdi
movq %r12, %rsi
callq 0xa89e
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0xf68e
cmpq 0xf8(%rsp), %rax
je 0x6118
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
callq 0xf334
movl 0x14(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x50(%rsp)
movq %r14, %rdi
leaq 0x4c(%rsp), %rsi
callq 0xf6e0
incl 0x14(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0xb290
leaq 0x80(%rsp), %rdi
callq 0xb290
movl 0x8(%rsp), %eax
incl %eax
jmp 0x5ff1
movl %ebx, %eax
imull 0x30(%rsp), %eax
movl %eax, 0x18(%rsp)
xorl %r14d, %r14d
movl %r14d, %r14d
movq 0x68(%r15), %rax
subq 0x60(%r15), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %r14, %rax
jbe 0x62cc
movq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0xa822
movq %rbp, %r13
movq %rbp, %rdi
movq %rax, %rsi
callq 0x40896
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movl 0x78(%rsp), %ecx
leaq 0x4c(%rsp), %rbp
movq %rbp, %rdi
callq 0x3d328
movq %rbp, %rdi
leaq 0x118(%rsp), %rsi
callq 0x3d364
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3d364
movq %rax, 0x38(%rsp)
movl %edx, 0x40(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x3d3d6
xorl %ebp, %ebp
testb %al, %al
jne 0x61f0
movl 0x3c(%rsp), %ebp
orl 0x38(%rsp), %ebp
orl 0x40(%rsp), %ebp
sarl $0x1f, %ebp
orl $0x1, %ebp
addl %ebx, %ebp
js 0x6215
cmpl $0xb, %ebp
jb 0x6251
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3d380
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
xorl %ebp, %ebp
jmp 0x6251
orl $-0x1, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x3d34a
movq %rax, 0xa0(%rsp)
movl %edx, 0xa8(%rsp)
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x3d380
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
pushq $0xa
popq %rbp
movq %r12, %rdi
callq 0x40878
movl 0x60(%rsp), %eax
addl 0x18(%rsp), %eax
movl %eax, 0xa0(%rsp)
imull 0x30(%rsp), %ebp
addl 0x64(%rsp), %ebp
movl %ebp, 0xa4(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd %xmm0, 0xa8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0xb8(%rsp)
movsd %xmm1, 0xc0(%rsp)
movq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0xa8ca
incl %r14d
movq %r13, %rbp
jmp 0x614f
incl %ebx
movq 0xe8(%rsp), %r13
jmp 0x5fde
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x62f6
movq %rax, %rbx
jmp 0x6306
jmp 0x62f6
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0xb290
leaq 0x80(%rsp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780