// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdpostct.c
// Function: post_process_2pass
METHODDEF(void)
post_process_2pass (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_post_ptr post = (my_post_ptr) cinfo->post;
  JDIMENSION num_rows, max_rows;

  /* Reposition virtual buffer if at start of strip. */
  if (post->next_row == 0) {
    post->buffer = (*cinfo->mem->access_virt_sarray)
	((j_common_ptr) cinfo, post->whole_image,
	 post->starting_row, post->strip_height, FALSE);
  }

  /* Determine number of rows to emit. */
  num_rows = post->strip_height - post->next_row; /* available in strip */
  max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  if (num_rows > max_rows)
    num_rows = max_rows;
  /* We have to check bottom of image here, can't depend on upsampler. */
  max_rows = cinfo->output_height - post->starting_row;
  if (num_rows > max_rows)
    num_rows = max_rows;

  /* Quantize and emit data. */
  (*cinfo->cquantize->color_quantize) (cinfo,
		post->buffer + post->next_row, output_buf + *out_row_ctr,
		(int) num_rows);
  *out_row_ctr += num_rows;

  /* Advance if we filled the strip. */
  post->next_row += num_rows;
  if (post->next_row >= post->strip_height) {
    post->starting_row += post->strip_height;
    post->next_row = 0;
  }
}

// Assembly:
subq $0x48, %rsp
movl 0x50(%rsp), %eax
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movl %ecx, 0x2c(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq 0x238(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0xef1dd
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rsi
movq 0x10(%rsp), %rcx
movl 0x24(%rcx), %edx
movq 0x10(%rsp), %rcx
movl 0x20(%rcx), %ecx
xorl %r8d, %r8d
callq *%rax
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x10(%rsp), %rcx
subl 0x28(%rcx), %eax
movl %eax, 0xc(%rsp)
movl 0x50(%rsp), %eax
movq 0x18(%rsp), %rcx
subl (%rcx), %eax
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x8(%rsp), %eax
jbe 0xef212
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rax
movl 0x8c(%rax), %eax
movq 0x10(%rsp), %rcx
subl 0x24(%rcx), %eax
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x8(%rsp), %eax
jbe 0xef23b
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rax
movq 0x270(%rax), %rax
movq 0x8(%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rsi
movq 0x10(%rsp), %rcx
movl 0x28(%rcx), %ecx
shlq $0x3, %rcx
addq %rcx, %rsi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movl (%rcx), %ecx
shlq $0x3, %rcx
addq %rcx, %rdx
movl 0xc(%rsp), %ecx
callq *%rax
movl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rax
addl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq 0x10(%rsp), %rax
movl 0x28(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jb 0xef2ce
movq 0x10(%rsp), %rax
movl 0x20(%rax), %ecx
movq 0x10(%rsp), %rax
addl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x28(%rax)
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)