// File: /workspace/github_cpp_makefile_star2_O3/dmarto[P]crrs-xlib/main.cpp
// Function: Trace(Ray const&, Sphere const&, std::vector<Sphere*, std::allocator<Sphere*>> const&)
Vec3 Trace(const Ray &ray, const Sphere &light, const std::vector<Sphere *> &objects)
{
	Colors color;
	Vec3 pixclr = color.black;

	for (auto &sphere : objects)
	{
		double t;
		double lightIntensity = 0.62;

		if (sphere->Intersects(ray, t))
		{
			const Vec3 pointOfIntersection = ray.origin + ray.destination * t;
			const Vec3 len = light.center - pointOfIntersection;
			const Vec3 normal = sphere->GetNormal(pointOfIntersection);
			const double dotProduct = dot(len.Normalize(), normal.Normalize());

			pixclr = (sphere->clr + light.clr / 2 * dotProduct) * lightIntensity;

			if (sphere->name != "world")
				Reflection(objects, pointOfIntersection, normal, pixclr);
			Shadow(objects, pointOfIntersection, normal, pixclr, light);

			ColorBoundary(pixclr);
		}
	}

	return pixclr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rdi)
movupd 0x58(%rsp), %xmm0
movupd %xmm0, (%rdi)
movq (%rcx), %rbp
movq 0x8(%rcx), %r13
cmpq %r13, %rbp
je 0x1992
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %r13, (%rsp)
movq (%rbp), %rdi
movq %r12, %rsi
leaq 0x8(%rsp), %rdx
callq 0x2246
testb %al, %al
je 0x1985
movsd 0x8(%rsp), %xmm3
movsd 0x28(%r12), %xmm0
mulsd %xmm3, %xmm0
addsd 0x10(%r12), %xmm0
movupd (%r12), %xmm1
movupd 0x18(%r12), %xmm2
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm2, %xmm3
addpd %xmm1, %xmm3
movapd %xmm3, 0x30(%rsp)
movsd %xmm0, 0x40(%rsp)
movsd 0x10(%r14), %xmm1
subsd %xmm0, %xmm1
movq (%rbp), %rdi
subsd 0x10(%rdi), %xmm0
movsd 0x17b5(%rip), %xmm4     # 0x3018
divsd 0x18(%rdi), %xmm4
mulsd %xmm4, %xmm0
movupd (%rdi), %xmm2
movapd %xmm3, %xmm5
subpd %xmm2, %xmm5
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm5, %xmm4
movapd %xmm4, 0x10(%rsp)
movsd %xmm0, 0x20(%rsp)
movapd %xmm0, %xmm5
unpcklpd %xmm1, %xmm5            # xmm5 = xmm5[0],xmm1[0]
mulpd %xmm5, %xmm5
movupd (%r14), %xmm6
movupd 0x20(%r14), %xmm2
subpd %xmm3, %xmm6
movapd %xmm4, %xmm3
unpcklpd %xmm6, %xmm3            # xmm3 = xmm3[0],xmm6[0]
mulpd %xmm3, %xmm3
movapd %xmm4, %xmm7
unpckhpd %xmm6, %xmm7            # xmm7 = xmm7[1],xmm6[1]
mulpd %xmm7, %xmm7
addpd %xmm3, %xmm7
addpd %xmm5, %xmm7
movapd %xmm7, %xmm3
unpckhpd %xmm7, %xmm3            # xmm3 = xmm3[1],xmm7[1]
mulsd %xmm7, %xmm3
sqrtsd %xmm3, %xmm3
mulpd %xmm4, %xmm6
movapd %xmm6, %xmm4
unpckhpd %xmm6, %xmm4            # xmm4 = xmm4[1],xmm6[1]
addsd %xmm6, %xmm4
mulsd %xmm1, %xmm0
addsd %xmm4, %xmm0
mulsd 0x1749(%rip), %xmm0     # 0x3040
divsd %xmm3, %xmm0
movsd 0x30(%r14), %xmm1
mulsd %xmm0, %xmm1
addsd 0x30(%rdi), %xmm1
mulsd 0x1736(%rip), %xmm1     # 0x3048
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm2, %xmm0
movupd 0x20(%rdi), %xmm2
addpd %xmm0, %xmm2
mulpd 0x17a5(%rip), %xmm2     # 0x30d0
movupd %xmm2, (%r15)
movsd %xmm1, 0x10(%r15)
addq $0x38, %rdi
leaq 0x18cf(%rip), %rsi      # 0x3210
callq 0x1040
testl %eax, %eax
movq %rbx, %r13
leaq 0x30(%rsp), %rbx
je 0x1965
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x1355
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rcx
movq %r14, %r8
callq 0x159c
movq %r15, %rdi
callq 0x12ec
movq %r13, %rbx
movq (%rsp), %r13
addq $0x8, %rbp
cmpq %r13, %rbp
jne 0x17f2
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq