// File: /workspace/github_cpp_makefile_star2_O2/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, 0x48(%rsp)
movq %rdi, %rbx
movq 0x1c8(%rdi), %rcx
movl 0x140(%rdi), %eax
movl 0x168(%rdi), %edx
decl %edx
movl %edx, 0xc(%rsp)
decl %eax
movl %eax, 0x30(%rsp)
movl 0x18(%rcx), %eax
leaq 0x20(%rcx), %r15
movq %rcx, 0x18(%rsp)
movq %rdi, 0x38(%rsp)
cmpl 0x1c(%rcx), %eax
jge 0x6b1f5
movl 0x14(%rcx), %ebp
leal (,%rax,8), %edx
movl %edx, 0x24(%rsp)
movq %rax, 0x10(%rsp)
cmpl 0xc(%rsp), %ebp
ja 0x6b1c9
xorl %edx, %edx
xorl %r14d, %r14d
movl %ebp, 0x28(%rsp)
movslq 0x144(%rbx), %rax
cmpq %rax, %rdx
jge 0x6b1a4
xorl %eax, %eax
cmpl 0xc(%rsp), %ebp
setae %al
movq %rdx, 0x40(%rsp)
movq 0x148(%rbx,%rdx,8), %r12
shll $0x4, %eax
movslq 0x34(%rax,%r12), %rax
movq %rax, 0x50(%rsp)
movl 0x40(%r12), %eax
imull %ebp, %eax
movl %eax, 0x2c(%rsp)
xorl %ebx, %ebx
movl 0x24(%rsp), %r8d
cmpl 0x38(%r12), %ebx
jge 0x6b18e
movslq %r14d, %rbp
movl 0x30(%rsp), %eax
cmpl %eax, 0x10(%rcx)
movl %r8d, 0x34(%rsp)
jb 0x6b0af
movq 0x10(%rsp), %rax
addl %ebx, %eax
cmpl 0x48(%r12), %eax
jge 0x6b12f
movq 0x38(%rsp), %rdi
movq 0x1e8(%rdi), %rax
movslq 0x4(%r12), %rcx
movq 0x48(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq (%r15,%rbp,8), %rcx
movq 0x50(%rsp), %r13
movl %r13d, (%rsp)
movq %r12, %rsi
movl 0x2c(%rsp), %r9d
callq *0x8(%rax)
movl 0x34(%r12), %eax
cmpl %eax, %r13d
jge 0x6b176
leal (%r14,%r13), %ecx
movslq %ecx, %rcx
movq (%r15,%rcx,8), %rdi
subl %r13d, %eax
movslq %eax, %rsi
shlq $0x7, %rsi
callq 0x791cd
movl 0x34(%r12), %eax
movslq %eax, %rcx
leaq (%r15,%rbp,8), %rdx
cmpq %rcx, %r13
jge 0x6b176
movq -0x8(%rdx,%r13,8), %rdi
movq (%rdx,%r13,8), %r8
movzwl (%rdi), %edi
movw %di, (%r8)
incq %r13
jmp 0x6b115
movq (%r15,%rbp,8), %rdi
movslq 0x34(%r12), %rsi
shlq $0x7, %rsi
callq 0x791cd
movl 0x34(%r12), %eax
leal -0x1(%rbp), %ecx
movslq %ecx, %rcx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
leaq (%r15,%rbp,8), %rsi
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x6b176
movq (%r15,%rcx,8), %r8
movzwl (%r8), %r8d
movq (%rsi,%rdi,8), %r9
movw %r8w, (%r9)
incq %rdi
jmp 0x6b15c
addl %eax, %r14d
movl 0x34(%rsp), %r8d
addl $0x8, %r8d
incl %ebx
movq 0x18(%rsp), %rcx
jmp 0x6b081
movq 0x40(%rsp), %rdx
incq %rdx
movq 0x38(%rsp), %rbx
movl 0x28(%rsp), %ebp
jmp 0x6b03b
movq 0x1f0(%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x8(%rax)
testl %eax, %eax
je 0x6b1d4
incl %ebp
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rax
jmp 0x6b028
andl $0x0, 0x14(%rcx)
incl %eax
jmp 0x6b00c
movq 0x18(%rsp), %rax
movq 0x10(%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
incl 0x10(%rcx)
movq %rbx, %rdi
callq 0x6af88
pushq $0x1
popq %rax
jmp 0x6b1e6