#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 */
double bias(double, double);
double gain(double x, double g) {
  if (x < 0.5)
    return bias(2.0 * x, 1.0 - g) / 2.0;
  else
    return 1.0 - bias(2.0 - 2.0 * x, 1.0 - g) / 2.0;
}


x86 assembly (clang, -O0):
<gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xed6(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    116a <gain+0x5a>
movsd  0xed3(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xebe(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
call   1030 <bias@plt>
movsd  0xeb4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b1 <gain+0xa1>
movsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe95(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe81(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
call   1030 <bias@plt>
movaps %xmm0,%xmm1
movsd  0xe74(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe60(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gain>:
push   %rax
movsd  0xee7(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    1142 <gain+0x32>
addsd  %xmm0,%xmm0
movsd  0xee5(%rip),%xmm2
subsd  %xmm1,%xmm2
movapd %xmm2,%xmm1
call   1030 <bias@plt>
mulsd  0xec0(%rip),%xmm0
pop    %rax
ret
addsd  %xmm0,%xmm0
movsd  0xeba(%rip),%xmm2
subsd  %xmm0,%xmm2
movsd  0xeb6(%rip),%xmm3
subsd  %xmm1,%xmm3
movapd %xmm2,%xmm0
movapd %xmm3,%xmm1
call   1030 <bias@plt>
mulsd  0xea5(%rip),%xmm0
addsd  0xe95(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @gain(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp olt double %6, 5.000000e-01
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load double, double* %4
%10 = fmul double 2.000000e+00, %9
%11 = load double, double* %5
%12 = fsub double 1.000000e+00, %11
%13 = call double @bias(double %10, double %12)
%14 = fdiv double %13, 2.000000e+00
store double %14, double* %3
br label %23
15: ; preds = %2
%16 = load double, double* %4
%17 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %16, double 2.000000e+00)
%18 = load double, double* %5
%19 = fsub double 1.000000e+00, %18
%20 = call double @bias(double %17, double %19)
%21 = fdiv double %20, 2.000000e+00
%22 = fsub double 1.000000e+00, %21
store double %22, double* %3
br label %23
23: ; preds = %15, %8
%24 = load double, double* %3
ret double %24
}

LLVM IR (-O2):
define double @gain(double %0, double %1) {
%3 = fcmp olt double %0, 5.000000e-01
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = fmul double %0, 2.000000e+00
%6 = fsub double 1.000000e+00, %1
%7 = tail call double @bias(double %5, double %6)
%8 = fmul double %7, 5.000000e-01
br label %15
9: ; preds = %2
%10 = tail call double @llvm.fmuladd.f64(double %0, double -2.000000e+00, double 2.000000e+00)
%11 = fsub double 1.000000e+00, %1
%12 = tail call double @bias(double %10, double %11)
%13 = fmul double %12, 5.000000e-01
%14 = fsub double 1.000000e+00, %13
br label %15
15: ; preds = %9, %4
%16 = phi double [ %8, %4 ], [ %14, %9 ]
ret double %16
}