// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::iccForwardTRC(lodepng::LodePNGICCCurve const*, float)
static float iccForwardTRC(const LodePNGICCCurve* curve, float x) {
  if(curve->type == 0) {
    return x;
  }
  if(curve->type == 1) { /* Lookup table */
    float v0, v1, fraction;
    size_t index;
    if(!curve->lut) return 0; /* error */
    if(x < 0) return x;
    index = (size_t)(x * (curve->lut_size - 1));
    if(index >= curve->lut_size) return x;

    /* LERP */
    v0 = curve->lut[index];
    v1 = (index + 1 < curve->lut_size) ? curve->lut[index + 1] : 1.0f;
    fraction = (x * (curve->lut_size - 1)) - index;
    return v0 * (1 - fraction) + v1 * fraction;
  }
  if(curve->type == 2) {
    /* Gamma expansion */
    return (x > 0) ? lodepng_powf(x, curve->gamma) : x;
  }
  /* TODO: all the ones below are untested */
  if(curve->type == 3) {
    if(x < 0) return x;
    return x >= (-curve->b / curve->a) ? (lodepng_powf(curve->a * x + curve->b, curve->gamma) + curve->c) : 0;
  }
  if(curve->type == 4) {
    if(x < 0) return x;
    return x >= (-curve->b / curve->a) ? (lodepng_powf(curve->a * x + curve->b, curve->gamma) + curve->c) : curve->c;
  }
  if(curve->type == 5) {
    return x >= curve->d ? (lodepng_powf(curve->a * x + curve->b, curve->gamma)) : (curve->c * x);
  }
  if(curve->type == 6) {
    return x >= curve->d ? (lodepng_powf(curve->a * x + curve->b, curve->gamma) + curve->c) : (curve->c * x + curve->f);
  }
  return 0;
}

// Assembly:
pushq %rbx
movl (%rdi), %eax
cmpq $0x6, %rax
ja 0x13a97
movq %rdi, %rbx
leaq 0x62410(%rip), %rcx     # 0x75e6c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x13a97
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x13b1e
movq 0x10(%rbx), %rcx
movq %rcx, %rdx
decq %rdx
js 0x13b7d
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
jmp 0x13b95
xorps %xmm2, %xmm2
jmp 0x13b78
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x13b1e
movss 0x1c(%rbx), %xmm2
movss 0x20(%rbx), %xmm1
movaps 0x5e598(%rip), %xmm3    # 0x72050
xorps %xmm1, %xmm3
divss %xmm2, %xmm3
ucomiss %xmm3, %xmm0
jae 0x13b5b
movss 0x24(%rbx), %xmm2
jmp 0x13b78
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x13b1e
jmp 0x13b3f
xorps %xmm2, %xmm2
ucomiss %xmm0, %xmm2
ja 0x13b1e
movss 0x1c(%rbx), %xmm3
movss 0x20(%rbx), %xmm1
movaps 0x5e55b(%rip), %xmm4    # 0x72050
xorps %xmm1, %xmm4
divss %xmm3, %xmm4
ucomiss %xmm4, %xmm0
jb 0x13b78
mulss %xmm0, %xmm3
addss %xmm1, %xmm3
movss 0x18(%rbx), %xmm1
movaps %xmm3, %xmm0
jmp 0x13b6b
ucomiss 0x28(%rbx), %xmm0
jae 0x13b35
mulss 0x24(%rbx), %xmm0
movaps %xmm0, %xmm2
jmp 0x13b78
ucomiss 0x28(%rbx), %xmm0
jae 0x13b4a
mulss 0x24(%rbx), %xmm0
addss 0x30(%rbx), %xmm0
jmp 0x13b7b
mulss 0x1c(%rbx), %xmm0
addss 0x20(%rbx), %xmm0
movss 0x18(%rbx), %xmm1
popq %rbx
jmp 0x13c26
mulss 0x1c(%rbx), %xmm0
addss 0x20(%rbx), %xmm0
movss 0x18(%rbx), %xmm1
jmp 0x13b6b
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss 0x18(%rbx), %xmm1
movaps %xmm2, %xmm0
callq 0x13c26
movaps %xmm0, %xmm2
addss 0x24(%rbx), %xmm2
movaps %xmm2, %xmm0
popq %rbx
retq
movq %rdx, %rsi
shrq %rsi
andl $0x1, %edx
orq %rsi, %rdx
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
addss %xmm1, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %rsi
movq %rsi, %rdi
sarq $0x3f, %rdi
movaps %xmm1, %xmm2
subss 0x6241c(%rip), %xmm2    # 0x75fcc
cvttss2si %xmm2, %rdx
andq %rdi, %rdx
orq %rsi, %rdx
movaps %xmm0, %xmm2
cmpq %rdx, %rcx
jbe 0x13b78
leaq 0x1(%rdx), %rsi
cmpq %rcx, %rsi
jae 0x13bd4
movss 0x4(%rax,%rdx,4), %xmm0
jmp 0x13bdc
movss 0x623b8(%rip), %xmm0    # 0x75f94
movss (%rax,%rdx,4), %xmm2
testq %rdx, %rdx
js 0x13bed
cvtsi2ss %rdx, %xmm3
jmp 0x13c02
movq %rdx, %rax
shrq %rax
andl $0x1, %edx
orq %rax, %rdx
cvtsi2ss %rdx, %xmm3
addss %xmm3, %xmm3
subss %xmm3, %xmm1
movss 0x62386(%rip), %xmm3    # 0x75f94
subss %xmm1, %xmm3
mulss %xmm3, %xmm2
mulss %xmm0, %xmm1
addss %xmm2, %xmm1
movaps %xmm1, %xmm0
jmp 0x13b7b