// File: /workspace/github_cpp_makefile_star2_O3/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, 0x40(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x38(%rsp)
movl 0x80(%rsp), %eax
cmpl %eax, (%r9)
jae 0x74b31
movq %r9, %r12
movl %ecx, %ebx
movq %rdi, %r13
movq 0x1c0(%rdi), %rdx
movl 0x13c(%rdi), %eax
leal (%rax,%rax,2), %eax
movl %eax, 0x24(%rsp)
leaq 0x10(%rdx), %r14
movl %ecx, 0x4(%rsp)
movq %rdx, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %r9, 0x30(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl %eax, %ebx
jbe 0x74a2e
movq %rdx, %r15
subl %eax, %ebx
movl 0x64(%rdx), %ecx
movl 0x6c(%rdx), %r8d
subl %ecx, %r8d
cmpl %ebx, %r8d
cmovael %ebx, %r8d
movq 0x1d8(%r13), %r9
movq 0x38(%rsp), %rdx
leaq (%rdx,%rax,8), %rsi
movq %r13, %rdi
movq %r14, %rdx
movl %r8d, 0x18(%rsp)
callq *0x8(%r9)
movl 0x60(%r15), %eax
cmpl 0x34(%r13), %eax
jne 0x74a02
movl 0x4c(%r13), %ecx
testl %ecx, %ecx
jle 0x74a02
movl 0x13c(%r13), %eax
xorl %ebx, %ebx
testl %eax, %eax
jle 0x749f7
movq %r12, %r14
xorl %r15d, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %r12
movq (%r12,%rbx,8), %rdi
movl 0x30(%r13), %r9d
xorl %esi, %esi
movq %rdi, %rdx
movl %ebp, %ecx
movl $0x1, %r8d
callq 0x85cb7
movl 0x13c(%r13), %eax
incl %r15d
decl %ebp
cmpl %eax, %r15d
jl 0x749c5
movl 0x4c(%r13), %ecx
movq %r14, %r12
incq %rbx
movslq %ecx, %rdx
cmpq %rdx, %rbx
jl 0x749b1
movq 0x28(%rsp), %rax
movl 0x18(%rsp), %ecx
addl %ecx, (%rax)
movq 0x8(%rsp), %rdx
movl 0x64(%rdx), %eax
addl %ecx, %eax
movl %eax, 0x64(%rdx)
subl %ecx, 0x60(%rdx)
movl 0x6c(%rdx), %ecx
movl 0x4(%rsp), %ebx
movq 0x10(%rsp), %r14
jmp 0x74abf
cmpl $0x0, 0x60(%rdx)
jne 0x74b31
movl 0x64(%rdx), %eax
movl 0x6c(%rdx), %ecx
cmpl %ecx, %eax
jge 0x74abf
movl 0x4c(%r13), %eax
testl %eax, %eax
jle 0x74ab6
xorl %esi, %esi
movl 0x64(%rdx), %r14d
movl 0x6c(%rdx), %r12d
cmpl %r12d, %r14d
jge 0x74a9a
movq %rsi, 0x18(%rsp)
movq 0x10(%rdx,%rsi,8), %rbp
movl 0x30(%r13), %r15d
leal -0x1(%r14), %ebx
movq %rbp, %rdi
movl %ebx, %esi
movq %rbp, %rdx
movl %r14d, %ecx
movl $0x1, %r8d
movl %r15d, %r9d
callq 0x85cb7
incl %r14d
cmpl %r14d, %r12d
jne 0x74a6b
movl 0x4c(%r13), %eax
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rsi
incq %rsi
movslq %eax, %rcx
cmpq %rcx, %rsi
jl 0x74a4c
movl 0x6c(%rdx), %ecx
movq 0x30(%rsp), %r12
movl 0x4(%rsp), %ebx
movq 0x10(%rsp), %r14
movl %ecx, 0x64(%rdx)
movl (%r12), %r8d
jmp 0x74ac7
movl (%r12), %r8d
cmpl %ecx, %eax
jne 0x74b23
movq 0x1e0(%r13), %rax
movq 0x8(%rsp), %rcx
movl 0x68(%rcx), %edx
movq %r13, %rdi
movq %r14, %rsi
movq 0x40(%rsp), %rcx
callq *0x8(%rax)
movq 0x8(%rsp), %rdx
incl (%r12)
movl 0x13c(%r13), %eax
movl 0x68(%rdx), %ecx
addl %eax, %ecx
movl 0x24(%rsp), %esi
cmpl %esi, %ecx
movl $0x0, %edi
cmovgel %edi, %ecx
movl %ecx, 0x68(%rdx)
movl 0x64(%rdx), %ecx
cmpl %esi, %ecx
jl 0x74b1a
movl $0x0, 0x64(%rdx)
xorl %ecx, %ecx
addl %eax, %ecx
movl %ecx, 0x6c(%rdx)
movl (%r12), %r8d
cmpl 0x80(%rsp), %r8d
jb 0x74952
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq