// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
movq 0x58(%rsi), %rsi
movl $0x9, %edi
xorl %r9d, %r9d
cmpl $0x8, %r9d
je 0x823c8
movswq 0x10(%rdx,%r9), %rbx
movzwl 0x20(%rdx,%r9), %r11d
movl %r11d, %ebp
orw %bx, %bp
jne 0x822a8
cmpw $0x0, 0x30(%rdx,%r9)
jne 0x822a5
cmpw $0x0, 0x50(%rdx,%r9)
jne 0x822a5
cmpw $0x0, 0x60(%rdx,%r9)
jne 0x822a5
cmpw $0x0, 0x70(%rdx,%r9)
je 0x823d9
xorl %r11d, %r11d
movswq (%rdx,%r9), %r15
movslq (%rsi,%r9,2), %r14
imulq %r15, %r14
shlq $0xe, %r14
movslq 0x40(%rsi,%r9,2), %r15
movswq %r11w, %r11
imulq %r15, %r11
movswq 0x60(%rdx,%r9), %r15
movslq 0xc0(%rsi,%r9,2), %r12
imulq %r15, %r12
imulq $0x3b21, %r11, %r11     # imm = 0x3B21
imulq $-0x187e, %r12, %r15    # imm = 0xE782
addq %r11, %r15
movq %r14, %r11
subq %r15, %r11
movswq 0x70(%rdx,%r9), %r12
movslq 0xe0(%rsi,%r9,2), %r13
imulq %r12, %r13
movswq 0x50(%rdx,%r9), %r12
movslq 0xa0(%rsi,%r9,2), %rbp
imulq %r12, %rbp
movswq 0x30(%rdx,%r9), %r12
movslq 0x60(%rsi,%r9,2), %r10
imulq %r12, %r10
movslq 0x20(%rsi,%r9,2), %r12
imulq %rbx, %r12
imulq $-0x6c2, %r13, %rbx     # imm = 0xF93E
imulq $0x2e75, %rbp, %r8      # imm = 0x2E75
addq %rbx, %r8
imulq $-0x4587, %r10, %rax    # imm = 0xBA79
imulq $0x21f9, %r12, %rbx     # imm = 0x21F9
addq %rax, %rbx
addq %r8, %rbx
imulq $-0x1050, %r13, %rax    # imm = 0xEFB0
imulq $-0x133e, %rbp, %r8     # imm = 0xECC2
addq %rax, %r8
imulq $0x1ccd, %r10, %rax     # imm = 0x1CCD
imulq $0x5203, %r12, %r10     # imm = 0x5203
addq %rax, %r10
addq %r8, %r10
movl $0x800, %r8d            # imm = 0x800
addq %r8, %r14
addq %r15, %r14
leaq (%r14,%r10), %rax
shrq $0xc, %rax
movl %eax, -0x70(%rsp,%r9,2)
subq %r10, %r14
shrq $0xc, %r14
movl %r14d, -0x10(%rsp,%r9,2)
leaq (%r11,%rbx), %rax
addq $0x800, %rax            # imm = 0x800
addq %r8, %r11
shrq $0xc, %rax
movl %eax, -0x50(%rsp,%r9,2)
subq %rbx, %r11
shrq $0xc, %r11
movl $0x40, %ebx
leaq (%rsp,%rbx), %rax
addq $-0x70, %rax
movl %r11d, (%rax,%r9,2)
decl %edi
addq $0x2, %r9
cmpl $0x1, %edi
ja 0x8225f
jmp 0x823fd
movswl (%rdx,%r9), %r11d
imull (%rsi,%r9,2), %r11d
shll $0x2, %r11d
movl %r11d, -0x70(%rsp,%r9,2)
movl %r11d, -0x50(%rsp,%r9,2)
movl %r11d, -0x30(%rsp,%r9,2)
movl $0x60, %ebx
jmp 0x823bc
movl -0x7c(%rsp), %edx
movl $0x7, %esi
movl $0x3ff, %r8d            # imm = 0x3FF
movq -0x78(%rsp), %rax
movq -0x7(%rax,%rsi), %r9
addq %rdx, %r9
movl -0x88(%rsp,%rsi,4), %r10d
movl -0x84(%rsp,%rsi,4), %ebx
movl %ebx, %eax
orl %r10d, %eax
jne 0x82451
xorl %ebx, %ebx
cmpl $0x0, -0x80(%rsp,%rsi,4)
jne 0x82451
cmpl $0x0, -0x78(%rsp,%rsi,4)
jne 0x82451
cmpl $0x0, -0x74(%rsp,%rsi,4)
jne 0x82451
cmpl $0x0, -0x70(%rsp,%rsi,4)
je 0x82544
movl -0x8c(%rsp,%rsi,4), %r11d
movl -0x80(%rsp,%rsi,4), %eax
shll $0xe, %r11d
imull $0xffffe782, -0x74(%rsp,%rsi,4), %ebp # imm = 0xFFFFE782
imull $0x3b21, %ebx, %ebx     # imm = 0x3B21
addl %ebx, %ebp
movl %r11d, %ebx
subl %ebp, %ebx
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, %eax, %edi # imm = 0xFFFFBA79
addl %r14d, %edi
imull $0x21f9, %r10d, %r14d   # imm = 0x21F9
addl %r13d, %r14d
addl %edi, %r14d
imull $0xffffefb0, %r15d, %edi # imm = 0xFFFFEFB0
imull $0xffffecc2, %r12d, %r15d # imm = 0xFFFFECC2
imull $0x1ccd, %eax, %eax     # imm = 0x1CCD
addl %r15d, %eax
imull $0x5203, %r10d, %r10d   # imm = 0x5203
addl %edi, %r10d
addl %eax, %r10d
movl $0x40000, %edi          # imm = 0x40000
addl %edi, %r11d
addl %ebp, %r11d
leal (%r11,%r10), %eax
shrl $0x13, %eax
andl %r8d, %eax
movb 0x80(%rcx,%rax), %al
movb %al, (%r9)
subl %r10d, %r11d
shrl $0x13, %r11d
andl %r8d, %r11d
movb 0x80(%rcx,%r11), %al
movb %al, 0x3(%r9)
leal (%rbx,%r14), %eax
addl $0x40000, %eax          # imm = 0x40000
addl %edi, %ebx
shrl $0x13, %eax
andl %r8d, %eax
movb 0x80(%rcx,%rax), %al
movb %al, 0x1(%r9)
subl %r14d, %ebx
shrl $0x13, %ebx
andl %r8d, %ebx
movb 0x80(%rcx,%rbx), %r10b
movl $0x2, %r11d
movb %r10b, (%r9,%r11)
addq $0x8, %rsi
cmpq $0x27, %rsi
jne 0x8240c
jmp 0x82571
movl -0x8c(%rsp,%rsi,4), %eax
addl $0x10, %eax
shrl $0x5, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movb 0x80(%rcx,%rax), %r10b
movb %r10b, (%r9)
movb %r10b, 0x1(%r9)
movb %r10b, 0x2(%r9)
movl $0x3, %r11d
jmp 0x82530
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq