#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 pow(float, int);
float Rec2020_EOTF(float value, int bitdepth) {
  float linear_out;
  if (value > 0) {
    float alpha, beta;
    if (bitdepth == 10) {
      alpha = 1.099;
      beta = 0.018;
    } else {
      alpha = 1.0993;
      beta = 0.0181;
    }
    if (value < beta) {
      linear_out = value / 4.5;
    } else {
      linear_out = pow((value + (alpha - 1)) / alpha, 1 / 0.45);
    }
  } else {
    linear_out = 0;
  }
  return linear_out;
}


x86 assembly (clang, -O0):
<Rec2020_EOTF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11dd <Rec2020_EOTF+0xcd>
cmpl   $0xa,-0x8(%rbp)
jne    115a <Rec2020_EOTF+0x4a>
movss  0xec9(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xeb8(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1174 <Rec2020_EOTF+0x64>
movss  0xea2(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xe91(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11aa <Rec2020_EOTF+0x9a>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe80(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    11d8 <Rec2020_EOTF+0xc8>
movss  -0x4(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  0xe54(%rip),%xmm2
subss  %xmm2,%xmm1
addss  %xmm1,%xmm0
divss  -0x10(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movss  %xmm0,-0xc(%rbp)
jmp    11e5 <Rec2020_EOTF+0xd5>
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Rec2020_EOTF>:
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    113c <Rec2020_EOTF+0x2c>
xor    %eax,%eax
cmp    $0xa,%edi
sete   %al
lea    0xee1(%rip),%rcx
movss  (%rcx,%rax,4),%xmm1
ucomiss %xmm0,%xmm1
jbe    1140 <Rec2020_EOTF+0x30>
divss  0xedb(%rip),%xmm0
movaps %xmm0,%xmm1
movaps %xmm1,%xmm0
ret
lea    0xeb9(%rip),%rcx
movss  (%rcx,%rax,4),%xmm2
movss  0xebc(%rip),%xmm1
addss  %xmm2,%xmm1
addss  %xmm0,%xmm1
divss  %xmm2,%xmm1
movaps %xmm1,%xmm0
mov    $0x2,%edi
jmp    1030 <pow@plt>

LLVM IR (-O0):
define float @Rec2020_EOTF(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float %0, float* %3
store i32 %1, i32* %4
%8 = load float, float* %3
%9 = fcmp ogt float %8, 0.000000e+00
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %10
store float 0x3FF1958100000000, float* %6
store float 0x3F926E9780000000, float* %7
br label %15
14: ; preds = %10
store float 0x3FF196BBA0000000, float* %6
store float 0x3F9288CE80000000, float* %7
br label %15
15: ; preds = %14, %13
%16 = load float, float* %3
%17 = load float, float* %7
%18 = fcmp olt float %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load float, float* %3
%21 = fpext float %20 to double
%22 = fdiv double %21, 4.500000e+00
%23 = fptrunc double %22 to float
store float %23, float* %5
br label %32
24: ; preds = %15
%25 = load float, float* %3
%26 = load float, float* %6
%27 = fsub float %26, 1.000000e+00
%28 = fadd float %25, %27
%29 = load float, float* %6
%30 = fdiv float %28, %29
%31 = call float @pow(float %30, i32 2)
store float %31, float* %5
br label %32
32: ; preds = %24, %19
br label %34
33: ; preds = %2
store float 0.000000e+00, float* %5
br label %34
34: ; preds = %33, %32
%35 = load float, float* %5
ret float %35
}

LLVM IR (-O2):
define float @Rec2020_EOTF(float %0, i32 %1) {
%3 = fcmp ogt float %0, 0.000000e+00
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = icmp eq i32 %1, 10
%6 = select i1 %5, float 0x3FF1958100000000, float 0x3FF196BBA0000000
%7 = select i1 %5, float 0x3F926E9780000000, float 0x3F9288CE80000000
%8 = fcmp ogt float %7, %0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = fdiv float %0, 4.500000e+00
br label %16
11: ; preds = %4
%12 = fadd float %6, -1.000000e+00
%13 = fadd float %12, %0
%14 = fdiv float %13, %6
%15 = tail call float @pow(float %14, i32 2)
br label %16
16: ; preds = %2, %9, %11
%17 = phi float [ %10, %9 ], [ %15, %11 ], [ 0.000000e+00, %2 ]
ret float %17
}