// File: IsaacLaw12[P]RayTracer/./src/OctTree.cpp
// Function: OctTree::subdivide_box()
void OctTree::subdivide_box(){
    // Binary divide the current cube into 8 smaller cubes
    Eigen::Vector3d transform;
    Eigen::Vector3d cube_center = (max_corner - min_corner) * .5 + min_corner;
    Eigen::Vector3d temp_min;
    Eigen::Vector3d temp_max;
    if (contained_faces.size()>10 && recursion_limit>0){
        double half_x = (max_corner(0) - min_corner(0)) / 2.0;
        double half_y = (max_corner(1) - min_corner(1)) / 2.0;
        double half_z = (max_corner(2) - min_corner(2)) / 2.0;
        for (int x=0; x<2; x++){
            for (int y=0; y<2; y++){
                for (int z=0; z<2; z++){
                    transform << x*half_x, y*half_y, z*half_z;
                    temp_min = min_corner + transform;
                    temp_max = cube_center + transform;
                    contained_boxes.push_back(std::make_unique<OctTree>(this, recursion_limit, temp_min, temp_max));
                }
            }
        }
    }
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq 0x220(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x11e20
movq 0x60(%rsp), %rdx
movq %rdx, %rsi
addq $0x18, %rsi
leaq 0x150(%rsp), %rdi
callq 0x9e80
movsd 0x1799e(%rip), %xmm0    # 0x6ed28
movsd %xmm0, 0x148(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x148(%rsp), %rdx
callq 0x58ce0
movq 0x60(%rsp), %rdx
leaq 0x1a0(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x58da0
leaq 0x1f0(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x58e10
leaq 0x130(%rsp), %rdi
callq 0x11e20
leaq 0x118(%rsp), %rdi
callq 0x11e20
movq 0x60(%rsp), %rdi
addq $0x58, %rdi
callq 0x58e50
cmpq $0xa, %rax
jbe 0x57753
movq 0x60(%rsp), %rax
cmpl $0x0, 0xa0(%rax)
jle 0x57753
movq 0x60(%rsp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6130
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x6130
movsd 0x48(%rsp), %xmm0
movq 0x60(%rsp), %rdi
subsd (%rax), %xmm0
movsd 0xf7fc(%rip), %xmm1     # 0x66c60
divsd %xmm1, %xmm0
movsd %xmm0, 0x110(%rsp)
addq $0x18, %rdi
movl $0x1, %esi
callq 0x6130
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0x1, %esi
callq 0x6130
movsd 0x50(%rsp), %xmm0
movq 0x60(%rsp), %rdi
subsd (%rax), %xmm0
movsd 0xf7b1(%rip), %xmm1     # 0x66c60
divsd %xmm1, %xmm0
movsd %xmm0, 0x108(%rsp)
addq $0x18, %rdi
movl $0x2, %esi
callq 0x6130
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movl $0x2, %esi
callq 0x6130
movsd 0x58(%rsp), %xmm0
subsd (%rax), %xmm0
movsd 0xf76b(%rip), %xmm1     # 0x66c60
divsd %xmm1, %xmm0
movsd %xmm0, 0x100(%rsp)
movl $0x0, 0xfc(%rsp)
cmpl $0x2, 0xfc(%rsp)
jge 0x57751
movl $0x0, 0xf8(%rsp)
cmpl $0x2, 0xf8(%rsp)
jge 0x57739
movl $0x0, 0xf4(%rsp)
cmpl $0x2, 0xf4(%rsp)
jge 0x57721
cvtsi2sdl 0xfc(%rsp), %xmm0
movsd 0x110(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xc8(%rsp)
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
leaq 0x208(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x11f20
movq 0x38(%rsp), %rdi
cvtsi2sdl 0xf8(%rsp), %xmm0
movsd 0x108(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
leaq 0xc0(%rsp), %rsi
callq 0x11f60
movq %rax, 0x40(%rsp)
jmp 0x575c6
movq 0x40(%rsp), %rdi
cvtsi2sdl 0xf4(%rsp), %xmm0
movsd 0x100(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xa8(%rsp), %rsi
callq 0x11f60
jmp 0x575f9
leaq 0xd0(%rsp), %rdi
callq 0x120e0
movq 0x60(%rsp), %rsi
leaq 0x90(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0x208(%rsp), %rdx
movq %rdx, 0x8(%rsp)
callq 0x1e4b0
movq (%rsp), %rsi
leaq 0x130(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x1e520
movq 0x8(%rsp), %rdx
leaq 0x78(%rsp), %rdi
movq %rdi, 0x10(%rsp)
leaq 0x1f0(%rsp), %rsi
callq 0x1e4b0
movq 0x10(%rsp), %rsi
leaq 0x118(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1e520
movq 0x60(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %rdx, %rax
addq $0x40, %rax
movq %rax, 0x28(%rsp)
movq %rdx, 0x68(%rsp)
addq $0xa0, %rdx
leaq 0x70(%rsp), %rdi
movq %rdi, 0x30(%rsp)
leaq 0x68(%rsp), %rsi
callq 0x58e90
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x58e60
jmp 0x576be
leaq 0x70(%rsp), %rdi
callq 0x1d360
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x5753f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x120e0
jmp 0x5775b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x1d360
jmp 0x5775b
jmp 0x57723
movl 0xf8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x57526
jmp 0x5773b
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x5750d
jmp 0x57753
addq $0x228, %rsp            # imm = 0x228
retq
movq 0xb8(%rsp), %rdi
callq 0x45e0
nopl (%rax,%rax)