// File: tomfunkhouser[P]gaps/pkgs/jpeg/jddctmgr.c
// Function: start_pass
METHODDEF(void)
start_pass (j_decompress_ptr cinfo)
{
  my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  int ci, i;
  jpeg_component_info *compptr;
  int method = 0;
  inverse_DCT_method_ptr method_ptr = NULL;
  JQUANT_TBL * qtbl;

  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    /* Select the proper IDCT routine for this component's scaling */
    switch (compptr->DCT_scaled_size) {
#ifdef IDCT_SCALING_SUPPORTED
    case 1:
      method_ptr = jpeg_idct_1x1;
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
      break;
    case 2:
      method_ptr = jpeg_idct_2x2;
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
      break;
    case 4:
      method_ptr = jpeg_idct_4x4;
      method = JDCT_ISLOW;	/* jidctred uses islow-style table */
      break;
#endif
    case DCTSIZE:
      switch (cinfo->dct_method) {
#ifdef DCT_ISLOW_SUPPORTED
      case JDCT_ISLOW:
	method_ptr = jpeg_idct_islow;
	method = JDCT_ISLOW;
	break;
#endif
#ifdef DCT_IFAST_SUPPORTED
      case JDCT_IFAST:
	method_ptr = jpeg_idct_ifast;
	method = JDCT_IFAST;
	break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
      case JDCT_FLOAT:
	method_ptr = jpeg_idct_float;
	method = JDCT_FLOAT;
	break;
#endif
      default:
	ERREXIT(cinfo, JERR_NOT_COMPILED);
	break;
      }
      break;
    default:
      ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
      break;
    }
    idct->pub.inverse_DCT[ci] = method_ptr;
    /* Create multiplier table from quant table.
     * However, we can skip this if the component is uninteresting
     * or if we already built the table.  Also, if no quant table
     * has yet been saved for the component, we leave the
     * multiplier table all-zero; we'll be reading zeroes from the
     * coefficient controller's buffer anyway.
     */
    if (! compptr->component_needed || idct->cur_method[ci] == method)
      continue;
    qtbl = compptr->quant_table;
    if (qtbl == NULL)		/* happens if no data yet for component */
      continue;
    idct->cur_method[ci] = method;
    switch (method) {
#ifdef PROVIDE_ISLOW_TABLES
    case JDCT_ISLOW:
      {
	/* For LL&M IDCT method, multipliers are equal to raw quantization
	 * coefficients, but are stored as ints to ensure access efficiency.
	 */
	ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
	for (i = 0; i < DCTSIZE2; i++) {
	  ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
	}
      }
      break;
#endif
#ifdef DCT_IFAST_SUPPORTED
    case JDCT_IFAST:
      {
	/* For AA&N IDCT method, multipliers are equal to quantization
	 * coefficients scaled by scalefactor[row]*scalefactor[col], where
	 *   scalefactor[0] = 1
	 *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
	 * For integer operation, the multiplier table is to be scaled by
	 * IFAST_SCALE_BITS.
	 */
	IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
#define CONST_BITS 14
	static const INT16 aanscales[DCTSIZE2] = {
	  /* precomputed values scaled up by 14 bits */
	  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
	  22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
	  21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
	  19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
	  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
	  12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
	   8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
	   4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
	};
	SHIFT_TEMPS

	for (i = 0; i < DCTSIZE2; i++) {
	  ifmtbl[i] = (IFAST_MULT_TYPE)
	    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
				  (INT32) aanscales[i]),
		    CONST_BITS-IFAST_SCALE_BITS);
	}
      }
      break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
    case JDCT_FLOAT:
      {
	/* For float AA&N IDCT method, multipliers are equal to quantization
	 * coefficients scaled by scalefactor[row]*scalefactor[col], where
	 *   scalefactor[0] = 1
	 *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
	 */
	FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
	int row, col;
	static const double aanscalefactor[DCTSIZE] = {
	  1.0, 1.387039845, 1.306562965, 1.175875602,
	  1.0, 0.785694958, 0.541196100, 0.275899379
	};

	i = 0;
	for (row = 0; row < DCTSIZE; row++) {
	  for (col = 0; col < DCTSIZE; col++) {
	    fmtbl[i] = (FLOAT_MULT_TYPE)
	      ((double) qtbl->quantval[i] *
	       aanscalefactor[row] * aanscalefactor[col]);
	    i++;
	  }
	}
      }
      break;
#endif
    default:
      ERREXIT(cinfo, JERR_NOT_COMPILED);
      break;
    }
  }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq 0x258(%rax), %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x44(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x0, 0x54(%rsp)
movq 0x60(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, 0x48(%rsp)
movl 0x54(%rsp), %eax
movq 0x60(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xef78f
movq 0x48(%rsp), %rax
movl 0x24(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x7, %eax
ja 0xef52d
movq 0x8(%rsp), %rax
leaq 0x47f14(%rip), %rcx     # 0x137360
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x3394(%rip), %rax      # 0xf27f0
movq %rax, 0x38(%rsp)
movl $0x0, 0x44(%rsp)
jmp 0xef561
leaq 0x2fbb(%rip), %rax      # 0xf2430
movq %rax, 0x38(%rsp)
movl $0x0, 0x44(%rsp)
jmp 0xef561
leaq 0x2992(%rip), %rax      # 0xf1e20
movq %rax, 0x38(%rsp)
movl $0x0, 0x44(%rsp)
jmp 0xef561
movq 0x60(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0xef4c8
jmp 0xef4b2
movl 0x4(%rsp), %eax
subl $0x1, %eax
je 0xef4de
jmp 0xef4bd
movl 0x4(%rsp), %eax
subl $0x2, %eax
je 0xef4f4
jmp 0xef50a
leaq 0x1af1(%rip), %rax      # 0xf0fc0
movq %rax, 0x38(%rsp)
movl $0x0, 0x44(%rsp)
jmp 0xef52b
leaq 0x2bb(%rip), %rax       # 0xef7a0
movq %rax, 0x38(%rsp)
movl $0x1, 0x44(%rsp)
jmp 0xef52b
leaq 0xe15(%rip), %rax       # 0xf0310
movq %rax, 0x38(%rsp)
movl $0x2, 0x44(%rsp)
jmp 0xef52b
movq 0x60(%rsp), %rax
movq (%rax), %rax
movl $0x30, 0x28(%rax)
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x60(%rsp), %rdi
callq *%rax
jmp 0xef561
movq 0x60(%rsp), %rax
movq (%rax), %rax
movl $0x7, 0x28(%rax)
movq 0x48(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x60(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x60(%rsp), %rdi
callq *%rax
movq 0x38(%rsp), %rdx
movq 0x58(%rsp), %rax
movslq 0x54(%rsp), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq 0x48(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0xef594
movq 0x58(%rsp), %rax
movslq 0x54(%rsp), %rcx
movl 0x58(%rax,%rcx,4), %eax
cmpl 0x44(%rsp), %eax
jne 0xef599
jmp 0xef771
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0xef5b4
jmp 0xef771
movl 0x44(%rsp), %edx
movq 0x58(%rsp), %rax
movslq 0x54(%rsp), %rcx
movl %edx, 0x58(%rax,%rcx,4)
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
testl %eax, %eax
je 0xef5ee
jmp 0xef5d3
movl (%rsp), %eax
subl $0x1, %eax
je 0xef638
jmp 0xef5dd
movl (%rsp), %eax
subl $0x2, %eax
je 0xef6a3
jmp 0xef74e
movq 0x48(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x50(%rsp)
cmpl $0x40, 0x50(%rsp)
jge 0xef633
movq 0x30(%rsp), %rax
movslq 0x50(%rsp), %rcx
movzwl (%rax,%rcx,2), %edx
movq 0x28(%rsp), %rax
movslq 0x50(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0xef604
jmp 0xef76f
movq 0x48(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x50(%rsp)
cmpl $0x40, 0x50(%rsp)
jge 0xef69e
movq 0x30(%rsp), %rax
movslq 0x50(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movslq 0x50(%rsp), %rdx
leaq 0x47d11(%rip), %rcx     # 0x137380
movswq (%rcx,%rdx,2), %rcx
imulq %rcx, %rax
addq $0x800, %rax            # imm = 0x800
sarq $0xc, %rax
movl %eax, %edx
movq 0x20(%rsp), %rax
movslq 0x50(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0xef64e
jmp 0xef76f
movq 0x48(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0x8, 0x14(%rsp)
jge 0xef74c
movl $0x0, 0x10(%rsp)
cmpl $0x8, 0x10(%rsp)
jge 0xef73a
movq 0x30(%rsp), %rax
movslq 0x50(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
cvtsi2sd %eax, %xmm0
movslq 0x14(%rsp), %rcx
leaq 0x47d07(%rip), %rax     # 0x137400
mulsd (%rax,%rcx,8), %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x47cf6(%rip), %rax     # 0x137400
mulsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x18(%rsp), %rax
movslq 0x50(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xef6d4
jmp 0xef73c
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xef6c1
jmp 0xef76f
movq 0x60(%rsp), %rax
movq (%rax), %rax
movl $0x30, 0x28(%rax)
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x60(%rsp), %rdi
callq *%rax
jmp 0xef771
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x48(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x48(%rsp)
jmp 0xef414
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)
nop