// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: LoadImagesFromConfiguration(gaps::R3SurfelScene*, char const*)
static int
LoadImagesFromConfiguration(R3SurfelScene *scene, const char *configuration_filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Read configuration file
  RGBDConfiguration configuration;
  if (!configuration.ReadFile(configuration_filename)) return 0;

  // Create images
  for (int i = 0; i < configuration.NImages(); i++) {
    RGBDImage *rgbd_image = configuration.Image(i);

    // Get name
    char name[1025];
    if (rgbd_image->Name() && strcmp(rgbd_image->Name(), "-")) {
      strncpy(name, rgbd_image->Name(), 1024);
    }
    else if (rgbd_image->ColorFilename() && strcmp(rgbd_image->ColorFilename(), "-")) {
      const char *start = strrchr(rgbd_image->ColorFilename(), '/');
      if (start) strncpy(name, start+1, 1024);
      else strncpy(name, rgbd_image->ColorFilename(), 1024);
    }
    else if (rgbd_image->DepthFilename() && strcmp(rgbd_image->DepthFilename(), "-")) {
      const char *start = strrchr(rgbd_image->DepthFilename(), '/');
      if (start) strncpy(name, start+1, 1024);
      else strncpy(name, rgbd_image->DepthFilename(), 1024);
    }
    else sprintf(name, "Image_%d\n", i);

    // Get stuff from rgbd image
    R3Point viewpoint = rgbd_image->WorldViewpoint();
    R3Vector towards = rgbd_image->WorldTowards();
    R3Vector up = rgbd_image->WorldUp();
    int width = rgbd_image->NPixels(RN_X);
    int height = rgbd_image->NPixels(RN_Y);
    R3Matrix intrinsics = rgbd_image->Intrinsics();
    double xfocal = intrinsics[0][0];
    double yfocal = intrinsics[1][1];
    double xcenter = intrinsics[0][2];
    double ycenter = intrinsics[1][2];

    // Create sfl image
    R3SurfelImage *sfl_image = new R3SurfelImage();
    sfl_image->SetViewpoint(viewpoint);
    sfl_image->SetOrientation(towards, up);
    sfl_image->SetImageDimensions(width, height);
    sfl_image->SetImageCenter(R2Point(xcenter, ycenter));
    sfl_image->SetXFocal(xfocal);
    sfl_image->SetYFocal(yfocal);
    sfl_image->SetName(name);

    // Insert sfl image into scene
    scene->InsertImage(sfl_image);
  }
  
  // Print statistics
  if (print_verbose) {
    printf("Loaded images from %s ...\n", configuration_filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Images = %d\n", configuration.NImages());
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x578, %rsp            # imm = 0x578
movq %rsi, %r12
movq %rdi, %r14
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0xc0cf4
xorl %ebx, %ebx
movq %r15, %rdi
xorl %esi, %esi
callq 0x15a10
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
callq 0x1f7c8
movq %r15, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x1fe6c
testl %eax, %eax
je 0x1c31b
movq %r12, (%rsp)
cmpl $0x0, 0xec(%rsp)
jle 0x1c2bf
leaq 0xc8(%rsp), %r13
xorl %r12d, %r12d
movq 0xe0(%rsp), %rax
movq (%rax,%r12,8), %rbp
movq 0x1d0(%rbp), %rsi
testq %rsi, %rsi
je 0x1c0cb
cmpb $0x2d, (%rsi)
jne 0x1c0bc
cmpb $0x0, 0x1(%rsi)
je 0x1c0cb
movl $0x400, %edx            # imm = 0x400
leaq 0x170(%rsp), %rdi
jmp 0x1c138
movq 0x1d8(%rbp), %rbx
testq %rbx, %rbx
je 0x1c0e2
cmpb $0x2d, (%rbx)
jne 0x1c101
cmpb $0x0, 0x1(%rbx)
jne 0x1c101
movq 0x1e0(%rbp), %rbx
testq %rbx, %rbx
je 0x1c2a1
cmpb $0x2d, (%rbx)
jne 0x1c101
cmpb $0x0, 0x1(%rbx)
je 0x1c2a1
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x156a0
testq %rax, %rax
je 0x1c128
incq %rax
movl $0x400, %edx            # imm = 0x400
leaq 0x170(%rsp), %rdi
movq %rax, %rsi
jmp 0x1c138
movl $0x400, %edx            # imm = 0x400
leaq 0x170(%rsp), %rdi
movq %rbx, %rsi
callq 0x15300
leaq 0x38(%rbp), %rbx
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
leaq 0x552740(%rip), %rdx    # 0x56e890
callq 0x8c54a
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
leaq 0xf4a0c(%rip), %rdx     # 0x110b70
callq 0x8c4d2
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
leaq 0xf4998(%rip), %rdx     # 0x110b10
callq 0x8c4d2
movl 0x28(%rbp), %ebx
movl 0x2c(%rbp), %r15d
addq $0x140, %rbp            # imm = 0x140
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
callq 0xb9062
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x1d8, %edi            # imm = 0x1D8
callq 0x15610
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
callq 0x3c790
movq (%rbp), %rax
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
callq *0x60(%rax)
movq (%rbp), %rax
movq %rbp, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq *0x68(%rax)
movq (%rbp), %rax
movq %rbp, %rdi
movl %ebx, %esi
movl %r15d, %edx
callq *0x70(%rax)
movq %r13, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0xbaf96
movq (%rbp), %rax
movq %rbp, %rdi
movq %r13, %rsi
callq *0x78(%rax)
movq (%rbp), %rax
movq %rbp, %rdi
movsd 0x10(%rsp), %xmm0
callq *0x88(%rax)
movq (%rbp), %rax
movq %rbp, %rdi
movsd 0x8(%rsp), %xmm0
callq *0x90(%rax)
movq (%rbp), %rax
movq %rbp, %rdi
leaq 0x170(%rsp), %rsi
callq *0xc8(%rax)
movq (%r14), %rax
movq %r14, %rdi
movq %rbp, %rsi
callq *0xa0(%rax)
incq %r12
movslq 0xec(%rsp), %rax
cmpq %rax, %r12
jl 0x1c099
jmp 0x1c2bf
leaq 0x170(%rsp), %rdi
leaq 0xeb7c5(%rip), %rsi     # 0x107a75
movl %r12d, %edx
xorl %eax, %eax
callq 0x15110
jmp 0x1c13d
movl $0x1, %ebx
cmpl $0x0, 0x150af1(%rip)    # 0x16cdbc
je 0x1c31b
leaq 0xeb7ab(%rip), %rdi     # 0x107a7f
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x15080
leaq 0x28(%rsp), %rdi
callq 0xc0d56
leaq 0xeb2c2(%rip), %rdi     # 0x1075b2
movb $0x1, %al
callq 0x15080
movl 0xec(%rsp), %esi
leaq 0xeb3ae(%rip), %rdi     # 0x1076b3
xorl %eax, %eax
callq 0x15080
movq 0x14fc4d(%rip), %rax    # 0x16bf60
movq (%rax), %rdi
callq 0x15750
leaq 0xd8(%rsp), %rdi
callq 0x1f858
movl %ebx, %eax
addq $0x578, %rsp            # imm = 0x578
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c35a
jmp 0x1c35a
jmp 0x1c35a
jmp 0x1c35a
jmp 0x1c35a
movq %rax, %rbx
movl $0x1d8, %esi            # imm = 0x1D8
movq %rbp, %rdi
callq 0x15620
jmp 0x1c35d
jmp 0x1c35a
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x1f858
movq %rbx, %rdi
callq 0x15ad0