// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: ReadImageFiles(char const*, double, double)
static ImageData *
ReadImageFiles(const char *image_name,
  double depth_scale, double depth_exponent)
{
  // Check image directory
  if (!image_directory) return NULL;
  if (!image_name) return NULL;
  
  /// Get convenient variables
  double ds = (depth_scale >= 0) ? 1.0 / depth_scale : 1.0;
  double de = (depth_exponent != 0) ? 1.0 / depth_exponent : 1.0;
  char filename[2048];
  
  // Allocate GSV image data structure
  ImageData *data = new ImageData();
  if (!data) {
    fprintf(stderr, "Unable to allocate GSV image data\n");
    return NULL;
  }

  // Read color image 
  sprintf(filename, "%s/color_images/%s.png", image_directory, image_name);
  if (RNFileExists(filename)) {
    if (!data->color_image.ReadFile(filename)) { delete data; return NULL; }
  }
  else {
    sprintf(filename, "%s/color_images/%s.jpg", image_directory, image_name);
    if (RNFileExists(filename)) {
      if (!data->color_image.ReadFile(filename)) { delete data; return NULL; }
    }
  }

  // Read depth image
  sprintf(filename, "%s/depth_images/%s.png", image_directory, image_name);
  if (RNFileExists(filename)) {
    if (!data->depth_image.ReadFile(filename)) { delete data; return NULL; }
    data->depth_image.Multiply(ds);
    data->depth_image.Pow(de);
  }

  // Read category image
  sprintf(filename, "%s/category_images/%s.png", image_directory, image_name);
  if (RNFileExists(filename)) {
    if (!data->category_image.ReadFile(filename)) { delete data; return NULL; }
  }

  // Read instance image
  sprintf(filename, "%s/instance_images/%s.png", image_directory, image_name);
  if (RNFileExists(filename)) {
    if (!data->instance_image.ReadFile(filename)) { delete data; return NULL; }
  }

  // Read ray_origin images
  for (int i = 0; i < 3; i++) {
    const char *channel_name = "";
    if (i == 0) channel_name = "ox";
    else if (i == 1) channel_name = "oy";
    else if (i == 2) channel_name = "oz";
    sprintf(filename, "%s/ray_images/%s_%s.pfm", image_directory, image_name, channel_name);
    if (RNFileExists(filename)) {
      if (!data->ray_origin_images[i].ReadFile(filename)) { delete data; return NULL; }
    }
  }

  // Read ray_direction images
  for (int i = 0; i < 3; i++) {
    const char *channel_name = "";
    if (i == 0) channel_name = "dx";
    else if (i == 1) channel_name = "dy";
    else if (i == 2) channel_name = "dz";
    sprintf(filename, "%s/ray_images/%s_%s.pfm", image_directory, image_name, channel_name);
    if (RNFileExists(filename)) {
      if (!data->ray_direction_images[i].ReadFile(filename)) { delete data; return NULL; }
    }
  }

  // Set image dimensions
  data->image_width = data->color_image.Width();
  data->image_height = data->color_image.Height();
  
  // Return data
  return data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x828, %rsp            # imm = 0x828
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x3285f
cmpq $0x0, 0x1a9083(%rip)    # 0x1db3e0
je 0x3285f
movq %rdi, %r14
movsd %xmm0, 0x18(%rsp)
movapd %xmm1, (%rsp)
movl $0x778, %edi            # imm = 0x778
callq 0x27930
movq %rax, %rbx
movq %rax, %rdi
callq 0x3288c
movq 0x1a9053(%rip), %rdx    # 0x1db3e0
leaq 0x11a4c9(%rip), %rsi    # 0x14c85d
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x3240a
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xf1fc8
testl %eax, %eax
jne 0x3244b
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x323cd
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x323ec
jmp 0x32824
movq 0x1a8fcf(%rip), %rdx    # 0x1db3e0
leaq 0x11a45c(%rip), %rsi    # 0x14c874
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x3244b
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xf1fc8
testl %eax, %eax
je 0x327a6
movq 0x1a8f8e(%rip), %rdx    # 0x1db3e0
leaq 0x11a432(%rip), %rsi    # 0x14c88b
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x324fb
leaq 0x18(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe7fee
testl %eax, %eax
je 0x3266a
movsd 0x119bdc(%rip), %xmm1   # 0x14c078
movapd %xmm1, %xmm2
movsd 0x18(%rsp), %xmm4
divsd %xmm4, %xmm2
xorpd %xmm3, %xmm3
xorpd %xmm0, %xmm0
cmplesd %xmm4, %xmm0
andpd %xmm0, %xmm2
andnpd %xmm1, %xmm0
orpd %xmm2, %xmm0
movapd %xmm1, %xmm2
movapd (%rsp), %xmm4
divsd %xmm4, %xmm2
cmpneqsd %xmm3, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, (%rsp)
movq %r15, %rdi
callq 0xe4604
movq %r15, %rdi
movapd (%rsp), %xmm0
callq 0xe4736
movq 0x1a8ede(%rip), %rdx    # 0x1db3e0
leaq 0x11a399(%rip), %rsi    # 0x14c8a2
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x32543
leaq 0xe8(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe7fee
testl %eax, %eax
je 0x326cb
movq 0x1a8e96(%rip), %rdx    # 0x1db3e0
leaq 0x11a36b(%rip), %rsi    # 0x14c8bc
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x3258b
leaq 0x1b8(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe7fee
testl %eax, %eax
je 0x32760
leaq 0x288(%rbx), %r15
leaq 0x119db7(%rip), %rbp    # 0x14c350
leaq 0x20(%rsp), %r13
xorl %r12d, %r12d
movslq (%r12,%rbp), %r8
addq %rbp, %r8
movq 0x1a8e31(%rip), %rdx    # 0x1db3e0
movq %r13, %rdi
leaq 0x11a323(%rip), %rsi    # 0x14c8dc
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r13, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x325e2
movq %r15, %rdi
movq %r13, %rsi
callq 0xe7fee
testl %eax, %eax
je 0x3271d
addq $0x4, %r12
addq $0xd0, %r15
cmpq $0xc, %r12
jne 0x325a1
leaq 0x4f8(%rbx), %r15
leaq 0x119d5b(%rip), %rbp    # 0x14c35c
leaq 0x20(%rsp), %r13
xorl %r12d, %r12d
movslq (%r12,%rbp), %r8
addq %rbp, %r8
movq 0x1a8dc9(%rip), %rdx    # 0x1db3e0
movq %r13, %rdi
leaq 0x11a2bb(%rip), %rsi    # 0x14c8dc
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r13, %rdi
callq 0xfaac4
testl %eax, %eax
je 0x3264a
movq %r15, %rdi
movq %r13, %rsi
callq 0xe7fee
testl %eax, %eax
je 0x327e6
addq $0x4, %r12
addq $0xd0, %r15
cmpq $0xc, %r12
jne 0x32609
movq (%rbx), %rax
movq %rax, 0x768(%rbx)
jmp 0x3285f
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32670
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x3268f
leaq 0x1b8(%rbx), %rdi
callq 0xe0804
movq %rbx, %rdi
addq $0xe8, %rdi
callq 0xe0804
movq %r15, %rdi
jmp 0x32843
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x326d1
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x326f0
leaq 0x1b8(%rbx), %rdi
callq 0xe0804
movq %r15, %rdi
jmp 0x32837
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32723
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x32742
jmp 0x32824
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32766
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x32785
movq %r15, %rdi
jmp 0x3282b
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x327ac
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x327cb
jmp 0x32824
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x327ec
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe0804
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x3280b
leaq 0x1b8(%rbx), %rdi
callq 0xe0804
leaq 0xe8(%rbx), %rdi
callq 0xe0804
movq %rbx, %rdi
addq $0x18, %rdi
callq 0xe0804
movq %rbx, %rdi
callq 0xf2520
movl $0x778, %esi            # imm = 0x778
movq %rbx, %rdi
callq 0x27950
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x778, %esi            # imm = 0x778
movq %rbx, %rdi
callq 0x27950
movq %r14, %rdi
callq 0x28150