// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: ply_put_element
void ply_put_element(PlyFile *plyfile, void *elem_ptr)
{
  int j,k;
  FILE *fp = plyfile->fp;
  PlyElement *elem;
  PlyProperty *prop;
  char *elem_data,*item;
  char **item_ptr;
  int list_count;
  int item_size;
  int int_val;
  unsigned int uint_val;
  double double_val;
  char **other_ptr;

  elem = plyfile->which_elem;
  elem_data = (char *)elem_ptr;
  other_ptr = (char **) (((char *) elem_ptr) + elem->other_offset);

  /* write out either to an ascii or binary file */

  if (plyfile->file_type == PLY_ASCII) {

    /* write an ascii file */

    /* write out each property of the element */
    for (j = 0; j < elem->nprops; j++) {
      prop = elem->props[j];
      if (elem->store_prop[j] == OTHER_PROP)
        elem_data = *other_ptr;
      else
        elem_data = (char *)elem_ptr;
      if (prop->is_list) {
        item = elem_data + prop->count_offset;
        get_stored_item ((void *) item, prop->count_internal,
                         &int_val, &uint_val, &double_val);
        write_ascii_item (fp, int_val, uint_val, double_val,
                          prop->count_external);
        list_count = uint_val;
        item_ptr = (char **) (elem_data + prop->offset);
        item = item_ptr[0];
        item_size = ply_type_size[prop->internal_type];
        for (k = 0; k < list_count; k++) {
          get_stored_item ((void *) item, prop->internal_type,
                           &int_val, &uint_val, &double_val);
          write_ascii_item (fp, int_val, uint_val, double_val,
                            prop->external_type);
          item += item_size;
        }
      }
      else {
        item = elem_data + prop->offset;
        get_stored_item ((void *) item, prop->internal_type,
                         &int_val, &uint_val, &double_val);
        write_ascii_item (fp, int_val, uint_val, double_val,
                          prop->external_type);
      }
    }

    fprintf (fp, "\n");
  }
  else {

    /* write a binary file */

    /* write out each property of the element */
    for (j = 0; j < elem->nprops; j++) {
      prop = elem->props[j];
      if (elem->store_prop[j] == OTHER_PROP)
        elem_data = *other_ptr;
      else
        elem_data = (char *)elem_ptr;
      if (prop->is_list) {
        item = elem_data + prop->count_offset;
        item_size = ply_type_size[prop->count_internal];
        get_stored_item ((void *) item, prop->count_internal,
                         &int_val, &uint_val, &double_val);
        write_binary_item (fp, plyfile->file_type, int_val, uint_val,
			   double_val, prop->count_external);
        list_count = uint_val;
        item_ptr = (char **) (elem_data + prop->offset);
        item = item_ptr[0];
        item_size = ply_type_size[prop->internal_type];
        for (k = 0; k < list_count; k++) {
          get_stored_item ((void *) item, prop->internal_type,
                           &int_val, &uint_val, &double_val);
          write_binary_item (fp, plyfile->file_type, int_val, uint_val,
			     double_val, prop->external_type);
          item += item_size;
        }
      }
      else {
        item = elem_data + prop->offset;
        item_size = ply_type_size[prop->internal_type];
        get_stored_item ((void *) item, prop->internal_type,
                         &int_val, &uint_val, &double_val);
        write_binary_item (fp, plyfile->file_type, int_val, uint_val,
			   double_val, prop->external_type);
      }
    }

  }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x60(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rax
movq 0x40(%rsp), %rcx
movslq 0x28(%rcx), %rcx
addq %rcx, %rax
movq %rax, (%rsp)
movq 0x60(%rsp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x72476
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x7245e
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x54(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x722cd
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x722d7
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
cmpl $0x0, 0x14(%rax)
je 0x723f5
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x20(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0x1c(%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x726b0
movq 0x48(%rsp), %rdi
movl 0x14(%rsp), %esi
movl 0x10(%rsp), %edx
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x18(%rax), %ecx
callq 0x72950
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movslq 0xc(%rax), %rcx
leaq 0x105f68(%rip), %rax    # 0x1782e0
movl (%rax,%rcx,4), %eax
movl %eax, 0x18(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jge 0x723f3
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x726b0
movq 0x48(%rsp), %rdi
movl 0x14(%rsp), %esi
movl 0x10(%rsp), %edx
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x8(%rax), %ecx
callq 0x72950
movl 0x18(%rsp), %ecx
movq 0x28(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x72387
jmp 0x7244c
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x726b0
movq 0x48(%rsp), %rdi
movl 0x14(%rsp), %esi
movl 0x10(%rsp), %edx
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x8(%rax), %ecx
callq 0x72950
jmp 0x7244e
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x7227f
movq 0x48(%rsp), %rdi
leaq 0xc65a8(%rip), %rsi     # 0x138a12
movb $0x0, %al
callq 0xf730
jmp 0x726a8
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x726a6
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x54(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x724cc
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x724d6
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
cmpl $0x0, 0x14(%rax)
je 0x7261d
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x20(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movslq 0x1c(%rax), %rcx
leaq 0x105dd5(%rip), %rax    # 0x1782e0
movl (%rax,%rcx,4), %eax
movl %eax, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0x1c(%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x726b0
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x18(%rax), %r8d
callq 0x72a10
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movslq 0xc(%rax), %rcx
leaq 0x105d49(%rip), %rax    # 0x1782e0
movl (%rax,%rcx,4), %eax
movl %eax, 0x18(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jge 0x7261b
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x726b0
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x8(%rax), %r8d
callq 0x72a10
movl 0x18(%rsp), %ecx
movq 0x28(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x725a6
jmp 0x72694
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movslq 0xc(%rax), %rcx
leaq 0x105c9d(%rip), %rax    # 0x1782e0
movl (%rax,%rcx,4), %eax
movl %eax, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x726b0
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rax
movl 0x8(%rax), %esi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x8(%rax), %r8d
callq 0x72a10
jmp 0x72696
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x7247e
jmp 0x726a8
addq $0x68, %rsp
retq
nopl (%rax)