// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdinput.c
// Function: initial_setup
LOCAL(void)
initial_setup (j_decompress_ptr cinfo)
/* Called once, when first SOS marker is reached */
{
  int ci;
  jpeg_component_info *compptr;

  /* Make sure image isn't bigger than I can handle */
  if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
      (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);

  /* For now, precision must match compiled-in value... */
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);

  /* Check that number of components won't exceed internal array sizes */
  if (cinfo->num_components > MAX_COMPONENTS)
    ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
	     MAX_COMPONENTS);

  /* Compute maximum sampling factors; check factor validity */
  cinfo->max_h_samp_factor = 1;
  cinfo->max_v_samp_factor = 1;
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
	compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
      ERREXIT(cinfo, JERR_BAD_SAMPLING);
    cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
				   compptr->h_samp_factor);
    cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
				   compptr->v_samp_factor);
  }

  /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
   * In the full decompressor, this will be overridden by jdmaster.c;
   * but in the transcoder, jdmaster.c is not used, so we must do it here.
   */
  cinfo->min_DCT_scaled_size = DCTSIZE;

  /* Compute dimensions of components */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    compptr->DCT_scaled_size = DCTSIZE;
    /* Size in DCT blocks */
    compptr->width_in_blocks = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
    compptr->height_in_blocks = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
    /* downsampled_width and downsampled_height will also be overridden by
     * jdmaster.c if we are doing full decompression.  The transcoder library
     * doesn't use these values, but the calling application might.
     */
    /* Size in samples */
    compptr->downsampled_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
		    (long) cinfo->max_h_samp_factor);
    compptr->downsampled_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
		    (long) cinfo->max_v_samp_factor);
    /* Mark component needed, until color conversion says otherwise */
    compptr->component_needed = TRUE;
    /* Mark no quantization table yet saved for component */
    compptr->quant_table = NULL;
  }

  /* Compute number of fully interleaved MCU rows. */
  cinfo->total_iMCU_rows = (JDIMENSION)
    jdiv_round_up((long) cinfo->image_height,
		  (long) (cinfo->max_v_samp_factor*DCTSIZE));

  /* Decide whether file contains multiple scans */
  if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
    cinfo->inputctl->has_multiple_scans = TRUE;
  else
    cinfo->inputctl->has_multiple_scans = FALSE;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
cmpq $0xffdc, %rax           # imm = 0xFFDC
jg 0xe4ae9
movq 0x20(%rsp), %rax
movl 0x30(%rax), %eax
cmpq $0xffdc, %rax           # imm = 0xFFDC
jle 0xe4b19
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x29, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xffdc, 0x2c(%rax)     # imm = 0xFFDC
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0x8, 0x128(%rax)
je 0xe4b5e
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xf, 0x28(%rax)
movq 0x20(%rsp), %rax
movl 0x128(%rax), %ecx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0xa, 0x38(%rax)
jle 0xe4bac
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1a, 0x28(%rax)
movq 0x20(%rsp), %rax
movl 0x38(%rax), %ecx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xa, 0x30(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
movl $0x1, 0x198(%rax)
movq 0x20(%rsp), %rax
movl $0x1, 0x19c(%rax)
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xe4ce2
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jle 0xe4c21
movq 0x10(%rsp), %rax
cmpl $0x4, 0x8(%rax)
jg 0xe4c21
movq 0x10(%rsp), %rax
cmpl $0x0, 0xc(%rax)
jle 0xe4c21
movq 0x10(%rsp), %rax
cmpl $0x4, 0xc(%rax)
jle 0xe4c42
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x12, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
movl 0x198(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jle 0xe4c68
movq 0x20(%rsp), %rax
movl 0x198(%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0xe4c74
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x198(%rax)
movq 0x20(%rsp), %rax
movl 0x19c(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jle 0xe4ca9
movq 0x20(%rsp), %rax
movl 0x19c(%rax), %eax
movl %eax, 0x8(%rsp)
jmp 0xe4cb5
movq 0x10(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x19c(%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x10(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x10(%rsp)
jmp 0xe4be3
movq 0x20(%rsp), %rax
movl $0x8, 0x1a0(%rax)
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xe4e31
movq 0x10(%rsp), %rax
movl $0x8, 0x24(%rax)
movq 0x20(%rsp), %rax
movl 0x30(%rax), %eax
movl %eax, %edi
movq 0x10(%rsp), %rax
movslq 0x8(%rax), %rax
imulq %rax, %rdi
movq 0x20(%rsp), %rax
movl 0x198(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, %edi
movq 0x10(%rsp), %rax
movslq 0xc(%rax), %rax
imulq %rax, %rdi
movq 0x20(%rsp), %rax
movl 0x19c(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x20(%rsp), %rax
movl 0x30(%rax), %eax
movl %eax, %edi
movq 0x10(%rsp), %rax
movslq 0x8(%rax), %rax
imulq %rax, %rdi
movq 0x20(%rsp), %rax
movslq 0x198(%rax), %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, %edi
movq 0x10(%rsp), %rax
movslq 0xc(%rax), %rax
imulq %rax, %rdi
movq 0x20(%rsp), %rax
movslq 0x19c(%rax), %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x2c(%rax)
movq 0x10(%rsp), %rax
movl $0x1, 0x30(%rax)
movq 0x10(%rsp), %rax
movq $0x0, 0x50(%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x10(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x10(%rsp)
jmp 0xe4d0a
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, %edi
movq 0x20(%rsp), %rax
movl 0x19c(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x1a4(%rax)
movq 0x20(%rsp), %rax
movl 0x1b0(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jl 0xe4e81
movq 0x20(%rsp), %rax
cmpl $0x0, 0x138(%rax)
je 0xe4e96
movq 0x20(%rsp), %rax
movq 0x240(%rax), %rax
movl $0x1, 0x20(%rax)
jmp 0xe4ea9
movq 0x20(%rsp), %rax
movq 0x240(%rax), %rax
movl $0x0, 0x20(%rax)
addq $0x28, %rsp
retq
nop