// File: /workspace/github_cpp_makefile_star2_O1/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 $0x198, %rsp            # imm = 0x198
movq %r9, %r14
movl %r8d, %r12d
movl %ecx, %r13d
movq %rdx, 0x10(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
movl 0xac(%r9), %ebp
xorl %eax, %eax
cmpl $0x9, %ebp
setae %al
movl $0x10000, %ecx          # imm = 0x10000
movl $0x100, %r15d           # imm = 0x100
cmovaeq %rcx, %r15
leal 0x8(,%rax,8), %edx
leaq 0x170(%rsp), %rdi
movl $0x6, %esi
callq 0x536a
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%rsp)
movups %xmm0, 0x108(%rsp)
movups %xmm0, 0x140(%rsp)
xorl %ebx, %ebx
cmpl $0x0, 0x1cc(%r14)
movl $0x0, %esi
je 0x11e31
movl %r12d, 0x8(%rsp)
movl %ebp, %r12d
movl %r13d, %ebp
movq 0x1d8(%r14), %rsi
movl 0x1e0(%r14), %edx
leaq 0x48(%rsp), %rdi
callq 0x12165
testl %eax, %eax
je 0x11dd0
movl %eax, %r13d
xorl %ebx, %ebx
jmp 0x11ea4
movl 0x48(%rsp), %esi
testl %esi, %esi
je 0x11e00
cmpl $0x2, %esi
movl %ebp, %r13d
jne 0x11e0d
xorl %esi, %esi
cmpl $0x0, 0x9c(%rsp)
movl %r12d, %ebp
je 0x11e06
cmpl $0x0, 0x8c(%rsp)
movl 0x8(%rsp), %r12d
jne 0x11e1f
jmp 0x11e31
movl %ebp, %r13d
movl %r12d, %ebp
movl 0x8(%rsp), %r12d
jmp 0x11e31
cmpl $0x0, 0x8c(%rsp)
movl %r12d, %ebp
movl 0x8(%rsp), %r12d
je 0x11e2f
xorl %esi, %esi
cmpl $0x0, 0xc4(%rsp)
setne %sil
jmp 0x11e31
xorl %esi, %esi
xorl %eax, %eax
movl %ebp, 0x18(%rsp)
cmpl $0x9, %ebp
setae %al
movl %r13d, %ecx
movl %r12d, %edi
imulq %rcx, %rdi
leaq 0x4(,%rax,4), %rcx
movq %rdi, %rax
mulq %rcx
movl %r13d, %ebp
movl $0x5c, %r13d
cmovnol %ebx, %r13d
jo 0x11ea4
movq %rdi, 0x30(%rsp)
movl %esi, 0xc(%rsp)
leaq 0xa8(%r14), %r13
movq %rax, %rdi
callq 0x22a0
movq %rax, %rbx
leaq 0x170(%rsp), %rdx
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rcx
movl %ebp, %r8d
movl %r12d, %r9d
callq 0x5e9a
testl %eax, %eax
je 0x11ef3
movl %eax, %r13d
xorl %r12d, %r12d
movq 0xd0(%rsp), %rdi
callq 0x2290
movq 0x108(%rsp), %rdi
callq 0x2290
movq 0x140(%rsp), %rdi
callq 0x2290
movq %rbx, %rdi
callq 0x2290
movq %r12, %rdi
callq 0x2290
movl %r13d, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, 0x1c(%rsp)
movl %r12d, 0x8(%rsp)
addq $0xd0, %r14
cmpl $0x0, 0xc(%rsp)
movq %r14, 0x28(%rsp)
je 0x12008
cmpl $0x2, 0x48(%rsp)
jne 0x12008
cmpl $0x9, 0x18(%rsp)
movl $0xc0000, %eax          # imm = 0xC0000
movl $0xc00, %edi            # imm = 0xC00
cmovaeq %rax, %rdi
callq 0x22a0
movq %rax, %r12
leal (,%r15,8), %eax
movq %rax, 0x20(%rsp)
leal -0x1(%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x63e0b(%rip), %xmm1    # 0x75d64
divss %xmm0, %xmm1
leaq 0xc8(%rsp), %r13
xorl %r14d, %r14d
movss %xmm1, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %r14, %xmm0
mulss %xmm1, %xmm0
movq %r13, %rdi
callq 0x13ca9
movss 0x10(%rsp), %xmm1
movss %xmm0, (%r12,%r14,4)
incq %r14
cmpq %r14, %r15
jne 0x11f6e
leaq (%r12,%r15,4), %rbp
leaq 0x100(%rsp), %r13
xorl %r14d, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14, %xmm0
mulss %xmm1, %xmm0
movq %r13, %rdi
callq 0x13ca9
movss 0x10(%rsp), %xmm1
movss %xmm0, (%rbp,%r14,4)
incq %r14
cmpq %r14, %r15
jne 0x11fa5
movq %r12, %r14
addq 0x20(%rsp), %r14
xorl %r13d, %r13d
xorps %xmm0, %xmm0
cvtsi2ss %r13, %xmm0
mulss %xmm1, %xmm0
leaq 0x138(%rsp), %rdi
callq 0x13ca9
movss 0x10(%rsp), %xmm1
movss %xmm0, (%r14,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x11fd9
jmp 0x12038
leal (,%r15,4), %edi
callq 0x22a0
movq %rax, %r12
leaq 0x48(%rsp), %r9
movq %rax, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r14, %rcx
movl 0xc(%rsp), %r8d
callq 0x12950
movq %r12, %rbp
movq %r12, %r14
cmpl $0x8, 0x18(%rsp)
movl 0x1c(%rsp), %esi
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %r9
jbe 0x120da
testq %r9, %r9
movl 0xc(%rsp), %r8d
je 0x12141
leaq 0xc(%rdi), %rax
xorl %ecx, %ecx
movss 0x63cff(%rip), %xmm0    # 0x75d6c
movzwl (%rbx,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
movss (%r12,%rdx,4), %xmm1
movss %xmm1, -0xc(%rax)
movzwl 0x2(%rbx,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
movss (%rbp,%rdx,4), %xmm1
movss %xmm1, -0x8(%rax)
movzwl 0x4(%rbx,%rcx,8), %edx
rolw $0x8, %dx
movzwl %dx, %edx
movss (%r14,%rdx,4), %xmm1
movss %xmm1, -0x4(%rax)
movzwl 0x6(%rbx,%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, %r9
jne 0x1206d
jmp 0x12141
testq %r9, %r9
movl 0xc(%rsp), %r8d
je 0x12141
leaq 0xc(%rdi), %rax
xorl %ecx, %ecx
movss 0x63c76(%rip), %xmm0    # 0x75d68
movzbl (%rbx,%rcx,4), %edx
movss (%r12,%rdx,4), %xmm1
movss %xmm1, -0xc(%rax)
movzbl 0x1(%rbx,%rcx,4), %edx
movss (%rbp,%rdx,4), %xmm1
movss %xmm1, -0x8(%rax)
movzbl 0x2(%rbx,%rcx,4), %edx
movss (%r14,%rdx,4), %xmm1
movss %xmm1, -0x4(%rax)
movzbl 0x3(%rbx,%rcx,4), %edx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rax)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %r9
jne 0x120f2
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
leaq 0x48(%rsp), %r9
movl 0x8(%rsp), %edx
movq 0x28(%rsp), %rcx
callq 0x12ac5
movl %eax, %r13d
jmp 0x11ea7