// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jdsample.c
// Function: jinit_upsampler
GLOBAL(void)
jinit_upsampler (j_decompress_ptr cinfo)
{
  my_upsample_ptr upsample;
  int ci;
  jpeg_component_info * compptr;
  jboolean need_buffer, do_fancy;
  int h_in_group, v_in_group, h_out_group, v_out_group;

  upsample = (my_upsample_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_upsampler));
  cinfo->upsample = (struct jpeg_upsampler *) upsample;
  upsample->pub.start_pass = start_pass_upsample;
  upsample->pub.upsample = sep_upsample;
  upsample->pub.need_context_rows = FALSE; /* until we find out differently */

  if (cinfo->CCIR601_sampling)	/* this isn't supported */
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);

  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
   * so don't ask for it.
   */
  do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;

  /* Verify we can handle the sampling factors, select per-component methods,
   * and create storage as needed.
   */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    /* Compute size of an "input group" after IDCT scaling.  This many samples
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
     */
    h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
		 cinfo->min_DCT_scaled_size;
    v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
		 cinfo->min_DCT_scaled_size;
    h_out_group = cinfo->max_h_samp_factor;
    v_out_group = cinfo->max_v_samp_factor;
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
    need_buffer = TRUE;
    if (! compptr->component_needed) {
      /* Don't bother to upsample an uninteresting component. */
      upsample->methods[ci] = noop_upsample;
      need_buffer = FALSE;
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
      /* Fullsize components can be processed without any work. */
      upsample->methods[ci] = fullsize_upsample;
      need_buffer = FALSE;
    } else if (h_in_group * 2 == h_out_group &&
	       v_in_group == v_out_group) {
      /* Special cases for 2h1v upsampling */
      if (do_fancy && compptr->downsampled_width > 2)
	upsample->methods[ci] = h2v1_fancy_upsample;
      else
	upsample->methods[ci] = h2v1_upsample;
    } else if (h_in_group * 2 == h_out_group &&
	       v_in_group * 2 == v_out_group) {
      /* Special cases for 2h2v upsampling */
      if (do_fancy && compptr->downsampled_width > 2) {
	upsample->methods[ci] = h2v2_fancy_upsample;
	upsample->pub.need_context_rows = TRUE;
      } else
	upsample->methods[ci] = h2v2_upsample;
    } else if ((h_out_group % h_in_group) == 0 &&
	       (v_out_group % v_in_group) == 0) {
      /* Generic integral-factors upsampling method */
      upsample->methods[ci] = int_upsample;
      upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
      upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
    } else
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
    if (need_buffer) {
      upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
	((j_common_ptr) cinfo, JPOOL_IMAGE,
	 (JDIMENSION) jround_up((long) cinfo->output_width,
				(long) cinfo->max_h_samp_factor),
	 (JDIMENSION) cinfo->max_v_samp_factor);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movl $0x100, %edx            # imm = 0x100
movl $0x1, %esi
callq *(%rax)
movq %rax, %r14
movq %rax, 0x260(%rbx)
leaq 0x1e2(%rip), %rax       # 0x837b8
movq %rax, (%r14)
leaq 0x1f8(%rip), %rax       # 0x837d8
movq %rax, 0x8(%r14)
movl $0x0, 0x10(%r14)
cmpl $0x0, 0x188(%rbx)
je 0x83604
movq (%rbx), %rax
movl $0x19, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
cmpl $0x0, 0x64(%rbx)
je 0x8361a
cmpl $0x2, 0x1a0(%rbx)
setge %al
movl %eax, 0xc(%rsp)
jmp 0x83622
movl $0x0, 0xc(%rsp)
cmpl $0x0, 0x38(%rbx)
jle 0x837a9
movq 0x130(%rbx), %r15
leaq 0x18(%r14), %rax
movq %rax, 0x10(%rsp)
movq %r14, %r13
addq $0x68, %r13
addq $0x30, %r15
xorl %ebp, %ebp
leaq 0x2b6(%rip), %r9        # 0x83906
movl -0xc(%r15), %ecx
movl -0x28(%r15), %eax
imull %ecx, %eax
movl 0x1a0(%rbx), %edi
cltd
idivl %edi
movl %eax, %esi
imull -0x24(%r15), %ecx
movl %ecx, %eax
cltd
idivl %edi
movl %eax, %ecx
movl 0x198(%rbx), %eax
movl 0x19c(%rbx), %edi
movl %ecx, 0xc0(%r14,%rbp,4)
cmpl $0x0, (%r15)
movq %r13, %r8
movq %r9, %rdx
je 0x83771
cmpl %eax, %esi
jne 0x836ac
movq %r13, %r8
leaq 0x26a(%rip), %rdx       # 0x8390e
cmpl %edi, %ecx
je 0x83771
leal (%rsi,%rsi), %edx
cmpl %eax, %edx
jne 0x836ce
cmpl %edi, %ecx
jne 0x836ce
cmpb $0x0, 0xc(%rsp)
je 0x836fd
cmpl $0x3, -0x8(%r15)
jb 0x836fd
leaq 0x246(%rip), %rax       # 0x83912
jmp 0x83730
cmpl %eax, %edx
jne 0x83706
leal (%rcx,%rcx), %edx
cmpl %edi, %edx
jne 0x83706
cmpb $0x0, 0xc(%rsp)
je 0x83729
cmpl $0x3, -0x8(%r15)
jb 0x83729
leaq 0x334(%rip), %rax       # 0x83a22
movq %rax, 0x68(%r14,%rbp,8)
movl $0x1, 0x10(%r14)
jmp 0x83735
leaq 0x2c9(%rip), %rax       # 0x839cd
jmp 0x83730
cltd
idivl %esi
testl %edx, %edx
jne 0x83718
movl %eax, %esi
movl %edi, %eax
cltd
idivl %ecx
testl %edx, %edx
je 0x8378b
movq (%rbx), %rax
movl $0x26, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
jmp 0x83735
leaq 0x430(%rip), %rax       # 0x83b60
movq %rax, 0x68(%r14,%rbp,8)
movq 0x8(%rbx), %rax
movq 0x10(%rax), %r12
movl 0x88(%rbx), %edi
movslq 0x198(%rbx), %rsi
callq 0x86aa9
movl 0x19c(%rbx), %ecx
movq %rbx, %rdi
movl $0x1, %esi
movl %eax, %edx
callq *%r12
movq %rax, %rdx
movq 0x10(%rsp), %r8
leaq 0x195(%rip), %r9        # 0x83906
movq %rdx, (%r8,%rbp,8)
incq %rbp
movslq 0x38(%rbx), %rax
addq $0x60, %r15
cmpq %rax, %rbp
jl 0x83650
jmp 0x837a9
leaq 0x463(%rip), %rcx       # 0x83bf5
movq %rcx, 0x68(%r14,%rbp,8)
movb %sil, 0xe8(%r14,%rbp)
movb %al, 0xf2(%r14,%rbp)
jmp 0x83735
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq