// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmarker.c
// Function: save_marker
METHODDEF(jboolean)
save_marker (j_decompress_ptr cinfo)
/* Save an APPn or COM marker into the marker list */
{
  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  unsigned int bytes_read, data_length;
  JOCTET FAR * data;
  INT32 length = 0;
  INPUT_VARS(cinfo);

  if (cur_marker == NULL) {
    /* begin reading a marker */
    INPUT_2BYTES(cinfo, length, return FALSE);
    length -= 2;
    if (length >= 0) {		/* watch out for bogus length word */
      /* figure out how much we want to save */
      unsigned int limit;
      if (cinfo->unread_marker == (int) M_COM)
	limit = marker->length_limit_COM;
      else
	limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
      if ((unsigned int) length < limit)
	limit = (unsigned int) length;
      /* allocate and initialize the marker item */
      cur_marker = (jpeg_saved_marker_ptr)
	(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				    SIZEOF(struct jpeg_marker_struct) + limit);
      cur_marker->next = NULL;
      cur_marker->marker = (UINT8) cinfo->unread_marker;
      cur_marker->original_length = (unsigned int) length;
      cur_marker->data_length = limit;
      /* data area is just beyond the jpeg_marker_struct */
      data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
      marker->cur_marker = cur_marker;
      marker->bytes_read = 0;
      bytes_read = 0;
      data_length = limit;
    } else {
      /* deal with bogus length word */
      bytes_read = data_length = 0;
      data = NULL;
    }
  } else {
    /* resume reading a marker */
    bytes_read = marker->bytes_read;
    data_length = cur_marker->data_length;
    data = cur_marker->data + bytes_read;
  }

  while (bytes_read < data_length) {
    INPUT_SYNC(cinfo);		/* move the restart point to here */
    marker->bytes_read = bytes_read;
    /* If there's not at least one byte in buffer, suspend */
    MAKE_BYTE_AVAIL(cinfo, return FALSE);
    /* Copy bytes with reasonable rapidity */
    while (bytes_read < data_length && bytes_in_buffer > 0) {
      *data++ = *next_input_byte++;
      bytes_in_buffer--;
      bytes_read++;
    }
  }

  /* Done reading what we want to read */
  if (cur_marker != NULL) {	/* will be NULL if bogus length word */
    /* Add new marker to end of list */
    if (cinfo->marker_list == NULL) {
      cinfo->marker_list = cur_marker;
    } else {
      jpeg_saved_marker_ptr prev = cinfo->marker_list;
      while (prev->next != NULL)
	prev = prev->next;
      prev->next = cur_marker;
    }
    /* Reset pointer & calc remaining data length */
    data = cur_marker->data;
    length = cur_marker->original_length - data_length;
  }
  /* Reset to initial state for next marker */
  marker->cur_marker = NULL;

  /* Process the marker if interesting; else just make a generic trace msg */
  switch (cinfo->unread_marker) {
  case M_APP0:
    examine_app0(cinfo, data, data_length, length);
    break;
  case M_APP14:
    examine_app14(cinfo, data, data_length, length);
    break;
  default:
    TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
	     (int) (data_length + length));
    break;
  }

  /* skip any remaining data -- could be lots */
  INPUT_SYNC(cinfo);		/* do before skip_input_data */
  if (length > 0)
    (*cinfo->src->skip_input_data) (cinfo, (long) length);

  return TRUE;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq 0x248(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0xf8(%rax), %rax
movq %rax, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0xe66c9
jmp 0xe64ab
cmpq $0x0, 0x18(%rsp)
jne 0xe64f0
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x58(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe64d5
movl $0x0, 0x64(%rsp)
jmp 0xe6968
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rsp)
movzbl (%rax), %eax
shll $0x8, %eax
movl %eax, %eax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0xe6561
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x58(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe6546
movl $0x0, 0x64(%rsp)
jmp 0xe6968
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rsp)
movzbl (%rax), %eax
addq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
subq $0x2, %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jl 0xe66ae
movq 0x58(%rsp), %rax
cmpl $0xfe, 0x21c(%rax)
jne 0xe65c9
movq 0x50(%rsp), %rax
movl 0xb0(%rax), %eax
movl %eax, 0x14(%rsp)
jmp 0xe65ed
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
movl 0x21c(%rcx), %ecx
subl $0xe0, %ecx
movslq %ecx, %rcx
movl 0xb4(%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
movq 0x30(%rsp), %rax
cmpl 0x14(%rsp), %eax
jae 0xe6601
movq 0x30(%rsp), %rax
movl %eax, 0x14(%rsp)
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x58(%rsp), %rdi
movl 0x14(%rsp), %ecx
movl %ecx, %edx
addq $0x20, %rdx
movl $0x1, %esi
callq *%rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq $0x0, (%rax)
movq 0x58(%rsp), %rax
movl 0x21c(%rax), %eax
movb %al, %cl
movq 0x48(%rsp), %rax
movb %cl, 0x8(%rax)
movq 0x30(%rsp), %rax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0xc(%rax)
movl 0x14(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x48(%rsp), %rax
addq $0x20, %rax
movq 0x48(%rsp), %rcx
movq %rax, 0x18(%rcx)
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0xf8(%rax)
movq 0x50(%rsp), %rax
movl $0x0, 0x100(%rax)
movl $0x0, 0x44(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x40(%rsp)
jmp 0xe66c7
movl $0x0, 0x40(%rsp)
movl $0x0, 0x44(%rsp)
movq $0x0, 0x38(%rsp)
jmp 0xe66f9
movq 0x50(%rsp), %rax
movl 0x100(%rax), %eax
movl %eax, 0x44(%rsp)
movq 0x48(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x44(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
jmp 0xe66fb
movl 0x44(%rsp), %eax
cmpl 0x40(%rsp), %eax
jae 0xe67e7
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movl 0x44(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x100(%rax)
cmpq $0x0, 0x18(%rsp)
jne 0xe6778
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x58(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe675d
movl $0x0, 0x64(%rsp)
jmp 0xe6968
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0xe677a
movl 0x44(%rsp), %ecx
xorl %eax, %eax
cmpl 0x40(%rsp), %ecx
movb %al, 0x7(%rsp)
jae 0xe6797
cmpq $0x0, 0x18(%rsp)
seta %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0xe67a1
jmp 0xe67e2
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rsp)
movb (%rax), %cl
movq 0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x38(%rsp)
movb %cl, (%rax)
movq 0x18(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x18(%rsp)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xe677a
jmp 0xe66fb
cmpq $0x0, 0x48(%rsp)
je 0xe686a
movq 0x58(%rsp), %rax
cmpq $0x0, 0x190(%rax)
jne 0xe6811
movq 0x48(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x190(%rax)
jmp 0xe6849
movq 0x58(%rsp), %rax
movq 0x190(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
je 0xe683c
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0xe6822
movq 0x48(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rax
movl 0xc(%rax), %eax
subl 0x40(%rsp), %eax
movl %eax, %eax
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq $0x0, 0xf8(%rax)
movq 0x58(%rsp), %rax
movl 0x21c(%rax), %eax
movl %eax, (%rsp)
subl $0xe0, %eax
je 0xe689d
jmp 0xe6891
movl (%rsp), %eax
subl $0xee, %eax
je 0xe68b7
jmp 0xe68d1
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %edx
movq 0x30(%rsp), %rcx
callq 0xe8b10
jmp 0xe6924
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %edx
movq 0x30(%rsp), %rcx
callq 0xe8ff0
jmp 0xe6924
movq 0x58(%rsp), %rax
movq (%rax), %rax
movl $0x5b, 0x28(%rax)
movq 0x58(%rsp), %rax
movl 0x21c(%rax), %ecx
movq 0x58(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movl 0x40(%rsp), %eax
addq 0x30(%rsp), %rax
movl %eax, %ecx
movq 0x58(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x30(%rax)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x58(%rsp), %rdi
movl $0x1, %esi
callq *%rax
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x30(%rsp)
jle 0xe6960
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq *%rax
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)