// File: /workspace/github_cpp_makefile_star2_O1/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 -0x188(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x6546
leaq -0x170(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4c76
xorl %r12d, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x5c1a
movsd %xmm0, -0x158(%rbp,%r12,8)
incq %r12
cmpq $0x3, %r12
jne 0x6174
addq $0x18, %r15
xorl %r12d, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x5c1a
movsd %xmm0, -0x140(%rbp,%r12,8)
incq %r12
cmpq $0x3, %r12
jne 0x6199
leaq -0x128(%rbp), %r12
leaq -0x158(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6546
leaq -0x1d0(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4c76
leaq -0x110(%rbp), %r12
leaq -0x140(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6546
leaq -0x1b8(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4c76
leaq 0x8(%rbx), %rsi
movsd 0x40(%rbx), %xmm0
movq %rbx, -0x98(%rbp)
movss 0x20(%rbx), %xmm1
leaq -0x218(%rbp), %rdi
leaq -0x170(%rbp), %rdx
callq 0x47d4
xorps %xmm0, %xmm0
movups %xmm0, -0xc8(%rbp)
movq $0x0, -0xb8(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0xe0(%rbp)
movq 0x10(%r15), %rax
movq %rax, -0xd0(%rbp)
xorl %r15d, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x5c1a
movsd %xmm0, -0x90(%rbp,%r15,8)
incq %r15
cmpq $0x3, %r15
jne 0x626f
movq -0x80(%rbp), %rax
leaq -0xe0(%rbp), %rsi
movq %rax, 0x28(%rsi)
movups -0x90(%rbp), %xmm0
movups %xmm0, 0x18(%rsi)
leaq -0x218(%rbp), %rdi
leaq -0xb0(%rbp), %r14
leaq -0xa8(%rbp), %rcx
movq %r14, %rdx
callq 0x5cee
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movsd (%r14), %xmm0
leaq -0xf8(%rbp), %r14
leaq -0x110(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x6663
leaq -0x50(%rbp), %r13
leaq -0x128(%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x65ea
leaq -0x70(%rbp), %r14
leaq -0x188(%rbp), %r15
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x4c76
leaq -0xa8(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x1a0(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x6663
leaq -0xf8(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x65ea
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x4c76
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
movsd %xmm0, -0x30(%rbp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x5c1a
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 0x636e
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x50(%rbp), %r15
movsd %xmm1, -0xa0(%rbp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x5c1a
movsd -0xa0(%rbp), %xmm1
mulsd -0x50(%rbp,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x63ac
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
movq -0x98(%rbp), %rbx
jbe 0x641d
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 0x5c1a
movsd -0x30(%rbp), %xmm1
mulsd -0x70(%rbp,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x6428
movsd 0x60(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2bd6(%rip), %xmm0     # 0x9038
ucomisd %xmm0, %xmm1
jb 0x64b3
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
leaq -0x50(%rbp), %r15
movsd %xmm1, -0x30(%rbp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x5c1a
movsd -0x30(%rbp), %xmm1
mulsd -0x50(%rbp,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x6473
movsd 0x60(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2b8b(%rip), %xmm0     # 0x9038
ucomisd %xmm0, %xmm1
jae 0x64bd
movsd -0xb0(%rbp), %xmm0
jmp 0x64c5
movsd 0x2b7b(%rip), %xmm0     # 0x9040
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop