// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq (%rdi), %r13
movq 0x40(%rdi), %rdi
movslq 0x28(%rdi), %rax
movq %rax, 0x28(%rsp)
cmpl $0x1, 0x8(%r15)
movl 0x10(%rdi), %eax
movq %rdi, 0x30(%rsp)
jne 0x3ece2
testl %eax, %eax
jle 0x3ecc7
xorl %esi, %esi
leaq 0xc(%rsp), %r8
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %rbx
movq 0x20(%rdi), %rax
cmpb $0x0, (%rax,%rsi)
movq 0x18(%rsp), %r14
jne 0x3ebb7
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rdx
movq (%rax,%rdx), %r14
movq 0x18(%rdi), %rax
movq %rsi, 0x20(%rsp)
movq (%rax,%rsi,8), %r12
cmpl $0x0, 0x14(%r12)
je 0x3ec67
movslq 0x20(%r12), %rdi
addq %r14, %rdi
movl 0x1c(%r12), %esi
movq %r8, %rdx
movq %rbx, %r8
callq 0x3ee39
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %ebp
movsd 0x10(%rsp), %xmm0
movl 0x18(%r12), %ecx
movq %r13, %rdi
movl %ebp, %edx
callq 0x3eee4
testl %ebp, %ebp
movq %r13, %r15
jle 0x3eca0
movslq 0xc(%r12), %rax
leaq 0xa6e54(%rip), %rcx     # 0xe5a70
movslq (%rcx,%rax,4), %r13
movslq 0x10(%r12), %rax
movq (%r14,%rax), %r14
movl 0xc(%r12), %esi
movq %r14, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %rbx, %r8
callq 0x3ee39
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movsd 0x10(%rsp), %xmm0
movl 0x8(%r12), %ecx
movq %r15, %rdi
callq 0x3eee4
addq %r13, %r14
decl %ebp
jne 0x3ec29
jmp 0x3eca0
movslq 0x10(%r12), %rax
addq %rax, %r14
movl 0xc(%r12), %esi
movq %r14, %rdi
movq %r8, %rdx
movq %rbx, %r8
callq 0x3ee39
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movsd 0x10(%rsp), %xmm0
movl 0x8(%r12), %ecx
movq %r13, %rdi
callq 0x3eee4
movq %r13, %r15
movq 0x20(%rsp), %rsi
incq %rsi
movq 0x30(%rsp), %rdi
movslq 0x10(%rdi), %rax
cmpq %rax, %rsi
leaq 0xc(%rsp), %r8
leaq 0x8(%rsp), %rcx
movq %r15, %r13
jl 0x3eb9a
movl $0xa, %edi
movq %r13, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe5a0
testl %eax, %eax
jle 0x3ee2a
xorl %esi, %esi
leaq 0xc(%rsp), %r9
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq 0x20(%rdi), %rax
cmpb $0x0, (%rax,%rsi)
movq 0x18(%rsp), %r12
jne 0x3ed18
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rdx
movq (%rax,%rdx), %r12
movq 0x18(%rdi), %rax
movq %rsi, 0x20(%rsp)
movq (%rax,%rsi,8), %rbp
cmpl $0x0, 0x14(%rbp)
je 0x3edc8
movslq 0x20(%rbp), %rdi
addq %r12, %rdi
movl 0x1c(%rbp), %esi
movq %r9, %rdx
callq 0x3ee39
movl 0x8(%r15), %esi
movl 0xc(%rsp), %edx
movq %r13, %rbx
movl 0x8(%rsp), %r14d
movsd 0x10(%rsp), %xmm0
movl 0x18(%rbp), %r8d
movq %r13, %rdi
movl %r14d, %ecx
callq 0x3ef38
testl %r14d, %r14d
jle 0x3edfe
movslq 0xc(%rbp), %rax
leaq 0xa6cf6(%rip), %rcx     # 0xe5a70
movslq (%rcx,%rax,4), %r13
movslq 0x10(%rbp), %rax
movq (%r12,%rax), %r12
movl 0xc(%rbp), %esi
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x3ee39
movl 0x8(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movl 0x8(%rbp), %r8d
movq %rbx, %rdi
callq 0x3ef38
addq %r13, %r12
decl %r14d
jne 0x3ed86
jmp 0x3edfe
movslq 0x10(%rbp), %rax
addq %rax, %r12
movl 0xc(%rbp), %esi
movq %r12, %rdi
movq %r9, %rdx
callq 0x3ee39
movl 0x8(%r15), %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movsd 0x10(%rsp), %xmm0
movl 0x8(%rbp), %r8d
movq %r13, %rdi
callq 0x3ef38
movq %r13, %rbx
movq 0x20(%rsp), %rsi
incq %rsi
movq 0x30(%rsp), %rdi
movslq 0x10(%rdi), %rax
cmpq %rax, %rsi
leaq 0xc(%rsp), %r9
movq %rbx, %r13
leaq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %r8
jl 0x3ecfb
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq