// File: lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::convertToXYZ_gamma(float*, float const*, unsigned int, unsigned int, LodePNGInfo const*, unsigned int, lodepng::LodePNGICC const*)
static unsigned convertToXYZ_gamma(float* out, const float* in, unsigned w, unsigned h,
                                  const LodePNGInfo* info, unsigned use_icc, const LodePNGICC* icc) {
  size_t i, c, n;
  if(lodepng_mulofl((size_t)w, (size_t)h, &n)) return 92;
  for(i = 0; i < n * 4; i++) {
    out[i] = in[i];
  }
  if(use_icc) {
    for(i = 0; i < n; i++) {
      for(c = 0; c < 3; c++) {
        /* TODO: this is likely very slow */
        out[i * 4 + c] = iccForwardTRC(&icc->trc[c], in[i * 4 + c]);
      }
    }
  } else if(info->gama_defined && !info->srgb_defined) {
    /* nothing to do if gamma is 1 */
    if(info->gama_gamma != 100000) {
      float gamma = 100000.0f / info->gama_gamma;
      for(i = 0; i < n; i++) {
        for(c = 0; c < 3; c++) {
          float v = in[i * 4 + c];
          out[i * 4 + c] = (v <= 0) ? v : lodepng_powf(v, gamma);
        }
      }
    }
  } else {
    for(i = 0; i < n; i++) {
      for(c = 0; c < 3; c++) {
        /* sRGB gamma expand */
        float v = in[i * 4 + c];
        out[i * 4 + c] = (v < 0.04045f) ? (v / 12.92f) : lodepng_powf((v + 0.055f) / 1.055f, 2.4f);
      }
    }
  }
  return 0; /* no error */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %edi
movl -0x20(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdx
callq 0x1ef60
cmpl $0x0, %eax
je 0x1f5d6
movl $0x5c, -0x4(%rbp)
jmp 0x1f884
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x2, %rcx
cmpq %rcx, %rax
jae 0x1f617
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1f5de
cmpl $0x0, -0x2c(%rbp)
je 0x1f6a7
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x1f6a2
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x1f692
movq 0x10(%rbp), %rdi
addq $0x80, %rdi
imulq $0x38, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
callq 0x20c90
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1f63b
jmp 0x1f694
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1f629
jmp 0x1f87d
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc8(%rax)
je 0x1f7a7
movq -0x28(%rbp), %rax
cmpl $0x0, 0xf4(%rax)
jne 0x1f7a7
movq -0x28(%rbp), %rax
cmpl $0x186a0, 0xcc(%rax)    # imm = 0x186A0
je 0x1f7a2
movq -0x28(%rbp), %rax
movl 0xcc(%rax), %eax
cvtsi2ss %rax, %xmm1
movss 0x93304(%rip), %xmm0    # 0xb29f8
divss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x1f7a0
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x1f78d
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x50(%rbp), %xmm0
jb 0x1f751
movss -0x50(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
jmp 0x1f765
movss -0x50(%rbp), %xmm0
movss -0x4c(%rbp), %xmm1
callq 0x21170
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1f71b
jmp 0x1f78f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1f705
jmp 0x1f7a2
jmp 0x1f87b
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x1f879
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x1f866
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x54(%rbp)
movss 0x9320a(%rip), %xmm0    # 0xb29fc
ucomiss -0x54(%rbp), %xmm0
jbe 0x1f810
movss -0x54(%rbp), %xmm0
movss 0x93207(%rip), %xmm1    # 0xb2a0c
divss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0x1f83b
movss 0x931f0(%rip), %xmm0    # 0xb2a08
addss -0x54(%rbp), %xmm0
movss 0x931df(%rip), %xmm1    # 0xb2a04
divss %xmm1, %xmm0
movss 0x931cf(%rip), %xmm1    # 0xb2a00
callq 0x21170
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1f7c5
jmp 0x1f868
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1f7af
jmp 0x1f87b
jmp 0x1f87d
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)