// File: /workspace/github_cpp_makefile_star2_O3/hamikm[P]Raytracer/src/cylinder.hh
// Function: cylinder<double, double, double>::intersection(ray<double, double, 3> const&) const
time_T intersection(const ray<vec_T, time_T, CDIM> &r) const {

		mvector<vec_T, CDIM> cpar = center.proj(axis);
		mvector<vec_T, CDIM> cperp = center - cpar;

		mvector<vec_T, CDIM> P = r.getOrig();
		mvector<vec_T, CDIM> D = r.getDir();

		mvector<vec_T, CDIM> ppar = P.proj(axis);
		mvector<vec_T, CDIM> pperp = P - ppar;

		mvector<vec_T, CDIM> dpar = D.proj(axis);
		mvector<vec_T, CDIM> dperp = D - dpar;

		sphere<vec_T, color_T, time_T, CDIM> fakesphere(
				this->getColor(),
				radius,
				cperp,
				this->getReflectivity());

		ray<vec_T, time_T, CDIM> ray(pperp, dperp, false);
		time_T t1, t2;

		// t1 and t2 will receive the first and second intersection points
		// on the sphere
		fakesphere.getIntersections(ray, t1, t2);

		mvector<vec_T, CDIM> tmp, val1 = ppar + dpar * t1 - cpar;
		mvector<vec_T, CDIM> val2 = ppar + dpar * t2 - cpar;
		if(val1.magsq() > val2.magsq()) {
			tmp = val1;
			val1 = val2;
			val2 = tmp;
		}
		// now val1 is the smallest
		if(val1.magsq() >= height * height / 4 &&
				val2.magsq() >= height * height / 4) {
			return RAY_MISS;
		}
		else {
			return t1;
		}

		return RAY_MISS;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x28(%rdi), %r12
leaq 0x48(%rdi), %r14
leaq -0x158(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x6486
leaq -0x140(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4c1e
xorl %r12d, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x5b6e
movsd %xmm0, -0x128(%rbp,%r12,8)
incq %r12
cmpq $0x3, %r12
jne 0x60ca
addq $0x18, %r15
xorl %r12d, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x5b6e
movsd %xmm0, -0x110(%rbp,%r12,8)
incq %r12
cmpq $0x3, %r12
jne 0x60ef
leaq -0xf8(%rbp), %r12
leaq -0x128(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6486
leaq -0x1d8(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4c1e
leaq -0xe0(%rbp), %r12
leaq -0x110(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6486
leaq -0x1c0(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4c1e
leaq 0x8(%rbx), %rsi
movsd 0x40(%rbx), %xmm0
movq %rbx, -0x98(%rbp)
movss 0x20(%rbx), %xmm1
leaq -0x220(%rbp), %rdi
leaq -0x140(%rbp), %rdx
callq 0x47cc
movq 0x10(%r15), %rax
movq %rax, -0x180(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0x190(%rbp)
xorl %r15d, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x5b6e
movsd %xmm0, -0x90(%rbp,%r15,8)
incq %r15
cmpq $0x3, %r15
jne 0x61b0
movq -0x80(%rbp), %rax
leaq -0x190(%rbp), %rsi
movq %rax, 0x28(%rsi)
movups -0x90(%rbp), %xmm0
movups %xmm0, 0x18(%rsi)
leaq -0x220(%rbp), %rdi
leaq -0xb0(%rbp), %r14
leaq -0xa8(%rbp), %rcx
movq %r14, %rdx
callq 0x5c42
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movsd (%r14), %xmm0
leaq -0xc8(%rbp), %r14
leaq -0xe0(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x65a3
leaq -0x50(%rbp), %r13
leaq -0xf8(%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x652a
leaq -0x70(%rbp), %r14
leaq -0x158(%rbp), %r15
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x4c1e
leaq -0xa8(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x1a8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x65a3
leaq -0xc8(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x652a
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x4c1e
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
movsd %xmm0, -0x30(%rbp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x5b6e
mulsd -0x70(%rbp,%r15,8), %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
incq %r15
cmpq $0x3, %r15
jne 0x62af
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x50(%rbp), %r15
movsd %xmm1, -0xa0(%rbp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x5b6e
movsd -0xa0(%rbp), %xmm1
mulsd -0x50(%rbp,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x62ed
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
movq -0x98(%rbp), %rbx
jbe 0x635e
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
movapd -0x70(%rbp), %xmm0
movapd %xmm0, -0x90(%rbp)
movapd -0x50(%rbp), %xmm1
movapd %xmm1, -0x70(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movapd %xmm0, -0x50(%rbp)
movq %rax, -0x40(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x70(%rbp), %r15
movsd %xmm1, -0x30(%rbp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x5b6e
movsd -0x30(%rbp), %xmm1
mulsd -0x70(%rbp,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x6369
movsd 0x60(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2c95(%rip), %xmm0     # 0x9038
ucomisd %xmm0, %xmm1
jb 0x63f4
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x50(%rbp), %r15
movsd %xmm1, -0x30(%rbp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x5b6e
movsd -0x30(%rbp), %xmm1
mulsd -0x50(%rbp,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x63b4
movsd 0x60(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2c4a(%rip), %xmm0     # 0x9038
ucomisd %xmm0, %xmm1
jae 0x63fe
movsd -0xb0(%rbp), %xmm0
jmp 0x6406
movsd 0x2c3a(%rip), %xmm0     # 0x9040
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq