// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jccolor.c
// Function: jinit_color_converter
GLOBAL(void)
jinit_color_converter (j_compress_ptr cinfo)
{
  my_cconvert_ptr cconvert;

  cconvert = (my_cconvert_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_color_converter));
  cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  /* set start_pass to null method until we find out differently */
  cconvert->pub.start_pass = null_method;

  /* Make sure input_components agrees with in_color_space */
  switch (cinfo->in_color_space) {
  case JCS_GRAYSCALE:
    if (cinfo->input_components != 1)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;

  case JCS_RGB:
#if RGB_PIXELSIZE != 3
    if (cinfo->input_components != RGB_PIXELSIZE)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;
#endif /* else share code with YCbCr */

  case JCS_YCbCr:
    if (cinfo->input_components != 3)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;

  case JCS_CMYK:
  case JCS_YCCK:
    if (cinfo->input_components != 4)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;

  default:			/* JCS_UNKNOWN can be anything */
    if (cinfo->input_components < 1)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;
  }

  /* Check num_components, set conversion method based on requested space */
  switch (cinfo->jpeg_color_space) {
  case JCS_GRAYSCALE:
    if (cinfo->num_components != 1)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_GRAYSCALE)
      cconvert->pub.color_convert = grayscale_convert;
    else if (cinfo->in_color_space == JCS_RGB) {
      cconvert->pub.start_pass = rgb_ycc_start;
      cconvert->pub.color_convert = rgb_gray_convert;
    } else if (cinfo->in_color_space == JCS_YCbCr)
      cconvert->pub.color_convert = grayscale_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_RGB:
    if (cinfo->num_components != 3)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_YCbCr:
    if (cinfo->num_components != 3)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_RGB) {
      cconvert->pub.start_pass = rgb_ycc_start;
      cconvert->pub.color_convert = rgb_ycc_convert;
    } else if (cinfo->in_color_space == JCS_YCbCr)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_CMYK:
    if (cinfo->num_components != 4)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_CMYK)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_YCCK:
    if (cinfo->num_components != 4)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_CMYK) {
      cconvert->pub.start_pass = rgb_ycc_start;
      cconvert->pub.color_convert = cmyk_ycck_convert;
    } else if (cinfo->in_color_space == JCS_YCCK)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  default:			/* allow null conversion of JCS_UNKNOWN */
    if (cinfo->jpeg_color_space != cinfo->in_color_space ||
	cinfo->num_components != cinfo->input_components)
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    cconvert->pub.color_convert = null_convert;
    break;
  }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x8(%rdi), %rax
movl $0x18, %edx
movl $0x1, %esi
callq *(%rax)
movq %rax, %rbx
movq %rax, 0x1d8(%r14)
leaq 0x1cc(%rip), %rax       # 0x76c84
movq %rax, (%rbx)
movl 0x3c(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jb 0x76ad8
leal -0x4(%rax), %ecx
cmpl $0x2, %ecx
jae 0x76b4b
cmpl $0x4, 0x38(%r14)
jne 0x76adf
jmp 0x76aee
cmpl $0x3, 0x38(%r14)
je 0x76aee
movq (%r14), %rax
movl $0x9, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x50(%r14), %ecx
leal -0x1(%rcx), %eax
cmpl $0x4, %eax
ja 0x76c3f
leaq 0x33a2b(%rip), %rcx     # 0xaa530
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x4c(%r14)
je 0x76b24
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x3, %eax
je 0x76b3f
cmpl $0x2, %eax
je 0x76c71
cmpl $0x1, %eax
jne 0x76c29
leaq 0x13f(%rip), %rax       # 0x76c85
jmp 0x76c65
cmpl $0x1, %eax
jne 0x76bfc
cmpl $0x1, 0x38(%r14)
jne 0x76adf
jmp 0x76aee
cmpl $0x4, 0x4c(%r14)
je 0x76b73
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x5, %eax
je 0x76c5e
cmpl $0x4, %eax
jne 0x76c29
leaq 0x13e(%rip), %rax       # 0x76cce
movq %rax, (%rbx)
leaq 0x3a3(%rip), %rax       # 0x76f3d
jmp 0x76c65
cmpl $0x3, 0x4c(%r14)
je 0x76bb5
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x3, %eax
je 0x76c5e
cmpl $0x2, %eax
jne 0x76c29
leaq 0x100(%rip), %rax       # 0x76cce
movq %rax, (%rbx)
leaq 0x286(%rip), %rax       # 0x76e5e
jmp 0x76c65
cmpl $0x4, 0x4c(%r14)
je 0x76bf3
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
cmpl $0x4, 0x3c(%r14)
jne 0x76c29
jmp 0x76c5e
cmpl $0x0, 0x38(%r14)
jg 0x76aee
jmp 0x76adf
cmpl $0x3, 0x4c(%r14)
je 0x76c22
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
cmpl $0x2, 0x3c(%r14)
je 0x76c5e
movq (%r14), %rax
movl $0x1b, 0x28(%rax)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *(%rax)
cmpl 0x3c(%r14), %ecx
jne 0x76c4f
movl 0x4c(%r14), %eax
cmpl 0x38(%r14), %eax
je 0x76c5e
movq (%r14), %rax
movl $0x1b, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
leaq 0x197(%rip), %rax       # 0x76dfc
movq %rax, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x56(%rip), %rax        # 0x76cce
movq %rax, (%rbx)
leaq 0x103(%rip), %rax       # 0x76d85
jmp 0x76c65