// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jccoefct.c
// Function: compress_first_pass
METHODDEF(jboolean)
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  JDIMENSION blocks_across, MCUs_across, MCUindex;
  int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  JCOEF lastDC;
  jpeg_component_info *compptr;
  JBLOCKARRAY buffer;
  JBLOCKROW thisblockrow, lastblockrow;

  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    /* Align the virtual buffer for this component. */
    buffer = (*cinfo->mem->access_virt_barray)
      ((j_common_ptr) cinfo, coef->whole_image[ci],
       coef->iMCU_row_num * compptr->v_samp_factor,
       (JDIMENSION) compptr->v_samp_factor, TRUE);
    /* Count non-dummy DCT block rows in this iMCU row. */
    if (coef->iMCU_row_num < last_iMCU_row)
      block_rows = compptr->v_samp_factor;
    else {
      /* NB: can't use last_row_height here, since may not be set! */
      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
    }
    blocks_across = compptr->width_in_blocks;
    h_samp_factor = compptr->h_samp_factor;
    /* Count number of dummy blocks to be added at the right margin. */
    ndummy = (int) (blocks_across % h_samp_factor);
    if (ndummy > 0)
      ndummy = h_samp_factor - ndummy;
    /* Perform DCT for all non-dummy blocks in this iMCU row.  Each call
     * on forward_DCT processes a complete horizontal row of DCT blocks.
     */
    for (block_row = 0; block_row < block_rows; block_row++) {
      thisblockrow = buffer[block_row];
      (*cinfo->fdct->forward_DCT) (cinfo, compptr,
				   input_buf[ci], thisblockrow,
				   (JDIMENSION) (block_row * DCTSIZE),
				   (JDIMENSION) 0, blocks_across);
      if (ndummy > 0) {
	/* Create dummy blocks at the right edge of the image. */
	thisblockrow += blocks_across; /* => first dummy block */
	jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
	lastDC = thisblockrow[-1][0];
	for (bi = 0; bi < ndummy; bi++) {
	  thisblockrow[bi][0] = lastDC;
	}
      }
    }
    /* If at end of image, create dummy block rows as needed.
     * The tricky part here is that within each MCU, we want the DC values
     * of the dummy blocks to match the last real block's DC value.
     * This squeezes a few more bytes out of the resulting file...
     */
    if (coef->iMCU_row_num == last_iMCU_row) {
      blocks_across += ndummy;	/* include lower right corner */
      MCUs_across = blocks_across / h_samp_factor;
      for (block_row = block_rows; block_row < compptr->v_samp_factor;
	   block_row++) {
	thisblockrow = buffer[block_row];
	lastblockrow = buffer[block_row-1];
	jzero_far((void FAR *) thisblockrow,
		  (size_t) (blocks_across * SIZEOF(JBLOCK)));
	for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
	  lastDC = lastblockrow[h_samp_factor-1][0];
	  for (bi = 0; bi < h_samp_factor; bi++) {
	    thisblockrow[bi][0] = lastDC;
	  }
	  thisblockrow += h_samp_factor; /* advance to next MCU in row */
	  lastblockrow += h_samp_factor;
	}
      }
    }
  }
  /* NB: compress_output will increment iMCU_row_num if successful.
   * A suspension return will result in redoing all the work above next time.
   */

  /* Emit data to the entropy encoder, sharing code with subsequent passes */
  return compress_output(cinfo, input_buf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, 0x58(%rsp)
movq %rdi, %rbp
movq 0x1c8(%rdi), %rax
movq %rax, 0x30(%rsp)
movl 0x140(%rdi), %eax
decl %eax
movl %eax, 0x1c(%rsp)
movq 0x58(%rdi), %r9
xorl %r15d, %r15d
movq %rdi, 0x38(%rsp)
movslq 0x4c(%rbp), %rax
cmpq %rax, %r15
jge 0x6b437
movq 0x8(%rbp), %rax
movq 0x30(%rsp), %rbx
movq 0x70(%rbx,%r15,8), %rsi
movl 0xc(%r9), %ecx
movl 0x10(%rbx), %edx
imull %ecx, %edx
movq %rbp, %rdi
pushq $0x1
popq %r8
movq %r9, %r14
callq *0x40(%rax)
movq %rax, 0x48(%rsp)
movl 0x1c(%rsp), %eax
cmpl %eax, 0x10(%rbx)
movq %r15, 0x40(%rsp)
jae 0x6b28a
movl 0xc(%r14), %esi
jmp 0x6b29d
movl 0xc(%r14), %ecx
movl 0x20(%r14), %eax
xorl %edx, %edx
divl %ecx
movl %edx, %esi
testl %edx, %edx
cmovel %ecx, %esi
movq %r14, %r9
movl 0x1c(%r14), %eax
movslq 0x8(%r14), %r14
movq %rax, 0x10(%rsp)
xorl %edx, %edx
divl %r14d
movl %r14d, %r13d
subl %edx, %r13d
testl %edx, %edx
cmovlel %edx, %r13d
movq %r13, 0x20(%rsp)
shlq $0x7, %r13
testl %esi, %esi
movl $0x0, %eax
movl %esi, 0x2c(%rsp)
cmovgl %esi, %eax
movq %rax, 0x60(%rsp)
xorl %r12d, %r12d
movq %r9, 0x50(%rsp)
cmpq 0x60(%rsp), %r12
je 0x6b372
movq 0x48(%rsp), %rax
movq (%rax,%r12,8), %r15
movq 0x1e8(%rbp), %rax
movq 0x58(%rsp), %rcx
movq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
leal (,%r12,8), %r8d
movq 0x10(%rsp), %rcx
movl %ecx, (%rsp)
movq %rbp, %rdi
movq %r9, %rsi
movq %r15, %rcx
xorl %r9d, %r9d
callq *0x8(%rax)
cmpl $0x0, 0x20(%rsp)
jle 0x6b365
movq 0x10(%rsp), %rbp
shlq $0x7, %rbp
leaq (%r15,%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x791cd
movzwl -0x80(%r15,%rbp), %eax
movq 0x38(%rsp), %rbp
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x6b365
movw %ax, (%rbx,%rcx)
subq $-0x80, %rcx
jmp 0x6b356
incq %r12
movq 0x50(%rsp), %r9
jmp 0x6b2e2
movq 0x30(%rsp), %rax
movl 0x1c(%rsp), %ecx
cmpl %ecx, 0x10(%rax)
jne 0x6b421
movq 0x20(%rsp), %rcx
addl 0x10(%rsp), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r14d
movl %eax, %ebp
shlq $0x7, %rcx
movq %rcx, 0x20(%rsp)
leaq -0x1(%r14), %rbx
testl %r14d, %r14d
movl $0x0, %r15d
cmovgl %r14d, %r15d
movslq 0x2c(%rsp), %rcx
shlq $0x7, %r15
shlq $0x7, %r14
shlq $0x7, %rbx
movslq 0xc(%r9), %rax
cmpq %rax, %rcx
jge 0x6b421
movq 0x48(%rsp), %rax
movq -0x8(%rax,%rcx,8), %r12
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %r13
movq %r13, %rdi
movq 0x20(%rsp), %rsi
callq 0x791cd
xorl %eax, %eax
cmpl %ebp, %eax
jae 0x6b412
movzwl (%r12,%rbx), %ecx
xorl %edx, %edx
cmpq %rdx, %r15
je 0x6b408
movw %cx, (%r13,%rdx)
subq $-0x80, %rdx
jmp 0x6b3f7
addq %r14, %r12
incl %eax
addq %r14, %r13
jmp 0x6b3ec
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x50(%rsp), %r9
jmp 0x6b3c1
movq 0x40(%rsp), %r15
incq %r15
addq $0x60, %r9
movq 0x38(%rsp), %rbp
jmp 0x6b23f
movq %rbp, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6b44a