// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x28(%rdi), %r12
leaq 0x48(%rdi), %r14
leaq -0x108(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5d88
leaq -0xf0(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x46c8
leaq -0x180(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5430
addq $0x18, %r15
leaq -0x168(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x5430
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5d88
leaq -0xc0(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x46c8
leaq -0x150(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x5d88
leaq -0x138(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x46c8
leaq 0x8(%rbx), %rsi
movsd 0x40(%rbx), %xmm0
movss 0x20(%rbx), %xmm1
leaq -0x1f8(%rbp), %r13
movq %r13, %rdi
leaq -0xf0(%rbp), %rdx
callq 0x439c
leaq -0x1b0(%rbp), %r15
movq %r15, %rdi
leaq -0xc0(%rbp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5dd8
leaq -0x78(%rbp), %r14
leaq -0x70(%rbp), %rcx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5702
leaq -0x90(%rbp), %rdi
callq 0x416e
movsd (%r14), %xmm0
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x5ea9
leaq -0x40(%rbp), %r13
movq %r13, %rdi
leaq -0xd8(%rbp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x5e50
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
leaq -0x108(%rbp), %r13
movq %r13, %rdx
callq 0x46c8
leaq -0x70(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x120(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x5ea9
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5e50
leaq -0x40(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x46c8
leaq -0x60(%rbp), %rdi
callq 0x5ef4
movsd %xmm0, -0x68(%rbp)
movq %r14, %rdi
callq 0x5ef4
movsd -0x68(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5cb9
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
movapd -0x60(%rbp), %xmm0
movapd %xmm0, -0x90(%rbp)
movapd -0x40(%rbp), %xmm1
movapd %xmm1, -0x60(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movapd %xmm0, -0x40(%rbp)
movq %rax, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5ef4
movsd 0x60(%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd 0x3365(%rip), %xmm1     # 0x9038
ucomisd %xmm1, %xmm0
jb 0x5cf9
leaq -0x40(%rbp), %rdi
callq 0x5ef4
movsd 0x60(%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd 0x3345(%rip), %xmm1     # 0x9038
ucomisd %xmm1, %xmm0
jae 0x5d00
movsd -0x78(%rbp), %xmm0
jmp 0x5d08
movsd 0x3338(%rip), %xmm0     # 0x9040
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq