// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmainct.c
// Function: jinit_d_main_controller
GLOBAL(void)
jinit_d_main_controller (j_decompress_ptr cinfo, jboolean need_full_buffer)
{
  my_main_ptr mainp;
  int ci, rgroup, ngroups;
  jpeg_component_info *compptr;

  mainp = (my_main_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_main_controller));
  cinfo->main = (struct jpeg_d_main_controller *) mainp;
  mainp->pub.start_pass = start_pass_main;

  if (need_full_buffer)		/* shouldn't happen */
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);

  /* Allocate the workspace.
   * ngroups is the number of row groups we need.
   */
  if (cinfo->upsample->need_context_rows) {
    if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
      ERREXIT(cinfo, JERR_NOTIMPL);
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
    ngroups = cinfo->min_DCT_scaled_size + 2;
  } else {
    ngroups = cinfo->min_DCT_scaled_size;
  }

  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
    mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
			((j_common_ptr) cinfo, JPOOL_IMAGE,
			 compptr->width_in_blocks * compptr->DCT_scaled_size,
			 (JDIMENSION) (rgroup * ngroups));
  }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
movl $0x88, %edx
callq *%rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x228(%rax)
movq 0x20(%rsp), %rax
leaq 0x154(%rip), %rcx       # 0xec5c0
movq %rcx, (%rax)
cmpl $0x0, 0x2c(%rsp)
je 0xec497
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x4, 0x28(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdi
callq *%rax
movq 0x30(%rsp), %rax
movq 0x260(%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0xec4f6
movq 0x30(%rsp), %rax
cmpl $0x2, 0x1a0(%rax)
jge 0xec4d8
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x2f, 0x28(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdi
callq *%rax
movq 0x30(%rsp), %rdi
callq 0xec6c0
movq 0x30(%rsp), %rax
movl 0x1a0(%rax), %eax
addl $0x2, %eax
movl %eax, 0x14(%rsp)
jmp 0xec505
movq 0x30(%rsp), %rax
movl 0x1a0(%rax), %eax
movl %eax, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x1c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xec5b4
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x8(%rsp), %rcx
imull 0x24(%rcx), %eax
movq 0x30(%rsp), %rcx
cltd
idivl 0x1a0(%rcx)
movl %eax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rcx
movl 0x1c(%rcx), %edx
movq 0x8(%rsp), %rcx
imull 0x24(%rcx), %edx
movl 0x18(%rsp), %ecx
imull 0x14(%rsp), %ecx
movl $0x1, %esi
callq *%rax
movq %rax, %rdx
movq 0x20(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq %rdx, 0x10(%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xec51e
addq $0x38, %rsp
retq
nopl (%rax)