// File: alan0201tw[P]RayTracer/src/bvh.cpp
// Function: bvh_node::hit(ray const&, float, float, hit_record&) const
bool bvh_node::hit(const ray& _ray, float t_min, float t_max, hit_record& rec) const
{
    if(box.hit(_ray, t_min, t_max))
    {
        hit_record left_record, right_record;
        bool hit_left = left->hit(_ray, t_min, t_max, left_record);
        bool hit_right = right->hit(_ray, t_min, t_max, right_record);

        if(hit_left && hit_right)
        {
            if(left_record.t < right_record.t)
            {
                rec = left_record;
                return true;
            }
            else
            {
                rec = right_record;
                return true;
            }
        }
        else if(hit_left)
        {
            rec = left_record;
            return true;
        }
        else if(hit_right)
        {
            rec = right_record;
            return true;
        }
        else
        {
            return false;
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movss %xmm1, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
addq $0x28, %rdi
movq -0x18(%rbp), %rsi
movss -0x1c(%rbp), %xmm0
movss -0x20(%rbp), %xmm1
callq 0x1abe0
testb $0x1, %al
jne 0x1376c
jmp 0x13931
leaq -0x60(%rbp), %rdi
callq 0x10540
leaq -0x98(%rbp), %rdi
callq 0x10540
jmp 0x13783
movq -0xb8(%rbp), %rdi
addq $0x8, %rdi
callq 0x105a0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
movss -0x1c(%rbp), %xmm0
movss -0x20(%rbp), %xmm1
movq (%rdi), %rax
movq (%rax), %rax
leaq -0x60(%rbp), %rdx
callq *%rax
movb %al, -0xb9(%rbp)
jmp 0x137b8
movq -0xb8(%rbp), %rdi
movb -0xb9(%rbp), %al
andb $0x1, %al
movb %al, -0xa5(%rbp)
addq $0x18, %rdi
callq 0x105a0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
movss -0x1c(%rbp), %xmm0
movss -0x20(%rbp), %xmm1
movq (%rdi), %rax
movq (%rax), %rax
leaq -0x98(%rbp), %rdx
callq *%rax
movb %al, -0xba(%rbp)
jmp 0x137fe
movb -0xba(%rbp), %al
andb $0x1, %al
movb %al, -0xa6(%rbp)
testb $0x1, -0xa5(%rbp)
je 0x138b2
testb $0x1, -0xa6(%rbp)
je 0x138b2
movss -0x60(%rbp), %xmm1
movss -0x98(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x13892
movq -0x28(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x105c0
movb $0x1, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0x1390f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x13926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10610
jmp 0x13926
movq -0x28(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x105c0
movb $0x1, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0x1390f
testb $0x1, -0xa5(%rbp)
je 0x138d8
movq -0x28(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x105c0
movb $0x1, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0x1390f
testb $0x1, -0xa6(%rbp)
je 0x13901
movq -0x28(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x105c0
movb $0x1, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0x1390f
movb $0x0, -0x1(%rbp)
movl $0x1, -0xac(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10610
leaq -0x60(%rbp), %rdi
callq 0x10610
jmp 0x13935
leaq -0x60(%rbp), %rdi
callq 0x10610
jmp 0x13943
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x7860
nop