#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 Abs(double);
double sqrt(double);
double draw_rate_fperf(double p, double d0) {
  double fi, a, b, c, x, y, dy, newx;
  double ret = 0;
  if (d0 < 0.0001) {
    ret = 2 * d0 * sqrt(p - p * p) - d0 * d0;
    return ret;
  }
  fi = (1 - d0) / (2 * d0);
  c = 4 * (p * p - p);
  b = 2;
  a = 4 * fi * fi - 1;
  if (d0 < 1 - 0.0001 && (d0 > 0.5001 || d0 < 0.4999)) {
    ret = (sqrt(b * b - 4 * a * c) - b) / (2 * a);
    return ret;
  }
  newx = 0;
  do {
    x = newx;
    y = c + b * x + a * x * x;
    dy = b + 2 * a * x;
    newx = x - y / dy;
  } while (Abs(newx - x) > 0.0000001);
  return newx;
}


x86 assembly (clang, -O0):
<draw_rate_fperf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xebe(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11d7 <draw_rate_fperf+0xb7>
movsd  0xecb(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13c0 <draw_rate_fperf+0x2a0>
movsd  0xe49(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe34(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xde8(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xddf(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdca(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdac(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd93(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1314 <draw_rate_fperf+0x1f4>
movsd  -0x18(%rbp),%xmm0
movsd  0xda3(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     12aa <draw_rate_fperf+0x18a>
movsd  0xd99(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1314 <draw_rate_fperf+0x1f4>
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xd5c(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
subsd  -0x30(%rbp),%xmm0
movsd  0xd29(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13c0 <draw_rate_fperf+0x2a0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  0xcba(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
divsd  -0x50(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
call   1030 <Abs@plt>
movsd  0xc94(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     131c <draw_rate_fperf+0x1fc>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_rate_fperf>:
sub    $0x28,%rsp
movsd  0xed4(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    115d <draw_rate_fperf+0x3d>
movapd %xmm1,%xmm3
addsd  %xmm1,%xmm3
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     1267 <draw_rate_fperf+0x147>
sqrtsd %xmm0,%xmm0
jmp    1284 <draw_rate_fperf+0x164>
movsd  0xea3(%rip),%xmm4
subsd  %xmm1,%xmm4
movapd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm4
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
subsd  %xmm0,%xmm3
movsd  0xe87(%rip),%xmm0
movapd %xmm4,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm4,%xmm2
addsd  0xe7b(%rip),%xmm2
mulsd  %xmm0,%xmm3
movsd  0xe77(%rip),%xmm4
ucomisd %xmm1,%xmm4
jbe    11cf <draw_rate_fperf+0xaf>
ucomisd 0xe71(%rip),%xmm1
ja     1299 <draw_rate_fperf+0x179>
movsd  0xe6b(%rip),%xmm4
ucomisd %xmm1,%xmm4
ja     1299 <draw_rate_fperf+0x179>
movapd %xmm2,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm1,%xmm1
xorpd  %xmm4,%xmm4
movsd  %xmm2,0x8(%rsp)
movsd  %xmm3,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe08(%rip),%xmm0
divsd  %xmm0,%xmm2
subsd  %xmm2,%xmm4
movsd  %xmm4,0x10(%rsp)
subsd  %xmm1,%xmm4
movapd %xmm4,%xmm0
call   1030 <Abs@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x20(%rsp),%xmm3
ucomisd 0xde1(%rip),%xmm0
movapd %xmm4,%xmm1
ja     1200 <draw_rate_fperf+0xe0>
jmp    12e1 <draw_rate_fperf+0x1c1>
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm3
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm3
movapd %xmm3,%xmm0
add    $0x28,%rsp
ret
movapd %xmm2,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm3
subsd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12bc <draw_rate_fperf+0x19c>
xorps  %xmm4,%xmm4
sqrtsd %xmm0,%xmm4
jmp    12d1 <draw_rate_fperf+0x1b1>
movsd  %xmm2,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm0,%xmm4
addsd  0xd6f(%rip),%xmm4
addsd  %xmm2,%xmm2
divsd  %xmm2,%xmm4
movapd %xmm4,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @draw_rate_fperf(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
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %4
store double %1, double* %5
store double 0.000000e+00, double* %14
%15 = load double, double* %5
%16 = fcmp olt double %15, 1.000000e-04
br i1 %16, label %17, label %32
17: ; preds = %2
%18 = load double, double* %5
%19 = fmul double 2.000000e+00, %18
%20 = load double, double* %4
%21 = load double, double* %4
%22 = load double, double* %4
%23 = fneg double %21
%24 = call double @llvm.fmuladd.f64(double %23, double %22, double %20)
%25 = call double @sqrt(double %24)
%26 = load double, double* %5
%27 = load double, double* %5
%28 = fmul double %26, %27
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %19, double %25, double %29)
store double %30, double* %14
%31 = load double, double* %14
store double %31, double* %3
br label %102
32: ; preds = %2
%33 = load double, double* %5
%34 = fsub double 1.000000e+00, %33
%35 = load double, double* %5
%36 = fmul double 2.000000e+00, %35
%37 = fdiv double %34, %36
store double %37, double* %6
%38 = load double, double* %4
%39 = load double, double* %4
%40 = load double, double* %4
%41 = fneg double %40
%42 = call double @llvm.fmuladd.f64(double %38, double %39, double %41)
%43 = fmul double 4.000000e+00, %42
store double %43, double* %9
store double 2.000000e+00, double* %8
%44 = load double, double* %6
%45 = fmul double 4.000000e+00, %44
%46 = load double, double* %6
%47 = call double @llvm.fmuladd.f64(double %45, double %46, double -1.000000e+00)
store double %47, double* %7
%48 = load double, double* %5
%49 = fcmp olt double %48, 9.999000e-01
br i1 %49, label %50, label %72
50: ; preds = %32
%51 = load double, double* %5
%52 = fcmp ogt double %51, 5.001000e-01
br i1 %52, label %56, label %53
53: ; preds = %50
%54 = load double, double* %5
%55 = fcmp olt double %54, 4.999000e-01
br i1 %55, label %56, label %72
56: ; preds = %53, %50
%57 = load double, double* %8
%58 = load double, double* %8
%59 = load double, double* %7
%60 = fmul double 4.000000e+00, %59
%61 = load double, double* %9
%62 = fmul double %60, %61
%63 = fneg double %62
%64 = call double @llvm.fmuladd.f64(double %57, double %58, double %63)
%65 = call double @sqrt(double %64)
%66 = load double, double* %8
%67 = fsub double %65, %66
%68 = load double, double* %7
%69 = fmul double 2.000000e+00, %68
%70 = fdiv double %67, %69
store double %70, double* %14
%71 = load double, double* %14
store double %71, double* %3
br label %102
72: ; preds = %53, %32
store double 0.000000e+00, double* %13
br label %73
73: ; preds = %94, %72
%74 = load double, double* %13
store double %74, double* %10
%75 = load double, double* %9
%76 = load double, double* %8
%77 = load double, double* %10
%78 = call double @llvm.fmuladd.f64(double %76, double %77, double %75)
%79 = load double, double* %7
%80 = load double, double* %10
%81 = fmul double %79, %80
%82 = load double, double* %10
%83 = call double @llvm.fmuladd.f64(double %81, double %82, double %78)
store double %83, double* %11
%84 = load double, double* %8
%85 = load double, double* %7
%86 = fmul double 2.000000e+00, %85
%87 = load double, double* %10
%88 = call double @llvm.fmuladd.f64(double %86, double %87, double %84)
store double %88, double* %12
%89 = load double, double* %10
%90 = load double, double* %11
%91 = load double, double* %12
%92 = fdiv double %90, %91
%93 = fsub double %89, %92
store double %93, double* %13
br label %94
94: ; preds = %73
%95 = load double, double* %13
%96 = load double, double* %10
%97 = fsub double %95, %96
%98 = call double @Abs(double %97)
%99 = fcmp ogt double %98, 0x3E7AD7F29ABCAF48
br i1 %99, label %73, label %100
100: ; preds = %94
%101 = load double, double* %13
store double %101, double* %3
br label %102
102: ; preds = %100, %56, %17
%103 = load double, double* %3
ret double %103
}

LLVM IR (-O2):
define double @draw_rate_fperf(double %0, double %1) {
%3 = fcmp olt double %1, 1.000000e-04
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = fmul double %1, 2.000000e+00
%6 = fneg double %0
%7 = tail call double @llvm.fmuladd.f64(double %6, double %0, double %0)
%8 = tail call double @sqrt(double %7)
%9 = fneg double %1
%10 = fmul double %9, %1
%11 = tail call double @llvm.fmuladd.f64(double %5, double %8, double %10)
br label %47
12: ; preds = %2
%13 = fsub double 1.000000e+00, %1
%14 = fmul double %1, 2.000000e+00
%15 = fdiv double %13, %14
%16 = fneg double %0
%17 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %16)
%18 = fmul double %17, 4.000000e+00
%19 = fmul double %15, 4.000000e+00
%20 = tail call double @llvm.fmuladd.f64(double %19, double %15, double -1.000000e+00)
%21 = fcmp olt double %1, 9.999000e-01
br i1 %21, label %22, label %34
22: ; preds = %12
%23 = fcmp ogt double %1, 5.001000e-01
%24 = fcmp olt double %1, 4.999000e-01
%25 = or i1 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = fmul double %20, 4.000000e+00
%28 = fmul double %18, %27
%29 = fsub double 4.000000e+00, %28
%30 = tail call double @sqrt(double %29)
%31 = fadd double %30, -2.000000e+00
%32 = fmul double %20, 2.000000e+00
%33 = fdiv double %31, %32
br label %47
34: ; preds = %22, %12
%35 = fmul double %20, 2.000000e+00
br label %36
36: ; preds = %36, %34
%37 = phi double [ 0.000000e+00, %34 ], [ %43, %36 ]
%38 = tail call double @llvm.fmuladd.f64(double %37, double 2.000000e+00, double %18)
%39 = fmul double %20, %37
%40 = tail call double @llvm.fmuladd.f64(double %39, double %37, double %38)
%41 = tail call double @llvm.fmuladd.f64(double %35, double %37, double 2.000000e+00)
%42 = fdiv double %40, %41
%43 = fsub double %37, %42
%44 = fsub double %43, %37
%45 = tail call double @Abs(double %44)
%46 = fcmp ogt double %45, 0x3E7AD7F29ABCAF48
br i1 %46, label %36, label %47
47: ; preds = %36, %26, %4
%48 = phi double [ %11, %4 ], [ %33, %26 ], [ %43, %36 ]
ret double %48
}