// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/ply.cpp
// Function: get_binary_item(_IO_FILE*, int, int, int*, unsigned int*, double*)
void get_binary_item(
  FILE *fp,
  int file_type,
  int type,
  int *int_val,
  unsigned int *uint_val,
  double *double_val
)
{
  char c[8];
  void *ptr;

  ptr = (void *) c;

  if (fread (ptr, ply_type_size[type], 1, fp) != (unsigned int) 1) {
    fprintf(stderr, "Unable to read item from ply file\n");
    return;
  }
  
  if ((file_type != native_binary_type) && (ply_type_size[type] > 1))
     swap_bytes((char *)ptr, ply_type_size[type]);

  switch (type) {
    case PLY_CHAR:
      *int_val = *((char *) ptr);
      *uint_val = (*int_val >= 0) ? *int_val : 0;
      *double_val = *int_val;
      break;
    case PLY_UCHAR:
      *uint_val = *((unsigned char *) ptr);
      *int_val = *uint_val;
      *double_val = *uint_val;
      break;
    case PLY_SHORT:
      *int_val = *((short int *) ptr);
      *uint_val = (*int_val >= 0) ? *int_val : 0;
      *double_val = *int_val;
      break;
    case PLY_USHORT:
      *uint_val = *((unsigned short int *) ptr);
      *int_val = *uint_val;
      *double_val = *uint_val;
      break;
    case PLY_INT:
      *int_val = *((int *) ptr);
      *uint_val = (*int_val >= 0) ? *int_val : 0;
      *double_val = *int_val;
      break;
    case PLY_UINT:
      *uint_val = *((unsigned int *) ptr);
      *int_val = *uint_val;
      *double_val = *uint_val;
      break;
    case PLY_FLOAT:
      *double_val = *((float *) ptr);
      *int_val = (int) *double_val;
      *uint_val = (*double_val >= 0) ? (unsigned int) *double_val : 0;
      break;
    case PLY_DOUBLE:
      *double_val = *((double *) ptr);
      *int_val = (int) *double_val;
      *uint_val = (*double_val >= 0) ? (unsigned int) *double_val : 0;
      break;
    default:
      fprintf (stderr, "get_binary_item: bad type = %d\n", type);
      exit (-1);
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movl %edx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %r9, 0x30(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movslq 0x48(%rsp), %rcx
leaq 0x1030e5(%rip), %rax    # 0x1782e0
movslq (%rax,%rcx,4), %rsi
movq 0x50(%rsp), %rcx
movl $0x1, %edx
callq 0xf780
cmpq $0x1, %rax
je 0x75231
movq 0xf9dad(%rip), %rax     # 0x16efc8
movq (%rax), %rdi
leaq 0xc0669(%rip), %rsi     # 0x13588e
movb $0x0, %al
callq 0xf730
jmp 0x75502
movl 0x4c(%rsp), %eax
cmpl 0x1030c9(%rip), %eax    # 0x178304
je 0x75268
movslq 0x48(%rsp), %rcx
leaq 0x103097(%rip), %rax    # 0x1782e0
cmpl $0x1, (%rax,%rcx,4)
jle 0x75268
movq 0x20(%rsp), %rdi
movslq 0x48(%rsp), %rcx
leaq 0x103080(%rip), %rax    # 0x1782e0
movl (%rax,%rcx,4), %esi
callq 0x75510
movl 0x48(%rsp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x18(%rsp)
subl $0x7, %eax
ja 0x754dc
movq 0x18(%rsp), %rax
leaq 0xbffde(%rip), %rcx     # 0x135268
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %rax
movsbl (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
cmpl $0x0, (%rax)
jl 0x752b9
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
jmp 0x752c1
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x752c1
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
cvtsi2sdl (%rax), %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movzbl (%rax), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movl (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movswl (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
cmpl $0x0, (%rax)
jl 0x75340
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x10(%rsp)
jmp 0x75348
xorl %eax, %eax
movl %eax, 0x10(%rsp)
jmp 0x75348
movl 0x10(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
cvtsi2sdl (%rax), %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movzwl (%rax), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movl (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movl (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
cmpl $0x0, (%rax)
jl 0x753c6
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x753ce
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x753ce
movl 0xc(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
cvtsi2sdl (%rax), %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movl (%rax), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movl (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rax
cvttsd2si (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x7546e
movq 0x30(%rsp), %rax
cvttsd2si (%rax), %rax
movl %eax, 0x8(%rsp)
jmp 0x75476
xorl %eax, %eax
movl %eax, 0x8(%rsp)
jmp 0x75476
movl 0x8(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
jmp 0x75502
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rax
cvttsd2si (%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x754c7
movq 0x30(%rsp), %rax
cvttsd2si (%rax), %rax
movl %eax, 0x4(%rsp)
jmp 0x754cf
xorl %eax, %eax
movl %eax, 0x4(%rsp)
jmp 0x754cf
movl 0x4(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
jmp 0x75502
movq 0xf9ae5(%rip), %rax     # 0x16efc8
movq (%rax), %rdi
movl 0x48(%rsp), %edx
leaq 0xc03c0(%rip), %rsi     # 0x1358b1
movb $0x0, %al
callq 0xf730
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xf600
addq $0x58, %rsp
retq
nopw (%rax,%rax)