// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdcoefct.c
// Function: jinit_d_coef_controller
GLOBAL(void)
jinit_d_coef_controller (j_decompress_ptr cinfo, jboolean need_full_buffer)
{
  my_coef_ptr coef;

  coef = (my_coef_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_coef_controller));
  cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  coef->pub.start_input_pass = start_input_pass;
  coef->pub.start_output_pass = start_output_pass;
#ifdef BLOCK_SMOOTHING_SUPPORTED
  coef->coef_bits_latch = NULL;
#endif

  /* Create the coefficient buffer. */
  if (need_full_buffer) {
#ifdef D_MULTISCAN_FILES_SUPPORTED
    /* Allocate a full-image virtual array for each component, */
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
    /* Note we ask for a pre-zeroed array. */
    int ci, access_rows;
    jpeg_component_info *compptr;

    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
	 ci++, compptr++) {
      access_rows = compptr->v_samp_factor;
#ifdef BLOCK_SMOOTHING_SUPPORTED
      /* If block smoothing could be used, need a bigger window */
      if (cinfo->progressive_mode)
	access_rows *= 3;
#endif
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
	((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
	 (JDIMENSION) jround_up((long) compptr->width_in_blocks,
				(long) compptr->h_samp_factor),
	 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
				(long) compptr->v_samp_factor),
	 (JDIMENSION) access_rows);
    }
    coef->pub.consume_data = consume_data;
    coef->pub.decompress_data = decompress_data;
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
#else
    ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
  } else {
    /* We only need a single-MCU buffer. */
    JBLOCKROW buffer;
    int i;

    buffer = (JBLOCKROW)
      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				  D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
      coef->MCU_buffer[i] = buffer + i;
    }
    coef->pub.consume_data = dummy_consume_data;
    coef->pub.decompress_data = decompress_onepass;
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x50(%rsp), %rdi
movl $0x1, %esi
movl $0xe0, %edx
callq *%rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x230(%rax)
movq 0x40(%rsp), %rax
leaq 0x1f4(%rip), %rcx       # 0xed340
movq %rcx, (%rax)
movq 0x40(%rsp), %rax
leaq 0x205(%rip), %rcx       # 0xed360
movq %rcx, 0x10(%rax)
movq 0x40(%rsp), %rax
movq $0x0, 0xd8(%rax)
cmpl $0x0, 0x4c(%rsp)
je 0xed2a7
movl $0x0, 0x3c(%rsp)
movq 0x50(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, 0x30(%rsp)
movl 0x3c(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xed26d
movq 0x30(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x38(%rsp)
movq 0x50(%rsp), %rax
cmpl $0x0, 0x138(%rax)
je 0xed1c8
imull $0x3, 0x38(%rsp), %eax
movl %eax, 0x38(%rsp)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rax
movl 0x1c(%rax), %eax
movl %eax, %edi
movq 0x30(%rsp), %rax
movslq 0x8(%rax), %rsi
callq 0xf9330
movl %eax, 0x14(%rsp)
movq 0x30(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, %edi
movq 0x30(%rsp), %rax
movslq 0xc(%rax), %rsi
callq 0xf9330
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %ecx
movq %rax, %rdx
movq 0x18(%rsp), %rax
movl %edx, %r8d
movl 0x38(%rsp), %r9d
movl $0x1, %edx
movl %edx, %esi
callq *%rax
movq %rax, %rdx
movq 0x40(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movq %rdx, 0x88(%rax,%rcx,8)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
movq 0x30(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x30(%rsp)
jmp 0xed193
movq 0x40(%rsp), %rax
leaq 0x167(%rip), %rcx       # 0xed3e0
movq %rcx, 0x8(%rax)
movq 0x40(%rsp), %rax
leaq 0x427(%rip), %rcx       # 0xed6b0
movq %rcx, 0x18(%rax)
movq 0x40(%rsp), %rcx
addq $0x88, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x20(%rax)
jmp 0xed333
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x50(%rsp), %rdi
movl $0x1, %esi
movl $0x500, %edx            # imm = 0x500
callq *%rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
cmpl $0xa, 0x24(%rsp)
jge 0xed306
movq 0x28(%rsp), %rdx
movslq 0x24(%rsp), %rax
shlq $0x7, %rax
addq %rax, %rdx
movq 0x40(%rsp), %rax
movslq 0x24(%rsp), %rcx
movq %rdx, 0x38(%rax,%rcx,8)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xed2d2
movq 0x40(%rsp), %rax
leaq 0x68e(%rip), %rcx       # 0xed9a0
movq %rcx, 0x8(%rax)
movq 0x40(%rsp), %rax
leaq 0x68e(%rip), %rcx       # 0xed9b0
movq %rcx, 0x18(%rax)
movq 0x40(%rsp), %rax
movq $0x0, 0x20(%rax)
addq $0x58, %rsp
retq
nopl (%rax,%rax)