// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Isect.cpp
// Function: gaps::R2Intersects(gaps::R2Box const&, gaps::R2Box const&, gaps::R2Box*)
RNClassID R2Intersects(const R2Box& box1, const R2Box& box2, 
    R2Box *result)
{
    // Compute whether box intersects box
    if ((RNIsGreater(box1.XMin(), box2.XMax())) ||
        (RNIsGreater(box1.YMin(), box2.YMax())) ||
        (RNIsGreater(box2.XMin(), box1.XMax())) ||
        (RNIsGreater(box2.YMin(), box1.YMax()))) return RN_NULL_CLASS_ID;

    // Compute intersection
    if (result) {
        RNCoord xmin = box1.XMin();
        if (xmin < box2.XMin()) xmin = box2.XMin();
        RNCoord ymin = box1.YMin();
        if (ymin < box2.YMin()) ymin = box2.YMin();
        RNCoord xmax = box1.XMax();
        if (xmax > box2.XMax()) xmax = box2.XMax();
        RNCoord ymax = box1.YMax();
        if (ymax > box2.YMax()) ymax = box2.YMax();
        *result = R2Box(xmin, ymin, xmax, ymax);
    }
    
    // Return ID of intersection ???
    return RN_UNKNOWN_CLASS_ID;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb8(%rsp)
movq %rsi, 0xb0(%rsp)
movq %rdx, 0xa8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xa3750
movsd %xmm0, 0x48(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa3790
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
leaq 0xd2e51(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0xa575b
movq 0xb8(%rsp), %rdi
callq 0xa3770
movsd %xmm0, 0x40(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa37b0
movaps %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
leaq 0xd2e0f(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0xa575b
movq 0xb0(%rsp), %rdi
callq 0xa3750
movsd %xmm0, 0x38(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xa3790
movaps %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
leaq 0xd2dd1(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0xa575b
movq 0xb0(%rsp), %rdi
callq 0xa3770
movsd %xmm0, 0x30(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xa37b0
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
leaq 0xd2d93(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
je 0xa576b
movl $0x0, 0xc4(%rsp)
jmp 0xa5948
cmpq $0x0, 0xa8(%rsp)
je 0xa593d
movq 0xb8(%rsp), %rdi
callq 0xa3750
movsd %xmm0, 0xa0(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa3750
movsd 0x28(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xa57ce
movq 0xb0(%rsp), %rdi
callq 0xa3750
movsd %xmm0, 0xa0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xa3770
movsd %xmm0, 0x98(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa3770
movsd 0x20(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xa5822
movq 0xb0(%rsp), %rdi
callq 0xa3770
movsd %xmm0, 0x98(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xa3790
movsd %xmm0, 0x90(%rsp)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa3790
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa5879
movq 0xb0(%rsp), %rdi
callq 0xa3790
movsd %xmm0, 0x90(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xa37b0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa37b0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa58d0
movq 0xb0(%rsp), %rdi
callq 0xa37b0
movsd %xmm0, 0x88(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
movsd 0x90(%rsp), %xmm2
movsd 0x88(%rsp), %xmm3
leaq 0x60(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xbd610
movq 0x8(%rsp), %rsi
movq 0xa8(%rsp), %rdi
callq 0xa5da0
jmp 0xa5917
leaq 0x60(%rsp), %rdi
callq 0x6bc50
jmp 0xa593d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x6bc50
jmp 0xa5957
movl $0xffffffff, 0xc4(%rsp) # imm = 0xFFFFFFFF
movl 0xc4(%rsp), %eax
addq $0xc8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)