// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmerge.c
// Function: h2v2_merged_upsample
METHODDEF(void)
h2v2_merged_upsample (j_decompress_ptr cinfo,
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
		      JSAMPARRAY output_buf)
{
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  register int y, cred, cgreen, cblue;
  int cb, cr;
  register JSAMPROW outptr0, outptr1;
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
  JDIMENSION col;
  /* copy these pointers into registers if possible */
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
  int * Crrtab = upsample->Cr_r_tab;
  int * Cbbtab = upsample->Cb_b_tab;
  INT32 * Crgtab = upsample->Cr_g_tab;
  INT32 * Cbgtab = upsample->Cb_g_tab;
  SHIFT_TEMPS

  inptr00 = input_buf[0][in_row_group_ctr*2];
  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  inptr1 = input_buf[1][in_row_group_ctr];
  inptr2 = input_buf[2][in_row_group_ctr];
  outptr0 = output_buf[0];
  outptr1 = output_buf[1];
  /* Loop for each group of output pixels */
  for (col = cinfo->output_width >> 1; col > 0; col--) {
    /* Do the chroma part of the calculation */
    cb = GETJSAMPLE(*inptr1++);
    cr = GETJSAMPLE(*inptr2++);
    cred = Crrtab[cr];
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
    cblue = Cbbtab[cb];
    /* Fetch 4 Y values and emit 4 pixels */
    y  = GETJSAMPLE(*inptr00++);
    outptr0[RGB_RED] =   range_limit[y + cred];
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
    outptr0 += RGB_PIXELSIZE;
    y  = GETJSAMPLE(*inptr00++);
    outptr0[RGB_RED] =   range_limit[y + cred];
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
    outptr0 += RGB_PIXELSIZE;
    y  = GETJSAMPLE(*inptr01++);
    outptr1[RGB_RED] =   range_limit[y + cred];
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
    outptr1 += RGB_PIXELSIZE;
    y  = GETJSAMPLE(*inptr01++);
    outptr1[RGB_RED] =   range_limit[y + cred];
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
    outptr1 += RGB_PIXELSIZE;
  }
  /* If image width is odd, do the last output column separately */
  if (cinfo->output_width & 1) {
    cb = GETJSAMPLE(*inptr1);
    cr = GETJSAMPLE(*inptr2);
    cred = Crrtab[cr];
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
    cblue = Cbbtab[cb];
    y  = GETJSAMPLE(*inptr00);
    outptr0[RGB_RED] =   range_limit[y + cred];
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
    y  = GETJSAMPLE(*inptr01);
    outptr1[RGB_RED] =   range_limit[y + cred];
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
  }
}

// Assembly:
subq $0x20, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rcx, (%rsp)
movq 0x18(%rsp), %rax
movq 0x260(%rax), %rax
movq %rax, -0x8(%rsp)
movq 0x18(%rsp), %rax
movq 0x1a8(%rax), %rax
movq %rax, -0x60(%rsp)
movq -0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x68(%rsp)
movq -0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x70(%rsp)
movq -0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x78(%rsp)
movq -0x8(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x80(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shll %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movl 0xc(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl 0xc(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rsp)
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rsp)
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rsp)
movq 0x18(%rsp), %rax
movl 0x88(%rax), %eax
shrl %eax
movl %eax, -0x54(%rsp)
cmpl $0x0, -0x54(%rsp)
jbe 0xf8b24
movq -0x48(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rsp)
movzbl (%rax), %eax
movl %eax, -0x1c(%rsp)
movq -0x50(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rsp)
movzbl (%rax), %eax
movl %eax, -0x20(%rsp)
movq -0x68(%rsp), %rax
movslq -0x20(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x10(%rsp)
movq -0x80(%rsp), %rax
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x78(%rsp), %rcx
movslq -0x20(%rsp), %rdx
addq (%rcx,%rdx,8), %rax
sarq $0x10, %rax
movl %eax, -0x14(%rsp)
movq -0x70(%rsp), %rax
movslq -0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rsp)
movq -0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rsp)
movzbl (%rax), %eax
movl %eax, -0xc(%rsp)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x10(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x14(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, 0x2(%rax)
movq -0x28(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rsp)
movq -0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rsp)
movzbl (%rax), %eax
movl %eax, -0xc(%rsp)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x10(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x14(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, 0x2(%rax)
movq -0x28(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rsp)
movq -0x40(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rsp)
movzbl (%rax), %eax
movl %eax, -0xc(%rsp)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x10(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x14(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x2(%rax)
movq -0x30(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x30(%rsp)
movq -0x40(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rsp)
movzbl (%rax), %eax
movl %eax, -0xc(%rsp)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x10(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x14(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x2(%rax)
movq -0x30(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x30(%rsp)
movl -0x54(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rsp)
jmp 0xf88bb
movq 0x18(%rsp), %rax
movl 0x88(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf8c51
movq -0x48(%rsp), %rax
movzbl (%rax), %eax
movl %eax, -0x1c(%rsp)
movq -0x50(%rsp), %rax
movzbl (%rax), %eax
movl %eax, -0x20(%rsp)
movq -0x68(%rsp), %rax
movslq -0x20(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x10(%rsp)
movq -0x80(%rsp), %rax
movslq -0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x78(%rsp), %rcx
movslq -0x20(%rsp), %rdx
addq (%rcx,%rdx,8), %rax
sarq $0x10, %rax
movl %eax, -0x14(%rsp)
movq -0x70(%rsp), %rax
movslq -0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rsp)
movq -0x38(%rsp), %rax
movzbl (%rax), %eax
movl %eax, -0xc(%rsp)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x10(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x14(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rsp), %rax
movb %cl, 0x2(%rax)
movq -0x40(%rsp), %rax
movzbl (%rax), %eax
movl %eax, -0xc(%rsp)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x10(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x14(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x1(%rax)
movq -0x60(%rsp), %rax
movl -0xc(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rsp), %rax
movb %cl, 0x2(%rax)
addq $0x20, %rsp
retq
nopw %cs:(%rax,%rax)