// File: /workspace/github_cpp_makefile_star2_O1/2TallTim[P]modern-raytracing/bvh.cpp
// Function: bvh_node::bvh_node(__gnu_cxx::__normal_iterator<std::shared_ptr<hitable>*, std::vector<std::shared_ptr<hitable>, std::allocator<std::shared_ptr<hitable>>>>, __gnu_cxx::__normal_iterator<std::shared_ptr<hitable>*, std::vector<std::shared_ptr<hitable>, std::allocator<std::shared_ptr<hitable>>>>)
bvh_node::bvh_node(std::vector<hitable::Ptr>::iterator begin,
                   std::vector<hitable::Ptr>::iterator end) {
    int axis = int(rng::gen01()*3);
    switch (axis)
    {
    case 0:
        std::sort(begin,end,box_compare<0>());
        break;
    case 1:
        std::sort(begin,end,box_compare<1>());
        break;
    case 2:
        std::sort(begin,end,box_compare<2>());
    default:
        break;
    }
    int dist = std::distance(begin,end);
    if(dist == 1){
        left = right = *begin;
    }else if(dist == 2){
        left = *begin;
        right = *(begin+1);
    }else{
        left = std::make_shared<bvh_node>(begin,begin+dist/2);
        right = std::make_shared<bvh_node>(begin+dist/2,end);
    }

    aabb box_left, box_right;
    if(!left->bounding_box(box_left) || !right->bounding_box(box_right))
        std::cerr << "no bounding box in bvh_node constructor!" << std::endl;
    box = aabb::surrounding_box(box_left,box_right);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x80, %rsp
movq %rdi, %rbx
movq %rsi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
leaq 0x6556(%rip), %rax      # 0xdd70
movq %rax, (%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movupd %xmm0, 0x18(%rdi)
movupd %xmm0, 0x28(%rdi)
movupd %xmm0, 0x38(%rdi)
movupd %xmm0, 0x48(%rdi)
callq 0x3d9a
mulsd 0x2c89(%rip), %xmm0     # 0xa4d0
cvttsd2si %xmm0, %eax
testl %eax, %eax
je 0x78e1
cmpl $0x1, %eax
je 0x78a3
cmpl $0x2, %eax
jne 0x791d
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x791d
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8f56
movq %r14, %rdi
movq %r15, %rsi
callq 0x9009
jmp 0x791d
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x791d
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8657
movq %r14, %rdi
movq %r15, %rsi
callq 0x870a
jmp 0x791d
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x791d
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7d02
movq %r14, %rdi
movq %r15, %rsi
callq 0x7db5
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
shrq $0x4, %rax
cmpl $0x2, %eax
je 0x7960
cmpl $0x1, %eax
jne 0x7993
movq (%rsi), %rax
movq %rax, 0x18(%rbx)
leaq 0x20(%rbx), %r14
addq $0x8, %rsi
movq %r14, %rdi
callq 0x37a6
movq 0x18(%rbx), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
movq %r14, %rsi
jmp 0x7989
movq (%rsi), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
addq $0x8, %rsi
callq 0x37a6
movq 0x10(%rsp), %rsi
movq 0x10(%rsi), %rax
movq %rax, 0x18(%rbx)
leaq 0x20(%rbx), %rdi
addq $0x18, %rsi
callq 0x37a6
jmp 0x7a5d
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movslq %ecx, %r14
shlq $0x4, %r14
addq %r14, %rsi
leaq 0x50(%rsp), %r8
movq %rsi, (%r8)
leaq 0x28(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x20(%rsp), %rsi
leaq 0xf(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x9856
movapd 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x10(%rbx), %rdi
movupd %xmm0, 0x8(%rbx)
testq %rdi, %rdi
je 0x79f0
callq 0x37ec
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x79ff
callq 0x37ec
addq 0x10(%rsp), %r14
leaq 0x50(%rsp), %rcx
movq %r14, (%rcx)
leaq 0x28(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x20(%rsp), %rsi
leaq 0xf(%rsp), %rdx
leaq 0x18(%rsp), %r8
callq 0x98d6
movapd 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x20(%rbx), %rdi
movupd %xmm0, 0x18(%rbx)
testq %rdi, %rdi
je 0x7a4e
callq 0x37ec
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x7a5d
callq 0x37ec
leaq 0x8(%rbx), %rax
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movapd %xmm0, 0x20(%rsi)
movapd %xmm0, 0x10(%rsi)
movapd %xmm0, (%rsi)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
testb %al, %al
je 0x7aaa
movq 0x18(%rbx), %rdi
movq (%rdi), %rax
leaq 0x50(%rsp), %rsi
callq *0x8(%rax)
testb %al, %al
jne 0x7af0
movq 0x653f(%rip), %r14      # 0xdff0
leaq 0x2a20(%rip), %rsi      # 0xa4d8
movl $0x28, %edx
movq %r14, %rdi
callq 0x3200
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x31c0
movsbl %al, %esi
movq 0x650d(%rip), %rdi      # 0xdff0
callq 0x3030
movq %rax, %rdi
callq 0x30e0
movsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
movapd %xmm3, %xmm0
cmpunordsd %xmm3, %xmm0
movapd %xmm0, %xmm5
andpd %xmm1, %xmm5
minsd %xmm3, %xmm1
andnpd %xmm1, %xmm0
orpd %xmm5, %xmm0
movapd %xmm4, %xmm1
cmpunordsd %xmm4, %xmm1
movapd %xmm1, %xmm3
andpd %xmm2, %xmm3
minsd %xmm4, %xmm2
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movsd 0x30(%rsp), %xmm3
movsd 0x60(%rsp), %xmm4
movapd %xmm3, %xmm2
cmpunordsd %xmm3, %xmm2
movapd %xmm2, %xmm5
andpd %xmm4, %xmm5
minsd %xmm3, %xmm4
andnpd %xmm4, %xmm2
orpd %xmm5, %xmm2
movsd 0x38(%rsp), %xmm4
movsd 0x68(%rsp), %xmm5
movapd %xmm4, %xmm3
cmpunordsd %xmm4, %xmm3
movapd %xmm3, %xmm6
andpd %xmm5, %xmm6
maxsd %xmm4, %xmm5
andnpd %xmm5, %xmm3
orpd %xmm6, %xmm3
movsd 0x40(%rsp), %xmm4
movsd 0x70(%rsp), %xmm5
movapd %xmm4, %xmm6
cmpunordsd %xmm4, %xmm6
movapd %xmm6, %xmm7
andpd %xmm5, %xmm7
maxsd %xmm4, %xmm5
andnpd %xmm5, %xmm6
orpd %xmm7, %xmm6
movsd 0x48(%rsp), %xmm4
movsd 0x78(%rsp), %xmm5
movapd %xmm4, %xmm7
cmpunordsd %xmm4, %xmm7
movapd %xmm7, %xmm8
andpd %xmm5, %xmm8
maxsd %xmm4, %xmm5
andnpd %xmm5, %xmm7
orpd %xmm8, %xmm7
movlpd %xmm0, 0x28(%rbx)
movlpd %xmm1, 0x30(%rbx)
movlpd %xmm2, 0x38(%rbx)
movlpd %xmm3, 0x40(%rbx)
movlpd %xmm6, 0x48(%rbx)
movlpd %xmm7, 0x50(%rbx)
addq $0x80, %rsp
popq %rbx
popq %r14
popq %r15
retq
jmp 0x7c1a
jmp 0x7c1a
jmp 0x7c1a
movq %rax, %r14
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x7c2b
callq 0x37ec
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x7c39
callq 0x37ec
movq %r14, %rdi
callq 0x32e0
nop