// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcparam.c
// Function: jpeg_add_quant_table
GLOBAL(void)
jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
		      const unsigned int *basic_table,
		      int scale_factor, jboolean force_baseline)
/* Define a quantization table equal to the basic_table times
 * a scale factor (given as a percentage).
 * If force_baseline is TRUE, the computed quantization table entries
 * are limited to 1..255 for JPEG baseline compatibility.
 */
{
  JQUANT_TBL ** qtblptr;
  int i;
  long temp;

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

  if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
    ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);

  qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];

  if (*qtblptr == NULL)
    *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);

  for (i = 0; i < DCTSIZE2; i++) {
    temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
    /* limit the values to the valid range */
    if (temp <= 0L) temp = 1L;
    if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
    if (force_baseline && temp > 255L)
      temp = 255L;		/* limit to baseline range if requested */
    (*qtblptr)->quantval[i] = (UINT16) temp;
  }

  /* Initialize sent_table FALSE so table will be written to JPEG file. */
  (*qtblptr)->sent_table = FALSE;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movq %rdx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpl $0x64, 0x24(%rax)
je 0xd5c9a
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x14, 0x28(%rax)
movq 0x30(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdi
callq *%rax
cmpl $0x0, 0x2c(%rsp)
jl 0xd5ca8
cmpl $0x4, 0x2c(%rsp)
jl 0xd5cd8
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x1f, 0x28(%rax)
movl 0x2c(%rsp), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdi
callq *%rax
movq 0x30(%rsp), %rax
addq $0x60, %rax
movslq 0x2c(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
jne 0xd5d12
movq 0x30(%rsp), %rdi
callq 0xf9270
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movl $0x0, 0xc(%rsp)
cmpl $0x40, 0xc(%rsp)
jge 0xd5daf
movq 0x20(%rsp), %rax
movslq 0xc(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movslq 0x1c(%rsp), %rcx
imulq %rcx, %rax
addq $0x32, %rax
movl $0x64, %ecx
cqto
idivq %rcx
movq %rax, (%rsp)
cmpq $0x0, (%rsp)
jg 0xd5d5c
movq $0x1, (%rsp)
cmpq $0x7fff, (%rsp)         # imm = 0x7FFF
jle 0xd5d6e
movq $0x7fff, (%rsp)         # imm = 0x7FFF
cmpl $0x0, 0x18(%rsp)
je 0xd5d87
cmpq $0xff, (%rsp)
jle 0xd5d87
movq $0xff, (%rsp)
movq (%rsp), %rax
movw %ax, %dx
movq 0x10(%rsp), %rax
movq (%rax), %rax
movslq 0xc(%rsp), %rcx
movw %dx, (%rax,%rcx,2)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xd5d1a
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl $0x0, 0x80(%rax)
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)