// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Isect.cpp
// Function: gaps::R3Intersects(gaps::R3Plane const&, gaps::R3Plane const&, gaps::R3Line*)
RNClassID R3Intersects(const R3Plane& plane1, const R3Plane& plane2, 
    R3Line *result)
{
    // Check if planes are parallel
    if (R3Parallel(plane1, plane2)) {
	// Planes are parallel - check if planes are equal
	if (RNIsEqual(plane1.D(), plane2.D())) {
	    // Planes are coincident
	    return R3_PLANE_CLASS_ID;
	}
	else {
	    // Planes are parallel, but not coincident
	    return RN_NULL_CLASS_ID;
	}
    }
    else {
	// Planes are not parallel -- they must intersect
	if (result) {
	    // Compute direction vector of intersection line
	    R3Vector v = plane1.Normal();
	    v.Cross(plane2.Normal());

	    // Find v's largest dimension
	    RNDimension dim = v.MaxDimension();
	    RNDimension dim1 = (dim+1) % 3;
	    RNDimension dim2 = (dim+2) % 3;
	    assert(RNIsNotZero(v[dim]));

	    // Solve for point on zero plane of v's largest dimension
	    R3Point p;
	    p[dim] = 0.0;
	    p[dim1] = (plane1[dim2] * plane2.D() - plane2[dim2] * plane1.D()) / v[dim];
	    p[dim2] = (plane2[dim1] * plane1.D() - plane1[dim1] * plane2.D()) / v[dim];
	    *result = R3Line(p, v);
	}

	// Planes intersect in a line
	return R3_LINE_CLASS_ID;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
callq 0x4c416
testl %eax, %eax
je 0x455db
movsd 0x18(%r12), %xmm0
leaq 0xa05ed(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
subsd 0x18(%r15), %xmm0
movapd 0x5ca63(%rip), %xmm2    # 0xa2020
xorpd %xmm1, %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm1
setae %al
xorl %ecx, %ecx
ucomisd %xmm2, %xmm0
leal (%rax,%rax,4), %ebx
cmovbl %ecx, %ebx
jmp 0x456fc
movl $0x2, %ebx
testq %r14, %r14
je 0x456fc
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3d4ce
movq %r13, %rdi
movq %r15, %rsi
callq 0x3d86a
movq %r13, %rdi
callq 0x3d652
movl %eax, %ebp
leal 0x1(%rbp), %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (%rax,%rax,2), %eax
negl %eax
addl %ebp, %eax
incl %eax
movl %eax, 0x4(%rsp)
leal 0x2(%rbp), %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (%rax,%rax,2), %eax
negl %eax
leal (%rax,%rbp), %r13d
addl $0x2, %r13d
leaq 0x8(%rsp), %rdi
callq 0x3ca24
movslq %ebp, %rax
movq $0x0, 0x8(%rsp,%rax,8)
movslq %r13d, %rcx
movsd 0x18(%r15), %xmm0
movsd 0x18(%r12), %xmm1
movsd (%r15,%rcx,8), %xmm2
mulsd %xmm1, %xmm2
movsd (%r12,%rcx,8), %xmm3
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
movsd 0x20(%rsp,%rax,8), %xmm2
divsd %xmm2, %xmm3
movslq 0x4(%rsp), %rax
movsd %xmm3, 0x8(%rsp,%rax,8)
mulsd (%r12,%rax,8), %xmm0
mulsd (%r15,%rax,8), %xmm1
subsd %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp,%rcx,8)
leaq 0x38(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3c73c
movq %r14, %rdi
movq %r15, %rsi
callq 0x3cd94
addq $0x18, %r14
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x3dc6a
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq