// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r13
callq 0x43420
movapd %xmm0, (%rsp)
leaq 0x30(%rbx), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x43420
movapd (%rsp), %xmm2
movapd %xmm0, %xmm3
leaq 0x95396(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm1
movapd 0x4d812(%rip), %xmm0    # 0x93030
xorpd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
ja 0x45836
ucomisd %xmm1, %xmm2
ja 0x4584d
ucomisd %xmm3, %xmm0
ja 0x4583c
jmp 0x45857
ucomisd %xmm1, %xmm3
ja 0x45873
pushq $0x1
popq %rbp
testq %r15, %r15
je 0x4598d
movq %r15, %rdi
jmp 0x45866
ucomisd %xmm3, %xmm0
ja 0x45900
pushq $0x2
popq %rbp
testq %r14, %r14
je 0x4598d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21dfa
jmp 0x4598d
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm3, %xmm0
movapd %xmm3, 0x10(%rsp)
callq 0x382c0
movaps 0x4d79f(%rip), %xmm0    # 0x93030
xorps (%rsp), %xmm0
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x382c0
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x3827a
movapd 0x10(%rsp), %xmm0
subsd (%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x382e2
testq %r15, %r15
je 0x458e7
leaq 0x28(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x37480
testq %r14, %r14
je 0x4598a
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
movq %r12, %rdx
jmp 0x45985
movapd 0x4d728(%rip), %xmm0    # 0x93030
xorpd %xmm3, %xmm0
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm3, 0x10(%rsp)
callq 0x382c0
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movaps (%rsp), %xmm0
callq 0x382c0
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %rbp, %rdx
callq 0x3827a
movapd (%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x382e2
testq %r15, %r15
je 0x45975
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x37480
testq %r14, %r14
je 0x4598a
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x37480
pushq $0x3
popq %rbp
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq