// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdsample.c
// Function: h2v2_fancy_upsample
METHODDEF(void)
h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
		     JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{
  JSAMPARRAY output_data = *output_data_ptr;
  register JSAMPROW inptr0, inptr1, outptr;
#if BITS_IN_JSAMPLE == 8
  register int thiscolsum, lastcolsum, nextcolsum;
#else
  register INT32 thiscolsum, lastcolsum, nextcolsum;
#endif
  register JDIMENSION colctr;
  int inrow, outrow, v;

  inrow = outrow = 0;
  while (outrow < cinfo->max_v_samp_factor) {
    for (v = 0; v < 2; v++) {
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
      inptr0 = input_data[inrow];
      if (v == 0)		/* next nearest is row above */
	inptr1 = input_data[inrow-1];
      else			/* next nearest is row below */
	inptr1 = input_data[inrow+1];
      outptr = output_data[outrow++];

      /* Special case for first column */
      thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
      nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
      *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
      *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
      lastcolsum = thiscolsum; thiscolsum = nextcolsum;

      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
	/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
	/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
	nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
	*outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
	*outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
	lastcolsum = thiscolsum; thiscolsum = nextcolsum;
      }

      /* Special case for last column */
      *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
      *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
    }
    inrow++;
  }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movq %rcx, -0x20(%rsp)
movq -0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rsp)
movl $0x0, -0x58(%rsp)
movl $0x0, -0x54(%rsp)
movl -0x58(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x19c(%rcx), %eax
jge 0xf3454
movl $0x0, -0x5c(%rsp)
cmpl $0x2, -0x5c(%rsp)
jge 0xf3444
movq -0x18(%rsp), %rax
movslq -0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rsp)
cmpl $0x0, -0x5c(%rsp)
jne 0xf324d
movq -0x18(%rsp), %rax
movl -0x54(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
jmp 0xf3265
movq -0x18(%rsp), %rax
movl -0x54(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
movq -0x28(%rsp), %rax
movl -0x58(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x58(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rsp)
movq -0x30(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rsp)
movzbl (%rax), %eax
imull $0x3, %eax, %eax
movq -0x38(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movzbl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x44(%rsp)
movq -0x30(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rsp)
movzbl (%rax), %eax
imull $0x3, %eax, %eax
movq -0x38(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movzbl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x4c(%rsp)
movl -0x44(%rsp), %eax
shll $0x2, %eax
addl $0x8, %eax
sarl $0x4, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
imull $0x3, -0x44(%rsp), %eax
addl -0x4c(%rsp), %eax
addl $0x7, %eax
sarl $0x4, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
movl -0x44(%rsp), %eax
movl %eax, -0x48(%rsp)
movl -0x4c(%rsp), %eax
movl %eax, -0x44(%rsp)
movq -0x10(%rsp), %rax
movl 0x28(%rax), %eax
subl $0x2, %eax
movl %eax, -0x50(%rsp)
cmpl $0x0, -0x50(%rsp)
jbe 0xf33ee
movq -0x30(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rsp)
movzbl (%rax), %eax
imull $0x3, %eax, %eax
movq -0x38(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movzbl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x4c(%rsp)
imull $0x3, -0x44(%rsp), %eax
addl -0x48(%rsp), %eax
addl $0x8, %eax
sarl $0x4, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
imull $0x3, -0x44(%rsp), %eax
addl -0x4c(%rsp), %eax
addl $0x7, %eax
sarl $0x4, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
movl -0x44(%rsp), %eax
movl %eax, -0x48(%rsp)
movl -0x4c(%rsp), %eax
movl %eax, -0x44(%rsp)
movl -0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x50(%rsp)
jmp 0xf334a
imull $0x3, -0x44(%rsp), %eax
addl -0x48(%rsp), %eax
addl $0x8, %eax
sarl $0x4, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
movl -0x44(%rsp), %eax
shll $0x2, %eax
addl $0x7, %eax
sarl $0x4, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
movl -0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rsp)
jmp 0xf320e
movl -0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rsp)
jmp 0xf31f1
retq
nopw %cs:(%rax,%rax)