// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jcsample.c
// Function: int_downsample
METHODDEF(void)
int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
		JSAMPARRAY input_data, JSAMPARRAY output_data)
{
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  JDIMENSION outcol, outcol_h;	/* outcol_h == outcol*h_expand */
  JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  JSAMPROW inptr, outptr;
  INT32 outvalue;

  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  numpix = h_expand * v_expand;
  numpix2 = numpix/2;

  /* Expand input data enough to let all the output samples be generated
   * by the standard loop.  Special-casing padded output would be more
   * efficient.
   */
  expand_right_edge(input_data, cinfo->max_v_samp_factor,
		    cinfo->image_width, output_cols * h_expand);

  inrow = 0;
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
    outptr = output_data[outrow];
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
	 outcol++, outcol_h += h_expand) {
      outvalue = 0;
      for (v = 0; v < v_expand; v++) {
	inptr = input_data[inrow+v] + outcol_h;
	for (h = 0; h < h_expand; h++) {
	  outvalue += (INT32) GETJSAMPLE(*inptr++);
	}
      }
      *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
    }
    inrow += v_expand;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x20(%rsp)
movq %rdx, %r15
movl 0xc(%rsi), %r14d
movl 0x1c(%rsi), %r10d
movl 0x138(%rdi), %eax
cltd
movq %rsi, 0x10(%rsp)
idivl 0x8(%rsi)
movl %eax, %ebp
shll $0x3, %r10d
movslq 0x13c(%rdi), %rbx
movl %ebx, %eax
cltd
idivl %r14d
movl %eax, 0x4(%rsp)
testq %rbx, %rbx
movl %r10d, %r12d
jle 0x76a87
movl 0x30(%rdi), %r13d
movl %ebp, %eax
imull %r10d, %eax
movq %rax, %rdx
subl %r13d, %eax
testl %eax, %eax
jle 0x76a87
movl %r13d, %eax
notl %eax
addl %eax, %edx
incq %rdx
movq %rdx, 0x8(%rsp)
xorl %r14d, %r14d
movq (%r15,%r14,8), %rdi
movzbl -0x1(%rdi,%r13), %esi
addq %r13, %rdi
movq 0x8(%rsp), %rdx
callq 0xe260
incq %r14
cmpq %r14, %rbx
jne 0x76a5c
movq 0x10(%rsp), %rax
movl 0xc(%rax), %r14d
movl %r12d, %r10d
testl %r14d, %r14d
jle 0x76b62
movl 0x4(%rsp), %edx
movl %edx, %eax
imull %ebp, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
movslq %eax, %rsi
movslq %edx, %rax
movq %rax, 0x28(%rsp)
movl %eax, %r8d
movl %ebp, %r9d
xorl %edx, %edx
xorl %edi, %edi
movq %r15, 0x18(%rsp)
testl %r10d, %r10d
je 0x76b4e
movq 0x20(%rsp), %rax
movq %rdx, 0x8(%rsp)
movq (%rax,%rdx,8), %rbx
movq %rdi, 0x30(%rsp)
leaq (%r15,%rdi,8), %r14
xorl %r13d, %r13d
xorl %edi, %edi
movl %r13d, %r13d
cmpl $0x0, 0x4(%rsp)
jle 0x76b1a
xorl %edx, %edx
xorl %eax, %eax
testl %ebp, %ebp
jle 0x76b10
movq (%r14,%rdx,8), %r11
addq %r13, %r11
xorl %r10d, %r10d
movzbl (%r11,%r10), %r15d
addq %r15, %rax
incq %r10
cmpl %r10d, %r9d
jne 0x76b00
incq %rdx
cmpq %r8, %rdx
jne 0x76af2
jmp 0x76b1c
xorl %eax, %eax
addq %rcx, %rax
cqto
idivq %rsi
movb %al, (%rbx)
incq %rbx
incl %edi
addl %ebp, %r13d
cmpl %r12d, %edi
jne 0x76ae4
movl %r12d, %r10d
movq 0x10(%rsp), %rax
movl 0xc(%rax), %r14d
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rdx
movq 0x30(%rsp), %rdi
addq 0x28(%rsp), %rdi
incq %rdx
movslq %r14d, %rax
cmpq %rax, %rdx
jl 0x76abf
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)