// File: /workspace/github_cpp_makefile_star2_O3/Lut99[P]RayTracer/src/lib/ObjectTree.cpp
// Function: RayTracer::ObjectTreeBranch::ObjectTreeBranch(std::vector<RayTracer::RenderObject*, std::allocator<RayTracer::RenderObject*>>)
ObjectTreeBranch::ObjectTreeBranch(const std::vector<RenderObject*> elements)
    : ObjectTreeNode(false, BoundingBox())
{
    // First, construct the nodes by assigning them half each cluster
    std::vector<RenderObject*> left;
    std::vector<RenderObject*> right;
    cluster(elements, left, right);
    
    // Construct leaves instead if only one element is left
    if (left.size() == 1) {
        this->left = (ObjectTreeNode*) new ObjectTreeLeaf(left.at(0));
    } else {
        this->left = (ObjectTreeNode*) new ObjectTreeBranch(left);
    }
    if (right.size() == 1) {
        this->right = (ObjectTreeNode*) new ObjectTreeLeaf(right.at(0));
    } else {
        this->right = (ObjectTreeNode*) new ObjectTreeBranch(right);
    }

    // Update the bounding box to be a merge of those
    this->box.merge(this->left->box);
    this->box.merge(this->right->box);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xa8(%rsp), %rdi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x71eae
leaq 0xc8(%rsp), %r15
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
callq 0x71eae
movb $0x0, 0x8(%rbx)
leaq 0x21ae6(%rip), %r12     # 0xa30b0
addq $0x10, %r12
movq %r12, 0x10(%rbx)
movups -0x18(%r15), %xmm0
movups %xmm0, 0x18(%rbx)
movq -0x8(%r15), %rax
movq %rax, 0x28(%rbx)
movq %r12, 0x30(%rbx)
movups 0x8(%r15), %xmm0
movups %xmm0, 0x38(%rbx)
movq 0x18(%r15), %rax
movq %rax, 0x48(%rbx)
leaq 0x22669(%rip), %rax     # 0xa3c68
movq %rax, (%rbx)
xorl %eax, %eax
leaq 0x20(%rsp), %rsi
movq %rax, 0x10(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
movq %rsp, %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq %r14, %rdi
callq 0x80dc9
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %rax
subq %r14, %rax
cmpq $0x8, %rax
jne 0x816ad
movl $0x58, %edi
callq 0x3a470
movq (%r14), %rcx
movups 0x40(%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x50(%rcx), %rdx
movq %rdx, 0x70(%rsp)
movups 0x60(%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x70(%rcx), %rdx
movq %rdx, 0x50(%rsp)
movb $0x1, 0x8(%rax)
movq %r12, 0x10(%rax)
movaps 0x60(%rsp), %xmm0
movups %xmm0, 0x18(%rax)
movq 0x70(%rsp), %rdx
movq %rdx, 0x28(%rax)
movq %r12, 0x30(%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, 0x38(%rax)
movq 0x50(%rsp), %rdx
movq %rdx, 0x48(%rax)
leaq 0x22600(%rip), %rdx     # 0xa3ca0
movq %rdx, (%rax)
movq %rcx, 0x50(%rax)
movq %rax, 0x50(%rbx)
jmp 0x816fd
movl $0x60, %edi
callq 0x3a470
movq %rax, %r14
leaq 0x90(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x77df4
leaq 0x90(%rsp), %rsi
movq %r14, %rdi
callq 0x8157c
movq %r14, 0x50(%rbx)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x816fd
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
movq (%rsp), %r14
movq 0x8(%rsp), %rax
subq %r14, %rax
cmpq $0x8, %rax
jne 0x81784
movl $0x58, %edi
callq 0x3a470
movq (%r14), %rcx
movups 0x40(%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x50(%rcx), %rdx
movq %rdx, 0x70(%rsp)
movups 0x60(%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x70(%rcx), %rdx
movq %rdx, 0x50(%rsp)
movb $0x1, 0x8(%rax)
movq %r12, 0x10(%rax)
movaps 0x60(%rsp), %xmm0
movups %xmm0, 0x18(%rax)
movq 0x70(%rsp), %rdx
movq %rdx, 0x28(%rax)
movq %r12, 0x30(%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, 0x38(%rax)
movq 0x50(%rsp), %rdx
movq %rdx, 0x48(%rax)
leaq 0x22529(%rip), %rdx     # 0xa3ca0
movq %rdx, (%rax)
movq %rcx, 0x50(%rax)
movq %rax, 0x58(%rbx)
jmp 0x817c9
movl $0x60, %edi
callq 0x3a470
movq %rax, %r14
leaq 0x78(%rsp), %rdi
movq %rsp, %rsi
callq 0x77df4
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x8157c
movq %r14, 0x58(%rbx)
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x817c9
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
leaq 0x10(%rbx), %r14
movq 0x50(%rbx), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x80af0
movq 0x58(%rbx), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x80af0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x81803
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x8181a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x81867
movq 0x88(%rsp), %rsi
jmp 0x8185a
jmp 0x81864
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x81867
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
jmp 0x81867
movq %rax, %rbx
movl $0x60, %esi
movq %r14, %rdi
callq 0x3a480
jmp 0x81879
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8188f
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x818a6
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3a480
movq %rbx, %rdi
callq 0x3a790