// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointSet.cpp
// Function: gaps::R3SurfelPointSet::InsertPoints(gaps::R3SurfelBlock*, gaps::R3Point const&, double, double, double)
void R3SurfelPointSet::
InsertPoints(R3SurfelBlock *block, const R3Point& center, RNLength radius, RNCoord zmin, RNCoord zmax)
{
  // Check block
  if (block->NSurfels() == 0) return;

  // Check and update bounding box (conservatively)
  R3Box constraint_box(center[0] - radius, center[1] - radius, zmin, center[0] + radius, center[1] + radius, zmax);
  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 xc = center[0] - origin[0];
  float yc = center[1] - origin[1];
  float zlo = zmin - origin[2];
  float zhi = zmax - origin[2];
  float rr = radius * radius;

  // 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->Z() < zlo) continue;
    if (surfel->Z() > zhi) continue;
    float dx = surfel->X() - xc;
    float dy = surfel->Y() - yc;
    float dd = dx*dx + dy*dy;
    if (dd > rr) continue;
    points[npoints].Reset(block, surfel);
    npoints++;
  }

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

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1b0(%rsp)
movq %rsi, 0x1a8(%rsp)
movq %rdx, 0x1a0(%rsp)
movsd %xmm0, 0x198(%rsp)
movsd %xmm1, 0x190(%rsp)
movsd %xmm2, 0x188(%rsp)
movq 0x1b0(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x1c0e0
cmpl $0x0, %eax
jne 0x578a1
jmp 0x57e7f
movq 0x1a0(%rsp), %rdi
xorl %esi, %esi
movl %esi, 0x98(%rsp)
callq 0x1bba0
movsd 0x198(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0x1a0(%rsp), %rdi
movl $0x1, %esi
movl %esi, 0x9c(%rsp)
callq 0x1bba0
movl 0x98(%rsp), %esi
movsd 0x198(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x190(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq 0x1a0(%rsp), %rdi
callq 0x1bba0
movl 0x9c(%rsp), %esi
movsd 0x198(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
movq 0x1a0(%rsp), %rdi
callq 0x1bba0
movsd 0xa0(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm2
movsd 0xb0(%rsp), %xmm3
movaps %xmm0, %xmm4
movsd 0xb8(%rsp), %xmm0
movsd 0x198(%rsp), %xmm5
addsd %xmm5, %xmm4
movsd 0x188(%rsp), %xmm5
leaq 0x150(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0xc9ee0
movq 0xc0(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0xc9de0
jmp 0x579b5
movq 0x1a8(%rsp), %rdi
callq 0x4a500
movq %rax, 0x90(%rsp)
jmp 0x579cc
movq 0x90(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0xcbf10
jmp 0x579e3
leaq 0x118(%rsp), %rdi
callq 0x44290
movl %eax, 0x8c(%rsp)
jmp 0x579f9
movl 0x8c(%rsp), %eax
cmpl $0x0, %eax
je 0x57a54
movl $0x1, 0x108(%rsp)
jmp 0x57e65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x57e87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x1b990
jmp 0x57e87
movq 0xc8(%rsp), %rdi
addq $0x18, %rdi
leaq 0x118(%rsp), %rsi
callq 0xcbc30
jmp 0x57a6f
movq 0xc8(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x78(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x4a780
movq %rax, 0x80(%rsp)
jmp 0x57a97
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdi
callq 0x1bbc0
jmp 0x57aab
movq 0x1a8(%rsp), %rdi
callq 0x189c0
movq %rax, 0x70(%rsp)
jmp 0x57abf
movq 0x70(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x1a0(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0x68(%rsp)
jmp 0x57ae3
movq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0x60(%rsp)
jmp 0x57afa
movsd 0x60(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xfc(%rsp)
movq 0x1a0(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x58(%rsp)
jmp 0x57b31
movq 0x100(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x50(%rsp)
jmp 0x57b4b
movsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf8(%rsp)
movsd 0x190(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x100(%rsp), %rdi
movl $0x2, %esi
callq 0x1bba0
movsd %xmm0, 0x48(%rsp)
jmp 0x57b91
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf4(%rsp)
movsd 0x188(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x100(%rsp), %rdi
movl $0x2, %esi
callq 0x1bba0
movsd %xmm0, 0x38(%rsp)
jmp 0x57bd7
movq 0xc8(%rsp), %rax
movsd 0x38(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf0(%rsp)
movsd 0x198(%rsp), %xmm0
mulsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xec(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x1c0e0
movl %eax, 0x2c(%rsp)
jmp 0x57c30
movq 0xc8(%rsp), %rdi
movl 0x2c(%rsp), %eax
movl 0x28(%rsp), %esi
addl %eax, %esi
movq (%rdi), %rax
movq 0x80(%rax), %rax
callq *%rax
jmp 0x57c50
movq 0x1a8(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x57c7a
movq 0x1a8(%rsp), %rsi
movq 0x98(%rsi), %rdi
callq 0x31140
jmp 0x57c78
jmp 0x57c7a
movl $0x0, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x1c0e0
movl %eax, 0x24(%rsp)
jmp 0x57ca3
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
cmpl %ecx, %eax
jge 0x57e30
movq 0x1a8(%rsp), %rdi
movl 0xe8(%rsp), %esi
callq 0x43660
movq %rax, 0x18(%rsp)
jmp 0x57cce
movq 0x18(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x441b0
movss %xmm0, 0x14(%rsp)
jmp 0x57cf0
movss 0x14(%rsp), %xmm1
movss 0xf4(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x57d09
jmp 0x57e1a
movq 0xe0(%rsp), %rdi
callq 0x441b0
movss %xmm0, 0x10(%rsp)
jmp 0x57d1e
movss 0x10(%rsp), %xmm0
ucomiss 0xf0(%rsp), %xmm0
jbe 0x57d33
jmp 0x57e1a
movq 0xe0(%rsp), %rdi
callq 0x44190
movss %xmm0, 0xc(%rsp)
jmp 0x57d48
movss 0xc(%rsp), %xmm0
movss 0xfc(%rsp), %xmm1
subss %xmm1, %xmm0
movss %xmm0, 0xdc(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x441a0
movss %xmm0, 0x8(%rsp)
jmp 0x57d79
movss 0x8(%rsp), %xmm0
subss 0xf8(%rsp), %xmm0
movss %xmm0, 0xd8(%rsp)
movss 0xdc(%rsp), %xmm0
movss 0xdc(%rsp), %xmm2
movss 0xd8(%rsp), %xmm1
mulss 0xd8(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0xd4(%rsp)
movss 0xd4(%rsp), %xmm0
ucomiss 0xec(%rsp), %xmm0
jbe 0x57ddb
jmp 0x57e1a
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x10(%rax), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq 0x1a8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
callq 0x558d0
jmp 0x57e09
movq 0xc8(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x57c85
movq 0x1a8(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x57e5a
movq 0x1a8(%rsp), %rsi
movq 0x98(%rsi), %rdi
callq 0x311c0
jmp 0x57e58
jmp 0x57e5a
movl $0x0, 0x108(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x1b990
leaq 0x150(%rsp), %rdi
callq 0x1b990
addq $0x1b8, %rsp            # imm = 0x1B8
retq
leaq 0x150(%rsp), %rdi
callq 0x1b990
movq 0x110(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)