// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/sphere_approx.cc
// Function: AtomCluster::calc_center(std::vector<ATOM, std::allocator<ATOM>>, int, int, int, int, int, double)
ATOM AtomCluster::calc_center(vector <ATOM> old_coords, int i_0, int i_1, int i_2, int i_3, int i_4, double shift){
	ATOM origin = center;

	vector <ATOM> coords;

	coords.push_back(old_coords.at(i_0));
	coords.push_back(old_coords.at(i_1));
	coords.push_back(old_coords.at(i_2));
	coords.push_back(old_coords.at(i_3));
	coords.push_back(old_coords.at(i_4));

	double x_sum = 0;
	double y_sum = 0;
	double z_sum = 0;
	for (int i = 0; i<coords.size(); i++){
		x_sum = x_sum + coords.at(i).x;
		y_sum = y_sum + coords.at(i).y;
		z_sum = z_sum + coords.at(i).z;
	}

	double n = coords.size();

	ATOM center_sphere;

//translation vector
	double x = (x_sum/n)-origin.x;
	double y = (y_sum/n)-origin.y;
	double z = (z_sum/n)-origin.z;
	
	double norm = sqrt(x*x + y*y + z*z);
	double scaled_shift = shift/norm;

	center_sphere.x = x*scaled_shift + origin.x;
	center_sphere.y = y*scaled_shift + origin.y;
	center_sphere.z = z*scaled_shift + origin.z;
	center_sphere.radius = smallSphereRadius;

	return center_sphere;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movapd %xmm0, 0x40(%rsp)
movl %r9d, %ebp
movl %r8d, %r12d
movl %ecx, %r13d
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
addq $0xa0, %rsi
leaq 0x60(%rsp), %rdi
callq 0xa75c
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movslq %r13d, %rsi
movq %r15, %rdi
callq 0xa73a
movq %rsp, %rdi
movq %rax, %rsi
callq 0xa7d8
movslq %r12d, %rsi
movq %r15, %rdi
callq 0xa73a
movq %rsp, %rdi
movq %rax, %rsi
callq 0xa7d8
movslq %ebp, %rsi
movq %r15, %rdi
callq 0xa73a
movq %rsp, %rdi
movq %rax, %rsi
callq 0xa7d8
movslq 0x130(%rsp), %rsi
movq %r15, %rdi
callq 0xa73a
movq %rsp, %rdi
movq %rax, %rsi
callq 0xa7d8
movslq 0x138(%rsp), %rsi
movq %r15, %rdi
callq 0xa73a
movq %rsp, %rdi
movq %rax, %rsi
callq 0xa7d8
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r15d, %r15d
movl $0x98, %ebp
movq %rsp, %r12
movq 0x8(%rsp), %rax
subq (%rsp), %rax
cqto
idivq %rbp
cmpq %r15, %rax
jbe 0x6d86c
movq %r12, %rdi
movq %r15, %rsi
callq 0xa73a
movsd (%rax), %xmm0
addsd 0x20(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xa73a
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xa73a
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd 0x38(%rsp), %xmm0
movapd 0x50(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movsd 0x18(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
incq %r15
movapd %xmm1, 0x20(%rsp)
jmp 0x6d7e4
movq %rax, %r13
movq %rbx, %rdi
callq 0x3dc5a
cvtsi2sd %r13, %xmm1
movsd 0x18(%rsp), %xmm4
divsd %xmm1, %xmm4
leaq 0x60(%rsp), %r15
movsd 0x10(%r15), %xmm0
subsd %xmm0, %xmm4
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x20(%rsp), %xmm5
divpd %xmm1, %xmm5
movapd (%r15), %xmm1
subpd %xmm1, %xmm5
movapd %xmm5, %xmm2
mulpd %xmm5, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm5, %xmm3
mulsd %xmm5, %xmm3
addsd %xmm2, %xmm3
movapd %xmm4, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
movapd 0x40(%rsp), %xmm3
divsd %xmm2, %xmm3
mulsd %xmm3, %xmm4
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm5, %xmm3
addpd %xmm1, %xmm3
movupd %xmm3, (%rbx)
addsd %xmm0, %xmm4
movsd %xmm4, 0x10(%rbx)
movsd (%r14), %xmm0
movsd %xmm0, 0x30(%rbx)
movq %rsp, %rdi
callq 0xb110
movq %r15, %rdi
callq 0xa808
movq %rbx, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6d92e
jmp 0x6d92e
movq %rax, %rbx
movq %rsp, %rdi
callq 0xb110
leaq 0x60(%rsp), %rdi
callq 0xa808
movq %rbx, %rdi
callq 0x4780
nop