// File: /workspace/github_cpp_makefile_star2_O3/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 $0x4068, %rsp           # imm = 0x4068
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, 0x4c(%rsp)
movq 0x40(%rdi), %r13
cmpl $-0x1, 0x28(%r13)
je 0x3f63e
movl 0x2c(%r13), %edi
leaq 0x692ce(%rip), %rdx     # 0xa88eb
movl $0x61e, %esi            # imm = 0x61E
callq 0x3deec
movslq 0x28(%r13), %rdx
movq %rax, 0x50(%rsp)
movq %rax, (%r14,%rdx)
movl $0x1, 0x2c(%rsp)
jmp 0x3f64f
movq $0x0, 0x50(%rsp)
movl $0x0, 0x2c(%rsp)
movq (%rbx), %rdx
leaq 0x60(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xe730
testq %rax, %rax
je 0x3f8b9
leaq 0x60(%rsp), %rdi
leaq 0x3060(%rsp), %rcx
leaq 0x1060(%rsp), %r8
leaq 0x4c(%rsp), %r9
movl $0x1000, %esi           # imm = 0x1000
movl $0x400, %edx            # imm = 0x400
callq 0x3f07d
cmpl $0x0, 0x10(%r13)
jle 0x3f8a7
xorl %esi, %esi
xorl %ecx, %ecx
xorl %ebp, %ebp
movq %r14, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movl %ecx, %eax
movq 0x18(%r13), %rcx
movq 0x20(%r13), %rdx
movq (%rcx,%rsi,8), %r15
movq %rsi, 0x18(%rsp)
movsbl (%rdx,%rsi), %ecx
movl 0x2c(%rsp), %r12d
orl %ecx, %r12d
testl %ecx, %ecx
movq %r14, %rbx
cmoveq 0x50(%rsp), %rbx
movslq %eax, %rcx
incl %eax
movl %eax, 0x10(%rsp)
cmpl $0x0, 0x14(%r15)
movq 0x1060(%rsp,%rcx,8), %rdi
je 0x3f781
movl 0x18(%r15), %esi
leaq 0xc(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x3ffc8
testl %r12d, %r12d
je 0x3f7cb
movslq 0x20(%r15), %rbp
addq %rbx, %rbp
movl 0x1c(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x14(%rsp), %ecx
movsd 0x20(%rsp), %xmm0
movq %rbp, %rdi
callq 0x4004f
movl 0xc(%rsp), %r13d
movslq 0x10(%r15), %r14
testl %r13d, %r13d
je 0x3f87c
leaq 0xc(%r15), %rax
movq %rax, 0x58(%rsp)
movslq 0xc(%r15), %rax
leaq 0xa6314(%rip), %rcx     # 0xe5a70
movl (%rcx,%rax,4), %edi
movl %edi, 0x40(%rsp)
imull %r13d, %edi
movl $0x657, %esi            # imm = 0x657
leaq 0x69178(%rip), %rdx     # 0xa88eb
callq 0x3deec
movq %rax, %rbp
movq %rax, (%rbx,%r14)
jmp 0x3f7f4
movl 0x8(%r15), %esi
leaq 0xc(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x3ffc8
testl %r12d, %r12d
je 0x3f88e
movslq 0x10(%r15), %rax
addq %rax, %rbx
movl 0xc(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x14(%rsp), %ecx
movsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x4004f
movq %rbx, %rbp
jmp 0x3f88e
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
je 0x3f884
leaq 0xc(%r15), %rax
movq %rax, 0x58(%rsp)
movslq 0xc(%r15), %rax
leaq 0xa6283(%rip), %rcx     # 0xe5a70
movl (%rcx,%rax,4), %eax
movl %eax, 0x40(%rsp)
testl %r13d, %r13d
movl 0x10(%rsp), %ecx
jle 0x3f86b
movslq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movslq %ecx, %rax
leaq (%rsp,%rax,8), %r14
addq $0x1060, %r14           # imm = 0x1060
movl %r13d, %r13d
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movl 0x8(%r15), %esi
leaq 0xc(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x3ffc8
testl %r12d, %r12d
je 0x3f85d
movq 0x58(%rsp), %rax
movl (%rax), %esi
movl 0xc(%rsp), %edx
movl 0x14(%rsp), %ecx
movsd 0x20(%rsp), %xmm0
movq %rbp, %rdi
callq 0x4004f
addq 0x40(%rsp), %rbp
incq %rbx
cmpl %ebx, %r13d
jne 0x3f81a
movl 0x10(%rsp), %ecx
addl %ebx, %ecx
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %r13
movq 0x18(%rsp), %rsi
jmp 0x3f897
movq $0x0, (%rbx,%r14)
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %r13
movq 0x18(%rsp), %rsi
movl 0x10(%rsp), %ecx
incq %rsi
movslq 0x10(%r13), %rax
cmpq %rax, %rsi
jl 0x3f6ae
addq $0x4068, %rsp           # imm = 0x4068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xec46