// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2PixelDatabase.cpp
// Function: gaps::R2PixelDatabase::InsertGrid(char const*, gaps::R2Grid const&, double, double, double, int)
int R2PixelDatabase::
InsertGrid(const char *key, const R2Grid& grid,
  double offset, double scale, double exponent, RNBoolean apply_transformation)
{
  // Seek to end of entries
  unsigned long long seek = entries_seek;
  RNFileSeek(fp, seek, RN_FILE_SEEK_SET);

  // Check if need to apply offset, scale, or exponent
  if ((apply_transformation) &&
      ((offset != 0) || (scale != 1) || (exponent != 1))) {
    // Write processed pixels to file
    R2Grid tmp(grid);
    if (exponent != 1) tmp.Pow(exponent);
    if (scale != 1) tmp.Multiply(scale);
    if (offset != 0) tmp.Add(offset);
    if (!tmp.WritePNGStream(fp)) return FALSE;
  }
  else {
    // Write original pixels to file
    if (!grid.WritePNGStream(fp)) return FALSE;
  }

  // Update entries seek
  entries_seek = RNFileTell(fp);
  unsigned int size = entries_seek - seek;
  
  // Insert entry into map
  R2PixelDatabaseEntry entry(key, R2_PIXEL_DATABASE_1_16_PNG_FORMAT, size, seek, offset, scale, exponent);
  map.Insert(key, entry);
  
  // Insert key
  keys.push_back(key);
  
  // Increment number of entries
  entries_count++;

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movl %ecx, %r13d
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq 0x38(%rbx), %r15
xorl %ebp, %ebp
movq %r15, %rsi
xorl %edx, %edx
callq 0xad14e
testl %r13d, %r13d
je 0x9cb28
xorpd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x9cb41
jp 0x9cb41
movsd 0x10(%rsp), %xmm0
ucomisd 0x4163e(%rip), %xmm0    # 0xde150
jne 0x9cb41
jp 0x9cb41
movsd 0x8(%rsp), %xmm0
ucomisd 0x4162c(%rip), %xmm0    # 0xde150
jne 0x9cb41
jp 0x9cb41
movq 0x8(%rbx), %rsi
movq %r12, %rdi
callq 0x9bff0
testl %eax, %eax
jne 0x9cbd6
jmp 0x9ccfe
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x92870
movsd 0x8(%rsp), %xmm0
ucomisd 0x415f4(%rip), %xmm0    # 0xde150
jne 0x9cb60
jnp 0x9cb70
leaq 0x40(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x96a40
movsd 0x10(%rsp), %xmm0
ucomisd 0x415d2(%rip), %xmm0    # 0xde150
jne 0x9cb82
jnp 0x9cb92
leaq 0x40(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
callq 0x9690e
xorpd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x9cba4
jnp 0x9cbb4
leaq 0x40(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
callq 0x967da
movq 0x8(%rbx), %rsi
leaq 0x40(%rsp), %rdi
callq 0x9bff0
movl %eax, %ebp
leaq 0x40(%rsp), %rdi
callq 0x92a48
testl %ebp, %ebp
je 0x9cd12
movq 0x8(%rbx), %rdi
callq 0xad15f
movq %rax, 0x38(%rbx)
subl %r15d, %eax
movl $0x1, 0x190(%rsp)
movl %eax, 0x194(%rsp)
movq %r15, 0x198(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movb $0x0, 0x110(%rsp)
testq %r14, %r14
je 0x9cc4f
leaq 0x110(%rsp), %rdi
movl $0x7f, %edx
movq %r14, %rsi
callq 0x13280
movb $0x0, 0x18f(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %r14, %rsi
callq 0x9d95a
leaq 0x40(%rsp), %rdi
leaq 0x110(%rsp), %rsi
movl $0xa8, %edx
callq 0x133f0
movq 0x40(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0x9dc6a
leaq 0x40(%rsp), %rsi
movl $0xa8, %edx
movq %rax, %rdi
callq 0x133f0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9ccbb
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x134f0
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %r14, %rsi
callq 0x9d95a
leaq 0x48(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x9e714
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9ccf6
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x134f0
incl 0x34(%rbx)
movl $0x1, %ebp
movl %ebp, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x9ccfe
movq %rax, %rbx
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9cd62
movq 0x50(%rsp), %rsi
jmp 0x9cd46
jmp 0x9cd50
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9cd62
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x134f0
jmp 0x9cd62
movq %rax, %rbx
jmp 0x9cd62
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x92a48
movq %rbx, %rdi
callq 0x138b0