// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jidctred.c
// Function: jpeg_idct_2x2
GLOBAL(void)
jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
	       JCOEFPTR coef_block,
	       JSAMPARRAY output_buf, JDIMENSION output_col)
{
  INT32 tmp0, tmp10, z1;
  JCOEFPTR inptr;
  ISLOW_MULT_TYPE * quantptr;
  int * wsptr;
  JSAMPROW outptr;
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  int ctr;
  int workspace[DCTSIZE*2];	/* buffers data between passes */
  SHIFT_TEMPS

  /* Pass 1: process columns from input, store into work array. */

  inptr = coef_block;
  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  wsptr = workspace;
  for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
    /* Don't bother to process columns 2,4,6 */
    if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
      continue;
    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
	inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
      /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
      int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
      
      wsptr[DCTSIZE*0] = dcval;
      wsptr[DCTSIZE*1] = dcval;
      
      continue;
    }
    
    /* Even part */
    
    z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
    tmp10 = z1 << (CONST_BITS+2);
    
    /* Odd part */

    z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
    tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
    z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
    tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
    z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
    tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
    tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */

    /* Final output stage */
    
    wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
    wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  }
  
  /* Pass 2: process 2 rows from work array, store into output array. */

  wsptr = workspace;
  for (ctr = 0; ctr < 2; ctr++) {
    outptr = output_buf[ctr] + output_col;
    /* It's not clear whether a zero row test is worthwhile here ... */

#ifndef NO_ZERO_ROW_TEST
    if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 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;
      
      wsptr += DCTSIZE;		/* advance pointer to next row */
      continue;
    }
#endif
    
    /* Even part */
    
    tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
    
    /* Odd part */

    tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
	 + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
	 + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
	 + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */

    /* Final output stage */
    
    outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
					  CONST_BITS+PASS1_BITS+3+2)
			    & RANGE_MASK];
    outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
					  CONST_BITS+PASS1_BITS+3+2)
			    & RANGE_MASK];
    
    wsptr += DCTSIZE;		/* advance pointer to next row */
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
movq 0x1a8(%rdi), %rax
movq 0x58(%rsi), %rsi
movl $0x9, %edi
xorl %r9d, %r9d
decl %edi
cmpl $0xc, %r9d
je 0x8347f
movl %edi, %r10d
andl $0x7ffffffd, %r10d      # imm = 0x7FFFFFFD
cmpl $0x4, %r10d
je 0x8347f
movswq 0x10(%rdx,%r9), %r11
testq %r11, %r11
jne 0x833e6
cmpw $0x0, 0x30(%rdx,%r9)
jne 0x833e6
cmpw $0x0, 0x50(%rdx,%r9)
jne 0x833e6
cmpw $0x0, 0x70(%rdx,%r9)
je 0x8348e
movswq (%rdx,%r9), %rbx
movslq (%rsi,%r9,2), %r10
imulq %rbx, %r10
shlq $0xf, %r10
movswq 0x70(%rdx,%r9), %rbx
movslq 0xe0(%rsi,%r9,2), %r14
imulq %rbx, %r14
imulq $-0x1712, %r14, %rbx    # imm = 0xE8EE
movswq 0x50(%rdx,%r9), %r14
movslq 0xa0(%rsi,%r9,2), %r15
imulq %r14, %r15
imulq $0x1b37, %r15, %r14     # imm = 0x1B37
addq %rbx, %r14
movswq 0x30(%rdx,%r9), %rbx
movslq 0x60(%rsi,%r9,2), %r15
imulq %rbx, %r15
imulq $-0x28ba, %r15, %rbx    # imm = 0xD746
movslq 0x20(%rsi,%r9,2), %r15
imulq %r11, %r15
imulq $0x73fc, %r15, %r11     # imm = 0x73FC
addq %rbx, %r11
addq %r14, %r11
leaq (%r10,%r11), %rbx
addq $0x1000, %rbx           # imm = 0x1000
orq $0x1000, %r10           # imm = 0x1000
shrq $0xd, %rbx
movl %ebx, -0x48(%rsp,%r9,2)
subq %r11, %r10
shrq $0xd, %r10
movl %r10d, -0x28(%rsp,%r9,2)
addq $0x2, %r9
cmpl $0x1, %edi
ja 0x8339c
jmp 0x834a3
movswl (%rdx,%r9), %r10d
imull (%rsi,%r9,2), %r10d
shll $0x2, %r10d
movl %r10d, -0x48(%rsp,%r9,2)
jmp 0x8347a
movl %r8d, %edx
xorl %esi, %esi
movl $0x3ff, %edi            # imm = 0x3FF
movq (%rcx,%rsi), %r8
movl -0x44(%rsp,%rsi,4), %r9d
testq %r9, %r9
jne 0x834d0
cmpl $0x0, -0x3c(%rsp,%rsi,4)
jne 0x834d0
cmpl $0x0, -0x34(%rsp,%rsi,4)
jne 0x834d0
cmpl $0x0, -0x2c(%rsp,%rsi,4)
je 0x8354d
movl -0x48(%rsp,%rsi,4), %r10d
imull $0xffffe8ee, -0x2c(%rsp,%rsi,4), %r11d # imm = 0xFFFFE8EE
imull $0x1b37, -0x34(%rsp,%rsi,4), %ebx # imm = 0x1B37
imull $0xffffd746, -0x3c(%rsp,%rsi,4), %ebp # imm = 0xFFFFD746
shll $0xf, %r10d
addl %ebx, %ebp
imull $0x73fc, %r9d, %r9d     # imm = 0x73FC
addl %r11d, %r9d
addl %ebp, %r9d
leal (%r10,%r9), %r11d
addl $0x80000, %r11d         # imm = 0x80000
addl $0x80000, %r10d         # imm = 0x80000
shrl $0x14, %r11d
andl %edi, %r11d
movb 0x80(%rax,%r11), %r11b
movb %r11b, (%r8,%rdx)
subl %r9d, %r10d
shrl $0x14, %r10d
andl %edi, %r10d
movb 0x80(%rax,%r10), %r9b
movb %r9b, 0x1(%r8,%rdx)
addq $0x8, %rsi
cmpq $0x8, %rsi
je 0x834ad
jmp 0x8356f
movl -0x48(%rsp,%rsi,4), %r9d
addl $0x10, %r9d
shrl $0x5, %r9d
andl $0x3ff, %r9d            # imm = 0x3FF
movb 0x80(%rax,%r9), %r9b
movb %r9b, (%r8,%rdx)
jmp 0x83538
popq %rbx
popq %r14
popq %r15
popq %rbp
retq