// File: /workspace/github_cpp_makefile_star2_O3/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 0x49617
movapd %xmm0, (%rsp)
leaq 0x30(%rbx), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x49617
movapd (%rsp), %xmm2
movapd %xmm0, %xmm3
leaq 0x99c80(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
movapd 0x560fc(%rip), %xmm0    # 0xa2020
xorpd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
ja 0x4bf3c
ucomisd %xmm1, %xmm2
ja 0x4bf8b
ucomisd %xmm3, %xmm0
ja 0x4bf46
jmp 0x4bf95
ucomisd %xmm1, %xmm3
ja 0x4bfd7
movl $0x1, %ebp
testq %r12, %r12
je 0x4c0f3
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3c89a
leaq 0x18(%r12), %rdi
leaq 0x18(%rbx), %rsi
callq 0x3d752
leaq 0x30(%r12), %rdi
movq %r14, %rsi
callq 0x3c89a
movsd 0x48(%rbx), %xmm0
movsd %xmm0, 0x48(%r12)
jmp 0x4c0f3
ucomisd %xmm3, %xmm0
ja 0x4c064
movl $0x2, %ebp
testq %r15, %r15
je 0x4c0f3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3c89a
leaq 0x18(%r15), %rdi
leaq 0x18(%rbx), %rsi
callq 0x3d752
leaq 0x30(%r15), %rdi
movq %r14, %rsi
callq 0x3c89a
movsd 0x48(%rbx), %xmm0
movsd %xmm0, 0x48(%r15)
jmp 0x4c0f3
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm3, %xmm0
movapd %xmm3, 0x10(%rsp)
callq 0x3cf76
movaps 0x5602b(%rip), %xmm0    # 0xa2020
xorps (%rsp), %xmm0
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3cf76
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x3cf30
movapd 0x10(%rsp), %xmm0
subsd (%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x3cf98
testq %r12, %r12
je 0x4c04b
leaq 0x28(%rsp), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3be92
testq %r15, %r15
je 0x4c0ee
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %r14, %rdx
jmp 0x4c0e9
movapd 0x55fb4(%rip), %xmm0    # 0xa2020
xorpd %xmm3, %xmm0
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm3, 0x10(%rsp)
callq 0x3cf76
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movaps (%rsp), %xmm0
callq 0x3cf76
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x3cf30
movapd (%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x3cf98
testq %r12, %r12
je 0x4c0d9
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x3be92
testq %r15, %r15
je 0x4c0ee
leaq 0x28(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3be92
movl $0x3, %ebp
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq