// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: ReadFiles()
static int 
ReadFiles(void)
{
  // Read pointsets
  for (int i = 0; i < pointset_filenames.NEntries(); i++) {
    const char *filename = pointset_filenames[i];
    R3PointSet *pointset = ReadPointSetFile(filename);
    if (!pointset) return 0;
    pointsets.Insert(pointset);
  }

  // Read meshes
  for (int i = 0; i < mesh_filenames.NEntries(); i++) {
    const char *filename = mesh_filenames[i];
    R3Mesh *mesh = ReadMeshFile(filename);
    if (!mesh) return 0;
    meshes.Insert(mesh);
  }

  // Read scenes
  for (int i = 0; i < scene_filenames.NEntries(); i++) {
    const char *filename = scene_filenames[i];
    R3Scene *scene = ReadSceneFile(filename);
    if (!scene) return 0;
    scenes.Insert(scene);
  }

  // Read grids
  for (int i = 0; i < grid_filenames.NEntries(); i++) {
    const char *filename = grid_filenames[i];
    R3Grid *grid = ReadGridFile(filename);
    if (!grid) return 0;
    grids.Insert(grid);
    grid_ranges[i] = grid->Range();
    grid_thresholds[i] = grid->Mean() + 3 * grid->StandardDeviation();
    if (grid_thresholds[i] > grid_ranges[i].Max() - RN_EPSILON) {
      grid_thresholds[i] = grid_ranges[i].Max() - RN_EPSILON;
    }
  }

  // Read sfl scenes
  for (int i = 0; i < ssa_filenames.NEntries(); i++) {
    if (i >= ssb_filenames.NEntries()) break;
    const char *ssa_filename = ssa_filenames[i];
    const char *ssb_filename = ssb_filenames[i];
    R3SurfelScene *sfl = OpenSFLFiles(ssa_filename, ssb_filename);
    if (!sfl) return 0;
    sfls.Insert(sfl);
    if (!ReadSFLImageFiles(sfl, depth_scale, depth_exponent)) {
      delete sfl;
      return 0;
    }
  }
  
  // Read gsv scenes
  for (int i = 0; i < gsv_filenames.NEntries(); i++) {
    const char *filename = gsv_filenames[i];
    GSVScene *gsv = ReadGSVFile(filename);
    if (!gsv) return 0;
    gsvs.Insert(gsv);
    if (!ReadGSVImageFiles(gsv, depth_scale, depth_exponent)) {
      delete gsv;
      return 0;
    }
  }
  
  // Return OK status 
  return 1;
}

// Assembly:
subq $0xe8, %rsp
movl $0x0, 0xe0(%rsp)
movl 0xe0(%rsp), %eax
movl %eax, 0x3c(%rsp)
leaq 0x2ceeec(%rip), %rdi    # 0x2fe720
callq 0x38730
movl %eax, %ecx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jge 0x2f8bb
movl 0xe0(%rsp), %esi
leaq 0x2ceecf(%rip), %rdi    # 0x2fe720
callq 0x3a570
movq (%rax), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x369c0
movq %rax, 0xd0(%rsp)
cmpq $0x0, 0xd0(%rsp)
jne 0x2f891
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
movq 0xd0(%rsp), %rsi
leaq 0x2cef58(%rip), %rdi    # 0x2fe7f8
callq 0x3a590
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
jmp 0x2f822
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
movl %eax, 0x38(%rsp)
leaq 0x2cee58(%rip), %rdi    # 0x2fe730
callq 0x38730
movl %eax, %ecx
movl 0x38(%rsp), %eax
cmpl %ecx, %eax
jge 0x2f95f
movl 0xcc(%rsp), %esi
leaq 0x2cee3b(%rip), %rdi    # 0x2fe730
callq 0x3a570
movq (%rax), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x36b20
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0x2f935
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
movq 0xb8(%rsp), %rsi
leaq 0x2ceea4(%rip), %rdi    # 0x2fe7e8
callq 0x3a5c0
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x2f8c6
movl $0x0, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0x34(%rsp)
leaq 0x2cedc4(%rip), %rdi    # 0x2fe740
callq 0x38730
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jge 0x2fa03
movl 0xb4(%rsp), %esi
leaq 0x2ceda7(%rip), %rdi    # 0x2fe740
callq 0x3a570
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x36cb0
movq %rax, 0xa0(%rsp)
cmpq $0x0, 0xa0(%rsp)
jne 0x2f9d9
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
movq 0xa0(%rsp), %rsi
leaq 0x2cedf0(%rip), %rdi    # 0x2fe7d8
callq 0x3a5f0
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x2f96a
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
movl %eax, 0x30(%rsp)
leaq 0x2ced30(%rip), %rdi    # 0x2fe750
callq 0x38730
movl %eax, %ecx
movl 0x30(%rsp), %eax
cmpl %ecx, %eax
jge 0x2fbbc
movl 0x9c(%rsp), %esi
leaq 0x2ced0f(%rip), %rdi    # 0x2fe750
callq 0x3a570
movq (%rax), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
callq 0x36ea0
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
jne 0x2fa81
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
movq 0x88(%rsp), %rsi
leaq 0x2ced78(%rip), %rdi    # 0x2fe808
callq 0x3a620
movq 0x88(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x167dd0
movslq 0x9c(%rsp), %rcx
leaq 0x2cedea(%rip), %rax    # 0x2fe8a0
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x78(%rsp), %rcx
movq %rcx, (%rax)
movq 0x80(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rdi
callq 0x3a650
movsd %xmm0, 0x20(%rsp)
movq 0x88(%rsp), %rdi
callq 0x3a6a0
movsd 0x20(%rsp), %xmm1
movsd 0x236549(%rip), %xmm2   # 0x266048
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movslq 0x9c(%rsp), %rcx
leaq 0x2cf1ca(%rip), %rax    # 0x2fece0
movsd %xmm0, (%rax,%rcx,8)
movslq 0x9c(%rsp), %rcx
leaq 0x2cf1b6(%rip), %rax    # 0x2fece0
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movslq 0x9c(%rsp), %rax
leaq 0x2ced5c(%rip), %rdi    # 0x2fe8a0
shlq $0x4, %rax
addq %rax, %rdi
callq 0x3a490
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
leaq 0x2c92c8(%rip), %rax    # 0x2f8e28
subsd (%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2fba4
movslq 0x9c(%rsp), %rax
leaq 0x2ced27(%rip), %rdi    # 0x2fe8a0
shlq $0x4, %rax
addq %rax, %rdi
callq 0x3a490
leaq 0x2c929c(%rip), %rax    # 0x2f8e28
subsd (%rax), %xmm0
movslq 0x9c(%rsp), %rcx
leaq 0x2cf141(%rip), %rax    # 0x2fece0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fba6
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x2fa0e
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x1c(%rsp)
leaq 0x2ceb8d(%rip), %rdi    # 0x2fe760
callq 0x38730
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x2fcd2
movl 0x74(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x2ceb7b(%rip), %rdi    # 0x2fe770
callq 0x38730
movl %eax, %ecx
movl 0x18(%rsp), %eax
cmpl %ecx, %eax
jl 0x2fc09
jmp 0x2fcd2
movl 0x74(%rsp), %esi
leaq 0x2ceb4c(%rip), %rdi    # 0x2fe760
callq 0x3a570
movq (%rax), %rax
movq %rax, 0x68(%rsp)
movl 0x74(%rsp), %esi
leaq 0x2ceb44(%rip), %rdi    # 0x2fe770
callq 0x3a570
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x37310
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0x2fc65
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
movq 0x58(%rsp), %rsi
leaq 0x2ceba7(%rip), %rdi    # 0x2fe818
callq 0x3a6c0
movq 0x58(%rsp), %rdi
movsd 0x2bff25(%rip), %xmm0   # 0x2efba8
movsd 0x2bff25(%rip), %xmm1   # 0x2efbb0
callq 0x37520
cmpl $0x0, %eax
jne 0x2fcc0
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x2fcb0
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
jmp 0x2fcc2
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x2fbc4
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x2cea97(%rip), %rdi    # 0x2fe780
callq 0x38730
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x2fda0
movl 0x54(%rsp), %esi
leaq 0x2cea79(%rip), %rdi    # 0x2fe780
callq 0x3a570
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x37860
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x2fd38
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
movq 0x40(%rsp), %rsi
leaq 0x2ceae4(%rip), %rdi    # 0x2fe828
callq 0x3a6f0
movq 0x40(%rsp), %rdi
movsd 0x2bfe52(%rip), %xmm0   # 0x2efba8
movsd 0x2bfe52(%rip), %xmm1   # 0x2efbb0
callq 0x37ab0
cmpl $0x0, %eax
jne 0x2fd8e
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x2fd81
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x0, 0xe4(%rsp)
jmp 0x2fdab
jmp 0x2fd90
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x2fcda
movl $0x1, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
addq $0xe8, %rsp
retq
nopw (%rax,%rax)