// File: /workspace/github_cpp_makefile_star2_O3/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 0x6c745
movapd %xmm0, 0x60(%rsp)
leaq 0x38(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6c745
movapd 0x60(%rsp), %xmm3
leaq 0x78601(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
movapd 0x34a7d(%rip), %xmm2    # 0xa2020
xorpd %xmm1, %xmm2
ucomisd %xmm3, %xmm2
ja 0x6d5f2
ucomisd %xmm1, %xmm3
ja 0x6d65a
ucomisd %xmm0, %xmm2
ja 0x6d5fc
ucomisd %xmm1, %xmm0
ja 0x6d664
testq %r12, %r12
je 0x6d5d7
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6d882
xorl %ebx, %ebx
testq %r14, %r14
je 0x6d871
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6d882
jmp 0x6d871
ucomisd %xmm1, %xmm0
ja 0x6d6b7
movl $0x1, %ebx
testq %r12, %r12
je 0x6d871
movq %r12, %rdi
movq %rbp, %rsi
callq 0x68720
leaq 0x10(%r12), %rdi
leaq 0x10(%rbp), %rsi
callq 0x68720
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x20(%r12)
leaq 0x28(%r12), %rdi
movq %r13, %rsi
callq 0x681de
leaq 0x38(%r12), %rdi
movq %r15, %rsi
callq 0x681de
movsd 0x48(%rbp), %xmm0
movsd %xmm0, 0x48(%r12)
jmp 0x6d871
ucomisd %xmm0, %xmm2
ja 0x6d776
movl $0x2, %ebx
testq %r14, %r14
je 0x6d871
movq %r14, %rdi
movq %rbp, %rsi
callq 0x68720
leaq 0x10(%r14), %rdi
leaq 0x10(%rbp), %rsi
callq 0x68720
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x20(%r14)
leaq 0x28(%r14), %rdi
movq %r13, %rsi
callq 0x681de
leaq 0x38(%r14), %rdi
movq %r15, %rsi
callq 0x681de
movsd 0x48(%rbp), %xmm0
jmp 0x6d86b
movl $0x3, %ebx
movq %r12, %rax
orq %r14, %rax
je 0x6d871
movapd 0x34950(%rip), %xmm0    # 0xa2020
xorpd %xmm3, %xmm0
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x6720a
testq %r12, %r12
je 0x6d74f
leaq 0x10(%rsp), %rbp
movq %rsp, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x67056
movq %r12, %rdi
movq %rbp, %rsi
callq 0x68720
leaq 0x10(%r12), %rdi
leaq 0x20(%rsp), %r13
movq %r13, %rsi
callq 0x68720
movsd 0x10(%r13), %xmm0
movsd %xmm0, 0x20(%r12)
leaq 0x28(%r12), %rdi
leaq 0x38(%rsp), %rsi
callq 0x681de
leaq 0x38(%r12), %rdi
leaq 0x48(%rsp), %r13
movq %r13, %rsi
callq 0x681de
movsd 0x10(%r13), %xmm0
movsd %xmm0, 0x48(%r12)
testq %r14, %r14
je 0x6d871
leaq 0x10(%rsp), %r12
movq %rsp, %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x67056
movq %r14, %rdi
movq %r12, %rsi
jmp 0x6d824
movl $0x3, %ebx
movq %r12, %rax
orq %r14, %rax
je 0x6d871
movq %rsp, %rdi
movq %rbp, %rsi
movapd %xmm3, %xmm0
callq 0x6720a
testq %r12, %r12
je 0x6d806
leaq 0x10(%rsp), %rbp
movq %rsp, %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x67056
movq %r12, %rdi
movq %rbp, %rsi
callq 0x68720
leaq 0x10(%r12), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x68720
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x20(%r12)
leaq 0x28(%r12), %rdi
leaq 0x38(%rsp), %rsi
callq 0x681de
leaq 0x38(%r12), %rdi
leaq 0x48(%rsp), %r15
movq %r15, %rsi
callq 0x681de
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x48(%r12)
testq %r14, %r14
je 0x6d871
leaq 0x10(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x67056
movq %r14, %rdi
movq %r15, %rsi
callq 0x68720
leaq 0x10(%r14), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x68720
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x20(%r14)
leaq 0x28(%r14), %rdi
leaq 0x38(%rsp), %rsi
callq 0x681de
leaq 0x38(%r14), %rdi
leaq 0x48(%rsp), %r15
movq %r15, %rsi
callq 0x681de
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