// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcmarker.c
// Function: write_frame_header
METHODDEF(void)
write_frame_header (j_compress_ptr cinfo)
{
  int ci, prec;
  jboolean is_baseline;
  jpeg_component_info *compptr;
  
  /* Emit DQT for each quantization table.
   * Note that emit_dqt() suppresses any duplicate tables.
   */
  prec = 0;
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  }
  /* now prec is nonzero iff there are any 16-bit quant tables. */

  /* Check for a non-baseline specification.
   * Note we assume that Huffman table numbers won't be changed later.
   */
  if (cinfo->arith_code || cinfo->progressive_mode ||
      cinfo->data_precision != 8) {
    is_baseline = FALSE;
  } else {
    is_baseline = TRUE;
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
	 ci++, compptr++) {
      if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
	is_baseline = FALSE;
    }
    if (prec && is_baseline) {
      is_baseline = FALSE;
      /* If it's baseline except for quantizer size, warn the user */
      TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
    }
  }

  /* Emit the proper SOF marker */
  if (cinfo->arith_code) {
    emit_sof(cinfo, M_SOF9);	/* SOF code for arithmetic coding */
  } else {
    if (cinfo->progressive_mode)
      emit_sof(cinfo, M_SOF2);	/* SOF code for progressive Huffman */
    else if (is_baseline)
      emit_sof(cinfo, M_SOF0);	/* SOF code for baseline implementation */
    else
      emit_sof(cinfo, M_SOF1);	/* SOF code for non-baseline Huffman file */
  }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0xd8d8a
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rax
movl 0x10(%rax), %esi
callq 0xd9490
addl 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xd8d47
movq 0x20(%rsp), %rax
cmpl $0x0, 0x104(%rax)
jne 0xd8db1
movq 0x20(%rsp), %rax
cmpl $0x0, 0x134(%rax)
jne 0xd8db1
movq 0x20(%rsp), %rax
cmpl $0x8, 0x48(%rax)
je 0xd8dbe
movl $0x0, 0x14(%rsp)
jmp 0xd8e61
movl $0x1, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0xd8e25
movq 0x8(%rsp), %rax
cmpl $0x1, 0x14(%rax)
jg 0xd8e00
movq 0x8(%rsp), %rax
cmpl $0x1, 0x18(%rax)
jle 0xd8e08
movl $0x0, 0x14(%rsp)
jmp 0xd8e0a
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xd8ddc
cmpl $0x0, 0x18(%rsp)
je 0xd8e5f
cmpl $0x0, 0x14(%rsp)
je 0xd8e5f
movl $0x0, 0x14(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x4b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq *%rax
jmp 0xd8e61
movq 0x20(%rsp), %rax
cmpl $0x0, 0x104(%rax)
je 0xd8e80
movq 0x20(%rsp), %rdi
movl $0xc9, %esi
callq 0xd9600
jmp 0xd8eca
movq 0x20(%rsp), %rax
cmpl $0x0, 0x134(%rax)
je 0xd8e9f
movq 0x20(%rsp), %rdi
movl $0xc2, %esi
callq 0xd9600
jmp 0xd8ec8
cmpl $0x0, 0x14(%rsp)
je 0xd8eb7
movq 0x20(%rsp), %rdi
movl $0xc0, %esi
callq 0xd9600
jmp 0xd8ec6
movq 0x20(%rsp), %rdi
movl $0xc1, %esi
callq 0xd9600
jmp 0xd8ec8
jmp 0xd8eca
addq $0x28, %rsp
retq
nop