// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
testq %rsi, %rsi
je 0x6e35
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
movq (%rsi), %rax
movq %rsi, %rdi
callq *(%rax)
movq %rax, %r12
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movq %rax, %rsi
callq 0x708e
movq %rsp, %rdi
movq %r12, %rsi
callq 0x6e8c
leaq 0x3e7(%r12), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, 0x28(%rsp)
xorl %eax, %eax
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
andq $0x0, 0x20(%rdi)
movsd 0x1b12(%rip), %xmm0     # 0x87b0
leaq 0x80(%rsp), %rcx
movsd %xmm0, (%rcx)
movl $0x7f800000, 0x8(%rcx)  # imm = 0x7F800000
movsd 0x1b07(%rip), %xmm0     # 0x87c0
movsd %xmm0, 0x10(%rcx)
movl $0xff800000, 0x18(%rcx) # imm = 0xFF800000
leaq 0xa0(%rsp), %rbx
leaq 0xe8(%rsp), %rbp
xorl %ecx, %ecx
movq %r12, 0x20(%rsp)
cmpq 0x28(%rsp), %rcx
je 0x6ddb
movq %rcx, 0x30(%rsp)
imulq $0x3e8, %rcx, %r13      # imm = 0x3E8
movl $0x3e8, %ecx            # imm = 0x3E8
leaq (%rcx,%r13), %r15
cmpq %r15, %r12
cmovbq %r12, %r15
movsd 0x1aa5(%rip), %xmm0     # 0x87b0
movsd %xmm0, 0x40(%rsp)
movl $0x7f800000, 0x48(%rsp) # imm = 0x7F800000
movsd 0x1a9f(%rip), %xmm0     # 0x87c0
movsd %xmm0, 0x50(%rsp)
movl $0xff800000, 0x58(%rsp) # imm = 0xFF800000
movq %rax, 0x38(%rsp)
movq %rax, %r12
cmpq %r15, %r13
jae 0x6d94
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq *0x8(%rax)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6f68
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x6fc2
movq 0x60(%rsp), %rax
movups 0xa0(%rsp), %xmm0
movups 0xb0(%rsp), %xmm1
movups %xmm1, 0x10(%rax,%r12,4)
movups %xmm0, (%rax,%r12,4)
movq (%rsp), %rax
movq %r13, (%rax,%r12)
incq %r13
addq $0x8, %r12
jmp 0x6d37
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x2260
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x7010
movq %r15, %rdi
callq 0x2170
movq 0x30(%rsp), %rcx
incq %rcx
movq 0x38(%rsp), %rax
addq $0x1f40, %rax           # imm = 0x1F40
movq 0x20(%rsp), %r12
jmp 0x6cdc
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x731c
movq 0x60(%rsp), %rcx
leaq 0x80(%rsp), %rdx
movq %rsp, %r8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6580
movq %rsp, %rdi
callq 0x70ec
leaq 0x60(%rsp), %rdi
callq 0x74ae
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19a8(%rip), %rdi      # 0x87e4
leaq 0x19aa(%rip), %rsi      # 0x87ed
leaq 0x19af(%rip), %rcx      # 0x87f9
movl $0x86, %edx
callq 0x2120
jmp 0x6e6e
jmp 0x6e6e
jmp 0x6e6e
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x2170
jmp 0x6e71
jmp 0x6e6e
movq %rax, %rbx
movq %rsp, %rdi
callq 0x70ec
leaq 0x60(%rsp), %rdi
callq 0x74ae
movq %rbx, %rdi
callq 0x2310
nop