// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
testq %rsi, %rsi
je 0x90f6
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, %rdi
callq *(%rax)
movq %rax, %r12
xorl %eax, %eax
leaq 0x90(%rsp), %rdi
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq %rax, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq %r12, %rsi
callq 0x91da
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x91a8
movq %rbx, 0xa8(%rsp)
leaq 0x3e7(%r12), %rcx
movq %rcx, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
mulq %rdx
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movq $0x0, 0xe0(%rsp)
movabsq $0x7f8000007f800000, %rax # imm = 0x7F8000007F800000
movq %rax, 0x30(%rsp)
movl $0x7f800000, 0x38(%rsp) # imm = 0x7F800000
movabsq $-0x7fffff00800000, %rax # imm = 0xFF800000FF800000
movq %rax, 0x40(%rsp)
movl $0xff800000, 0x48(%rsp) # imm = 0xFF800000
movss 0x18e2(%rip), %xmm0     # 0xa650
movss 0x1a42(%rip), %xmm2     # 0xa7b8
cmpq $0x3e8, %rcx            # imm = 0x3E8
movss %xmm0, 0x14(%rsp)
jae 0x8d9e
movaps %xmm2, %xmm5
movaps %xmm2, %xmm4
movaps %xmm2, %xmm3
movss %xmm0, 0x4(%rsp)
movss %xmm0, (%rsp)
jmp 0x9022
shrq $0x4, %rdx
movss 0x1a0e(%rip), %xmm1     # 0xa7b8
movq $0x0, 0x88(%rsp)
leaq 0x50(%rsp), %r13
xorl %ebp, %ebp
movss %xmm0, (%rsp)
movss %xmm0, 0x4(%rsp)
movaps %xmm2, %xmm0
movq %r12, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movss %xmm0, 0x24(%rsp)
movss %xmm1, 0x28(%rsp)
movss %xmm2, 0x2c(%rsp)
imulq $0x3e8, %rbp, %rbx      # imm = 0x3E8
movl $0x3e8, %eax            # imm = 0x3E8
leaq (%rbx,%rax), %r15
cmpq %r15, %r12
cmovbq %r12, %r15
movss 0x1844(%rip), %xmm0     # 0xa650
movaps %xmm0, %xmm6
movaps %xmm0, %xmm5
movaps %xmm0, %xmm4
movss 0x199b(%rip), %xmm0     # 0xa7b8
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
cmpq %rbx, %r12
jbe 0x8f39
movq 0x88(%rsp), %r12
movss 0x1979(%rip), %xmm0     # 0xa7b8
movaps %xmm0, %xmm7
movaps %xmm0, %xmm8
movaps %xmm0, %xmm9
movss 0x17fe(%rip), %xmm0     # 0xa650
movaps %xmm0, %xmm4
movaps %xmm0, %xmm5
movaps %xmm0, %xmm6
movss %xmm9, 0x8(%rsp)
movss %xmm8, 0xc(%rsp)
movss %xmm7, 0x10(%rsp)
movss %xmm6, 0x18(%rsp)
movss %xmm5, 0x1c(%rsp)
movss %xmm4, 0x20(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq *0x8(%rax)
movss 0x50(%rsp), %xmm1
addss 0x60(%rsp), %xmm1
movss 0x54(%rsp), %xmm2
addss 0x64(%rsp), %xmm2
movss 0x58(%rsp), %xmm3
addss 0x68(%rsp), %xmm3
movss 0x18f8(%rip), %xmm0     # 0xa7b4
mulss %xmm0, %xmm1
mulss %xmm0, %xmm2
mulss %xmm0, %xmm3
movss 0x18(%rsp), %xmm6
minss %xmm1, %xmm6
movss 0x1c(%rsp), %xmm5
minss %xmm2, %xmm5
movss 0x20(%rsp), %xmm4
minss %xmm3, %xmm4
maxss 0x8(%rsp), %xmm1
maxss 0xc(%rsp), %xmm2
maxss 0x10(%rsp), %xmm3
movq 0x90(%rsp), %rax
movups 0x60(%rsp), %xmm0
movups %xmm0, 0x10(%rax,%r12)
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rax,%r12)
movq 0x70(%rsp), %rax
movq %rbx, (%rax,%rbx,8)
incq %rbx
addq $0x20, %r12
movaps %xmm3, %xmm7
movaps %xmm2, %xmm8
movaps %xmm1, %xmm9
cmpq %r15, %rbx
jb 0x8e5b
movss %xmm6, 0x18(%rsp)
movss %xmm5, 0x1c(%rsp)
movss %xmm4, 0x20(%rsp)
movss %xmm3, 0x8(%rsp)
movss %xmm2, 0xc(%rsp)
movss %xmm1, 0x10(%rsp)
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2240
movss 0x14(%rsp), %xmm0
minss 0x18(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movss (%rsp), %xmm0
minss 0x1c(%rsp), %xmm0
movss %xmm0, (%rsp)
movss 0x4(%rsp), %xmm0
minss 0x20(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x10(%rsp), %xmm0
maxss 0x2c(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0xc(%rsp), %xmm0
maxss 0x24(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x8(%rsp), %xmm0
maxss 0x28(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x2160
movss 0x8(%rsp), %xmm5
movss 0xc(%rsp), %xmm4
movss 0x10(%rsp), %xmm3
incq %rbp
addq $0x7d00, 0x88(%rsp) # imm = 0x7D00
movaps %xmm3, %xmm2
movaps %xmm4, %xmm0
movaps %xmm5, %xmm1
movq 0xb0(%rsp), %rdx
cmpq %rdx, %rbp
movq 0xb8(%rsp), %r12
jne 0x8ddb
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
movss (%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
movss %xmm3, 0x40(%rsp)
movss %xmm4, 0x44(%rsp)
movss %xmm5, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0xa8(%rsp), %rbx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x9084
movups %xmm0, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, 0x8(%rbx)
jmp 0x9091
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x9376
movq 0x90(%rsp), %rcx
leaq 0x30(%rsp), %rdx
leaq 0x70(%rsp), %r8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x82fc
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x90c7
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x90e4
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16bf(%rip), %rdi      # 0xa7bc
leaq 0x16c1(%rip), %rsi      # 0xa7c5
leaq 0x16c6(%rip), %rcx      # 0xa7d1
movl $0x86, %edx
callq 0x2110
jmp 0x9119
jmp 0x9119
movq %rax, %rbx
jmp 0x9168
movq %rax, %rbx
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
movss (%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
movss 0x2c(%rsp), %xmm0
movss %xmm0, 0x40(%rsp)
movss 0x24(%rsp), %xmm0
movss %xmm0, 0x44(%rsp)
movss 0x28(%rsp), %xmm0
movss %xmm0, 0x48(%rsp)
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x9182
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x919f
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
movq %rbx, %rdi
callq 0x22f0
nop