#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 sqrt(double);
float diminishing_returns(float val, float scale) {
  float mult, trinum;
  if (val < 0.0)
    return -diminishing_returns(-val, scale);
  mult = val / scale;
  trinum = (sqrt(8.0 * mult + 1.0) - 1.0) / 2.0;
  return trinum * scale;
}


x86 assembly (clang, -O0):
<diminishing_returns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    117b <diminishing_returns+0x5b>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  -0xc(%rbp),%xmm1
call   1030 <diminishing_returns@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11e0 <diminishing_returns+0xc0>
movss  -0x8(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe75(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe61(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  0xe50(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe3c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diminishing_returns>:
push   %rax
xorps  %xmm2,%xmm2
ucomiss %xmm0,%xmm2
jbe    113e <diminishing_returns+0x1e>
xorps  0xef0(%rip),%xmm0
call   1030 <diminishing_returns@plt>
xorps  0xee4(%rip),%xmm0
pop    %rax
ret
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xeb2(%rip),%xmm0
addsd  0xeb2(%rip),%xmm0
xorps  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     1165 <diminishing_returns+0x45>
sqrtsd %xmm0,%xmm0
jmp    1176 <diminishing_returns+0x56>
movss  %xmm1,0x4(%rsp)
call   1040 <sqrt@plt>
movss  0x4(%rsp),%xmm1
addsd  0xe92(%rip),%xmm0
mulsd  0xe92(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
mulss  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @diminishing_returns(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float %0, float* %4
store float %1, float* %5
%8 = load float, float* %4
%9 = fpext float %8 to double
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load float, float* %4
%13 = fneg float %12
%14 = load float, float* %5
%15 = call float @diminishing_returns(float %13, float %14)
%16 = fneg float %15
store float %16, float* %3
br label %31
17: ; preds = %2
%18 = load float, float* %4
%19 = load float, float* %5
%20 = fdiv float %18, %19
store float %20, float* %6
%21 = load float, float* %6
%22 = fpext float %21 to double
%23 = call double @llvm.fmuladd.f64(double 8.000000e+00, double %22, double 1.000000e+00)
%24 = call double @sqrt(double %23)
%25 = fsub double %24, 1.000000e+00
%26 = fdiv double %25, 2.000000e+00
%27 = fptrunc double %26 to float
store float %27, float* %7
%28 = load float, float* %7
%29 = load float, float* %5
%30 = fmul float %28, %29
store float %30, float* %3
br label %31
31: ; preds = %17, %11
%32 = load float, float* %3
ret float %32
}

LLVM IR (-O2):
define float @diminishing_returns(float %0, float %1) {
%3 = fcmp olt float %0, 0.000000e+00
br i1 %3, label %6, label %10
4: ; preds = %10, %6
%5 = phi float [ %9, %6 ], [ %18, %10 ]
ret float %5
6: ; preds = %2
%7 = fneg float %0
%8 = tail call float @diminishing_returns(float %7, float %1)
%9 = fneg float %8
br label %4
10: ; preds = %2
%11 = fdiv float %0, %1
%12 = fpext float %11 to double
%13 = tail call double @llvm.fmuladd.f64(double %12, double 8.000000e+00, double 1.000000e+00)
%14 = tail call double @sqrt(double %13)
%15 = fadd double %14, -1.000000e+00
%16 = fmul double %15, 5.000000e-01
%17 = fptrunc double %16 to float
%18 = fmul float %17, %1
br label %4
}