// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelDatabase.cpp
// Function: gaps::R3SurfelDatabase::WriteBlockHeader(_IO_FILE*, int)
int R3SurfelDatabase::
WriteBlockHeader(FILE *fp, int swap_endian)
{
  // Seek to start of blocks
  RNFileSeek(fp, file_blocks_offset, RN_FILE_SEEK_SET);

  // Write blocks
  char buffer[128] = { '\0' };
  for (int i = 0; i < blocks.NEntries(); i++) {
    R3SurfelBlock *block = blocks.Kth(i);
    unsigned int block_flags = block->flags;
    if (!RNWriteUnsignedLongLong(fp, &block->file_surfels_offset, 1, swap_endian)) return 0;
    if (!RNWriteUnsignedInt(fp, &block->file_surfels_count, 1, swap_endian)) return 0;
    if (!RNWriteInt(fp, &block->nsurfels, 1, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &block->position_origin[0], 3, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &block->bbox[0][0], 6, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &block->resolution, 1, swap_endian)) return 0;
    if (!RNWriteUnsignedInt(fp, &block_flags, 1, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &block->timestamp_origin, 1, swap_endian)) return 0;
    if (!RNWriteDouble(fp, &block->timestamp_range[0], 2, swap_endian)) return 0;
    if (!RNWriteUnsignedInt(fp, &block->max_identifier, 1, swap_endian)) return 0;
    if (!RNWriteUnsignedInt(fp, &block->min_identifier, 1, swap_endian)) return 0;
    if (!RNWriteChar(fp, buffer, 32, swap_endian)) return 0;
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movq 0x30(%rdi), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0xabc5a
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpl $0x0, 0x4c(%r15)
jle 0x42dff
xorl %r13d, %r13d
leaq 0xc(%rsp), %r12
movq 0x40(%r15), %rax
movq (%rax,%r13,8), %rbp
movl 0x88(%rbp), %eax
movl %eax, 0xc(%rsp)
leaq 0xa8(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac50a
testl %eax, %eax
je 0x42dfb
leaq 0xb0(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42dfb
leaq 0x8(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac256
testl %eax, %eax
je 0x42dfb
leaq 0x10(%rbp), %rsi
movq %r14, %rdi
movl $0x3, %edx
movl %ebx, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42dfb
leaq 0x30(%rbp), %rsi
movq %r14, %rdi
movl $0x6, %edx
movl %ebx, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42dfb
leaq 0x80(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42dfb
movq %r14, %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42dfb
leaq 0x60(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42dfb
leaq 0x68(%rbp), %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebx, %ecx
callq 0xac3ee
testl %eax, %eax
je 0x42dfb
leaq 0x7c(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42dfb
addq $0x78, %rbp
movq %r14, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xac2de
testl %eax, %eax
je 0x42dfb
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movl %ebx, %ecx
callq 0xac0d0
testl %eax, %eax
je 0x42df2
incq %r13
movslq 0x4c(%r15), %rcx
cmpq %rcx, %r13
jl 0x42c94
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
jmp 0x42e04
xorl %ecx, %ecx
jmp 0x42e04
movl $0x1, %ecx
movl %ecx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq