// File: tomfunkhouser[P]gaps/pkgs/jpeg/jquant1.c
// Function: quantize3_ord_dither
METHODDEF(void)
quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
		      JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, with ordered dithering */
{
  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  register int pixcode;
  register JSAMPROW input_ptr;
  register JSAMPROW output_ptr;
  JSAMPROW colorindex0 = cquantize->colorindex[0];
  JSAMPROW colorindex1 = cquantize->colorindex[1];
  JSAMPROW colorindex2 = cquantize->colorindex[2];
  int * dither0;		/* points to active row of dither matrix */
  int * dither1;
  int * dither2;
  int row_index, col_index;	/* current indexes into dither matrix */
  int row;
  JDIMENSION col;
  JDIMENSION width = cinfo->output_width;

  for (row = 0; row < num_rows; row++) {
    row_index = cquantize->row_index;
    input_ptr = input_buf[row];
    output_ptr = output_buf[row];
    dither0 = cquantize->odither[0][row_index];
    dither1 = cquantize->odither[1][row_index];
    dither2 = cquantize->odither[2][row_index];
    col_index = 0;

    for (col = width; col > 0; col--) {
      pixcode  = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
					dither0[col_index]]);
      pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
					dither1[col_index]]);
      pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
					dither2[col_index]]);
      *output_ptr++ = (JSAMPLE) pixcode;
      col_index = (col_index + 1) & ODITHER_MASK;
    }
    row_index = (row_index + 1) & ODITHER_MASK;
    cquantize->row_index = row_index;
  }
}

// Assembly:
pushq %rax
movq %rdi, (%rsp)
movq %rsi, -0x8(%rsp)
movq %rdx, -0x10(%rsp)
movl %ecx, -0x14(%rsp)
movq (%rsp), %rax
movq 0x270(%rax), %rax
movq %rax, -0x20(%rsp)
movq -0x20(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq %rax, -0x40(%rsp)
movq -0x20(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rsp)
movq -0x20(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rsp)
movq (%rsp), %rax
movl 0x88(%rax), %eax
movl %eax, -0x7c(%rsp)
movl $0x0, -0x74(%rsp)
movl -0x74(%rsp), %eax
cmpl -0x14(%rsp), %eax
jge 0xf4f93
movq -0x20(%rsp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x6c(%rsp)
movq -0x8(%rsp), %rax
movslq -0x74(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rsp)
movq -0x10(%rsp), %rax
movslq -0x74(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
movq -0x20(%rsp), %rax
movq 0x50(%rax), %rax
movslq -0x6c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rsp)
movq -0x20(%rsp), %rax
movq 0x58(%rax), %rax
movslq -0x6c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rsp)
movq -0x20(%rsp), %rax
movq 0x60(%rax), %rax
movslq -0x6c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rsp)
movl $0x0, -0x70(%rsp)
movl -0x7c(%rsp), %eax
movl %eax, -0x78(%rsp)
cmpl $0x0, -0x78(%rsp)
jbe 0xf4f69
movq -0x40(%rsp), %rax
movq -0x30(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rsp)
movzbl (%rcx), %ecx
movq -0x58(%rsp), %rdx
movslq -0x70(%rsp), %rsi
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x24(%rsp)
movq -0x48(%rsp), %rax
movq -0x30(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rsp)
movzbl (%rcx), %ecx
movq -0x60(%rsp), %rdx
movslq -0x70(%rsp), %rsi
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
addl -0x24(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x50(%rsp), %rax
movq -0x30(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rsp)
movzbl (%rcx), %ecx
movq -0x68(%rsp), %rdx
movslq -0x70(%rsp), %rsi
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
addl -0x24(%rsp), %eax
movl %eax, -0x24(%rsp)
movl -0x24(%rsp), %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rsp)
movb %cl, (%rax)
movl -0x70(%rsp), %eax
addl $0x1, %eax
andl $0xf, %eax
movl %eax, -0x70(%rsp)
movl -0x78(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x78(%rsp)
jmp 0xf4e8c
movl -0x6c(%rsp), %eax
addl $0x1, %eax
andl $0xf, %eax
movl %eax, -0x6c(%rsp)
movl -0x6c(%rsp), %ecx
movq -0x20(%rsp), %rax
movl %ecx, 0x4c(%rax)
movl -0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rsp)
jmp 0xf4dee
popq %rax
retq
nopw %cs:(%rax,%rax)