// File: /workspace/github_cpp_makefile_star2_O1/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), %r9
movq 0xf8(%r9), %rax
movq 0x28(%rdi), %rbp
movq (%rbp), %r14
movq 0x8(%rbp), %r12
testq %rax, %rax
movq %rdi, 0x8(%rsp)
movq %r9, 0x18(%rsp)
je 0x7e0e4
movl 0x100(%r9), %ebx
movl 0x10(%rax), %r15d
movq %rbx, %r13
movq %rax, 0x10(%rsp)
addq 0x18(%rax), %r13
movq $0x0, 0x20(%rsp)
jmp 0x7e253
testq %r12, %r12
jne 0x7e106
callq *0x18(%rbp)
testl %eax, %eax
je 0x7e27e
movq (%rbp), %r14
movq 0x8(%rbp), %r12
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %r9
movzbl (%r14), %ebx
decq %r12
je 0x7e114
incq %r14
jmp 0x7e131
callq *0x18(%rbp)
testl %eax, %eax
je 0x7e27e
movq (%rbp), %r14
movq 0x8(%rbp), %r12
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %r9
shll $0x8, %ebx
decq %r12
movzbl (%r14), %eax
incq %r14
movq %rbx, %rcx
orq %rax, %rcx
leaq (%rbx,%rax), %r13
addq $-0x2, %r13
xorl %ebx, %ebx
cmpq $0x2, %rcx
movq %r13, 0x20(%rsp)
jb 0x7e1d6
movslq 0x21c(%rdi), %rax
leaq 0xb0(%r9), %rcx
cmpq $0xfe, %rax
leaq -0x2cc(%r9,%rax,4), %rax
cmoveq %rcx, %rax
movl (%rax), %r15d
cmpl %r13d, %r15d
cmovael %r13d, %r15d
movq 0x8(%rdi), %rax
leaq 0x20(%r15), %rdx
movl $0x1, %esi
callq *0x8(%rax)
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rdi
movq $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, 0x10(%rsp)
movq %rax, 0xf8(%r9)
movl $0x0, 0x100(%r9)
jmp 0x7e253
movq $0x0, 0x10(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x7e253
movq %r14, (%rbp)
movq %r12, 0x8(%rbp)
movl %ebx, 0x100(%r9)
testq %r12, %r12
jne 0x7e214
callq *0x18(%rbp)
testl %eax, %eax
je 0x7e27e
movq (%rbp), %r14
movq 0x8(%rbp), %r12
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %r9
cmpl %r15d, %ebx
jae 0x7e253
testq %r12, %r12
je 0x7e253
leaq -0x1(%r12), %rax
movl %ebx, %ecx
xorl %esi, %esi
movb (%r14,%rsi), %dl
movb %dl, (%r13,%rsi)
leal (%rcx,%rsi), %r8d
incl %r8d
leaq 0x1(%rsi), %rdx
cmpl %r15d, %r8d
jae 0x7e248
cmpq %rsi, %rax
movq %rdx, %rsi
jne 0x7e227
subq %rdx, %r12
addq %rdx, %r14
addq %rdx, %r13
addl %edx, %ebx
cmpl %r15d, %ebx
jb 0x7e1e7
cmpq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rbx
je 0x7e29e
movq 0x190(%rdi), %rax
testq %rax, %rax
je 0x7e285
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x7e271
jmp 0x7e28c
xorl %ebp, %ebp
jmp 0x7e320
leaq 0x190(%rdi), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
movq 0x18(%rax), %r13
movl 0xc(%rax), %ebx
subl %r15d, %ebx
movq $0x0, 0xf8(%r9)
movl 0x21c(%rdi), %eax
cmpl $0xee, %eax
je 0x7e2cd
cmpl $0xe0, %eax
jne 0x7e2dd
movq %r13, %rsi
movl %r15d, %edx
movq %rbx, %rcx
callq 0x7e698
jmp 0x7e2ff
movq %r13, %rsi
movl %r15d, %edx
movq %rbx, %rcx
callq 0x7e899
jmp 0x7e2ff
movq (%rdi), %rcx
movl $0x5b, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
addl %ebx, %r15d
movq (%rdi), %rax
movl %r15d, 0x30(%rax)
movq (%rdi), %rax
movl $0x1, %esi
callq *0x8(%rax)
movq %r14, (%rbp)
movq %r12, 0x8(%rbp)
movl $0x1, %ebp
testq %rbx, %rbx
jle 0x7e320
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rax
movq %rbx, %rsi
callq *0x20(%rax)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq