// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcprepct.c
// Function: pre_process_data
METHODDEF(void)
pre_process_data (j_compress_ptr cinfo,
		  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
		  JDIMENSION in_rows_avail,
		  JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
		  JDIMENSION out_row_groups_avail)
{
  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  int numrows, ci;
  JDIMENSION inrows;
  jpeg_component_info * compptr;

  while (*in_row_ctr < in_rows_avail &&
	 *out_row_group_ctr < out_row_groups_avail) {
    /* Do color conversion to fill the conversion buffer. */
    inrows = in_rows_avail - *in_row_ctr;
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
    numrows = (int) MIN((JDIMENSION) numrows, inrows);
    (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
				       prep->color_buf,
				       (JDIMENSION) prep->next_buf_row,
				       numrows);
    *in_row_ctr += numrows;
    prep->next_buf_row += numrows;
    prep->rows_to_go -= numrows;
    /* If at bottom of image, pad to fill the conversion buffer. */
    if (prep->rows_to_go == 0 &&
	prep->next_buf_row < cinfo->max_v_samp_factor) {
      for (ci = 0; ci < cinfo->num_components; ci++) {
	expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
			   prep->next_buf_row, cinfo->max_v_samp_factor);
      }
      prep->next_buf_row = cinfo->max_v_samp_factor;
    }
    /* If we've filled the conversion buffer, empty it. */
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
      (*cinfo->downsample->downsample) (cinfo,
					prep->color_buf, (JDIMENSION) 0,
					output_buf, *out_row_group_ctr);
      prep->next_buf_row = 0;
      (*out_row_group_ctr)++;
    }
    /* If at bottom of image, pad the output to a full iMCU height.
     * Note we assume the caller is providing a one-iMCU-height output buffer!
     */
    if (prep->rows_to_go == 0 &&
	*out_row_group_ctr < out_row_groups_avail) {
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
	   ci++, compptr++) {
	expand_bottom_edge(output_buf[ci],
			   compptr->width_in_blocks * DCTSIZE,
			   (int) (*out_row_group_ctr * compptr->v_samp_factor),
			   (int) (out_row_groups_avail * compptr->v_samp_factor));
      }
      *out_row_group_ctr = out_row_groups_avail;
      break;			/* can exit outer loop without test */
    }
  }
}

// Assembly:
subq $0x58, %rsp
movl 0x60(%rsp), %eax
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movl %ecx, 0x3c(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq 0x50(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
movl (%rax), %ecx
xorl %eax, %eax
cmpl 0x3c(%rsp), %ecx
movb %al, 0x7(%rsp)
jae 0xda4db
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl 0x60(%rsp), %eax
setb %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0xda4e8
jmp 0xda729
movl 0x3c(%rsp), %eax
movq 0x40(%rsp), %rcx
subl (%rcx), %eax
movl %eax, 0x14(%rsp)
movq 0x50(%rsp), %rax
movl 0x13c(%rax), %eax
movq 0x20(%rsp), %rcx
subl 0x64(%rcx), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x14(%rsp), %eax
jae 0xda521
movl 0x1c(%rsp), %eax
movl %eax, (%rsp)
jmp 0xda528
movl 0x14(%rsp), %eax
movl %eax, (%rsp)
movl (%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x50(%rsp), %rax
movq 0x1d8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rcx
movl (%rcx), %ecx
shlq $0x3, %rcx
addq %rcx, %rsi
movq 0x20(%rsp), %rdx
addq $0x10, %rdx
movq 0x20(%rsp), %rcx
movl 0x64(%rcx), %ecx
movl 0x1c(%rsp), %r8d
callq *%rax
movl 0x1c(%rsp), %ecx
movq 0x40(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl 0x1c(%rsp), %ecx
movq 0x20(%rsp), %rax
addl 0x64(%rax), %ecx
movl %ecx, 0x64(%rax)
movl 0x1c(%rsp), %edx
movq 0x20(%rsp), %rax
movl 0x60(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x60(%rax)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x60(%rax)
jne 0xda621
movq 0x20(%rsp), %rax
movl 0x64(%rax), %eax
movq 0x50(%rsp), %rcx
cmpl 0x13c(%rcx), %eax
jge 0xda621
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0xda60e
movq 0x20(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq 0x10(%rax,%rcx,8), %rdi
movq 0x50(%rsp), %rax
movl 0x30(%rax), %esi
movq 0x20(%rsp), %rax
movl 0x64(%rax), %edx
movq 0x50(%rsp), %rax
movl 0x13c(%rax), %ecx
callq 0xda730
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0xda5c4
movq 0x50(%rsp), %rax
movl 0x13c(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x64(%rax)
movq 0x20(%rsp), %rax
movl 0x64(%rax), %eax
movq 0x50(%rsp), %rcx
cmpl 0x13c(%rcx), %eax
jne 0xda67d
movq 0x50(%rsp), %rax
movq 0x1e0(%rax), %rax
movq 0x8(%rax), %rax
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rsi
addq $0x10, %rsi
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdx
movl (%rdx), %r8d
xorl %edx, %edx
callq *%rax
movq 0x20(%rsp), %rax
movl $0x0, 0x64(%rax)
movq 0x28(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x60(%rax)
jne 0xda724
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl 0x60(%rsp), %eax
jae 0xda724
movl $0x0, 0x18(%rsp)
movq 0x50(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x18(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0xda717
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rax
movl 0x1c(%rax), %esi
shll $0x3, %esi
movq 0x28(%rsp), %rax
movl (%rax), %edx
movq 0x8(%rsp), %rax
imull 0xc(%rax), %edx
movl 0x60(%rsp), %ecx
movq 0x8(%rsp), %rax
imull 0xc(%rax), %ecx
callq 0xda730
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movq 0x8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xda6b3
movl 0x60(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
jmp 0xda729
jmp 0xda4b6
addq $0x58, %rsp
retq
nop