// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: ply_header_complete
void ply_header_complete(PlyFile *plyfile)
{
  int i,j;
  FILE *fp = plyfile->fp;
  PlyElement *elem;
  PlyProperty *prop;

  fprintf (fp, "ply\n");

  switch (plyfile->file_type) {
    case PLY_ASCII:
      fprintf (fp, "format ascii 1.0\n");
      break;
    case PLY_BINARY_BE:
      fprintf (fp, "format binary_big_endian 1.0\n");
      break;
    case PLY_BINARY_LE:
      fprintf (fp, "format binary_little_endian 1.0\n");
      break;
    default:
      fprintf (stderr, "ply_header_complete: bad file type = %d\n",
               plyfile->file_type);
      exit (-1);
  }

  /* write out the comments */

  for (i = 0; i < plyfile->num_comments; i++)
    fprintf (fp, "comment %s\n", plyfile->comments[i]);

  /* write out object information */

  for (i = 0; i < plyfile->num_obj_info; i++)
    fprintf (fp, "obj_info %s\n", plyfile->obj_info[i]);

  /* write out information about each element */

  for (i = 0; i < plyfile->nelems; i++) {

    elem = plyfile->elems[i];
    fprintf (fp, "element %s %d\n", elem->name, elem->num);

    /* write out each property */
    for (j = 0; j < elem->nprops; j++) {
      prop = elem->props[j];
      if (prop->is_list) {
        fprintf (fp, "property list ");
        write_scalar_type (fp, prop->count_external);
        fprintf (fp, " ");
        write_scalar_type (fp, prop->external_type);
        fprintf (fp, " %s\n", prop->name);
      }
      else {
        fprintf (fp, "property ");
        write_scalar_type (fp, prop->external_type);
        fprintf (fp, " %s\n", prop->name);
      }
    }
  }

  fprintf (fp, "end_header\n");
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
leaq 0xc3518(%rip), %rsi     # 0x1353ba
xorl %eax, %eax
callq 0xf730
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xc(%rsp)
subl $0x1, %eax
je 0x71ed2
jmp 0x71ebc
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0x71ee7
jmp 0x71ec7
movl 0xc(%rsp), %eax
subl $0x3, %eax
je 0x71efc
jmp 0x71f11
movq 0x20(%rsp), %rdi
leaq 0xc34e1(%rip), %rsi     # 0x1353bf
movb $0x0, %al
callq 0xf730
jmp 0x71f3b
movq 0x20(%rsp), %rdi
leaq 0xc34de(%rip), %rsi     # 0x1353d1
movb $0x0, %al
callq 0xf730
jmp 0x71f3b
movq 0x20(%rsp), %rdi
leaq 0xc34e7(%rip), %rsi     # 0x1353ef
movb $0x0, %al
callq 0xf730
jmp 0x71f3b
movq 0xfd0b0(%rip), %rax     # 0x16efc8
movq (%rax), %rdi
movq 0x30(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0xc34e6(%rip), %rsi     # 0x135410
movb $0x0, %al
callq 0xf730
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xf600
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x71f83
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xc34ca(%rip), %rsi     # 0x135439
movb $0x0, %al
callq 0xf730
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x71f43
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x71fcb
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x38(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xc348e(%rip), %rsi     # 0x135445
movb $0x0, %al
callq 0xf730
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x71f8b
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x72126
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq (%rax), %rdx
movq 0x18(%rsp), %rax
movl 0x8(%rax), %ecx
leaq 0xc343a(%rip), %rsi     # 0x135452
movb $0x0, %al
callq 0xf730
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movq 0x18(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x72114
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x14(%rax)
je 0x720c2
movq 0x20(%rsp), %rdi
leaq 0xc33fa(%rip), %rsi     # 0x135461
movb $0x0, %al
callq 0xf730
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
movl 0x18(%rax), %esi
callq 0x72140
movq 0x20(%rsp), %rdi
leaq 0xc162e(%rip), %rsi     # 0x1336ba
movb $0x0, %al
callq 0xf730
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x72140
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rdx
leaq 0xc3d75(%rip), %rsi     # 0x135e2e
movb $0x0, %al
callq 0xf730
jmp 0x72102
movq 0x20(%rsp), %rdi
leaq 0xc33a2(%rip), %rsi     # 0x135470
movb $0x0, %al
callq 0xf730
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x72140
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rdx
leaq 0xc3d33(%rip), %rsi     # 0x135e2e
movb $0x0, %al
callq 0xf730
jmp 0x72104
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x72027
jmp 0x72116
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x71fd3
movq 0x20(%rsp), %rdi
leaq 0xc3348(%rip), %rsi     # 0x13547a
movb $0x0, %al
callq 0xf730
addq $0x38, %rsp
retq
nop