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