// File: lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::convertFromXYZ_gamma(float*, unsigned int, unsigned int, LodePNGInfo const*, unsigned int, lodepng::LodePNGICC const*)
static unsigned convertFromXYZ_gamma(float* im, 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;
  if(use_icc) {
    for(i = 0; i < n; i++) {
      for(c = 0; c < 3; c++) {
        /* TODO: this is likely very slow */
        im[i * 4 + c] = iccBackwardTRC(&icc->trc[c], im[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 = info->gama_gamma / 100000.0f;
      for(i = 0; i < n; i++) {
        for(c = 0; c < 3; c++) {
          if(im[i * 4 + c] > 0) im[i * 4 + c] = lodepng_powf(im[i * 4 + c], gamma);
        }
      }
    }
  } else {
    for(i = 0; i < n; i++) {
      for(c = 0; c < 3; c++) {
        /* sRGB gamma compress */
        float* v = &im[i * 4 + c];
        *v = (*v < 0.0031308f) ? (*v * 12.92f) : (1.055f * lodepng_powf(*v, 1 / 2.4f) - 0.055f);
      }
    }
  }
  return 0; /* no error */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %edi
movl -0x18(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdx
callq 0x1ef60
cmpl $0x0, %eax
je 0x200f2
movl $0x5c, -0x4(%rbp)
jmp 0x20352
cmpl $0x0, -0x24(%rbp)
je 0x20182
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x2017d
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x2016d
movq -0x30(%rbp), %rdi
addq $0x80, %rdi
imulq $0x38, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
callq 0x22be0
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 0x20116
jmp 0x2016f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x20104
jmp 0x2034b
movq -0x20(%rbp), %rax
cmpl $0x0, 0xc8(%rax)
je 0x20278
movq -0x20(%rbp), %rax
cmpl $0x0, 0xf4(%rax)
jne 0x20278
movq -0x20(%rbp), %rax
cmpl $0x186a0, 0xcc(%rax)    # imm = 0x186A0
je 0x20273
movq -0x20(%rbp), %rax
movl 0xcc(%rax), %eax
cvtsi2ss %rax, %xmm0
movss 0x92829(%rip), %xmm1    # 0xb29f8
divss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x20271
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x2025e
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x2024e
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss -0x4c(%rbp), %xmm1
callq 0x21170
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x20250
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x201f6
jmp 0x20260
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x201e0
jmp 0x20273
jmp 0x20349
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x20347
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x20334
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq -0x40(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movss 0x92754(%rip), %xmm0    # 0xb2a1c
ucomiss (%rax), %xmm0
jbe 0x202e4
movq -0x58(%rbp), %rax
movss 0x92733(%rip), %xmm0    # 0xb2a0c
mulss (%rax), %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0x20316
movq -0x58(%rbp), %rax
movss (%rax), %xmm0
movss 0x92730(%rip), %xmm1    # 0xb2a24
callq 0x21170
movss 0x92703(%rip), %xmm1    # 0xb2a04
mulss %xmm1, %xmm0
movss 0x92713(%rip), %xmm1    # 0xb2a20
addss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x20296
jmp 0x20336
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x20280
jmp 0x20349
jmp 0x2034b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)