// File: /workspace/github_cpp_makefile_star2_O1/Aries-orz[P]Ari-RayTracing/src/RTBox.cpp
// Function: rt::RTBox::hit(rt::Ray const&)
double RTBox::hit(const Ray& r) {
    double tmin = 0;
    double ox = r.o.x, oy = r.o.y, oz = r.o.z;
    double dx = r.d.x, dy = r.d.y, dz = r.d.z;
    double x0 = p0.x, y0 = p0.y, z0 = p0.z;
    double x1 = p1.x, y1 = p1.y, z1 = p1.z;
        
    double tx_min, ty_min, tz_min;
    double tx_max, ty_max, tz_max;
        
    double a = 1.0/dx;
    if (a >= 0) {
        tx_min = (x0 - ox) * a;
        tx_max = (x1 - ox) * a;
    } else {
        tx_min = (x1 - ox) * a;
        tx_max = (x0 - ox) * a;
    }
        
    double b = 1.0/dy;
    if (b >= 0) {
        ty_min = (y0 - oy) * b;
        ty_max = (y1 - oy) * b;
    } else {
        ty_min = (y1 - oy) * b;
        ty_max = (y0 - oy) * b;
    }
        
    double c = 1.0/dz;
    if (c >= 0) {
        tz_min = (z0 - oz) * c;
        tz_max = (z1 - oz) * c;
    } else {
        tz_min = (z1 - oz) * c;
        tz_max = (z0 - oz) * c;
    }
        
    double t0, t1;
    int face_in, face_out;
    if (tx_min > ty_min) {
        t0 = tx_min;
        face_in = (a >= 0.0) ? 0 : 3;
    } else {
        t0 = ty_min;
        face_in = (b >= 0.0) ? 1 : 4;
    }
    if (tz_min > t0) {
        t0 = tz_min;
        face_in = (c >= 0.0) ? 2 : 5;
    }
        
    if (tx_max < ty_max) {
        t1 = tx_max;
        face_out = (a >= 0.0) ? 3 : 0;
    } else {
        t1 = ty_max;
        face_out = (b >= 0.0) ? 4 : 1;
    }
    if (tz_max < t1) {
        t1 = tz_max;
        face_out = (c >= 0.0) ? 5 : 2;
    }
        
    if (t0 < t1 && t1 > 1e-4) {
        if (t0 > 1e-4) {
            tmin = t0;
            face = face_in;
        } else {
            tmin = t1;
            face = face_out;
        }
    }
    return tmin;
}

// Assembly:
movsd (%rsi), %xmm7
movsd 0x40(%rdi), %xmm1
movsd 0x48(%rdi), %xmm2
movsd 0x58(%rdi), %xmm5
movsd 0x60(%rdi), %xmm8
movsd 0x2085(%rip), %xmm6     # 0x7060
movapd %xmm6, %xmm3
divsd 0x18(%rsi), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
xorpd %xmm4, %xmm4
cmplesd %xmm3, %xmm4
movapd %xmm4, %xmm9
andpd %xmm5, %xmm9
andnpd %xmm1, %xmm4
orpd %xmm9, %xmm4
jae 0x500e
movapd %xmm5, %xmm1
movsd 0x8(%rsi), %xmm12
movsd 0x50(%rdi), %xmm10
movsd 0x68(%rdi), %xmm5
subsd %xmm7, %xmm1
subsd %xmm7, %xmm4
movapd %xmm6, %xmm9
divsd 0x20(%rsi), %xmm9
ucomisd %xmm0, %xmm9
xorpd %xmm7, %xmm7
cmplesd %xmm9, %xmm7
movapd %xmm7, %xmm11
andpd %xmm8, %xmm11
andnpd %xmm2, %xmm7
orpd %xmm11, %xmm7
jae 0x505b
movapd %xmm8, %xmm2
movsd 0x10(%rsi), %xmm11
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm4
subsd %xmm12, %xmm2
mulsd %xmm9, %xmm2
subsd %xmm12, %xmm7
mulsd %xmm9, %xmm7
divsd 0x28(%rsi), %xmm6
ucomisd %xmm0, %xmm6
xorpd %xmm8, %xmm8
cmplesd %xmm6, %xmm8
movapd %xmm8, %xmm12
andpd %xmm10, %xmm12
andnpd %xmm5, %xmm8
orpd %xmm12, %xmm8
jae 0x50ac
movapd %xmm10, %xmm5
subsd %xmm11, %xmm5
mulsd %xmm6, %xmm5
subsd %xmm11, %xmm8
mulsd %xmm6, %xmm8
movapd %xmm1, %xmm12
maxsd %xmm2, %xmm12
movapd %xmm8, %xmm10
maxsd %xmm12, %xmm10
movapd %xmm4, %xmm13
minsd %xmm7, %xmm13
movapd %xmm5, %xmm11
minsd %xmm13, %xmm11
ucomisd %xmm10, %xmm11
jbe 0x5190
ucomisd 0x21ad(%rip), %xmm11    # 0x72a8
jbe 0x5190
xorl %eax, %eax
xorl %edx, %edx
ucomisd %xmm0, %xmm6
setb %al
setae %dl
xorl %ecx, %ecx
xorl %esi, %esi
ucomisd %xmm0, %xmm9
setb %cl
setae %sil
xorl %r8d, %r8d
xorl %r9d, %r9d
ucomisd %xmm0, %xmm3
setb %r8b
setae %r9b
ucomisd %xmm4, %xmm7
leal (%r9,%r9,2), %r9d
leal 0x1(%rsi,%rsi,2), %esi
cmoval %r9d, %esi
ucomisd %xmm5, %xmm13
leal 0x2(%rdx,%rdx,2), %edx
cmovbel %esi, %edx
ucomisd %xmm2, %xmm1
leal (%r8,%r8,2), %esi
leal 0x1(%rcx,%rcx,2), %ecx
cmoval %esi, %ecx
ucomisd %xmm12, %xmm8
leal 0x2(%rax,%rax,2), %eax
cmovbel %ecx, %eax
movsd 0x2138(%rip), %xmm0     # 0x72a8
ucomisd %xmm0, %xmm10
cmovbel %edx, %eax
cmpltsd %xmm10, %xmm0
andpd %xmm0, %xmm10
andnpd %xmm11, %xmm0
orpd %xmm10, %xmm0
movl %eax, 0x70(%rdi)
retq
nop