// File: /workspace/github_cpp_makefile_star2_O3/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       # 0x75d44
movq %rax, (%rbx)
movl 0x3c(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jb 0x75b98
leal -0x4(%rax), %ecx
cmpl $0x2, %ecx
jae 0x75c0b
cmpl $0x4, 0x38(%r14)
jne 0x75b9f
jmp 0x75bae
cmpl $0x3, 0x38(%r14)
je 0x75bae
movq (%r14), %rax
movl $0x9, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x50(%r14), %ecx
leal -0x1(%rcx), %eax
cmpl $0x4, %eax
ja 0x75cff
leaq 0x3497b(%rip), %rcx     # 0xaa540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x4c(%r14)
je 0x75be4
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x3, %eax
je 0x75bff
cmpl $0x2, %eax
je 0x75d31
cmpl $0x1, %eax
jne 0x75ce9
leaq 0x13f(%rip), %rax       # 0x75d45
jmp 0x75d25
cmpl $0x1, %eax
jne 0x75cbc
cmpl $0x1, 0x38(%r14)
jne 0x75b9f
jmp 0x75bae
cmpl $0x4, 0x4c(%r14)
je 0x75c33
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x5, %eax
je 0x75d1e
cmpl $0x4, %eax
jne 0x75ce9
leaq 0x13e(%rip), %rax       # 0x75d8e
movq %rax, (%rbx)
leaq 0x3a9(%rip), %rax       # 0x76003
jmp 0x75d25
cmpl $0x3, 0x4c(%r14)
je 0x75c75
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x3, %eax
je 0x75d1e
cmpl $0x2, %eax
jne 0x75ce9
leaq 0x100(%rip), %rax       # 0x75d8e
movq %rax, (%rbx)
leaq 0x28c(%rip), %rax       # 0x75f24
jmp 0x75d25
cmpl $0x4, 0x4c(%r14)
je 0x75cb3
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
cmpl $0x4, 0x3c(%r14)
jne 0x75ce9
jmp 0x75d1e
cmpl $0x0, 0x38(%r14)
jg 0x75bae
jmp 0x75b9f
cmpl $0x3, 0x4c(%r14)
je 0x75ce2
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
cmpl $0x2, 0x3c(%r14)
je 0x75d1e
movq (%r14), %rax
movl $0x1b, 0x28(%rax)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *(%rax)
cmpl 0x3c(%r14), %ecx
jne 0x75d0f
movl 0x4c(%r14), %eax
cmpl 0x38(%r14), %eax
je 0x75d1e
movq (%r14), %rax
movl $0x1b, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
leaq 0x197(%rip), %rax       # 0x75ebc
movq %rax, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x56(%rip), %rax        # 0x75d8e
movq %rax, (%rbx)
leaq 0x103(%rip), %rax       # 0x75e45
jmp 0x75d25