// File: tomfunkhouser[P]gaps/apps/sfl2pts/sfl2pts.cpp
// Function: main
int main(int argc, char **argv)
{
  // Parse program arguments
  if (!ParseArgs(argc, argv)) exit(-1);

  // Open surfel scene
  R3SurfelScene *surfel_scene = OpenSurfelScene(input_surfel_scene_name, input_surfel_database_name);
  if (!surfel_scene) exit(-1);

  // Create points and write to ply file
  if (max_points > 0) {
    if (max_points < surfel_scene->Tree()->Database()->NSurfels()) {
      RNScalar p = (RNScalar) (2*max_points) / (RNScalar) surfel_scene->Tree()->Database()->NSurfels();
      p *= load_every_kth_image;
      p *= load_every_kth_pixel * load_every_kth_pixel;
      if (p < sample_probability) sample_probability = p;
    }
  }

  // Create points
  RNArray<PlyPoint *> points;
  if (!CreatePoints(surfel_scene, points)) exit(-1);

  // Sample points
  if (!SamplePoints(points, max_points)) exit(-1);

  // Write points file
  if (!WritePoints(points, output_points_name)) exit(-1);

  // Delete points
  for (int i = 0; i < points.NEntries(); i++) delete points[i];

  // Close surfel scene
  if (!CloseSurfelScene(surfel_scene)) exit(-1);

  // Return success 
  return 0;
}

// Assembly:
subq $0x88, %rsp
movl $0x0, 0x84(%rsp)
movl %edi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl 0x80(%rsp), %edi
movq 0x78(%rsp), %rsi
callq 0x168c0
cmpl $0x0, %eax
jne 0x1664e
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x136b0
movq 0x1e9153(%rip), %rdi    # 0x1ff7a8
movq 0x1e9154(%rip), %rsi    # 0x1ff7b0
callq 0x16d10
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0x16678
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x136b0
cmpl $0x0, 0x1e9139(%rip)    # 0x1ff7b8
jle 0x16754
movslq 0x1e912c(%rip), %rax    # 0x1ff7b8
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rdi
callq 0x187d0
movq %rax, %rdi
callq 0x187e0
movq %rax, %rdi
callq 0x187f0
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jge 0x16752
movl 0x1e90f6(%rip), %eax    # 0x1ff7b8
shll %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x70(%rsp), %rdi
callq 0x187d0
movq %rax, %rdi
callq 0x187e0
movq %rax, %rdi
callq 0x187f0
movsd 0x38(%rsp), %xmm0
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
cvtsi2sdl 0x1dfe7b(%rip), %xmm0 # 0x1f6580
mulsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movl 0x1dfe6d(%rip), %eax    # 0x1f6584
imull 0x1dfe66(%rip), %eax    # 0x1f6584
cvtsi2sd %eax, %xmm0
mulsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm1
movsd 0x1dfe4c(%rip), %xmm0   # 0x1f6588
ucomisd %xmm1, %xmm0
jbe 0x16750
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x1dfe38(%rip)   # 0x1f6588
jmp 0x16752
jmp 0x16754
leaq 0x58(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x18800
movq 0x28(%rsp), %rsi
movq 0x70(%rsp), %rdi
callq 0x16f50
movl %eax, 0x34(%rsp)
jmp 0x16778
movl 0x34(%rsp), %eax
cmpl $0x0, %eax
jne 0x167a8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x136b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x18840
jmp 0x168b4
movl 0x1e900a(%rip), %esi    # 0x1ff7b8
leaq 0x58(%rsp), %rdi
callq 0x177a0
movl %eax, 0x24(%rsp)
jmp 0x167be
movl 0x24(%rsp), %eax
cmpl $0x0, %eax
jne 0x167d1
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x136b0
movq 0x1e8fe8(%rip), %rsi    # 0x1ff7c0
leaq 0x58(%rsp), %rdi
callq 0x17bc0
movl %eax, 0x20(%rsp)
jmp 0x167e8
movl 0x20(%rsp), %eax
cmpl $0x0, %eax
jne 0x167fb
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x136b0
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x18810
movl %eax, 0x1c(%rsp)
jmp 0x1681b
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x1686d
movl 0x48(%rsp), %esi
leaq 0x58(%rsp), %rdi
callq 0x18820
movq %rax, 0x10(%rsp)
jmp 0x1683c
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x1685e
movq 0x8(%rsp), %rdi
movl $0x24, %esi
callq 0x13580
jmp 0x16860
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x16803
movq 0x70(%rsp), %rdi
callq 0x185a0
movl %eax, 0x4(%rsp)
jmp 0x1687d
movl 0x4(%rsp), %eax
cmpl $0x0, %eax
jne 0x16890
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x136b0
movl $0x0, 0x84(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x18840
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x13970
nop