// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jcphuff.c
// Function: encode_mcu_DC_first
METHODDEF(jboolean)
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  register int temp, temp2;
  register int nbits;
  int blkn, ci;
  int Al = cinfo->Al;
  JBLOCKROW block;
  jpeg_component_info * compptr;
  ISHIFT_TEMPS

  entropy->next_output_byte = cinfo->dest->next_output_byte;
  entropy->free_in_buffer = cinfo->dest->free_in_buffer;

  /* Emit restart marker if needed */
  if (cinfo->restart_interval)
    if (entropy->restarts_to_go == 0)
      emit_restart(entropy, entropy->next_restart_num);

  /* Encode the MCU data blocks */
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
    block = MCU_data[blkn];
    ci = cinfo->MCU_membership[blkn];
    compptr = cinfo->cur_comp_info[ci];

    /* Compute the DC value after the required point transform by Al.
     * This is simply an arithmetic right shift.
     */
    temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);

    /* DC differences are figured on the point-transformed values. */
    temp = temp2 - entropy->last_dc_val[ci];
    entropy->last_dc_val[ci] = temp2;

    /* Encode the DC coefficient difference per section G.1.2.1 */
    temp2 = temp;
    if (temp < 0) {
      temp = -temp;		/* temp is abs value of input */
      /* For a negative input, want temp2 = bitwise complement of abs(input) */
      /* This code assumes we are on a two's complement machine */
      temp2--;
    }
    
    /* Find the number of bits needed for the magnitude of the coefficient */
    nbits = 0;
    while (temp) {
      nbits++;
      temp >>= 1;
    }
    /* Check for out-of-range coefficient values.
     * Since we're encoding a difference, the range limit is twice as much.
     */
    if (nbits > MAX_COEF_BITS+1)
      ERREXIT(cinfo, JERR_BAD_DCT_COEF);
    
    /* Count/emit the Huffman-coded symbol for the number of bits */
    emit_symbol(entropy, compptr->dc_tbl_no, nbits);
    
    /* Emit that number of bits of the value, if positive, */
    /* or the complement of its magnitude, if negative. */
    if (nbits)			/* emit_bits rejects calls with size 0 */
      emit_bits(entropy, (unsigned int) temp2, nbits);
  }

  cinfo->dest->next_output_byte = entropy->next_output_byte;
  cinfo->dest->free_in_buffer = entropy->free_in_buffer;

  /* Update restart-interval state too */
  if (cinfo->restart_interval) {
    if (entropy->restarts_to_go == 0) {
      entropy->restarts_to_go = cinfo->restart_interval;
      entropy->next_restart_num++;
      entropy->next_restart_num &= 7;
    }
    entropy->restarts_to_go--;
  }

  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0x1f0(%rdi), %rbx
movl 0x1a8(%rdi), %eax
movl %eax, 0x4(%rsp)
movq 0x28(%rdi), %rax
movq (%rax), %rcx
movq %rcx, 0x20(%rbx)
movq 0x8(%rax), %rax
movq %rax, 0x28(%rbx)
cmpl $0x0, 0x118(%rdi)
je 0x6d406
cmpl $0x0, 0x70(%rbx)
jne 0x6d406
movl 0x74(%rbx), %esi
movq %rbx, %rdi
callq 0x6dae4
xorl %r15d, %r15d
movq %rbx, 0x8(%rsp)
movslq 0x170(%r14), %rax
cmpq %rax, %r15
jge 0x6d4ba
movq 0x10(%rsp), %rax
movq (%rax,%r15,8), %rax
movslq 0x174(%r14,%r15,4), %rdx
movswl (%rax), %eax
movl 0x4(%rsp), %ecx
sarl %cl, %eax
movq 0x148(%r14,%rdx,8), %rsi
movl %eax, %r12d
subl 0x48(%rbx,%rdx,4), %r12d
movl %eax, 0x48(%rbx,%rdx,4)
movl %r12d, %ebp
sarl $0x1f, %ebp
movl %r12d, %eax
negl %eax
cmovsl %r12d, %eax
xorl %r13d, %r13d
testl %eax, %eax
je 0x6d469
incl %r13d
shrl %eax
jmp 0x6d45e
cmpl $0xc, %r13d
jb 0x6d48a
movq (%r14), %rax
movl $0x6, 0x28(%rax)
movq %r14, %rdi
movq %r14, %rbx
movq %rsi, %r14
callq *(%rax)
movq %r14, %rsi
movq %rbx, %r14
movl 0x14(%rsi), %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %r13d, %edx
callq 0x6db6e
testl %r13d, %r13d
je 0x6d4b2
addl %r12d, %ebp
movq %rbx, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x6db99
incq %r15
jmp 0x6d40e
movq 0x20(%rbx), %rax
movq 0x28(%r14), %rcx
movq %rax, (%rcx)
movq 0x28(%rbx), %rax
movq %rax, 0x8(%rcx)
movl 0x118(%r14), %eax
testl %eax, %eax
je 0x6d4f1
movl 0x70(%rbx), %ecx
testl %ecx, %ecx
jne 0x6d4ec
movl 0x74(%rbx), %ecx
incl %ecx
andl $0x7, %ecx
movl %ecx, 0x74(%rbx)
movl %eax, %ecx
decl %ecx
movl %ecx, 0x70(%rbx)
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq