#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 floor(double);
double gain(double x, double p) {
  double i, px;
  i = 2.0 * floor(x + 0.5);
  px = 2.0 * x - i;
  return 0.5 * (px > 0.0 ? i + bias(px, p) : i - bias(-px, p));
}


x86 assembly (clang, -O0):
<gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xece(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
movaps %xmm0,%xmm1
movsd  0xeb1(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c7 <gain+0xa7>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <bias@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1208 <gain+0xe8>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <bias@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xdf3(%rip),%xmm0
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gain>:
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,%xmm1
movapd %xmm0,0x10(%rsp)
movsd  0xec4(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1040 <floor@plt>
addsd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  %xmm0,0x10(%rsp)
subsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jbe    1182 <gain+0x62>
movsd  0x8(%rsp),%xmm1
call   1030 <bias@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
jmp    119f <gain+0x7f>
xorpd  0xe86(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <bias@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mulsd  0xe55(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @gain(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %3
store double %1, double* %4
%7 = load double, double* %3
%8 = fadd double %7, 5.000000e-01
%9 = call double @llvm.floor.f64(double %8)
%10 = fmul double 2.000000e+00, %9
store double %10, double* %5
%11 = load double, double* %3
%12 = load double, double* %5
%13 = fneg double %12
%14 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %11, double %13)
store double %14, double* %6
%15 = load double, double* %6
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load double, double* %5
%19 = load double, double* %6
%20 = load double, double* %4
%21 = call double @bias(double %19, double %20)
%22 = fadd double %18, %21
br label %30
23: ; preds = %2
%24 = load double, double* %5
%25 = load double, double* %6
%26 = fneg double %25
%27 = load double, double* %4
%28 = call double @bias(double %26, double %27)
%29 = fsub double %24, %28
br label %30
30: ; preds = %23, %17
%31 = phi double [ %22, %17 ], [ %29, %23 ]
%32 = fmul double 5.000000e-01, %31
ret double %32
}

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