// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcparam.c
// Function: jpeg_set_defaults
GLOBAL(void)
jpeg_set_defaults (j_compress_ptr cinfo)
{
  int i;

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* Allocate comp_info array large enough for maximum component count.
   * Array is made permanent in case application wants to compress
   * multiple images at same param settings.
   */
  if (cinfo->comp_info == NULL)
    cinfo->comp_info = (jpeg_component_info *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
				  MAX_COMPONENTS * SIZEOF(jpeg_component_info));

  /* Initialize everything not dependent on the color space */

  cinfo->data_precision = BITS_IN_JSAMPLE;
  /* Set up two quantization tables using default quality of 75 */
  jpeg_set_quality(cinfo, 75, TRUE);
  /* Set up two Huffman tables */
  std_huff_tables(cinfo);

  /* Initialize default arithmetic coding conditioning */
  for (i = 0; i < NUM_ARITH_TBLS; i++) {
    cinfo->arith_dc_L[i] = 0;
    cinfo->arith_dc_U[i] = 1;
    cinfo->arith_ac_K[i] = 5;
  }

  /* Default is no multiple-scan output */
  cinfo->scan_info = NULL;
  cinfo->num_scans = 0;

  /* Expect normal source image, not raw downsampled data */
  cinfo->raw_data_in = FALSE;

  /* Use Huffman coding, not arithmetic coding, by default */
  cinfo->arith_code = FALSE;

  /* By default, don't do extra passes to optimize entropy coding */
  cinfo->optimize_coding = FALSE;
  /* The standard Huffman tables are only valid for 8-bit data precision.
   * If the precision is higher, force optimization on so that usable
   * tables will be computed.  This test can be removed if default tables
   * are supplied that are valid for the desired precision.
   */
  if (cinfo->data_precision > 8)
    cinfo->optimize_coding = TRUE;

  /* By default, use the simpler non-cosited sampling alignment */
  cinfo->CCIR601_sampling = FALSE;

  /* No input smoothing */
  cinfo->smoothing_factor = 0;

  /* DCT algorithm preference */
  cinfo->dct_method = JDCT_DEFAULT;

  /* No restart markers */
  cinfo->restart_interval = 0;
  cinfo->restart_in_rows = 0;

  /* Fill in default JFIF marker parameters.  Note that whether the marker
   * will actually be written is determined by jpeg_set_colorspace.
   *
   * By default, the library emits JFIF version code 1.01.
   * An application that wants to emit JFIF 1.02 extension markers should set
   * JFIF_minor_version to 2.  We could probably get away with just defaulting
   * to 1.02, but there may still be some decoders in use that will complain
   * about that; saying 1.01 should minimize compatibility problems.
   */
  cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  cinfo->JFIF_minor_version = 1;
  cinfo->density_unit = 0;	/* Pixel size is unknown by default */
  cinfo->X_density = 1;		/* Pixel aspect ratio is square by default */
  cinfo->Y_density = 1;

  /* Choose JPEG colorspace based on input space, set defaults accordingly */

  jpeg_default_colorspace(cinfo);
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x64, 0x24(%rax)
je 0xd5f08
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl $0x14, 0x28(%rax)
movq 0x10(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
movq 0x10(%rsp), %rax
cmpq $0x0, 0x58(%rax)
jne 0xd5f3a
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x3c0, %edx            # imm = 0x3C0
callq *%rax
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x58(%rax)
movq 0x10(%rsp), %rax
movl $0x8, 0x48(%rax)
movq 0x10(%rsp), %rdi
movl $0x4b, %esi
movl $0x1, %edx
callq 0xd5e80
movq 0x10(%rsp), %rdi
callq 0xd60c0
movl $0x0, 0xc(%rsp)
cmpl $0x10, 0xc(%rsp)
jge 0xd5fb6
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x0, 0xc0(%rax,%rcx)
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x1, 0xd0(%rax,%rcx)
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x5, 0xe0(%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xd5f6c
movq 0x10(%rsp), %rax
movq $0x0, 0xf8(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0xf0(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x100(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x104(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x108(%rax)
movq 0x10(%rsp), %rax
cmpl $0x8, 0x48(%rax)
jle 0xd601c
movq 0x10(%rsp), %rax
movl $0x1, 0x108(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x10c(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x110(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x114(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x118(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x11c(%rax)
movq 0x10(%rsp), %rax
movb $0x1, 0x124(%rax)
movq 0x10(%rsp), %rax
movb $0x1, 0x125(%rax)
movq 0x10(%rsp), %rax
movb $0x0, 0x126(%rax)
movq 0x10(%rsp), %rax
movw $0x1, 0x128(%rax)
movq 0x10(%rsp), %rax
movw $0x1, 0x12a(%rax)
movq 0x10(%rsp), %rdi
callq 0xd6160
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)