// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/v_network.cc
// Function: void voronoi_network::add_to_network_internal<voro::voronoicell>(voro::voronoicell&, int, double, double, double, double, int*)
void voronoi_network::add_to_network_internal(v_cell &c,int idn,double x,double y,double z,double rad,int *cmap) {
	int i,j,k,ijk,l,q,ai,aj,ak,*vmp(cmap);
	double gx,gy,vx,vy,vz,crad,*cp(c.pts);
	
	// Loop over the vertices of the Voronoi cell
	for(l=0;l<c.p;l++,vmp+=4) {

		// Compute the real position of this vertex, and evaluate its
		// position along the non-rectangular axes
		vx=x+cp[4*l]*0.5;vy=y+cp[4*l+1]*0.5;vz=z+cp[4*l+2]*0.5;
		gx=vx-vy*(bxy/by)+vz*(bxy*byz-by*bxz)/(by*bz);
		gy=vy-vz*(byz/bz);

		// Compute the adjusted radius, which will be needed either way
		crad=0.5*sqrt(cp[4*l]*cp[4*l]+cp[4*l+1]*cp[4*l+1]+cp[4*l+2]*cp[4*l+2])-rad;
	
		// Check to see if a vertex very close to this one already
		// exists in the network 
		if(search_previous(gx,gy,vx,vy,vz,ijk,q,vmp[1],vmp[2],vmp[3])) {

			// If it does, then just map the Voronoi cell
			// vertex to it
			*vmp=idmem[ijk][q];
			
			// Store this radius if it smaller than the current
			// value
			if(pts[ijk][4*q+3]>crad) pts[ijk][4*q+3]=crad;
		} else {
			k=step_int(vz*zsp);if(k<0||k>=nz) {ak=step_div(k,nz);vx-=bxz*ak;vy-=byz*ak;vz-=bz*ak;k-=ak*nz;} else ak=0;
			j=step_int(gy*ysp);if(j<0||j>=ny) {aj=step_div(j,ny);vx-=bxy*aj;vy-=by*aj;j-=aj*ny;} else aj=0;
			i=step_int(gx*xsp);if(i<0||i>=nx) {ai=step_div(i,nx);vx-=bx*ai;i-=ai*nx;} else ai=0;

			vmp[1]=ai;vmp[2]=aj;vmp[3]=ak;
			ijk=i+nx*(j+ny*k);

			if(edc==edmem) add_edge_network_memory();
			if(ptsc[ijk]==ptsmem[ijk]) add_network_memory(ijk);

			reg[edc]=ijk;regp[edc]=ptsc[ijk];
			pts[ijk][4*ptsc[ijk]]=vx;
			pts[ijk][4*ptsc[ijk]+1]=vy;
			pts[ijk][4*ptsc[ijk]+2]=vz;
			pts[ijk][4*ptsc[ijk]+3]=crad;
			idmem[ijk][ptsc[ijk]++]=edc;
			*vmp=edc++;
		}

		// Add the neighbor information to this vertex
		add_neighbor(*vmp,idn);
	}

	add_edges_to_network(c,x,y,z,rad,cmap);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm2, 0x30(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movq 0x40(%rsi), %rbx
movapd 0x9ed39(%rip), %xmm2    # 0x1005d0
movapd %xmm3, 0x70(%rsp)
xorpd %xmm3, %xmm2
movapd %xmm2, 0x90(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm1, 0x60(%rsp)
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movapd %xmm0, 0x80(%rsp)
addq $0x10, %rbx
movq %rcx, 0x40(%rsp)
leaq 0x8(%rcx), %r12
xorl %r13d, %r13d
movl %edx, 0x18(%rsp)
movslq 0x1c(%r14), %rax
cmpq %rax, %r13
jge 0x61d0f
movupd -0x10(%rbx), %xmm9
movapd %xmm9, %xmm2
mulpd 0xa2619(%rip), %xmm2    # 0x103f10
addpd 0x80(%rsp), %xmm2
movsd (%rbx), %xmm10
movapd %xmm10, %xmm4
movsd 0x9a726(%rip), %xmm7    # 0xfc038
mulsd %xmm7, %xmm4
addsd 0x30(%rsp), %xmm4
movsd 0x8(%r15), %xmm0
movsd 0x10(%r15), %xmm8
movapd %xmm0, %xmm1
divsd %xmm8, %xmm1
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
mulsd %xmm3, %xmm1
movapd %xmm2, %xmm5
subsd %xmm1, %xmm5
movsd 0x20(%r15), %xmm11
movsd 0x18(%r15), %xmm6
mulsd %xmm8, %xmm6
mulsd %xmm11, %xmm0
subsd %xmm6, %xmm0
mulsd %xmm4, %xmm0
movsd 0x28(%r15), %xmm6
mulsd %xmm6, %xmm8
divsd %xmm8, %xmm0
addsd %xmm5, %xmm0
divsd %xmm6, %xmm11
mulsd %xmm4, %xmm11
movapd %xmm3, %xmm1
subsd %xmm11, %xmm1
movapd %xmm9, %xmm5
mulpd %xmm9, %xmm5
unpckhpd %xmm5, %xmm5            # xmm5 = xmm5[1,1]
mulsd %xmm9, %xmm9
addsd %xmm5, %xmm9
mulsd %xmm10, %xmm10
addsd %xmm9, %xmm10
sqrtsd %xmm10, %xmm5
mulsd %xmm7, %xmm5
addsd 0x90(%rsp), %xmm5
movsd %xmm5, 0x38(%rsp)
leaq -0x4(%r12), %rcx
leaq 0x4(%r12), %r9
movq %r15, %rdi
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, 0xa0(%rsp)
movapd %xmm2, 0x20(%rsp)
movsd %xmm4, 0x10(%rsp)
leaq 0x4(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
movq %r12, %r8
callq 0x60ba2
testb %al, %al
je 0x61a54
movq 0x68(%r15), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movslq 0x1c(%rsp), %rax
movl (%rdx,%rax,4), %esi
movl %esi, -0x8(%r12)
movq 0x60(%r15), %rdx
movq (%rdx,%rcx,8), %rcx
leaq (,%rax,4), %rdx
movsd 0x18(%rcx,%rdx,8), %xmm0
movsd 0x38(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x61cf5
leaq 0x3(,%rax,4), %rax
movsd %xmm1, (%rcx,%rax,8)
jmp 0x61cf5
movq %r13, 0x48(%rsp)
movsd 0x50(%r15), %xmm0
movsd 0x10(%rsp), %xmm3
mulsd %xmm3, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
cvttsd2si %xmm0, %r13d
subl %eax, %r13d
setns %al
movl 0x38(%r15), %edi
cmpl %edi, %r13d
setl %dl
xorl %ecx, %ecx
testb %dl, %al
je 0x61a9b
xorl %esi, %esi
movapd 0x20(%rsp), %xmm2
jmp 0x61ae9
testl %r13d, %r13d
js 0x61aaa
movl %r13d, %eax
cltd
idivl %edi
movl %eax, %esi
jmp 0x61ab5
leal 0x1(%r13), %eax
cltd
idivl %edi
movl %eax, %esi
decl %esi
cvtsi2sd %esi, %xmm0
movupd 0x18(%r15), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
mulpd %xmm1, %xmm2
mulsd 0x28(%r15), %xmm0
movapd 0x20(%rsp), %xmm1
subpd %xmm2, %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm3
imull %esi, %edi
subl %edi, %r13d
movapd 0xa0(%rsp), %xmm1
mulsd 0x48(%r15), %xmm1
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
seta %al
cvttsd2si %xmm1, %edi
subl %eax, %edi
setns %al
movl 0x34(%r15), %r8d
cmpl %r8d, %edi
setl %dl
testb %dl, %al
jne 0x61b52
testl %edi, %edi
js 0x61b2a
movl %edi, %eax
cltd
idivl %r8d
movl %eax, %ecx
jmp 0x61b35
leal 0x1(%rdi), %eax
cltd
idivl %r8d
movl %eax, %ecx
decl %ecx
cvtsi2sd %ecx, %xmm0
movupd 0x8(%r15), %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
subpd %xmm0, %xmm2
imull %ecx, %r8d
subl %r8d, %edi
movsd 0x8(%rsp), %xmm1
mulsd 0x40(%r15), %xmm1
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
seta %al
cvttsd2si %xmm1, %r8d
subl %eax, %r8d
setns %al
movl 0x30(%r15), %r9d
cmpl %r9d, %r8d
setl %dl
testb %dl, %al
je 0x61b8e
xorl %eax, %eax
movsd %xmm2, 0x8(%rsp)
jmp 0x61bc4
testl %r8d, %r8d
js 0x61b9c
movl %r8d, %eax
cltd
idivl %r9d
jmp 0x61ba6
leal 0x1(%r8), %eax
cltd
idivl %r9d
decl %eax
cvtsi2sd %eax, %xmm0
mulsd (%r15), %xmm0
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
imull %eax, %r9d
subl %r9d, %r8d
movq %r14, %rbp
movl %eax, -0x4(%r12)
movl %ecx, (%r12)
movl %esi, 0x4(%r12)
imull 0x34(%r15), %r13d
addl %edi, %r13d
imull 0x30(%r15), %r13d
addl %r8d, %r13d
movl %r13d, 0x4(%rsp)
movl 0xa0(%r15), %eax
cmpl 0xa4(%r15), %eax
movapd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x10(%rsp)
jne 0x61c1a
movq %r15, %rdi
callq 0x5fdd2
movsd 0x10(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movq 0x70(%r15), %rax
movq 0x78(%r15), %rcx
movslq %r13d, %r14
movl (%rax,%r14,4), %edx
cmpl (%rcx,%r14,4), %edx
jne 0x61c4a
movq %r15, %rdi
movl %r13d, %esi
callq 0x5fcd4
movsd 0x10(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movq 0x70(%r15), %rax
movq 0xc0(%r15), %rcx
movslq 0xa0(%r15), %rdx
movl %r13d, (%rcx,%rdx,4)
movslq (%rax,%r14,4), %rcx
movq 0xc8(%r15), %rdx
movslq 0xa0(%r15), %rsi
movl %ecx, (%rdx,%rsi,4)
movq 0x60(%r15), %rdx
movq (%rdx,%r14,8), %rdx
leaq (,%rcx,4), %rsi
movq %rcx, %rdi
shlq $0x5, %rdi
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rdx,%rdi)
leal 0x1(%rsi), %edi
movslq %edi, %rdi
movhpd %xmm2, (%rdx,%rdi,8)
leal 0x2(%rsi), %edi
movslq %edi, %rdi
movsd %xmm3, (%rdx,%rdi,8)
orl $0x3, %esi
movslq %esi, %rsi
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
movl 0xa0(%r15), %edx
movq 0x68(%r15), %rsi
movq (%rsi,%r14,8), %rsi
leal 0x1(%rcx), %edi
movl %edi, (%rax,%r14,4)
movl %edx, (%rsi,%rcx,4)
movl 0xa0(%r15), %esi
leal 0x1(%rsi), %eax
movl %eax, 0xa0(%r15)
movl %esi, -0x8(%r12)
movq %rbp, %r14
movl 0x18(%rsp), %ebp
movq 0x48(%rsp), %r13
movq %r15, %rdi
movl %ebp, %edx
callq 0x62d22
incq %r13
addq $0x20, %rbx
addq $0x10, %r12
jmp 0x618d7
movq %r15, %rdi
movq %r14, %rsi
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movaps 0x70(%rsp), %xmm3
movq 0x40(%rsp), %rdx
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x62da6
nop