// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmarker.c
// Function: next_marker
LOCAL(jboolean)
next_marker (j_decompress_ptr cinfo)
{
  int c;
  INPUT_VARS(cinfo);

  for (;;) {
    INPUT_BYTE(cinfo, c, return FALSE);
    /* Skip any non-FF bytes.
     * This may look a bit inefficient, but it will not occur in a valid file.
     * We sync after each discarded byte so that a suspending data source
     * can discard the byte from its buffer.
     */
    while (c != 0xFF) {
      cinfo->marker->discarded_bytes++;
      INPUT_SYNC(cinfo);
      INPUT_BYTE(cinfo, c, return FALSE);
    }
    /* This loop swallows any duplicate FF bytes.  Extra FFs are legal as
     * pad bytes, so don't count them in discarded_bytes.  We assume there
     * will not be so many consecutive FF bytes as to overflow a suspending
     * data source's input buffer.
     */
    do {
      INPUT_BYTE(cinfo, c, return FALSE);
    } while (c == 0xFF);
    if (c != 0)
      break;			/* found a valid marker, exit loop */
    /* Reach here if we found a stuffed-zero data sequence (FF/00).
     * Discard it and loop back to try again.
     */
    cinfo->marker->discarded_bytes += 2;
    INPUT_SYNC(cinfo);
  }

  if (cinfo->marker->discarded_bytes != 0) {
    WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
    cinfo->marker->discarded_bytes = 0;
  }

  cinfo->unread_marker = c;

  INPUT_SYNC(cinfo);
  return TRUE;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0xe5534
cmpq $0x0, 0x8(%rsp)
jne 0xe5579
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe555e
movl $0x0, 0x34(%rsp)
jmp 0xe57af
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rsp)
movzbl (%rax), %eax
movl %eax, 0x24(%rsp)
jmp 0xe55a1
cmpl $0xff, 0x24(%rsp)
je 0xe564f
movq 0x28(%rsp), %rax
movq 0x248(%rax), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x8(%rsp)
jne 0xe5624
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe5609
movl $0x0, 0x34(%rsp)
jmp 0xe57af
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rsp)
movzbl (%rax), %eax
movl %eax, 0x24(%rsp)
jmp 0xe55a1
jmp 0xe5651
jmp 0xe5653
cmpq $0x0, 0x8(%rsp)
jne 0xe5698
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xe567d
movl $0x0, 0x34(%rsp)
jmp 0xe57af
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rsp)
movzbl (%rax), %eax
movl %eax, 0x24(%rsp)
jmp 0xe56c0
cmpl $0xff, 0x24(%rsp)
je 0xe5651
cmpl $0x0, 0x24(%rsp)
je 0xe56d3
jmp 0xe5708
movq 0x28(%rsp), %rax
movq 0x248(%rax), %rax
movl 0x24(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0x24(%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0xe5532
movq 0x28(%rsp), %rax
movq 0x248(%rax), %rax
cmpl $0x0, 0x24(%rax)
je 0xe577d
movq 0x28(%rsp), %rax
movq (%rax), %rax
movl $0x74, 0x28(%rax)
movq 0x28(%rsp), %rax
movq 0x248(%rax), %rax
movl 0x24(%rax), %ecx
movq 0x28(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movl 0x24(%rsp), %ecx
movq 0x28(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x30(%rax)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
movq 0x28(%rsp), %rax
movq 0x248(%rax), %rax
movl $0x0, 0x24(%rax)
movl 0x24(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x21c(%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopl (%rax,%rax)