// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jcmarker.c
// Function: write_scan_header
METHODDEF(void)
write_scan_header (j_compress_ptr cinfo)
{
  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  int i;
  jpeg_component_info *compptr;

  if (cinfo->arith_code) {
    /* Emit arith conditioning info.  We may have some duplication
     * if the file has multiple scans, but it's so small it's hardly
     * worth worrying about.
     */
    emit_dac(cinfo);
  } else {
    /* Emit Huffman tables.
     * Note that emit_dht() suppresses any duplicate tables.
     */
    for (i = 0; i < cinfo->comps_in_scan; i++) {
      compptr = cinfo->cur_comp_info[i];
      if (cinfo->progressive_mode) {
	/* Progressive mode: only DC or only AC tables are used in one scan */
	if (cinfo->Ss == 0) {
	  if (cinfo->Ah == 0)	/* DC needs no table for refinement scan */
	    emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
	} else {
	  emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
	}
      } else {
	/* Sequential mode: need both DC and AC tables */
	emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
	emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
      }
    }
  }

  /* Emit DRI if required --- note that DRI value could change for each scan.
   * We avoid wasting space with unnecessary DRIs, however.
   */
  if (cinfo->restart_interval != marker->last_restart_interval) {
    emit_dri(cinfo);
    marker->last_restart_interval = cinfo->restart_interval;
  }

  emit_sos(cinfo);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x1d0(%rdi), %r14
cmpl $0x0, 0x104(%rdi)
jne 0x74ddf
cmpl $0x0, 0x144(%rbx)
jle 0x74ddf
xorl %r15d, %r15d
movq 0x148(%rbx,%r15,8), %r12
cmpl $0x0, 0x134(%rbx)
je 0x74daf
cmpl $0x0, 0x19c(%rbx)
jne 0x74dbe
cmpl $0x0, 0x1a4(%rbx)
jne 0x74dd0
movl 0x14(%r12), %esi
movq %rbx, %rdi
xorl %edx, %edx
jmp 0x74dcb
movl 0x14(%r12), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x75302
movl 0x18(%r12), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x75302
incq %r15
movslq 0x144(%rbx), %rax
cmpq %rax, %r15
jl 0x74d80
movl 0x118(%rbx), %eax
cmpl 0x38(%r14), %eax
je 0x74e4f
movl $0xff, %r15d
movq %rbx, %rdi
movl $0xff, %esi
callq 0x7507b
movq %rbx, %rdi
movl $0xdd, %esi
callq 0x7507b
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7507b
movq %rbx, %rdi
movl $0x4, %esi
callq 0x7507b
movl 0x118(%rbx), %ebp
movl %ebp, %esi
shrl $0x8, %esi
andl %r15d, %esi
movq %rbx, %rdi
callq 0x7507b
andl %r15d, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7507b
movl 0x118(%rbx), %eax
movl %eax, 0x38(%r14)
movl $0xff, %r14d
movq %rbx, %rdi
movl $0xff, %esi
callq 0x7507b
movq %rbx, %rdi
movl $0xda, %esi
callq 0x7507b
movl 0x144(%rbx), %eax
leal 0x6(,%rax,2), %ebp
movl %ebp, %esi
shrl $0x8, %esi
andl %r14d, %esi
movq %rbx, %rdi
callq 0x7507b
andl %r14d, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7507b
movl 0x144(%rbx), %esi
movq %rbx, %rdi
callq 0x7507b
cmpl $0x0, 0x144(%rbx)
jle 0x74f16
xorl %r14d, %r14d
movq 0x148(%rbx,%r14,8), %r15
movl (%r15), %esi
movq %rbx, %rdi
callq 0x7507b
movl 0x14(%r15), %ecx
movl 0x18(%r15), %eax
cmpl $0x0, 0x134(%rbx)
je 0x74ef8
xorl %esi, %esi
cmpl $0x0, 0x19c(%rbx)
jne 0x74efa
xorl %eax, %eax
cmpl $0x0, 0x1a4(%rbx)
je 0x74ef8
movl 0x104(%rbx), %edx
testl %edx, %edx
cmovel %edx, %ecx
movl %ecx, %esi
shll $0x4, %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x7507b
incq %r14
movslq 0x144(%rbx), %rax
cmpq %rax, %r14
jl 0x74eb3
movl 0x19c(%rbx), %esi
movq %rbx, %rdi
callq 0x7507b
movl 0x1a0(%rbx), %esi
movq %rbx, %rdi
callq 0x7507b
movl 0x1a4(%rbx), %esi
shll $0x4, %esi
addl 0x1a8(%rbx), %esi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7507b