// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Relate.cpp
// Function: gaps::R3Splits(gaps::R3Plane const&, gaps::R3Span const&, gaps::R3Span*, gaps::R3Span*)
int 
R3Splits(const R3Plane& plane, const R3Span& span, R3Span *below_result, R3Span *above_result)
{
    // Characterize endpoints with respect to plane
    RNScalar d1 = R3SignedDistance(plane, span.Start());
    RNScalar d2 = R3SignedDistance(plane, span.End());

    // Clip span to plane
    if (RNIsNegative(d1)) {
	if (RNIsPositive(d2)) {
	    // Start is below, end is above
	    R3Point intersection_point = (span.Start() * d2 + span.End() * -d1) / (d2 - d1);
	    if (below_result) below_result->Reset(span.Start(), intersection_point);
	    if (above_result) above_result->Reset(intersection_point, span.End());
	    return 0x3;
	}
	else {
	    // Both points are on or below plane 
	    if (below_result) *below_result = span;
	    return 0x1;
	}
    }
    else if (RNIsPositive(d1)) {
	if (RNIsNegative(d2)) {
	    // Start is above, end is below
	    R3Point intersection_point = (span.Start() * -d2 + span.End() * d1) / (d1 - d2);
	    if (below_result) below_result->Reset(intersection_point, span.End());
	    if (above_result) above_result->Reset(span.Start(), intersection_point);
	    return 0x3;
	}
	else {
	    // Start is above, end is on or above
	    if (above_result) *above_result = span;
	    return 0x2;
	}
    }
    else {
	if (RNIsNegative(d2)) {
	    // Start is on, end is below -- move end to start
	    if (below_result) *below_result = span;
	    return 0x1;
	}
	else {
	    // Start is on, end is on or above
	    if (above_result) *above_result = span;
	    return 0x2;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
callq 0x4a10f
movapd %xmm0, (%rsp)
leaq 0x30(%rbx), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x4a10f
movapd (%rsp), %xmm2
movapd %xmm0, %xmm3
leaq 0x99168(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
movapd 0x555e4(%rip), %xmm0    # 0xa2020
xorpd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
ja 0x4ca54
ucomisd %xmm1, %xmm2
ja 0x4caa3
ucomisd %xmm3, %xmm0
ja 0x4ca5e
jmp 0x4caad
ucomisd %xmm1, %xmm3
ja 0x4caef
movl $0x1, %ebp
testq %r12, %r12
je 0x4cc0b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3cd94
leaq 0x18(%r12), %rdi
leaq 0x18(%rbx), %rsi
callq 0x3dc6a
leaq 0x30(%r12), %rdi
movq %r14, %rsi
callq 0x3cd94
movsd 0x48(%rbx), %xmm0
movsd %xmm0, 0x48(%r12)
jmp 0x4cc0b
ucomisd %xmm3, %xmm0
ja 0x4cb7c
movl $0x2, %ebp
testq %r15, %r15
je 0x4cc0b
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3cd94
leaq 0x18(%r15), %rdi
leaq 0x18(%rbx), %rsi
callq 0x3dc6a
leaq 0x30(%r15), %rdi
movq %r14, %rsi
callq 0x3cd94
movsd 0x48(%rbx), %xmm0
movsd %xmm0, 0x48(%r15)
jmp 0x4cc0b
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm3, %xmm0
movapd %xmm3, 0x10(%rsp)
callq 0x3d470
movaps 0x55513(%rip), %xmm0    # 0xa2020
xorps (%rsp), %xmm0
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3d470
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x3d42a
movapd 0x10(%rsp), %xmm0
subsd (%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x3d492
testq %r12, %r12
je 0x4cb63
leaq 0x28(%rsp), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3c386
testq %r15, %r15
je 0x4cc06
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %r14, %rdx
jmp 0x4cc01
movapd 0x5549c(%rip), %xmm0    # 0xa2020
xorpd %xmm3, %xmm0
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm3, 0x10(%rsp)
callq 0x3d470
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movaps (%rsp), %xmm0
callq 0x3d470
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x3d42a
movapd (%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x3d492
testq %r12, %r12
je 0x4cbf1
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x3c386
testq %r15, %r15
je 0x4cc06
leaq 0x28(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3c386
movl $0x3, %ebp
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq