// File: /workspace/github_cpp_makefile_star2_O2/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
xorl %r13d, %r13d
movq %r14, %rdi
xorl %edx, %edx
callq 0x9c462
movq %r15, %rax
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rcx
movaps %xmm0, 0x70(%rcx)
movaps %xmm0, 0x60(%rcx)
movaps %xmm0, 0x50(%rcx)
movaps %xmm0, 0x40(%rcx)
movaps %xmm0, 0x30(%rcx)
movaps %xmm0, 0x20(%rcx)
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, (%rcx)
pushq $0x1
popq %rbp
movq %r15, 0x8(%rsp)
movq %r13, %r12
movslq 0x4c(%rax), %r15
cmpq %r15, %r13
jge 0x3da19
movq 0x40(%rax), %rax
movq (%rax,%r12,8), %r13
movl 0x88(%r13), %eax
movl %eax, 0x4(%rsp)
leaq 0xa8(%r13), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9cb44
testl %eax, %eax
je 0x3da23
leaq 0xb0(%r13), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9c99c
testl %eax, %eax
je 0x3da23
leaq 0x8(%r13), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9c932
testl %eax, %eax
je 0x3da23
leaq 0x10(%r13), %rsi
movq %r14, %rdi
pushq $0x3
popq %rdx
movl %ebx, %ecx
callq 0x9ca70
testl %eax, %eax
je 0x3da23
leaq 0x30(%r13), %rsi
movq %r14, %rdi
pushq $0x6
popq %rdx
movl %ebx, %ecx
callq 0x9ca70
testl %eax, %eax
je 0x3da23
leaq 0x80(%r13), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9ca70
testl %eax, %eax
je 0x3da23
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9c99c
testl %eax, %eax
je 0x3da23
leaq 0x60(%r13), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9ca70
testl %eax, %eax
je 0x3da23
leaq 0x68(%r13), %rsi
movq %r14, %rdi
pushq $0x2
popq %rdx
movl %ebx, %ecx
callq 0x9ca70
testl %eax, %eax
je 0x3da23
leaq 0x7c(%r13), %rsi
movq %r14, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9c99c
testl %eax, %eax
je 0x3da23
addq $0x78, %r13
movq %r14, %rdi
movq %r13, %rsi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x9c99c
testl %eax, %eax
je 0x3da23
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x20
popq %rdx
movl %ebx, %ecx
callq 0x9c7f2
leaq 0x1(%r12), %r13
testl %eax, %eax
movq 0x8(%rsp), %rax
jne 0x3d8ca
xorl %eax, %eax
cmpq %r15, %r12
setge %al
jmp 0x3da25
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop