// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jcprepct.c
// Function: pre_process_context
METHODDEF(void)
pre_process_context (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;
  int buf_height = cinfo->max_v_samp_factor * 3;
  JDIMENSION inrows;

  while (*out_row_group_ctr < out_row_groups_avail) {
    if (*in_row_ctr < in_rows_avail) {
      /* Do color conversion to fill the conversion buffer. */
      inrows = in_rows_avail - *in_row_ctr;
      numrows = prep->next_buf_stop - 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);
      /* Pad at top of image, if first time through */
      if (prep->rows_to_go == cinfo->image_height) {
	for (ci = 0; ci < cinfo->num_components; ci++) {
	  int row;
	  for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
	    jcopy_sample_rows(prep->color_buf[ci], 0,
			      prep->color_buf[ci], -row,
			      1, cinfo->image_width);
	  }
	}
      }
      *in_row_ctr += numrows;
      prep->next_buf_row += numrows;
      prep->rows_to_go -= numrows;
    } else {
      /* Return for more data, unless we are at the bottom of the image. */
      if (prep->rows_to_go != 0)
	break;
      /* When at bottom of image, pad to fill the conversion buffer. */
      if (prep->next_buf_row < prep->next_buf_stop) {
	for (ci = 0; ci < cinfo->num_components; ci++) {
	  expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
			     prep->next_buf_row, prep->next_buf_stop);
	}
	prep->next_buf_row = prep->next_buf_stop;
      }
    }
    /* If we've gotten enough data, downsample a row group. */
    if (prep->next_buf_row == prep->next_buf_stop) {
      (*cinfo->downsample->downsample) (cinfo,
					prep->color_buf,
					(JDIMENSION) prep->this_row_group,
					output_buf, *out_row_group_ctr);
      (*out_row_group_ctr)++;
      /* Advance pointers with wraparound as necessary. */
      prep->this_row_group += cinfo->max_v_samp_factor;
      if (prep->this_row_group >= buf_height)
	prep->this_row_group = 0;
      if (prep->next_buf_row >= buf_height)
	prep->next_buf_row = 0;
      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r15
movq %r8, 0x30(%rsp)
movl %ecx, %ebp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %r13
movq 0x1c0(%rdi), %r14
imull $0x3, 0x13c(%rdi), %eax
movl %eax, 0x10(%rsp)
leaq 0x10(%r14), %r12
pushq $0x1
popq %rbx
movq %r14, (%rsp)
movq %r9, 0x28(%rsp)
movl %ecx, 0xc(%rsp)
movl 0x70(%rsp), %eax
cmpl %eax, (%r15)
jae 0x6ac44
movq 0x18(%rsp), %rax
movl (%rax), %eax
cmpl %eax, %ebp
jbe 0x6ab70
subl %eax, %ebp
movl 0x64(%r14), %ecx
movl 0x6c(%r14), %r8d
subl %ecx, %r8d
cmpl %ebp, %r8d
cmovael %ebp, %r8d
movq 0x1d8(%r13), %r9
movq 0x20(%rsp), %rdx
leaq (%rdx,%rax,8), %rsi
movq %r13, %rdi
movq %r12, %rdx
movl %r8d, 0x14(%rsp)
callq *0x8(%r9)
movl 0x60(%r14), %eax
cmpl 0x34(%r13), %eax
jne 0x6abb0
xorl %ebp, %ebp
movslq 0x4c(%r13), %rax
cmpq %rax, %rbp
jge 0x6abb0
pushq $-0x1
popq %r15
movl %ebx, %r14d
cmpl 0x13c(%r13), %r14d
jg 0x6ab67
movq (%r12,%rbp,8), %rdi
movl 0x30(%r13), %r9d
xorl %esi, %esi
movq %rdi, %rdx
movl %r15d, %ecx
movl %ebx, %r8d
callq 0x79173
incl %r14d
decl %r15d
jmp 0x6ab3e
incq %rbp
movq (%rsp), %r14
jmp 0x6ab2e
cmpl $0x0, 0x60(%r14)
jne 0x6ac44
movl 0x64(%r14), %eax
movl 0x6c(%r14), %ecx
cmpl %ecx, %eax
jge 0x6abd6
xorl %r14d, %r14d
movslq 0x4c(%r13), %rax
cmpq %rax, %r14
jge 0x6abe0
movq (%rsp), %rax
movq 0x10(%rax,%r14,8), %rdi
movl 0x30(%r13), %esi
movl 0x64(%rax), %edx
movl 0x6c(%rax), %ecx
callq 0x6adc8
incq %r14
jmp 0x6ab8a
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl %ecx, (%rax)
movl 0x64(%r14), %eax
addl %ecx, %eax
movl %eax, 0x64(%r14)
subl %ecx, 0x60(%r14)
movl 0x6c(%r14), %ecx
movq 0x28(%rsp), %r15
movl 0xc(%rsp), %ebp
cmpl %ecx, %eax
jne 0x6aacf
jmp 0x6abec
movq (%rsp), %r14
movl 0x6c(%r14), %eax
movl %eax, 0x64(%r14)
movq 0x1e0(%r13), %rax
movl 0x68(%r14), %edx
movl (%r15), %r8d
movq %r13, %rdi
movq %r12, %rsi
movq 0x30(%rsp), %rcx
callq *0x8(%rax)
incl (%r15)
movl 0x13c(%r13), %eax
movl 0x68(%r14), %ecx
addl %eax, %ecx
movl 0x10(%rsp), %edx
cmpl %edx, %ecx
movl $0x0, %esi
cmovgel %esi, %ecx
movl %ecx, 0x68(%r14)
movl 0x64(%r14), %ecx
cmpl %edx, %ecx
jl 0x6ac39
andl $0x0, 0x64(%r14)
xorl %ecx, %ecx
addl %eax, %ecx
movl %ecx, 0x6c(%r14)
jmp 0x6aacf
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq