// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdsample.c
// Function: h2v1_fancy_upsample
METHODDEF(void)
h2v1_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 inptr, outptr;
  register int invalue;
  register JDIMENSION colctr;
  int inrow;

  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
    inptr = input_data[inrow];
    outptr = output_data[inrow];
    /* Special case for first column */
    invalue = GETJSAMPLE(*inptr++);
    *outptr++ = (JSAMPLE) invalue;
    *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);

    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
      invalue = GETJSAMPLE(*inptr++) * 3;
      *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
      *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
    }

    /* Special case for last column */
    invalue = GETJSAMPLE(*inptr);
    *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
    *outptr++ = (JSAMPLE) invalue;
  }
}

// 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, -0x44(%rsp)
movl -0x44(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x19c(%rcx), %eax
jge 0xf30c3
movq -0x18(%rsp), %rax
movslq -0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rsp)
movq -0x28(%rsp), %rax
movslq -0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
movq -0x30(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rsp)
movzbl (%rax), %eax
movl %eax, -0x3c(%rsp)
movl -0x3c(%rsp), %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
imull $0x3, -0x3c(%rsp), %eax
movq -0x30(%rsp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
movq -0x10(%rsp), %rax
movl 0x28(%rax), %eax
subl $0x2, %eax
movl %eax, -0x40(%rsp)
cmpl $0x0, -0x40(%rsp)
jbe 0xf3063
movq -0x30(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rsp)
movzbl (%rax), %eax
imull $0x3, %eax, %eax
movl %eax, -0x3c(%rsp)
movl -0x3c(%rsp), %eax
movq -0x30(%rsp), %rcx
movzbl -0x2(%rcx), %ecx
addl %ecx, %eax
addl $0x1, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
movl -0x3c(%rsp), %eax
movq -0x30(%rsp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
movl -0x40(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rsp)
jmp 0xf2fde
movq -0x30(%rsp), %rax
movzbl (%rax), %eax
movl %eax, -0x3c(%rsp)
imull $0x3, -0x3c(%rsp), %eax
movq -0x30(%rsp), %rcx
movzbl -0x1(%rcx), %ecx
addl %ecx, %eax
addl $0x1, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
movl -0x3c(%rsp), %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
movl -0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rsp)
jmp 0xf2f39
retq
nopw %cs:(%rax,%rax)