// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2PixelDatabase.cpp
// Function: gaps::R2PixelDatabase::InsertImage(char const*, gaps::R2Image const&)
int R2PixelDatabase::
InsertImage(const char *key, const R2Image& image)
{
  // Seek to end of entries
  unsigned long long seek = entries_seek;
  RNFileSeek(fp, seek, RN_FILE_SEEK_SET);

  // Write pixels to file
  if (!image.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_3_8_PNG_FORMAT, size, seek);
  map.Insert(key, entry);

  // Insert key
  keys.push_back(key);
  
  // Increment number of entries
  entries_count++;

  // Return success
  return 1;
}

// Assembly:
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rdi, 0x2b8(%rsp)
movq %rsi, 0x2b0(%rsp)
movq %rdx, 0x2a8(%rsp)
movq 0x2b8(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x38(%rax), %rcx
movq %rcx, 0x2a0(%rsp)
movq 0x8(%rax), %rdi
movq 0x2a0(%rsp), %rsi
xorl %edx, %edx
callq 0x145360
movq 0xe0(%rsp), %rax
movq 0x2a8(%rsp), %rdi
movq 0x8(%rax), %rsi
callq 0x13ad40
cmpl $0x0, %eax
jne 0x1250dc
movl $0x0, 0x2c4(%rsp)
jmp 0x125337
movq 0xe0(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1453b0
movq %rax, %rcx
movq 0xe0(%rsp), %rax
movq %rcx, 0x38(%rax)
movl 0x38(%rax), %eax
movl 0x2a0(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x29c(%rsp)
movq 0x2b0(%rsp), %rsi
movl 0x29c(%rsp), %ecx
movq 0x2a0(%rsp), %r8
leaq 0x1f0(%rsp), %rdi
xorl %edx, %edx
xorps %xmm0, %xmm0
movsd 0x7f02d(%rip), %xmm2    # 0x1a4168
movaps %xmm2, %xmm1
callq 0x126bf0
movq 0xe0(%rsp), %rax
addq $0x40, %rax
movq %rax, 0xc8(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0xd0(%rsp)
leaq 0x1cf(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x13980
movq 0xd0(%rsp), %rsi
movq 0xd8(%rsp), %rdx
leaq 0x1d0(%rsp), %rdi
callq 0xbd8c0
jmp 0x12519b
leaq 0x110(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
leaq 0x1f0(%rsp), %rsi
movl $0xa8, %edx
callq 0x13460
movq 0xc0(%rsp), %rsi
movq %rsp, %rdi
movl $0x15, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq 0xc8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x126d40
jmp 0x1251e7
leaq 0x1d0(%rsp), %rdi
callq 0x13340
leaq 0x1cf(%rsp), %rdi
callq 0x135f0
movq 0xe0(%rsp), %rax
addq $0x48, %rax
movq %rax, 0xa8(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0xef(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x13980
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
leaq 0xf0(%rsp), %rdi
callq 0xbd8c0
jmp 0x125259
movq 0xa8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x126d80
jmp 0x125270
leaq 0xf0(%rsp), %rdi
callq 0x13340
leaq 0xef(%rsp), %rdi
callq 0x135f0
movq 0xe0(%rsp), %rax
movl 0x34(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x34(%rax)
movl $0x1, 0x2c4(%rsp)
jmp 0x125337
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
jmp 0x1252e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x13340
leaq 0x1cf(%rsp), %rdi
callq 0x135f0
jmp 0x125346
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
jmp 0x125328
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x13340
leaq 0xef(%rsp), %rdi
callq 0x135f0
jmp 0x125346
movl 0x2c4(%rsp), %eax
addq $0x2c8, %rsp            # imm = 0x2C8
retq
movq 0x1c0(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)