// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, -0x10(%rsp)
movq %rdi, -0x8(%rsp)
movq (%rcx), %rax
xorl %edi, %edi
xorl %r8d, %r8d
movq -0x8(%rsp), %rcx
cmpl 0x19c(%rcx), %r8d
jge 0x76710
movq -0x10(%rsp), %rcx
leaq (%rcx,%rdi,8), %r9
movslq %r8d, %r8
xorl %r10d, %r10d
cmpl $0x2, %r10d
je 0x76708
movq (%r9), %rbx
xorl %ecx, %ecx
testl %r10d, %r10d
setne %cl
shll $0x4, %ecx
movq -0x8(%rcx,%r9), %r14
movq (%rax,%r8,8), %r11
movzbl (%rbx), %ecx
leal (%rcx,%rcx,2), %ecx
movzbl (%r14), %r15d
addl %ecx, %r15d
movzbl 0x1(%rbx), %ecx
leal (%rcx,%rcx,2), %ebp
movzbl 0x1(%r14), %ecx
addl %ebp, %ecx
leal 0x8(,%r15,4), %ebp
shrl $0x4, %ebp
movb %bpl, (%r11)
leal (%r15,%r15,2), %r12d
leal (%r12,%rcx), %ebp
addl $0x7, %ebp
shrl $0x4, %ebp
movb %bpl, 0x1(%r11)
movl 0x28(%rsi), %ebp
addl $-0x2, %ebp
xorl %r12d, %r12d
movl %ecx, %r13d
cmpl %r12d, %ebp
je 0x766da
movzbl 0x2(%rbx,%r12), %ecx
leal (%rcx,%rcx,2), %edx
movzbl 0x2(%r14,%r12), %ecx
addl %edx, %ecx
leal (%r13,%r13,2), %edx
addl %edx, %r15d
addl $0x8, %r15d
shrl $0x4, %r15d
movb %r15b, 0x2(%r11,%r12,2)
addl %ecx, %edx
addl $0x7, %edx
shrl $0x4, %edx
movb %dl, 0x3(%r11,%r12,2)
incq %r12
movl %r13d, %r15d
jmp 0x76697
incq %r8
leal (%r13,%r13,2), %ecx
addl %r15d, %ecx
addl $0x8, %ecx
shrl $0x4, %ecx
movb %cl, 0x2(%r11,%r12,2)
leal 0x7(,%r13,4), %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%r11,%r12,2)
incl %r10d
jmp 0x76632
incq %rdi
jmp 0x76611
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq