// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0xb0, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x8063a
movb $0x0, 0x8(%rbx)
leaq 0x286ec(%rip), %rax     # 0xb1478
addq $0x10, %rax
movq %rax, 0x10(%rbx)
movups 0x8(%r15), %xmm0
movups %xmm0, 0x18(%rbx)
movq 0x18(%r15), %rcx
movq %rcx, 0x28(%rbx)
movq %rax, 0x30(%rbx)
movups 0x28(%r15), %xmm0
movups %xmm0, 0x38(%rbx)
movq 0x38(%r15), %rax
movq %rax, 0x48(%rbx)
leaq 0x28ec7(%rip), %rax     # 0xb1c88
movq %rax, (%rbx)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %rsp, %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
movq %r14, %rdi
callq 0x888fc
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
cmpq $0x8, %rax
jne 0x88e1f
pushq $0x58
popq %rdi
callq 0x52470
movq %rax, %r14
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x82330
movq (%rax), %rsi
movq %r14, %rdi
callq 0x89230
movq %r14, 0x50(%rbx)
jmp 0x88e54
pushq $0x60
popq %rdi
callq 0x52470
movq %rax, %r14
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x822e2
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x88d62
movq %r14, 0x50(%rbx)
leaq 0x58(%rsp), %rdi
callq 0x82400
movq 0x8(%rsp), %rax
subq (%rsp), %rax
cmpq $0x8, %rax
jne 0x88e89
pushq $0x58
popq %rdi
callq 0x52470
movq %rax, %r14
movq %rsp, %rdi
xorl %esi, %esi
callq 0x82330
movq (%rax), %rsi
movq %r14, %rdi
callq 0x89230
movq %r14, 0x58(%rbx)
jmp 0x88ebc
pushq $0x60
popq %rdi
callq 0x52470
movq %rax, %r14
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x822e2
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x88d62
movq %r14, 0x58(%rbx)
leaq 0x40(%rsp), %rdi
callq 0x82400
leaq 0x10(%rbx), %r14
movq 0x50(%rbx), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x886a4
movq 0x58(%rbx), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x886a4
movq %rsp, %rdi
callq 0x82400
leaq 0x20(%rsp), %rdi
callq 0x82400
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x88f15
jmp 0x88f1c
jmp 0x88f23
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x82400
jmp 0x88f1f
movq %rax, %rbx
pushq $0x60
jmp 0x88f28
movq %rax, %rbx
pushq $0x58
popq %rsi
movq %r14, %rdi
callq 0x52480
jmp 0x88f36
movq %rax, %rbx
movq %rsp, %rdi
callq 0x82400
leaq 0x20(%rsp), %rdi
callq 0x82400
movq %rbx, %rdi
callq 0x527a0