#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);
int /*<<< orphan*/ assert(int);
double draw_rate_fperf_iter(double p, double d0) {
  double fi, a, b, c, x, y, dy, newx;
  assert(d0 <= 1.0 && d0 >= 0);
  assert(p <= 1.0 && p >= 0);
  assert(!(d0 < 0.4999) && d0 < 0.5001);
  fi = (1 - d0) / (2 * d0);
  c = 4 * (p * p - p);
  b = 2;
  a = 4 * fi * fi - 1;
  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_iter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xor    %eax,%eax
movsd  0xec4(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
mov    %al,-0x51(%rbp)
jb     115c <draw_rate_fperf_iter+0x3c>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
movsd  0xe8d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
mov    %al,-0x52(%rbp)
jb     1193 <draw_rate_fperf_iter+0x73>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x52(%rbp)
mov    -0x52(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
movsd  0xe5e(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
mov    %al,-0x53(%rbp)
ja     11cb <draw_rate_fperf_iter+0xab>
movsd  0xe50(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
mov    %al,-0x53(%rbp)
mov    -0x53(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  0xe20(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
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  0xdef(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xde6(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdd1(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xd68(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
call   1030 <Abs@plt>
movsd  0xd2a(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1276 <draw_rate_fperf_iter+0x156>
movsd  -0x50(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_rate_fperf_iter>:
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  0xece(%rip),%xmm2
ucomisd %xmm1,%xmm2
setae  %al
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
movsd  %xmm0,0x10(%rsp)
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
movsd  0x10(%rsp),%xmm1
movsd  0xe9e(%rip),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
ucomisd 0xebd(%rip),%xmm1
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
movsd  0xe78(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
setbe  %al
movsd  0xe6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
movsd  0xe42(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
addsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm2,%xmm1
movsd  0xe2e(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe1c(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
addsd  %xmm2,%xmm2
movsd  %xmm2,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x18(%rsp),%xmm3
movapd %xmm3,%xmm1
movapd %xmm3,%xmm0
addsd  %xmm3,%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  %xmm3,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movsd  0x20(%rsp),%xmm0
mulsd  %xmm3,%xmm0
addsd  0xdcc(%rip),%xmm0
divsd  %xmm0,%xmm2
subsd  %xmm2,%xmm3
movsd  %xmm3,0x18(%rsp)
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
call   1030 <Abs@plt>
ucomisd 0xdb1(%rip),%xmm0
ja     1220 <draw_rate_fperf_iter+0x100>
movsd  0x18(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @draw_rate_fperf_iter(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
store double %0, double* %3
store double %1, double* %4
%13 = load double, double* %4
%14 = fcmp ole double %13, 1.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load double, double* %4
%17 = fcmp oge double %16, 0.000000e+00
br label %18
18: ; preds = %15, %2
%19 = phi i1 [ false, %2 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load double, double* %3
%23 = fcmp ole double %22, 1.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load double, double* %3
%26 = fcmp oge double %25, 0.000000e+00
br label %27
27: ; preds = %24, %18
%28 = phi i1 [ false, %18 ], [ %26, %24 ]
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load double, double* %4
%32 = fcmp olt double %31, 4.999000e-01
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load double, double* %4
%35 = fcmp olt double %34, 5.001000e-01
br label %36
36: ; preds = %33, %27
%37 = phi i1 [ false, %27 ], [ %35, %33 ]
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load double, double* %4
%41 = fsub double 1.000000e+00, %40
%42 = load double, double* %4
%43 = fmul double 2.000000e+00, %42
%44 = fdiv double %41, %43
store double %44, double* %5
%45 = load double, double* %3
%46 = load double, double* %3
%47 = load double, double* %3
%48 = fneg double %47
%49 = call double @llvm.fmuladd.f64(double %45, double %46, double %48)
%50 = fmul double 4.000000e+00, %49
store double %50, double* %8
store double 2.000000e+00, double* %7
%51 = load double, double* %5
%52 = fmul double 4.000000e+00, %51
%53 = load double, double* %5
%54 = call double @llvm.fmuladd.f64(double %52, double %53, double -1.000000e+00)
store double %54, double* %6
store double 0.000000e+00, double* %12
br label %55
55: ; preds = %76, %36
%56 = load double, double* %12
store double %56, double* %9
%57 = load double, double* %8
%58 = load double, double* %7
%59 = load double, double* %9
%60 = call double @llvm.fmuladd.f64(double %58, double %59, double %57)
%61 = load double, double* %6
%62 = load double, double* %9
%63 = fmul double %61, %62
%64 = load double, double* %9
%65 = call double @llvm.fmuladd.f64(double %63, double %64, double %60)
store double %65, double* %10
%66 = load double, double* %7
%67 = load double, double* %6
%68 = fmul double 2.000000e+00, %67
%69 = load double, double* %9
%70 = call double @llvm.fmuladd.f64(double %68, double %69, double %66)
store double %70, double* %11
%71 = load double, double* %9
%72 = load double, double* %10
%73 = load double, double* %11
%74 = fdiv double %72, %73
%75 = fsub double %71, %74
store double %75, double* %12
br label %76
76: ; preds = %55
%77 = load double, double* %12
%78 = load double, double* %9
%79 = fsub double %77, %78
%80 = call double @Abs(double %79)
%81 = fcmp ogt double %80, 0x3E7AD7F29ABCAF48
br i1 %81, label %55, label %82
82: ; preds = %76
%83 = load double, double* %12
ret double %83
}

LLVM IR (-O2):
define double @draw_rate_fperf_iter(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 uge double %1, 4.999000e-01
%14 = fcmp olt double %1, 5.001000e-01
%15 = and i1 %13, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = fsub double 1.000000e+00, %1
%19 = fmul double %1, 2.000000e+00
%20 = fdiv double %18, %19
%21 = fneg double %0
%22 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %21)
%23 = fmul double %22, 4.000000e+00
%24 = fmul double %20, 4.000000e+00
%25 = tail call double @llvm.fmuladd.f64(double %24, double %20, double -1.000000e+00)
%26 = fmul double %25, 2.000000e+00
br label %27
27: ; preds = %27, %2
%28 = phi double [ 0.000000e+00, %2 ], [ %34, %27 ]
%29 = tail call double @llvm.fmuladd.f64(double %28, double 2.000000e+00, double %23)
%30 = fmul double %25, %28
%31 = tail call double @llvm.fmuladd.f64(double %30, double %28, double %29)
%32 = tail call double @llvm.fmuladd.f64(double %26, double %28, double 2.000000e+00)
%33 = fdiv double %31, %32
%34 = fsub double %28, %33
%35 = fsub double %34, %28
%36 = tail call double @Abs(double %35)
%37 = fcmp ogt double %36, 0x3E7AD7F29ABCAF48
br i1 %37, label %27, label %38
38: ; preds = %27
ret double %34
}