// File: /workspace/github_cpp_makefile_star2_O1/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 0x32d19(%rip), %xmm0    # 0x3c340
movss 0x32d15(%rip), %xmm1    # 0x3c344
callq *(%rax)
testb %al, %al
je 0x9753
movq 0x8(%r14), %rdi
movss 0x10(%rsp), %xmm0
addss 0x32bb5(%rip), %xmm0    # 0x3c200
movq (%rdi), %rax
movss 0x32cee(%rip), %xmm1    # 0x3c344
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
callq *(%rax)
testb %al, %al
je 0x9753
movss 0x8(%rsp), %xmm0
ucomiss 0x10(%rsp), %xmm0
jbe 0x967b
movss %xmm0, 0x10(%rsp)
movss 0x48(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x9692
movss %xmm1, 0x48(%rsp)
movss 0x10(%rsp), %xmm0
movss 0x48(%rsp), %xmm4
ucomiss %xmm4, %xmm0
jae 0x9753
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x96b7
movl $0x0, 0x10(%rsp)
movss 0x10(%rsp), %xmm5
movsd 0xc(%r15), %xmm2
movss 0x14(%r15), %xmm0
movaps %xmm2, %xmm3
mulps %xmm2, %xmm3
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
mulss %xmm0, %xmm0
addss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
jb 0x96ee
sqrtss %xmm0, %xmm0
jmp 0x970b
movss %xmm4, 0x4(%rsp)
movss %xmm5, 0x8(%rsp)
callq 0x6710
movss 0x8(%rsp), %xmm5
movss 0x4(%rsp), %xmm4
subss %xmm5, %xmm4
mulss %xmm0, %xmm4
movss %xmm4, 0x4(%rsp)
movss 0x32c27(%rip), %xmm0    # 0x3c348
divss 0x18(%r14), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x63a0
callq 0x6320
mulsd 0x8(%rsp), %xmm0
xorps %xmm4, %xmm4
cvtsd2ss %xmm0, %xmm4
movss 0x4(%rsp), %xmm0
ucomiss %xmm4, %xmm0
ja 0x9782
xorl %ebx, %ebx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x9764
callq 0x7768
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9773
callq 0x7768
movl %ebx, %eax
addq $0x80, %rsp
popq %rbx
popq %r14
popq %r15
retq
movss 0x10(%rsp), %xmm3
movsd 0xc(%r15), %xmm1
movss 0x14(%r15), %xmm0
movaps %xmm1, %xmm2
mulps %xmm1, %xmm2
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x97bc
sqrtss %xmm0, %xmm0
jmp 0x97d9
movss %xmm3, 0x4(%rsp)
movss %xmm4, 0x8(%rsp)
callq 0x6710
movss 0x8(%rsp), %xmm4
movss 0x4(%rsp), %xmm3
divss %xmm0, %xmm4
addss %xmm4, %xmm3
movss %xmm3, (%rbx)
movss 0xc(%r15), %xmm0
mulss %xmm3, %xmm0
movss 0x10(%r15), %xmm1
mulss %xmm3, %xmm1
mulss 0x14(%r15), %xmm3
addss (%r15), %xmm0
addss 0x4(%r15), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
addss 0x8(%r15), %xmm3
movlps %xmm0, 0xc(%rbx)
movss %xmm3, 0x14(%rbx)
movq $0x3f800000, 0x18(%rbx) # imm = 0x3F800000
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 0x7a04
movb $0x1, %bl
jmp 0x9755
movq %rax, %rbx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x985f
callq 0x7768
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x986e
callq 0x7768
movq %rbx, %rdi
callq 0x66e0