// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: ascii_get_element(PlyFile*, char*)
void ascii_get_element(PlyFile *plyfile, char *elem_ptr)
{
  int j,k;
  PlyElement *elem;
  PlyProperty *prop;
  const int max_line_size = 4096;
  char orig_line[max_line_size];
  const int max_words = 1024;
  char *words[max_words];
  char word_buffer[max_line_size];
  int nwords = 0;
  int which_word;
  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 the element */

  /* read in the elemnt */
  if (!fgets (orig_line, max_line_size, plyfile->fp)) {
    fprintf(stderr, "ply_get_element: unexpected end of file\n");
    exit (-1);
  }

  /* break line into words */
  if (!get_words(orig_line, max_line_size, max_words, word_buffer, words, &nwords)) {
    fprintf(stderr, "ply_get_element: unexpected format\n");
    exit (-1);
  }

  which_word = 0;

  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_ascii_item (words[which_word++], 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_ascii_item (words[which_word++], 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_ascii_item (words[which_word++], 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 $0x4058, %rsp           # imm = 0x4058
movq %rsi, %r12
andl $0x0, 0x34(%rsp)
movq %rdi, %rbx
movq 0x40(%rdi), %r13
cmpl $-0x1, 0x28(%r13)
je 0x3a59f
movl 0x2c(%r13), %edi
leaq 0x5f31c(%rip), %rdx     # 0x9989b
movl $0x61e, %esi            # imm = 0x61E
callq 0x38f69
movslq 0x28(%r13), %rdx
movq %rax, 0x38(%rsp)
movq %rax, (%r12,%rdx)
pushq $0x1
popq %rax
movl %eax, 0x1c(%rsp)
jmp 0x3a5b0
movq $0x0, 0x38(%rsp)
movl $0x0, 0x1c(%rsp)
movq (%rbx), %rdx
leaq 0x50(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xe760
testq %rax, %rax
je 0x3a7d2
leaq 0x50(%rsp), %rdi
leaq 0x3050(%rsp), %rcx
leaq 0x1050(%rsp), %r8
leaq 0x34(%rsp), %r9
movl $0x1000, %esi           # imm = 0x1000
movl $0x400, %edx            # imm = 0x400
callq 0x3a003
xorl %esi, %esi
xorl %ebp, %ebp
xorl %eax, %eax
movq %r12, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movslq 0x10(%r13), %rcx
cmpq %rcx, %rsi
jge 0x3a7c0
movq 0x18(%r13), %rcx
movq 0x20(%r13), %rdx
movq (%rcx,%rsi,8), %r14
movq %rsi, 0x40(%rsp)
movsbl (%rdx,%rsi), %ecx
movl 0x1c(%rsp), %r15d
orl %ecx, %r15d
testl %ecx, %ecx
movq %r12, %rbx
cmoveq 0x38(%rsp), %rbx
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%rsp)
cmpl $0x0, 0x14(%r14)
cltq
movq 0x1050(%rsp,%rax,8), %rdi
je 0x3a758
movl 0x18(%r14), %esi
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3af20
testl %r15d, %r15d
je 0x3a693
movslq 0x20(%r14), %rbp
addq %rbx, %rbp
movl 0x1c(%r14), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
callq 0x3afc0
movl 0x8(%rsp), %r12d
movslq 0x10(%r14), %r13
testl %r12d, %r12d
je 0x3a79b
movslq 0xc(%r14), %rax
leaq 0xa03d0(%rip), %rcx     # 0xdaa80
movslq (%rcx,%rax,4), %rax
testl %r15d, %r15d
movq %rax, 0x48(%rsp)
je 0x3a6dc
movl %eax, %edi
imull %r12d, %edi
movl $0x657, %esi            # imm = 0x657
leaq 0x5f1cb(%rip), %rdx     # 0x9989b
callq 0x38f69
movq %rax, %rbp
movq %rax, (%rbx,%r13)
movslq 0x4(%rsp), %rax
testl %r12d, %r12d
movl $0x0, %ecx
cmovlel %ecx, %r12d
leaq (%rsp,%rax,8), %rbx
addq $0x1050, %rbx           # imm = 0x1050
xorl %r13d, %r13d
cmpl %r13d, %r12d
je 0x3a745
movq (%rbx,%r13,8), %rdi
movl 0x8(%r14), %esi
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3af20
testl %r15d, %r15d
je 0x3a740
movl 0xc(%r14), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
callq 0x3afc0
addq 0x48(%rsp), %rbp
incq %r13
jmp 0x3a6fb
movl 0x4(%rsp), %eax
addl %r13d, %eax
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r13
jmp 0x3a7b3
movl 0x8(%r14), %esi
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3af20
testl %r15d, %r15d
je 0x3a7af
movslq 0x10(%r14), %rax
addq %rax, %rbx
movl 0xc(%r14), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x3afc0
movq %rbx, %rbp
jmp 0x3a7af
testl %r15d, %r15d
je 0x3a7a5
andq $0x0, (%rbx,%r13)
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r13
movl 0x4(%rsp), %eax
movq 0x40(%rsp), %rsi
incq %rsi
jmp 0x3a604
addq $0x4058, %rsp           # imm = 0x4058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9f7e7(%rip), %rax     # 0xd9fc0
movq (%rax), %rcx
leaq 0x5f48b(%rip), %rdi     # 0x99c6e
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0xe8e0
pushq $-0x1
popq %rdi
callq 0xe570