// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2PixelDatabase.cpp
// Function: gaps::R2PixelDatabase::WriteEntries(_IO_FILE*, int)
int R2PixelDatabase::
WriteEntries(FILE *fp, int swap_endian)
{
  // Seek to entries seek
  RNFileSeek(fp, entries_seek, RN_FILE_SEEK_SET);

  // Write entries
  int dummy = 0;
  char buffer[128] = { '\0' };
  std::map<std::string, R2PixelDatabaseEntry, RNMapComparator<std::string> >::iterator it;
  for (it = map.m->begin(); it != map.m->end(); ++it) {
    R2PixelDatabaseEntry entry = it->second;
    strncpy(buffer, entry.key, 128);
    if (!RNWriteChar(fp, buffer, 128, swap_endian)) return 0;
    if (!RNWriteUnsignedInt(fp, &entry.format, 1, swap_endian)) return 0;
    if (!RNWriteUnsignedInt(fp, &entry.size, 1, swap_endian)) return 0;
    if (!RNWriteUnsignedLongLong(fp, &entry.seek, 1, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &entry.offset, 1, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &entry.scale, 1, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &entry.exponent, 1, swap_endian)) return 0;
    for (int j = 0; j < 12; j++) RNWriteInt(fp, &dummy, 1, swap_endian);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x168(%rsp)
movq %rsi, 0x160(%rsp)
movl %edx, 0x15c(%rsp)
movq 0x168(%rsp), %rax
movq %rax, (%rsp)
movq 0x160(%rsp), %rdi
movq 0x38(%rax), %rsi
xorl %edx, %edx
callq 0x145360
movl $0x0, 0x158(%rsp)
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x132c0
leaq 0xc8(%rsp), %rdi
callq 0x126fe0
movq (%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x127000
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq (%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x127050
movq %rax, 0xb8(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x127030
testb $0x1, %al
jne 0x126921
jmp 0x126b3b
leaq 0xc8(%rsp), %rdi
callq 0x127080
movq %rax, %rsi
addq $0x20, %rsi
leaq 0x10(%rsp), %rdi
movl $0xa8, %edx
callq 0x13460
leaq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x80, %edx
callq 0x132a0
movq 0x160(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movl 0x15c(%rsp), %ecx
movl $0x80, %edx
callq 0x145a90
cmpl $0x0, %eax
jne 0x126991
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movq 0x160(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0x80, %rsi
movl 0x15c(%rsp), %ecx
movl $0x1, %edx
callq 0x145d20
cmpl $0x0, %eax
jne 0x1269cb
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movq 0x160(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0x84, %rsi
movl 0x15c(%rsp), %ecx
movl $0x1, %edx
callq 0x145d20
cmpl $0x0, %eax
jne 0x126a05
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movq 0x160(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0x88, %rsi
movl 0x15c(%rsp), %ecx
movl $0x1, %edx
callq 0x145f60
cmpl $0x0, %eax
jne 0x126a3f
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movq 0x160(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0x90, %rsi
movl 0x15c(%rsp), %ecx
movl $0x1, %edx
callq 0x145e40
cmpl $0x0, %eax
jne 0x126a79
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movq 0x160(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0x98, %rsi
movl 0x15c(%rsp), %ecx
movl $0x1, %edx
callq 0x145e40
cmpl $0x0, %eax
jne 0x126ab3
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movq 0x160(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0xa0, %rsi
movl 0x15c(%rsp), %ecx
movl $0x1, %edx
callq 0x145e40
cmpl $0x0, %eax
jne 0x126aea
movl $0x0, 0x174(%rsp)
jmp 0x126b46
movl $0x0, 0xc(%rsp)
cmpl $0xc, 0xc(%rsp)
jge 0x126b27
movq 0x160(%rsp), %rdi
movl 0x15c(%rsp), %ecx
leaq 0x158(%rsp), %rsi
movl $0x1, %edx
callq 0x145c90
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x126af2
jmp 0x126b29
leaq 0xc8(%rsp), %rdi
callq 0x1270a0
jmp 0x1268ee
movl $0x1, 0x174(%rsp)
movl 0x174(%rsp), %eax
addq $0x178, %rsp            # imm = 0x178
retq
nopw %cs:(%rax,%rax)
nop