// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movl $0x0, 0x3c(%rsp)
movq 0x40(%rdi), %r13
cmpl $-0x1, 0x28(%r13)
je 0x3fbe6
movl 0x2c(%r13), %edi
leaq 0x68d26(%rip), %rdx     # 0xa88eb
movl $0x61e, %esi            # imm = 0x61E
callq 0x3e440
movslq 0x28(%r13), %rdx
movq %rax, 0x40(%rsp)
movq %rax, (%r14,%rdx)
movl $0x1, 0x24(%rsp)
jmp 0x3fbf7
movq $0x0, 0x40(%rsp)
movl $0x0, 0x24(%rsp)
movq (%rbx), %rdx
leaq 0x50(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xe730
testq %rax, %rax
je 0x3fe37
leaq 0x50(%rsp), %rdi
leaq 0x3050(%rsp), %rcx
leaq 0x1050(%rsp), %r8
leaq 0x3c(%rsp), %r9
movl $0x1000, %esi           # imm = 0x1000
movl $0x400, %edx            # imm = 0x400
callq 0x3f60a
cmpl $0x0, 0x10(%r13)
jle 0x3fe25
xorl %esi, %esi
xorl %ecx, %ecx
xorl %ebp, %ebp
movq %r14, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movl %ecx, %eax
movq 0x18(%r13), %rcx
movq 0x20(%r13), %rdx
movq (%rcx,%rsi,8), %r15
movq %rsi, 0x10(%rsp)
movsbl (%rdx,%rsi), %ecx
movl 0x24(%rsp), %r12d
orl %ecx, %r12d
testl %ecx, %ecx
movq %r14, %rbx
cmoveq 0x40(%rsp), %rbx
movslq %eax, %rcx
incl %eax
movl %eax, 0x4(%rsp)
cmpl $0x0, 0x14(%r15)
movq 0x1050(%rsp,%rcx,8), %rdi
je 0x3fd9d
movl 0x18(%r15), %esi
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x40509
testl %r12d, %r12d
je 0x3fcda
movslq 0x20(%r15), %rbp
addq %rbx, %rbp
movl 0x1c(%r15), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x18(%rsp), %xmm0
movq %rbp, %rdi
callq 0x40590
movl 0x8(%rsp), %r13d
movslq 0x10(%r15), %r14
testq %r13, %r13
je 0x3fde0
movslq 0xc(%r15), %rax
leaq 0xa5d79(%rip), %rcx     # 0xe5a70
movslq (%rcx,%rax,4), %rax
testl %r12d, %r12d
movq %rax, 0x48(%rsp)
je 0x3fd23
movl %eax, %edi
imull %r13d, %edi
movl $0x657, %esi            # imm = 0x657
leaq 0x68bd4(%rip), %rdx     # 0xa88eb
callq 0x3e440
movq %rax, %rbp
movq %rax, (%rbx,%r14)
testl %r13d, %r13d
jle 0x3fe02
movslq 0x4(%rsp), %rax
leaq (%rsp,%rax,8), %r14
addq $0x1050, %r14           # imm = 0x1050
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movl 0x8(%r15), %esi
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x40509
testl %r12d, %r12d
je 0x3fd7e
movl 0xc(%r15), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x18(%rsp), %xmm0
movq %rbp, %rdi
callq 0x40590
addq 0x48(%rsp), %rbp
incq %rbx
cmpl %ebx, %r13d
jne 0x3fd3e
movl 0x4(%rsp), %ecx
addl %ebx, %ecx
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %rsi
jmp 0x3fe15
movl 0x8(%r15), %esi
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x40509
testl %r12d, %r12d
je 0x3fe0c
movslq 0x10(%r15), %rax
addq %rax, %rbx
movl 0xc(%r15), %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x40590
movq %rbx, %rbp
jmp 0x3fe0c
testl %r12d, %r12d
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %rsi
movl 0x4(%rsp), %ecx
je 0x3fdfb
movq $0x0, (%rbx,%r14)
movq 0x28(%rsp), %r14
jmp 0x3fe15
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %rsi
movl 0x4(%rsp), %ecx
incq %rsi
movslq 0x10(%r13), %rax
cmpq %rax, %rsi
jl 0x3fc56
addq $0x4058, %rsp           # imm = 0x4058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xec64