// File: /workspace/github_cpp_makefile_star2_O2/Aries-orz[P]Ari-RayTracing/src/RTBBox.cpp
// Function: rt::RTBBox::hit(rt::Ray const&)
double RTBBox::hit(const Ray& r) {
    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;
    if (tx_min > ty_min)
        t0 = tx_min;
    else
        t0 = ty_min;
    if (tz_min > t0)
        t0 = tz_min;
    
    if (tx_max < ty_max)
        t1 = tx_max;
    else
        t1 = ty_max;
    if (tz_max < t1)
        t1 = tz_max;
    
    if (t0 < t1 && t1 > 1e-4) return 1;
    return 0;
}

// Assembly:
movupd 0x40(%rdi), %xmm2
movupd 0x58(%rdi), %xmm0
movsd 0x15fc(%rip), %xmm1     # 0x60f0
movapd %xmm1, %xmm3
divsd 0x28(%rsi), %xmm3
xorpd %xmm4, %xmm4
xorl %eax, %eax
ucomisd %xmm4, %xmm3
setb %al
movupd (%rsi), %xmm5
movupd 0x10(%rsi), %xmm4
movupd 0x18(%rsi), %xmm6
movapd 0x1510(%rip), %xmm7     # 0x6030
divpd %xmm6, %xmm7
xorpd %xmm6, %xmm6
cmpnlepd %xmm7, %xmm6
movhpd 0x48(%rdi), %xmm0       # xmm0 = xmm0[0],mem[0]
movhpd 0x60(%rdi), %xmm2       # xmm2 = xmm2[0],mem[0]
movapd %xmm6, %xmm8
andnpd %xmm2, %xmm8
movapd %xmm6, %xmm9
andnpd %xmm0, %xmm9
andpd %xmm6, %xmm0
orpd %xmm8, %xmm0
andpd %xmm6, %xmm2
orpd %xmm9, %xmm2
subpd %xmm5, %xmm2
mulpd %xmm7, %xmm2
subpd %xmm5, %xmm0
mulpd %xmm7, %xmm0
movapd %xmm0, %xmm5
shufpd $0x1, %xmm0, %xmm5      # xmm5 = xmm5[1],xmm0[0]
movd %eax, %xmm6
pshufd $0x0, %xmm6, %xmm6      # xmm6 = xmm6[0,0,0,0]
pslld $0x1f, %xmm6
psrad $0x1f, %xmm6
movq 0x50(%rdi), %xmm7
movq 0x68(%rdi), %xmm8
movdqa %xmm8, %xmm9
punpcklqdq %xmm7, %xmm9    # xmm9 = xmm9[0],xmm7[0]
punpcklqdq %xmm8, %xmm7    # xmm7 = xmm7[0],xmm8[0]
pand %xmm6, %xmm9
pandn %xmm7, %xmm6
por %xmm9, %xmm6
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
pshufd $0x4e, %xmm6, %xmm6     # xmm6 = xmm6[2,3,0,1]
subpd %xmm4, %xmm6
mulpd %xmm3, %xmm6
movapd %xmm2, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
cmpltpd %xmm5, %xmm2
andpd %xmm2, %xmm3
andnpd %xmm0, %xmm2
orpd %xmm3, %xmm2
movapd %xmm6, %xmm0
movsd %xmm2, %xmm0            # xmm0 = xmm2[0],xmm0[1]
movapd %xmm2, %xmm3
movsd %xmm6, %xmm3            # xmm3 = xmm6[0],xmm3[1]
cmpltpd %xmm0, %xmm3
andpd %xmm3, %xmm6
andnpd %xmm2, %xmm3
orpd %xmm6, %xmm3
pshufd $0xee, %xmm3, %xmm2     # xmm2 = xmm3[2,3,2,3]
cmpltsd %xmm3, %xmm2
movsd 0x1782(%rip), %xmm0     # 0x6398
cmpltsd %xmm3, %xmm0
andpd %xmm1, %xmm0
andpd %xmm2, %xmm0
retq