// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::convertToXYZ(float*, float*, unsigned char const*, unsigned int, unsigned int, LodePNGState const*)
unsigned convertToXYZ(float* out, float whitepoint[3], const unsigned char* in,
                      unsigned w, unsigned h, const LodePNGState* state) {
  unsigned error = 0;
  size_t i, n, bytes;
  const LodePNGColorMode* mode_in = &state->info_raw;
  const LodePNGInfo* info = &state->info_png;
  unsigned char* data = 0;
  float* gammatable = 0;
  int bit16 = mode_in->bitdepth > 8;
  size_t num = bit16 ? 65536 : 256;
  LodePNGColorMode tempmode = lodepng_color_mode_make(LCT_RGBA, bit16 ? 16 : 8);

  unsigned use_icc = 0;
  LodePNGICC icc;
  lodepng_icc_init(&icc);
  if(info->iccp_defined) {
    error = parseICC(&icc, info->iccp_profile, info->iccp_profile_size);
    if(error) goto cleanup; /* corrupted ICC profile */
    use_icc = validateICC(&icc);
  }

  if(lodepng_mulofl((size_t)w, (size_t)h, &n)) error = 92;
  if(error) goto cleanup;
  if(lodepng_mulofl(n, bit16 ? 8 : 4, &bytes)) error = 92;
  if(error) goto cleanup;

  data = (unsigned char*)lodepng_malloc(bytes);
  error = lodepng_convert(data, in, &tempmode, mode_in, w, h);
  if(error) goto cleanup;

  /* Handle transfer function */
  {
    float* gammatable_r;
    float* gammatable_g;
    float* gammatable_b;

    /* RGB ICC, can have three different transfer functions */
    if(use_icc && icc.inputspace == 2) {
      gammatable = (float*)lodepng_malloc(num * 3 * sizeof(float));
      gammatable_r = &gammatable[num * 0];
      gammatable_g = &gammatable[num * 1];
      gammatable_b = &gammatable[num * 2];
      convertToXYZ_gamma_table(gammatable_r, num, 0, info, use_icc, &icc);
      convertToXYZ_gamma_table(gammatable_g, num, 1, info, use_icc, &icc);
      convertToXYZ_gamma_table(gammatable_b, num, 2, info, use_icc, &icc);
    } else {
      gammatable = (float*)lodepng_malloc(num * sizeof(float));
      gammatable_r = gammatable_g = gammatable_b = gammatable;
      convertToXYZ_gamma_table(gammatable, num, 0, info, use_icc, &icc);
    }

    if(bit16) {
      for(i = 0; i < n; i++) {
        out[i * 4 + 0] = gammatable_r[data[i * 8 + 0] * 256u + data[i * 8 + 1]];
        out[i * 4 + 1] = gammatable_g[data[i * 8 + 2] * 256u + data[i * 8 + 3]];
        out[i * 4 + 2] = gammatable_b[data[i * 8 + 4] * 256u + data[i * 8 + 5]];
        out[i * 4 + 3] = (data[i * 8 + 6] * 256 + data[i * 8 + 7]) * (1 / 65535.0f);
      }
    } else {
      for(i = 0; i < n; i++) {
        out[i * 4 + 0] = gammatable_r[data[i * 4 + 0]];
        out[i * 4 + 1] = gammatable_g[data[i * 4 + 1]];
        out[i * 4 + 2] = gammatable_b[data[i * 4 + 2]];
        out[i * 4 + 3] = data[i * 4 + 3] * (1 / 255.0f);
      }
    }
  }

  error = convertToXYZ_chrm(out, w, h, info, use_icc, &icc, whitepoint);
  if(error) goto cleanup;

cleanup:
  lodepng_icc_cleanup(&icc);
  lodepng_free(data);
  lodepng_free(gammatable);
  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %r9, %r15
movl %r8d, %r12d
movl %ecx, %ebx
movq %rdx, 0x20(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, %r13
movl 0xac(%r9), %r14d
xorl %eax, %eax
cmpl $0x9, %r14d
setae %al
movl $0x10000, %ecx          # imm = 0x10000
movl $0x100, %ebp            # imm = 0x100
cmovaeq %rcx, %rbp
leal 0x8(,%rax,8), %edx
leaq 0x180(%rsp), %rdi
movl $0x6, %esi
callq 0x5944
xorps %xmm0, %xmm0
movups %xmm0, 0xe0(%rsp)
movups %xmm0, 0x118(%rsp)
movups %xmm0, 0x150(%rsp)
cmpl $0x0, 0x1cc(%r15)
je 0x11a51
movl %ebx, 0x14(%rsp)
movl %r12d, %ebx
movq %r13, %r12
movl %r14d, %r13d
movq 0x1d8(%r15), %rsi
movl 0x1e0(%r15), %edx
leaq 0x58(%rsp), %rdi
callq 0x11e1d
testl %eax, %eax
je 0x11a55
movl %eax, %r14d
xorl %r12d, %r12d
jmp 0x11b4b
xorl %esi, %esi
jmp 0x11ace
movl 0x58(%rsp), %eax
testl %eax, %eax
je 0x11a8f
cmpl $0x2, %eax
movl %r13d, %r14d
jne 0x11aa4
xorl %esi, %esi
cmpl $0x0, 0xac(%rsp)
movl $0x2, 0x18(%rsp)
movq %r12, %r13
je 0x11a9b
cmpl $0x0, 0x9c(%rsp)
movl %ebx, %r12d
movl 0x14(%rsp), %ebx
jne 0x11ab8
jmp 0x11ace
movl %eax, 0x18(%rsp)
movl %eax, %esi
movl %r13d, %r14d
movq %r12, %r13
movl %ebx, %r12d
movl 0x14(%rsp), %ebx
jmp 0x11ace
cmpl $0x0, 0x9c(%rsp)
movq %r12, %r13
movl %ebx, %r12d
movl 0x14(%rsp), %ebx
je 0x11ac8
xorl %esi, %esi
cmpl $0x0, 0xd4(%rsp)
setne %sil
jmp 0x11aca
xorl %esi, %esi
movl %eax, 0x18(%rsp)
xorl %eax, %eax
cmpl $0x9, %r14d
setae %al
movl %ebx, %ecx
movl %r12d, %edi
imulq %rcx, %rdi
leaq 0x4(,%rax,4), %rcx
movq %rdi, %rax
mulq %rcx
jno 0x11afb
xorl %r12d, %r12d
movl $0x5c, %r14d
jmp 0x11b4b
movl %r14d, 0x28(%rsp)
movq %rdi, 0x48(%rsp)
movl %esi, 0x2c(%rsp)
movq %r13, 0x30(%rsp)
leaq 0xa8(%r15), %r14
movq %rax, %rdi
callq 0x22b0
movl %ebx, %r13d
movl %r12d, %ebx
movq %rax, %r12
leaq 0x180(%rsp), %rdx
movq %rax, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rcx
movl %r13d, %r8d
movl %ebx, %r9d
callq 0x642f
testl %eax, %eax
je 0x11b9a
movl %eax, %r14d
xorl %r15d, %r15d
movq 0xe0(%rsp), %rdi
callq 0x22a0
movq 0x118(%rsp), %rdi
callq 0x22a0
movq 0x150(%rsp), %rdi
callq 0x22a0
movq %r12, %rdi
callq 0x22a0
movq %r15, %rdi
callq 0x22a0
movl %r14d, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, 0x14(%rsp)
movl %ebx, 0x3c(%rsp)
addq $0xd0, %r15
movl 0x2c(%rsp), %r14d
testl %r14d, %r14d
sete %al
cmpl $0x2, 0x18(%rsp)
setne %cl
orb %al, %cl
movq %r15, 0x40(%rsp)
jne 0x11cb5
cmpl $0x9, 0x28(%rsp)
movl $0xc0000, %eax          # imm = 0xC0000
movl $0xc00, %edi            # imm = 0xC00
cmovaeq %rax, %rdi
callq 0x22b0
movq %rax, %r15
leal (,%rbp,8), %eax
movq %rax, 0x18(%rsp)
leal -0x1(%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x64391(%rip), %xmm1    # 0x75f94
divss %xmm0, %xmm1
leaq 0xd8(%rsp), %r14
xorl %ebx, %ebx
movss %xmm1, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
mulss %xmm1, %xmm0
movq %r14, %rdi
callq 0x13a49
movss 0x20(%rsp), %xmm1
movss %xmm0, (%r15,%rbx,4)
incq %rbx
cmpq %rbx, %rbp
jne 0x11c17
leaq (%r15,%rbp,4), %r13
leaq 0x110(%rsp), %r14
xorl %ebx, %ebx
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
mulss %xmm1, %xmm0
movq %r14, %rdi
callq 0x13a49
movss 0x20(%rsp), %xmm1
movss %xmm0, (%r13,%rbx,4)
incq %rbx
cmpq %rbx, %rbp
jne 0x11c4d
movq %r15, %rbx
addq 0x18(%rsp), %rbx
xorl %r14d, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14, %xmm0
mulss %xmm1, %xmm0
leaq 0x148(%rsp), %rdi
callq 0x13a49
movss 0x20(%rsp), %xmm1
movss %xmm0, (%rbx,%r14,4)
incq %r14
cmpq %r14, %rbp
jne 0x11c81
movl 0x2c(%rsp), %r14d
jmp 0x11ce5
movq %r15, %rbx
leal (,%rbp,4), %edi
callq 0x22b0
movq %rax, %r15
leaq 0x58(%rsp), %r9
movq %rax, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rbx, %rcx
movl %r14d, %r8d
callq 0x12666
movq %r15, %r13
movq %r15, %rbx
cmpl $0x8, 0x28(%rsp)
movq 0x48(%rsp), %rsi
jbe 0x11d82
testq %rsi, %rsi
je 0x11ded
movq 0x30(%rsp), %rax
addq $0xc, %rax
xorl %ecx, %ecx
movss 0x6428b(%rip), %xmm0    # 0x75f9c
movzwl (%r12,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
movss (%r15,%rdx,4), %xmm1
movss %xmm1, -0xc(%rax)
movzwl 0x2(%r12,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
movss (%r13,%rdx,4), %xmm1
movss %xmm1, -0x8(%rax)
movzwl 0x4(%r12,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
movss (%rbx,%rdx,4), %xmm1
movss %xmm1, -0x4(%rax)
movzwl 0x6(%r12,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rax)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %rsi
jne 0x11d11
jmp 0x11ded
testq %rsi, %rsi
je 0x11ded
movq 0x30(%rsp), %rax
addq $0xc, %rax
xorl %ecx, %ecx
movss 0x641fe(%rip), %xmm0    # 0x75f98
movzbl (%r12,%rcx,4), %edx
movss (%r15,%rdx,4), %xmm1
movss %xmm1, -0xc(%rax)
movzbl 0x1(%r12,%rcx,4), %edx
movss (%r13,%rdx,4), %xmm1
movss %xmm1, -0x8(%rax)
movzbl 0x2(%r12,%rcx,4), %edx
movss (%rbx,%rdx,4), %xmm1
movss %xmm1, -0x4(%rax)
movzbl 0x3(%r12,%rcx,4), %edx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rax)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %rsi
jne 0x11d9a
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
leaq 0x58(%rsp), %r9
movq 0x30(%rsp), %rdi
movl 0x14(%rsp), %esi
movl 0x3c(%rsp), %edx
movq 0x40(%rsp), %rcx
movl %r14d, %r8d
callq 0x1287e
movl %eax, %r14d
jmp 0x11b4e