// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmerge.c
// Function: h2v1_merged_upsample
METHODDEF(void)
h2v1_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 outptr;
  JSAMPROW inptr0, 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

  inptr0 = input_buf[0][in_row_group_ctr];
  inptr1 = input_buf[1][in_row_group_ctr];
  inptr2 = input_buf[2][in_row_group_ctr];
  outptr = output_buf[0];
  /* Loop for each pair 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 2 Y values and emit 2 pixels */
    y  = GETJSAMPLE(*inptr0++);
    outptr[RGB_RED] =   range_limit[y + cred];
    outptr[RGB_GREEN] = range_limit[y + cgreen];
    outptr[RGB_BLUE] =  range_limit[y + cblue];
    outptr += RGB_PIXELSIZE;
    y  = GETJSAMPLE(*inptr0++);
    outptr[RGB_RED] =   range_limit[y + cred];
    outptr[RGB_GREEN] = range_limit[y + cgreen];
    outptr[RGB_BLUE] =  range_limit[y + cblue];
    outptr += 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(*inptr0);
    outptr[RGB_RED] =   range_limit[y + cred];
    outptr[RGB_GREEN] = range_limit[y + cgreen];
    outptr[RGB_BLUE] =  range_limit[y + cblue];
  }
}

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