// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x18(%rsp)
movq (%rdi), %rbx
movq 0x40(%rdi), %rcx
movslq 0x28(%rcx), %rax
movq %rax, 0x28(%rsp)
cmpl $0x1, 0x8(%rdi)
movq %rcx, 0x30(%rsp)
jne 0x39823
leaq 0x10(%rsp), %r13
xorl %esi, %esi
movslq 0x10(%rcx), %rax
cmpq %rax, %rsi
jge 0x39964
movq 0x20(%rcx), %rax
cmpb $0x0, (%rax,%rsi)
movq 0x18(%rsp), %r14
jne 0x39728
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rdx
movq (%rax,%rdx), %r14
movq 0x18(%rcx), %rax
movq %rsi, 0x20(%rsp)
movq (%rax,%rsi,8), %r15
cmpl $0x0, 0x14(%r15)
je 0x397d7
movslq 0x20(%r15), %rdi
addq %r14, %rdi
movl 0x1c(%r15), %esi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r13, %r8
callq 0x3998c
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %ebp
movsd 0x10(%rsp), %xmm0
movl 0x18(%r15), %ecx
movq %rbx, %rdi
movl %ebp, %edx
callq 0x39a54
movslq 0x10(%r15), %rax
movq (%r14,%rax), %r14
movslq 0xc(%r15), %rax
leaq 0xa12f4(%rip), %rcx     # 0xdaa80
movslq (%rcx,%rax,4), %r12
testl %ebp, %ebp
movl $0x0, %eax
cmovlel %eax, %ebp
subl $0x1, %ebp
jb 0x39811
movl 0xc(%r15), %esi
movq %r14, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r13, %r8
callq 0x3998c
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movsd 0x10(%rsp), %xmm0
movl 0x8(%r15), %ecx
movq %rbx, %rdi
callq 0x39a54
addq %r12, %r14
jmp 0x3979a
movslq 0x10(%r15), %rax
addq %rax, %r14
movl 0xc(%r15), %esi
movq %r14, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r13, %r8
callq 0x3998c
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movsd 0x10(%rsp), %xmm0
movl 0x8(%r15), %ecx
movq %rbx, %rdi
callq 0x39a54
movq 0x20(%rsp), %rsi
incq %rsi
movq 0x30(%rsp), %rcx
jmp 0x396fe
movq %rdi, %r15
xorl %esi, %esi
movslq 0x10(%rcx), %rax
cmpq %rax, %rsi
jge 0x3997d
movq 0x20(%rcx), %rax
cmpb $0x0, (%rax,%rsi)
movq 0x18(%rsp), %r12
jne 0x39852
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rdx
movq (%rax,%rdx), %r12
movq 0x18(%rcx), %rax
movq %rsi, 0x20(%rsp)
movq (%rax,%rsi,8), %r13
cmpl $0x0, 0x14(%r13)
je 0x39912
movslq 0x20(%r13), %rdi
addq %r12, %rdi
movl 0x1c(%r13), %esi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3998c
movl 0x8(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %r14d
movsd 0x10(%rsp), %xmm0
movl 0x18(%r13), %r8d
movq %rbx, %rdi
movl %r14d, %ecx
callq 0x39abf
movslq 0x10(%r13), %rax
movq (%r12,%rax), %r12
movslq 0xc(%r13), %rax
leaq 0xa11c2(%rip), %rcx     # 0xdaa80
movslq (%rcx,%rax,4), %rbp
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
subl $0x1, %r14d
jb 0x39952
movl 0xc(%r13), %esi
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3998c
movl 0x8(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movl 0x8(%r13), %r8d
movq %rbx, %rdi
callq 0x39abf
addq %rbp, %r12
jmp 0x398ce
movslq 0x10(%r13), %rax
addq %rax, %r12
movl 0xc(%r13), %esi
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3998c
movl 0x8(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movl 0x8(%r13), %r8d
movq %rbx, %rdi
callq 0x39abf
movq 0x20(%rsp), %rsi
incq %rsi
movq 0x30(%rsp), %rcx
jmp 0x39828
pushq $0xa
popq %rdi
movq %rbx, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe5c0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq