// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointSet.cpp
// Function: gaps::R3SurfelPointSet::InsertPoints(gaps::R3SurfelBlock*, gaps::R3Box const&)
void R3SurfelPointSet::
InsertPoints(R3SurfelBlock *block, const R3Box& constraint_box)
{
  // Check block
  if (block->NSurfels() == 0) return;

  // Check and update bounding box (conservatively)
  R3Box intersection_box = constraint_box;
  intersection_box.Intersect(block->BBox());
  if (intersection_box.IsEmpty()) return;
  bbox.Union(intersection_box);

  // Update timestamp range (conservatively)
  timestamp_range.Union(block->TimestampRange());

  // Translate constraint to block coordinate system (and store in floats)
  const R3Point& origin = block->PositionOrigin();
  float xmin = constraint_box[0][0] - origin[0];
  float ymin = constraint_box[0][1] - origin[1];
  float zmin = constraint_box[0][2] - origin[2];
  float xmax = constraint_box[1][0] - origin[0];
  float ymax = constraint_box[1][1] - origin[1];
  float zmax = constraint_box[1][2] - origin[2];

  // Allocate space for points
  AllocatePoints(npoints + block->NSurfels());

  // Read block
  if (block->database) block->database->ReadBlock(block);

  // Copy points
  for (int i = 0; i < block->NSurfels(); i++) {
    const R3Surfel *surfel = block->Surfel(i);
    if (surfel->X() < xmin) continue;
    if (surfel->Y() < ymin) continue;
    if (surfel->Z() < zmin) continue;
    if (surfel->X() > xmax) continue;
    if (surfel->Y() > ymax) continue;
    if (surfel->Z() > zmax) continue;
    points[npoints].Reset(block, surfel);
    npoints++;
  }

  // Release block
  if (block->database) block->database->ReleaseBlock(block);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x88, %rsp
cmpl $0x0, 0x8(%rsi)
je 0x30095
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x50(%rsp), %rdi
movq %rdx, %rsi
callq 0x63ce6
movq %rbx, %rdi
callq 0x2a720
leaq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x647fc
movsd 0x58(%rsp), %xmm0
ucomisd 0x70(%rsp), %xmm0
ja 0x3008b
movsd 0x60(%rsp), %xmm0
ucomisd 0x78(%rsp), %xmm0
ja 0x3008b
movsd 0x68(%rsp), %xmm0
ucomisd 0x80(%rsp), %xmm0
ja 0x3008b
leaq 0x18(%r14), %rdi
leaq 0x50(%rsp), %rsi
callq 0x646fe
movq %rbx, %rdi
callq 0x2a8a8
leaq 0x50(%r14), %rdi
movq %rax, %rsi
callq 0x177ca
movsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x20(%r15), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x28(%r15), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x30(%r15), %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x8(%rbx), %esi
addl 0x10(%r14), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x80(%rax)
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x2ff62
movq %rbx, %rsi
callq 0x20a64
movsd 0x10(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm3
movsd 0x8(%rsp), %xmm2
movsd 0x20(%rsp), %xmm0
subsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm4
movsd 0x30(%rsp), %xmm0
movsd 0x18(%rsp), %xmm5
subsd %xmm0, %xmm5
cvtsd2ss %xmm5, %xmm5
movsd 0x38(%rsp), %xmm6
subsd %xmm1, %xmm6
cvtsd2ss %xmm6, %xmm6
movsd 0x40(%rsp), %xmm1
subsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm7
movsd 0x48(%rsp), %xmm1
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x30(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movss %xmm3, 0x28(%rsp)
movss %xmm4, 0x20(%rsp)
movss %xmm5, 0x18(%rsp)
movss %xmm6, 0x10(%rsp)
movss %xmm7, 0x8(%rsp)
movslq 0x8(%rbx), %rax
cmpq %rax, %r12
jge 0x30077
movq (%rbx), %rdx
movss (%rdx,%r15), %xmm0
ucomiss %xmm0, %xmm3
ja 0x3006b
movss 0x4(%rdx,%r15), %xmm1
ucomiss %xmm1, %xmm4
ja 0x3006b
movss 0x8(%rdx,%r15), %xmm2
ucomiss %xmm2, %xmm5
ja 0x3006b
ucomiss %xmm6, %xmm0
ja 0x3006b
ucomiss %xmm7, %xmm1
ja 0x3006b
ucomiss 0x30(%rsp), %xmm2
ja 0x3006b
addq %r15, %rdx
movslq 0x10(%r14), %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x2f200
incl 0x10(%r14)
movss 0x28(%rsp), %xmm3
movss 0x20(%rsp), %xmm4
movss 0x18(%rsp), %xmm5
movss 0x10(%rsp), %xmm6
movss 0x8(%rsp), %xmm7
incq %r12
addq $0x30, %r15
jmp 0x2fff2
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x3008b
movq %rbx, %rsi
callq 0x20aa0
leaq 0x50(%rsp), %rdi
callq 0x649ae
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x300a8
jmp 0x300a8
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x649ae
movq %rbx, %rdi
callq 0x138f0
nop