// File: /workspace/github_cpp_makefile_star2_O2/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 0x1119c
movq %rdi, %rbx
leaq 0x4eaf8(%rip), %rcx     # 0x5fc5c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1119c
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x11223
movq 0x10(%rbx), %rcx
movq %rcx, %rdx
decq %rdx
js 0x11282
cvtsi2ss %rdx, %xmm1
jmp 0x11297
xorps %xmm2, %xmm2
jmp 0x1127d
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x11223
movss 0x1c(%rbx), %xmm2
movss 0x20(%rbx), %xmm1
movaps 0x4ec63(%rip), %xmm3    # 0x5fe20
xorps %xmm1, %xmm3
divss %xmm2, %xmm3
ucomiss %xmm3, %xmm0
jae 0x11260
movss 0x24(%rbx), %xmm2
jmp 0x1127d
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x11223
jmp 0x11244
xorps %xmm2, %xmm2
ucomiss %xmm0, %xmm2
ja 0x11223
movss 0x1c(%rbx), %xmm3
movss 0x20(%rbx), %xmm1
movaps 0x4ec26(%rip), %xmm4    # 0x5fe20
xorps %xmm1, %xmm4
divss %xmm3, %xmm4
ucomiss %xmm4, %xmm0
jb 0x1127d
mulss %xmm0, %xmm3
addss %xmm1, %xmm3
movss 0x18(%rbx), %xmm1
movaps %xmm3, %xmm0
jmp 0x11270
ucomiss 0x28(%rbx), %xmm0
jae 0x1123a
mulss 0x24(%rbx), %xmm0
movaps %xmm0, %xmm2
jmp 0x1127d
ucomiss 0x28(%rbx), %xmm0
jae 0x1124f
mulss 0x24(%rbx), %xmm0
addss 0x30(%rbx), %xmm0
jmp 0x11280
mulss 0x1c(%rbx), %xmm0
addss 0x20(%rbx), %xmm0
movss 0x18(%rbx), %xmm1
popq %rbx
jmp 0x11328
mulss 0x1c(%rbx), %xmm0
addss 0x20(%rbx), %xmm0
movss 0x18(%rbx), %xmm1
jmp 0x11270
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss 0x18(%rbx), %xmm1
movaps %xmm2, %xmm0
callq 0x11328
movaps %xmm0, %xmm2
addss 0x24(%rbx), %xmm2
movaps %xmm2, %xmm0
popq %rbx
retq
movq %rdx, %rsi
shrq %rsi
andl $0x1, %edx
orq %rsi, %rdx
cvtsi2ss %rdx, %xmm1
addss %xmm1, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %rsi
movq %rsi, %rdi
sarq $0x3f, %rdi
movaps %xmm1, %xmm2
subss 0x4eb16(%rip), %xmm2    # 0x5fdc8
cvttss2si %xmm2, %rdx
andq %rdi, %rdx
orq %rsi, %rdx
movaps %xmm0, %xmm2
cmpq %rdx, %rcx
jbe 0x1127d
leaq 0x1(%rdx), %rsi
cmpq %rcx, %rsi
jae 0x112d6
movss 0x4(%rax,%rdx,4), %xmm0
jmp 0x112de
movss 0x4eab2(%rip), %xmm0    # 0x5fd90
movss (%rax,%rdx,4), %xmm2
testq %rdx, %rdx
js 0x112ef
cvtsi2ss %rdx, %xmm3
jmp 0x11304
movq %rdx, %rax
shrq %rax
andl $0x1, %edx
orq %rax, %rdx
cvtsi2ss %rdx, %xmm3
addss %xmm3, %xmm3
subss %xmm3, %xmm1
movss 0x4ea80(%rip), %xmm3    # 0x5fd90
subss %xmm1, %xmm3
mulss %xmm3, %xmm2
mulss %xmm0, %xmm1
addss %xmm2, %xmm1
movaps %xmm1, %xmm0
jmp 0x11280