// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcapistd.c
// Function: jpeg_write_raw_data
GLOBAL(JDIMENSION)
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
		     JDIMENSION num_lines)
{
  JDIMENSION lines_per_iMCU_row;

  if (cinfo->global_state != CSTATE_RAW_OK)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  if (cinfo->next_scanline >= cinfo->image_height) {
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
    return 0;
  }

  /* 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_raw_data.  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_raw_data.
   */
  if (cinfo->master->call_pass_startup)
    (*cinfo->master->pass_startup) (cinfo);

  /* Verify that at least one iMCU row has been passed. */
  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  if (num_lines < lines_per_iMCU_row)
    ERREXIT(cinfo, JERR_BUFFER_SIZE);

  /* Directly compress the row. */
  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
    /* If compressor did not consume the whole row, suspend processing. */
    return 0;
  }

  /* OK, we processed one iMCU row. */
  cinfo->next_scanline += lines_per_iMCU_row;
  return lines_per_iMCU_row;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq 0x18(%rsp), %rax
cmpl $0x66, 0x24(%rax)
je 0xd5ae1
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl $0x14, 0x28(%rax)
movq 0x18(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rdi
callq *%rax
movq 0x18(%rsp), %rax
movl 0x130(%rax), %eax
movq 0x18(%rsp), %rcx
cmpl 0x34(%rcx), %eax
jb 0xd5b2a
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl $0x7b, 0x28(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
movl $0x0, 0x24(%rsp)
jmp 0xd5c28
movq 0x18(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0xd5b7a
movq 0x18(%rsp), %rax
movl 0x130(%rax), %eax
movl %eax, %ecx
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, %ecx
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rdi
callq *%rax
movq 0x18(%rsp), %rax
movq 0x1b0(%rax), %rax
cmpl $0x0, 0x18(%rax)
je 0xd5ba3
movq 0x18(%rsp), %rax
movq 0x1b0(%rax), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rdi
callq *%rax
movq 0x18(%rsp), %rax
movl 0x13c(%rax), %eax
shll $0x3, %eax
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x8(%rsp), %eax
jae 0xd5be0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl $0x17, 0x28(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rdi
callq *%rax
movq 0x18(%rsp), %rax
movq 0x1c8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq *%rax
cmpl $0x0, %eax
jne 0xd5c0b
movl $0x0, 0x24(%rsp)
jmp 0xd5c28
movl 0x8(%rsp), %ecx
movq 0x18(%rsp), %rax
addl 0x130(%rax), %ecx
movl %ecx, 0x130(%rax)
movl 0x8(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)