// File: /workspace/github_cpp_makefile_star2_O3/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 0x9c6a2
movq 0x40(%r15), %rdi
movq %r12, %rsi
callq 0x9c77c
movq %rax, %r12
movl %ebp, 0xc(%rsp)
movq 0x40(%r15), %rbp
addq $0x8, %rbp
cmpq %rbp, %rax
je 0x9b469
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 0x9b483
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x41cce(%rip), %xmm0    # 0xdd148
xorl %r13d, %r13d
movsd %xmm0, 0x18(%rsp)
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movsd %xmm0, 0x20(%rsp)
je 0x9b4a4
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x134f0
cmpq %rbp, %r12
je 0x9b570
testq %rbx, %rbx
je 0x9b568
movq 0x8(%r15), %rdi
xorl %r12d, %r12d
movq %r13, %rsi
xorl %edx, %edx
callq 0xabc5a
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0x9a856
testl %eax, %eax
je 0x9b575
cmpl $0x0, 0xc(%rsp)
je 0x9b568
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x9b4f8
jnp 0x9b504
movq %rbx, %rdi
callq 0x95652
xorpd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x9b512
jnp 0x9b536
ucomisd 0x41c2e(%rip), %xmm0    # 0xdd148
jne 0x9b51e
jnp 0x9b536
movapd %xmm0, %xmm1
movsd 0x41c1e(%rip), %xmm0    # 0xdd148
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x956ec
xorpd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x9b548
jnp 0x9b568
ucomisd 0x41bf8(%rip), %xmm1    # 0xdd148
jne 0x9b554
jnp 0x9b568
movsd 0x41bec(%rip), %xmm0    # 0xdd148
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x9581e
movl $0x1, %r12d
jmp 0x9b586
xorl %r12d, %r12d
jmp 0x9b586
leaq 0x4aa94(%rip), %rdi     # 0xe6010
movq %r14, %rsi
xorl %eax, %eax
callq 0xac81a
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 0x9b5b6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x134f0
movq %rbx, %rdi
callq 0x138b0