// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jcmaster.c
// Function: per_scan_setup
LOCAL(void)
per_scan_setup (j_compress_ptr cinfo)
/* Do computations that are needed before processing a JPEG scan */
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
{
  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 = DCTSIZE;
    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 * DCTSIZE;
      /* 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 > C_MAX_BLOCKS_IN_MCU)
	ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
      while (mcublks-- > 0) {
	cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
      }
    }
    
  }

  /* Convert restart specified in rows to actual MCU count. */
  /* Note that count must fit in 16 bits, so we provide limiting. */
  if (cinfo->restart_in_rows > 0) {
    long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
    cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0x144(%rdi), %eax
cmpl $0x1, %eax
jne 0x748a2
movq 0x148(%rbx), %rcx
movl 0x1c(%rcx), %eax
movl %eax, 0x168(%rbx)
movl 0x20(%rcx), %eax
movl %eax, 0x16c(%rbx)
movaps 0x35c48(%rip), %xmm0    # 0xaa4c0
movups %xmm0, 0x34(%rcx)
movl $0x1, 0x44(%rcx)
movl 0xc(%rcx), %esi
xorl %edx, %edx
divl %esi
testl %edx, %edx
cmovel %esi, %edx
movl %edx, 0x48(%rcx)
movq $0x1, 0x170(%rbx)
jmp 0x749ad
leal -0x5(%rax), %ecx
cmpl $-0x5, %ecx
ja 0x748c9
movq (%rbx), %rcx
movl $0x1a, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%rbx), %rax
movl $0x4, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl 0x30(%rbx), %edi
movslq 0x138(%rbx), %rsi
shlq $0x3, %rsi
callq 0x86a9c
movl %eax, 0x168(%rbx)
movl 0x34(%rbx), %edi
movslq 0x13c(%rbx), %rsi
shlq $0x3, %rsi
callq 0x86a9c
movl %eax, 0x16c(%rbx)
movl $0x0, 0x170(%rbx)
cmpl $0x0, 0x144(%rbx)
jle 0x749ad
xorl %r14d, %r14d
movq 0x148(%rbx,%r14,8), %rcx
movl 0x8(%rcx), %esi
movl 0xc(%rcx), %edi
movl %esi, 0x34(%rcx)
movl %edi, 0x38(%rcx)
movl %edi, %ebp
imull %esi, %ebp
movl %ebp, 0x3c(%rcx)
leal (,%rsi,8), %eax
movl %eax, 0x40(%rcx)
movl 0x1c(%rcx), %eax
xorl %edx, %edx
divl %esi
testl %edx, %edx
cmovel %esi, %edx
movl %edx, 0x44(%rcx)
movl 0x20(%rcx), %eax
xorl %edx, %edx
divl %edi
testl %edx, %edx
cmovel %edi, %edx
movl %edx, 0x48(%rcx)
movl 0x170(%rbx), %eax
addl %ebp, %eax
cmpl $0xb, %eax
jl 0x74975
movq (%rbx), %rax
movl $0xd, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
testl %ebp, %ebp
jle 0x7499a
incl %ebp
movslq 0x170(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x170(%rbx)
movl %r14d, 0x174(%rbx,%rax,4)
decl %ebp
cmpl $0x1, %ebp
jg 0x7497b
incq %r14
movslq 0x144(%rbx), %rax
cmpq %rax, %r14
jl 0x74915
movslq 0x11c(%rbx), %rax
testq %rax, %rax
jle 0x749d5
movl 0x168(%rbx), %ecx
imulq %rax, %rcx
movl $0xffff, %eax           # imm = 0xFFFF
cmpq %rax, %rcx
cmovaeq %rax, %rcx
movl %ecx, 0x118(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop