// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdinput.c
// Function: per_scan_setup
LOCAL(void)
per_scan_setup (j_decompress_ptr cinfo)
/* Do computations that are needed before processing a JPEG scan */
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
{
  int ci, mcublks, tmp;
  jpeg_component_info *compptr;
  
  if (cinfo->comps_in_scan == 1) {
    
    /* Noninterleaved (single-component) scan */
    compptr = cinfo->cur_comp_info[0];
    
    /* Overall image size in MCUs */
    cinfo->MCUs_per_row = compptr->width_in_blocks;
    cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
    
    /* For noninterleaved scan, always one block per MCU */
    compptr->MCU_width = 1;
    compptr->MCU_height = 1;
    compptr->MCU_blocks = 1;
    compptr->MCU_sample_width = compptr->DCT_scaled_size;
    compptr->last_col_width = 1;
    /* For noninterleaved scans, it is convenient to define last_row_height
     * as the number of block rows present in the last iMCU row.
     */
    tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
    if (tmp == 0) tmp = compptr->v_samp_factor;
    compptr->last_row_height = tmp;
    
    /* Prepare array describing MCU composition */
    cinfo->blocks_in_MCU = 1;
    cinfo->MCU_membership[0] = 0;
    
  } else {
    
    /* Interleaved (multi-component) scan */
    if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
	       MAX_COMPS_IN_SCAN);
    
    /* Overall image size in MCUs */
    cinfo->MCUs_per_row = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width,
		    (long) (cinfo->max_h_samp_factor*DCTSIZE));
    cinfo->MCU_rows_in_scan = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height,
		    (long) (cinfo->max_v_samp_factor*DCTSIZE));
    
    cinfo->blocks_in_MCU = 0;
    
    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
      compptr = cinfo->cur_comp_info[ci];
      /* Sampling factors give # of blocks of component in each MCU */
      compptr->MCU_width = compptr->h_samp_factor;
      compptr->MCU_height = compptr->v_samp_factor;
      compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
      compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
      /* Figure number of non-dummy blocks in last MCU column & row */
      tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
      if (tmp == 0) tmp = compptr->MCU_width;
      compptr->last_col_width = tmp;
      tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
      if (tmp == 0) tmp = compptr->MCU_height;
      compptr->last_row_height = tmp;
      /* Prepare array describing MCU composition */
      mcublks = compptr->MCU_blocks;
      if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
	ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
      while (mcublks-- > 0) {
	cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
      }
    }
    
  }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpl $0x1, 0x1b0(%rax)
jne 0xe4f9a
movq 0x20(%rsp), %rax
movq 0x1b8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movl 0x1c(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x1d8(%rax)
movq 0x8(%rsp), %rax
movl 0x20(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x1dc(%rax)
movq 0x8(%rsp), %rax
movl $0x1, 0x34(%rax)
movq 0x8(%rsp), %rax
movl $0x1, 0x38(%rax)
movq 0x8(%rsp), %rax
movl $0x1, 0x3c(%rax)
movq 0x8(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x40(%rax)
movq 0x8(%rsp), %rax
movl $0x1, 0x44(%rax)
movq 0x8(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
divl 0xc(%rcx)
movl %edx, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0xe4f6b
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x48(%rax)
movq 0x20(%rsp), %rax
movl $0x1, 0x1e0(%rax)
movq 0x20(%rsp), %rax
movl $0x0, 0x1e4(%rax)
jmp 0xe51e9
movq 0x20(%rsp), %rax
cmpl $0x0, 0x1b0(%rax)
jle 0xe4fb6
movq 0x20(%rsp), %rax
cmpl $0x4, 0x1b0(%rax)
jle 0xe4ffc
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1a, 0x28(%rax)
movq 0x20(%rsp), %rax
movl 0x1b0(%rax), %ecx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x4, 0x30(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
movl 0x30(%rax), %eax
movl %eax, %edi
movq 0x20(%rsp), %rax
movl 0x198(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x1d8(%rax)
movq 0x20(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, %edi
movq 0x20(%rsp), %rax
movl 0x19c(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0xf9310
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x1dc(%rax)
movq 0x20(%rsp), %rax
movl $0x0, 0x1e0(%rax)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x1b0(%rcx), %eax
jge 0xe51e7
movq 0x20(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq 0x1b8(%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x34(%rax)
movq 0x8(%rsp), %rax
movl 0xc(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0x8(%rsp), %rax
movl 0x34(%rax), %ecx
movq 0x8(%rsp), %rax
imull 0x38(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x3c(%rax)
movq 0x8(%rsp), %rax
movl 0x34(%rax), %ecx
movq 0x8(%rsp), %rax
imull 0x24(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x40(%rax)
movq 0x8(%rsp), %rax
movl 0x1c(%rax), %eax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
divl 0x34(%rcx)
movl %edx, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0xe5114
movq 0x8(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x44(%rax)
movq 0x8(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
divl 0x38(%rcx)
movl %edx, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0xe5149
movq 0x8(%rsp), %rax
movl 0x38(%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x48(%rax)
movq 0x8(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movl 0x1e0(%rax), %eax
addl 0x18(%rsp), %eax
cmpl $0xa, %eax
jle 0xe5196
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xd, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xe5198
movl 0x18(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rsp)
cmpl $0x0, %eax
jle 0xe51d5
movl 0x1c(%rsp), %edx
movq 0x20(%rsp), %rax
movq 0x20(%rsp), %rsi
movl 0x1e0(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x1e0(%rsi)
movslq %ecx, %rcx
movl %edx, 0x1e4(%rax,%rcx,4)
jmp 0xe5198
jmp 0xe51d7
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xe506d
jmp 0xe51e9
addq $0x28, %rsp
retq
nop