// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: ply_get_other_element
PlyOtherElems *ply_get_other_element (
  PlyFile *plyfile,
  char *elem_name,
  int elem_count
)
{
  int i;
  PlyElement *elem;
  PlyOtherElems *other_elems;
  OtherElem *other;

  /* look for appropriate element */
  elem = find_element (plyfile, elem_name);
  if (elem == NULL) {
    fprintf (stderr,
             "ply_get_other_element: can't find element '%s'\n", elem_name);
    exit (-1);
  }

  /* create room for the new "other" element, initializing the */
  /* other data structure if necessary */

  if (plyfile->other_elems == NULL) {
    plyfile->other_elems = (PlyOtherElems *) myalloc (sizeof (PlyOtherElems));
    other_elems = plyfile->other_elems;
    other_elems->other_list = (OtherElem *) myalloc (sizeof (OtherElem));
    other = &(other_elems->other_list[0]);
    other_elems->num_elems = 1;
  }
  else {
    other_elems = plyfile->other_elems;
    other_elems->other_list = (OtherElem *) realloc (other_elems->other_list,
                              sizeof (OtherElem) * other_elems->num_elems + 1);
    other = &(other_elems->other_list[other_elems->num_elems]);
    other_elems->num_elems++;
  }

  /* count of element instances in file */
  other->elem_count = elem_count;

  /* save name of element */
  other->elem_name = my_strdup (elem_name);

  /* create a list to hold all the current elements */
  other->other_data = (OtherData **)
                  malloc (sizeof (OtherData *) * other->elem_count);

  /* set up for getting elements */
  other->other_props = ply_get_other_properties (plyfile, elem_name,
                         offsetof(OtherData,other_props));

  /* grab all these elements */
  for (i = 0; i < other->elem_count; i++) {
    /* grab and element from the file */
    other->other_data[i] = (OtherData *) malloc (sizeof (OtherData));
    ply_get_element (plyfile, (void *) other->other_data[i]);
  }

  /* return pointer to the other elements data */
  return (other_elems);
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x71970
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x749a5
movq 0xfa643(%rip), %rax     # 0x16efc8
movq (%rax), %rdi
movq 0x28(%rsp), %rdx
leaq 0xc0ce7(%rip), %rsi     # 0x13567b
movb $0x0, %al
callq 0xf730
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xf600
movq 0x30(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x74a1e
movl $0x10, %edi
movl $0x506, %esi            # imm = 0x506
leaq 0xc092d(%rip), %rdx     # 0x1352ef
callq 0x71630
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x10(%rsp)
movl $0x20, %edi
movl $0x508, %esi            # imm = 0x508
leaq 0xc08fd(%rip), %rdx     # 0x1352ef
callq 0x71630
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
jmp 0x74a7f
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rsp), %rax
movslq (%rax), %rsi
shlq $0x5, %rsi
addq $0x1, %rsi
callq 0xf850
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl 0x24(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x28(%rsp), %rdi
callq 0x71680
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x3, %rdi
callq 0xf6a0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x74790
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movq 0x8(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x74b39
movl $0x8, %edi
callq 0xf6a0
movq %rax, %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x20(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x73dc0
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x74ae3
movq 0x10(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)