// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jdmaster.c
// Function: jpeg_calc_output_dimensions
GLOBAL(void)
jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
/* Do computations that are needed before master selection phase */
{
#ifdef IDCT_SCALING_SUPPORTED
  int ci;
  jpeg_component_info *compptr;
#endif

  /* Prevent application from calling me at wrong times */
  if (cinfo->global_state != DSTATE_READY)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

#ifdef IDCT_SCALING_SUPPORTED

  /* Compute actual output image dimensions and DCT scaling choices. */
  if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
    /* Provide 1/8 scaling */
    cinfo->output_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width, 8L);
    cinfo->output_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height, 8L);
    cinfo->min_DCT_scaled_size = 1;
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
    /* Provide 1/4 scaling */
    cinfo->output_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width, 4L);
    cinfo->output_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height, 4L);
    cinfo->min_DCT_scaled_size = 2;
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
    /* Provide 1/2 scaling */
    cinfo->output_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width, 2L);
    cinfo->output_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height, 2L);
    cinfo->min_DCT_scaled_size = 4;
  } else {
    /* Provide 1/1 scaling */
    cinfo->output_width = cinfo->image_width;
    cinfo->output_height = cinfo->image_height;
    cinfo->min_DCT_scaled_size = DCTSIZE;
  }
  /* In selecting the actual DCT scaling for each component, we try to
   * scale up the chroma components via IDCT scaling rather than upsampling.
   * This saves time if the upsampler gets to use 1:1 scaling.
   * Note this code assumes that the supported DCT scalings are powers of 2.
   */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    int ssize = cinfo->min_DCT_scaled_size;
    while (ssize < DCTSIZE &&
	   (compptr->h_samp_factor * ssize * 2 <=
	    cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
	   (compptr->v_samp_factor * ssize * 2 <=
	    cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
      ssize = ssize * 2;
    }
    compptr->DCT_scaled_size = ssize;
  }

  /* Recompute downsampled dimensions of components;
   * application needs to know these if using raw downsampled data.
   */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    /* Size in samples, after IDCT scaling */
    compptr->downsampled_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width *
		    (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
    compptr->downsampled_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height *
		    (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
  }

#else /* !IDCT_SCALING_SUPPORTED */

  /* Hardwire it to "no scaling" */
  cinfo->output_width = cinfo->image_width;
  cinfo->output_height = cinfo->image_height;
  /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
   * and has computed unscaled downsampled_width and downsampled_height.
   */

#endif /* IDCT_SCALING_SUPPORTED */

  /* Report number of components in selected colorspace. */
  /* Probably this should be in the color conversion module... */
  switch (cinfo->out_color_space) {
  case JCS_GRAYSCALE:
    cinfo->out_color_components = 1;
    break;
  case JCS_RGB:
#if RGB_PIXELSIZE != 3
    cinfo->out_color_components = RGB_PIXELSIZE;
    break;
#endif /* else share code with YCbCr */
  case JCS_YCbCr:
    cinfo->out_color_components = 3;
    break;
  case JCS_CMYK:
  case JCS_YCCK:
    cinfo->out_color_components = 4;
    break;
  default:			/* else must be same colorspace as in file */
    cinfo->out_color_components = cinfo->num_components;
    break;
  }
  cinfo->output_components = (cinfo->quantize_colors ? 1 :
			      cinfo->out_color_components);

  /* See if upsampler will want to emit more than one row at a time */
  if (use_merged_upsample(cinfo))
    cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  else
    cinfo->rec_outbuf_height = 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x24(%rdi), %eax
cmpl $0xca, %eax
je 0x7b3ad
movq (%rbx), %rcx
movl $0x14, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl 0x44(%rbx), %eax
movl 0x48(%rbx), %ecx
leal (,%rax,8), %edx
cmpl %ecx, %edx
jbe 0x7b3e4
leal (,%rax,4), %edx
cmpl %ecx, %edx
jbe 0x7b40d
addl %eax, %eax
movl 0x30(%rbx), %edi
cmpl %ecx, %eax
jbe 0x7b436
movl %edi, 0x88(%rbx)
movl 0x34(%rbx), %eax
movl $0x8, %edx
xorl %ecx, %ecx
jmp 0x7b45a
movl 0x30(%rbx), %edi
movl $0x8, %esi
callq 0x85c94
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movl $0x8, %esi
callq 0x85c94
movb $0x1, %cl
movl $0x1, %edx
jmp 0x7b45a
movl 0x30(%rbx), %edi
movl $0x4, %esi
callq 0x85c94
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movl $0x4, %esi
callq 0x85c94
movb $0x1, %cl
movl $0x2, %edx
jmp 0x7b45a
movl $0x2, %esi
callq 0x85c94
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movl $0x2, %esi
callq 0x85c94
movb $0x1, %cl
movl $0x4, %edx
movl %eax, 0x8c(%rbx)
movl %edx, 0x1a0(%rbx)
movl 0x38(%rbx), %eax
testl %eax, %eax
jle 0x7b540
movq 0x130(%rbx), %r14
xorl %esi, %esi
movq %r14, %rdi
movl %edx, %r11d
testb %cl, %cl
je 0x7b4ce
movl 0x8(%rdi), %r8d
addl %r8d, %r8d
movl 0x198(%rbx), %r9d
imull %edx, %r9d
movl %edx, %r10d
movl %r10d, %r11d
imull %r8d, %r11d
cmpl %r9d, %r11d
jg 0x7b4cb
leal (%r10,%r10), %r11d
movl 0xc(%rdi), %ebp
imull %r11d, %ebp
movl 0x19c(%rbx), %r15d
imull %edx, %r15d
cmpl %r15d, %ebp
jg 0x7b4cb
cmpl $0x4, %r10d
movl %r11d, %r10d
jl 0x7b499
jmp 0x7b4ce
movl %r10d, %r11d
movl %r11d, 0x24(%rdi)
incl %esi
addq $0x60, %rdi
cmpl %eax, %esi
jne 0x7b47d
testl %eax, %eax
jle 0x7b540
addq $0x2c, %r14
xorl %ebp, %ebp
movl 0x30(%rbx), %eax
movslq -0x24(%r14), %rcx
movslq -0x8(%r14), %rdi
imulq %rcx, %rdi
imulq %rax, %rdi
movslq 0x198(%rbx), %rsi
shlq $0x3, %rsi
callq 0x85c94
movl %eax, -0x4(%r14)
movl 0x34(%rbx), %eax
movslq -0x20(%r14), %rcx
movslq -0x8(%r14), %rdi
imulq %rcx, %rdi
imulq %rax, %rdi
movslq 0x19c(%rbx), %rsi
shlq $0x3, %rsi
callq 0x85c94
movl %eax, (%r14)
incl %ebp
movl 0x38(%rbx), %eax
addq $0x60, %r14
cmpl %eax, %ebp
jl 0x7b4e6
movl 0x40(%rbx), %ecx
decl %ecx
cmpl $0x4, %ecx
ja 0x7b556
movl %ecx, %eax
leaq 0x2f2ed(%rip), %rcx     # 0xaa840
movl (%rcx,%rax,4), %eax
movl %eax, 0x90(%rbx)
cmpl $0x0, 0x6c(%rbx)
movl $0x1, %ebp
cmovnel %ebp, %eax
movl %eax, 0x94(%rbx)
movq %rbx, %rdi
callq 0x7b591
testl %eax, %eax
je 0x7b580
movl 0x19c(%rbx), %ebp
movl %ebp, 0x98(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq