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


x86 assembly (clang, -O0):
<diminishing_returns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1187 <diminishing_returns+0x67>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <diminishing_returns@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <diminishing_returns+0xcc>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe65(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe61(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <sqrt@plt>
movss  0xe40(%rip),%xmm1
subss  %xmm1,%xmm0
movss  0xe30(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diminishing_returns>:
push   %rax
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jbe    1142 <diminishing_returns+0x22>
xorpd  0xeed(%rip),%xmm0
call   1030 <diminishing_returns@plt>
xorpd  0xee0(%rip),%xmm0
pop    %rax
ret
divsd  %xmm1,%xmm0
mulsd  0xeb2(%rip),%xmm0
addsd  0xeb2(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
xorpd  %xmm2,%xmm2
ucomiss %xmm2,%xmm0
jb     1169 <diminishing_returns+0x49>
sqrtss %xmm0,%xmm0
jmp    1178 <diminishing_returns+0x58>
movsd  %xmm1,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
addss  0xe90(%rip),%xmm0
mulss  0xe8c(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
pop    %rax
ret

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

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