// File: /workspace/github_cpp_makefile_star2_O2/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 0x41f41
movq %rsi, %r12
movq %rdi, %r15
leaq 0x87500(%rip), %rsi     # 0xc9376
movq %r12, %rdi
callq 0x21a90
testq %rax, %rax
je 0x41f4e
movq %rax, %rbp
leaq 0x1c(%rsp), %rdi
andl $0x0, (%rdi)
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x21e40
cmpq $0x1, %rax
jne 0x41f45
leaq 0x18(%rsp), %rdi
andl $0x0, (%rdi)
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbp, %rcx
callq 0x21e40
cmpq $0x1, %rax
jne 0x41f45
movl 0x1c(%rsp), %ecx
movq (%r15), %rax
movl %ecx, 0xc(%rsp)
cmpl 0x14(%rax), %ecx
jne 0x41f75
movl 0x18(%rsp), %r14d
pushq $0x1
popq %rbx
testl %r14d, %r14d
je 0x41f61
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
leaq 0x8(%r15), %r12
leaq 0x20(%rsp), %r13
movl %r14d, 0x10(%rsp)
subl $0x1, %r14d
jb 0x41f7e
movl $0x80, %edx
movq %r13, %rdi
pushq $0x1
popq %rsi
movq %rbp, %rcx
callq 0x21e40
movl $0x448, %edi            # imm = 0x448
callq 0x218c0
movq %rax, %rbx
movq (%r15), %rsi
movq %rax, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x42ae4
movq %r12, %rdi
movq %rbx, %rsi
callq 0x26aa0
jmp 0x41efe
xorl %ebx, %ebx
jmp 0x41f61
leaq 0x8919d(%rip), %rdi     # 0xcb0e9
jmp 0x41f55
leaq 0x89174(%rip), %rdi     # 0xcb0c9
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x82696
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8918d(%rip), %rdi     # 0xcb109
jmp 0x41f55
xorl %r15d, %r15d
movl 0xc(%rsp), %eax
testl %eax, %eax
cmovlel %r15d, %eax
movl %eax, 0xc(%rsp)
movl 0x10(%rsp), %r14d
pushq $0x1
popq %rbx
cmpl 0xc(%rsp), %r15d
je 0x41fd9
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x41fd4
leaq 0x14(%rsp), %rdi
pushq $0x4
popq %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x21e40
movq (%r12), %rax
movq (%rax,%r13,8), %rdi
cvtss2sd 0x14(%rsp), %xmm0
movl %r15d, %esi
callq 0x44320
incq %r13
jmp 0x41fa1
incl %r15d
jmp 0x41f97
movq %rbp, %rdi
callq 0x218b0
pushq $0x1
popq %rbx
jmp 0x41f61
movq %rax, %r14
movl $0x448, %esi            # imm = 0x448
movq %rbx, %rdi
callq 0x218e0
movq %r14, %rdi
callq 0x220c0
nop