// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movq (%rdi), %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x40(%rdi), %r14
cmpl $-0x1, 0x28(%r14)
je 0x3f914
movl 0x2c(%r14), %edi
leaq 0x68ff9(%rip), %rdx     # 0xa88eb
movl $0x699, %esi            # imm = 0x699
callq 0x3deec
movslq 0x28(%r14), %rdx
movq %rax, 0x28(%rsp)
movq %rax, (%rbp,%rdx)
movl $0x1, 0x1c(%rsp)
jmp 0x3f925
movq $0x0, 0x28(%rsp)
movl $0x0, 0x1c(%rsp)
cmpl $0x0, 0x10(%r14)
jle 0x3faf8
xorl %edx, %edx
xorl %r12d, %r12d
movq %rbp, 0x48(%rsp)
movq %r14, 0x40(%rsp)
movq 0x18(%r14), %rax
movq 0x20(%r14), %rcx
movsbl (%rcx,%rdx), %ecx
movl 0x1c(%rsp), %r14d
orl %ecx, %r14d
testl %ecx, %ecx
cmoveq 0x28(%rsp), %rbp
movq %rdx, 0x50(%rsp)
movq (%rax,%rdx,8), %r15
cmpl $0x0, 0x14(%r15)
movq 0x30(%rsp), %rax
movl 0x8(%rax), %esi
je 0x3fa0e
movl 0x18(%r15), %edx
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x40091
testl %r14d, %r14d
je 0x3fa5a
movslq 0x20(%r15), %r12
addq %rbp, %r12
movl 0x1c(%r15), %esi
movl 0x8(%rsp), %r13d
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
movl %r13d, %edx
callq 0x4004f
movslq 0x10(%r15), %rax
testl %r13d, %r13d
je 0x3fad0
leaq 0xc(%r15), %rbx
movq %rax, 0x38(%rsp)
movslq 0xc(%r15), %rax
leaq 0xa608d(%rip), %rcx     # 0xe5a70
movl (%rcx,%rax,4), %edi
movl %edi, 0x18(%rsp)
imull %r13d, %edi
movl $0x6c2, %esi            # imm = 0x6C2
leaq 0x68ef1(%rip), %rdx     # 0xa88eb
callq 0x3deec
movq %rax, %r12
movq 0x38(%rsp), %rax
movq %r12, (%rbp,%rax)
jmp 0x3fa7a
movl 0x8(%r15), %edx
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x40091
testl %r14d, %r14d
je 0x3fad9
movslq 0x10(%r15), %rax
addq %rax, %rbp
movl 0xc(%r15), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
callq 0x4004f
movq %rbp, %r12
jmp 0x3fad9
movl 0x8(%rsp), %r13d
testl %r13d, %r13d
je 0x3fad9
leaq 0xc(%r15), %rbx
movslq 0xc(%r15), %rax
leaq 0xa5ffd(%rip), %rcx     # 0xe5a70
movl (%rcx,%rax,4), %eax
movl %eax, 0x18(%rsp)
testl %r13d, %r13d
jle 0x3fad9
movslq 0x18(%rsp), %rbp
movq 0x30(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x8(%r15), %edx
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x40091
testl %r14d, %r14d
je 0x3fac9
movl (%rbx), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
callq 0x4004f
addq %rbp, %r12
decl %r13d
jne 0x3fa84
jmp 0x3fad9
movq $0x0, (%rbp,%rax)
movq 0x50(%rsp), %rdx
incq %rdx
movq 0x40(%rsp), %r14
movslq 0x10(%r14), %rax
cmpq %rax, %rdx
movq 0x48(%rsp), %rbp
jl 0x3f93f
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq