// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jidctred.c
// Function: jpeg_idct_4x4
GLOBAL(void)
jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
	       JCOEFPTR coef_block,
	       JSAMPARRAY output_buf, JDIMENSION output_col)
{
  INT32 tmp0, tmp2, tmp10, tmp12;
  INT32 z1, z2, z3, z4;
  JCOEFPTR inptr;
  ISLOW_MULT_TYPE * quantptr;
  int * wsptr;
  JSAMPROW outptr;
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  int ctr;
  int workspace[DCTSIZE*4];	/* 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 column 4, because second pass won't use it */
    if (ctr == DCTSIZE-4)
      continue;
    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
	inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
	inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
      /* AC terms all zero; we need not examine term 4 for 4x4 output */
      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;
      
      continue;
    }
    
    /* Even part */
    
    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
    tmp0 <<= (CONST_BITS+1);
    
    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);

    tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
    
    tmp10 = tmp0 + tmp2;
    tmp12 = tmp0 - tmp2;
    
    /* Odd part */
    
    z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
    z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
    z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
    z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
    
    tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
	 + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
	 + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
	 + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
    
    tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
	 + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
	 + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
	 + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */

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

  wsptr = workspace;
  for (ctr = 0; ctr < 4; 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[2] == 0 && wsptr[3] == 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;
      
      wsptr += DCTSIZE;		/* advance pointer to next row */
      continue;
    }
#endif
    
    /* Even part */
    
    tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
    
    tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
	 + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
    
    tmp10 = tmp0 + tmp2;
    tmp12 = tmp0 - tmp2;
    
    /* Odd part */
    
    z1 = (INT32) wsptr[7];
    z2 = (INT32) wsptr[5];
    z3 = (INT32) wsptr[3];
    z4 = (INT32) wsptr[1];
    
    tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
	 + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
	 + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
	 + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
    
    tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
	 + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
	 + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
	 + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, -0x7c(%rsp)
movq %rcx, -0x78(%rsp)
movq 0x1a8(%rdi), %rax
movq 0x58(%rsi), %rsi
movl $0x8, %edi
xorl %r9d, %r9d
cmpl $0x4, %edi
je 0x75dc1
testl %edi, %edi
je 0x75df5
movswq 0x10(%rdx,%r9), %r15
movzwl 0x20(%rdx,%r9), %ebp
movl %ebp, %r14d
orw %r15w, %r14w
jne 0x75c9b
cmpw $0x0, 0x30(%rdx,%r9)
jne 0x75c99
cmpw $0x0, 0x50(%rdx,%r9)
jne 0x75c99
cmpw $0x0, 0x60(%rdx,%r9)
jne 0x75c99
cmpw $0x0, 0x70(%rdx,%r9)
je 0x75dcc
xorl %ebp, %ebp
movswq (%rdx,%r9), %r14
movslq (%rsi,%r9,2), %r12
imulq %r14, %r12
shlq $0xe, %r12
movslq 0x40(%rsi,%r9,2), %r14
movswq %bp, %r13
imulq %r14, %r13
movswq 0x60(%rdx,%r9), %r14
movslq 0xc0(%rsi,%r9,2), %rbp
imulq %r14, %rbp
imulq $0x3b21, %r13, %r14     # imm = 0x3B21
imulq $-0x187e, %rbp, %r13    # imm = 0xE782
addq %r14, %r13
movq %r12, %r14
subq %r13, %r14
movswq 0x70(%rdx,%r9), %rbp
movslq 0xe0(%rsi,%r9,2), %r10
imulq %rbp, %r10
movswq 0x50(%rdx,%r9), %rbp
movslq 0xa0(%rsi,%r9,2), %rbx
imulq %rbp, %rbx
movswq 0x30(%rdx,%r9), %rbp
movslq 0x60(%rsi,%r9,2), %r8
imulq %rbp, %r8
movslq 0x20(%rsi,%r9,2), %rbp
imulq %r15, %rbp
imulq $-0x6c2, %r10, %r15     # imm = 0xF93E
imulq $0x2e75, %rbx, %r11     # imm = 0x2E75
addq %r15, %r11
imulq $-0x4587, %r8, %rcx     # imm = 0xBA79
imulq $0x21f9, %rbp, %r15     # imm = 0x21F9
addq %rcx, %r15
addq %r11, %r15
imulq $-0x1050, %r10, %rcx    # imm = 0xEFB0
imulq $-0x133e, %rbx, %r10    # imm = 0xECC2
addq %rcx, %r10
imulq $0x1ccd, %r8, %rcx      # imm = 0x1CCD
imulq $0x5203, %rbp, %r8      # imm = 0x5203
addq %rcx, %r8
addq %r10, %r8
movl $0x800, %r10d           # imm = 0x800
addq %r10, %r12
addq %r13, %r12
leaq (%r12,%r8), %rcx
shrq $0xc, %rcx
movl %ecx, -0x70(%rsp,%r9,2)
subq %r8, %r12
shrq $0xc, %r12
movl %r12d, -0x10(%rsp,%r9,2)
leaq (%r14,%r15), %rcx
addq $0x800, %rcx            # imm = 0x800
addq %r10, %r14
shrq $0xc, %rcx
movl %ecx, -0x50(%rsp,%r9,2)
subq %r15, %r14
shrq $0xc, %r14
movabsq $0x40, %r15
leaq (%rsp,%r15), %rcx
addq $-0x70, %rcx
movl %r14d, (%rcx,%r9,2)
decl %edi
addq $0x2, %r9
jmp 0x75c4b
movswl (%rdx,%r9), %r14d
imull (%rsi,%r9,2), %r14d
shll $0x2, %r14d
movl %r14d, -0x70(%rsp,%r9,2)
movl %r14d, -0x50(%rsp,%r9,2)
movl %r14d, -0x30(%rsp,%r9,2)
movabsq $0x60, %r15
jmp 0x75db5
movl -0x7c(%rsp), %edx
movabsq $0x7, %rsi
movl $0x40000, %r8d          # imm = 0x40000
movl $0x3ff, %r9d            # imm = 0x3FF
movabsq $0x2, %r10
cmpq $0x27, %rsi
je 0x75f7a
movq -0x78(%rsp), %rcx
movq -0x7(%rcx,%rsi), %r11
addq %rdx, %r11
movl -0x88(%rsp,%rsi,4), %ebx
movl -0x84(%rsp,%rsi,4), %ebp
movl %ebp, %ecx
orl %ebx, %ecx
jne 0x75e66
xorl %ebp, %ebp
cmpl $0x0, -0x80(%rsp,%rsi,4)
jne 0x75e66
cmpl $0x0, -0x78(%rsp,%rsi,4)
jne 0x75e66
cmpl $0x0, -0x74(%rsp,%rsi,4)
jne 0x75e66
cmpl $0x0, -0x70(%rsp,%rsi,4)
je 0x75f49
movl -0x80(%rsp,%rsi,4), %ecx
imull $0x3b21, %ebp, %r14d    # imm = 0x3B21
imull $0xffffe782, -0x74(%rsp,%rsi,4), %ebp # imm = 0xFFFFE782
addl %r14d, %ebp
movl -0x70(%rsp,%rsi,4), %r15d
movl -0x78(%rsp,%rsi,4), %r12d
imull $0xfffff93e, %r15d, %r13d # imm = 0xFFFFF93E
imull $0x2e75, %r12d, %r14d   # imm = 0x2E75
imull $0xffffba79, %ecx, %edi # imm = 0xFFFFBA79
addl %r14d, %edi
imull $0x21f9, %ebx, %r14d    # imm = 0x21F9
addl %r13d, %r14d
addl %edi, %r14d
imull $0xffffecc2, %r12d, %edi # imm = 0xFFFFECC2
imull $0x1ccd, %ecx, %ecx     # imm = 0x1CCD
addl %edi, %ecx
imull $0xffffefb0, %r15d, %edi # imm = 0xFFFFEFB0
imull $0x5203, %ebx, %r12d    # imm = 0x5203
addl %edi, %r12d
movl -0x8c(%rsp,%rsi,4), %ebx
shll $0xe, %ebx
addl %ecx, %r12d
movl %ebx, %ecx
subl %ebp, %ecx
addl %r8d, %ebx
addl %ebp, %ebx
leal (%rbx,%r12), %r15d
subl %r12d, %ebx
leal (%rcx,%r14), %edi
addl $0x40000, %edi          # imm = 0x40000
addl %r8d, %ecx
subl %r14d, %ecx
shrl $0x13, %r15d
andl %r9d, %r15d
movb 0x80(%rax,%r15), %bpl
movb %bpl, (%r11)
shrl $0x13, %ebx
andl %r9d, %ebx
movb 0x80(%rax,%rbx), %bl
movb %bl, 0x3(%r11)
shrl $0x13, %edi
andl %r9d, %edi
movb 0x80(%rax,%rdi), %dil
movb %dil, 0x1(%r11)
shrl $0x13, %ecx
andl %r9d, %ecx
movb 0x80(%rax,%rcx), %bl
movq %r10, %r14
movb %bl, (%r11,%r14)
addq $0x8, %rsi
jmp 0x75e19
movl -0x8c(%rsp,%rsi,4), %ecx
addl $0x10, %ecx
shrl $0x5, %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movb 0x80(%rax,%rcx), %bl
movb %bl, (%r11)
movb %bl, 0x1(%r11)
movb %bl, 0x2(%r11)
movabsq $0x3, %r14
jmp 0x75f3c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq