// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: ply_read
PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names)
{
  int i,j;
  PlyFile *plyfile;
  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;
  char **elist;
  PlyElement *elem;

  /* check for NULL file pointer */
  if (fp == NULL)
    return (NULL);

  if (native_binary_type == -1)
     get_native_binary_type();
  if (!types_checked)
     check_types();
  
  /* create record for this object */

  plyfile = (PlyFile *) myalloc (sizeof (PlyFile));
  plyfile->nelems = 0;
  plyfile->comments = NULL;
  plyfile->num_comments = 0;
  plyfile->obj_info = NULL;
  plyfile->num_obj_info = 0;
  plyfile->fp = fp;
  plyfile->other_elems = NULL;

  /* read and parse the file's header */

  /* read in a line */
  if (!fgets (orig_line, max_line_size, plyfile->fp)) {
    fprintf(stderr, "Unable to read header from ply file\n");
    return (NULL);
  }

  /* break line into words */
  if (!get_words(orig_line, max_line_size, max_words, word_buffer, words, &nwords)) {
    fprintf(stderr, "Unable to parse first line from ply file\n");
    return (NULL);
  }

  // Check for ply keyword
  if (!equal_strings (words[0], "ply")) {
    fprintf(stderr, "No ply keyword at beginning of ply file\n");
    return (NULL);
  }

  // Parse rest of header
  while (true) {
    /* read in a line */
    if (!fgets (orig_line, max_line_size, plyfile->fp)) {
      fprintf(stderr, "Unable to read line from header of ply file\n");
      return (NULL);
    }

    /* break line into words */
    if (!get_words(orig_line, max_line_size, max_words, word_buffer, words, &nwords)) {
      fprintf(stderr, "Unable to parse words of line in header of ply file\n");
      return (NULL);
    }

    /* parse words */
    if (equal_strings (words[0], "format")) {
      if (nwords != 3) {
	return (NULL);
      }
      if (equal_strings (words[1], "ascii"))
        plyfile->file_type = PLY_ASCII;
      else if (equal_strings (words[1], "binary_big_endian"))
        plyfile->file_type = PLY_BINARY_BE;
      else if (equal_strings (words[1], "binary_little_endian"))
        plyfile->file_type = PLY_BINARY_LE;
      else {
        fprintf(stderr, "Unrecognized format (%s) in ply file\n", words[1]);
        return (NULL);
      }
      plyfile->version = atof (words[2]);
    }
    else if (equal_strings (words[0], "element"))
      add_element (plyfile, words);
    else if (equal_strings (words[0], "property"))
      add_property (plyfile, words);
    else if (equal_strings (words[0], "comment"))
      add_comment (plyfile, orig_line);
    else if (equal_strings (words[0], "obj_info"))
      add_obj_info (plyfile, orig_line);
    else if (equal_strings (words[0], "end_header")) {
      break;
    }
  }

  /* create tags for each property of each element, to be used */
  /* later to say whether or not to store each property for the user */

  for (i = 0; i < plyfile->nelems; i++) {
    elem = plyfile->elems[i];
    elem->store_prop = (char *) myalloc (sizeof (char) * elem->nprops);
    for (j = 0; j < elem->nprops; j++)
      elem->store_prop[j] = DONT_STORE_PROP;
    elem->other_offset = NO_OTHER_PROPS; /* no "other" props by default */
  }

  /* set return values about the elements */

  elist = (char **) myalloc (sizeof (char *) * plyfile->nelems);
  for (i = 0; i < plyfile->nelems; i++)
    elist[i] = my_strdup (plyfile->elems[i]->name);

  *elem_names = elist;
  *nelems = plyfile->nelems;

  /* return a pointer to the file's information */

  return (plyfile);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4028, %rsp           # imm = 0x4028
movl $0x0, 0x4(%rsp)
testq %rdi, %rdi
je 0x3f038
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
cmpb $0x0, 0x4a7fa3(%rip)    # 0x4e6b68
jne 0x3ebce
movb $0x1, 0x4a7f9a(%rip)    # 0x4e6b68
cmpb $0x0, 0x4a7f97(%rip)    # 0x4e6b6c
jne 0x3ebdc
callq 0x3deb2
leaq 0x69d08(%rip), %rdx     # 0xa88eb
movl $0x50, %edi
movl $0x2e6, %esi            # imm = 0x2E6
callq 0x3deec
movq %rax, %rbx
xorl %eax, %eax
movl %eax, 0x10(%rbx)
movq %rax, 0x28(%rbx)
movl %eax, 0x20(%rbx)
movq %rax, 0x38(%rbx)
movl %eax, 0x30(%rbx)
movq %r14, (%rbx)
movq %rax, 0x48(%rbx)
leaq 0x20(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0xe730
testq %rax, %rax
je 0x3f033
leaq 0x20(%rsp), %rdi
leaq 0x3020(%rsp), %rcx
leaq 0x1020(%rsp), %r12
leaq 0x4(%rsp), %r9
movl $0x1000, %esi           # imm = 0x1000
movl $0x400, %edx            # imm = 0x400
movq %r12, %r8
callq 0x3f07d
xorl %eax, %eax
movq (%r12), %rcx
leaq 0x6370a(%rip), %rdx     # 0xa236d
movb (%rcx,%rax), %sil
movb (%rax,%rdx), %dil
testb %sil, %sil
je 0x3ec82
testb %dil, %dil
je 0x3ec82
incq %rax
cmpb %dil, %sil
je 0x3ec63
jmp 0x3f02c
cmpb %dil, %sil
jne 0x3f02c
movq %r13, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0xe730
testq %rax, %rax
je 0x3ef58
leaq 0x20(%rsp), %rbp
leaq 0x3020(%rsp), %r13
leaq 0x1020(%rsp), %r14
leaq 0x4(%rsp), %rbx
leaq 0x69e54(%rip), %r15     # 0xa8b2a
leaq 0x69ea7(%rip), %r12     # 0xa8b84
movq %rbp, %rdi
movl $0x1000, %esi           # imm = 0x1000
movl $0x400, %edx            # imm = 0x400
movq %r13, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x3f07d
movq 0x1020(%rsp), %rax
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb (%rcx,%r15), %sil
testb %dl, %dl
je 0x3ed1c
testb %sil, %sil
je 0x3ed1c
incq %rcx
cmpb %sil, %dl
je 0x3ed02
jmp 0x3ed70
cmpb %sil, %dl
jne 0x3ed70
cmpl $0x3, 0x4(%rsp)
jne 0x3f038
movq 0x1028(%rsp), %rdx
xorl %eax, %eax
leaq 0x69df4(%rip), %rdi     # 0xa8b31
leaq 0x69df3(%rip), %r8      # 0xa8b37
leaq 0x69dfe(%rip), %r9      # 0xa8b49
movb (%rdx,%rax), %cl
movb (%rax,%rdi), %sil
testb %cl, %cl
je 0x3ee89
testb %sil, %sil
je 0x3ee89
incq %rax
cmpb %sil, %cl
je 0x3ed4b
jmp 0x3ee93
xorl %ecx, %ecx
leaq 0x69e13(%rip), %rdi     # 0xa8b8c
leaq 0x69e15(%rip), %r8      # 0xa8b95
movb (%rax,%rcx), %dl
movb (%rcx,%r12), %sil
testb %dl, %dl
je 0x3ed9a
testb %sil, %sil
je 0x3ed9a
incq %rcx
cmpb %sil, %dl
je 0x3ed80
jmp 0x3edb1
cmpb %sil, %dl
jne 0x3edb1
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3f143
jmp 0x3ef3a
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb (%rcx,%rdi), %sil
testb %dl, %dl
je 0x3edcd
testb %sil, %sil
je 0x3edcd
incq %rcx
cmpb %sil, %dl
je 0x3edb3
jmp 0x3ede4
cmpb %sil, %dl
jne 0x3ede4
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3f1d2
jmp 0x3ef3a
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb (%rcx,%r8), %dil
testb %dl, %dl
je 0x3ee00
testb %dil, %dil
je 0x3ee00
incq %rcx
cmpb %dil, %dl
je 0x3ede6
jmp 0x3ee20
leaq 0x27(%rsp), %rsi
cmpb %dil, %dl
jne 0x3ee20
movzbl (%rsi), %eax
cmpl $0x20, %eax
je 0x3ee1b
cmpl $0x9, %eax
jne 0x3eebd
incq %rsi
jmp 0x3ee0a
xorl %ecx, %ecx
leaq 0x69d74(%rip), %rsi     # 0xa8b9d
movb (%rax,%rcx), %dl
movb (%rcx,%rsi), %dil
testb %dl, %dl
je 0x3ee43
testb %dil, %dil
je 0x3ee43
incq %rcx
cmpb %dil, %dl
je 0x3ee29
jmp 0x3ee63
leaq 0x28(%rsp), %rsi
cmpb %dil, %dl
jne 0x3ee63
movzbl (%rsi), %eax
cmpl $0x20, %eax
je 0x3ee5e
cmpl $0x9, %eax
jne 0x3ef30
incq %rsi
jmp 0x3ee4d
xorl %ecx, %ecx
leaq 0x69d3a(%rip), %rdi     # 0xa8ba6
movb (%rax,%rcx), %dl
movb (%rcx,%rdi), %sil
testb %dl, %dl
je 0x3eeaf
testb %sil, %sil
je 0x3eeaf
incq %rcx
cmpb %sil, %dl
je 0x3ee6c
jmp 0x3ef3a
movl $0x1, %eax
cmpb %sil, %cl
je 0x3eef9
xorl %eax, %eax
movb (%rdx,%rax), %cl
movb (%rax,%r8), %sil
testb %cl, %cl
je 0x3eec9
testb %sil, %sil
je 0x3eec9
incq %rax
cmpb %sil, %cl
je 0x3ee95
jmp 0x3eed3
cmpb %sil, %dl
jne 0x3ef3a
jmp 0x3ef81
movq 0x8(%rsp), %rdi
callq 0x3eacf
jmp 0x3ef3a
movl $0x2, %eax
cmpb %sil, %cl
je 0x3eef9
xorl %eax, %eax
movb (%rdx,%rax), %cl
movb (%rax,%r9), %sil
testb %cl, %cl
je 0x3eeef
testb %sil, %sil
je 0x3eeef
incq %rax
cmpb %sil, %cl
je 0x3eed5
jmp 0x3ef62
movl $0x3, %eax
cmpb %sil, %cl
jne 0x3ef62
movq %r14, %rbx
movq %r13, %r14
movq %rbp, %r13
movq 0x8(%rsp), %rbp
movl %eax, 0x8(%rbp)
movq 0x1030(%rsp), %rdi
callq 0xe580
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rbp)
movq %r13, %rbp
movq %r14, %r13
movq %rbx, %r14
leaq 0x4(%rsp), %rbx
jmp 0x3ef3a
movq 0x8(%rsp), %rdi
callq 0x3eb31
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq %rbp, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xe730
testq %rax, %rax
jne 0x3ecdd
callq 0xec02
jmp 0x3f038
movq 0xa604f(%rip), %rax     # 0xe4fb8
movq (%rax), %rdi
leaq 0x69beb(%rip), %rsi     # 0xa8b5e
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xe670
jmp 0x3f03a
movq 0x8(%rsp), %rbp
movslq 0x10(%rbp), %rbx
testq %rbx, %rbx
jle 0x3f04f
movq 0x18(%rbp), %r15
xorl %r12d, %r12d
leaq 0x6994a(%rip), %r14     # 0xa88eb
movq (%r15,%r12,8), %r13
movl 0x10(%r13), %edi
movl $0x334, %esi            # imm = 0x334
movq %r14, %rdx
callq 0x3deec
movq %rax, 0x20(%r13)
cmpl $0x0, 0x10(%r13)
jle 0x3efd7
xorl %eax, %eax
movq 0x20(%r13), %rcx
movb $0x0, (%rcx,%rax)
incq %rax
movslq 0x10(%r13), %rcx
cmpq %rcx, %rax
jl 0x3efc3
movl $0xffffffff, 0x28(%r13) # imm = 0xFFFFFFFF
incq %r12
cmpq %rbx, %r12
jne 0x3efa1
leal (,%rbx,8), %edi
leaq 0x698f6(%rip), %rdx     # 0xa88eb
movl $0x33c, %esi            # imm = 0x33C
callq 0x3deec
movq %rax, %r14
testl %ebx, %ebx
jle 0x3f06a
movq 0x18(%rbp), %r15
xorl %r12d, %r12d
movq 0x10(%rsp), %r13
movq (%r15,%r12,8), %rax
movq (%rax), %rdi
callq 0x3df2c
movq %rax, (%r14,%r12,8)
incq %r12
cmpq %r12, %rbx
jne 0x3f012
jmp 0x3f06f
callq 0xebe0
jmp 0x3f038
callq 0xec24
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x4028, %rsp           # imm = 0x4028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal (,%rbx,8), %edi
leaq 0x6988e(%rip), %rdx     # 0xa88eb
movl $0x33c, %esi            # imm = 0x33C
callq 0x3deec
movq %rax, %r14
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rax
movq %r14, (%rax)
movl %ebx, (%r13)
jmp 0x3f03a