// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcapistd.c
// Function: jpeg_write_scanlines
GLOBAL(JDIMENSION)
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
		      JDIMENSION num_lines)
{
  JDIMENSION row_ctr, rows_left;

  if (cinfo->global_state != CSTATE_SCANNING)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  if (cinfo->next_scanline >= cinfo->image_height)
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);

  /* Call progress monitor hook if present */
  if (cinfo->progress != NULL) {
    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
    cinfo->progress->pass_limit = (long) cinfo->image_height;
    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  }

  /* Give master control module another chance if this is first call to
   * jpeg_write_scanlines.  This lets output of the frame/scan headers be
   * delayed so that application can write COM, etc, markers between
   * jpeg_start_compress and jpeg_write_scanlines.
   */
  if (cinfo->master->call_pass_startup)
    (*cinfo->master->pass_startup) (cinfo);

  /* Ignore any extra scanlines at bottom of image. */
  rows_left = cinfo->image_height - cinfo->next_scanline;
  if (num_lines > rows_left)
    num_lines = rows_left;

  row_ctr = 0;
  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  cinfo->next_scanline += row_ctr;
  return row_ctr;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movq 0x20(%rsp), %rax
cmpl $0x65, 0x24(%rax)
je 0xd5961
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x14, 0x28(%rax)
movq 0x20(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
movl 0x130(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x34(%rcx), %eax
jb 0xd599d
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x7b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
movq 0x20(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0xd59ed
movq 0x20(%rsp), %rax
movl 0x130(%rax), %eax
movl %eax, %ecx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, %ecx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
movq 0x1b0(%rax), %rax
cmpl $0x0, 0x18(%rax)
je 0xd5a16
movq 0x20(%rsp), %rax
movq 0x1b0(%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
movq 0x20(%rsp), %rcx
subl 0x130(%rcx), %eax
movl %eax, 0xc(%rsp)
movl 0x14(%rsp), %eax
cmpl 0xc(%rsp), %eax
jbe 0xd5a3f
movl 0xc(%rsp), %eax
movl %eax, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq 0x1b8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %ecx
leaq 0x10(%rsp), %rdx
callq *%rax
movl 0x10(%rsp), %ecx
movq 0x20(%rsp), %rax
addl 0x130(%rax), %ecx
movl %ecx, 0x130(%rax)
movl 0x10(%rsp), %eax
addq $0x28, %rsp
retq
nopw (%rax,%rax)