// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq 0x248(%rdi), %r9
movq 0xf8(%r9), %rax
movq 0x28(%rdi), %r13
movq (%r13), %rbp
movq 0x8(%r13), %r15
testq %rax, %rax
movq %rdi, (%rsp)
movq %r9, 0x8(%rsp)
je 0x7d443
movl 0x100(%r9), %ebx
movl 0x10(%rax), %r14d
movq %rbx, %r12
movq %rax, 0x10(%rsp)
addq 0x18(%rax), %r12
jmp 0x7d5a1
testq %r15, %r15
jne 0x7d465
callq *0x18(%r13)
testl %eax, %eax
je 0x7d656
movq (%r13), %rbp
movq 0x8(%r13), %r15
movq (%rsp), %rdi
movq 0x8(%rsp), %r9
movzbl (%rbp), %ebx
decq %r15
je 0x7d473
incq %rbp
jmp 0x7d490
callq *0x18(%r13)
testl %eax, %eax
je 0x7d656
movq (%r13), %rbp
movq 0x8(%r13), %r15
movq (%rsp), %rdi
movq 0x8(%rsp), %r9
shll $0x8, %ebx
decq %r15
movzbl (%rbp), %eax
incq %rbp
movq %rbx, %rcx
orq %rax, %rcx
leaq (%rbx,%rax), %r12
addq $-0x2, %r12
cmpq $0x2, %rcx
jb 0x7d669
movslq 0x21c(%rdi), %rax
leaq 0xb0(%r9), %rcx
cmpq $0xfe, %rax
leaq -0x2cc(%r9,%rax,4), %rax
cmoveq %rcx, %rax
movl (%rax), %r14d
cmpl %r12d, %r14d
cmovael %r12d, %r14d
movq 0x8(%rdi), %rax
leaq 0x20(%r14), %rdx
movl $0x1, %esi
callq *0x8(%rax)
movq 0x8(%rsp), %r9
movq (%rsp), %rdi
movq $0x0, (%rax)
movb 0x21c(%rdi), %cl
movb %cl, 0x8(%rax)
movl %r12d, 0xc(%rax)
movl %r14d, 0x10(%rax)
leaq 0x20(%rax), %r12
movq %r12, 0x18(%rax)
movq %rax, 0x10(%rsp)
movq %rax, 0xf8(%r9)
movl $0x0, 0x100(%r9)
xorl %ebx, %ebx
jmp 0x7d5a1
movq %rbp, (%r13)
movq %r15, 0x8(%r13)
movl %ebx, 0x100(%r9)
testq %r15, %r15
jne 0x7d564
callq *0x18(%r13)
testl %eax, %eax
je 0x7d656
movq (%r13), %rbp
movq 0x8(%r13), %r15
movq (%rsp), %rdi
movq 0x8(%rsp), %r9
cmpl %r14d, %ebx
jae 0x7d5a1
testq %r15, %r15
je 0x7d5a1
leaq -0x1(%r15), %rax
movl %ebx, %ecx
xorl %esi, %esi
movb (%rbp,%rsi), %dl
movb %dl, (%r12,%rsi)
leal (%rcx,%rsi), %r8d
incl %r8d
leaq 0x1(%rsi), %rdx
cmpl %r14d, %r8d
jae 0x7d596
cmpq %rsi, %rax
movq %rdx, %rsi
jne 0x7d576
subq %rdx, %r15
addq %rdx, %rbp
addq %rdx, %r12
addl %edx, %ebx
cmpl %r14d, %ebx
jb 0x7d533
movq 0x190(%rdi), %rax
testq %rax, %rax
je 0x7d5bf
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x7d5b2
jmp 0x7d5c6
leaq 0x190(%rdi), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
movq 0x18(%rax), %rsi
movl 0xc(%rax), %r12d
subl %r14d, %r12d
movq $0x0, 0xf8(%r9)
movl 0x21c(%rdi), %eax
cmpl $0xee, %eax
je 0x7d605
cmpl $0xe0, %eax
jne 0x7d612
movl %r14d, %edx
movq %r12, %rcx
callq 0x7d9ef
jmp 0x7d634
movl %r14d, %edx
movq %r12, %rcx
callq 0x7dc29
jmp 0x7d634
movq (%rdi), %rcx
movl $0x5b, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
addl %r12d, %r14d
movq (%rdi), %rax
movl %r14d, 0x30(%rax)
movq (%rdi), %rax
movl $0x1, %esi
callq *0x8(%rax)
movq %rbp, (%r13)
movq %r15, 0x8(%r13)
movl $0x1, %ebp
testq %r12, %r12
jle 0x7d658
movq (%rsp), %rdi
movq 0x28(%rdi), %rax
movq %r12, %rsi
callq *0x20(%rax)
jmp 0x7d658
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
xorl %esi, %esi
jmp 0x7d5d9