// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: binary_get_element(PlyFile*, char*)
void binary_get_element(PlyFile *plyfile, char *elem_ptr)
{
  int j,k;
  PlyElement *elem;
  PlyProperty *prop;
  FILE *fp = plyfile->fp;
  char *elem_data,*item=NULL;
  char *item_ptr;
  int item_size;
  int int_val;
  unsigned int uint_val;
  double double_val;
  int list_count;
  int store_it;
  char **store_array;
  char *other_data=NULL;
  int other_flag;

  /* the kind of element we're reading currently */
  elem = plyfile->which_elem;

  /* do we need to setup for other_props? */

  if (elem->other_offset != NO_OTHER_PROPS) {
    char **ptr;
    other_flag = 1;
    /* make room for other_props */
    other_data = (char *) myalloc (elem->other_size);
    /* store pointer in user's structure to the other_props */
    ptr = (char **) (elem_ptr + elem->other_offset);
    *ptr = other_data;
  }
  else
    other_flag = 0;

  /* read in a number of elements */

  for (j = 0; j < elem->nprops; j++) {

    prop = elem->props[j];
    store_it = (elem->store_prop[j] | other_flag);

    /* store either in the user's structure or in other_props */
    if (elem->store_prop[j])
      elem_data = elem_ptr;
    else
      elem_data = other_data;

    if (prop->is_list) {       /* a list */

      /* get and store the number of items in the list */
      get_binary_item (fp, plyfile->file_type, prop->count_external,
                      &int_val, &uint_val, &double_val);
      if (store_it) {
        item = elem_data + prop->count_offset;
        store_item(item, prop->count_internal, int_val, uint_val, double_val);
      }

      /* allocate space for an array of items and store a ptr to the array */
      list_count = int_val;
      item_size = ply_type_size[prop->internal_type];
      store_array = (char **) (elem_data + prop->offset);
      if (list_count == 0) {
        if (store_it)
          *store_array = NULL;
      }
      else {
        if (store_it) {
          item_ptr = (char *) myalloc (sizeof (char) * item_size * list_count);
          item = item_ptr;
          *store_array = item_ptr;
        }

        /* read items and store them into the array */
        for (k = 0; k < list_count; k++) {
          get_binary_item (fp, plyfile->file_type, prop->external_type,
                          &int_val, &uint_val, &double_val);
          if (store_it) {
            store_item (item, prop->internal_type,
                        int_val, uint_val, double_val);
            item += item_size;
          }
        }
      }

    }
    else {                     /* not a list */
      get_binary_item (fp, plyfile->file_type, prop->external_type,
                      &int_val, &uint_val, &double_val);
      if (store_it) {
        item = elem_data + prop->offset;
        store_item (item, prop->internal_type, int_val, uint_val, double_val);
      }
    }

  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %rax
movq %rax, 0x30(%rsp)
movq 0x40(%rdi), %rbp
cmpl $-0x1, 0x28(%rbp)
je 0x3a846
movl 0x2c(%rbp), %edi
leaq 0x5f075(%rip), %rdx     # 0x9989b
movl $0x699, %esi            # imm = 0x699
callq 0x38f69
movslq 0x28(%rbp), %rdx
movq %rax, 0x38(%rsp)
movq %rax, (%r15,%rdx)
pushq $0x1
popq %rax
movl %eax, 0x1c(%rsp)
jmp 0x3a857
movq $0x0, 0x38(%rsp)
movl $0x0, 0x1c(%rsp)
xorl %edx, %edx
xorl %r12d, %r12d
movq %r15, 0x40(%rsp)
movq %rbp, 0x28(%rsp)
movslq 0x10(%rbp), %rax
cmpq %rax, %rdx
jge 0x3aa02
movq 0x18(%rbp), %rax
movq 0x20(%rbp), %rcx
movsbl (%rcx,%rdx), %ecx
movl 0x1c(%rsp), %r13d
orl %ecx, %r13d
testl %ecx, %ecx
movq %r15, %rcx
cmoveq 0x38(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq %rdx, 0x50(%rsp)
movq (%rax,%rdx,8), %rbx
cmpl $0x0, 0x14(%rbx)
movl 0x8(%r14), %esi
je 0x3a999
movl 0x18(%rbx), %edx
movq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x3b01f
movl 0xc(%rsp), %ebp
testl %r13d, %r13d
je 0x3a8f3
movslq 0x20(%rbx), %r12
addq 0x20(%rsp), %r12
movl 0x1c(%rbx), %esi
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
movl %ebp, %edx
callq 0x3afc0
movslq 0x10(%rbx), %rdx
testl %ebp, %ebp
je 0x3a9e1
movslq 0xc(%rbx), %rax
leaq 0xa0176(%rip), %rcx     # 0xdaa80
movslq (%rcx,%rax,4), %r15
testl %r13d, %r13d
je 0x3a940
movl %r15d, %edi
imull %ebp, %edi
movl $0x6c2, %esi            # imm = 0x6C2
movq %rdx, 0x48(%rsp)
leaq 0x5ef71(%rip), %rdx     # 0x9989b
callq 0x38f69
movq %rax, %r12
movq 0x20(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %r12, (%rax,%rcx)
testl %ebp, %ebp
movl $0x0, %eax
cmovlel %eax, %ebp
subl $0x1, %ebp
jb 0x3a992
movl 0x8(%r14), %esi
movl 0x8(%rbx), %edx
movq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x3b01f
testl %r13d, %r13d
je 0x3a94a
movl 0xc(%rbx), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
callq 0x3afc0
addq %r15, %r12
jmp 0x3a94a
movq 0x40(%rsp), %r15
jmp 0x3a9f0
movl 0x8(%rbx), %edx
movq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x3b01f
testl %r13d, %r13d
je 0x3a9f5
movslq 0x10(%rbx), %rax
movq 0x20(%rsp), %r12
addq %rax, %r12
movl 0xc(%rbx), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
callq 0x3afc0
jmp 0x3a9f5
testl %r13d, %r13d
je 0x3a9f0
movq 0x20(%rsp), %rax
andq $0x0, (%rax,%rdx)
movq 0x28(%rsp), %rbp
movq 0x50(%rsp), %rdx
incq %rdx
jmp 0x3a866
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq