// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: LoadFeatureList(gaps::R3SurfelScene*, char const*)
static int
LoadFeatureList(R3SurfelScene *scene, const char *list_filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();
  int count = 0;

  // Open file
  FILE *fp = fopen(list_filename, "r");
  if (!fp) {
    RNFail("Unable to open %s\n", list_filename);
    return 0;
  }

  // Read features from file with list
  char buffer[4096];
  char type[1024], name[1024], filename[1024];
  double minimum, maximum, weight;
  while (fgets(buffer, 4096, fp)) {
    if (buffer[0] == '\0') continue;
    if (buffer[0] == '#') continue;
    if (sscanf(buffer, "%s%s%lf%lf%lf%s", type, name, &minimum, &maximum, &weight, filename) == 6) {
      // Create feature of appropriate type
      if (!strcmp(type, "PointSet")) {
        R3SurfelPointSetFeature *feature = new R3SurfelPointSetFeature(name, minimum, maximum, weight);
        scene->InsertFeature(feature);
      }
      else if (!strcmp(type, "OverheadGrid")) {
        R3SurfelOverheadGridFeature *feature = new R3SurfelOverheadGridFeature(filename, name, minimum, maximum, weight);
        scene->InsertFeature(feature);
      }
      else {
        R3SurfelFeature *feature = new R3SurfelFeature(name, minimum, maximum, weight);
        scene->InsertFeature(feature);
      }
      count++;
    }
  }

  // Close file
  fclose(fp);

  // Print statistics
  if (print_verbose) {
    printf("Loaded features from %s ...\n", list_filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Features = %d\n", count);
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x1ca8, %rsp           # imm = 0x1CA8
movq %rdi, 0x1c98(%rsp)
movq %rsi, 0x1c90(%rsp)
leaq 0x1c80(%rsp), %rdi
callq 0x16dd30
leaq 0x1c80(%rsp), %rdi
callq 0x263f0
movl $0x0, 0x1c7c(%rsp)
movq 0x1c90(%rsp), %rdi
leaq 0x1e2838(%rip), %rsi    # 0x2021d3
callq 0x168d0
movq %rax, 0x1c70(%rsp)
cmpq $0x0, 0x1c70(%rsp)
jne 0x1f9d9
movq 0x1c90(%rsp), %rsi
leaq 0x1d8ed9(%rip), %rdi    # 0x1f889b
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x1ca4(%rsp)
jmp 0x1fca6
jmp 0x1f9db
leaq 0xc70(%rsp), %rdi
movq 0x1c70(%rsp), %rdx
movl $0x1000, %esi           # imm = 0x1000
callq 0x16b90
cmpq $0x0, %rax
je 0x1fc30
movsbl 0xc70(%rsp), %eax
cmpl $0x0, %eax
jne 0x1fa0e
jmp 0x1f9db
movsbl 0xc70(%rsp), %eax
cmpl $0x23, %eax
jne 0x1fa1d
jmp 0x1f9db
leaq 0xc70(%rsp), %rdi
leaq 0x870(%rsp), %rdx
leaq 0x470(%rsp), %rcx
leaq 0x70(%rsp), %rax
leaq 0x1d9025(%rip), %rsi    # 0x1f8a66
leaq 0x68(%rsp), %r8
leaq 0x60(%rsp), %r9
leaq 0x58(%rsp), %r10
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x16710
cmpl $0x6, %eax
jne 0x1fc2b
leaq 0x870(%rsp), %rdi
leaq 0x1d8ffe(%rip), %rsi    # 0x1f8a76
callq 0x16a80
cmpl $0x0, %eax
jne 0x1faff
movl $0x48, %edi
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
leaq 0x470(%rsp), %rsi
callq 0x698c0
jmp 0x1fab8
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x1c98(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq (%rdi), %rax
callq *0xb0(%rax)
jmp 0x1fc1a
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl $0x48, %esi
callq 0x16750
jmp 0x1fcb5
leaq 0x870(%rsp), %rdi
leaq 0x1d8582(%rip), %rsi    # 0x1f8090
callq 0x16a80
cmpl $0x0, %eax
jne 0x1fb9e
movl $0xa8, %edi
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
leaq 0x70(%rsp), %rsi
leaq 0x470(%rsp), %rdx
callq 0x6a730
jmp 0x1fb57
movq 0x20(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x1c98(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq (%rdi), %rax
callq *0xb0(%rax)
jmp 0x1fc18
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl $0xa8, %esi
callq 0x16750
jmp 0x1fcb5
movl $0x48, %edi
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
leaq 0x470(%rsp), %rsi
callq 0x68ff0
jmp 0x1fbd4
movq 0x18(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1c98(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq (%rdi), %rax
callq *0xb0(%rax)
jmp 0x1fc18
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl $0x48, %esi
callq 0x16750
jmp 0x1fcb5
jmp 0x1fc1a
movl 0x1c7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c7c(%rsp)
jmp 0x1f9db
movq 0x1c70(%rsp), %rdi
callq 0x16730
cmpl $0x0, 0x244b7c(%rip)    # 0x2647c0
je 0x1fc9b
movq 0x1c90(%rsp), %rsi
leaq 0x1d8e2a(%rip), %rdi    # 0x1f8a7f
movb $0x0, %al
callq 0x16090
leaq 0x1c80(%rsp), %rdi
callq 0x16ddf0
leaq 0x1d890f(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
movl 0x1c7c(%rsp), %esi
leaq 0x1d8a04(%rip), %rdi    # 0x1f8689
movb $0x0, %al
callq 0x16090
movq 0x23b2fd(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movl $0x1, 0x1ca4(%rsp)
movl 0x1ca4(%rsp), %eax
addq $0x1ca8, %rsp           # imm = 0x1CA8
retq
movq 0x48(%rsp), %rdi
callq 0x16ca0
nop