// File: /workspace/github_cpp_makefile_star2_O2/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 0x26dc7(%rip), %xmm0    # 0x30348
movss 0x26dc3(%rip), %xmm1    # 0x3034c
callq *(%rax)
testb %al, %al
je 0x967a
movq 0x8(%r14), %rdi
movss 0x10(%rsp), %xmm0
addss 0x26c5b(%rip), %xmm0    # 0x30200
movq (%rdi), %rax
movss 0x26d9c(%rip), %xmm1    # 0x3034c
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
callq *(%rax)
testb %al, %al
je 0x967a
movss 0x10(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x95dc
movss %xmm1, 0x10(%rsp)
movaps %xmm1, %xmm0
movss 0x48(%rsp), %xmm4
movss 0x4(%rsp), %xmm1
ucomiss %xmm1, %xmm4
jbe 0x95f6
movss %xmm1, 0x48(%rsp)
movaps %xmm1, %xmm4
ucomiss %xmm4, %xmm0
jae 0x967a
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x960b
andl $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
sqrtss %xmm2, %xmm1
subss %xmm0, %xmm4
mulss %xmm1, %xmm4
movss %xmm4, 0x4(%rsp)
movss 0x26d05(%rip), %xmm0    # 0x30350
divss 0x18(%r14), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x63e0
callq 0x6350
mulsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss 0x4(%rsp), %xmm1
ucomiss %xmm0, %xmm1
ja 0x969f
xorl %ebx, %ebx
leaq 0x78(%rsp), %rdi
callq 0x7426
leaq 0x40(%rsp), %rdi
callq 0x7426
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
sqrtss %xmm2, %xmm1
divss %xmm1, %xmm0
addss 0x10(%rsp), %xmm0
movss %xmm0, (%rbx)
movq %r15, %rdi
callq 0x8924
movlps %xmm0, 0xc(%rbx)
movss %xmm1, 0x14(%rbx)
movss 0x26b14(%rip), %xmm0    # 0x30204
movlps %xmm0, 0x18(%rbx)
andl $0x0, 0x20(%rbx)
addq $0x20, %r14
addq $0x28, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x894e
movb $0x1, %bl
jmp 0x967c
jmp 0x9714
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x7426
leaq 0x40(%rsp), %rdi
callq 0x7426
movq %rbx, %rdi
callq 0x6710
nop