// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rsi, 0x80(%rsp)
cmpl $0x0, 0x4c(%rdi)
jle 0x768f8
movl 0x140(%rdi), %eax
decl %eax
movl %eax, 0x10(%rsp)
movq 0x58(%rdi), %r9
movq 0x1c8(%rdi), %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
movq %rdi, 0x30(%rsp)
movq 0x8(%rdi), %rax
movq 0x20(%rsp), %r14
movq %rcx, 0x38(%rsp)
movq 0x70(%r14,%rcx,8), %rsi
movl 0xc(%r9), %ecx
movl 0x10(%r14), %edx
imull %ecx, %edx
movl $0x1, %r8d
movq %r9, %rbx
callq *0x40(%rax)
movq %rax, 0x40(%rsp)
movl 0x10(%rsp), %eax
cmpl %eax, 0x10(%r14)
jae 0x761f2
movl 0xc(%rbx), %esi
jmp 0x76203
movl 0xc(%rbx), %ecx
movl 0x20(%rbx), %eax
xorl %edx, %edx
divl %ecx
movl %edx, %esi
testl %edx, %edx
cmovel %ecx, %esi
movq %rbx, %r9
movl 0x1c(%rbx), %ebp
movslq 0x8(%rbx), %rcx
movl %ebp, %eax
xorl %edx, %edx
divl %ecx
movq %rcx, 0x28(%rsp)
movl %ecx, %ebx
subl %edx, %ebx
testl %edx, %edx
cmovlel %edx, %ebx
movl %esi, 0x14(%rsp)
testl %esi, %esi
movq %r9, 0x48(%rsp)
movdqa 0x2c05c(%rip), %xmm1    # 0xa2290
jle 0x76566
movq %rbx, %rcx
movl %ecx, %eax
movq %rax, %rdx
shlq $0x7, %rdx
movq %rdx, 0x18(%rsp)
movl 0x14(%rsp), %edx
movq %rdx, 0x60(%rsp)
leal 0x7(%rbx), %r15d
decq %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm11    # xmm11 = xmm0[0,1,0,1]
movq %rbp, %r12
shlq $0x7, %r12
shrl $0x3, %r15d
shlq $0xa, %r15
pxor %xmm1, %xmm11
xorl %r13d, %r13d
movdqa %xmm11, 0x50(%rsp)
movq 0x40(%rsp), %rax
movq (%rax,%r13,8), %r14
movq 0x30(%rsp), %rdi
movq 0x1e8(%rdi), %rax
movq 0x80(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
leal (,%r13,8), %r8d
movl %ebp, (%rsp)
movq %r9, %rsi
movq %r14, %rcx
xorl %r9d, %r9d
callq *0x8(%rax)
testl %ebx, %ebx
jle 0x76553
leaq (%r14,%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x86b1f
movdqa 0x50(%rsp), %xmm11
pcmpeqd %xmm10, %xmm10
movdqa 0x2bfa4(%rip), %xmm9    # 0xa2290
leaq (%r14,%r12), %rax
addq $0x380, %rax            # imm = 0x380
movzwl -0x400(%rax), %ecx
xorl %edx, %edx
movdqa 0x2bf79(%rip), %xmm0    # 0xa2280
movdqa 0x34201(%rip), %xmm1    # 0xaa510
movdqa 0x341e9(%rip), %xmm2    # 0xaa500
movdqa 0x341d1(%rip), %xmm3    # 0xaa4f0
movdqa %xmm0, %xmm4
pxor %xmm9, %xmm4
movdqa %xmm4, %xmm6
pcmpgtd %xmm11, %xmm6
pshufd $0xa0, %xmm6, %xmm5     # xmm5 = xmm6[0,0,2,2]
pshuflw $0xe8, %xmm5, %xmm7     # xmm7 = xmm5[0,2,2,3,4,5,6,7]
pcmpeqd %xmm11, %xmm4
pshufd $0xf5, %xmm4, %xmm4     # xmm4 = xmm4[1,1,3,3]
pshuflw $0xe8, %xmm4, %xmm8     # xmm8 = xmm4[0,2,2,3,4,5,6,7]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pshuflw $0xe8, %xmm6, %xmm7     # xmm7 = xmm6[0,2,2,3,4,5,6,7]
por %xmm8, %xmm7
pxor %xmm10, %xmm7
packssdw %xmm7, %xmm7
movd %xmm7, %esi
testb $0x1, %sil
je 0x7637a
movw %cx, -0x380(%rax,%rdx)
pand %xmm5, %xmm4
por %xmm6, %xmm4
packssdw %xmm4, %xmm4
pxor %xmm10, %xmm4
packssdw %xmm4, %xmm4
movd %xmm4, %esi
shrl $0x10, %esi
testb $0x1, %sil
je 0x763a4
movw %cx, -0x300(%rax,%rdx)
movdqa %xmm1, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm11, %xmm6
pshufd $0xa0, %xmm6, %xmm4     # xmm4 = xmm6[0,0,2,2]
pcmpeqd %xmm11, %xmm5
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
movdqa %xmm5, %xmm7
pand %xmm4, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
por %xmm6, %xmm7
packssdw %xmm7, %xmm7
pxor %xmm10, %xmm7
packssdw %xmm7, %xmm7
pextrw $0x2, %xmm7, %esi
testb $0x1, %sil
je 0x763f6
movw %cx, -0x280(%rax,%rdx)
pshufhw $0x84, %xmm4, %xmm4     # xmm4 = xmm4[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm5, %xmm5     # xmm5 = xmm5[0,1,2,3,4,5,4,6]
pand %xmm4, %xmm5
pshufhw $0x84, %xmm6, %xmm4     # xmm4 = xmm6[0,1,2,3,4,5,4,6]
por %xmm5, %xmm4
pxor %xmm10, %xmm4
packssdw %xmm4, %xmm4
pextrw $0x3, %xmm4, %esi
testb $0x1, %sil
je 0x76429
movw %cx, -0x200(%rax,%rdx)
movdqa %xmm2, %xmm4
pxor %xmm9, %xmm4
movdqa %xmm4, %xmm6
pcmpgtd %xmm11, %xmm6
pshufd $0xa0, %xmm6, %xmm5     # xmm5 = xmm6[0,0,2,2]
pshuflw $0xe8, %xmm5, %xmm7     # xmm7 = xmm5[0,2,2,3,4,5,6,7]
pcmpeqd %xmm11, %xmm4
pshufd $0xf5, %xmm4, %xmm4     # xmm4 = xmm4[1,1,3,3]
pshuflw $0xe8, %xmm4, %xmm8     # xmm8 = xmm4[0,2,2,3,4,5,6,7]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pshuflw $0xe8, %xmm6, %xmm7     # xmm7 = xmm6[0,2,2,3,4,5,6,7]
por %xmm8, %xmm7
pxor %xmm10, %xmm7
packssdw %xmm7, %xmm7
pextrw $0x4, %xmm7, %esi
testb $0x1, %sil
je 0x76485
movw %cx, -0x180(%rax,%rdx)
pand %xmm5, %xmm4
por %xmm6, %xmm4
packssdw %xmm4, %xmm4
pxor %xmm10, %xmm4
packssdw %xmm4, %xmm4
pextrw $0x5, %xmm4, %esi
testb $0x1, %sil
je 0x764ad
movw %cx, -0x100(%rax,%rdx)
movdqa %xmm3, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm11, %xmm6
pshufd $0xa0, %xmm6, %xmm4     # xmm4 = xmm6[0,0,2,2]
pcmpeqd %xmm11, %xmm5
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
movdqa %xmm5, %xmm7
pand %xmm4, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
por %xmm6, %xmm7
packssdw %xmm7, %xmm7
pxor %xmm10, %xmm7
packssdw %xmm7, %xmm7
pextrw $0x6, %xmm7, %esi
testb $0x1, %sil
je 0x764fc
movw %cx, -0x80(%rax,%rdx)
pshufhw $0x84, %xmm4, %xmm4     # xmm4 = xmm4[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm5, %xmm5     # xmm5 = xmm5[0,1,2,3,4,5,4,6]
pand %xmm4, %xmm5
pshufhw $0x84, %xmm6, %xmm4     # xmm4 = xmm6[0,1,2,3,4,5,4,6]
por %xmm5, %xmm4
pxor %xmm10, %xmm4
packssdw %xmm4, %xmm4
pextrw $0x7, %xmm4, %esi
testb $0x1, %sil
je 0x7652b
movw %cx, (%rax,%rdx)
movdqa 0x33fed(%rip), %xmm4    # 0xaa520
paddq %xmm4, %xmm0
paddq %xmm4, %xmm1
paddq %xmm4, %xmm2
paddq %xmm4, %xmm3
addq $0x400, %rdx            # imm = 0x400
cmpq %rdx, %r15
jne 0x7631f
incq %r13
cmpq 0x60(%rsp), %r13
movq 0x48(%rsp), %r9
jne 0x76284
movl 0x10(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl %eax, 0x10(%rcx)
movq 0x28(%rsp), %r13
movl 0x14(%rsp), %esi
jne 0x768da
movl %r13d, %ecx
addl %ebp, %ebx
movq %rbx, 0x50(%rsp)
movl %ebx, %eax
xorl %edx, %edx
divl %ecx
cmpl 0xc(%r9), %esi
jge 0x768da
movl %eax, %ebp
movl 0x50(%rsp), %eax
shlq $0x7, %rax
movq %rax, 0x78(%rsp)
leaq -0x1(%r13), %r12
movslq %esi, %rdx
leal 0x7(%rcx), %ebx
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa %xmm0, 0x60(%rsp)
shlq $0x7, %r13
shrl $0x3, %ebx
shlq $0xa, %rbx
shlq $0x7, %r12
movq 0x40(%rsp), %rax
movq -0x8(%rax,%rdx,8), %r15
movq %rdx, 0x18(%rsp)
movq (%rax,%rdx,8), %r14
movq %r14, %rdi
movq 0x78(%rsp), %rsi
callq 0x86b1f
movq 0x28(%rsp), %rdi
pcmpeqd %xmm15, %xmm15
movdqa 0x2bc87(%rip), %xmm14   # 0xa2290
movq 0x48(%rsp), %r9
cmpl 0x50(%rsp), %edi
movdqa 0x33ed5(%rip), %xmm10   # 0xaa4f0
movdqa 0x33edc(%rip), %xmm11   # 0xaa500
movdqa 0x33ee3(%rip), %xmm12   # 0xaa510
movdqa 0x2bc4a(%rip), %xmm13   # 0xa2280
ja 0x768c5
xorl %eax, %eax
testl %edi, %edi
jle 0x768b5
movzwl (%r15,%r12), %ecx
xorl %edx, %edx
movdqa %xmm13, %xmm0
movdqa %xmm12, %xmm1
movdqa %xmm11, %xmm2
movdqa %xmm10, %xmm3
movdqa 0x60(%rsp), %xmm4
pxor %xmm14, %xmm4
movdqa %xmm0, %xmm5
pxor %xmm14, %xmm5
movdqa %xmm5, %xmm7
pcmpgtd %xmm4, %xmm7
pshufd $0xa0, %xmm7, %xmm6     # xmm6 = xmm7[0,0,2,2]
pshuflw $0xe8, %xmm6, %xmm8     # xmm8 = xmm6[0,2,2,3,4,5,6,7]
pcmpeqd %xmm4, %xmm5
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pshuflw $0xe8, %xmm5, %xmm9     # xmm9 = xmm5[0,2,2,3,4,5,6,7]
pand %xmm8, %xmm9
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
pshuflw $0xe8, %xmm7, %xmm8     # xmm8 = xmm7[0,2,2,3,4,5,6,7]
por %xmm9, %xmm8
pxor %xmm15, %xmm8
packssdw %xmm8, %xmm8
movd %xmm8, %esi
testb $0x1, %sil
je 0x766c6
movw %cx, (%r14,%rdx)
pand %xmm6, %xmm5
por %xmm7, %xmm5
packssdw %xmm5, %xmm5
pxor %xmm15, %xmm5
packssdw %xmm5, %xmm5
movd %xmm5, %esi
shrl $0x10, %esi
testb $0x1, %sil
je 0x766f1
movw %cx, 0x80(%r14,%rdx)
movdqa %xmm1, %xmm6
pxor %xmm14, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm4, %xmm7
pshufd $0xa0, %xmm7, %xmm5     # xmm5 = xmm7[0,0,2,2]
pcmpeqd %xmm4, %xmm6
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
movdqa %xmm6, %xmm8
pand %xmm5, %xmm8
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
por %xmm7, %xmm8
packssdw %xmm8, %xmm8
pxor %xmm15, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x2, %xmm8, %esi
testb $0x1, %sil
je 0x76748
movw %cx, 0x100(%r14,%rdx)
pshufhw $0x84, %xmm5, %xmm5     # xmm5 = xmm5[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm6, %xmm6     # xmm6 = xmm6[0,1,2,3,4,5,4,6]
pand %xmm5, %xmm6
pshufhw $0x84, %xmm7, %xmm5     # xmm5 = xmm7[0,1,2,3,4,5,4,6]
por %xmm6, %xmm5
pxor %xmm15, %xmm5
packssdw %xmm5, %xmm5
pextrw $0x3, %xmm5, %esi
testb $0x1, %sil
je 0x7677c
movw %cx, 0x180(%r14,%rdx)
movdqa %xmm2, %xmm5
pxor %xmm14, %xmm5
movdqa %xmm5, %xmm7
pcmpgtd %xmm4, %xmm7
pshufd $0xa0, %xmm7, %xmm6     # xmm6 = xmm7[0,0,2,2]
pshuflw $0xe8, %xmm6, %xmm8     # xmm8 = xmm6[0,2,2,3,4,5,6,7]
pcmpeqd %xmm4, %xmm5
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pshuflw $0xe8, %xmm5, %xmm9     # xmm9 = xmm5[0,2,2,3,4,5,6,7]
pand %xmm8, %xmm9
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
pshuflw $0xe8, %xmm7, %xmm8     # xmm8 = xmm7[0,2,2,3,4,5,6,7]
por %xmm9, %xmm8
pxor %xmm15, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x4, %xmm8, %esi
testb $0x1, %sil
je 0x767db
movw %cx, 0x200(%r14,%rdx)
pand %xmm6, %xmm5
por %xmm7, %xmm5
packssdw %xmm5, %xmm5
pxor %xmm15, %xmm5
packssdw %xmm5, %xmm5
pextrw $0x5, %xmm5, %esi
testb $0x1, %sil
je 0x76804
movw %cx, 0x280(%r14,%rdx)
movdqa %xmm3, %xmm6
pxor %xmm14, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm4, %xmm7
pshufd $0xa0, %xmm7, %xmm5     # xmm5 = xmm7[0,0,2,2]
pcmpeqd %xmm4, %xmm6
pshufd $0xf5, %xmm6, %xmm4     # xmm4 = xmm6[1,1,3,3]
movdqa %xmm4, %xmm8
pand %xmm5, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm6, %xmm8
packssdw %xmm8, %xmm7
pxor %xmm15, %xmm7
packssdw %xmm7, %xmm7
pextrw $0x6, %xmm7, %esi
testb $0x1, %sil
je 0x76859
movw %cx, 0x300(%r14,%rdx)
pshufhw $0x84, %xmm5, %xmm5     # xmm5 = xmm5[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm4, %xmm4     # xmm4 = xmm4[0,1,2,3,4,5,4,6]
pand %xmm5, %xmm4
pshufhw $0x84, %xmm6, %xmm5     # xmm5 = xmm6[0,1,2,3,4,5,4,6]
por %xmm4, %xmm5
pxor %xmm15, %xmm5
packssdw %xmm5, %xmm4
pextrw $0x7, %xmm4, %esi
testb $0x1, %sil
je 0x7688d
movw %cx, 0x380(%r14,%rdx)
movdqa 0x33c8b(%rip), %xmm4    # 0xaa520
paddq %xmm4, %xmm0
paddq %xmm4, %xmm1
paddq %xmm4, %xmm2
paddq %xmm4, %xmm3
addq $0x400, %rdx            # imm = 0x400
cmpq %rdx, %rbx
jne 0x76661
addq %r13, %r15
incl %eax
addq %r13, %r14
cmpl %ebp, %eax
jb 0x7663e
movq 0x18(%rsp), %rdx
incq %rdx
movslq 0xc(%r9), %rax
cmpq %rax, %rdx
jl 0x765d6
movq 0x38(%rsp), %rcx
incq %rcx
addq $0x60, %r9
movq 0x30(%rsp), %rdi
movslq 0x4c(%rdi), %rax
cmpq %rax, %rcx
jl 0x761b4
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7690b