// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jcdctmgr.c
// Function: forward_DCT
METHODDEF(void)
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
	     JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
	     JDIMENSION start_row, JDIMENSION start_col,
	     JDIMENSION num_blocks)
/* This version is used for integer DCT implementations. */
{
  /* This routine is heavily used, so it's worth coding it tightly. */
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  forward_DCT_method_ptr do_dct = fdct->do_dct;
  DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  DCTELEM workspace[DCTSIZE2];	/* work area for FDCT subroutine */
  JDIMENSION bi;

  sample_data += start_row;	/* fold in the vertical offset once */

  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
    /* Load data into workspace, applying unsigned->signed conversion */
    { register DCTELEM *workspaceptr;
      register JSAMPROW elemptr;
      register int elemr;

      workspaceptr = workspace;
      for (elemr = 0; elemr < DCTSIZE; elemr++) {
	elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8		/* unroll the inner loop */
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
#else
	{ register int elemc;
	  for (elemc = DCTSIZE; elemc > 0; elemc--) {
	    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
	  }
	}
#endif
      }
    }

    /* Perform the DCT */
    (*do_dct) (workspace);

    /* Quantize/descale the coefficients, and store into coef_blocks[] */
    { register DCTELEM temp, qval;
      register int i;
      register JCOEFPTR output_ptr = coef_blocks[bi];

      for (i = 0; i < DCTSIZE2; i++) {
	qval = divisors[i];
	temp = workspace[i];
	/* Divide the coefficient value by qval, ensuring proper rounding.
	 * Since C does not specify the direction of rounding for negative
	 * quotients, we have to force the dividend positive for portability.
	 *
	 * In most files, at least half of the output values will be zero
	 * (at default quantization settings, more like three-quarters...)
	 * so we should ensure that this case is fast.  On many machines,
	 * a comparison is enough cheaper than a divide to make a special test
	 * a win.  Since both inputs will be nonnegative, we need only test
	 * for a < b to discover whether a/b is 0.
	 * If your machine's division is fast enough, define FAST_DIVIDE.
	 */
#ifdef FAST_DIVIDE
#define DIVIDE_BY(a,b)	a /= b
#else
#define DIVIDE_BY(a,b)	if (a >= b) a /= b; else a = 0
#endif
	if (temp < 0) {
	  temp = -temp;
	  temp += qval>>1;	/* for rounding */
	  DIVIDE_BY(temp, qval);
	  temp = -temp;
	} else {
	  temp += qval>>1;	/* for rounding */
	  DIVIDE_BY(temp, qval);
	}
	output_ptr[i] = (JCOEF) temp;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl 0x150(%rsp), %eax
testl %eax, %eax
je 0x7a337
movl %r9d, %ebx
movq %rcx, %r14
movq 0x1e8(%rdi), %rcx
movq 0x10(%rcx), %rdi
movq %rdi, 0x8(%rsp)
movslq 0x10(%rsi), %rsi
movq 0x18(%rcx,%rsi,8), %r13
movl %r8d, %ecx
leaq (%rdx,%rcx,8), %rbp
movl %eax, %r15d
xorl %r12d, %r12d
movl %ebx, %ebx
xorl %eax, %eax
movq (%rbp,%rax), %rcx
movzbl (%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x10(%rsp,%rax,4)
movzbl 0x1(%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x14(%rsp,%rax,4)
movzbl 0x2(%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x18(%rsp,%rax,4)
movzbl 0x3(%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x1c(%rsp,%rax,4)
movzbl 0x4(%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x20(%rsp,%rax,4)
movzbl 0x5(%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x24(%rsp,%rax,4)
movzbl 0x6(%rcx,%rbx), %edx
addl $-0x80, %edx
movl %edx, 0x28(%rsp,%rax,4)
movzbl 0x7(%rcx,%rbx), %ecx
addl $-0x80, %ecx
movl %ecx, 0x2c(%rsp,%rax,4)
addq $0x8, %rax
cmpq $0x40, %rax
jne 0x7a26e
leaq 0x10(%rsp), %rdi
callq *0x8(%rsp)
xorl %esi, %esi
movl (%r13,%rsi,4), %edi
movl 0x10(%rsp,%rsi,4), %ecx
movl %edi, %edx
sarl %edx
testl %ecx, %ecx
js 0x7a307
addl %edx, %ecx
xorl %eax, %eax
cmpl %edi, %ecx
jl 0x7a316
movl %ecx, %eax
cltd
idivl %edi
jmp 0x7a316
subl %ecx, %edx
xorl %eax, %eax
cmpl %edi, %edx
jl 0x7a314
movl %edx, %eax
cltd
idivl %edi
negl %eax
movw %ax, (%r14,%rsi,2)
incq %rsi
cmpq $0x40, %rsi
jne 0x7a2e7
incq %r12
addl $0x8, %ebx
subq $-0x80, %r14
cmpq %r15, %r12
jne 0x7a26a
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq