// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq 0x1c8(%rdi), %r9
movl 0x18(%r9), %ecx
movq %rcx, 0x18(%rsp)
cmpl 0x1c(%r9), %ecx
jge 0x76139
movl 0x140(%rbx), %eax
movl 0x168(%rbx), %ecx
decl %ecx
movl %ecx, 0x14(%rsp)
decl %eax
movl %eax, 0x3c(%rsp)
leaq 0x20(%r9), %rax
movq %rax, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %rbx, 0x40(%rsp)
movl 0x14(%r9), %r15d
cmpl 0x14(%rsp), %r15d
ja 0x7611b
movq 0x18(%rsp), %rax
leal (,%rax,8), %eax
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x144(%rbx)
jle 0x760f2
xorl %edx, %edx
xorl %r14d, %r14d
movl %r15d, 0x34(%rsp)
xorl %eax, %eax
cmpl 0x14(%rsp), %r15d
setae %cl
movq %rdx, 0x48(%rsp)
movq 0x148(%rbx,%rdx,8), %r12
cmpl $0x0, 0x38(%r12)
jle 0x760d0
movb %cl, %al
shll $0x4, %eax
movslq 0x34(%rax,%r12), %rbp
movl 0x40(%r12), %eax
imull %r15d, %eax
movl %eax, 0x38(%rsp)
xorl %ebx, %ebx
movl 0x30(%rsp), %r13d
movslq %r14d, %r15
movl 0x3c(%rsp), %eax
cmpl %eax, 0x10(%r9)
jb 0x75fe6
movq 0x18(%rsp), %rax
addl %ebx, %eax
cmpl 0x48(%r12), %eax
jge 0x76075
movq 0x40(%rsp), %rdi
movq 0x1e8(%rdi), %rax
movslq 0x4(%r12), %rcx
movq 0x50(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x20(%r9,%r15,8), %rcx
movl %ebp, (%rsp)
movq %r12, %rsi
movl %r13d, %r8d
movl 0x38(%rsp), %r9d
callq *0x8(%rax)
movq 0x20(%rsp), %r9
movl 0x34(%r12), %eax
cmpl %ebp, %eax
jle 0x760ba
leal (%r14,%rbp), %ecx
movslq %ecx, %rcx
movq 0x20(%r9,%rcx,8), %rdi
subl %ebp, %eax
movslq %eax, %rsi
shlq $0x7, %rsi
callq 0x86b1f
movq 0x20(%rsp), %r9
movslq 0x34(%r12), %rax
cmpl %eax, %ebp
jge 0x760ba
movq 0x28(%rsp), %rcx
leaq (%rcx,%r15,8), %rcx
movq %rbp, %rdx
movq -0x8(%rcx,%rdx,8), %rsi
movq (%rcx,%rdx,8), %rdi
movzwl (%rsi), %esi
movw %si, (%rdi)
incq %rdx
cmpq %rdx, %rax
jne 0x7605c
jmp 0x760ba
movq 0x20(%r9,%r15,8), %rdi
movslq 0x34(%r12), %rsi
shlq $0x7, %rsi
callq 0x86b1f
movq 0x20(%rsp), %r9
movslq 0x34(%r12), %rax
testq %rax, %rax
jle 0x760ba
movq 0x18(%r9,%r15,8), %rcx
movq 0x28(%rsp), %rdx
leaq (%rdx,%r15,8), %rdx
xorl %esi, %esi
movzwl (%rcx), %edi
movq (%rdx,%rsi,8), %r8
movw %di, (%r8)
incq %rsi
cmpq %rsi, %rax
jne 0x760a7
addl 0x34(%r12), %r14d
addl $0x8, %r13d
incl %ebx
cmpl 0x38(%r12), %ebx
jl 0x75fc7
movq 0x48(%rsp), %rdx
incq %rdx
movq 0x40(%rsp), %rbx
movslq 0x144(%rbx), %rax
cmpq %rax, %rdx
movl 0x34(%rsp), %r15d
jl 0x75f86
movq 0x1f0(%rbx), %rax
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq *0x8(%rax)
testl %eax, %eax
je 0x7614c
incl %r15d
cmpl 0x14(%rsp), %r15d
movq 0x20(%rsp), %r9
jbe 0x75f6f
movl $0x0, 0x14(%r9)
movq 0x18(%rsp), %rcx
incl %ecx
movq %rcx, 0x18(%rsp)
cmpl 0x1c(%r9), %ecx
jl 0x75f50
incl 0x10(%r9)
movq %rbx, %rdi
callq 0x75eb4
movl $0x1, %eax
jmp 0x7615f
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
movl %ecx, 0x18(%rax)
movl %r15d, 0x14(%rax)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq