// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jccoefct.c
// Function: compress_data
METHODDEF(jboolean)
compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  JDIMENSION MCU_col_num;	/* index of current MCU within row */
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  int blkn, bi, ci, yindex, yoffset, blockcnt;
  JDIMENSION ypos, xpos;
  jpeg_component_info *compptr;

  /* Loop to write as much as one whole iMCU row */
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
       yoffset++) {
    for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
	 MCU_col_num++) {
      /* Determine where data comes from in input_buf and do the DCT thing.
       * Each call on forward_DCT processes a horizontal row of DCT blocks
       * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
       * sequentially.  Dummy blocks at the right or bottom edge are filled in
       * specially.  The data in them does not matter for image reconstruction,
       * so we fill them with values that will encode to the smallest amount of
       * data, viz: all zeroes in the AC entries, DC entries equal to previous
       * block's DC value.  (Thanks to Thomas Kinsman for this idea.)
       */
      blkn = 0;
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
	compptr = cinfo->cur_comp_info[ci];
	blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
						: compptr->last_col_width;
	xpos = MCU_col_num * compptr->MCU_sample_width;
	ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
	  if (coef->iMCU_row_num < last_iMCU_row ||
	      yoffset+yindex < compptr->last_row_height) {
	    (*cinfo->fdct->forward_DCT) (cinfo, compptr,
					 input_buf[compptr->component_index],
					 coef->MCU_buffer[blkn],
					 ypos, xpos, (JDIMENSION) blockcnt);
	    if (blockcnt < compptr->MCU_width) {
	      /* Create some dummy blocks at the right edge of the image. */
	      jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
			(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
	      for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
		coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
	      }
	    }
	  } else {
	    /* Create a row of dummy blocks at the bottom of the image. */
	    jzero_far((void FAR *) coef->MCU_buffer[blkn],
		      compptr->MCU_width * SIZEOF(JBLOCK));
	    for (bi = 0; bi < compptr->MCU_width; bi++) {
	      coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
	    }
	  }
	  blkn += compptr->MCU_width;
	  ypos += DCTSIZE;
	}
      }
      /* Try to write the MCU.  In event of a suspension failure, we will
       * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
       */
      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
	/* Suspension forced; update state counters and exit */
	coef->MCU_vert_offset = yoffset;
	coef->mcu_ctr = MCU_col_num;
	return FALSE;
      }
    }
    /* Completed an MCU row, but perhaps not an iMCU row */
    coef->mcu_ctr = 0;
  }
  /* Completed the iMCU row, advance counters for next one */
  coef->iMCU_row_num++;
  start_iMCU_row(cinfo);
  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x1c8(%rdi), %rdx
movl 0x18(%rdx), %esi
movl 0x1c(%rdx), %eax
movq %rsi, 0x20(%rsp)
cmpl %eax, %esi
jge 0x751ef
movq 0x10(%rsp), %rcx
movl 0x140(%rcx), %esi
movl 0x168(%rcx), %ecx
decl %ecx
movl %ecx, 0x1c(%rsp)
decl %esi
movl %esi, 0x44(%rsp)
leaq 0x20(%rdx), %r14
movl 0x14(%rdx), %ebp
movq %rdx, 0x30(%rsp)
cmpl 0x1c(%rsp), %ebp
ja 0x751d2
movq 0x20(%rsp), %rax
leal (,%rax,8), %eax
movl %eax, 0x38(%rsp)
movq 0x10(%rsp), %rax
movl 0x144(%rax), %ecx
testl %ecx, %ecx
jle 0x751a2
xorl %r8d, %r8d
xorl %eax, %eax
movl %ebp, 0x3c(%rsp)
xorl %edx, %edx
cmpl 0x1c(%rsp), %ebp
setae %sil
movq 0x10(%rsp), %rdi
movq 0x148(%rdi,%r8,8), %r12
cmpl $0x0, 0x38(%r12)
jle 0x75193
movq %r8, 0x48(%rsp)
movb %sil, %dl
shll $0x4, %edx
movslq 0x34(%rdx,%r12), %r10
movl 0x40(%r12), %ecx
imull %ebp, %ecx
movl %ecx, 0x40(%rsp)
xorl %ebp, %ebp
movl 0x38(%rsp), %r13d
movq %r10, 0x28(%rsp)
movl %eax, %ebx
movslq %eax, %r15
movq 0x30(%rsp), %rax
movl 0x44(%rsp), %ecx
cmpl %ecx, 0x10(%rax)
jb 0x7509e
movq 0x20(%rsp), %rax
addl %ebp, %eax
cmpl 0x48(%r12), %eax
jge 0x7512e
movq 0x10(%rsp), %rdi
movq 0x1e8(%rdi), %rax
movslq 0x4(%r12), %rcx
movq 0x50(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq (%r14,%r15,8), %rcx
movl %r10d, (%rsp)
movq %r12, %rsi
movl %r13d, %r8d
movl 0x40(%rsp), %r9d
callq *0x8(%rax)
movq 0x28(%rsp), %r10
movl 0x34(%r12), %eax
cmpl %r10d, %eax
jle 0x7516c
leal (%rbx,%r10), %ecx
movslq %ecx, %rcx
movq (%r14,%rcx,8), %rdi
subl %r10d, %eax
movslq %eax, %rsi
shlq $0x7, %rsi
callq 0x85d17
movq 0x28(%rsp), %r10
movl 0x34(%r12), %eax
cmpl %eax, %r10d
jge 0x7516c
movslq %eax, %rcx
leaq (%r14,%r15,8), %rdx
movq %r10, %rsi
movq -0x8(%rdx,%rsi,8), %rdi
movq (%rdx,%rsi,8), %r8
movzwl (%rdi), %edi
movw %di, (%r8)
incq %rsi
cmpq %rsi, %rcx
jne 0x75114
jmp 0x7516c
movq (%r14,%r15,8), %rdi
movslq 0x34(%r12), %rsi
shlq $0x7, %rsi
callq 0x85d17
movslq 0x34(%r12), %rax
testq %rax, %rax
jle 0x75167
movq -0x8(%r14,%r15,8), %rcx
movzwl (%rcx), %ecx
leaq (%r14,%r15,8), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movw %cx, (%rdi)
incq %rsi
cmpq %rsi, %rax
jne 0x75158
movq 0x28(%rsp), %r10
addl %ebx, %eax
addl $0x8, %r13d
incl %ebp
cmpl 0x38(%r12), %ebp
jl 0x75079
movq 0x10(%rsp), %rcx
movl 0x144(%rcx), %ecx
movl 0x3c(%rsp), %ebp
movq 0x48(%rsp), %r8
incq %r8
movslq %ecx, %rdx
cmpq %rdx, %r8
jl 0x7502e
movq 0x10(%rsp), %rdi
movq 0x1f0(%rdi), %rax
movq %r14, %rbx
movq %r14, %rsi
callq *0x8(%rax)
testl %eax, %eax
je 0x75203
incl %ebp
cmpl 0x1c(%rsp), %ebp
movq %rbx, %r14
jbe 0x75012
movq 0x30(%rsp), %rdx
movl 0x1c(%rdx), %eax
movl $0x0, 0x14(%rdx)
movq 0x20(%rsp), %rsi
incl %esi
xorl %ebp, %ebp
movq %rsi, 0x20(%rsp)
cmpl %eax, %esi
jl 0x74ff8
incl 0x10(%rdx)
movq 0x10(%rsp), %rdi
callq 0x74f5c
movl $0x1, %eax
jmp 0x75215
movq 0x30(%rsp), %rax
movq 0x20(%rsp), %rcx
movl %ecx, 0x18(%rax)
movl %ebp, 0x14(%rax)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq