// File: /workspace/github_cpp_makefile_star2_O3/ingowald[P]closestSurfacePointQueries/src/bvh.cpp
// Function: bvhlib::BVH::build(bvhlib::Geometry const*)
void BVH::build(const Geometry *geometry)
  {
    assert(geometry);
    size_t numPrimitives = geometry->numPrimitives();
    std::vector<BuildPrim> buildPrim;
    std::vector<size_t>    primID;
    buildPrim.resize(numPrimitives);
    primID.resize(numPrimitives);
    
    size_t blockSize = 1000;
    size_t numBlocks = (numPrimitives+blockSize-1) / blockSize;
    Mutex mutex;
    box3fa centBounds  = ospcommon::empty;

// #pragma omp for
    for (size_t blockID=0;blockID<numBlocks;blockID++) {
      size_t begin   = blockID * blockSize;
      size_t end     = std::min(begin+blockSize,numPrimitives);
      box3fa blockBounds  = ospcommon::empty;
      for (size_t i=begin;i<end;i++) {
        BuildPrim bp;
        geometry->initBuildPrim(bp,i);
        blockBounds.extend(bp.center());
        buildPrim[i] = bp;
        primID[i] = i;
      }

      LockGuard lock(mutex);
      centBounds.extend(blockBounds);
    }
    nodeList.push_back(Node());
    buildRec(0,centBounds,buildPrim.data(),primID);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
testq %rsi, %rsi
je 0x855a
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, %rdi
callq *(%rax)
movq %rax, %r12
xorl %eax, %eax
leaq 0x60(%rsp), %rdi
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r12, %rsi
callq 0x85ea
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x85b8
movq %rbx, 0x98(%rsp)
leaq 0x3e7(%r12), %rcx
movq %rcx, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
mulq %rdx
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movq $0x0, 0x110(%rsp)
cmpq $0x3e8, %rcx            # imm = 0x3E8
jae 0x82a4
movaps 0x1542(%rip), %xmm3     # 0x97c0
movaps 0x152b(%rip), %xmm0     # 0x97b0
movaps %xmm0, 0x30(%rsp)
movss 0x13ba(%rip), %xmm0     # 0x964c
movss %xmm0, (%rsp)
movss 0x1545(%rip), %xmm1     # 0x97e4
jmp 0x8498
shrq $0x4, %rdx
movaps 0x1511(%rip), %xmm0     # 0x97c0
movaps 0x14fa(%rip), %xmm1     # 0x97b0
movss 0x1526(%rip), %xmm2     # 0x97e4
movss 0x1386(%rip), %xmm3     # 0x964c
movq $0x0, 0x28(%rsp)
leaq 0x40(%rsp), %r13
xorl %ebp, %ebp
movss %xmm3, (%rsp)
movaps %xmm1, 0x30(%rsp)
movq %r12, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movss %xmm2, 0x8(%rsp)
imulq $0x3e8, %rbp, %rbx      # imm = 0x3E8
movl $0x3e8, %eax            # imm = 0x3E8
leaq (%rbx,%rax), %r15
cmpq %r15, %r12
cmovbq %r12, %r15
movss 0x132f(%rip), %xmm3     # 0x964c
movss 0x14bf(%rip), %xmm1     # 0x97e4
movaps 0x1484(%rip), %xmm4     # 0x97b0
movaps 0x148d(%rip), %xmm2     # 0x97c0
cmpq %rbx, %r12
jbe 0x8410
movq 0x28(%rsp), %r12
movss 0x149b(%rip), %xmm5     # 0x97e4
movss 0x12fb(%rip), %xmm3     # 0x964c
movaps 0x1458(%rip), %xmm4     # 0x97b0
movaps 0x1461(%rip), %xmm0     # 0x97c0
movaps %xmm0, 0xe0(%rsp)
movss %xmm5, 0xc(%rsp)
movaps %xmm4, 0x80(%rsp)
movss %xmm3, 0x4(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq *0x8(%rax)
movss 0x48(%rsp), %xmm1
addss 0x58(%rsp), %xmm1
mulss 0x1442(%rip), %xmm1     # 0x97e0
movsd 0x40(%rsp), %xmm0
movsd 0x50(%rsp), %xmm2
addps %xmm0, %xmm2
mulps 0x141c(%rip), %xmm2     # 0x97d0
movaps 0x80(%rsp), %xmm4
minps %xmm2, %xmm4
movss 0x4(%rsp), %xmm3
minss %xmm1, %xmm3
maxps 0xe0(%rsp), %xmm2
maxss 0xc(%rsp), %xmm1
movq 0x60(%rsp), %rax
movups 0x50(%rsp), %xmm0
movups %xmm0, 0x10(%rax,%r12)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rax,%r12)
movq 0x10(%rsp), %rax
movq %rbx, (%rax,%rbx,8)
incq %rbx
addq $0x20, %r12
movaps %xmm1, %xmm5
movaps %xmm2, %xmm0
cmpq %r15, %rbx
jb 0x835f
maxss 0x8(%rsp), %xmm1
movss %xmm1, 0x4(%rsp)
maxps 0xd0(%rsp), %xmm2
movaps %xmm2, 0x80(%rsp)
movss (%rsp), %xmm0
minss %xmm3, %xmm0
movss %xmm0, (%rsp)
movaps 0x30(%rsp), %xmm0
minps %xmm4, %xmm0
movaps %xmm0, 0x30(%rsp)
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2240
movq %rbx, %rdi
callq 0x2160
movaps 0x80(%rsp), %xmm3
movss 0x4(%rsp), %xmm1
incq %rbp
addq $0x7d00, 0x28(%rsp)     # imm = 0x7D00
movaps %xmm1, %xmm2
movaps %xmm3, %xmm0
movq 0xa0(%rsp), %rdx
cmpq %rdx, %rbp
movq 0xa8(%rsp), %r12
jne 0x82f0
movaps 0x30(%rsp), %xmm0
movlps %xmm0, 0xb0(%rsp)
movss (%rsp), %xmm0
movss %xmm0, 0xb8(%rsp)
movlps %xmm3, 0xc0(%rsp)
movss %xmm1, 0xc8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq 0x98(%rsp), %rbx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x84f1
movups %xmm0, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, 0x8(%rbx)
jmp 0x84fe
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x878c
movq 0x60(%rsp), %rcx
leaq 0xb0(%rsp), %rdx
leaq 0x10(%rsp), %r8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x788c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8531
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x8548
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1287(%rip), %rdi      # 0x97e8
leaq 0x1289(%rip), %rsi      # 0x97f1
leaq 0x128e(%rip), %rcx      # 0x97fd
movl $0x86, %edx
callq 0x2110
jmp 0x857f
jmp 0x857f
jmp 0x857f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8599
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x85b0
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
movq %rbx, %rdi
callq 0x22f0