// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jidctint.c
// Function: jpeg_idct_islow
GLOBAL(void)
jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
		 JCOEFPTR coef_block,
		 JSAMPARRAY output_buf, JDIMENSION output_col)
{
  INT32 tmp0, tmp1, tmp2, tmp3;
  INT32 tmp10, tmp11, tmp12, tmp13;
  INT32 z1, z2, z3, z4, z5;
  JCOEFPTR inptr;
  ISLOW_MULT_TYPE * quantptr;
  int * wsptr;
  JSAMPROW outptr;
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  int ctr;
  int workspace[DCTSIZE2];	/* buffers data between passes */
  SHIFT_TEMPS

  /* Pass 1: process columns from input, store into work array. */
  /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
  /* furthermore, we scale the results by 2**PASS1_BITS. */

  inptr = coef_block;
  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  wsptr = workspace;
  for (ctr = DCTSIZE; ctr > 0; ctr--) {
    /* Due to quantization, we will usually find that many of the input
     * coefficients are zero, especially the AC terms.  We can exploit this
     * by short-circuiting the IDCT calculation for any column in which all
     * the AC terms are zero.  In that case each output is equal to the
     * DC coefficient (with scale factor as needed).
     * With typical images and quantization tables, half or more of the
     * column DCT calculations can be simplified this way.
     */
    
    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
	inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
	inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
	inptr[DCTSIZE*7] == 0) {
      /* AC terms all zero */
      int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
      
      wsptr[DCTSIZE*0] = dcval;
      wsptr[DCTSIZE*1] = dcval;
      wsptr[DCTSIZE*2] = dcval;
      wsptr[DCTSIZE*3] = dcval;
      wsptr[DCTSIZE*4] = dcval;
      wsptr[DCTSIZE*5] = dcval;
      wsptr[DCTSIZE*6] = dcval;
      wsptr[DCTSIZE*7] = dcval;
      
      inptr++;			/* advance pointers to next column */
      quantptr++;
      wsptr++;
      continue;
    }
    
    /* Even part: reverse the even part of the forward DCT. */
    /* The rotator is sqrt(2)*c(-6). */
    
    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
    
    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
    tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
    tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
    
    z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
    z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);

    tmp0 = (z2 + z3) << CONST_BITS;
    tmp1 = (z2 - z3) << CONST_BITS;
    
    tmp10 = tmp0 + tmp3;
    tmp13 = tmp0 - tmp3;
    tmp11 = tmp1 + tmp2;
    tmp12 = tmp1 - tmp2;
    
    /* Odd part per figure 8; the matrix is unitary and hence its
     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.
     */
    
    tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
    tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
    tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
    tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
    
    z1 = tmp0 + tmp3;
    z2 = tmp1 + tmp2;
    z3 = tmp0 + tmp2;
    z4 = tmp1 + tmp3;
    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
    
    tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
    tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
    tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
    tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
    
    z3 += z5;
    z4 += z5;
    
    tmp0 += z1 + z3;
    tmp1 += z2 + z4;
    tmp2 += z2 + z3;
    tmp3 += z1 + z4;
    
    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
    
    wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
    wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
    
    inptr++;			/* advance pointers to next column */
    quantptr++;
    wsptr++;
  }
  
  /* Pass 2: process rows from work array, store into output array. */
  /* Note that we must descale the results by a factor of 8 == 2**3, */
  /* and also undo the PASS1_BITS scaling. */

  wsptr = workspace;
  for (ctr = 0; ctr < DCTSIZE; ctr++) {
    outptr = output_buf[ctr] + output_col;
    /* Rows of zeroes can be exploited in the same way as we did with columns.
     * However, the column calculation has created many nonzero AC terms, so
     * the simplification applies less often (typically 5% to 10% of the time).
     * On machines with very fast multiplication, it's possible that the
     * test takes more time than it's worth.  In that case this section
     * may be commented out.
     */
    
#ifndef NO_ZERO_ROW_TEST
    if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
	wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
      /* AC terms all zero */
      JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
				  & RANGE_MASK];
      
      outptr[0] = dcval;
      outptr[1] = dcval;
      outptr[2] = dcval;
      outptr[3] = dcval;
      outptr[4] = dcval;
      outptr[5] = dcval;
      outptr[6] = dcval;
      outptr[7] = dcval;

      wsptr += DCTSIZE;		/* advance pointer to next row */
      continue;
    }
#endif
    
    /* Even part: reverse the even part of the forward DCT. */
    /* The rotator is sqrt(2)*c(-6). */
    
    z2 = (INT32) wsptr[2];
    z3 = (INT32) wsptr[6];
    
    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
    tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
    tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
    
    tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
    tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
    
    tmp10 = tmp0 + tmp3;
    tmp13 = tmp0 - tmp3;
    tmp11 = tmp1 + tmp2;
    tmp12 = tmp1 - tmp2;
    
    /* Odd part per figure 8; the matrix is unitary and hence its
     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.
     */
    
    tmp0 = (INT32) wsptr[7];
    tmp1 = (INT32) wsptr[5];
    tmp2 = (INT32) wsptr[3];
    tmp3 = (INT32) wsptr[1];
    
    z1 = tmp0 + tmp3;
    z2 = tmp1 + tmp2;
    z3 = tmp0 + tmp2;
    z4 = tmp1 + tmp3;
    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
    
    tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
    tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
    tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
    tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
    
    z3 += z5;
    z4 += z5;
    
    tmp0 += z1 + z3;
    tmp1 += z2 + z4;
    tmp2 += z2 + z3;
    tmp3 += z1 + z4;
    
    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
    
    outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
					  CONST_BITS+PASS1_BITS+3)
			    & RANGE_MASK];
    
    wsptr += DCTSIZE;		/* advance pointer to next row */
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, -0x78(%rsp)
movq %rcx, -0x68(%rsp)
movq 0x1a8(%rdi), %rax
movq %rax, -0x70(%rsp)
movq 0x58(%rsi), %rsi
xorl %edi, %edi
cmpl $0x8, %edi
je 0x759bd
movswq 0x10(%rdx,%rdi,2), %rbx
movzwl 0x20(%rdx,%rdi,2), %ecx
movl %ecx, %r9d
orw %bx, %r9w
jne 0x757d0
cmpw $0x0, 0x30(%rdx,%rdi,2)
jne 0x757ce
cmpw $0x0, 0x40(%rdx,%rdi,2)
jne 0x757ce
cmpw $0x0, 0x50(%rdx,%rdi,2)
jne 0x757ce
cmpw $0x0, 0x60(%rdx,%rdi,2)
jne 0x757ce
cmpw $0x0, 0x70(%rdx,%rdi,2)
je 0x75990
xorl %ecx, %ecx
movslq 0x40(%rsi,%rdi,4), %r9
movswq %cx, %rcx
imulq %r9, %rcx
movswq 0x60(%rdx,%rdi,2), %r9
movslq 0xc0(%rsi,%rdi,4), %r10
imulq %r9, %r10
leaq (%r10,%rcx), %r9
imulq $0x1151, %r9, %r9       # imm = 0x1151
imulq $-0x3b21, %r10, %r11    # imm = 0xC4DF
addq %r9, %r11
imulq $0x187e, %rcx, %r15     # imm = 0x187E
addq %r9, %r15
movswq (%rdx,%rdi,2), %rcx
movslq (%rsi,%rdi,4), %r10
imulq %rcx, %r10
movswq 0x40(%rdx,%rdi,2), %rcx
movslq 0x80(%rsi,%rdi,4), %r9
imulq %rcx, %r9
leaq (%r9,%r10), %r14
subq %r9, %r10
movswq 0x70(%rdx,%rdi,2), %rcx
movslq 0xe0(%rsi,%rdi,4), %r12
imulq %rcx, %r12
movswq 0x50(%rdx,%rdi,2), %rcx
movslq 0xa0(%rsi,%rdi,4), %r13
imulq %rcx, %r13
movswq 0x30(%rdx,%rdi,2), %rcx
movslq 0x60(%rsi,%rdi,4), %rbp
imulq %rcx, %rbp
movslq 0x20(%rsi,%rdi,4), %r9
imulq %rbx, %r9
leaq (%r12,%rbp), %rcx
leaq (%r9,%r13), %rbx
leaq (%rbx,%rcx), %r8
imulq $0x25a1, %r8, %r8       # imm = 0x25A1
imulq $-0x3ec5, %rcx, %rax    # imm = 0xC13B
imulq $-0xc7c, %rbx, %rcx     # imm = 0xF384
addq %r8, %rax
addq %r8, %rcx
movq %rbp, %r8
addq %r13, %r8
imulq $0x41b3, %r13, %r13     # imm = 0x41B3
imulq $0x6254, %rbp, %rbp     # imm = 0x6254
imulq $-0x5203, %r8, %r8      # imm = 0xADFD
addq %r8, %r13
addq %r8, %rbp
leaq (%r9,%r12), %r8
imulq $0x98e, %r12, %r12      # imm = 0x98E
imulq $-0x1ccd, %r8, %r8      # imm = 0xE333
addq %r8, %r12
addq %rax, %r12
addq %rax, %rbp
imulq $0x300b, %r9, %rax      # imm = 0x300B
addq %r8, %rax
shlq $0xd, %r14
addq %rcx, %r13
addq %rcx, %rax
movq %r14, %rbx
subq %r15, %rbx
movl $0x400, %r8d            # imm = 0x400
addq %r8, %r14
addq %r15, %r14
leaq (%r14,%rax), %rcx
shrq $0xb, %rcx
movl %ecx, -0x60(%rsp,%rdi,4)
subq %rax, %r14
shlq $0xd, %r10
shrq $0xb, %r14
movl %r14d, 0x80(%rsp,%rdi,4)
movq %r10, %rax
subq %r11, %rax
addq %r8, %r10
addq %r11, %r10
leaq (%r10,%rbp), %rcx
shrq $0xb, %rcx
movl %ecx, -0x40(%rsp,%rdi,4)
subq %rbp, %r10
shrq $0xb, %r10
movl %r10d, 0x60(%rsp,%rdi,4)
leaq (%rax,%r13), %rcx
addq $0x400, %rcx            # imm = 0x400
shrq $0xb, %rcx
movl %ecx, -0x20(%rsp,%rdi,4)
addq %r8, %rax
subq %r13, %rax
shrq $0xb, %rax
movl %eax, 0x40(%rsp,%rdi,4)
leaq (%rbx,%r12), %rax
addq $0x400, %rax            # imm = 0x400
shrq $0xb, %rax
movl %eax, (%rsp,%rdi,4)
addq %r8, %rbx
subq %r12, %rbx
shrq $0xb, %rbx
movl $0x80, %ecx
leaq (%rsp,%rcx), %rax
addq $-0x60, %rax
movl %ebx, (%rax,%rdi,4)
incq %rdi
jmp 0x75785
movswl (%rdx,%rdi,2), %ebx
imull (%rsi,%rdi,4), %ebx
shll $0x2, %ebx
movl %ebx, -0x60(%rsp,%rdi,4)
movl %ebx, -0x40(%rsp,%rdi,4)
movl %ebx, -0x20(%rsp,%rdi,4)
movl %ebx, (%rsp,%rdi,4)
movl %ebx, 0x20(%rsp,%rdi,4)
movl %ebx, 0x40(%rsp,%rdi,4)
movl %ebx, 0x60(%rsp,%rdi,4)
movl $0xe0, %ecx
jmp 0x7597d
movl -0x78(%rsp), %eax
movq %rax, -0x78(%rsp)
movabsq $0x7, %r10
movl $0x20000, %edi          # imm = 0x20000
movl $0x3ff, %r8d            # imm = 0x3FF
cmpq $0x47, %r10
je 0x75c0d
movq -0x68(%rsp), %rax
movq -0x7(%rax,%r10), %r11
addq -0x78(%rsp), %r11
movl -0x78(%rsp,%r10,4), %r12d
movl -0x74(%rsp,%r10,4), %esi
movl %esi, %eax
orl %r12d, %eax
jne 0x75a33
xorl %esi, %esi
cmpl $0x0, -0x70(%rsp,%r10,4)
jne 0x75a33
cmpl $0x0, -0x6c(%rsp,%r10,4)
jne 0x75a33
cmpl $0x0, -0x68(%rsp,%r10,4)
jne 0x75a33
cmpl $0x0, -0x64(%rsp,%r10,4)
jne 0x75a33
cmpl $0x0, -0x60(%rsp,%r10,4)
je 0x75bc6
movl -0x64(%rsp,%r10,4), %eax
leal (%rax,%rsi), %edx
imull $0x1151, %edx, %edx     # imm = 0x1151
imull $0xffffc4df, %eax, %ebp # imm = 0xFFFFC4DF
addl %edx, %ebp
imull $0x187e, %esi, %esi     # imm = 0x187E
addl %edx, %esi
movl -0x6c(%rsp,%r10,4), %eax
movl -0x7c(%rsp,%r10,4), %ebx
movl -0x70(%rsp,%r10,4), %r9d
leal (%rax,%rbx), %r14d
subl %eax, %ebx
movl -0x60(%rsp,%r10,4), %r15d
movl -0x68(%rsp,%r10,4), %r13d
leal (%r9,%r15), %eax
leal (%r12,%r13), %edx
leal (%rax,%rdx), %ecx
imull $0x25a1, %ecx, %ecx     # imm = 0x25A1
imull $0xffffc13b, %eax, %eax # imm = 0xFFFFC13B
imull $0xfffff384, %edx, %edx # imm = 0xFFFFF384
addl %ecx, %eax
addl %ecx, %edx
leal (%r9,%r13), %ecx
imull $0x41b3, %r13d, %r13d   # imm = 0x41B3
imull $0x6254, %r9d, %r9d     # imm = 0x6254
imull $0xffffadfd, %ecx, %ecx # imm = 0xFFFFADFD
addl %ecx, %r13d
addl %ecx, %r9d
leal (%r15,%r12), %ecx
imull $0x98e, %r15d, %r15d    # imm = 0x98E
imull $0xffffe333, %ecx, %ecx # imm = 0xFFFFE333
addl %ecx, %r15d
addl %eax, %r15d
addl %eax, %r9d
imull $0x300b, %r12d, %eax    # imm = 0x300B
addl %ecx, %eax
shll $0xd, %r14d
shll $0xd, %ebx
addl %edx, %r13d
addl %edx, %eax
movl %r14d, %r12d
subl %esi, %r12d
addl %edi, %r14d
addl %esi, %r14d
leal (%r14,%rax), %esi
subl %eax, %r14d
movl %ebx, %edx
subl %ebp, %edx
addl %edi, %ebx
addl %ebp, %ebx
leal (%rbx,%r9), %ebp
subl %r9d, %ebx
leal (%rdx,%r13), %eax
addl $0x20000, %eax          # imm = 0x20000
addl %edi, %edx
subl %r13d, %edx
shrl $0x12, %esi
andl %r8d, %esi
movq -0x70(%rsp), %r9
movb 0x80(%r9,%rsi), %cl
movb %cl, (%r11)
shrl $0x12, %r14d
andl %r8d, %r14d
movb 0x80(%r9,%r14), %cl
movb %cl, 0x7(%r11)
shrl $0x12, %ebp
andl %r8d, %ebp
movb 0x80(%r9,%rbp), %cl
movb %cl, 0x1(%r11)
shrl $0x12, %ebx
andl %r8d, %ebx
movb 0x80(%r9,%rbx), %cl
movb %cl, 0x6(%r11)
shrl $0x12, %eax
andl %r8d, %eax
movb 0x80(%r9,%rax), %al
movb %al, 0x2(%r11)
shrl $0x12, %edx
andl %r8d, %edx
movb 0x80(%r9,%rdx), %al
movb %al, 0x5(%r11)
leal (%r12,%r15), %eax
addl $0x20000, %eax          # imm = 0x20000
shrl $0x12, %eax
andl %r8d, %eax
movb 0x80(%r9,%rax), %al
movb %al, 0x3(%r11)
addl %edi, %r12d
subl %r15d, %r12d
shrl $0x12, %r12d
andl %r8d, %r12d
movb 0x80(%r9,%r12), %dl
movabsq $0x4, %rsi
movb %dl, (%r11,%rsi)
addq $0x8, %r10
jmp 0x759db
movl -0x7c(%rsp,%r10,4), %eax
addl $0x10, %eax
shrl $0x5, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movq -0x70(%rsp), %rcx
movzbl 0x80(%rcx,%rax), %edx
movd %edx, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0,4,5,6,7]
movd %xmm0, (%r11)
movb %dl, 0x4(%r11)
movb %dl, 0x5(%r11)
movb %dl, 0x6(%r11)
movabsq $0x7, %rsi
jmp 0x75bb9
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop