// File: /workspace/github_cpp_makefile_star2_O1/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 0x19cb
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %r13, (%rsp)
movq (%rbp), %rdi
movq %r12, %rsi
leaq 0x8(%rsp), %rdx
callq 0x2284
testb %al, %al
je 0x19be
movsd 0x8(%rsp), %xmm1
movsd 0x28(%r12), %xmm3
mulsd %xmm1, %xmm3
addsd 0x10(%r12), %xmm3
movupd (%r12), %xmm0
movupd 0x18(%r12), %xmm2
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm2, %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movsd %xmm3, 0x40(%rsp)
movsd (%r14), %xmm4
subsd %xmm1, %xmm4
movq (%rbp), %rdi
movapd %xmm3, %xmm2
subsd 0x10(%rdi), %xmm2
movsd 0x1794(%rip), %xmm0     # 0x3018
divsd 0x18(%rdi), %xmm0
movapd %xmm1, %xmm5
shufpd $0x1, %xmm3, %xmm1      # xmm1 = xmm1[1],xmm3[0]
mulsd %xmm0, %xmm2
movupd (%rdi), %xmm3
subpd %xmm3, %xmm5
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm5, %xmm0
movapd %xmm0, 0x10(%rsp)
movsd %xmm2, 0x20(%rsp)
movapd %xmm0, %xmm3
mulsd %xmm4, %xmm3
movupd 0x8(%r14), %xmm5
subpd %xmm1, %xmm5
movupd 0x20(%r14), %xmm1
movapd %xmm0, %xmm6
unpcklpd %xmm4, %xmm6            # xmm6 = xmm6[0],xmm4[0]
mulpd %xmm6, %xmm6
movapd %xmm0, %xmm4
shufpd $0x1, %xmm5, %xmm4      # xmm4 = xmm4[1],xmm5[0]
mulpd %xmm4, %xmm4
addpd %xmm6, %xmm4
shufpd $0x1, %xmm2, %xmm0      # xmm0 = xmm0[1],xmm2[0]
mulpd %xmm5, %xmm0
movsd %xmm2, %xmm5            # xmm5 = xmm2[0],xmm5[1]
mulpd %xmm5, %xmm5
addpd %xmm4, %xmm5
sqrtpd %xmm5, %xmm2
movapd %xmm2, %xmm4
unpckhpd %xmm2, %xmm4            # xmm4 = xmm4[1],xmm2[1]
movapd %xmm2, %xmm5
mulsd %xmm4, %xmm5
divsd %xmm5, %xmm3
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm4, %xmm2
divpd %xmm2, %xmm0
addsd %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
mulsd 0x170c(%rip), %xmm0     # 0x3040
movsd 0x30(%r14), %xmm2
mulsd %xmm0, %xmm2
addsd 0x30(%rdi), %xmm2
mulsd 0x16fd(%rip), %xmm2     # 0x3048
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
movupd 0x20(%rdi), %xmm1
addpd %xmm0, %xmm1
mulpd 0x176c(%rip), %xmm1     # 0x30d0
movupd %xmm1, (%r15)
movsd %xmm2, 0x10(%r15)
addq $0x38, %rdi
leaq 0x1896(%rip), %rsi      # 0x3210
callq 0x1040
testl %eax, %eax
movq %rbx, %r13
leaq 0x30(%rsp), %rbx
je 0x199e
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 0x15a9
movq %r15, %rdi
callq 0x12ec
movq %r13, %rbx
movq (%rsp), %r13
addq $0x8, %rbp
cmpq %r13, %rbp
jne 0x1810
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq