// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelDatabase.cpp
// Function: gaps::R3SurfelDatabase::WriteFileHeader(_IO_FILE*, int)
int R3SurfelDatabase::
WriteFileHeader(FILE *fp, int swap_endian)
{
  // Get convenient variables
  unsigned int endian_test = 1;
  unsigned int nblocks = blocks.NEntries();
  char magic[32] = { '\0' };
  strncpy(magic, "R3SurfelDatabase", 32);
  char buffer[1024] = { '\0' };

  // Seek to start of file
  RNFileSeek(fp, 0, RN_FILE_SEEK_SET);

  // Write first part of header
  if (!RNWriteChar(fp, magic, 32, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &endian_test, 1, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &endian_test, 1, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &major_version, 1, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &minor_version, 1, swap_endian)) return 0;
  if (!RNWriteUnsignedLongLong(fp, &file_blocks_offset, 1, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &file_blocks_count, 1, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &nblocks, 1, swap_endian)) return 0;

  // Write number of surfels
  if (major_version < 4) {
    // nsurfels used to be an int
    int nsurfels32 = nsurfels;
    if (!RNWriteInt(fp, &nsurfels32, 1, swap_endian)) return 0;
  }
  else {
    // nsurfels now is an RNInt64
    if (!RNWriteLongLong(fp, &nsurfels, 1, swap_endian)) return 0;
  }

  // Write rest of header
  if (!RNWriteDouble(fp, &bbox[0][0], 6, swap_endian)) return 0;
  if (!RNWriteDouble(fp, &timestamp_range[0], 2, swap_endian)) return 0;
  if (!RNWriteUnsignedInt(fp, &max_identifier, 1, swap_endian)) return 0;
  if (!RNWriteChar(fp, buffer, 1004, swap_endian)) return 0;

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x430, %rsp            # imm = 0x430
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movl $0x1, 0x4(%rsp)
movl 0x4c(%rdi), %eax
movl %eax, 0x8(%rsp)
movups 0x9c2fe(%rip), %xmm0    # 0xdead9
leaq 0x10(%rsp), %r12
movaps %xmm0, 0x10(%r12)
movups 0x9c2dc(%rip), %xmm0    # 0xdeac9
movaps %xmm0, (%r12)
leaq 0x30(%rsp), %rdi
xorl %ebx, %ebx
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x132a0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xabc5a
movq %r14, %rdi
movq %r12, %rsi
movl $0x20, %edx
movl %ebp, %ecx
callq 0xac0d0
testl %eax, %eax
je 0x42991
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
leaq 0x20(%r15), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
leaq 0x24(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
leaq 0x30(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac50a
testl %eax, %eax
je 0x42991
leaq 0x38(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
cmpl $0x3, (%r12)
ja 0x42911
movl 0x50(%r15), %eax
leaq 0xc(%rsp), %rsi
movl %eax, (%rsi)
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac256
jmp 0x42924
leaq 0x50(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac47c
testl %eax, %eax
je 0x42991
leaq 0x60(%r15), %rsi
movq %r14, %rdi
movl $0x6, %edx
movl %ebp, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42991
leaq 0x90(%r15), %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42991
addq $0xa0, %r15
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
movl %ebp, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42991
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
movl $0x3ec, %edx            # imm = 0x3EC
movl %ebp, %ecx
callq 0xac0d0
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
movl %ebx, %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop