// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Isect.cpp
// Function: gaps::R3Intersects(gaps::R3Ray const&, gaps::R3OrientedBox const&, gaps::R3Point*, gaps::R3Vector*, double*)
RNClassID R3Intersects(const R3Ray& ray, const R3OrientedBox& box, 
    R3Point *hit_point1, R3Vector *hit_normal1, RNScalar *hit_t1)
{
    // Check if box is empty
    if (box.IsEmpty()) return RN_NULL_CLASS_ID;

    // Transform ray into std coordinate system
    R3Ray transformed_ray = ray;
    R3Affine cs_to_std_xform(box.CoordSystem().InverseMatrix());
    transformed_ray.Transform(cs_to_std_xform);

    // Intersect in std coordinate system
    R3Box axis_aligned_box(-box.Radius(0), -box.Radius(1), -box.Radius(2), box.Radius(0), box.Radius(1), box.Radius(2));
    int status = R3Intersects(transformed_ray, axis_aligned_box, hit_point1, hit_normal1, hit_t1);
    if (status == RN_NULL_CLASS_ID) return RN_NULL_CLASS_ID;

    // Compute hit point
    if (hit_point1 || hit_normal1) {
      R3Affine std_to_cs_xform(box.CoordSystem().Matrix());
      if (hit_point1) hit_point1->Transform(std_to_cs_xform);
      if (hit_normal1) hit_normal1->Transform(std_to_cs_xform);
    }

    // Return whether hit
    return status;
}

// Assembly:
subq $0x448, %rsp            # imm = 0x448
movq %rdi, 0x438(%rsp)
movq %rsi, 0x430(%rsp)
movq %rdx, 0x428(%rsp)
movq %rcx, 0x420(%rsp)
movq %r8, 0x418(%rsp)
movq 0x430(%rsp), %rdi
callq 0x3c180
cmpl $0x0, %eax
je 0x7c241
movl $0x0, 0x444(%rsp)
jmp 0x7c568
movq 0x438(%rsp), %rsi
leaq 0x3e8(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x6e3e0
movq 0x430(%rsp), %rdi
callq 0x81bb0
movq %rax, %rsi
leaq 0x258(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4e590
movq 0x60(%rsp), %rsi
leaq 0x2d8(%rsp), %rdi
movq %rdi, 0x70(%rsp)
xorl %edx, %edx
callq 0x4d390
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x6e600
jmp 0x7c2a7
movq 0x430(%rsp), %rdi
xorl %esi, %esi
callq 0x3c1d0
movsd %xmm0, 0x58(%rsp)
jmp 0x7c2be
movsd 0x58(%rsp), %xmm0
movaps 0xb6d65(%rip), %xmm1    # 0x133030
pxor %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x430(%rsp), %rdi
movl $0x1, %esi
callq 0x3c1d0
movsd %xmm0, 0x50(%rsp)
jmp 0x7c2ef
movsd 0x50(%rsp), %xmm0
movaps 0xb6d34(%rip), %xmm1    # 0x133030
pxor %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x430(%rsp), %rdi
movl $0x2, %esi
callq 0x3c1d0
movsd %xmm0, 0x40(%rsp)
jmp 0x7c320
movsd 0x40(%rsp), %xmm0
movaps 0xb6d03(%rip), %xmm1    # 0x133030
pxor %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x430(%rsp), %rdi
xorl %esi, %esi
callq 0x3c1d0
movsd %xmm0, 0x30(%rsp)
jmp 0x7c34e
movq 0x430(%rsp), %rdi
movl $0x1, %esi
callq 0x3c1d0
movsd %xmm0, 0x20(%rsp)
jmp 0x7c368
movq 0x430(%rsp), %rdi
movl $0x2, %esi
callq 0x3c1d0
movsd %xmm0, 0x18(%rsp)
jmp 0x7c382
movsd 0x18(%rsp), %xmm5
movsd 0x20(%rsp), %xmm4
movsd 0x30(%rsp), %xmm3
movsd 0x28(%rsp), %xmm2
movsd 0x38(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
leaq 0x210(%rsp), %rdi
callq 0x429c0
jmp 0x7c3b5
movq 0x428(%rsp), %rdx
movq 0x420(%rsp), %rcx
movq 0x418(%rsp), %r8
leaq 0x3e8(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x7b430
movl %eax, 0x14(%rsp)
jmp 0x7c3e8
movl 0x14(%rsp), %eax
movl %eax, 0x20c(%rsp)
cmpl $0x0, 0x20c(%rsp)
jne 0x7c44a
movl $0x0, 0x444(%rsp)
movl $0x1, 0x208(%rsp)
jmp 0x7c530
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x7c559
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x7c54c
cmpq $0x0, 0x428(%rsp)
jne 0x7c464
cmpq $0x0, 0x420(%rsp)
je 0x7c517
movq 0x430(%rsp), %rdi
callq 0x81bb0
movq %rax, 0x8(%rsp)
jmp 0x7c478
movq 0x8(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x4e500
jmp 0x7c489
leaq 0xf8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
xorl %edx, %edx
callq 0x4d390
jmp 0x7c49f
cmpq $0x0, 0x428(%rsp)
je 0x7c4e6
movq 0x428(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x6f7c0
jmp 0x7c4c1
jmp 0x7c4e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x4d430
jmp 0x7c54c
cmpq $0x0, 0x420(%rsp)
je 0x7c50a
movq 0x420(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x70e10
jmp 0x7c508
jmp 0x7c50a
leaq 0xf8(%rsp), %rdi
callq 0x4d430
movl 0x20c(%rsp), %eax
movl %eax, 0x444(%rsp)
movl $0x1, 0x208(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x36a80
leaq 0x2d8(%rsp), %rdi
callq 0x4d430
jmp 0x7c568
leaq 0x210(%rsp), %rdi
callq 0x36a80
leaq 0x2d8(%rsp), %rdi
callq 0x4d430
jmp 0x7c577
movl 0x444(%rsp), %eax
addq $0x448, %rsp            # imm = 0x448
retq
movq 0x250(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)