// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3MeshPropertySet.cpp
// Function: gaps::R3MeshPropertySet::ReadBinary(char const*)
int R3MeshPropertySet::
ReadBinary(const char *filename)
{
  // Just checking
  if (!mesh) return 0;
  
  // Open file
  FILE *fp = fopen(filename, "rb");
  if (!fp) {
    RNFail("Unable to open binary file: %s\n", filename);
    return 0;
  }

  // Read number of vertices
  int vertex_count = 0;
  if (fread(&vertex_count, sizeof(int), 1, fp) != (unsigned int) 1) {
    RNFail("Unable to read binary file: %s\n", filename);
    return 0;
  }

  // Read number of properties
  int property_count = 0;
  if (fread(&property_count, sizeof(int), 1, fp) != (unsigned int) 1) {
    RNFail("Unable to read binary file: %s\n", filename);
    return 0;
  }
  
  // Check number of vertices
  if (vertex_count != mesh->NVertices()) {
    RNFail("Mismatching number of vertices in %s\n", filename);
    return 0;
  }
  
  // Check number of properties
  if (property_count == 0) return 1;


  // Read property names and create properties
  char property_name[128];
  for (int j = 0; j < property_count; j++) {
    fread(property_name, sizeof(char), 128, fp);
    R3MeshProperty *property = new R3MeshProperty(mesh, property_name);
    Insert(property);
  }

  // Read data and assign property values
  RNScalar32 value;
  for (int i = 0; i < vertex_count; i++) {
    for (int j = 0; j < property_count; j++) {
      fread(&value, sizeof(RNScalar32), 1, fp);
      Property(j)->SetVertexValue(i, value);
    }
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
cmpq $0x0, (%rdi)
je 0x47585
movq %rsi, %r12
movq %rdi, %r14
leaq 0x97f3a(%rip), %rsi     # 0xdf376
movq %r12, %rdi
callq 0x21a90
testq %rax, %rax
je 0x47592
movq %rax, %r15
leaq 0x14(%rsp), %rdi
movl $0x0, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x21e20
cmpq $0x1, %rax
jne 0x47589
leaq 0x10(%rsp), %rdi
movl $0x0, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x21e20
cmpq $0x1, %rax
jne 0x47589
movl 0x14(%rsp), %ecx
movq (%r14), %rax
movl %ecx, 0x8(%rsp)
cmpl 0x14(%rax), %ecx
jne 0x475b9
movl 0x10(%rsp), %ebx
movl $0x1, %ebp
testq %rbx, %rbx
je 0x475a5
testl %ebx, %ebx
jle 0x47521
leaq 0x8(%r14), %rax
movq %rax, 0x18(%rsp)
movl %ebx, %r13d
movl $0x1, %esi
movl $0x80, %edx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rcx
callq 0x21e20
movl $0x448, %edi            # imm = 0x448
callq 0x218b0
movq %rax, %rbp
movq (%r14), %rsi
movq %rax, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x48134
movl 0x14(%r14), %edx
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x8bdb2
decl %r13d
jne 0x474d4
cmpl $0x0, 0x8(%rsp)
jle 0x47576
xorl %r12d, %r12d
leaq 0xc(%rsp), %r13
testl %ebx, %ebx
jle 0x4756c
xorl %ebp, %ebp
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x21e20
movq 0x8(%r14), %rax
movq (%rax,%rbp,8), %rdi
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rsp), %xmm0
movl %r12d, %esi
callq 0x49b8e
incq %rbp
cmpq %rbp, %rbx
jne 0x47536
incl %r12d
cmpl 0x8(%rsp), %r12d
jne 0x47530
movq %r15, %rdi
callq 0x218a0
movl $0x1, %ebp
jmp 0x475a5
xorl %ebp, %ebp
jmp 0x475a5
leaq 0x99b81(%rip), %rdi     # 0xe1111
jmp 0x47599
leaq 0x99b58(%rip), %rdi     # 0xe10f1
xorl %ebp, %ebp
movq %r12, %rsi
xorl %eax, %eax
callq 0x8e88e
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x99b71(%rip), %rdi     # 0xe1131
jmp 0x47599
movq %rax, %rbx
movl $0x448, %esi            # imm = 0x448
movq %rbp, %rdi
callq 0x218d0
movq %rbx, %rdi
callq 0x220a0