// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::ReadBinary(_IO_FILE*)
int R3SurfelBlock::
ReadBinary(FILE *fp)
{
  // Read number of surfels
  if (fread(&nsurfels, sizeof(int), 1, fp) != (size_t) 1) {
    RNFail("Unable to read number of surfels\n");
    return 0;
  }

  // Read bounding box
  if (fread(&bbox, sizeof(R3Box), 1, fp) != (size_t) 1) {
    RNFail("Unable to read bounding box of surfel block\n");
    return 0;
  }

  // Read resolution
  if (fread(&resolution, sizeof(RNLength), 1, fp) != (size_t) 1) {
    RNFail("Unable to read resolution of surfel block\n");
    return 0;
  }

  // Read flags
  if (fread(&flags, sizeof(RNFlags), 1, fp) != (size_t) 1) {
    RNFail("Unable to read flags of surfel block\n");
    return 0;
  }

  // Allocate memory for surfels
  surfels = new R3Surfel [ nsurfels ];
  if (!surfels) {
    RNFail("Unable to allocate surfel block\n");
    return 0;
  }

  // Read surfels
  int count = 0;
  while (count < nsurfels) {
    int status = fread(&surfels[count], sizeof(R3Surfel), nsurfels - count, fp);
    if (status <= 0) {
      RNFail("Unable to read surfel block\n");
      delete [] surfels;
      surfels = NULL;
      nsurfels = 0;
      return 0;
    }
    count += status;
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rdi), %r15
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x13790
cmpq $0x1, %rax
jne 0x2f885
leaq 0x28(%rbx), %rdi
movl $0x38, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x13790
cmpq $0x1, %rax
jne 0x2f88e
leaq 0x80(%rbx), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x13790
cmpq $0x1, %rax
jne 0x2f897
leaq 0x88(%rbx), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x13790
cmpq $0x1, %rax
jne 0x2f8a0
movslq (%r15), %rbp
movl $0x30, %ecx
movq %rbp, %rax
mulq %rcx
movq $-0x1, %r12
cmovnoq %rax, %r12
movq %r12, %rdi
callq 0x13030
movq %rax, %r13
testq %rbp, %rbp
je 0x2f8c1
movq %r12, (%rsp)
shlq $0x4, %rbp
leaq (%rbp,%rbp,2), %rbp
xorl %r12d, %r12d
leaq (%r12,%r13), %rdi
callq 0x2b118
addq $0x30, %r12
cmpq %r12, %rbp
jne 0x2f82f
movl 0x8(%rbx), %eax
movq %r13, (%rbx)
movl $0x1, %ebp
testl %eax, %eax
jle 0x2f8b0
xorl %r12d, %r12d
movl %r12d, %ecx
leaq (%rcx,%rcx,2), %rdi
shlq $0x4, %rdi
addq (%rbx), %rdi
subl %r12d, %eax
movslq %eax, %rdx
movl $0x30, %esi
movq %r14, %rcx
callq 0x13790
testl %eax, %eax
jle 0x2f8cb
addl %eax, %r12d
movl (%r15), %eax
cmpl %eax, %r12d
jl 0x2f853
jmp 0x2f8b0
leaq 0xae780(%rip), %rdi     # 0xde00c
jmp 0x2f8a7
leaq 0xae799(%rip), %rdi     # 0xde02e
jmp 0x2f8a7
leaq 0xae7bd(%rip), %rdi     # 0xde05b
jmp 0x2f8a7
leaq 0xae7df(%rip), %rdi     # 0xde086
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xac81a
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, (%rbx)
movl $0x1, %ebp
jmp 0x2f8b0
leaq 0xae7da(%rip), %rdi     # 0xde0ac
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xac81a
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2f8e8
callq 0x13680
movq $0x0, (%rbx)
movl $0x0, 0x8(%rbx)
jmp 0x2f8b0
movq %rax, %rbx
movq %r13, %rdi
movq (%rsp), %rsi
callq 0x139b0
movq %rbx, %rdi
callq 0x138b0
nop