// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0x28(%rsi), %r13
movq %r13, %rsi
callq 0x6d501
movapd %xmm0, 0x60(%rsp)
leaq 0x38(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6d501
movapd 0x60(%rsp), %xmm3
leaq 0x77825(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
movapd 0x33ca1(%rip), %xmm2    # 0xa2020
xorpd %xmm1, %xmm2
ucomisd %xmm3, %xmm2
ja 0x6e3ce
ucomisd %xmm1, %xmm3
ja 0x6e436
ucomisd %xmm0, %xmm2
ja 0x6e3d8
ucomisd %xmm1, %xmm0
ja 0x6e440
testq %r12, %r12
je 0x6e3b3
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6e65e
xorl %ebx, %ebx
testq %r14, %r14
je 0x6e64d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6e65e
jmp 0x6e64d
ucomisd %xmm1, %xmm0
ja 0x6e493
movl $0x1, %ebx
testq %r12, %r12
je 0x6e64d
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6950a
leaq 0x10(%r12), %rdi
leaq 0x10(%rbp), %rsi
callq 0x6950a
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x20(%r12)
leaq 0x28(%r12), %rdi
movq %r13, %rsi
callq 0x68f66
leaq 0x38(%r12), %rdi
movq %r15, %rsi
callq 0x68f66
movsd 0x48(%rbp), %xmm0
movsd %xmm0, 0x48(%r12)
jmp 0x6e64d
ucomisd %xmm0, %xmm2
ja 0x6e552
movl $0x2, %ebx
testq %r14, %r14
je 0x6e64d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6950a
leaq 0x10(%r14), %rdi
leaq 0x10(%rbp), %rsi
callq 0x6950a
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x20(%r14)
leaq 0x28(%r14), %rdi
movq %r13, %rsi
callq 0x68f66
leaq 0x38(%r14), %rdi
movq %r15, %rsi
callq 0x68f66
movsd 0x48(%rbp), %xmm0
jmp 0x6e647
movl $0x3, %ebx
movq %r12, %rax
orq %r14, %rax
je 0x6e64d
movapd 0x33b74(%rip), %xmm0    # 0xa2020
xorpd %xmm3, %xmm0
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x67f92
testq %r12, %r12
je 0x6e52b
leaq 0x10(%rsp), %rbp
movq %rsp, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x67dde
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6950a
leaq 0x10(%r12), %rdi
leaq 0x20(%rsp), %r13
movq %r13, %rsi
callq 0x6950a
movsd 0x10(%r13), %xmm0
movsd %xmm0, 0x20(%r12)
leaq 0x28(%r12), %rdi
leaq 0x38(%rsp), %rsi
callq 0x68f66
leaq 0x38(%r12), %rdi
leaq 0x48(%rsp), %r13
movq %r13, %rsi
callq 0x68f66
movsd 0x10(%r13), %xmm0
movsd %xmm0, 0x48(%r12)
testq %r14, %r14
je 0x6e64d
leaq 0x10(%rsp), %r12
movq %rsp, %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x67dde
movq %r14, %rdi
movq %r12, %rsi
jmp 0x6e600
movl $0x3, %ebx
movq %r12, %rax
orq %r14, %rax
je 0x6e64d
movq %rsp, %rdi
movq %rbp, %rsi
movapd %xmm3, %xmm0
callq 0x67f92
testq %r12, %r12
je 0x6e5e2
leaq 0x10(%rsp), %rbp
movq %rsp, %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x67dde
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6950a
leaq 0x10(%r12), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x6950a
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x20(%r12)
leaq 0x28(%r12), %rdi
leaq 0x38(%rsp), %rsi
callq 0x68f66
leaq 0x38(%r12), %rdi
leaq 0x48(%rsp), %r15
movq %r15, %rsi
callq 0x68f66
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x48(%r12)
testq %r14, %r14
je 0x6e64d
leaq 0x10(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x67dde
movq %r14, %rdi
movq %r15, %rsi
callq 0x6950a
leaq 0x10(%r14), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x6950a
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x20(%r14)
leaq 0x28(%r14), %rdi
leaq 0x38(%rsp), %rsi
callq 0x68f66
leaq 0x38(%r14), %rdi
leaq 0x48(%rsp), %r15
movq %r15, %rsi
callq 0x68f66
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x48(%r14)
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq