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


x86 assembly (clang, -O0):
<DistancePolar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11be <DistancePolar+0x9e>
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
shl    $0x1,%eax
cvtsi2sd %eax,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe61(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1230 <DistancePolar+0x110>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
shl    $0x1,%eax
cvtsi2sd %eax,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdea(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DistancePolar>:
sub    $0x18,%rsp
ucomisd %xmm1,%xmm0
jbe    113c <DistancePolar+0x1c>
movsd  %xmm0,0x10(%rsp)
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    114c <DistancePolar+0x2c>
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movaps %xmm2,%xmm0
call   1030 <cos@plt>
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  0xe89(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1187 <DistancePolar+0x67>
sqrtsd %xmm0,%xmm0
jmp    118c <DistancePolar+0x6c>
call   1040 <sqrt@plt>
mulsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @DistancePolar(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%10 = load double, double* %5
%11 = load double, double* %6
%12 = fcmp ogt double %10, %11
br i1 %12, label %13, label %28
13: ; preds = %3
%14 = load double, double* %6
%15 = load double, double* %5
%16 = fdiv double %14, %15
store double %16, double* %8
%17 = load double, double* %5
%18 = load double, double* %8
%19 = load double, double* %8
%20 = load double, double* %7
%21 = call i32 @cos(double %20)
%22 = mul nsw i32 2, %21
%23 = sitofp i32 %22 to double
%24 = fsub double %19, %23
%25 = call double @llvm.fmuladd.f64(double %18, double %24, double 1.000000e+00)
%26 = call double @sqrt(double %25)
%27 = fmul double %17, %26
store double %27, double* %4
br label %43
28: ; preds = %3
%29 = load double, double* %5
%30 = load double, double* %6
%31 = fdiv double %29, %30
store double %31, double* %9
%32 = load double, double* %6
%33 = load double, double* %9
%34 = load double, double* %9
%35 = load double, double* %7
%36 = call i32 @cos(double %35)
%37 = mul nsw i32 2, %36
%38 = sitofp i32 %37 to double
%39 = fsub double %34, %38
%40 = call double @llvm.fmuladd.f64(double %33, double %39, double 1.000000e+00)
%41 = call double @sqrt(double %40)
%42 = fmul double %32, %41
store double %42, double* %4
br label %43
43: ; preds = %28, %13
%44 = load double, double* %4
ret double %44
}

LLVM IR (-O2):
define double @DistancePolar(double %0, double %1, double %2) {
%4 = fcmp ogt double %0, %1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = fdiv double %1, %0
br label %9
7: ; preds = %3
%8 = fdiv double %0, %1
br label %9
9: ; preds = %7, %5
%10 = phi double [ %8, %7 ], [ %6, %5 ]
%11 = phi double [ %1, %7 ], [ %0, %5 ]
%12 = tail call i32 @cos(double %2)
%13 = shl nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = fsub double %10, %14
%16 = tail call double @llvm.fmuladd.f64(double %10, double %15, double 1.000000e+00)
%17 = tail call double @sqrt(double %16)
%18 = fmul double %17, %11
ret double %18
}