#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 log(double);
int pow(int, float);
float gain(float a, float b) {
  float p = log(1. - b) / log(0.5);
  if (a < .001)
    return 0.;
  else if (a > .999)
    return 1.;
  if (a < 0.5)
    return pow(2 * a, p) / 2;
  else
    return 1. - pow(2 * (1. - a), p) / 2;
}


x86 assembly (clang, -O0):
<gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xecd(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1030 <log@plt>
movss  %xmm0,-0x14(%rbp)
movsd  0xeaf(%rip),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe80(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1197 <gain+0x77>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1265 <gain+0x145>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe70(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c4 <gain+0xa4>
movss  0xe72(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1265 <gain+0x145>
jmp    11c9 <gain+0xa9>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe2e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1215 <gain+0xf5>
movss  0xe3c(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
cvttss2si %xmm0,%edi
movss  -0x10(%rbp),%xmm0
call   1040 <pow@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1265 <gain+0x145>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdea(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xdee(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movss  -0x10(%rbp),%xmm0
call   1040 <pow@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
movsd  0xdb8(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gain>:
push   %rax
movss  %xmm0,0x4(%rsp)
cvtss2sd %xmm1,%xmm1
movsd  0xecd(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1030 <log@plt>
movss  %xmm0,(%rsp)
movsd  0xebf(%rip),%xmm0
call   1030 <log@plt>
movss  0x4(%rsp),%xmm4
movaps %xmm0,%xmm1
cvtss2sd %xmm4,%xmm2
xorps  %xmm0,%xmm0
movsd  0xeaa(%rip),%xmm3
ucomisd %xmm2,%xmm3
ja     11fe <gain+0xde>
ucomisd 0xea0(%rip),%xmm2
jbe    1184 <gain+0x64>
movss  0xe9e(%rip),%xmm0
pop    %rax
ret
movss  (%rsp),%xmm0
divss  %xmm1,%xmm0
movaps %xmm0,%xmm1
movss  0xe8c(%rip),%xmm0
ucomiss %xmm4,%xmm0
jbe    11bf <gain+0x9f>
addss  %xmm4,%xmm4
cvttss2si %xmm4,%edi
movaps %xmm1,%xmm0
call   1040 <pow@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
pop    %rax
ret
movsd  0xe39(%rip),%xmm0
subsd  %xmm2,%xmm0
addsd  %xmm0,%xmm0
cvttsd2si %xmm0,%edi
movaps %xmm1,%xmm0
call   1040 <pow@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xe0d(%rip),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @gain(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store float %0, float* %4
store float %1, float* %5
%7 = load float, float* %5
%8 = fpext float %7 to double
%9 = fsub double 1.000000e+00, %8
%10 = call float @log(double %9)
%11 = call float @log(double 5.000000e-01)
%12 = fdiv float %10, %11
store float %12, float* %6
%13 = load float, float* %4
%14 = fpext float %13 to double
%15 = fcmp olt double %14, 1.000000e-03
br i1 %15, label %16, label %17
16: ; preds = %2
store float 0.000000e+00, float* %3
br label %47
17: ; preds = %2
%18 = load float, float* %4
%19 = fpext float %18 to double
%20 = fcmp ogt double %19, 0x3FEFF7CED916872B
br i1 %20, label %21, label %22
21: ; preds = %17
store float 1.000000e+00, float* %3
br label %47
22: ; preds = %17
br label %23
23: ; preds = %22
%24 = load float, float* %4
%25 = fpext float %24 to double
%26 = fcmp olt double %25, 5.000000e-01
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load float, float* %4
%29 = fmul float 2.000000e+00, %28
%30 = fptosi float %29 to i32
%31 = load float, float* %6
%32 = call i32 @pow(i32 %30, float %31)
%33 = sdiv i32 %32, 2
%34 = sitofp i32 %33 to float
store float %34, float* %3
br label %47
35: ; preds = %23
%36 = load float, float* %4
%37 = fpext float %36 to double
%38 = fsub double 1.000000e+00, %37
%39 = fmul double 2.000000e+00, %38
%40 = fptosi double %39 to i32
%41 = load float, float* %6
%42 = call i32 @pow(i32 %40, float %41)
%43 = sdiv i32 %42, 2
%44 = sitofp i32 %43 to double
%45 = fsub double 1.000000e+00, %44
%46 = fptrunc double %45 to float
store float %46, float* %3
br label %47
47: ; preds = %35, %27, %21, %16
%48 = load float, float* %3
ret float %48
}

LLVM IR (-O2):
define float @gain(float %0, float %1) {
%3 = fpext float %1 to double
%4 = fsub double 1.000000e+00, %3
%5 = tail call float @log(double %4)
%6 = tail call float @log(double 5.000000e-01)
%7 = fdiv float %5, %6
%8 = fpext float %0 to double
%9 = fcmp olt double %8, 1.000000e-03
br i1 %9, label %29, label %10
10: ; preds = %2
%11 = fcmp ogt double %8, 0x3FEFF7CED916872B
br i1 %11, label %29, label %12
12: ; preds = %10
%13 = fcmp olt float %0, 5.000000e-01
br i1 %13, label %14, label %20
14: ; preds = %12
%15 = fmul float %0, 2.000000e+00
%16 = fptosi float %15 to i32
%17 = tail call i32 @pow(i32 %16, float %7)
%18 = sdiv i32 %17, 2
%19 = sitofp i32 %18 to float
br label %29
20: ; preds = %12
%21 = fsub double 1.000000e+00, %8
%22 = fmul double %21, 2.000000e+00
%23 = fptosi double %22 to i32
%24 = tail call i32 @pow(i32 %23, float %7)
%25 = sdiv i32 %24, 2
%26 = sitofp i32 %25 to double
%27 = fsub double 1.000000e+00, %26
%28 = fptrunc double %27 to float
br label %29
29: ; preds = %10, %2, %20, %14
%30 = phi float [ %19, %14 ], [ %28, %20 ], [ 0.000000e+00, %2 ], [ 1.000000e+00, %10 ]
ret float %30
}