// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Relate.cpp
// Function: gaps::R2Splits(gaps::R2Line const&, gaps::R2Span const&, gaps::R2Span*, gaps::R2Span*)
int 
R2Splits(const R2Line& line, const R2Span& span, R2Span *below_result, R2Span *above_result)
{
    // Classify span
    // Result values: 0 = on, 1 = below, 2 = above, 3 = crossing
    RNScalar d1 = R2SignedDistance(line, span.Start());
    RNScalar d2 = R2SignedDistance(line, span.End());
    if (RNIsNegative(d1)) {
        if (RNIsPositive(d2)) {
  	    // Span crosses line
	    if (below_result || above_result) {
	        // Compute intersection
		R2Point point = span.Point(-d1);
		if (below_result) *below_result = R2Span(span.Start(), point);
		if (above_result) *above_result = R2Span(point, span.End());
	    }
	    return 3;
	}
	else {
  	    // Span is below line
	    if (below_result) *below_result = span; 
	    return 1;
	}
    }
    else if (RNIsPositive(d1)) {
        if (RNIsNegative(d2)) {
  	    // Span crosses line
	    if (below_result || above_result) {
	        // Compute intersection
		R2Point point = span.Point(d1);
		if (below_result) *below_result = R2Span(span.End(), point);
		if (above_result) *above_result = R2Span(point, span.Start());
	    }
	    return 3;
	}
	else {
  	    // Span is above line
	    if (above_result) *above_result = span; 
	    return 2;
	}
    }
    else {
        if (RNIsNegative(d2)) {
  	    // Span is below line
	    if (below_result) *below_result = span; 
	    return 1;
	}
        else if (RNIsPositive(d2)) {
  	    // Span is above line
	    if (above_result) *above_result = span; 
	    return 2;
	}
	else {
  	    // Span is on line
	    if (below_result) *below_result = span; 
	    if (above_result) *above_result = span; 
	    return 0;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x28(%rsi), %r13
movq %r13, %rsi
callq 0x63638
movapd %xmm0, 0x10(%rsp)
leaq 0x38(%r12), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x63638
movapd 0x10(%rsp), %xmm3
leaq 0x767fe(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm1
movapd 0x2ec7a(%rip), %xmm2    # 0x93030
xorpd %xmm1, %xmm2
ucomisd %xmm3, %xmm2
ja 0x643e6
ucomisd %xmm1, %xmm3
ja 0x643fd
ucomisd %xmm0, %xmm2
ja 0x643ec
ucomisd %xmm1, %xmm0
ja 0x64403
testq %r15, %r15
je 0x643e2
movq %r15, %rdi
movq %r12, %rsi
callq 0x644ea
xorl %ebx, %ebx
jmp 0x64406
ucomisd %xmm1, %xmm0
ja 0x6441a
pushq $0x1
popq %rbx
testq %r15, %r15
je 0x644d8
movq %r15, %rdi
jmp 0x64412
ucomisd %xmm0, %xmm2
ja 0x64478
pushq $0x2
popq %rbx
testq %r14, %r14
je 0x644d8
movq %r14, %rdi
movq %r12, %rsi
jmp 0x644d3
pushq $0x3
popq %rbx
movq %r15, %rax
orq %r14, %rax
je 0x644d8
movapd 0x2ebff(%rip), %xmm0    # 0x93030
xorpd %xmm3, %xmm0
movq %rsp, %rdi
movq %r12, %rsi
callq 0x5e760
testq %r15, %r15
je 0x64463
leaq 0x28(%rsp), %r12
movq %rsp, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x5e5de
movq %r15, %rdi
movq %r12, %rsi
callq 0x644ea
testq %r14, %r14
je 0x644d8
leaq 0x28(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
movq %rbp, %rdx
jmp 0x644c8
pushq $0x3
popq %rbx
movq %r15, %rax
orq %r14, %rax
je 0x644d8
movq %rsp, %rdi
movq %r12, %rsi
movapd %xmm3, %xmm0
callq 0x5e760
testq %r15, %r15
je 0x644b5
leaq 0x28(%rsp), %r12
movq %rsp, %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5e5de
movq %r15, %rdi
movq %r12, %rsi
callq 0x644ea
testq %r14, %r14
je 0x644d8
leaq 0x28(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x5e5de
movq %r14, %rdi
movq %r15, %rsi
callq 0x644ea
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop