#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
float saturate(float);
float X360LinearToGamma(float flLinearValue) {
  float fl360GammaValue;
  flLinearValue = saturate(flLinearValue);
  if (flLinearValue < (128.0f / 1023.0f)) {
    if (flLinearValue < (64.0f / 1023.0f)) {
      fl360GammaValue = flLinearValue * (1023.0f * (1.0f / 255.0f));
    } else {
      fl360GammaValue = flLinearValue * ((1023.0f / 2.0f) * (1.0f / 255.0f)) +
                        (32.0f / 255.0f);
    }
  } else {
    if (flLinearValue < (512.0f / 1023.0f)) {
      fl360GammaValue = flLinearValue * ((1023.0f / 4.0f) * (1.0f / 255.0f)) +
                        (64.0f / 255.0f);
    } else {
      fl360GammaValue = flLinearValue * ((1023.0f / 8.0f) * (1.0f / 255.0f)) +
                        (128.0f / 255.0f);
      fl360GammaValue = saturate(fl360GammaValue);
    }
  }
  fl360GammaValue = saturate(fl360GammaValue);
  return fl360GammaValue;
}


x86 assembly (clang, -O0):
<X360LinearToGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <saturate@plt>
movss  %xmm0,-0x4(%rbp)
movss  0xecc(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    118e <X360LinearToGamma+0x7e>
movss  0xed2(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    1167 <X360LinearToGamma+0x57>
movss  0xecc(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1189 <X360LinearToGamma+0x79>
movss  -0x4(%rbp),%xmm0
movss  0xea8(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xea0(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11fd <X360LinearToGamma+0xed>
movss  0xe6e(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    11c7 <X360LinearToGamma+0xb7>
movss  -0x4(%rbp),%xmm0
movss  0xe63(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe5b(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11f8 <X360LinearToGamma+0xe8>
movss  -0x4(%rbp),%xmm0
movss  0xe34(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe2c(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <saturate@plt>
movss  %xmm0,-0x8(%rbp)
jmp    11fd <X360LinearToGamma+0xed>
movss  -0x8(%rbp),%xmm0
call   1030 <saturate@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X360LinearToGamma>:
push   %rax
call   1030 <saturate@plt>
movss  0xee2(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    113e <X360LinearToGamma+0x2e>
movss  0xeed(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1161 <X360LinearToGamma+0x51>
mulss  0xeec(%rip),%xmm0
pop    %rax
jmp    1030 <saturate@plt>
movss  0xebe(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1177 <X360LinearToGamma+0x67>
mulss  0xebd(%rip),%xmm0
addss  0xeb9(%rip),%xmm0
pop    %rax
jmp    1030 <saturate@plt>
mulss  0xeb3(%rip),%xmm0
addss  0xeaf(%rip),%xmm0
pop    %rax
jmp    1030 <saturate@plt>
mulss  0xe89(%rip),%xmm0
addss  0xe85(%rip),%xmm0
call   1030 <saturate@plt>
pop    %rax
jmp    1030 <saturate@plt>

LLVM IR (-O0):
define float @X360LinearToGamma(float %0) {
%2 = alloca float
%3 = alloca float
store float %0, float* %2
%4 = load float, float* %2
%5 = call float @saturate(float %4)
store float %5, float* %2
%6 = load float, float* %2
%7 = fcmp olt float %6, 0x3FC0040100000000
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load float, float* %2
%10 = fcmp olt float %9, 0x3FB0040100000000
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load float, float* %2
%13 = fmul float %12, 0x40100C0C20000000
store float %13, float* %3
br label %17
14: ; preds = %8
%15 = load float, float* %2
%16 = call float @llvm.fmuladd.f32(float %15, float 0x40000C0C20000000, float 0x3FC0101020000000)
store float %16, float* %3
br label %17
17: ; preds = %14, %11
br label %30
18: ; preds = %1
%19 = load float, float* %2
%20 = fcmp olt float %19, 0x3FE0040100000000
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load float, float* %2
%23 = call float @llvm.fmuladd.f32(float %22, float 0x3FF00C0C20000000, float 0x3FD0101020000000)
store float %23, float* %3
br label %29
24: ; preds = %18
%25 = load float, float* %2
%26 = call float @llvm.fmuladd.f32(float %25, float 0x3FE00C0C20000000, float 0x3FE0101020000000)
store float %26, float* %3
%27 = load float, float* %3
%28 = call float @saturate(float %27)
store float %28, float* %3
br label %29
29: ; preds = %24, %21
br label %30
30: ; preds = %29, %17
%31 = load float, float* %3
%32 = call float @saturate(float %31)
store float %32, float* %3
%33 = load float, float* %3
ret float %33
}

LLVM IR (-O2):
define float @X360LinearToGamma(float %0) {
%2 = tail call float @saturate(float %0)
%3 = fcmp olt float %2, 0x3FC0040100000000
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = fcmp olt float %2, 0x3FB0040100000000
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = fmul float %2, 0x40100C0C20000000
br label %17
8: ; preds = %4
%9 = tail call float @llvm.fmuladd.f32(float %2, float 0x40000C0C20000000, float 0x3FC0101020000000)
br label %17
10: ; preds = %1
%11 = fcmp olt float %2, 0x3FE0040100000000
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call float @llvm.fmuladd.f32(float %2, float 0x3FF00C0C20000000, float 0x3FD0101020000000)
br label %17
14: ; preds = %10
%15 = tail call float @llvm.fmuladd.f32(float %2, float 0x3FE00C0C20000000, float 0x3FE0101020000000)
%16 = tail call float @saturate(float %15)
br label %17
17: ; preds = %12, %14, %6, %8
%18 = phi float [ %7, %6 ], [ %9, %8 ], [ %13, %12 ], [ %16, %14 ]
%19 = tail call float @saturate(float %18)
ret float %19
}