// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jcdctmgr.c
// Function: start_pass_fdctmgr
METHODDEF(void)
start_pass_fdctmgr (j_compress_ptr cinfo)
{
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  int ci, qtblno, i;
  jpeg_component_info *compptr;
  JQUANT_TBL * qtbl;
  DCTELEM * dtbl;

  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    qtblno = compptr->quant_tbl_no;
    /* Make sure specified quantization table is present */
    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
	cinfo->quant_tbl_ptrs[qtblno] == NULL)
      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
    qtbl = cinfo->quant_tbl_ptrs[qtblno];
    /* Compute divisors for this quant table */
    /* We may do this more than once for same table, but it's not a big deal */
    switch (cinfo->dct_method) {
#ifdef DCT_ISLOW_SUPPORTED
    case JDCT_ISLOW:
      /* For LL&M IDCT method, divisors are equal to raw quantization
       * coefficients multiplied by 8 (to counteract scaling).
       */
      if (fdct->divisors[qtblno] == NULL) {
	fdct->divisors[qtblno] = (DCTELEM *)
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				      DCTSIZE2 * SIZEOF(DCTELEM));
      }
      dtbl = fdct->divisors[qtblno];
      for (i = 0; i < DCTSIZE2; i++) {
	dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
      }
      break;
#endif
#ifdef DCT_IFAST_SUPPORTED
    case JDCT_IFAST:
      {
	/* For AA&N IDCT method, divisors 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
	 * We apply a further scale factor of 8.
	 */
#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

	if (fdct->divisors[qtblno] == NULL) {
	  fdct->divisors[qtblno] = (DCTELEM *)
	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
					DCTSIZE2 * SIZEOF(DCTELEM));
	}
	dtbl = fdct->divisors[qtblno];
	for (i = 0; i < DCTSIZE2; i++) {
	  dtbl[i] = (DCTELEM)
	    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
				  (INT32) aanscales[i]),
		    CONST_BITS-3);
	}
      }
      break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
    case JDCT_FLOAT:
      {
	/* For float AA&N IDCT method, divisors 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
	 * We apply a further scale factor of 8.
	 * What's actually stored is 1/divisor so that the inner loop can
	 * use a multiplication rather than a division.
	 */
	FAST_FLOAT * fdtbl;
	int row, col;
	static const double aanscalefactor[DCTSIZE] = {
	  1.0, 1.387039845, 1.306562965, 1.175875602,
	  1.0, 0.785694958, 0.541196100, 0.275899379
	};

	if (fdct->float_divisors[qtblno] == NULL) {
	  fdct->float_divisors[qtblno] = (FAST_FLOAT *)
	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
					DCTSIZE2 * SIZEOF(FAST_FLOAT));
	}
	fdtbl = fdct->float_divisors[qtblno];
	i = 0;
	for (row = 0; row < DCTSIZE; row++) {
	  for (col = 0; col < DCTSIZE; col++) {
	    fdtbl[i] = (FAST_FLOAT)
	      (1.0 / (((double) qtbl->quantval[i] *
		       aanscalefactor[row] * aanscalefactor[col] * 8.0)));
	    i++;
	  }
	}
      }
      break;
#endif
    default:
      ERREXIT(cinfo, JERR_NOT_COMPILED);
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x58(%rdi), %r8
movq 0x1e8(%rdi), %rax
movq %rax, 0x8(%rsp)
xorl %r9d, %r9d
leaq 0x2d6a1(%rip), %r13     # 0x9b4e0
leaq 0x2d61a(%rip), %rbp     # 0x9b460
cmpl 0x4c(%rbx), %r9d
jge 0x6e01e
movq %r9, 0x10(%rsp)
movq %r8, %r12
movl 0x10(%r8), %r14d
cmpq $0x3, %r14
ja 0x6de6c
movq 0x60(%rbx,%r14,8), %r15
testq %r15, %r15
jne 0x6de8a
movslq %r14d, %r14
movq (%rbx), %rax
movl $0x34, 0x28(%rax)
movl %r14d, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq 0x60(%rbx,%r14,8), %r15
movl 0x114(%rbx), %eax
cmpl $0x2, %eax
je 0x6df57
cmpl $0x1, %eax
je 0x6def4
testl %eax, %eax
jne 0x6dffb
movq 0x8(%rsp), %rax
movq 0x18(%rax,%r14,8), %rax
testq %rax, %rax
jne 0x6ded0
movq 0x8(%rbx), %rax
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq *(%rax)
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx,%r14,8)
xorl %ecx, %ecx
movq %r12, %r8
movq 0x10(%rsp), %r9
cmpq $0x40, %rcx
je 0x6e012
movzwl (%r15,%rcx,2), %edx
shll $0x3, %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0x6deda
movq 0x8(%rsp), %rax
movq 0x18(%rax,%r14,8), %rax
testq %rax, %rax
jne 0x6df1e
movq 0x8(%rbx), %rax
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq *(%rax)
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx,%r14,8)
xorl %ecx, %ecx
movq %r12, %r8
movq 0x10(%rsp), %r9
cmpq $0x80, %rcx
je 0x6e012
movzwl (%r15,%rcx), %edx
movswq (%rcx,%rbp), %rsi
imulq %rdx, %rsi
addq $0x400, %rsi            # imm = 0x400
shrq $0xb, %rsi
movl %esi, (%rax,%rcx,2)
addq $0x2, %rcx
jmp 0x6df28
movq 0x8(%rsp), %rax
movq 0x40(%rax,%r14,8), %rax
testq %rax, %rax
movsd 0x2528c(%rip), %xmm3    # 0x931f8
movsd 0x25094(%rip), %xmm4    # 0x93008
jne 0x6dfa1
movq 0x8(%rbx), %rax
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq *(%rax)
movsd 0x25079(%rip), %xmm4    # 0x93008
movsd 0x25261(%rip), %xmm3    # 0x931f8
movq 0x8(%rsp), %rcx
movq %rax, 0x40(%rcx,%r14,8)
xorl %ecx, %ecx
xorl %edx, %edx
movq %r12, %r8
movq 0x10(%rsp), %r9
cmpq $0x8, %rcx
je 0x6e012
movsd (%r13,%rcx,8), %xmm0
movslq %edx, %rdx
xorl %esi, %esi
cmpq $0x40, %rsi
je 0x6dff6
movzwl (%r15,%rdx,2), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm0, %xmm1
mulsd (%rsi,%r13), %xmm1
mulsd %xmm3, %xmm1
movapd %xmm4, %xmm2
divsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm1
movss %xmm1, (%rax,%rdx,4)
incq %rdx
addq $0x8, %rsi
jmp 0x6dfbf
incq %rcx
jmp 0x6dfad
movq (%rbx), %rax
movl $0x30, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
movq %r12, %r8
movq 0x10(%rsp), %r9
incl %r9d
addq $0x60, %r8
jmp 0x6de46
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq