// File: /workspace/github_cpp_makefile_star2_O3/alan0201tw[P]RayTracer/src/constant_medium.cpp
// Function: constant_medium::hit(ray const&, float, float, hit_record&) const
bool constant_medium::hit(const ray& _ray, float t_min, float t_max, hit_record& rec) const
{
    //bool db = false;
    hit_record rec1, rec2;

    if(boundary->hit(_ray, -FLOAT_MAX, FLOAT_MAX, rec1) == true)
    {
        if(boundary->hit(_ray, rec1.t + 0.0001f, FLOAT_MAX, rec2) == true)
        {
            if(rec1.t < t_min)
            {
                rec1.t = t_min;
            }
            if(rec2.t > t_max)
            {
                rec2.t = t_max;
            }
            if(rec1.t >= rec2.t)
            {
                return false;
            }
            if(rec1.t < 0)
            {
                rec1.t = 0;
            }
            float distance_inside_boundary = (rec2.t - rec1.t) * _ray.direction().length();
            float hit_distance = -(1 / density) * std::log(drand48());
            if(hit_distance < distance_inside_boundary)
            {
                rec.t = rec1.t + hit_distance / _ray.direction().length();
                rec.hit_point = _ray.point_at_parameter(rec.t);
                rec.normal = vec3(1, 0, 0); // arbitrary
                rec.material_ref = phase_function;
                return true;
            }
        }
    }
    return false;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x80, %rsp
movq %rdx, %rbx
movss %xmm1, 0x4(%rsp)
movss %xmm0, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movups %xmm0, 0x28(%rdx)
movups %xmm0, 0x70(%rsp)
movq 0x8(%rdi), %rdi
movq (%rdi), %rax
movss 0x32e51(%rip), %xmm0    # 0x3c360
movss 0x32e4d(%rip), %xmm1    # 0x3c364
callq *(%rax)
testb %al, %al
je 0x9612
movq 0x8(%r14), %rdi
movss 0x10(%rsp), %xmm0
addss 0x32ccd(%rip), %xmm0    # 0x3c200
movq (%rdi), %rax
movss 0x32e26(%rip), %xmm1    # 0x3c364
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
callq *(%rax)
testb %al, %al
je 0x9612
movss 0x10(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x956a
movss %xmm1, 0x10(%rsp)
movaps %xmm1, %xmm0
movss 0x48(%rsp), %xmm4
movss 0x4(%rsp), %xmm1
ucomiss %xmm1, %xmm4
jbe 0x9584
movss %xmm1, 0x48(%rsp)
movaps %xmm1, %xmm4
ucomiss %xmm4, %xmm0
jae 0x9612
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x95a0
movl $0x0, 0x10(%rsp)
xorps %xmm0, %xmm0
movsd 0xc(%r15), %xmm1
movss 0x14(%r15), %xmm2
movaps %xmm1, %xmm3
mulps %xmm1, %xmm3
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
mulss %xmm1, %xmm1
addss %xmm3, %xmm1
mulss %xmm2, %xmm2
addss %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtss %xmm2, %xmm1
subss %xmm0, %xmm4
mulss %xmm1, %xmm4
movss %xmm4, 0x4(%rsp)
movss 0x32d85(%rip), %xmm0    # 0x3c368
divss 0x18(%r14), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x63a0
callq 0x6320
mulsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss 0x4(%rsp), %xmm1
ucomiss %xmm0, %xmm1
ja 0x9641
xorl %ebx, %ebx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x9623
callq 0x7774
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9632
callq 0x7774
movl %ebx, %eax
addq $0x80, %rsp
popq %rbx
popq %r14
popq %r15
retq
movsd 0xc(%r15), %xmm1
movss 0x14(%r15), %xmm2
movaps %xmm1, %xmm3
mulps %xmm1, %xmm3
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
mulss %xmm1, %xmm1
addss %xmm3, %xmm1
mulss %xmm2, %xmm2
addss %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtss %xmm2, %xmm1
divss %xmm1, %xmm0
addss 0x10(%rsp), %xmm0
movss %xmm0, (%rbx)
movss 0x14(%r15), %xmm1
mulss %xmm0, %xmm1
movsd (%r15), %xmm2
movsd 0xc(%r15), %xmm3
unpcklps %xmm0, %xmm0            # xmm0 = xmm0[0,0,1,1]
mulps %xmm3, %xmm0
addps %xmm2, %xmm0
addss 0x8(%r15), %xmm1
movlps %xmm0, 0xc(%rbx)
movss %xmm1, 0x14(%rbx)
movss 0x32b53(%rip), %xmm0    # 0x3c204
movlps %xmm0, 0x18(%rbx)
movl $0x0, 0x20(%rbx)
movq 0x20(%r14), %rax
movq %rax, 0x28(%rbx)
addq $0x30, %rbx
addq $0x28, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7a28
movb $0x1, %bl
jmp 0x9614
movq %rax, %rbx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x96f0
callq 0x7774
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x96ff
callq 0x7774
movq %rbx, %rdi
callq 0x66e0
nop