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

  // Check and update bounding box (conservatively)
  R3Box intersection_box(constraint_box[0][0], constraint_box[0][1], -FLT_MAX, constraint_box[1][0], constraint_box[1][1], FLT_MAX);
  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 by block origin (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 xmax = constraint_box[1][0] - origin[0];
  float ymax = constraint_box[1][1] - origin[1];

  // 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->X() > xmax) continue;
    if (surfel->Y() > ymax) continue;
    points[npoints].Reset(block, surfel);
    npoints++;
  }

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

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movq %rdx, 0x150(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x158(%rsp), %rdi
callq 0x1c0e0
cmpl $0x0, %eax
jne 0x56c16
jmp 0x571ad
movq 0x150(%rsp), %rdi
xorl %esi, %esi
movl %esi, 0xb0(%rsp)
callq 0x5b1f0
movl 0xb0(%rsp), %esi
movq %rax, %rdi
callq 0x45390
movl 0xb0(%rsp), %esi
movsd %xmm0, 0xc8(%rsp)
movq 0x150(%rsp), %rdi
callq 0x5b1f0
movq %rax, %rdi
movl $0x1, %esi
movl %esi, 0xb4(%rsp)
callq 0x45390
movl 0xb4(%rsp), %esi
movsd %xmm0, 0xb8(%rsp)
movq 0x150(%rsp), %rdi
callq 0x5b1f0
movl 0xb0(%rsp), %esi
movq %rax, %rdi
callq 0x45390
movl 0xb4(%rsp), %esi
movsd %xmm0, 0xc0(%rsp)
movq 0x150(%rsp), %rdi
callq 0x5b1f0
movl 0xb4(%rsp), %esi
movq %rax, %rdi
callq 0x45390
movsd 0xb8(%rsp), %xmm1
movsd 0xc0(%rsp), %xmm3
movaps %xmm0, %xmm4
movsd 0xc8(%rsp), %xmm0
leaq 0x118(%rsp), %rdi
movsd 0x14d496(%rip), %xmm2   # 0x1a4188
movsd 0x14d496(%rip), %xmm5   # 0x1a4190
callq 0xc9ee0
movq 0x158(%rsp), %rdi
callq 0x4a500
movq %rax, 0xd0(%rsp)
jmp 0x56d16
movq 0xd0(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0xcbf10
jmp 0x56d2d
leaq 0x118(%rsp), %rdi
callq 0x44290
movl %eax, 0xac(%rsp)
jmp 0x56d43
movl 0xac(%rsp), %eax
cmpl $0x0, %eax
je 0x56d85
movl $0x1, 0x108(%rsp)
jmp 0x571a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x1b990
jmp 0x571b5
movq 0xd8(%rsp), %rdi
addq $0x18, %rdi
leaq 0x118(%rsp), %rsi
callq 0xcbc30
jmp 0x56da0
movq 0xd8(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x98(%rsp)
movq 0x158(%rsp), %rdi
callq 0x4a780
movq %rax, 0xa0(%rsp)
jmp 0x56dcb
movq 0xa0(%rsp), %rsi
movq 0x98(%rsp), %rdi
callq 0x1bbc0
jmp 0x56de2
movq 0x158(%rsp), %rdi
callq 0x189c0
movq %rax, 0x90(%rsp)
jmp 0x56df9
movq 0x90(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x150(%rsp), %rdi
xorl %esi, %esi
callq 0x5b1f0
movq %rax, 0x88(%rsp)
jmp 0x56e22
movq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x45390
movsd %xmm0, 0x80(%rsp)
jmp 0x56e3c
movq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0x78(%rsp)
jmp 0x56e53
movsd 0x78(%rsp), %xmm1
movsd 0x80(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xfc(%rsp)
movq 0x150(%rsp), %rdi
xorl %esi, %esi
callq 0x5b1f0
movq %rax, 0x70(%rsp)
jmp 0x56e89
movq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x45390
movsd %xmm0, 0x68(%rsp)
jmp 0x56ea0
movq 0x100(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x60(%rsp)
jmp 0x56eba
movsd 0x60(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf8(%rsp)
movq 0x150(%rsp), %rdi
movl $0x1, %esi
callq 0x5b1f0
movq %rax, 0x58(%rsp)
jmp 0x56ef0
movq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0x45390
movsd %xmm0, 0x50(%rsp)
jmp 0x56f04
movq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0x48(%rsp)
jmp 0x56f1b
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf4(%rsp)
movq 0x150(%rsp), %rdi
movl $0x1, %esi
callq 0x5b1f0
movq %rax, 0x40(%rsp)
jmp 0x56f51
movq 0x40(%rsp), %rdi
movl $0x1, %esi
callq 0x45390
movsd %xmm0, 0x38(%rsp)
jmp 0x56f68
movq 0x100(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x30(%rsp)
jmp 0x56f82
movq 0xd8(%rsp), %rax
movsd 0x30(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf0(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x158(%rsp), %rdi
callq 0x1c0e0
movl %eax, 0x2c(%rsp)
jmp 0x56fc1
movq 0xd8(%rsp), %rdi
movl 0x2c(%rsp), %eax
movl 0x28(%rsp), %esi
addl %eax, %esi
movq (%rdi), %rax
movq 0x80(%rax), %rax
callq *%rax
jmp 0x56fe1
movq 0x158(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x5700b
movq 0x158(%rsp), %rsi
movq 0x98(%rsi), %rdi
callq 0x31140
jmp 0x57009
jmp 0x5700b
movl $0x0, 0xec(%rsp)
movl 0xec(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x158(%rsp), %rdi
callq 0x1c0e0
movl %eax, 0x24(%rsp)
jmp 0x57034
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5716b
movq 0x158(%rsp), %rdi
movl 0xec(%rsp), %esi
callq 0x43660
movq %rax, 0x18(%rsp)
jmp 0x5705f
movq 0x18(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x44190
movss %xmm0, 0x14(%rsp)
jmp 0x57081
movss 0x14(%rsp), %xmm1
movss 0xfc(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x5709a
jmp 0x57155
movq 0xe0(%rsp), %rdi
callq 0x441a0
movss %xmm0, 0x10(%rsp)
jmp 0x570af
movss 0x10(%rsp), %xmm1
movss 0xf8(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x570c8
jmp 0x57155
movq 0xe0(%rsp), %rdi
callq 0x44190
movss %xmm0, 0xc(%rsp)
jmp 0x570dd
movss 0xc(%rsp), %xmm0
ucomiss 0xf4(%rsp), %xmm0
jbe 0x570ef
jmp 0x57155
movq 0xe0(%rsp), %rdi
callq 0x441a0
movss %xmm0, 0x8(%rsp)
jmp 0x57104
movss 0x8(%rsp), %xmm0
ucomiss 0xf0(%rsp), %xmm0
jbe 0x57116
jmp 0x57155
movq 0xd8(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x10(%rax), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq 0x158(%rsp), %rsi
movq 0xe0(%rsp), %rdx
callq 0x558d0
jmp 0x57144
movq 0xd8(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x57016
movq 0x158(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x57195
movq 0x158(%rsp), %rsi
movq 0x98(%rsi), %rdi
callq 0x311c0
jmp 0x57193
jmp 0x57195
movl $0x0, 0x108(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x1b990
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x110(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)