#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 */
int /*<<< orphan*/ assert(int);
int sqrt(int);
double draw_rate_fperf_calc(double p, double d0) {
  double a, c;
  double ret;
  assert(d0 <= 1.0 && d0 >= 0);
  assert(p <= 1.0 && p >= 0);
  assert(!(!(d0 < 0.4999) && d0 < 0.5001));
  c = 4 * (p * p - p);
  a = (1 - 2 * d0) / (d0 * d0);
  ret = (sqrt(1 - a * c) - 1) / a;
  return ret;
}


x86 assembly (clang, -O0):
<draw_rate_fperf_calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xor    %eax,%eax
movsd  0xec4(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
mov    %al,-0x29(%rbp)
jb     115c <draw_rate_fperf_calc+0x3c>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
movsd  0xe8d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
mov    %al,-0x2a(%rbp)
jb     1193 <draw_rate_fperf_calc+0x73>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
movsd  0xe5e(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
mov    %al,-0x2b(%rbp)
ja     11cb <draw_rate_fperf_calc+0xab>
movsd  0xe50(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
mov    %al,-0x2b(%rbp)
mov    -0x2b(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe08(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xdd6(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd92(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_rate_fperf_calc>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  0xece(%rip),%xmm2
ucomisd %xmm1,%xmm2
setae  %al
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
movsd  %xmm0,0x8(%rsp)
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
movsd  0xea4(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
ucomisd 0xeaf(%rip),%xmm1
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
movsd  0xe82(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
movsd  0xe75(%rip),%xmm0
ucomisd %xmm1,%xmm0
setbe  %cl
or     %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
subsd  %xmm1,%xmm0
mulsd  0xe52(%rip),%xmm0
movsd  0x10(%rsp),%xmm3
movapd %xmm3,%xmm1
addsd  %xmm3,%xmm1
movsd  0xe24(%rip),%xmm2
movapd %xmm2,%xmm4
subsd  %xmm1,%xmm4
mulsd  %xmm3,%xmm3
divsd  %xmm3,%xmm4
movsd  %xmm4,0x8(%rsp)
mulsd  %xmm4,%xmm0
addsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @draw_rate_fperf_calc(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store double %1, double* %4
%8 = load double, double* %4
%9 = fcmp ole double %8, 1.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load double, double* %4
%12 = fcmp oge double %11, 0.000000e+00
br label %13
13: ; preds = %10, %2
%14 = phi i1 [ false, %2 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load double, double* %3
%18 = fcmp ole double %17, 1.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load double, double* %3
%21 = fcmp oge double %20, 0.000000e+00
br label %22
22: ; preds = %19, %13
%23 = phi i1 [ false, %13 ], [ %21, %19 ]
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load double, double* %4
%27 = fcmp olt double %26, 4.999000e-01
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = load double, double* %4
%30 = fcmp olt double %29, 5.001000e-01
br label %31
31: ; preds = %28, %22
%32 = phi i1 [ false, %22 ], [ %30, %28 ]
%33 = xor i1 %32, true
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load double, double* %3
%37 = load double, double* %3
%38 = load double, double* %3
%39 = fneg double %38
%40 = call double @llvm.fmuladd.f64(double %36, double %37, double %39)
%41 = fmul double 4.000000e+00, %40
store double %41, double* %6
%42 = load double, double* %4
%43 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %42, double 1.000000e+00)
%44 = load double, double* %4
%45 = load double, double* %4
%46 = fmul double %44, %45
%47 = fdiv double %43, %46
store double %47, double* %5
%48 = load double, double* %5
%49 = load double, double* %6
%50 = fneg double %48
%51 = call double @llvm.fmuladd.f64(double %50, double %49, double 1.000000e+00)
%52 = fptosi double %51 to i32
%53 = call i32 @sqrt(i32 %52)
%54 = sub nsw i32 %53, 1
%55 = sitofp i32 %54 to double
%56 = load double, double* %5
%57 = fdiv double %55, %56
store double %57, double* %7
%58 = load double, double* %7
ret double %58
}

LLVM IR (-O2):
define double @draw_rate_fperf_calc(double %0, double %1) {
%3 = fcmp ole double %1, 1.000000e+00
%4 = fcmp oge double %1, 0.000000e+00
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = fcmp ole double %0, 1.000000e+00
%9 = fcmp oge double %0, 0.000000e+00
%10 = and i1 %8, %9
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = fcmp olt double %1, 4.999000e-01
%14 = fcmp uge double %1, 5.001000e-01
%15 = or i1 %13, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = fneg double %0
%19 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %18)
%20 = fmul double %19, 4.000000e+00
%21 = tail call double @llvm.fmuladd.f64(double %1, double -2.000000e+00, double 1.000000e+00)
%22 = fmul double %1, %1
%23 = fdiv double %21, %22
%24 = fneg double %23
%25 = tail call double @llvm.fmuladd.f64(double %24, double %20, double 1.000000e+00)
%26 = fptosi double %25 to i32
%27 = tail call i32 @sqrt(i32 %26)
%28 = add nsw i32 %27, -1
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, %23
ret double %30
}