// File: /workspace/github_cpp_makefile_star2_O1/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 0xc2368
xorl %ebx, %ebx
movq %r15, %rdi
xorl %esi, %esi
callq 0x15a20
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
callq 0x1fa4c
movq %r15, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x20118
testl %eax, %eax
je 0x1c5c1
movq %r12, (%rsp)
cmpl $0x0, 0xec(%rsp)
jle 0x1c565
leaq 0xc8(%rsp), %r13
xorl %r12d, %r12d
movq 0xe0(%rsp), %rax
movq (%rax,%r12,8), %r15
movq 0x1d0(%r15), %rbx
testq %rbx, %rbx
je 0x1c375
movq %rbx, %rdi
leaq 0xed710(%rip), %rsi     # 0x109a7c
callq 0x158c0
testl %eax, %eax
jne 0x1c3da
movq 0x1d8(%r15), %rbx
testq %rbx, %rbx
je 0x1c394
movq %rbx, %rdi
leaq 0xed6f1(%rip), %rsi     # 0x109a7c
callq 0x158c0
testl %eax, %eax
jne 0x1c3b3
movq 0x1e0(%r15), %rbx
testq %rbx, %rbx
je 0x1c3f1
movq %rbx, %rdi
leaq 0xed6d2(%rip), %rsi     # 0x109a7c
callq 0x158c0
testl %eax, %eax
je 0x1c3f1
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x156a0
testq %rax, %rax
je 0x1c3da
incq %rax
movl $0x400, %edx            # imm = 0x400
leaq 0x170(%rsp), %rdi
movq %rax, %rsi
jmp 0x1c3ea
movl $0x400, %edx            # imm = 0x400
leaq 0x170(%rsp), %rdi
movq %rbx, %rsi
callq 0x15300
jmp 0x1c40a
leaq 0x170(%rsp), %rdi
leaq 0xed67e(%rip), %rsi     # 0x109a7e
movl %r12d, %edx
xorl %eax, %eax
callq 0x15110
leaq 0x38(%r15), %rbx
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
leaq 0x554483(%rip), %rdx    # 0x5708a0
callq 0x8d652
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
leaq 0xf6757(%rip), %rdx     # 0x112b88
callq 0x8d5da
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
leaq 0xf66e3(%rip), %rdx     # 0x112b28
callq 0x8d5da
movl 0x28(%r15), %ebp
movl 0x2c(%r15), %ebx
addq $0x140, %r15            # imm = 0x140
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0xba6a2
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, %r15
movq %rax, %rdi
xorl %esi, %esi
callq 0x3cc0c
movq (%r15), %rax
movq %r15, %rdi
leaq 0x68(%rsp), %rsi
callq *0x60(%rax)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq *0x68(%rax)
movq (%r15), %rax
movq %r15, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq *0x70(%rax)
movq %r13, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0xbc5d6
movq (%r15), %rax
movq %r15, %rdi
movq %r13, %rsi
callq *0x78(%rax)
movq (%r15), %rax
movq %r15, %rdi
movsd 0x10(%rsp), %xmm0
callq *0x88(%rax)
movq (%r15), %rax
movq %r15, %rdi
movsd 0x8(%rsp), %xmm0
callq *0x90(%rax)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x170(%rsp), %rsi
callq *0xc8(%rax)
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0xa0(%rax)
incq %r12
movslq 0xec(%rsp), %rax
cmpq %rax, %r12
jl 0x1c34a
movl $0x1, %ebx
cmpl $0x0, 0x15285b(%rip)    # 0x16edcc
je 0x1c5c1
leaq 0xed50e(%rip), %rdi     # 0x109a88
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x15080
leaq 0x28(%rsp), %rdi
callq 0xc23ca
leaq 0xed023(%rip), %rdi     # 0x1095b9
movb $0x1, %al
callq 0x15080
movl 0xec(%rsp), %esi
leaq 0xed10f(%rip), %rdi     # 0x1096ba
xorl %eax, %eax
callq 0x15080
movq 0x1519a7(%rip), %rax    # 0x16df60
movq (%rax), %rdi
callq 0x15760
leaq 0xd8(%rsp), %rdi
callq 0x1fadc
movl %ebx, %eax
addq $0x578, %rsp            # imm = 0x578
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c600
jmp 0x1c600
jmp 0x1c600
jmp 0x1c600
jmp 0x1c600
movq %rax, %rbx
movl $0x1d8, %esi            # imm = 0x1D8
movq %r15, %rdi
callq 0x15620
jmp 0x1c603
jmp 0x1c600
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x1fadc
movq %rbx, %rdi
callq 0x15ae0