// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jchuff.c
// Function: encode_mcu_huff
METHODDEF(jboolean)
encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  working_state state;
  int blkn, ci;
  jpeg_component_info * compptr;

  /* Load up working state */
  state.next_output_byte = cinfo->dest->next_output_byte;
  state.free_in_buffer = cinfo->dest->free_in_buffer;
  ASSIGN_STATE(state.cur, entropy->saved);
  state.cinfo = cinfo;

  /* Emit restart marker if needed */
  if (cinfo->restart_interval) {
    if (entropy->restarts_to_go == 0)
      if (! emit_restart(&state, entropy->next_restart_num))
	return FALSE;
  }

  /* Encode the MCU data blocks */
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
    ci = cinfo->MCU_membership[blkn];
    compptr = cinfo->cur_comp_info[ci];
    if (! encode_one_block(&state,
			   MCU_data[blkn][0], state.cur.last_dc_val[ci],
			   entropy->dc_derived_tbls[compptr->dc_tbl_no],
			   entropy->ac_derived_tbls[compptr->ac_tbl_no]))
      return FALSE;
    /* Update last_dc_val */
    state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  }

  /* Completed MCU, so update state */
  cinfo->dest->next_output_byte = state.next_output_byte;
  cinfo->dest->free_in_buffer = state.free_in_buffer;
  ASSIGN_STATE(entropy->saved, state.cur);

  /* 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 $0x78, %rsp
movq %rsi, %r12
movq %rdi, %r14
movq 0x1f0(%rdi), %r13
movq 0x28(%rdi), %rax
movq (%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movups 0x18(%r13), %xmm0
movups 0x28(%r13), %xmm1
movups %xmm0, 0x18(%rsp)
movups %xmm1, 0x28(%rsp)
movq %rdi, 0x38(%rsp)
cmpl $0x0, 0x118(%rdi)
je 0x6cd10
cmpl $0x0, 0x38(%r13)
je 0x6cf18
leaq 0x18(%r13), %rax
movq %rax, 0x40(%rsp)
xorl %ecx, %ecx
leaq 0x8(%rsp), %r15
movq %r13, 0x58(%rsp)
movq %r14, 0x50(%rsp)
movq %r12, 0x48(%rsp)
movslq 0x170(%r14), %rax
cmpq %rax, %rcx
jge 0x6cfb5
movslq 0x174(%r14,%rcx,4), %rdx
movq 0x148(%r14,%rdx,8), %rax
movq %rcx, 0x68(%rsp)
movq (%r12,%rcx,8), %rsi
movslq 0x14(%rax), %rcx
movq 0x40(%r13,%rcx,8), %rbx
movslq 0x18(%rax), %rax
movq 0x60(%r13,%rax,8), %r14
movq %rsi, 0x70(%rsp)
movswl (%rsi), %ebp
movq %rdx, 0x60(%rsp)
subl 0x24(%rsp,%rdx,4), %ebp
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
xorl %r12d, %r12d
testl %eax, %eax
je 0x6cd90
shrl %eax
incq %r12
jmp 0x6cd85
cmpl $0xc, %r12d
jb 0x6cda7
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl $0x6, 0x28(%rax)
callq *(%rax)
movl (%rbx,%r12,4), %esi
movsbl 0x400(%rbx,%r12), %edx
movq %r15, %rdi
callq 0x6d101
xorl %ebx, %ebx
testl %eax, %eax
je 0x6cf07
testl %r12d, %r12d
je 0x6cde5
movl %ebp, %esi
sarl $0x1f, %esi
addl %ebp, %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x6d101
testl %eax, %eax
je 0x6cf07
xorl %ebx, %ebx
pushq $0x1
popq %r12
cmpq $0x40, %r12
je 0x6cebe
leaq 0x2ebe4(%rip), %rax     # 0x9b9e0
movslq (%rax,%r12,4), %rax
movq 0x70(%rsp), %rcx
movswl (%rcx,%rax,2), %r13d
testl %r13d, %r13d
je 0x6ce45
movl %ebx, %ebp
shll $0x4, %ebp
incl %ebp
cmpl $0x10, %ebx
jl 0x6ce49
movl 0x3c0(%r14), %esi
movsbl 0x4f0(%r14), %edx
movq %r15, %rdi
callq 0x6d101
testl %eax, %eax
je 0x6cf05
addl $-0x10, %ebx
addl $0xffffff00, %ebp       # imm = 0xFFFFFF00
jmp 0x6ce16
incl %ebx
jmp 0x6ceb6
movl %r13d, %eax
negl %eax
cmovsl %r13d, %eax
movl %r13d, %ecx
shrl $0xf, %ecx
movl %ecx, 0x4(%rsp)
pushq $0x1
popq %rbx
cmpl $0x2, %eax
jb 0x6ce6c
shrl %eax
incl %ebx
incl %ebp
jmp 0x6ce5f
cmpl $0xb, %ebx
jb 0x6ce82
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl $0x6, 0x28(%rax)
callq *(%rax)
movslq %ebp, %rax
movl (%r14,%rax,4), %esi
movsbl 0x400(%r14,%rax), %edx
movq %r15, %rdi
callq 0x6d101
testl %eax, %eax
je 0x6cf05
movswl 0x4(%rsp), %esi
addl %r13d, %esi
movq %r15, %rdi
movl %ebx, %edx
callq 0x6d101
xorl %ebx, %ebx
testl %eax, %eax
je 0x6cf07
incq %r12
jmp 0x6cdeb
testl %ebx, %ebx
jle 0x6ced9
movl (%r14), %esi
movsbl 0x400(%r14), %edx
movq %r15, %rdi
callq 0x6d101
testl %eax, %eax
je 0x6cf05
movq 0x48(%rsp), %r12
movq 0x68(%rsp), %rcx
movq (%r12,%rcx,8), %rax
movswl (%rax), %eax
movq 0x60(%rsp), %rdx
movl %eax, 0x24(%rsp,%rdx,4)
incq %rcx
movq 0x58(%rsp), %r13
movq 0x50(%rsp), %r14
jmp 0x6cd2f
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x3c(%r13), %ebp
leaq 0x8(%rsp), %rdi
callq 0x6d0a8
xorl %ebx, %ebx
testl %eax, %eax
je 0x6cf07
movq 0x8(%rsp), %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rsp)
movb $-0x1, (%rcx)
movq 0x10(%rsp), %rcx
decq %rcx
movq %rcx, 0x10(%rsp)
jne 0x6cf64
leaq 0x8(%rsp), %rdi
callq 0x6d0cd
testl %eax, %eax
je 0x6cf07
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
addb $-0x30, %bpl
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%rsp)
movb %bpl, (%rax)
decq %rcx
movq %rcx, 0x10(%rsp)
jne 0x6cf90
leaq 0x8(%rsp), %rdi
callq 0x6d0cd
testl %eax, %eax
je 0x6cf07
movq 0x38(%rsp), %rax
movl 0x144(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x6cd10
andl $0x0, 0x24(%rsp,%rcx,4)
incq %rcx
jmp 0x6cfa2
movq 0x8(%rsp), %rax
movq 0x28(%r14), %rcx
movq %rax, (%rcx)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rcx)
leaq 0x18(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movq 0x40(%rsp), %rax
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movl 0x118(%r14), %eax
pushq $0x1
popq %rbx
testl %eax, %eax
je 0x6cf07
movl 0x38(%r13), %ecx
testl %ecx, %ecx
jne 0x6d00b
movl 0x3c(%r13), %ecx
incl %ecx
andl $0x7, %ecx
movl %ecx, 0x3c(%r13)
movl %eax, %ecx
decl %ecx
movl %ecx, 0x38(%r13)
jmp 0x6cf07