// File: /workspace/github_cpp_makefile_star2_O3/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, -0x74(%rsp)
movq %rcx, -0x68(%rsp)
movq 0x1a8(%rdi), %rax
movq %rax, -0x70(%rsp)
movq 0x58(%rsi), %rax
movq %rax, -0x80(%rsp)
movl $0x9, %edi
xorl %r9d, %r9d
movswq 0x10(%rdx,%r9), %r14
movzwl 0x20(%rdx,%r9), %ecx
movl %ecx, %r10d
orw %r14w, %r10w
jne 0x81dd4
cmpw $0x0, 0x30(%rdx,%r9)
jne 0x81dd2
cmpw $0x0, 0x40(%rdx,%r9)
jne 0x81dd2
cmpw $0x0, 0x50(%rdx,%r9)
jne 0x81dd2
cmpw $0x0, 0x60(%rdx,%r9)
jne 0x81dd2
cmpw $0x0, 0x70(%rdx,%r9)
je 0x81fa9
xorl %ecx, %ecx
movq -0x80(%rsp), %rax
movslq 0x40(%rax,%r9,2), %r10
movswq %cx, %rcx
imulq %r10, %rcx
movswq 0x60(%rdx,%r9), %r10
movslq 0xc0(%rax,%r9,2), %r11
imulq %r10, %r11
leaq (%r11,%rcx), %r10
imulq $0x1151, %r10, %r10     # imm = 0x1151
imulq $-0x3b21, %r11, %rbx    # imm = 0xC4DF
addq %r10, %rbx
imulq $0x187e, %rcx, %r12     # imm = 0x187E
addq %r10, %r12
movswq (%rdx,%r9), %rcx
movslq (%rax,%r9,2), %r11
imulq %rcx, %r11
movswq 0x40(%rdx,%r9), %rcx
movslq 0x80(%rax,%r9,2), %r10
imulq %rcx, %r10
leaq (%r10,%r11), %r15
subq %r10, %r11
movswq 0x70(%rdx,%r9), %rcx
movslq 0xe0(%rax,%r9,2), %r13
imulq %rcx, %r13
movswq 0x50(%rdx,%r9), %rcx
movslq 0xa0(%rax,%r9,2), %r10
imulq %rcx, %r10
movswq 0x30(%rdx,%r9), %rcx
movslq 0x60(%rax,%r9,2), %r8
imulq %rcx, %r8
movslq 0x20(%rax,%r9,2), %rcx
imulq %r14, %rcx
leaq (%r8,%r13), %r14
leaq (%rcx,%r10), %rbp
leaq (%r14,%rbp), %rax
imulq $0x25a1, %rax, %rax     # imm = 0x25A1
movl %edi, %esi
imulq $-0x3ec5, %r14, %rdi    # imm = 0xC13B
imulq $-0xc7c, %rbp, %r14     # imm = 0xF384
addq %rax, %rdi
addq %rax, %r14
leaq (%r8,%r10), %rax
imulq $0x41b3, %r10, %rbp     # imm = 0x41B3
imulq $0x6254, %r8, %r10      # imm = 0x6254
imulq $-0x5203, %rax, %rax    # imm = 0xADFD
addq %rax, %rbp
addq %rax, %r10
leaq (%rcx,%r13), %rax
imulq $0x98e, %r13, %r13      # imm = 0x98E
imulq $-0x1ccd, %rax, %rax    # imm = 0xE333
addq %rax, %r13
addq %rdi, %r13
addq %rdi, %r10
movl %esi, %edi
imulq $0x300b, %rcx, %rcx     # imm = 0x300B
addq %rax, %rcx
shlq $0xd, %r15
addq %r14, %rbp
addq %r14, %rcx
movq %r15, %r14
subq %r12, %r14
movl $0x400, %esi            # imm = 0x400
addq %rsi, %r15
addq %r12, %r15
leaq (%r15,%rcx), %rax
shrq $0xb, %rax
movl %eax, -0x60(%rsp,%r9,2)
subq %rcx, %r15
shlq $0xd, %r11
shrq $0xb, %r15
movl %r15d, 0x80(%rsp,%r9,2)
movq %r11, %rax
subq %rbx, %rax
addq %rsi, %r11
addq %rbx, %r11
leaq (%r11,%r10), %rcx
shrq $0xb, %rcx
movl %ecx, -0x40(%rsp,%r9,2)
subq %r10, %r11
shrq $0xb, %r11
movl %r11d, 0x60(%rsp,%r9,2)
leaq (%rax,%rbp), %rcx
addq $0x400, %rcx            # imm = 0x400
shrq $0xb, %rcx
movl %ecx, -0x20(%rsp,%r9,2)
addq %rsi, %rax
subq %rbp, %rax
shrq $0xb, %rax
movl %eax, 0x40(%rsp,%r9,2)
leaq (%r14,%r13), %rax
addq $0x400, %rax            # imm = 0x400
shrq $0xb, %rax
movl %eax, (%rsp,%r9,2)
addq %rsi, %r14
subq %r13, %r14
shrq $0xb, %r14
movl $0x80, %ecx
leaq (%rsp,%rcx), %rax
addq $-0x60, %rax
movl %r14d, (%rax,%r9,2)
decl %edi
addq $0x2, %r9
cmpl $0x1, %edi
ja 0x81d8c
jmp 0x81fe5
movswl (%rdx,%r9), %r14d
movq -0x80(%rsp), %rax
imull (%rax,%r9,2), %r14d
shll $0x2, %r14d
movl %r14d, -0x60(%rsp,%r9,2)
movl %r14d, -0x40(%rsp,%r9,2)
movl %r14d, -0x20(%rsp,%r9,2)
movl %r14d, (%rsp,%r9,2)
movl %r14d, 0x20(%rsp,%r9,2)
movl %r14d, 0x40(%rsp,%r9,2)
movl %r14d, 0x60(%rsp,%r9,2)
movl $0xe0, %ecx
jmp 0x81f8c
movl -0x74(%rsp), %eax
movq %rax, -0x80(%rsp)
movl $0x7, %esi
movl $0x20000, %r8d          # imm = 0x20000
movq -0x68(%rsp), %rax
movq -0x7(%rax,%rsi), %r9
addq -0x80(%rsp), %r9
movl -0x78(%rsp,%rsi,4), %r14d
movl -0x74(%rsp,%rsi,4), %r10d
movl %r10d, %eax
orl %r14d, %eax
jne 0x82044
xorl %r10d, %r10d
cmpl $0x0, -0x70(%rsp,%rsi,4)
jne 0x82044
cmpl $0x0, -0x6c(%rsp,%rsi,4)
jne 0x82044
cmpl $0x0, -0x68(%rsp,%rsi,4)
jne 0x82044
cmpl $0x0, -0x64(%rsp,%rsi,4)
jne 0x82044
cmpl $0x0, -0x60(%rsp,%rsi,4)
je 0x821e1
movl -0x64(%rsp,%rsi,4), %eax
leal (%rax,%r10), %ecx
imull $0x1151, %ecx, %ecx     # imm = 0x1151
imull $0xffffc4df, %eax, %ebp # imm = 0xFFFFC4DF
addl %ecx, %ebp
imull $0x187e, %r10d, %r12d   # imm = 0x187E
addl %ecx, %r12d
movl -0x6c(%rsp,%rsi,4), %eax
movl -0x7c(%rsp,%rsi,4), %r10d
movl -0x70(%rsp,%rsi,4), %ebx
leal (%rax,%r10), %r11d
subl %eax, %r10d
movl -0x60(%rsp,%rsi,4), %edx
movl -0x68(%rsp,%rsi,4), %r15d
leal (%rbx,%rdx), %eax
leal (%r15,%r14), %ecx
leal (%rax,%rcx), %r13d
imull $0x25a1, %r13d, %r13d   # imm = 0x25A1
imull $0xffffc13b, %eax, %eax # imm = 0xFFFFC13B
imull $0xfffff384, %ecx, %ecx # imm = 0xFFFFF384
addl %r13d, %eax
addl %r13d, %ecx
leal (%rbx,%r15), %edi
imull $0x41b3, %r15d, %r15d   # imm = 0x41B3
imull $0x6254, %ebx, %r13d    # imm = 0x6254
imull $0xffffadfd, %edi, %edi # imm = 0xFFFFADFD
addl %edi, %r15d
addl %edi, %r13d
leal (%rdx,%r14), %edi
imull $0x98e, %edx, %ebx      # imm = 0x98E
imull $0xffffe333, %edi, %edx # imm = 0xFFFFE333
addl %edx, %ebx
addl %eax, %ebx
addl %eax, %r13d
imull $0x300b, %r14d, %eax    # imm = 0x300B
addl %edx, %eax
shll $0xd, %r11d
shll $0xd, %r10d
addl %ecx, %r15d
addl %ecx, %eax
movl %r11d, %r14d
subl %r12d, %r14d
addl %r8d, %r11d
addl %r12d, %r11d
leal (%r11,%rax), %r12d
subl %eax, %r11d
movl %r10d, %ecx
subl %ebp, %ecx
addl %r8d, %r10d
addl %ebp, %r10d
leal (%r10,%r13), %edx
subl %r13d, %r10d
leal (%rcx,%r15), %eax
addl $0x20000, %eax          # imm = 0x20000
addl %r8d, %ecx
subl %r15d, %ecx
shrl $0x12, %r12d
movl $0x3ff, %ebp            # imm = 0x3FF
andl %ebp, %r12d
movq -0x70(%rsp), %r15
movb 0x80(%r15,%r12), %dil
movb %dil, (%r9)
shrl $0x12, %r11d
andl %ebp, %r11d
movb 0x80(%r15,%r11), %dil
movb %dil, 0x7(%r9)
shrl $0x12, %edx
andl %ebp, %edx
movb 0x80(%r15,%rdx), %dl
movb %dl, 0x1(%r9)
shrl $0x12, %r10d
andl %ebp, %r10d
movb 0x80(%r15,%r10), %dl
movb %dl, 0x6(%r9)
shrl $0x12, %eax
andl %ebp, %eax
movb 0x80(%r15,%rax), %al
movb %al, 0x2(%r9)
shrl $0x12, %ecx
andl %ebp, %ecx
movb 0x80(%r15,%rcx), %al
movb %al, 0x5(%r9)
leal (%r14,%rbx), %eax
addl $0x20000, %eax          # imm = 0x20000
shrl $0x12, %eax
andl %ebp, %eax
movb 0x80(%r15,%rax), %al
movb %al, 0x3(%r9)
addl %r8d, %r14d
subl %ebx, %r14d
shrl $0x12, %r14d
andl %ebp, %r14d
movb 0x80(%r15,%r14), %cl
movl $0x4, %edx
movb %cl, (%r9,%rdx)
addq $0x8, %rsi
cmpq $0x47, %rsi
jne 0x81ff9
jmp 0x82222
movl -0x7c(%rsp,%rsi,4), %eax
addl $0x10, %eax
shrl $0x5, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movq -0x70(%rsp), %rcx
movzbl 0x80(%rcx,%rax), %ecx
movd %ecx, %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, (%r9)
movb %cl, 0x4(%r9)
movb %cl, 0x5(%r9)
movb %cl, 0x6(%r9)
movl $0x7, %edx
jmp 0x821cd
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq