#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);
double calc_remaining_percent(double v, double load) {
  double x;
  if (load >= 0) {
    double t1, t2, t3, t3o;
    if (load > 0) {
      t1 = (-0.0009875627907627 * load * load) + (-0.0000333799157361 * load) +
           (-0.0001026050825665);
      t2 = 0.0736670600990142 * load + 0.0186826198807222;
      t3 = -6.8273790276026600 * load + 11.7603312904290000;
    } else {
      t1 = -0.0001264568764569;
      t2 = 0.0235093240093240;
      t3 = 11.4989510489510000;
    }
    t3o = t3 - v;
    double sqinner = (t2 * t2) - (4 * t1 * t3o);
    if (sqinner < 0.0) {
      return 100.0;
    }
    x = (-t2 + sqrt(sqinner)) / (2 * t1);
  } else {
  }
  return x;
}


x86 assembly (clang, -O0):
<calc_remaining_percent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12af <calc_remaining_percent+0x19f>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c7 <calc_remaining_percent+0xb7>
movsd  0xefa(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  0xee0(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xec3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe9d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe6b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe67(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11ee <calc_remaining_percent+0xde>
movsd  0xe41(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe2c(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe17(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xe41(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    125d <calc_remaining_percent+0x14d>
movsd  0xe0d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12be <calc_remaining_percent+0x1ae>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xdbc(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12b4 <calc_remaining_percent+0x1a4>
jmp    12b4 <calc_remaining_percent+0x1a4>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_remaining_percent>:
sub    $0x28,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jb     11ea <calc_remaining_percent+0xda>
jbe    1162 <calc_remaining_percent+0x52>
movsd  0xf0c(%rip),%xmm4
mulsd  %xmm1,%xmm4
movsd  0xf08(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm4
addsd  %xmm2,%xmm4
addsd  0xefc(%rip),%xmm4
unpcklpd %xmm1,%xmm1
mulpd  0xeb8(%rip),%xmm1
addpd  0xec0(%rip),%xmm1
jmp    1172 <calc_remaining_percent+0x62>
movapd 0xe96(%rip),%xmm1
movsd  0xebe(%rip),%xmm4
movapd %xmm1,%xmm3
unpckhpd %xmm1,%xmm3
subsd  %xmm0,%xmm3
movsd  0xeca(%rip),%xmm2
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jbe    11ae <calc_remaining_percent+0x9e>
movsd  0xeac(%rip),%xmm2
jmp    11ea <calc_remaining_percent+0xda>
ucomisd %xmm2,%xmm0
jb     11bd <calc_remaining_percent+0xad>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    11de <calc_remaining_percent+0xce>
movapd %xmm1,0x10(%rsp)
movsd  %xmm4,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm4
movapd 0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
addsd  %xmm4,%xmm4
divsd  %xmm4,%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @calc_remaining_percent(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store double %1, double* %5
%12 = load double, double* %5
%13 = fcmp oge double %12, 0.000000e+00
br i1 %13, label %14, label %54
14: ; preds = %2
%15 = load double, double* %5
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load double, double* %5
%19 = fmul double 0xBF502E2378E68F74, %18
%20 = load double, double* %5
%21 = load double, double* %5
%22 = fmul double 0xBF01802D2BE36117, %21
%23 = call double @llvm.fmuladd.f64(double %19, double %20, double %22)
%24 = fadd double %23, 0xBF1AE5B5E56733BC
store double %24, double* %7
%25 = load double, double* %5
%26 = call double @llvm.fmuladd.f64(double 0x3FB2DBD82DEAF085, double %25, double 0x3F9321896590B148)
store double %26, double* %8
%27 = load double, double* %5
%28 = call double @llvm.fmuladd.f64(double 0xC01B4F3C72A3CC80, double %27, double 0x4027854A2495093C)
store double %28, double* %9
br label %30
29: ; preds = %14
store double 0xBF2093304C27376A, double* %7
store double 0x3F9812D407159EF5, double* %8
store double 0x4026FF76830B1950, double* %9
br label %30
30: ; preds = %29, %17
%31 = load double, double* %9
%32 = load double, double* %4
%33 = fsub double %31, %32
store double %33, double* %10
%34 = load double, double* %8
%35 = load double, double* %8
%36 = load double, double* %7
%37 = fmul double 4.000000e+00, %36
%38 = load double, double* %10
%39 = fmul double %37, %38
%40 = fneg double %39
%41 = call double @llvm.fmuladd.f64(double %34, double %35, double %40)
store double %41, double* %11
%42 = load double, double* %11
%43 = fcmp olt double %42, 0.000000e+00
br i1 %43, label %44, label %45
44: ; preds = %30
store double 1.000000e+02, double* %3
br label %57
45: ; preds = %30
%46 = load double, double* %8
%47 = fneg double %46
%48 = load double, double* %11
%49 = call double @sqrt(double %48)
%50 = fadd double %47, %49
%51 = load double, double* %7
%52 = fmul double 2.000000e+00, %51
%53 = fdiv double %50, %52
store double %53, double* %6
br label %55
54: ; preds = %2
br label %55
55: ; preds = %54, %45
%56 = load double, double* %6
store double %56, double* %3
br label %57
57: ; preds = %55, %44
%58 = load double, double* %3
ret double %58
}

LLVM IR (-O2):
define double @calc_remaining_percent(double %0, double %1) {
%3 = fcmp ult double %1, 0.000000e+00
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = fcmp ogt double %1, 0.000000e+00
br i1 %5, label %6, label %14
6: ; preds = %4
%7 = fmul double %1, 0xBF502E2378E68F74
%8 = fmul double %1, 0xBF01802D2BE36117
%9 = tail call double @llvm.fmuladd.f64(double %7, double %1, double %8)
%10 = fadd double %9, 0xBF1AE5B5E56733BC
%11 = insertelement <2 x double> poison, double %1, i64 0
%12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
%13 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> <double 0x3FB2DBD82DEAF085, double 0xC01B4F3C72A3CC80>, <2 x double> <double 0x3F9321896590B148, double 0x4027854A2495093C>)
br label %14
14: ; preds = %4, %6
%15 = phi double [ %10, %6 ], [ 0xBF2093304C27376A, %4 ]
%16 = phi <2 x double> [ %13, %6 ], [ <double 0x3F9812D407159EF5, double 0x4026FF76830B1950>, %4 ]
%17 = extractelement <2 x double> %16, i64 1
%18 = fsub double %17, %0
%19 = fmul double %15, -4.000000e+00
%20 = fmul double %19, %18
%21 = extractelement <2 x double> %16, i64 0
%22 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %20)
%23 = fcmp olt double %22, 0.000000e+00
br i1 %23, label %29, label %24
24: ; preds = %14
%25 = tail call double @sqrt(double %22)
%26 = fsub double %25, %21
%27 = fmul double %15, 2.000000e+00
%28 = fdiv double %26, %27
br label %29
29: ; preds = %14, %2, %24
%30 = phi double [ %28, %24 ], [ undef, %2 ], [ 1.000000e+02, %14 ]
ret double %30
}