// File: /workspace/github_cpp_makefile_star2_O3/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:
movupd 0x40(%rdi), %xmm4
movupd 0x58(%rdi), %xmm5
movsd 0x12f0(%rip), %xmm1     # 0x60f0
divsd 0x28(%rsi), %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm0, %xmm1
setae %al
movupd (%rsi), %xmm2
movupd 0x10(%rsi), %xmm6
movupd 0x18(%rsi), %xmm7
movapd 0x1208(%rip), %xmm3     # 0x6030
divpd %xmm7, %xmm3
xorpd %xmm7, %xmm7
movhpd 0x60(%rdi), %xmm4       # xmm4 = xmm4[0],mem[0]
cmplepd %xmm3, %xmm7
movhpd 0x48(%rdi), %xmm5       # xmm5 = xmm5[0],mem[0]
movapd %xmm7, %xmm8
andnpd %xmm5, %xmm8
movapd %xmm7, %xmm9
andnpd %xmm4, %xmm9
andpd %xmm7, %xmm4
orpd %xmm8, %xmm4
andpd %xmm7, %xmm5
orpd %xmm9, %xmm5
subpd %xmm2, %xmm5
mulpd %xmm3, %xmm5
subpd %xmm2, %xmm4
mulpd %xmm3, %xmm4
movapd %xmm4, %xmm7
shufpd $0x1, %xmm4, %xmm7      # xmm7 = xmm7[1],xmm4[0]
movd %eax, %xmm2
pshufd $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
pslld $0x1f, %xmm2
psrad $0x1f, %xmm2
movq 0x68(%rdi), %xmm8
movq 0x50(%rdi), %xmm9
movdqa %xmm9, %xmm10
punpcklqdq %xmm8, %xmm10   # xmm10 = xmm10[0],xmm8[0]
punpcklqdq %xmm9, %xmm8    # xmm8 = xmm8[0],xmm9[0]
pand %xmm2, %xmm10
pandn %xmm8, %xmm2
por %xmm10, %xmm2
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
movapd %xmm1, %xmm8
unpcklpd %xmm1, %xmm8            # xmm8 = xmm8[0],xmm1[0]
pshufd $0x4e, %xmm2, %xmm2     # xmm2 = xmm2[2,3,0,1]
subpd %xmm6, %xmm2
mulpd %xmm8, %xmm2
movapd %xmm5, %xmm8
unpcklpd %xmm4, %xmm8            # xmm8 = xmm8[0],xmm4[0]
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
cmpltpd %xmm7, %xmm5
movapd %xmm5, %xmm6
andnpd %xmm4, %xmm6
andpd %xmm5, %xmm8
orpd %xmm6, %xmm8
movapd %xmm2, %xmm4
movsd %xmm8, %xmm4            # xmm4 = xmm8[0],xmm4[1]
movapd %xmm8, %xmm6
movsd %xmm2, %xmm6            # xmm6 = xmm2[0],xmm6[1]
cmpltpd %xmm4, %xmm6
movapd %xmm6, %xmm4
andnpd %xmm8, %xmm4
andpd %xmm6, %xmm2
orpd %xmm4, %xmm2
pshufd $0xee, %xmm2, %xmm4     # xmm4 = xmm2[2,3,2,3]
ucomisd %xmm4, %xmm2
jbe 0x4ff4
ucomisd 0x1435(%rip), %xmm2     # 0x6370
jbe 0x4ff4
movmskpd %xmm6, %eax
movmskpd %xmm5, %ecx
xorpd %xmm0, %xmm0
cmplepd %xmm3, %xmm0
movmskpd %xmm0, %r8d
xorl %edx, %edx
testb $0x2, %r8b
sete %dl
movl %r8d, %r9d
shrb %r9b
xorpd %xmm0, %xmm0
xorl %esi, %esi
xorl %r10d, %r10d
ucomisd %xmm0, %xmm1
setb %sil
setae %r10b
movl %r8d, %r11d
andl $0x1, %r11d
leal (%r11,%r11,2), %r11d
movzbl %r9b, %r9d
leal (%r9,%r9,2), %r9d
incl %r9d
testb $0x1, %cl
cmovnel %r11d, %r9d
leal (%r10,%r10,2), %r10d
addl $0x2, %r10d
testb $0x1, %al
cmovnel %r10d, %r9d
notb %r8b
movzbl %r8b, %r8d
andl $0x1, %r8d
leal (%r8,%r8,2), %r8d
leal (%rdx,%rdx,2), %edx
incl %edx
testb $0x2, %cl
cmovnel %r8d, %edx
leal (%rsi,%rsi,2), %ecx
addl $0x2, %ecx
testb $0x2, %al
cmovnel %ecx, %edx
movsd 0x139c(%rip), %xmm0     # 0x6370
ucomisd %xmm0, %xmm4
cmovbel %r9d, %edx
cmpltsd %xmm4, %xmm0
movapd %xmm0, %xmm1
andpd %xmm4, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movl %edx, 0x70(%rdi)
retq
nop