// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2PixelDatabase.cpp
// Function: gaps::R2PixelDatabase::FindGrid(char const*, gaps::R2Grid*, int) const
int R2PixelDatabase::
FindGrid(const char *key, R2Grid *grid, RNBoolean apply_transformation) const
{
  // Find entry
  R2PixelDatabaseEntry entry;
  if (!map.Find(key, &entry)) return FALSE;

  // Read grid
  if (grid) {
    // Seek to start of entry
    RNFileSeek(fp, entry.seek, RN_FILE_SEEK_SET);
  
    // Read entry
    if (!grid->ReadPNGStream(fp)) {
      RNFail("Error reading %s from pixel database\n", key);
      return FALSE;
    }

    // Check if should apply transformation
    if (apply_transformation) {
      // Apply offset 
      if (entry.offset != 0) {
        grid->Subtract(entry.offset);
      }

      // Apply scale 
      if ((entry.scale != 0) && (entry.scale != 1)) {
        grid->Multiply(1.0 / entry.scale);
      }

      // Apply exponent
      if ((entry.exponent != 0) && (entry.exponent != 1)) {
        grid->Pow(1.0 / entry.exponent);
      }
    }
  }

  // Return success
  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x28(%rsp), %r12
leaq 0xb(%rsp), %rdx
movq %r12, %rdi
callq 0x9d95a
movq 0x40(%r15), %rdi
movq %r12, %rsi
callq 0x9da34
movq %rax, %r12
movl %ebp, 0xc(%rsp)
movq 0x40(%r15), %rbp
addq $0x8, %rbp
cmpq %rbp, %rax
je 0x9c701
movq 0xc8(%r12), %r13
movsd 0xd0(%r12), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0xd8(%r12), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0xe0(%r12), %xmm0
jmp 0x9c71b
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x41a3e(%rip), %xmm0    # 0xde150
xorl %r13d, %r13d
movsd %xmm0, 0x18(%rsp)
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movsd %xmm0, 0x20(%rsp)
je 0x9c73c
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x134f0
cmpq %rbp, %r12
je 0x9c808
testq %rbx, %rbx
je 0x9c800
movq 0x8(%r15), %rdi
xorl %r12d, %r12d
movq %r13, %rsi
xorl %edx, %edx
callq 0xad14e
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0x9bae6
testl %eax, %eax
je 0x9c80d
cmpl $0x0, 0xc(%rsp)
je 0x9c800
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x9c790
jnp 0x9c79c
movq %rbx, %rdi
callq 0x96874
xorpd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x9c7aa
jnp 0x9c7ce
ucomisd 0x4199e(%rip), %xmm0    # 0xde150
jne 0x9c7b6
jnp 0x9c7ce
movapd %xmm0, %xmm1
movsd 0x4198e(%rip), %xmm0    # 0xde150
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x9690e
xorpd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x9c7e0
jnp 0x9c800
ucomisd 0x41968(%rip), %xmm1    # 0xde150
jne 0x9c7ec
jnp 0x9c800
movsd 0x4195c(%rip), %xmm0    # 0xde150
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x96a40
movl $0x1, %r12d
jmp 0x9c81e
xorl %r12d, %r12d
jmp 0x9c81e
leaq 0x4a81c(%rip), %rdi     # 0xe7030
movq %r14, %rsi
xorl %eax, %eax
callq 0xaddb2
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c84e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x134f0
movq %rbx, %rdi
callq 0x138b0