// File: /workspace/github_cpp_makefile_star2_O1/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 0xad14e
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)
setle %r13b
jle 0x43183
xorl %r12d, %r12d
movq 0x40(%r15), %rax
movq (%rax,%r12,8), %rbp
movl 0x88(%rbp), %eax
movl %eax, 0xc(%rsp)
leaq 0xa8(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xada8a
testl %eax, %eax
je 0x43183
leaq 0xb0(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad80e
testl %eax, %eax
je 0x43183
leaq 0x8(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad772
testl %eax, %eax
je 0x43183
leaq 0x10(%rbp), %rsi
movq %r14, %rdi
movl $0x3, %edx
movl %ebx, %ecx
callq 0xad946
testl %eax, %eax
je 0x43183
leaq 0x30(%rbp), %rsi
movq %r14, %rdi
movl $0x6, %edx
movl %ebx, %ecx
callq 0xad946
testl %eax, %eax
je 0x43183
leaq 0x80(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad946
testl %eax, %eax
je 0x43183
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad80e
testl %eax, %eax
je 0x43183
leaq 0x60(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad946
testl %eax, %eax
je 0x43183
leaq 0x68(%rbp), %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebx, %ecx
callq 0xad946
testl %eax, %eax
je 0x43183
leaq 0x7c(%rbp), %rsi
movq %r14, %rdi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad80e
testl %eax, %eax
je 0x43183
addq $0x78, %rbp
movq %r14, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0xad80e
testl %eax, %eax
je 0x43183
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movl %ebx, %ecx
callq 0xad5c4
testl %eax, %eax
je 0x43183
incq %r12
movslq 0x4c(%r15), %rax
cmpq %rax, %r12
setge %r13b
jl 0x4301f
movzbl %r13b, %eax
andl $0x1, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq