// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmarker.c
// Function: examine_app0
LOCAL(void)
examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
	      unsigned int datalen, INT32 remaining)
/* Examine first few bytes from an APP0.
 * Take appropriate action if it is a JFIF marker.
 * datalen is # of bytes at data[], remaining is length of rest of marker data.
 */
{
  INT32 totallen = (INT32) datalen + remaining;

  if (datalen >= APP0_DATA_LEN &&
      GETJOCTET(data[0]) == 0x4A &&
      GETJOCTET(data[1]) == 0x46 &&
      GETJOCTET(data[2]) == 0x49 &&
      GETJOCTET(data[3]) == 0x46 &&
      GETJOCTET(data[4]) == 0) {
    /* Found JFIF APP0 marker: save info */
    cinfo->saw_JFIF_marker = TRUE;
    cinfo->JFIF_major_version = GETJOCTET(data[5]);
    cinfo->JFIF_minor_version = GETJOCTET(data[6]);
    cinfo->density_unit = GETJOCTET(data[7]);
    cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
    cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
    /* Check version.
     * Major version must be 1, anything else signals an incompatible change.
     * (We used to treat this as an error, but now it's a nonfatal warning,
     * because some bozo at Hijaak couldn't read the spec.)
     * Minor version should be 0..2, but process anyway if newer.
     */
    if (cinfo->JFIF_major_version != 1)
      WARNMS2(cinfo, JWRN_JFIF_MAJOR,
	      cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
    /* Generate trace messages */
    TRACEMS5(cinfo, 1, JTRC_JFIF,
	     cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
	     cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
    /* Validate thumbnail dimensions and issue appropriate messages */
    if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
      TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
	       GETJOCTET(data[12]), GETJOCTET(data[13]));
    totallen -= APP0_DATA_LEN;
    if (totallen !=
	((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
      TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  } else if (datalen >= 6 &&
      GETJOCTET(data[0]) == 0x4A &&
      GETJOCTET(data[1]) == 0x46 &&
      GETJOCTET(data[2]) == 0x58 &&
      GETJOCTET(data[3]) == 0x58 &&
      GETJOCTET(data[4]) == 0) {
    /* Found JFIF "JFXX" extension APP0 marker */
    /* The library doesn't actually do anything with these,
     * but we try to produce a helpful trace message.
     */
    switch (GETJOCTET(data[5])) {
    case 0x10:
      TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
      break;
    case 0x11:
      TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
      break;
    case 0x13:
      TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
      break;
    default:
      TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
	       GETJOCTET(data[5]), (int) totallen);
      break;
    }
  } else {
    /* Start of APP0 does not match "JFIF" or "JFXX", or too short */
    TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movq %rcx, 0x18(%rsp)
movl 0x24(%rsp), %eax
addq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0xe, 0x24(%rsp)
jb 0xe8e08
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x4a, %eax
jne 0xe8e08
movq 0x28(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x46, %eax
jne 0xe8e08
movq 0x28(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x49, %eax
jne 0xe8e08
movq 0x28(%rsp), %rax
movzbl 0x3(%rax), %eax
cmpl $0x46, %eax
jne 0xe8e08
movq 0x28(%rsp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0xe8e08
movq 0x30(%rsp), %rax
movl $0x1, 0x174(%rax)
movq 0x28(%rsp), %rax
movb 0x5(%rax), %cl
movq 0x30(%rsp), %rax
movb %cl, 0x178(%rax)
movq 0x28(%rsp), %rax
movb 0x6(%rax), %cl
movq 0x30(%rsp), %rax
movb %cl, 0x179(%rax)
movq 0x28(%rsp), %rax
movb 0x7(%rax), %cl
movq 0x30(%rsp), %rax
movb %cl, 0x17a(%rax)
movq 0x28(%rsp), %rax
movzbl 0x8(%rax), %eax
shll $0x8, %eax
movq 0x28(%rsp), %rcx
movzbl 0x9(%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x17c(%rax)
movq 0x28(%rsp), %rax
movzbl 0xa(%rax), %eax
shll $0x8, %eax
movq 0x28(%rsp), %rcx
movzbl 0xb(%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x17e(%rax)
movq 0x30(%rsp), %rax
movzbl 0x178(%rax), %eax
cmpl $0x1, %eax
je 0xe8c93
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x77, 0x28(%rax)
movq 0x30(%rsp), %rax
movzbl 0x178(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movzbl 0x179(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x30(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
jmp 0xe8c95
movq 0x30(%rsp), %rax
movq (%rax), %rax
addq $0x2c, %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rax
movzbl 0x178(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movzbl 0x179(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x30(%rsp), %rax
movzwl 0x17c(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x30(%rsp), %rax
movzwl 0x17e(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x30(%rsp), %rax
movzbl 0x17a(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x57, 0x28(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
movq 0x28(%rsp), %rax
movzbl 0xc(%rax), %eax
movq 0x28(%rsp), %rcx
movzbl 0xd(%rcx), %ecx
orl %ecx, %eax
cmpl $0x0, %eax
je 0xe8d98
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x5a, 0x28(%rax)
movq 0x28(%rsp), %rax
movzbl 0xc(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x28(%rsp), %rax
movzbl 0xd(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x30(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
movq 0x10(%rsp), %rax
subq $0xe, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
movzbl 0xc(%rcx), %ecx
movq 0x28(%rsp), %rdx
movzbl 0xd(%rdx), %edx
imulq %rdx, %rcx
imulq $0x3, %rcx, %rcx
cmpq %rcx, %rax
je 0xe8e03
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x58, 0x28(%rax)
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe8fde
cmpl $0x6, 0x24(%rsp)
jb 0xe8fa3
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x4a, %eax
jne 0xe8fa3
movq 0x28(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x46, %eax
jne 0xe8fa3
movq 0x28(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x58, %eax
jne 0xe8fa3
movq 0x28(%rsp), %rax
movzbl 0x3(%rax), %eax
cmpl $0x58, %eax
jne 0xe8fa3
movq 0x28(%rsp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0xe8fa3
movq 0x28(%rsp), %rax
movzbl 0x5(%rax), %eax
movl %eax, 0x4(%rsp)
subl $0x10, %eax
je 0xe8e9d
jmp 0xe8e80
movl 0x4(%rsp), %eax
subl $0x11, %eax
je 0xe8edb
jmp 0xe8e8b
movl 0x4(%rsp), %eax
subl $0x13, %eax
je 0xe8f19
jmp 0xe8f54
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x6c, 0x28(%rax)
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe8fa1
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x6d, 0x28(%rax)
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe8fa1
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x6e, 0x28(%rax)
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe8fa1
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x59, 0x28(%rax)
movq 0x28(%rsp), %rax
movzbl 0x5(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x30(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe8fdc
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x4d, 0x28(%rax)
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0xe8fde
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)