// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rsi, 0x30(%rsp)
movq %rdi, %r15
leaq 0x20(%rsp), %rbx
movq %rdx, (%rbx)
movl %ecx, 0x8(%rbx)
movq %r8, 0xe8(%rsp)
movq %r8, %rdi
callq 0x116ea
movq %r14, 0x38(%rsp)
movq %r14, %rdi
callq 0x1326c
leaq 0x50(%rsp), %r12
movl $0x1, %r14d
movq %r12, %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x506b0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x50720
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 0x8333
xorl %ecx, %ecx
leaq 0x50(%rsp), %r12
leaq 0x94(%rsp), %r13
leaq 0x20(%rsp), %rbp
leaq 0xa0(%rsp), %rbx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r12, %rdi
callq 0x551fc
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
movq %r13, %rdi
callq 0x506b0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x506ec
movq %rax, 0xa0(%rsp)
movl %edx, 0xa8(%rsp)
movq %rbx, %rdi
callq 0x5075e
testb %al, %al
jne 0x8307
cmpl $0x0, 0xa0(%rsp)
js 0x82f8
cmpl $0x0, 0xa4(%rsp)
js 0x82f8
cmpl $0x0, 0xa8(%rsp)
jns 0x8307
movq 0x38(%rsp), %rdi
leaq 0x54(%rsp), %rsi
callq 0x1329a
movl %r14d, %ecx
movq 0x60(%r15), %rax
movq 0x68(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %r14d
cmpq %rcx, %rdx
ja 0x8290
shrq $0x6, 0x18(%rsp)
movq 0x30(%rsp), %r12
leaq 0x48(%r12), %rdi
movq 0x48(%r12), %rsi
movq %rdi, 0xf8(%rsp)
callq 0x133a8
movq 0x60(%r12), %rax
cmpq %rax, 0x68(%r12)
je 0x8366
movq %rax, 0x68(%r12)
leaq 0x60(%r12), %rax
movq %rax, 0x100(%rsp)
leaq 0x20(%rsp), %r14
movl (%r14), %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
cvtsi2sd %eax, %xmm0
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x84416
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r12)
movups (%rbx), %xmm0
movups %xmm0, (%r12)
leaq 0x18(%r15), %rsi
movl 0x4(%r14), %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x84416
movq 0x10(%rbx), %rax
movq %rax, 0x28(%r12)
movups (%rbx), %xmm0
movups %xmm0, 0x18(%r12)
leaq 0x30(%r15), %rsi
movl 0x8(%r14), %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x84416
movq 0x10(%rbx), %rax
movq %rax, 0x40(%r12)
movups (%rbx), %xmm0
movups %xmm0, 0x30(%r12)
leaq 0x4(%rsp), %rax
movl $0x0, (%rax)
movq 0x38(%rsp), %rbp
leaq 0x8(%rbp), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0xf0(%rsp)
xorl %r13d, %r13d
leaq 0xa0(%rsp), %r14
cmpl $0x0, 0x18(%rsp)
jle 0x8628
xorl %ebx, %ebx
movq 0x48(%r15), %rax
movq 0x50(%r15), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %rbx, %rdx
jbe 0x87e7
movq %rbx, %rcx
shlq $0x6, %rcx
leaq (%rax,%rcx), %r12
addq $0x20, %r12
movups -0x20(%r12), %xmm0
movupd -0x10(%r12), %xmm1
movapd %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0xe8f8
movb 0x18(%r12), %al
movb %al, 0x88(%rsp)
movq %r14, %rdi
callq 0x5521c
movl 0x20(%rsp), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0x24(%rsp), %eax
imull %r13d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl 0x28(%rsp), %eax
imull %r13d, %eax
xorps %xmm2, %xmm2
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 0x50(%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 0x60(%rsp), %xmm0
mulsd 0x28(%r15), %xmm1
addsd %xmm0, %xmm1
mulsd 0x40(%r15), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0xb0(%rsp)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0xf8(%rsp), %rdi
movq %r14, %rsi
callq 0xe9d4
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x85dc
movq 0x30(%rsp), %rcx
movslq 0x20(%rax), %rdx
xorl %esi, %esi
cmpq %rdx, %rbx
setg %sil
cmovleq %rax, %rcx
movq 0x10(%rax,%rsi,8), %rax
testq %rax, %rax
jne 0x857d
cmpq 0x30(%rsp), %rcx
je 0x85dc
movslq 0x20(%rcx), %rax
cmpq %rax, %rbx
jl 0x85dc
movq %rbp, %rdi
leaq 0x4(%rsp), %rsi
callq 0x1329a
movl 0x4(%rsp), %eax
movl %eax, 0x94(%rsp)
movl %ebx, 0x98(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x135ee
incl 0x4(%rsp)
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x85fd
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8617
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incq %rbx
cmpq 0xf0(%rsp), %rbx
jne 0x844e
movq 0x60(%r15), %rax
cmpq %rax, 0x68(%r15)
je 0x87c3
movl %r13d, %ebx
imull 0x18(%rsp), %ebx
movl $0x1, %r12d
xorl %ecx, %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x50(%rsp), %rdi
callq 0x551fc
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
leaq 0x94(%rsp), %rbp
movq %rbp, %rdi
callq 0x506b0
movq %rbp, %rdi
leaq 0x108(%rsp), %rsi
callq 0x506ec
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x506ec
movq %rax, 0x40(%rsp)
movl %edx, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x5075e
xorl %ebp, %ebp
testb %al, %al
jne 0x86c5
movl 0x44(%rsp), %ebp
orl 0x40(%rsp), %ebp
orl 0x48(%rsp), %ebp
sarl $0x1f, %ebp
orl $0x1, %ebp
addl %r13d, %ebp
js 0x86eb
cmpl $0xb, %ebp
jb 0x872c
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x50708
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
xorl %ebp, %ebp
jmp 0x872c
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %rdi
leaq 0x4c(%rsp), %rsi
callq 0x506d2
movq %rax, 0xa0(%rsp)
movl %edx, 0xa8(%rsp)
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x50708
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
movl $0xa, %ebp
movq %r14, %rdi
callq 0x551de
movl 0x50(%rsp), %eax
addl %ebx, %eax
movl %eax, 0xa0(%rsp)
imull 0x18(%rsp), %ebp
addl 0x54(%rsp), %ebp
movl %ebp, 0xa4(%rsp)
movsd 0x58(%rsp), %xmm0
movsd 0x70(%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 0x100(%rsp), %rdi
movq %r14, %rsi
callq 0xea2c
movl %r12d, %ecx
movq 0x60(%r15), %rax
movq 0x68(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %r12d
cmpq %rcx, %rdx
ja 0x8646
incl %r13d
cmpl $0xb, %r13d
movq 0x38(%rsp), %rbp
jne 0x8441
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x144f07(%rip), %rdi    # 0x14d6f5
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x87ff
movq %rax, %rbx
jmp 0x881f
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x881f
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8839
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780