// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq (%rdi), %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movq 0x40(%rdi), %rbx
cmpl $-0x1, 0x28(%rbx)
je 0x3fe90
movl 0x2c(%rbx), %edi
leaq 0x68a7d(%rip), %rdx     # 0xa88eb
movl $0x699, %esi            # imm = 0x699
callq 0x3e440
movslq 0x28(%rbx), %rdx
movq %rax, 0x30(%rsp)
movq %rax, (%r13,%rdx)
movl $0x1, 0x1c(%rsp)
jmp 0x3fea1
movq $0x0, 0x30(%rsp)
movl $0x0, 0x1c(%rsp)
cmpl $0x0, 0x10(%rbx)
jle 0x40051
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %r13, 0x50(%rsp)
movq %rbx, 0x48(%rsp)
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movq (%rax,%rbp,8), %rbx
movsbl (%rcx,%rbp), %eax
movl 0x1c(%rsp), %r15d
orl %eax, %r15d
testl %eax, %eax
cmoveq 0x30(%rsp), %r13
cmpl $0x0, 0x14(%rbx)
je 0x3ffdb
movq 0x28(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x18(%rbx), %edx
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x405d2
testl %r15d, %r15d
je 0x3ff2d
movslq 0x20(%rbx), %r12
addq %r13, %r12
movl 0x1c(%rbx), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
callq 0x40590
movl 0x8(%rsp), %r14d
movslq 0x10(%rbx), %rdx
testl %r14d, %r14d
je 0x40029
movq %r13, 0x40(%rsp)
movslq 0xc(%rbx), %rax
leaq 0xa5b21(%rip), %rcx     # 0xe5a70
movslq (%rcx,%rax,4), %r13
testl %r15d, %r15d
je 0x3ff86
movl %r13d, %edi
imull %r14d, %edi
movl $0x6c2, %esi            # imm = 0x6C2
movq %rdx, 0x38(%rsp)
leaq 0x6897b(%rip), %rdx     # 0xa88eb
callq 0x3e440
movq %rax, %r12
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %r12, (%rax,%rcx)
testl %r14d, %r14d
jle 0x40037
movq 0x28(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x8(%rbx), %edx
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x405d2
testl %r15d, %r15d
je 0x3ffd4
movl 0xc(%rbx), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r12, %rdi
callq 0x40590
addq %r13, %r12
decl %r14d
jne 0x3ff8f
jmp 0x40037
movq 0x28(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x8(%rbx), %edx
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x405d2
testl %r15d, %r15d
je 0x40037
movslq 0x10(%rbx), %rax
addq %rax, %r13
movl 0xc(%rbx), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %r13, %rdi
callq 0x40590
movq %r13, %r12
jmp 0x40037
testl %r15d, %r15d
je 0x40037
movq $0x0, (%r13,%rdx)
incq %rbp
movq 0x48(%rsp), %rbx
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
movq 0x50(%rsp), %r13
jl 0x3feba
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq