#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 db2lin(double);
double kneecurve(double, double, double);
double lin2db(double);
double compcurve(double x, double k, double slope, double linearthreshold,
                 double linearthresholdknee, double threshold, double knee,
                 double kneedboffset) {
  if (x < linearthreshold)
    return x;
  if (knee <= 0.0)
    return db2lin(threshold + slope * (lin2db(x) - threshold));
  if (x < linearthresholdknee)
    return kneecurve(x, k, linearthreshold);
  return db2lin(kneedboffset + slope * (lin2db(x) - threshold - knee));
}


x86 assembly (clang, -O0):
<compcurve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  %xmm5,-0x38(%rbp)
movsd  %xmm6,-0x40(%rbp)
movsd  %xmm7,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1183 <compcurve+0x53>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1251 <compcurve+0x121>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     11d8 <compcurve+0xa8>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <lin2db@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <db2lin@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1251 <compcurve+0x121>
movsd  -0x10(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120a <compcurve+0xda>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
call   1040 <kneecurve@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1251 <compcurve+0x121>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <lin2db@plt>
movsd  -0x68(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm2
subsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <db2lin@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compcurve>:
sub    $0x28,%rsp
ucomisd %xmm0,%xmm3
jbe    113f <compcurve+0xf>
add    $0x28,%rsp
ret
xorpd  %xmm8,%xmm8
ucomisd %xmm6,%xmm8
jae    115e <compcurve+0x2e>
ucomisd %xmm0,%xmm4
jbe    118c <compcurve+0x5c>
movapd %xmm3,%xmm2
add    $0x28,%rsp
jmp    1040 <kneecurve@plt>
movsd  %xmm5,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1030 <lin2db@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
jmp    1050 <db2lin@plt>
movsd  %xmm5,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm7,0x20(%rsp)
movsd  %xmm6,0x18(%rsp)
call   1030 <lin2db@plt>
subsd  0x8(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
jmp    1050 <db2lin@plt>

LLVM IR (-O0):
define double @compcurve(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double %0, double* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store double %7, double* %17
%18 = load double, double* %10
%19 = load double, double* %13
%20 = fcmp olt double %18, %19
br i1 %20, label %21, label %23
21: ; preds = %8
%22 = load double, double* %10
store double %22, double* %9
br label %55
23: ; preds = %8
%24 = load double, double* %16
%25 = fcmp ole double %24, 0.000000e+00
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load double, double* %15
%28 = load double, double* %12
%29 = load double, double* %10
%30 = call double @lin2db(double %29)
%31 = load double, double* %15
%32 = fsub double %30, %31
%33 = call double @llvm.fmuladd.f64(double %28, double %32, double %27)
%34 = call double @db2lin(double %33)
store double %34, double* %9
br label %55
35: ; preds = %23
%36 = load double, double* %10
%37 = load double, double* %14
%38 = fcmp olt double %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load double, double* %10
%41 = load double, double* %11
%42 = load double, double* %13
%43 = call double @kneecurve(double %40, double %41, double %42)
store double %43, double* %9
br label %55
44: ; preds = %35
%45 = load double, double* %17
%46 = load double, double* %12
%47 = load double, double* %10
%48 = call double @lin2db(double %47)
%49 = load double, double* %15
%50 = fsub double %48, %49
%51 = load double, double* %16
%52 = fsub double %50, %51
%53 = call double @llvm.fmuladd.f64(double %46, double %52, double %45)
%54 = call double @db2lin(double %53)
store double %54, double* %9
br label %55
55: ; preds = %44, %39, %26, %21
%56 = load double, double* %9
ret double %56
}

LLVM IR (-O2):
define double @compcurve(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = fcmp olt double %0, %3
br i1 %9, label %27, label %10
10: ; preds = %8
%11 = fcmp ugt double %6, 0.000000e+00
br i1 %11, label %17, label %12
12: ; preds = %10
%13 = tail call double @lin2db(double %0)
%14 = fsub double %13, %5
%15 = tail call double @llvm.fmuladd.f64(double %2, double %14, double %5)
%16 = tail call double @db2lin(double %15)
br label %27
17: ; preds = %10
%18 = fcmp olt double %0, %4
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = tail call double @kneecurve(double %0, double %1, double %3)
br label %27
21: ; preds = %17
%22 = tail call double @lin2db(double %0)
%23 = fsub double %22, %5
%24 = fsub double %23, %6
%25 = tail call double @llvm.fmuladd.f64(double %2, double %24, double %7)
%26 = tail call double @db2lin(double %25)
br label %27
27: ; preds = %8, %21, %19, %12
%28 = phi double [ %16, %12 ], [ %20, %19 ], [ %26, %21 ], [ %0, %8 ]
ret double %28
}