// File: 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
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdx, -0x158(%rbp)
movq %rdi, -0x170(%rbp)
movq %rdi, %rax
movq %rax, -0x168(%rbp)
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x160(%rbp)
addq $0xa0, %rsi
leaq -0xc8(%rbp), %rdi
callq 0xf0d0
leaq -0xe0(%rbp), %rdi
callq 0x59bd0
movq -0x158(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0xf090
movq %rax, -0x150(%rbp)
jmp 0xfbc88
movq -0x150(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf190
jmp 0xfbc9d
movq -0x158(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0xf090
movq %rax, -0x178(%rbp)
jmp 0xfbcb6
movq -0x178(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf190
jmp 0xfbccb
movq -0x158(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0xf090
movq %rax, -0x180(%rbp)
jmp 0xfbce4
movq -0x180(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf190
jmp 0xfbcf9
movq -0x158(%rbp), %rdi
movslq 0x10(%rbp), %rsi
callq 0xf090
movq %rax, -0x188(%rbp)
jmp 0xfbd12
movq -0x188(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf190
jmp 0xfbd27
movq -0x158(%rbp), %rdi
movslq 0x18(%rbp), %rsi
callq 0xf090
movq %rax, -0x190(%rbp)
jmp 0xfbd40
movq -0x190(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf190
jmp 0xfbd55
xorps %xmm0, %xmm0
movsd %xmm0, -0xf8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x108(%rbp)
movl $0x0, -0x10c(%rbp)
movslq -0x10c(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xf060
movq %rax, %rcx
movq -0x198(%rbp), %rax
cmpq %rcx, %rax
jae 0xfbecf
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
movslq -0x10c(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf090
movq %rax, -0x1a0(%rbp)
jmp 0xfbdd9
movsd -0x1a8(%rbp), %xmm0
movq -0x1a0(%rbp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x1b8(%rbp)
movslq -0x10c(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf090
movq %rax, -0x1b0(%rbp)
jmp 0xfbe24
movsd -0x1b8(%rbp), %xmm0
movq -0x1b0(%rbp), %rax
movsd 0x8(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0x1c8(%rbp)
movslq -0x10c(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xf090
movq %rax, -0x1c0(%rbp)
jmp 0xfbe70
movq -0x1c0(%rbp), %rax
movsd -0x1c8(%rbp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0xfbd80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x12310
leaq -0xc8(%rbp), %rdi
callq 0xf200
jmp 0xfc0aa
leaq -0xe0(%rbp), %rdi
callq 0xf060
movq -0x170(%rbp), %rdi
movq %rax, %xmm0
movaps 0xfa472(%rip), %xmm1    # 0x1f6360
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xfa476(%rip), %xmm1    # 0x1f6370
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x118(%rbp)
movb $0x0, -0x119(%rbp)
callq 0x954b0
jmp 0xfbf1f
movsd -0xf8(%rbp), %xmm0
divsd -0x118(%rbp), %xmm0
subsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x100(%rbp), %xmm0
divsd -0x118(%rbp), %xmm0
subsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movsd -0x108(%rbp), %xmm0
divsd -0x118(%rbp), %xmm0
subsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
movsd -0x128(%rbp), %xmm1
movsd -0x128(%rbp), %xmm2
movsd -0x130(%rbp), %xmm0
mulsd -0x130(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x138(%rbp), %xmm0
movsd -0x138(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x53f0
movq -0x160(%rbp), %rcx
movq -0x170(%rbp), %rax
movsd %xmm0, -0x140(%rbp)
movsd -0x30(%rbp), %xmm0
divsd -0x140(%rbp), %xmm0
movsd %xmm0, -0x148(%rbp)
movsd -0x128(%rbp), %xmm0
movsd -0x148(%rbp), %xmm2
movsd -0xc8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movsd -0x130(%rbp), %xmm0
movsd -0x148(%rbp), %xmm2
movsd -0xc0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x138(%rbp), %xmm0
movsd -0x148(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rax)
movsd (%rcx), %xmm0
movsd %xmm0, 0x30(%rax)
movb $0x1, -0x119(%rbp)
testb $0x1, -0x119(%rbp)
jne 0xfc082
movq -0x170(%rbp), %rdi
callq 0xf200
leaq -0xe0(%rbp), %rdi
callq 0x12310
leaq -0xc8(%rbp), %rdi
callq 0xf200
movq -0x168(%rbp), %rax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0xe8(%rbp), %rdi
callq 0x58f0
nopw %cs:(%rax,%rax)