// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
movq %rdx, %rbx
movl 0x1c(%rsi), %eax
shll $0x3, %eax
movl %eax, 0x4(%rsp)
movl 0x138(%rdi), %eax
cltd
idivl 0x8(%rsi)
movl %eax, %ebp
movslq 0x13c(%rdi), %r15
movl %r15d, %eax
cltd
movq %rsi, 0x18(%rsp)
idivl 0xc(%rsi)
movl %eax, %r12d
testq %r15, %r15
jle 0x779b4
movl 0x30(%rdi), %r14d
movl %ebp, %eax
imull 0x4(%rsp), %eax
movq %rax, %rdx
subl %r14d, %eax
testl %eax, %eax
jle 0x779b4
movl %r14d, %eax
notl %eax
addl %eax, %edx
incq %rdx
movq %rdx, 0x8(%rsp)
xorl %r13d, %r13d
movq (%rbx,%r13,8), %rdi
movzbl -0x1(%rdi,%r14), %esi
addq %r14, %rdi
movq 0x8(%rsp), %rdx
callq 0xe260
incq %r13
cmpq %r13, %r15
jne 0x77995
movq %rbx, 0x20(%rsp)
movq 0x18(%rsp), %rax
cmpl $0x0, 0xc(%rax)
jle 0x77aa2
movl %r12d, %eax
imull %ebp, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
movslq %eax, %rsi
movslq %r12d, %rax
movq %rax, 0x30(%rsp)
movl %eax, %r8d
movl %ebp, %r9d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0x77a74
movq 0x28(%rsp), %rax
movq 0x8(%rsp), %rdx
movq (%rax,%rdx,8), %rbx
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdx
leaq (%rax,%rdx,8), %r13
xorl %r14d, %r14d
xorl %edi, %edi
movl %r14d, %r14d
testl %r12d, %r12d
jle 0x77a5a
xorl %edx, %edx
xorl %eax, %eax
testl %ebp, %ebp
jle 0x77a50
movq (%r13,%rdx,8), %r11
addq %r14, %r11
xorl %r10d, %r10d
movzbl (%r11,%r10), %r15d
addq %r15, %rax
incq %r10
cmpl %r10d, %r9d
jne 0x77a40
incq %rdx
cmpq %r8, %rdx
jne 0x77a31
jmp 0x77a5c
xorl %eax, %eax
addq %rcx, %rax
cqto
idivq %rsi
movb %al, (%rbx)
incq %rbx
incl %edi
addl %ebp, %r14d
cmpl 0x4(%rsp), %edi
jne 0x77a25
movq 0x10(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rdi
incq %rdi
movq 0x18(%rsp), %rax
movslq 0xc(%rax), %rax
movq %rdi, 0x8(%rsp)
cmpq %rax, %rdi
jl 0x779fd
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)