// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %r8, 0x38(%rsp)
movq %rsi, 0x40(%rsp)
movl 0x80(%rsp), %eax
cmpl %eax, (%r9)
jae 0x75a7f
movq %r9, %r15
movl %ecx, %ebx
movq %rdx, %r14
movq %rdi, %r13
movq 0x1c0(%rdi), %rbp
movl 0x13c(%rdi), %eax
leal (%rax,%rax,2), %eax
movl %eax, 0x24(%rsp)
leaq 0x10(%rbp), %r10
movl %ecx, 0x4(%rsp)
movq %rdx, 0x28(%rsp)
movq %rbp, 0x10(%rsp)
movq %r10, 0x8(%rsp)
movq %r9, 0x30(%rsp)
movl (%r14), %eax
cmpl %eax, %ebx
jbe 0x75975
subl %eax, %ebx
movl 0x64(%rbp), %ecx
movl 0x6c(%rbp), %r12d
subl %ecx, %r12d
cmpl %ebx, %r12d
cmovael %ebx, %r12d
movq 0x1d8(%r13), %r9
movq 0x40(%rsp), %rdx
leaq (%rdx,%rax,8), %rsi
movq %r13, %rdi
movq %r10, %rdx
movl %r12d, %r8d
callq *0x8(%r9)
movl 0x60(%rbp), %eax
cmpl 0x34(%r13), %eax
jne 0x7594d
cmpl $0x0, 0x4c(%r13)
jle 0x7594d
xorl %ebx, %ebx
cmpl $0x0, 0x13c(%r13)
movq 0x8(%rsp), %r15
jle 0x75941
xorl %r14d, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%r15,%rbx,8), %rdi
movl 0x30(%r13), %r9d
xorl %esi, %esi
movq %rdi, %rdx
movl %ebp, %ecx
movl $0x1, %r8d
callq 0x86abf
incl %r14d
decl %ebp
cmpl 0x13c(%r13), %r14d
jl 0x75919
incq %rbx
movslq 0x4c(%r13), %rax
cmpq %rax, %rbx
jl 0x75902
movq 0x28(%rsp), %r14
addl %r12d, (%r14)
movq 0x10(%rsp), %rbp
addl %r12d, 0x64(%rbp)
subl %r12d, 0x60(%rbp)
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %r10
movq 0x30(%rsp), %r15
jmp 0x75a15
cmpl $0x0, 0x60(%rbp)
jne 0x75a7f
movl 0x64(%rbp), %eax
cmpl 0x6c(%rbp), %eax
jge 0x75a15
cmpl $0x0, 0x4c(%r13)
jle 0x759fc
movq $0x0, 0x18(%rsp)
movl 0x64(%rbp), %r12d
movl 0x6c(%rbp), %r14d
cmpl %r14d, %r12d
jge 0x759e1
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x10(%rax,%rcx,8), %rbp
movl 0x30(%r13), %r15d
leal -0x1(%r12), %ebx
movq %rbp, %rdi
movl %ebx, %esi
movq %rbp, %rdx
movl %r12d, %ecx
movl $0x1, %r8d
movl %r15d, %r9d
callq 0x86abf
incl %r12d
cmpl %r12d, %r14d
jne 0x759c0
movq 0x18(%rsp), %rdx
incq %rdx
movslq 0x4c(%r13), %rax
movq %rdx, 0x18(%rsp)
cmpq %rax, %rdx
movq 0x10(%rsp), %rbp
jl 0x7599b
movl 0x6c(%rbp), %eax
movl %eax, 0x64(%rbp)
movq 0x30(%rsp), %r15
movl 0x4(%rsp), %ebx
movq 0x28(%rsp), %r14
movq 0x8(%rsp), %r10
movl 0x64(%rbp), %eax
cmpl 0x6c(%rbp), %eax
jne 0x75a6f
movq 0x1e0(%r13), %rax
movl 0x68(%rbp), %edx
movl (%r15), %r8d
movq %r13, %rdi
movq %r10, %rsi
movq 0x38(%rsp), %rcx
callq *0x8(%rax)
incl (%r15)
movl 0x13c(%r13), %eax
movl 0x68(%rbp), %ecx
addl %eax, %ecx
movl 0x24(%rsp), %edx
cmpl %edx, %ecx
movl $0x0, %esi
cmovgel %esi, %ecx
movl %ecx, 0x68(%rbp)
cmpl %edx, 0x64(%rbp)
jl 0x75a64
movl $0x0, 0x64(%rbp)
addl 0x64(%rbp), %eax
movl %eax, 0x6c(%rbp)
movq 0x8(%rsp), %r10
movl 0x80(%rsp), %eax
cmpl %eax, (%r15)
jb 0x758b5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq