// File: /workspace/github_cpp_makefile_star2_O1/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 0x32a06
cmpq $0x0, 0x1aaf1a(%rip)    # 0x1dd3f0
je 0x32a06
movq %rdi, %r14
movsd %xmm0, 0x18(%rsp)
movapd %xmm1, (%rsp)
movl $0x778, %edi            # imm = 0x778
callq 0x27930
movq %rax, %rbx
movq %rax, %rdi
callq 0x32a34
movq 0x1aaeea(%rip), %rdx    # 0x1dd3f0
leaq 0x11c343(%rip), %rsi    # 0x14e850
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfc978
testl %eax, %eax
je 0x32583
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xf3c20
testl %eax, %eax
jne 0x325c4
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32546
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x32565
jmp 0x329cb
movq 0x1aae66(%rip), %rdx    # 0x1dd3f0
leaq 0x11c2d6(%rip), %rsi    # 0x14e867
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfc978
testl %eax, %eax
je 0x325c4
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xf3c20
testl %eax, %eax
je 0x3294d
movq 0x1aae25(%rip), %rdx    # 0x1dd3f0
leaq 0x11c2ac(%rip), %rsi    # 0x14e87e
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfc978
testl %eax, %eax
je 0x32674
leaq 0x18(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe9bfe
testl %eax, %eax
je 0x32811
movsd 0x11ba73(%rip), %xmm1   # 0x14e088
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 0xe61e2
movq %r15, %rdi
movapd (%rsp), %xmm0
callq 0xe6314
movq 0x1aad75(%rip), %rdx    # 0x1dd3f0
leaq 0x11c213(%rip), %rsi    # 0x14e895
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfc978
testl %eax, %eax
je 0x326bc
leaq 0xe8(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe9bfe
testl %eax, %eax
je 0x32872
movq 0x1aad2d(%rip), %rdx    # 0x1dd3f0
leaq 0x11c1e5(%rip), %rsi    # 0x14e8af
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r15, %rdi
callq 0xfc978
testl %eax, %eax
je 0x32704
leaq 0x1b8(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe9bfe
testl %eax, %eax
je 0x32907
leaq 0x288(%rbx), %r15
leaq 0x11bc46(%rip), %rbp    # 0x14e358
leaq 0x20(%rsp), %r13
xorl %r12d, %r12d
leaq 0x11c75b(%rip), %r8     # 0x14ee7c
cmpq $0x2, %r12
ja 0x32735
movslq (%rbp), %r8
leaq 0x11bc26(%rip), %rax    # 0x14e358
addq %rax, %r8
movq 0x1aacb4(%rip), %rdx    # 0x1dd3f0
movq %r13, %rdi
leaq 0x11c189(%rip), %rsi    # 0x14e8cf
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r13, %rdi
callq 0xfc978
testl %eax, %eax
je 0x3276f
movq %r15, %rdi
movq %r13, %rsi
callq 0xe9bfe
testl %eax, %eax
je 0x328c4
incq %r12
addq $0x4, %rbp
addq $0xd0, %r15
cmpq $0x3, %r12
jne 0x3271a
leaq 0x4f8(%rbx), %r15
leaq 0x11bbd3(%rip), %rbp    # 0x14e364
leaq 0x20(%rsp), %r13
xorl %r12d, %r12d
leaq 0x11c6dc(%rip), %r8     # 0x14ee7c
cmpq $0x2, %r12
ja 0x327b4
movslq (%rbp), %r8
leaq 0x11bbb3(%rip), %rax    # 0x14e364
addq %rax, %r8
movq 0x1aac35(%rip), %rdx    # 0x1dd3f0
movq %r13, %rdi
leaq 0x11c10a(%rip), %rsi    # 0x14e8cf
movq %r14, %rcx
xorl %eax, %eax
callq 0x27140
movq %r13, %rdi
callq 0xfc978
testl %eax, %eax
je 0x327ee
movq %r15, %rdi
movq %r13, %rsi
callq 0xe9bfe
testl %eax, %eax
je 0x3298d
incq %r12
addq $0x4, %rbp
addq $0xd0, %r15
cmpq $0x3, %r12
jne 0x32799
movq (%rbx), %rax
movq %rax, 0x768(%rbx)
jmp 0x32a06
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32817
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x32836
leaq 0x1b8(%rbx), %rdi
callq 0xe231c
movq %rbx, %rdi
addq $0xe8, %rdi
callq 0xe231c
movq %r15, %rdi
jmp 0x329ea
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32878
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x32897
leaq 0x1b8(%rbx), %rdi
callq 0xe231c
movq %r15, %rdi
jmp 0x329de
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x328ca
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x328e9
jmp 0x329cb
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x3290d
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x3292c
movq %r15, %rdi
jmp 0x329d2
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32953
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x32972
jmp 0x329cb
movl $0x698, %r14d           # imm = 0x698
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x428, %r14            # imm = 0x428
jne 0x32993
movl $0x428, %r14d           # imm = 0x428
leaq (%rbx,%r14), %rdi
callq 0xe231c
addq $-0xd0, %r14
cmpq $0x1b8, %r14            # imm = 0x1B8
jne 0x329b2
leaq 0x1b8(%rbx), %rdi
callq 0xe231c
leaq 0xe8(%rbx), %rdi
callq 0xe231c
movq %rbx, %rdi
addq $0x18, %rdi
callq 0xe231c
movq %rbx, %rdi
callq 0xf4186
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 0x28160
nop