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

  // Read blocks
  char buffer[128] = { '\0' };
  for (unsigned int i = 0; i < nblocks; i++) {
    R3SurfelBlock *block = new R3SurfelBlock();
    unsigned int block_flags;
    if (!RNReadUnsignedLongLong(fp, &block->file_surfels_offset, 1, swap_endian)) return 0;
    if (!RNReadUnsignedInt(fp, &block->file_surfels_count, 1, swap_endian)) return 0;
    if (!RNReadInt(fp, &block->nsurfels, 1, swap_endian)) return 0;
    if (!RNReadDouble(fp, &block->position_origin[0], 3, swap_endian)) return 0;
    if (!RNReadDouble(fp, &block->bbox[0][0], 6, swap_endian)) return 0;
    if (!RNReadDouble(fp, &block->resolution, 1, swap_endian)) return 0;
    if (!RNReadUnsignedInt(fp, &block_flags, 1, swap_endian)) return 0;
    if (!RNReadDouble(fp, &block->timestamp_origin, 1, swap_endian)) return 0;
    if (!RNReadDouble(fp, &block->timestamp_range[0], 2, swap_endian)) return 0;
    if (!RNReadUnsignedInt(fp, &block->max_identifier, 1, swap_endian)) return 0;
    if (!RNReadUnsignedInt(fp, &block->min_identifier, 1, swap_endian)) return 0;
    if (!RNReadChar(fp, buffer, 32, swap_endian)) return 0;
    block->flags = block_flags;
    block->SetDirty(FALSE);
    block->database = this;
    block->database_index = blocks.NEntries();
    blocks.Insert(block);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
movl %edx, 0xdc(%rsp)
movl %ecx, 0xd8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xe0(%rsp), %rdi
movq 0x30(%rax), %rsi
xorl %edx, %edx
callq 0x145360
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x132c0
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
jae 0x755e7
movl $0xc8, %edi
callq 0x13570
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x47c30
jmp 0x7526b
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0xa8, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145a10
cmpl $0x0, %eax
jne 0x752d1
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
movl $0xc8, %esi
callq 0x13580
jmp 0x75601
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0xb0, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145710
cmpl $0x0, %eax
jne 0x7530b
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0x8, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145610
cmpl $0x0, %eax
jne 0x75342
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
addq $0x10, %rdi
xorl %esi, %esi
callq 0x1bde0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movl 0xd8(%rsp), %ecx
movl $0x3, %edx
callq 0x145810
cmpl $0x0, %eax
jne 0x7538d
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
addq $0x28, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl 0xd8(%rsp), %ecx
movl $0x6, %edx
callq 0x145810
cmpl $0x0, %eax
jne 0x753e2
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0x80, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145810
cmpl $0x0, %eax
jne 0x7541c
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
movl 0xd8(%rsp), %ecx
leaq 0x30(%rsp), %rsi
movl $0x1, %edx
callq 0x145710
cmpl $0x0, %eax
jne 0x7544f
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0x60, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145810
cmpl $0x0, %eax
jne 0x75486
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq 0x40(%rsp), %rdi
addq $0x68, %rdi
xorl %esi, %esi
callq 0x1be00
movq (%rsp), %rdi
movq %rax, %rsi
movl 0xd8(%rsp), %ecx
movl $0x2, %edx
callq 0x145810
cmpl $0x0, %eax
jne 0x754cf
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0x7c, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145710
cmpl $0x0, %eax
jne 0x75506
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq $0x78, %rsi
movl 0xd8(%rsp), %ecx
movl $0x1, %edx
callq 0x145710
cmpl $0x0, %eax
jne 0x7553d
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movq 0xe0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl 0xd8(%rsp), %ecx
movl $0x20, %edx
callq 0x1453c0
cmpl $0x0, %eax
jne 0x75570
movl $0x0, 0xf4(%rsp)
jmp 0x755f2
movl 0x30(%rsp), %eax
movl %eax, %esi
leaq 0x28(%rsp), %rdi
callq 0x1b970
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x88(%rax)
movq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x4b240
movq 0x20(%rsp), %rdi
movq 0x40(%rsp), %rax
movq %rdi, 0x98(%rax)
addq $0x40, %rdi
callq 0x16d50
movq 0x20(%rsp), %rdi
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0xa0(%rax)
addq $0x40, %rdi
movq 0x40(%rsp), %rsi
callq 0x436c0
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x7523e
movl $0x1, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
addq $0xf8, %rsp
retq
movq 0x38(%rsp), %rdi
callq 0x13970
nopl (%rax,%rax)