// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movsd %xmm0, 0x38(%rsp)
movl %r9d, %ebp
movl %r8d, %r12d
movl %ecx, %r13d
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movupd 0xa0(%rsi), %xmm0
movupd 0xb0(%rsi), %xmm1
movupd 0xc0(%rsi), %xmm2
movups 0xd0(%rsi), %xmm3
leaq 0x80(%rsp), %rdi
movaps %xmm3, -0x10(%rdi)
movapd %xmm2, -0x20(%rdi)
movapd %xmm1, -0x30(%rdi)
movapd %xmm0, -0x40(%rdi)
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0xe0(%rsi), %rsi
movq 0xe8(%r14), %rdx
addq %rsi, %rdx
callq 0xf32a
leaq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x100(%r14), %rsi
movq 0x108(%r14), %rdx
addq %rsi, %rdx
callq 0xf32a
movb 0x130(%r14), %al
movb %al, 0xd0(%rsp)
movupd 0x120(%r14), %xmm0
movapd %xmm0, 0xc0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movslq %r13d, %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x79435e50d79435e5, %r13 # imm = 0x86BCA1AF286BCA1B
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x94a33
imulq $0x98, %rsi, %rcx
addq %rcx, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xe936
movslq %r12d, %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x94a33
imulq $0x98, %rsi, %rcx
addq %rcx, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xe936
movslq %ebp, %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x94a33
imulq $0x98, %rsi, %rcx
addq %rcx, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xe936
movslq 0x110(%rsp), %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x94a33
imulq $0x98, %rsi, %rcx
addq %rcx, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xe936
movslq 0x118(%rsp), %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x94a33
imulq $0x98, %rsi, %rcx
addq %rcx, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xe936
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, %r15
subq %rax, %r15
sarq $0x3, %r15
imulq %r13, %r15
cmpq %rax, %rcx
je 0x948be
cmpq $0x1, %r15
movq %r15, %rcx
adcq $0x0, %rcx
addq $0x10, %rax
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
addsd -0x10(%rax), %xmm2
addsd -0x8(%rax), %xmm1
addsd (%rax), %xmm0
addq $0x98, %rax
decq %rcx
jne 0x948a3
jmp 0x948ca
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
callq 0x5162c
movq %r15, %xmm0
punpckldq 0xbe9af(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xbe9b7(%rip), %xmm0    # 0x1532b0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm3
divsd %xmm1, %xmm3
subsd 0x40(%rsp), %xmm3
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
subsd 0x48(%rsp), %xmm0
movsd 0x18(%rsp), %xmm2
divsd %xmm1, %xmm2
subsd 0x50(%rsp), %xmm2
movsd %xmm0, 0x10(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm3, 0x8(%rsp)
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd %xmm2, 0x18(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x94973
sqrtsd %xmm0, %xmm0
jmp 0x94978
callq 0x4350
movsd 0x38(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd 0x10(%rsp), %xmm2
mulsd %xmm1, %xmm2
addsd 0x48(%rsp), %xmm2
movsd %xmm0, (%rbx)
movsd 0x18(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm2, 0x8(%rbx)
movsd %xmm0, 0x10(%rbx)
movsd (%r14), %xmm0
movsd %xmm0, 0x30(%rbx)
leaq 0x20(%rsp), %rdi
callq 0xf236
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x949f9
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x94a1e
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbac6b(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
jmp 0x94a6d
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x94a84
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x94a84
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xf236
leaq 0x40(%rsp), %rdi
callq 0x2f814
movq %rbx, %rdi
callq 0x4780