// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmarker.c
// Function: read_markers
METHODDEF(int)
read_markers (j_decompress_ptr cinfo)
{
  /* Outer loop repeats once for each marker. */
  for (;;) {
    /* Collect the marker proper, unless we already did. */
    /* NB: first_marker() enforces the requirement that SOI appear first. */
    if (cinfo->unread_marker == 0) {
      if (! cinfo->marker->saw_SOI) {
	if (! first_marker(cinfo))
	  return JPEG_SUSPENDED;
      } else {
	if (! next_marker(cinfo))
	  return JPEG_SUSPENDED;
      }
    }
    /* At this point cinfo->unread_marker contains the marker code and the
     * input point is just past the marker proper, but before any parameters.
     * A suspension will cause us to return with this state still true.
     */
    switch (cinfo->unread_marker) {
    case M_SOI:
      if (! get_soi(cinfo))
	return JPEG_SUSPENDED;
      break;

    case M_SOF0:		/* Baseline */
    case M_SOF1:		/* Extended sequential, Huffman */
      if (! get_sof(cinfo, FALSE, FALSE))
	return JPEG_SUSPENDED;
      break;

    case M_SOF2:		/* Progressive, Huffman */
      if (! get_sof(cinfo, TRUE, FALSE))
	return JPEG_SUSPENDED;
      break;

    case M_SOF9:		/* Extended sequential, arithmetic */
      if (! get_sof(cinfo, FALSE, TRUE))
	return JPEG_SUSPENDED;
      break;

    case M_SOF10:		/* Progressive, arithmetic */
      if (! get_sof(cinfo, TRUE, TRUE))
	return JPEG_SUSPENDED;
      break;

    /* Currently unsupported SOFn types */
    case M_SOF3:		/* Lossless, Huffman */
    case M_SOF5:		/* Differential sequential, Huffman */
    case M_SOF6:		/* Differential progressive, Huffman */
    case M_SOF7:		/* Differential lossless, Huffman */
    case M_JPG:			/* Reserved for JPEG extensions */
    case M_SOF11:		/* Lossless, arithmetic */
    case M_SOF13:		/* Differential sequential, arithmetic */
    case M_SOF14:		/* Differential progressive, arithmetic */
    case M_SOF15:		/* Differential lossless, arithmetic */
      ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
      break;

    case M_SOS:
      if (! get_sos(cinfo))
	return JPEG_SUSPENDED;
      cinfo->unread_marker = 0;	/* processed the marker */
      return JPEG_REACHED_SOS;
    
    case M_EOI:
      TRACEMS(cinfo, 1, JTRC_EOI);
      cinfo->unread_marker = 0;	/* processed the marker */
      return JPEG_REACHED_EOI;
      
    case M_DAC:
      if (! get_dac(cinfo))
	return JPEG_SUSPENDED;
      break;
      
    case M_DHT:
      if (! get_dht(cinfo))
	return JPEG_SUSPENDED;
      break;
      
    case M_DQT:
      if (! get_dqt(cinfo))
	return JPEG_SUSPENDED;
      break;
      
    case M_DRI:
      if (! get_dri(cinfo))
	return JPEG_SUSPENDED;
      break;
      
    case M_APP0:
    case M_APP1:
    case M_APP2:
    case M_APP3:
    case M_APP4:
    case M_APP5:
    case M_APP6:
    case M_APP7:
    case M_APP8:
    case M_APP9:
    case M_APP10:
    case M_APP11:
    case M_APP12:
    case M_APP13:
    case M_APP14:
    case M_APP15:
      if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[
		cinfo->unread_marker - (int) M_APP0]) (cinfo))
	return JPEG_SUSPENDED;
      break;
      
    case M_COM:
      if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
	return JPEG_SUSPENDED;
      break;

    case M_RST0:		/* these are all parameterless */
    case M_RST1:
    case M_RST2:
    case M_RST3:
    case M_RST4:
    case M_RST5:
    case M_RST6:
    case M_RST7:
    case M_TEM:
      TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
      break;

    case M_DNL:			/* Ignore DNL ... perhaps the wrong thing */
      if (! skip_variable(cinfo))
	return JPEG_SUSPENDED;
      break;

    default:			/* must be DHP, EXP, JPGn, or RESn */
      /* For now, we treat the reserved markers as fatal errors since they are
       * likely to be used to signal incompatible JPEG Part 3 extensions.
       * Once the JPEG 3 version-number marker is well defined, this code
       * ought to change!
       */
      ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
      break;
    }
    /* Successfully processed marker, so reset state variable */
    cinfo->unread_marker = 0;
  } /* end loop */
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x21c(%rax)
jne 0xe59a7
movq 0x8(%rsp), %rax
movq 0x248(%rax), %rax
cmpl $0x0, 0x18(%rax)
jne 0xe5987
movq 0x8(%rsp), %rdi
callq 0xe6a30
cmpl $0x0, %eax
jne 0xe5985
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe59a5
movq 0x8(%rsp), %rdi
callq 0xe5500
cmpl $0x0, %eax
jne 0xe59a3
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe59a5
jmp 0xe59a7
movq 0x8(%rsp), %rax
movl 0x21c(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0xfd, %eax
ja 0xe5c9d
movq (%rsp), %rax
leaq 0x5148c(%rip), %rcx     # 0x136e5c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rdi
callq 0xe6bd0
cmpl $0x0, %eax
jne 0xe59f5
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xe6d40
cmpl $0x0, %eax
jne 0xe5a1a
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xe6d40
cmpl $0x0, %eax
jne 0xe5a42
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xe6d40
cmpl $0x0, %eax
jne 0xe5a6a
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0xe6d40
cmpl $0x0, %eax
jne 0xe5a92
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl $0x3c, 0x28(%rax)
movq 0x8(%rsp), %rax
movl 0x21c(%rax), %ecx
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rdi
callq *%rax
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
callq 0xe7520
cmpl $0x0, %eax
jne 0xe5aef
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
movq 0x8(%rsp), %rax
movl $0x0, 0x21c(%rax)
movl $0x1, 0x14(%rsp)
jmp 0xe5ce8
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl $0x55, 0x28(%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rsp), %rdi
movl $0x1, %esi
callq *%rax
movq 0x8(%rsp), %rax
movl $0x0, 0x21c(%rax)
movl $0x2, 0x14(%rsp)
jmp 0xe5ce8
movq 0x8(%rsp), %rdi
callq 0xe5e20
cmpl $0x0, %eax
jne 0xe5b6a
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
callq 0xe7be0
cmpl $0x0, %eax
jne 0xe5b8b
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
callq 0xe82b0
cmpl $0x0, %eax
jne 0xe5bac
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
callq 0xe8890
cmpl $0x0, %eax
jne 0xe5bcd
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rax
movq 0x248(%rax), %rax
movq 0x8(%rsp), %rcx
movl 0x21c(%rcx), %ecx
subl $0xe0, %ecx
movslq %ecx, %rcx
movq 0x30(%rax,%rcx,8), %rax
movq 0x8(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe5c10
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rax
movq 0x248(%rax), %rax
movq 0x28(%rax), %rax
movq 0x8(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe5c3e
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl $0x5c, 0x28(%rax)
movq 0x8(%rsp), %rax
movl 0x21c(%rax), %ecx
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe5cd4
movq 0x8(%rsp), %rdi
callq 0xe5e20
cmpl $0x0, %eax
jne 0xe5c9b
movl $0x0, 0x14(%rsp)
jmp 0xe5ce8
jmp 0xe5cd4
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl $0x44, 0x28(%rax)
movq 0x8(%rsp), %rax
movl 0x21c(%rax), %ecx
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rdi
callq *%rax
movq 0x8(%rsp), %rax
movl $0x0, 0x21c(%rax)
jmp 0xe5949
movl 0x14(%rsp), %eax
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)