// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2PixelDatabase.cpp
// Function: gaps::R2PixelDatabase::ReadHeader(_IO_FILE*)
int R2PixelDatabase::
ReadHeader(FILE *fp)
{
  // Seek to beginning of file
  RNFileSeek(fp, 0, RN_FILE_SEEK_SET);

  // Read magic string
  char buffer[1024]; 
  if (!RNReadChar(fp, buffer, 32, 0)) return 0;
  if (strcmp(buffer, "R2PixelDatabase")) {
    RNFail("Incorrect header (%s) in database file %s\n", buffer, filename);
    return 0;
  }

  // Read endian test
  unsigned int endian_test1, endian_test2;
  if (!RNReadUnsignedInt(fp, &endian_test1, 1, 0)) return 0;
  if (endian_test1 != 1) swap_endian = 1;
  if (!RNReadUnsignedInt(fp, &endian_test2, 1, swap_endian)) return 0;
  if (endian_test2 != 1) {
    RNFail("Incorrect endian (%x) in database file %s\n", endian_test1, filename);
    return 0;
  }

  // Read version
  if (!RNReadUnsignedInt(fp, &major_version, 1, swap_endian)) return 0;
  if (!RNReadUnsignedInt(fp, &minor_version, 1, swap_endian)) return 0;
  
  // Read entry info
  if (!RNReadUnsignedLongLong(fp, &entries_seek, 1, swap_endian)) return 0;
  if (!RNReadUnsignedInt(fp, &entries_count, 1, swap_endian)) return 0;

  // Read extra at end of header
  if (!RNReadChar(fp, buffer, 1024, swap_endian)) return 0;
  
  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rsi, %r14
movq %rdi, %r15
xorl %ebx, %ebx
movq %rsi, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x9c462
leaq 0x10(%rsp), %rsi
pushq $0x20
popq %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x9c478
testl %eax, %eax
je 0x8ddff
movdqa 0x10(%rsp), %xmm0
pcmpeqb 0x431a5(%rip), %xmm0    # 0xd0f80
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x8de0f
movq 0x18(%r15), %rdx
leaq 0x3bbbf(%rip), %rdi     # 0xc99b0
xorl %ebx, %ebx
leaq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x9ce26
movl %ebx, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rsi
pushq $0x1
popq %rbp
xorl %ebx, %ebx
movq %r14, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x9c61d
testl %eax, %eax
je 0x8ddff
cmpl $0x1, 0x8(%rsp)
jne 0x8de36
movl 0x30(%r15), %ebp
jmp 0x8de3e
movl $0x1, 0x30(%r15)
leaq 0xc(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movl %ebp, %ecx
callq 0x9c61d
testl %eax, %eax
je 0x8ddff
cmpl $0x1, 0xc(%rsp)
jne 0x8dee9
leaq 0x28(%r15), %rsi
movl 0x30(%r15), %ecx
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x9c61d
testl %eax, %eax
je 0x8ddff
leaq 0x2c(%r15), %rsi
movl 0x30(%r15), %ecx
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x9c61d
testl %eax, %eax
je 0x8ddff
leaq 0x38(%r15), %rsi
movl 0x30(%r15), %ecx
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x9c79a
testl %eax, %eax
je 0x8ddff
leaq 0x34(%r15), %rsi
movl 0x30(%r15), %ecx
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x9c61d
testl %eax, %eax
je 0x8ddff
movl 0x30(%r15), %ecx
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x9c478
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
jmp 0x8ddff
movl 0x8(%rsp), %esi
movq 0x18(%r15), %rdx
leaq 0x3bae3(%rip), %rdi     # 0xc99db
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x9ce26
jmp 0x8ddff