// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jdsample.c
// Function: sep_upsample
METHODDEF(void)
sep_upsample (j_decompress_ptr cinfo,
	      JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
	      JDIMENSION in_row_groups_avail,
	      JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
	      JDIMENSION out_rows_avail)
{
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  int ci;
  jpeg_component_info * compptr;
  JDIMENSION num_rows;

  /* Fill the conversion buffer, if it's empty */
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
	 ci++, compptr++) {
      /* Invoke per-component upsample method.  Notice we pass a POINTER
       * to color_buf[ci], so that fullsize_upsample can change it.
       */
      (*upsample->methods[ci]) (cinfo, compptr,
	input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
	upsample->color_buf + ci);
    }
    upsample->next_row_out = 0;
  }

  /* Color-convert and emit rows */

  /* How many we have in the buffer: */
  num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  /* Not more than the distance to the end of the image.  Need this test
   * in case the image height is not a multiple of max_v_samp_factor:
   */
  if (num_rows > upsample->rows_to_go) 
    num_rows = upsample->rows_to_go;
  /* And not more than what the client can accept: */
  out_rows_avail -= *out_row_ctr;
  if (num_rows > out_rows_avail)
    num_rows = out_rows_avail;

  (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
				     (JDIMENSION) upsample->next_row_out,
				     output_buf + *out_row_ctr,
				     (int) num_rows);

  /* Adjust counts */
  *out_row_ctr += num_rows;
  upsample->rows_to_go -= num_rows;
  upsample->next_row_out += num_rows;
  /* When the buffer is emptied, declare this input row group consumed */
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
    (*in_row_group_ctr)++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r12
movq %rdx, %r15
movq %rdi, %r14
movl 0x50(%rsp), %ebp
movq 0x260(%rdi), %rbx
movl 0xb8(%rbx), %edx
movl 0x19c(%rdi), %eax
cmpl %eax, %edx
jl 0x82aa4
cmpl $0x0, 0x38(%r14)
jle 0x82a98
movq %rsi, %r13
movq %r8, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq 0x130(%r14), %r12
movq %r15, (%rsp)
leaq 0x18(%rbx), %r15
xorl %ebp, %ebp
movl 0xc0(%rbx,%rbp,4), %edx
movq (%rsp), %rax
imull (%rax), %edx
shlq $0x3, %rdx
addq (%r13,%rbp,8), %rdx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq *0x68(%rbx,%rbp,8)
incq %rbp
addq $0x60, %r12
movslq 0x38(%r14), %rax
addq $0x8, %r15
cmpq %rax, %rbp
jl 0x82a47
movl 0x19c(%r14), %eax
movq (%rsp), %r15
movq 0x10(%rsp), %r12
movl 0x50(%rsp), %ebp
movq 0x8(%rsp), %r8
movl $0x0, 0xb8(%rbx)
xorl %edx, %edx
subl %edx, %eax
movl 0xbc(%rbx), %ecx
cmpl %ecx, %eax
cmovael %ecx, %eax
movl (%r12), %ecx
subl %ecx, %ebp
cmpl %ebp, %eax
cmovbl %eax, %ebp
movq 0x268(%r14), %rax
leaq 0x18(%rbx), %rsi
leaq (%r8,%rcx,8), %rcx
movq %r14, %rdi
movl %ebp, %r8d
callq *0x8(%rax)
addl %ebp, (%r12)
subl %ebp, 0xbc(%rbx)
addl 0xb8(%rbx), %ebp
movl %ebp, 0xb8(%rbx)
cmpl 0x19c(%r14), %ebp
jl 0x82af6
incl (%r15)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq