// File: /workspace/github_cpp_makefile_star2_O3/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, 0xc(%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 0x781b2
cmpl $0x0, 0x70(%rbx)
jne 0x781b2
movl 0x74(%rbx), %esi
movq %rbx, %rdi
callq 0x78d3a
cmpl $0x0, 0x170(%r14)
jle 0x78310
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rax
movswl (%rax), %eax
movl 0xc(%rsp), %ecx
sarl %cl, %eax
movslq 0x174(%r14,%r13,4), %rcx
movl 0x48(%rbx,%rcx,4), %esi
movl %eax, %edx
subl %esi, %edx
movq 0x148(%r14,%rcx,8), %rbp
movl %eax, 0x48(%rbx,%rcx,4)
subl %esi, %eax
jne 0x78207
movl 0x14(%rbp), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x78dd3
jmp 0x782fd
sarl $0x1f, %edx
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %edx, %eax
movl %eax, 0x8(%rsp)
movl $0x9, %edx
xorl %r12d, %r12d
movl %ecx, %eax
movl %edx, %r15d
shrl %eax
incq %r12
leal 0x1(%r15), %edx
cmpl $0x1, %ecx
movl %eax, %ecx
ja 0x78221
leal -0x1(%r12), %eax
cmpl $0xb, %eax
jb 0x7824d
movq (%r14), %rax
movl $0x6, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x14(%rbp), %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x78dd3
cmpl $0x0, 0x18(%rbx)
jne 0x782fd
movq $-0x1, %rbp
movl %r12d, %ecx
shlq %cl, %rbp
movl 0x38(%rbx), %edx
notl %ebp
andl 0x8(%rsp), %ebp
movq %rdx, %rax
addq %r12, %rax
addl %edx, %r12d
movb $0x18, %cl
subb %r12b, %cl
shlq %cl, %rbp
orq 0x30(%rbx), %rbp
cmpl $0x7, %eax
jle 0x782f6
addl %edx, %r15d
movl %ebp, %eax
shrl $0x10, %eax
movq 0x20(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rbx)
movb %al, (%rcx)
decq 0x28(%rbx)
jne 0x782b9
movq %rbx, %rdi
callq 0x7907c
movl %ebp, %eax
notl %eax
testl $0xff0000, %eax         # imm = 0xFF0000
jne 0x782e1
movq 0x20(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movb $0x0, (%rax)
decq 0x28(%rbx)
jne 0x782e1
movq %rbx, %rdi
callq 0x7907c
shlq $0x8, %rbp
addl $-0x8, %r15d
cmpl $0xf, %r15d
jg 0x78298
addl $-0x8, %r15d
movl %r15d, %eax
movq %rbp, 0x30(%rbx)
movl %eax, 0x38(%rbx)
incq %r13
movslq 0x170(%r14), %rax
cmpq %rax, %r13
jl 0x781c3
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 0x78347
movl 0x70(%rbx), %ecx
testl %ecx, %ecx
jne 0x78342
movl 0x74(%rbx), %ecx
incl %ecx
andl $0x7, %ecx
movl %ecx, 0x74(%rbx)
movl %eax, %ecx
decl %ecx
movl %ecx, 0x70(%rbx)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq