// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdcoefct.c
// Function: consume_data
METHODDEF(int)
consume_data (j_decompress_ptr cinfo)
{
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  JDIMENSION MCU_col_num;	/* index of current MCU within row */
  int blkn, ci, xindex, yindex, yoffset;
  JDIMENSION start_col;
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  JBLOCKROW buffer_ptr;
  jpeg_component_info *compptr;

  /* Align the virtual buffers for the components used in this scan. */
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
    compptr = cinfo->cur_comp_info[ci];
    buffer[ci] = (*cinfo->mem->access_virt_barray)
      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
       cinfo->input_iMCU_row * compptr->v_samp_factor,
       (JDIMENSION) compptr->v_samp_factor, TRUE);
    /* Note: entropy decoder expects buffer to be zeroed,
     * but this is handled automatically by the memory manager
     * because we requested a pre-zeroed array.
     */
  }

  /* Loop to process one whole iMCU row */
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
       yoffset++) {
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
	 MCU_col_num++) {
      /* Construct list of pointers to DCT blocks belonging to this MCU */
      blkn = 0;			/* index of current DCT block within MCU */
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
	compptr = cinfo->cur_comp_info[ci];
	start_col = MCU_col_num * compptr->MCU_width;
	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
	  buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
	  for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
	    coef->MCU_buffer[blkn++] = buffer_ptr++;
	  }
	}
      }
      /* Try to fetch the MCU. */
      if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
	/* Suspension forced; update state counters and exit */
	coef->MCU_vert_offset = yoffset;
	coef->MCU_ctr = MCU_col_num;
	return JPEG_SUSPENDED;
      }
    }
    /* Completed an MCU row, but perhaps not an iMCU row */
    coef->MCU_ctr = 0;
  }
  /* Completed the iMCU row, advance counters for next one */
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
    start_iMCU_row(cinfo);
    return JPEG_ROW_COMPLETED;
  }
  /* Completed the scan */
  (*cinfo->inputctl->finish_input_pass) (cinfo);
  return JPEG_SCAN_COMPLETED;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq 0x230(%rax), %rax
movq %rax, 0x50(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x1b0(%rcx), %eax
jge 0xed48f
movq 0x58(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq 0x1b8(%rax,%rcx,8), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x40(%rax), %rax
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rcx
movq (%rsp), %rdx
movslq 0x4(%rdx), %rdx
movq 0x88(%rcx,%rdx,8), %rsi
movq 0x58(%rsp), %rcx
movl 0xb0(%rcx), %edx
movq (%rsp), %rcx
imull 0xc(%rcx), %edx
movq (%rsp), %rcx
movl 0xc(%rcx), %ecx
movl $0x1, %r8d
callq *%rax
movq %rax, %rcx
movslq 0x44(%rsp), %rax
movq %rcx, 0x10(%rsp,%rax,8)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xed402
movq 0x50(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl 0x30(%rcx), %eax
jge 0xed646
movq 0x50(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x1d8(%rcx), %eax
jae 0xed62a
movl $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x1b0(%rcx), %eax
jge 0xed5ce
movq 0x58(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq 0x1b8(%rax,%rcx,8), %rax
movq %rax, (%rsp)
movl 0x4c(%rsp), %eax
movq (%rsp), %rcx
imull 0x34(%rcx), %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq (%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xed5bc
movslq 0x44(%rsp), %rax
movq 0x10(%rsp,%rax,8), %rax
movl 0x3c(%rsp), %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl 0x34(%rsp), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
movq (%rsp), %rcx
cmpl 0x34(%rcx), %eax
jge 0xed5aa
movq 0x8(%rsp), %rdx
movq %rdx, %rax
addq $0x80, %rax
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %rax
movl 0x48(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x48(%rsp)
movslq %ecx, %rcx
movq %rdx, 0x38(%rax,%rcx,8)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xed563
jmp 0xed5ac
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0xed521
jmp 0xed5be
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xed4de
movq 0x58(%rsp), %rax
movq 0x250(%rax), %rax
movq 0x8(%rax), %rax
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
addq $0x38, %rsi
callq *%rax
cmpl $0x0, %eax
jne 0xed618
movl 0x38(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x2c(%rax)
movl 0x4c(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x28(%rax)
movl $0x0, 0x64(%rsp)
jmp 0xed69a
jmp 0xed61a
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xed4b9
movq 0x50(%rsp), %rax
movl $0x0, 0x28(%rax)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0xed49b
movq 0x58(%rsp), %rcx
movl 0xb0(%rcx), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rcx)
movq 0x58(%rsp), %rcx
cmpl 0x1a4(%rcx), %eax
jae 0xed67b
movq 0x58(%rsp), %rdi
callq 0xedd10
movl $0x3, 0x64(%rsp)
jmp 0xed69a
movq 0x58(%rsp), %rax
movq 0x240(%rax), %rax
movq 0x18(%rax), %rax
movq 0x58(%rsp), %rdi
callq *%rax
movl $0x4, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)