// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdcolor.c
// Function: ycck_cmyk_convert
METHODDEF(void)
ycck_cmyk_convert (j_decompress_ptr cinfo,
		   JSAMPIMAGE input_buf, JDIMENSION input_row,
		   JSAMPARRAY output_buf, int num_rows)
{
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  register int y, cb, cr;
  register JSAMPROW outptr;
  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  register JDIMENSION col;
  JDIMENSION num_cols = cinfo->output_width;
  /* copy these pointers into registers if possible */
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
  register int * Crrtab = cconvert->Cr_r_tab;
  register int * Cbbtab = cconvert->Cb_b_tab;
  register INT32 * Crgtab = cconvert->Cr_g_tab;
  register INT32 * Cbgtab = cconvert->Cb_g_tab;
  SHIFT_TEMPS

  while (--num_rows >= 0) {
    inptr0 = input_buf[0][input_row];
    inptr1 = input_buf[1][input_row];
    inptr2 = input_buf[2][input_row];
    inptr3 = input_buf[3][input_row];
    input_row++;
    outptr = *output_buf++;
    for (col = 0; col < num_cols; col++) {
      y  = GETJSAMPLE(inptr0[col]);
      cb = GETJSAMPLE(inptr1[col]);
      cr = GETJSAMPLE(inptr2[col]);
      /* Range-limiting is essential due to noise introduced by DCT losses. */
      outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];	/* red */
      outptr[1] = range_limit[MAXJSAMPLE - (y +			/* green */
			      ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
						 SCALEBITS)))];
      outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];	/* blue */
      /* K passes through unchanged */
      outptr[3] = inptr3[col];	/* don't need GETJSAMPLE here */
      outptr += 4;
    }
  }
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rcx, -0x8(%rsp)
movl %r8d, -0xc(%rsp)
movq 0x10(%rsp), %rax
movq 0x268(%rax), %rax
movq %rax, -0x18(%rsp)
movq 0x10(%rsp), %rax
movl 0x88(%rax), %eax
movl %eax, -0x58(%rsp)
movq 0x10(%rsp), %rax
movq 0x1a8(%rax), %rax
movq %rax, -0x60(%rsp)
movq -0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rsp)
movq -0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rsp)
movq -0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x78(%rsp)
movq -0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x80(%rsp)
movl -0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rsp)
cmpl $0x0, %eax
jl 0xf42a9
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x4(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x4(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rsp)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x4(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rsp)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
movq -0x8(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x8(%rsp)
movq (%rax), %rax
movq %rax, -0x30(%rsp)
movl $0x0, -0x54(%rsp)
movl -0x54(%rsp), %eax
cmpl -0x58(%rsp), %eax
jae 0xf42a4
movq -0x38(%rsp), %rax
movl -0x54(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x1c(%rsp)
movq -0x40(%rsp), %rax
movl -0x54(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x20(%rsp)
movq -0x48(%rsp), %rax
movl -0x54(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x24(%rsp)
movq -0x60(%rsp), %rax
movl -0x1c(%rsp), %edx
movq -0x68(%rsp), %rcx
movslq -0x24(%rsp), %rsi
addl (%rcx,%rsi,4), %edx
movl $0xff, %ecx
subl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0x1c(%rsp), %edx
movq -0x80(%rsp), %rcx
movslq -0x20(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq -0x78(%rsp), %rsi
movslq -0x24(%rsp), %rdi
addq (%rsi,%rdi,8), %rcx
sarq $0x10, %rcx
addl %ecx, %edx
movl $0xff, %ecx
subl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0x1c(%rsp), %edx
movq -0x70(%rsp), %rcx
movslq -0x20(%rsp), %rsi
addl (%rcx,%rsi,4), %edx
movl $0xff, %ecx
subl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x2(%rax)
movq -0x50(%rsp), %rax
movl -0x54(%rsp), %ecx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x3(%rax)
movq -0x30(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rsp)
movl -0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rsp)
jmp 0xf419c
jmp 0xf4105
addq $0x18, %rsp
retq
nop