// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: LoadAssignmentList(gaps::R3SurfelScene*, char const*)
static int
LoadAssignmentList(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 labels from file with list
  char buffer[4096];
  char object_name[4096];
  char label_name[4096];
  char originator_str[4096];
  double confidence;
  while (fgets(buffer, 4096, fp)) {
    if (buffer[0] == '\0') continue;
    if (buffer[0] == '#') continue;
    if (sscanf(buffer, "%s%s%lf%s", object_name, label_name, &confidence, originator_str) == 4) {
      // Find object
      R3SurfelObject *object = scene->FindObjectByName(object_name);
      if (!object) {
        RNFail("Unable to find object %s in assignments file %s\n", object_name, list_filename);
        return 0;
      }

      // Find label
      R3SurfelLabel *label = scene->FindLabelByName(label_name);
      if (!label) {
        RNFail("Unable to find label %s in assignments file %s\n", label_name, list_filename);
        return 0;
      }

      // Create assignment
      int originator = R3_SURFEL_MACHINE_ORIGINATOR;
      if (!strcmp(originator_str, "Human")) originator = R3_SURFEL_HUMAN_ORIGINATOR;
      else if (!strcmp(originator_str, "GroundTruth")) originator = R3_SURFEL_GROUND_TRUTH_ORIGINATOR;
      R3SurfelLabelAssignment *assignment = new R3SurfelLabelAssignment(object, label, confidence, originator);
      scene->InsertLabelAssignment(assignment);
      count++;
    }
  }

  // Close file
  fclose(fp);

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

  // Return success
  return 1;
}

// Assembly:
subq $0x4078, %rsp           # imm = 0x4078
movq %rdi, 0x4068(%rsp)
movq %rsi, 0x4060(%rsp)
leaq 0x4050(%rsp), %rdi
callq 0x16dd30
leaq 0x4050(%rsp), %rdi
callq 0x263f0
movl $0x0, 0x404c(%rsp)
movq 0x4060(%rsp), %rdi
leaq 0x1e2b48(%rip), %rsi    # 0x2021d3
callq 0x168d0
movq %rax, 0x4040(%rsp)
cmpq $0x0, 0x4040(%rsp)
jne 0x1f6c9
movq 0x4060(%rsp), %rsi
leaq 0x1d91e9(%rip), %rdi    # 0x1f889b
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x4074(%rsp)
jmp 0x1f92b
jmp 0x1f6cb
leaq 0x3040(%rsp), %rdi
movq 0x4040(%rsp), %rdx
movl $0x1000, %esi           # imm = 0x1000
callq 0x16b90
cmpq $0x0, %rax
je 0x1f8b5
movsbl 0x3040(%rsp), %eax
cmpl $0x0, %eax
jne 0x1f6fe
jmp 0x1f6cb
movsbl 0x3040(%rsp), %eax
cmpl $0x23, %eax
jne 0x1f70d
jmp 0x1f6cb
leaq 0x3040(%rsp), %rdi
leaq 0x2040(%rsp), %rdx
leaq 0x1040(%rsp), %rcx
leaq 0x40(%rsp), %r9
leaq 0x1d9298(%rip), %rsi    # 0x1f89c9
leaq 0x38(%rsp), %r8
movb $0x0, %al
callq 0x16710
cmpl $0x4, %eax
jne 0x1f8b0
movq 0x4068(%rsp), %rdi
leaq 0x2040(%rsp), %rsi
callq 0x70d50
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x1f796
leaq 0x2040(%rsp), %rsi
movq 0x4060(%rsp), %rdx
leaq 0x1d9254(%rip), %rdi    # 0x1f89d3
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x4074(%rsp)
jmp 0x1f92b
movq 0x4068(%rsp), %rdi
leaq 0x1040(%rsp), %rsi
callq 0x70ea0
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x1f7e6
leaq 0x1040(%rsp), %rsi
movq 0x4060(%rsp), %rdx
leaq 0x1d9235(%rip), %rdi    # 0x1f8a04
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x4074(%rsp)
jmp 0x1f92b
movl $0x1, 0x24(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x1d923a(%rip), %rsi    # 0x1f8a34
callq 0x16a80
cmpl $0x0, %eax
jne 0x1f80e
movl $0x0, 0x24(%rsp)
jmp 0x1f82e
leaq 0x40(%rsp), %rdi
leaq 0x1d9220(%rip), %rsi    # 0x1f8a3a
callq 0x16a80
cmpl $0x0, %eax
jne 0x1f82c
movl $0x2, 0x24(%rsp)
jmp 0x1f82e
movl $0x50, %edi
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
movsd 0x38(%rsp), %xmm0
movl 0x24(%rsp), %ecx
callq 0x6fbd0
jmp 0x1f85d
movq (%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x4068(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq (%rdi), %rax
callq *0x80(%rax)
movl 0x404c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x404c(%rsp)
jmp 0x1f8b0
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10(%rsp)
movl %eax, 0xc(%rsp)
movl $0x50, %esi
callq 0x16750
jmp 0x1f93a
jmp 0x1f6cb
movq 0x4040(%rsp), %rdi
callq 0x16730
cmpl $0x0, 0x244ef7(%rip)    # 0x2647c0
je 0x1f920
movq 0x4060(%rsp), %rsi
leaq 0x1d916c(%rip), %rdi    # 0x1f8a46
movb $0x0, %al
callq 0x16090
leaq 0x4050(%rsp), %rdi
callq 0x16ddf0
leaq 0x1d8c8a(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
movl 0x404c(%rsp), %esi
leaq 0x1d8d69(%rip), %rdi    # 0x1f8673
movb $0x0, %al
callq 0x16090
movq 0x23b678(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movl $0x1, 0x4074(%rsp)
movl 0x4074(%rsp), %eax
addq $0x4078, %rsp           # imm = 0x4078
retq
movq 0x10(%rsp), %rdi
callq 0x16ca0
nopw %cs:(%rax,%rax)