// File: /workspace/github_cpp_makefile_star2_O1/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 0x13cf7
movq %rdi, %rbx
leaq 0x61f80(%rip), %rcx     # 0x75c3c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x13cf7
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x13d7e
movq 0x10(%rbx), %rcx
movq %rcx, %rdx
decq %rdx
js 0x13ddd
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
jmp 0x13df5
xorps %xmm2, %xmm2
jmp 0x13dd8
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x13d7e
movss 0x1c(%rbx), %xmm2
movss 0x20(%rbx), %xmm1
movaps 0x620f8(%rip), %xmm3    # 0x75e10
xorps %xmm1, %xmm3
divss %xmm2, %xmm3
ucomiss %xmm3, %xmm0
jae 0x13dbb
movss 0x24(%rbx), %xmm2
jmp 0x13dd8
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x13d7e
jmp 0x13d9f
xorps %xmm2, %xmm2
ucomiss %xmm0, %xmm2
ja 0x13d7e
movss 0x1c(%rbx), %xmm3
movss 0x20(%rbx), %xmm1
movaps 0x620bb(%rip), %xmm4    # 0x75e10
xorps %xmm1, %xmm4
divss %xmm3, %xmm4
ucomiss %xmm4, %xmm0
jb 0x13dd8
mulss %xmm0, %xmm3
addss %xmm1, %xmm3
movss 0x18(%rbx), %xmm1
movaps %xmm3, %xmm0
jmp 0x13dcb
ucomiss 0x28(%rbx), %xmm0
jae 0x13d95
mulss 0x24(%rbx), %xmm0
movaps %xmm0, %xmm2
jmp 0x13dd8
ucomiss 0x28(%rbx), %xmm0
jae 0x13daa
mulss 0x24(%rbx), %xmm0
addss 0x30(%rbx), %xmm0
jmp 0x13ddb
mulss 0x1c(%rbx), %xmm0
addss 0x20(%rbx), %xmm0
movss 0x18(%rbx), %xmm1
popq %rbx
jmp 0x13e86
mulss 0x1c(%rbx), %xmm0
addss 0x20(%rbx), %xmm0
movss 0x18(%rbx), %xmm1
jmp 0x13dcb
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss 0x18(%rbx), %xmm1
movaps %xmm2, %xmm0
callq 0x13e86
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 0x61f98(%rip), %xmm2    # 0x75da8
cvttss2si %xmm2, %rdx
andq %rdi, %rdx
orq %rsi, %rdx
movaps %xmm0, %xmm2
cmpq %rdx, %rcx
jbe 0x13dd8
leaq 0x1(%rdx), %rsi
cmpq %rcx, %rsi
jae 0x13e34
movss 0x4(%rax,%rdx,4), %xmm0
jmp 0x13e3c
movss 0x61f28(%rip), %xmm0    # 0x75d64
movss (%rax,%rdx,4), %xmm2
testq %rdx, %rdx
js 0x13e4d
cvtsi2ss %rdx, %xmm3
jmp 0x13e62
movq %rdx, %rax
shrq %rax
andl $0x1, %edx
orq %rax, %rdx
cvtsi2ss %rdx, %xmm3
addss %xmm3, %xmm3
subss %xmm3, %xmm1
movss 0x61ef6(%rip), %xmm3    # 0x75d64
subss %xmm1, %xmm3
mulss %xmm3, %xmm2
mulss %xmm0, %xmm1
addss %xmm2, %xmm1
movaps %xmm1, %xmm0
jmp 0x13ddb