// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmaster.c
// Function: prepare_for_output_pass
METHODDEF(void)
prepare_for_output_pass (j_decompress_ptr cinfo)
{
  my_master_ptr master = (my_master_ptr) cinfo->master;

  if (master->pub.is_dummy_pass) {
#ifdef QUANT_2PASS_SUPPORTED
    /* Final pass of 2-pass quantization */
    master->pub.is_dummy_pass = FALSE;
    (*cinfo->cquantize->start_pass) (cinfo, FALSE);
    (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
    (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
#else
    ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif /* QUANT_2PASS_SUPPORTED */
  } else {
    if (cinfo->quantize_colors && cinfo->colormap == NULL) {
      /* Select new quantization method */
      if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
	cinfo->cquantize = master->quantizer_2pass;
	master->pub.is_dummy_pass = TRUE;
      } else if (cinfo->enable_1pass_quant) {
	cinfo->cquantize = master->quantizer_1pass;
      } else {
	ERREXIT(cinfo, JERR_MODE_CHANGE);
      }
    }
    (*cinfo->idct->start_pass) (cinfo);
    (*cinfo->coef->start_output_pass) (cinfo);
    if (! cinfo->raw_data_out) {
      if (! master->using_merged_upsample)
	(*cinfo->cconvert->start_pass) (cinfo);
      (*cinfo->upsample->start_pass) (cinfo);
      if (cinfo->quantize_colors)
	(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
      (*cinfo->post->start_pass) (cinfo,
	    (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
      (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
    }
  }

  /* Set up progress monitor's pass info if present */
  if (cinfo->progress != NULL) {
    cinfo->progress->completed_passes = master->pass_number;
    cinfo->progress->total_passes = master->pass_number +
				    (master->pub.is_dummy_pass ? 2 : 1);
    /* In buffered-image mode, we assume one more output pass if EOI not
     * yet reached, but no more passes if EOI has been reached.
     */
    if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
      cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
    }
  }
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x220(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0xe3fa4
movq 0x8(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x10(%rsp), %rax
movq 0x270(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq *%rax
movq 0x10(%rsp), %rax
movq 0x238(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
movl $0x2, %esi
callq *%rax
movq 0x10(%rsp), %rax
movq 0x228(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
movl $0x2, %esi
callq *%rax
jmp 0xe412a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x6c(%rax)
je 0xe4049
movq 0x10(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
jne 0xe4049
movq 0x10(%rsp), %rax
cmpl $0x0, 0x74(%rax)
je 0xe4002
movq 0x10(%rsp), %rax
cmpl $0x0, 0x84(%rax)
je 0xe4002
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x270(%rax)
movq 0x8(%rsp), %rax
movl $0x1, 0x10(%rax)
jmp 0xe4047
movq 0x10(%rsp), %rax
cmpl $0x0, 0x7c(%rax)
je 0xe4024
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x270(%rax)
jmp 0xe4045
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl $0x2e, 0x28(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
jmp 0xe4047
jmp 0xe4049
movq 0x10(%rsp), %rax
movq 0x258(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
movq 0x10(%rsp), %rax
movq 0x230(%rax), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
movq 0x10(%rsp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0xe4128
movq 0x8(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0xe40a6
movq 0x10(%rsp), %rax
movq 0x268(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
movq 0x10(%rsp), %rax
movq 0x260(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
movq 0x10(%rsp), %rax
cmpl $0x0, 0x6c(%rax)
je 0xe40e5
movq 0x10(%rsp), %rax
movq 0x270(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %esi
callq *%rax
movq 0x10(%rsp), %rax
movq 0x238(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %edx
xorl %esi, %esi
movl $0x3, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %esi
callq *%rax
movq 0x10(%rsp), %rax
movq 0x228(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq *%rax
jmp 0xe412a
movq 0x10(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0xe41c5
movq 0x8(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x18(%rax)
movq 0x8(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x8(%rsp), %rax
movl 0x10(%rax), %esi
movl $0x1, %eax
movl $0x2, %edx
cmpl $0x0, %esi
cmovnel %edx, %eax
addl %eax, %ecx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x1c(%rax)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x58(%rax)
je 0xe41c3
movq 0x10(%rsp), %rax
movq 0x240(%rax), %rax
cmpl $0x0, 0x24(%rax)
jne 0xe41c3
movq 0x10(%rsp), %rax
movl 0x84(%rax), %edx
movl $0x1, %ecx
movl $0x2, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
addl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rax)
jmp 0xe41c5
addq $0x18, %rsp
retq
nopw (%rax,%rax)