#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 DistancePolar(double const, double const, double const);
int /*<<< orphan*/ assert(int);
double cos(double const);
double const sqrt(double);
double InvDistanceDr(const double r0, const double r1, const double dphi) {
  double cosdphi = cos(dphi);
  double d;
  if (r0 > r1) {
    double rd = r1 / r0;
    d = r0 * sqrt(1.0 + rd * (rd - 2 * cosdphi));
  } else {
    double rd = r0 / r1;
    d = r1 * sqrt(1.0 + rd * (rd - 2 * cosdphi));
  }
  assert(d == DistancePolar(r0, r1, dphi));
  return (r1 * cosdphi - r0) / (d * d * d);
}


x86 assembly (clang, -O0):
<InvDistanceDr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d1 <InvDistanceDr+0x91>
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
addsd  %xmm2,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4e(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1227 <InvDistanceDr+0xe7>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
addsd  %xmm2,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdf3(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1050 <DistancePolar@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InvDistanceDr>:
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x18(%rsp)
movapd %xmm2,%xmm0
call   1040 <cos@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
ucomisd %xmm1,%xmm3
jbe    117f <InvDistanceDr+0x3f>
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
movapd %xmm3,%xmm5
jmp    118b <InvDistanceDr+0x4b>
movapd %xmm3,%xmm4
divsd  %xmm1,%xmm4
movapd %xmm1,%xmm5
movsd  %xmm0,0x20(%rsp)
movapd %xmm0,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm4,%xmm0
subsd  %xmm2,%xmm0
mulsd  %xmm4,%xmm0
addsd  0xe53(%rip),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     11bd <InvDistanceDr+0x7d>
sqrtsd %xmm0,%xmm0
jmp    11d8 <InvDistanceDr+0x98>
movsd  %xmm5,(%rsp)
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm5
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
mulsd  %xmm5,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm3,%xmm0
movsd  0x18(%rsp),%xmm2
call   1050 <DistancePolar@plt>
cmpeqsd (%rsp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1030 <assert@plt>
movsd  0x20(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @InvDistanceDr(double %0, double %1, double %2) {
%4 = tail call double @cos(double %2)
%5 = fcmp ogt double %0, %1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = fdiv double %1, %0
br label %10
8: ; preds = %3
%9 = fdiv double %0, %1
br label %10
10: ; preds = %8, %6
%11 = phi double [ %9, %8 ], [ %7, %6 ]
%12 = phi double [ %1, %8 ], [ %0, %6 ]
%13 = tail call double @llvm.fmuladd.f64(double %4, double -2.000000e+00, double %11)
%14 = tail call double @llvm.fmuladd.f64(double %11, double %13, double 1.000000e+00)
%15 = tail call double @sqrt(double %14)
%16 = fmul double %15, %12
%17 = tail call double @DistancePolar(double %0, double %1, double %2)
%18 = fcmp oeq double %16, %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = fneg double %0
%22 = tail call double @llvm.fmuladd.f64(double %1, double %4, double %21)
%23 = fmul double %16, %16
%24 = fmul double %16, %23
%25 = fdiv double %22, %24
ret double %25
}