// File: 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
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdx
movq %rdx, -0x250(%rbp)
movq %rdx, %rsi
addq $0x28, %rsi
movq %rsi, -0x288(%rbp)
addq $0x48, %rdx
movq %rdx, -0x268(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x87c0
movq -0x288(%rbp), %rsi
movq -0x280(%rbp), %rdx
leaq -0x48(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x53a0
movq -0x18(%rbp), %rdi
callq 0x7f10
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x7570
movq -0x18(%rbp), %rdi
callq 0x7e80
movq %rax, %rsi
leaq -0x78(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x7570
movq -0x278(%rbp), %rsi
movq -0x268(%rbp), %rdx
leaq -0x90(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x87c0
movq -0x278(%rbp), %rsi
movq -0x270(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x53a0
movq -0x268(%rbp), %rdx
movq -0x260(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x87c0
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x53a0
movq -0x250(%rbp), %rdi
callq 0x8830
movq -0x250(%rbp), %rdi
movq %rax, -0x248(%rbp)
movsd 0x40(%rdi), %xmm0
movsd %xmm0, -0x238(%rbp)
callq 0x8850
movq -0x248(%rbp), %rsi
movq -0x240(%rbp), %rdx
movaps %xmm0, %xmm1
movsd -0x238(%rbp), %xmm0
leaq -0x120(%rbp), %rdi
callq 0x4da0
movq -0x230(%rbp), %rsi
movq -0x228(%rbp), %rdx
leaq -0x150(%rbp), %rdi
xorl %ecx, %ecx
callq 0x8870
jmp 0x84a0
leaq -0x120(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x168(%rbp), %rdx
leaq -0x170(%rbp), %rcx
callq 0x7b00
jmp 0x84c3
leaq -0x188(%rbp), %rdi
callq 0x4aa0
jmp 0x84d1
movsd -0x168(%rbp), %xmm0
leaq -0x1d0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8990
jmp 0x84ee
leaq -0x1b8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x1d0(%rbp), %rdx
callq 0x8910
jmp 0x850a
leaq -0x1a0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x53a0
jmp 0x8523
movsd -0x170(%rbp), %xmm0
leaq -0x218(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8990
jmp 0x8540
leaq -0x200(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x218(%rbp), %rdx
callq 0x8910
jmp 0x855c
leaq -0x1e8(%rbp), %rdi
leaq -0x200(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x53a0
jmp 0x8575
leaq -0x1a0(%rbp), %rdi
callq 0x8a10
movsd %xmm0, -0x290(%rbp)
jmp 0x858b
leaq -0x1e8(%rbp), %rdi
callq 0x8a10
movsd %xmm0, -0x298(%rbp)
jmp 0x85a1
movsd -0x290(%rbp), %xmm0
movsd -0x298(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x865e
movq -0x1a0(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x1d8(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x1d8(%rbp)
jmp 0x865e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x75f0
jmp 0x872a
leaq -0x1a0(%rbp), %rdi
callq 0x8a10
movsd %xmm0, -0x2a0(%rbp)
jmp 0x8674
movsd -0x2a0(%rbp), %xmm0
movq -0x250(%rbp), %rax
movsd 0x60(%rax), %xmm1
mulsd 0x60(%rax), %xmm1
movsd 0x79a3(%rip), %xmm2     # 0x10038
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x86f9
leaq -0x1e8(%rbp), %rdi
callq 0x8a10
movsd %xmm0, -0x2a8(%rbp)
jmp 0x86b5
movsd -0x2a8(%rbp), %xmm0
movq -0x250(%rbp), %rax
movsd 0x60(%rax), %xmm1
mulsd 0x60(%rax), %xmm1
movsd 0x7962(%rip), %xmm2     # 0x10038
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x86f9
movsd 0x7958(%rip), %xmm0     # 0x10040
movsd %xmm0, -0x8(%rbp)
movl $0x1, -0x21c(%rbp)
jmp 0x8710
movsd -0x168(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movl $0x1, -0x21c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x75f0
movsd -0x8(%rbp), %xmm0
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x158(%rbp), %rdi
callq 0x3380
nopw %cs:(%rax,%rax)