// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rsi, 0x70(%rsp)
cmpl $0x0, 0x4c(%rdi)
jle 0x759b7
movl 0x140(%rdi), %eax
decl %eax
movl %eax, 0xc(%rsp)
movq 0x58(%rdi), %r14
movq 0x1c8(%rdi), %rax
movq %rax, 0x40(%rsp)
xorl %ecx, %ecx
movq %rdi, 0x48(%rsp)
movq 0x8(%rdi), %rax
movq 0x40(%rsp), %rbx
movq %rcx, 0x50(%rsp)
movq 0x70(%rbx,%rcx,8), %rsi
movl 0xc(%r14), %ecx
movl 0x10(%rbx), %edx
imull %ecx, %edx
movl $0x1, %r8d
callq *0x40(%rax)
movq %rax, 0x58(%rsp)
movl 0x10(%rbx), %ecx
cmpl 0xc(%rsp), %ecx
jae 0x7529e
movl 0xc(%r14), %r8d
jmp 0x752b3
movl 0xc(%r14), %esi
movl 0x20(%r14), %eax
xorl %edx, %edx
divl %esi
movl %edx, %r8d
testl %edx, %edx
cmovel %esi, %r8d
movl 0x1c(%r14), %eax
movslq 0x8(%r14), %rdi
movq %rax, 0x30(%rsp)
xorl %edx, %edx
divl %edi
movl %edi, %ebp
subl %edx, %ebp
testl %edx, %edx
cmovlel %edx, %ebp
testl %r8d, %r8d
movq %r14, 0x28(%rsp)
movdqa 0x2cfb3(%rip), %xmm1    # 0xa2290
jle 0x75629
movq %rdi, 0x18(%rsp)
movq %rbp, %rcx
movl %ecx, %eax
movq %rax, %rdx
shlq $0x7, %rdx
movq %rdx, 0x20(%rsp)
movl %r8d, 0x10(%rsp)
movl %r8d, %ebx
leal 0x7(%rbp), %r15d
decq %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm11    # xmm11 = xmm0[0,1,0,1]
movq 0x30(%rsp), %r12
shlq $0x7, %r12
shrl $0x3, %r15d
shlq $0xa, %r15
pxor %xmm1, %xmm11
xorl %r13d, %r13d
movdqa %xmm11, 0x60(%rsp)
movq 0x58(%rsp), %rax
movq (%rax,%r13,8), %r14
movq 0x48(%rsp), %rdi
movq 0x1e8(%rdi), %rax
movq 0x70(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
leal (,%r13,8), %r8d
movq 0x30(%rsp), %rcx
movl %ecx, (%rsp)
movq 0x28(%rsp), %rsi
movq %r14, %rcx
xorl %r9d, %r9d
callq *0x8(%rax)
testl %ebp, %ebp
jle 0x75606
leaq (%r14,%r12), %rdi
movq 0x20(%rsp), %rsi
callq 0x85d17
movdqa 0x60(%rsp), %xmm11
pcmpeqd %xmm10, %xmm10
movdqa 0x2cef1(%rip), %xmm9    # 0xa2290
leaq (%r14,%r12), %rax
addq $0x380, %rax            # imm = 0x380
movzwl -0x400(%rax), %ecx
xorl %edx, %edx
movdqa 0x2cec6(%rip), %xmm0    # 0xa2280
movdqa 0x3515e(%rip), %xmm1    # 0xaa520
movdqa 0x35146(%rip), %xmm2    # 0xaa510
movdqa 0x3512e(%rip), %xmm3    # 0xaa500
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 0x7542d
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 0x75457
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 0x754a9
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 0x754dc
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 0x75538
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 0x75560
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 0x755af
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 0x755de
movw %cx, (%rax,%rdx)
movdqa 0x34f4a(%rip), %xmm4    # 0xaa530
paddq %xmm4, %xmm0
paddq %xmm4, %xmm1
paddq %xmm4, %xmm2
paddq %xmm4, %xmm3
addq $0x400, %rdx            # imm = 0x400
cmpq %rdx, %r15
jne 0x753d2
incq %r13
cmpq %rbx, %r13
jne 0x75333
movq 0x40(%rsp), %rax
movl 0x10(%rax), %ecx
movq 0x28(%rsp), %r14
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %r8d
cmpl 0xc(%rsp), %ecx
jne 0x75999
movl %edi, %ecx
addl 0x30(%rsp), %ebp
movq %rbp, 0x60(%rsp)
movl %ebp, %eax
xorl %edx, %edx
divl %ecx
cmpl 0xc(%r14), %r8d
jge 0x75999
movl %eax, %r12d
movl 0x60(%rsp), %edx
shlq $0x7, %rdx
movq %rdx, 0x10(%rsp)
leaq -0x1(%rdi), %rbp
movslq %r8d, %rdx
leal 0x7(%rcx), %ebx
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa %xmm0, 0x30(%rsp)
movq %rdi, %r13
shlq $0x7, %r13
shrl $0x3, %ebx
shlq $0xa, %rbx
shlq $0x7, %rbp
movq %rdi, 0x18(%rsp)
movq 0x58(%rsp), %rcx
movq -0x8(%rcx,%rdx,8), %r15
movq %rdx, 0x20(%rsp)
movq (%rcx,%rdx,8), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x85d17
movq 0x18(%rsp), %rdi
pcmpeqd %xmm15, %xmm15
movdqa 0x2cbcb(%rip), %xmm14   # 0xa2290
cmpl 0x60(%rsp), %edi
movdqa 0x34e2e(%rip), %xmm10   # 0xaa500
movdqa 0x34e35(%rip), %xmm11   # 0xaa510
movdqa 0x34e3c(%rip), %xmm12   # 0xaa520
movdqa 0x2cb93(%rip), %xmm13   # 0xa2280
ja 0x7597f
xorl %r8d, %r8d
testl %edi, %edi
jle 0x7596d
movzwl (%r15,%rbp), %ecx
xorl %edx, %edx
movdqa %xmm13, %xmm0
movdqa %xmm12, %xmm1
movdqa %xmm11, %xmm2
movdqa %xmm10, %xmm3
movdqa 0x30(%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 0x7577e
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 0x757a9
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 0x75800
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 0x75834
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 0x75893
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 0x758bc
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 0x75911
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 0x75945
movw %cx, 0x380(%r14,%rdx)
movdqa 0x34be3(%rip), %xmm4    # 0xaa530
paddq %xmm4, %xmm0
paddq %xmm4, %xmm1
paddq %xmm4, %xmm2
paddq %xmm4, %xmm3
addq $0x400, %rdx            # imm = 0x400
cmpq %rdx, %rbx
jne 0x75719
addq %r13, %r15
incl %r8d
addq %r13, %r14
cmpl %r12d, %r8d
jb 0x756f6
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x28(%rsp), %r14
movslq 0xc(%r14), %rcx
cmpq %rcx, %rdx
jl 0x75692
movq 0x50(%rsp), %rcx
incq %rcx
addq $0x60, %r14
movq 0x48(%rsp), %rdi
movslq 0x4c(%rdi), %rax
cmpq %rax, %rcx
jl 0x75264
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x759c7