// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x248(%rdi), %rdx
movq 0xf8(%rdx), %rax
movq 0x28(%rdi), %r14
movq (%r14), %r12
movq 0x8(%r14), %rbx
testq %rax, %rax
movq %rdi, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
je 0x71384
movl 0x100(%rdx), %ebp
movl 0x10(%rax), %r15d
movq %rbp, %r13
movq %rax, 0x20(%rsp)
addq 0x18(%rax), %r13
movq $0x0, 0x10(%rsp)
cmpl %r15d, %ebp
jae 0x71361
movq %r12, (%r14)
movq %rbx, 0x8(%r14)
movl %ebp, 0x100(%rdx)
testq %rbx, %rbx
jne 0x71339
callq *0x18(%r14)
testl %eax, %eax
je 0x7152e
movq (%r14), %r12
movq 0x8(%r14), %rbx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %rbx, %rax
addq $-0x1, %rax
setb %cl
cmpl %r15d, %ebp
jae 0x71305
testb %cl, %cl
je 0x71305
movb (%r12), %cl
incq %r12
movb %cl, (%r13)
incq %r13
incl %ebp
movq %rax, %rbx
jmp 0x7133c
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x713d5
movq 0x190(%rdi), %rax
testq %rax, %rax
je 0x713bc
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x71377
jmp 0x713c3
testq %rbx, %rbx
jne 0x713a6
callq *0x18(%r14)
testl %eax, %eax
je 0x7152e
movq (%r14), %r12
movq 0x8(%r14), %rbx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rdx
movzbl (%r12), %r15d
decq %rbx
je 0x71467
incq %r12
jmp 0x71484
leaq 0x190(%rdi), %rcx
movq %rsi, (%rcx)
movq 0x18(%rsi), %r13
movl 0xc(%rsi), %eax
subl %r15d, %eax
movq %rax, 0x10(%rsp)
andq $0x0, 0xf8(%rdx)
movl 0x21c(%rdi), %eax
cmpl $0xee, %eax
je 0x71406
cmpl $0xe0, %eax
jne 0x7141b
movq %r13, %rsi
movl %r15d, %edx
movq 0x10(%rsp), %r13
movq %r13, %rcx
callq 0x718b3
jmp 0x71440
movq %r13, %rsi
movl %r15d, %edx
movq 0x10(%rsp), %r13
movq %r13, %rcx
callq 0x71ae3
jmp 0x71440
movq (%rdi), %rcx
movl $0x5b, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq 0x10(%rsp), %r13
addl %r13d, %r15d
movq (%rdi), %rax
movl %r15d, 0x30(%rax)
movq (%rdi), %rax
pushq $0x1
popq %rsi
callq *0x8(%rax)
pushq $0x1
popq %rbp
movq %r12, (%r14)
movq %rbx, 0x8(%r14)
testq %r13, %r13
jle 0x71530
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rax
movq %r13, %rsi
callq *0x20(%rax)
jmp 0x71530
callq *0x18(%r14)
testl %eax, %eax
je 0x7152e
movq (%r14), %r12
movq 0x8(%r14), %rbx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rdx
shll $0x8, %r15d
decq %rbx
movzbl (%r12), %eax
incq %r12
movq %r15, %rcx
orq %rax, %rcx
leaq (%r15,%rax), %r13
addq $-0x2, %r13
xorl %ebp, %ebp
cmpq $0x2, %rcx
movq %r13, 0x10(%rsp)
jb 0x71541
movslq 0x21c(%rdi), %rax
leaq 0xb0(%rdx), %rcx
cmpq $0xfe, %rax
leaq -0x2cc(%rdx,%rax,4), %rax
cmoveq %rcx, %rax
movl (%rax), %r15d
cmpl %r13d, %r15d
cmovael %r13d, %r15d
movq 0x8(%rdi), %rax
leaq 0x20(%r15), %rdx
pushq $0x1
popq %rsi
movq 0x8(%rsp), %rdi
callq *0x8(%rax)
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rdi
andq $0x0, (%rax)
movb 0x21c(%rdi), %cl
movb %cl, 0x8(%rax)
movl %r13d, 0xc(%rax)
movl %r15d, 0x10(%rax)
leaq 0x20(%rax), %r13
movq %r13, 0x18(%rax)
movq %rax, 0x20(%rsp)
movq %rax, 0xf8(%rdx)
andl $0x0, 0x100(%rdx)
jmp 0x71305
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x71305