// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
movq 0x1a8(%rdi), %rax
movq 0x58(%rsi), %rsi
movl $0x9, %edi
xorl %r9d, %r9d
decl %edi
cmpl $0xc, %r9d
je 0x8267f
movl %edi, %r10d
andl $0x7ffffffd, %r10d      # imm = 0x7FFFFFFD
cmpl $0x4, %r10d
je 0x8267f
movswq 0x10(%rdx,%r9), %r10
movzwl 0x30(%rdx,%r9), %ebx
movl %ebx, %r11d
orw %r10w, %r11w
jne 0x825e8
cmpw $0x0, 0x50(%rdx,%r9)
jne 0x825e6
cmpw $0x0, 0x70(%rdx,%r9)
je 0x8268e
xorl %ebx, %ebx
movswq (%rdx,%r9), %r14
movslq (%rsi,%r9,2), %r11
imulq %r14, %r11
shlq $0xf, %r11
movswq 0x70(%rdx,%r9), %r14
movslq 0xe0(%rsi,%r9,2), %r15
imulq %r14, %r15
imulq $-0x1712, %r15, %r14    # imm = 0xE8EE
movswq 0x50(%rdx,%r9), %r15
movslq 0xa0(%rsi,%r9,2), %r12
imulq %r15, %r12
imulq $0x1b37, %r12, %r15     # imm = 0x1B37
addq %r14, %r15
movslq 0x60(%rsi,%r9,2), %r14
movswq %bx, %rbx
imulq %r14, %rbx
imulq $-0x28ba, %rbx, %rbx    # imm = 0xD746
addq %r15, %rbx
movslq 0x20(%rsi,%r9,2), %r14
imulq %r10, %r14
imulq $0x73fc, %r14, %r10     # imm = 0x73FC
addq %rbx, %r10
leaq (%r11,%r10), %rbx
addq $0x1000, %rbx           # imm = 0x1000
orq $0x1000, %r11           # imm = 0x1000
shrq $0xd, %rbx
movl %ebx, -0x40(%rsp,%r9,2)
subq %r10, %r11
shrq $0xd, %r11
movl %r11d, -0x20(%rsp,%r9,2)
addq $0x2, %r9
cmpl $0x1, %edi
ja 0x8259b
jmp 0x826a3
movswl (%rdx,%r9), %r11d
imull (%rsi,%r9,2), %r11d
shll $0x2, %r11d
movl %r11d, -0x40(%rsp,%r9,2)
jmp 0x8267a
movl %r8d, %edx
movb $0x1, %dil
leaq -0x24(%rsp), %rsi
xorl %r9d, %r9d
movl $0x3ff, %r8d            # imm = 0x3FF
movq (%rcx,%r9,8), %r9
movl -0x18(%rsi), %r10d
movl -0x10(%rsi), %r11d
movl %r11d, %ebx
orl %r10d, %ebx
jne 0x826dd
xorl %r11d, %r11d
cmpl $0x0, -0x8(%rsi)
jne 0x826dd
cmpl $0x0, (%rsi)
je 0x8275d
movl -0x1c(%rsi), %ebx
shll $0xf, %ebx
imull $0xffffe8ee, (%rsi), %ebp # imm = 0xFFFFE8EE
imull $0x1b37, -0x8(%rsi), %r14d # imm = 0x1B37
imull $0xffffd746, %r11d, %r11d # imm = 0xFFFFD746
addl %r14d, %r11d
imull $0x73fc, %r10d, %r10d   # imm = 0x73FC
addl %ebp, %r10d
addl %r11d, %r10d
leal (%rbx,%r10), %r11d
addl $0x80000, %r11d         # imm = 0x80000
addl $0x80000, %ebx          # imm = 0x80000
shrl $0x14, %r11d
andl %r8d, %r11d
movb 0x80(%rax,%r11), %r11b
movb %r11b, (%r9,%rdx)
subl %r10d, %ebx
shrl $0x14, %ebx
andl %r8d, %ebx
movb 0x80(%rax,%rbx), %r10b
movb %r10b, 0x1(%r9,%rdx)
addq $0x20, %rsi
movl $0x1, %r9d
testb $0x1, %dil
movl $0x0, %edi
jne 0x826b7
jmp 0x8277e
movl -0x1c(%rsi), %r10d
addl $0x10, %r10d
shrl $0x5, %r10d
andl $0x3ff, %r10d           # imm = 0x3FF
movb 0x80(%rax,%r10), %r10b
movb %r10b, (%r9,%rdx)
jmp 0x8273d
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq