// File: /workspace/github_cpp_makefile_star2_O1/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 0x47bc5
movq %rsi, %r12
movq %rdi, %r14
leaq 0x998fd(%rip), %rsi     # 0xe1379
movq %r12, %rdi
callq 0x21aa0
testq %rax, %rax
je 0x47bd2
movq %rax, %r15
leaq 0x14(%rsp), %rdi
movl $0x0, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x21e30
cmpq $0x1, %rax
jne 0x47bc9
leaq 0x10(%rsp), %rdi
movl $0x0, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x21e30
cmpq $0x1, %rax
jne 0x47bc9
movl 0x14(%rsp), %ecx
movq (%r14), %rax
movl %ecx, 0x8(%rsp)
cmpl 0x14(%rax), %ecx
jne 0x47bf9
movl 0x10(%rsp), %ebx
movl $0x1, %ebp
testq %rbx, %rbx
je 0x47be5
testl %ebx, %ebx
jle 0x47b61
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 0x21e30
movl $0x448, %edi            # imm = 0x448
callq 0x218b0
movq %rax, %rbp
movq (%r14), %rsi
movq %rax, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x487c8
movl 0x14(%r14), %edx
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x8cf92
decl %r13d
jne 0x47b14
cmpl $0x0, 0x8(%rsp)
jle 0x47bb6
xorl %r12d, %r12d
leaq 0xc(%rsp), %r13
testl %ebx, %ebx
jle 0x47bac
xorl %ebp, %ebp
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x21e30
movq 0x8(%r14), %rax
movq (%rax,%rbp,8), %rdi
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rsp), %xmm0
movl %r12d, %esi
callq 0x4a20c
incq %rbp
cmpq %rbp, %rbx
jne 0x47b76
incl %r12d
cmpl 0x8(%rsp), %r12d
jne 0x47b70
movq %r15, %rdi
callq 0x218a0
movl $0x1, %ebp
jmp 0x47be5
xorl %ebp, %ebp
jmp 0x47be5
leaq 0x9b551(%rip), %rdi     # 0xe3121
jmp 0x47bd9
leaq 0x9b528(%rip), %rdi     # 0xe3101
xorl %ebp, %ebp
movq %r12, %rsi
xorl %eax, %eax
callq 0x8fd7a
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9b541(%rip), %rdi     # 0xe3141
jmp 0x47bd9
movq %rax, %rbx
movl $0x448, %esi            # imm = 0x448
movq %rbp, %rdi
callq 0x218d0
movq %rbx, %rdi
callq 0x220b0