// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
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 0x79091
cmpl $0x0, 0x70(%rbx)
jne 0x79091
movl 0x74(%rbx), %esi
movq %rbx, %rdi
callq 0x799ff
cmpl $0x0, 0x170(%r15)
jle 0x791e4
xorl %r13d, %r13d
movq %r15, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rax
movswl (%rax), %ebp
movl 0x4(%rsp), %ecx
sarl %cl, %ebp
movslq 0x174(%r15,%r13,4), %rax
movl 0x48(%rbx,%rax,4), %ecx
movl %ebp, %r14d
subl %ecx, %r14d
movq 0x148(%r15,%rax,8), %r15
movl %ebp, 0x48(%rbx,%rax,4)
movl $0x0, %r12d
subl %ecx, %ebp
je 0x790f9
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
xorl %r12d, %r12d
movl %eax, %ecx
incl %r12d
shrl %ecx
cmpl $0x1, %eax
movl %ecx, %eax
ja 0x790ed
cmpl $0xc, %r12d
jb 0x79110
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movl $0x6, 0x28(%rax)
callq *(%rax)
movl 0x14(%r15), %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x79a98
testl %r12d, %r12d
je 0x791cc
cmpl $0x0, 0x18(%rbx)
jne 0x791cc
movq $-0x1, %r15
movl %r12d, %ecx
shlq %cl, %r15
sarl $0x1f, %r14d
leal (%r14,%rbp), %eax
notl %r15d
andl %eax, %r15d
addl 0x38(%rbx), %r12d
movb $0x18, %cl
subb %r12b, %cl
shlq %cl, %r15
orq 0x30(%rbx), %r15
cmpl $0x8, %r12d
jl 0x791c2
movl %r15d, %eax
shrl $0x10, %eax
movq 0x20(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rbx)
movb %al, (%rcx)
decq 0x28(%rbx)
jne 0x79185
movq %rbx, %rdi
callq 0x79d4a
movl %r15d, %eax
notl %eax
testl $0xff0000, %eax         # imm = 0xFF0000
jne 0x791ae
movq 0x20(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movb $0x0, (%rax)
decq 0x28(%rbx)
jne 0x791ae
movq %rbx, %rdi
callq 0x79d4a
shlq $0x8, %r15
leal -0x8(%r12), %eax
cmpl $0xf, %r12d
movl %eax, %r12d
jg 0x79163
jmp 0x791c5
movl %r12d, %eax
movq %r15, 0x30(%rbx)
movl %eax, 0x38(%rbx)
incq %r13
movq 0x8(%rsp), %r15
movslq 0x170(%r15), %rax
cmpq %rax, %r13
jl 0x790a7
movq 0x20(%rbx), %rax
movq 0x28(%r15), %rcx
movq %rax, (%rcx)
movq 0x28(%rbx), %rax
movq %rax, 0x8(%rcx)
movl 0x118(%r15), %eax
testl %eax, %eax
je 0x79219
cmpl $0x0, 0x70(%rbx)
jne 0x79216
movl %eax, 0x70(%rbx)
movl 0x74(%rbx), %eax
incl %eax
andl $0x7, %eax
movl %eax, 0x74(%rbx)
decl 0x70(%rbx)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq