// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Isect.cpp
// Function: gaps::R3Intersects(gaps::R3Box const&, gaps::R3Box const&, gaps::R3Box*)
RNClassID R3Intersects(const R3Box& box1, const R3Box& box2, 
    R3Box *result)
{
    // Compute whether box intersects box
    if ((RNIsGreater(box1.XMin(), box2.XMax())) ||
        (RNIsGreater(box1.YMin(), box2.YMax())) ||
        (RNIsGreater(box1.ZMin(), box2.ZMax())) ||
        (RNIsGreater(box2.XMin(), box1.XMax())) ||
        (RNIsGreater(box2.YMin(), box1.YMax())) ||
        (RNIsGreater(box2.ZMin(), box1.ZMax()))) 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 zmin = box1.ZMin();
        if (zmin < box2.ZMin()) zmin = box2.ZMin();
        RNCoord xmax = box1.XMax();
        if (xmax > box2.XMax()) xmax = box2.XMax();
        RNCoord ymax = box1.YMax();
        if (ymax > box2.YMax()) ymax = box2.YMax();
        RNCoord zmax = box1.ZMax();
        if (zmax > box2.ZMax()) zmax = box2.ZMax();
        *result = R3Box(xmin, ymin, zmin, xmax, ymax, zmax);
    }
    
    // Return ID of intersection ???
    return RN_UNKNOWN_CLASS_ID;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x37830
movsd %xmm0, 0x68(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x44f80
movaps %xmm0, %xmm1
movsd 0x68(%rsp), %xmm0
leaq 0xf7681(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0x80faf
movq 0xf8(%rsp), %rdi
callq 0x37880
movsd %xmm0, 0x60(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x44fa0
movaps %xmm0, %xmm1
movsd 0x60(%rsp), %xmm0
leaq 0xf763f(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0x80faf
movq 0xf8(%rsp), %rdi
callq 0x378d0
movsd %xmm0, 0x58(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x44fc0
movaps %xmm0, %xmm1
movsd 0x58(%rsp), %xmm0
leaq 0xf75fd(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0x80faf
movq 0xf0(%rsp), %rdi
callq 0x37830
movsd %xmm0, 0x50(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44f80
movaps %xmm0, %xmm1
movsd 0x50(%rsp), %xmm0
leaq 0xf75bb(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0x80faf
movq 0xf0(%rsp), %rdi
callq 0x37880
movsd %xmm0, 0x48(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44fa0
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
leaq 0xf757d(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
jne 0x80faf
movq 0xf0(%rsp), %rdi
callq 0x378d0
movsd %xmm0, 0x40(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44fc0
movaps %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
leaq 0xf753f(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm2
callq 0x3c090
cmpl $0x0, %eax
je 0x80fbf
movl $0x0, 0x104(%rsp)
jmp 0x81262
cmpq $0x0, 0xe8(%rsp)
je 0x81257
movq 0xf8(%rsp), %rdi
callq 0x37830
movsd %xmm0, 0xe0(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x37830
movsd 0x38(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x81022
movq 0xf0(%rsp), %rdi
callq 0x37830
movsd %xmm0, 0xe0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x37880
movsd %xmm0, 0xd8(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x37880
movsd 0x30(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x81076
movq 0xf0(%rsp), %rdi
callq 0x37880
movsd %xmm0, 0xd8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x378d0
movsd %xmm0, 0xd0(%rsp)
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x378d0
movsd 0x28(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x810ca
movq 0xf0(%rsp), %rdi
callq 0x378d0
movsd %xmm0, 0xd0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44f80
movsd %xmm0, 0xc8(%rsp)
movsd 0xc8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x44f80
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x81121
movq 0xf0(%rsp), %rdi
callq 0x44f80
movsd %xmm0, 0xc8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44fa0
movsd %xmm0, 0xc0(%rsp)
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x44fa0
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x81178
movq 0xf0(%rsp), %rdi
callq 0x44fa0
movsd %xmm0, 0xc0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44fc0
movsd %xmm0, 0xb8(%rsp)
movsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x44fc0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x811cf
movq 0xf0(%rsp), %rdi
callq 0x44fc0
movsd %xmm0, 0xb8(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
movsd 0xd0(%rsp), %xmm2
movsd 0xc8(%rsp), %xmm3
movsd 0xc0(%rsp), %xmm4
movsd 0xb8(%rsp), %xmm5
leaq 0x80(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x429c0
movq 0x8(%rsp), %rsi
movq 0xe8(%rsp), %rdi
callq 0x37500
jmp 0x8122b
leaq 0x80(%rsp), %rdi
callq 0x36a80
jmp 0x81257
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x36a80
jmp 0x81271
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
movq 0x78(%rsp), %rdi
callq 0xf890
nopl (%rax,%rax)