#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 atan(double);
double tan(double);
double solve(double B, double H) {
  double h;
  double sum = 0;
  double theta;
  double r;
  while (1) {
    theta = atan(2.0 * H / B);
    r = tan(theta / 2.0) * B / 2.0;
    if (r < 1e-6)
      break;
    sum += 2 * (4 * atan(1.0)) * r;
    h = H - 2 * r;
    B = B * h / H;
    H = h;
  }
  return sum;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec6(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1030 <atan@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xea1(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <tan@plt>
mulsd  -0x8(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe72(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    119e <solve+0x7e>
jmp    1206 <solve+0xe6>
movsd  0xe6a(%rip),%xmm0
call   1030 <atan@plt>
shl    $0x2,%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    113a <solve+0x1a>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
sub    $0x28,%rsp
movapd %xmm0,%xmm2
movsd  %xmm0,(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1030 <atan@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xead(%rip),%xmm0
call   1040 <tan@plt>
movsd  (%rsp),%xmm3
mulsd  %xmm3,%xmm0
mulsd  0xe97(%rip),%xmm0
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe8d(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1267 <solve+0x147>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x20(%rsp)
movsd  %xmm3,(%rsp)
movsd  0xe5d(%rip),%xmm0
call   1030 <atan@plt>
shl    $0x3,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  %xmm2,%xmm2
movsd  0x18(%rsp),%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  (%rsp),%xmm0
call   1030 <atan@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdd1(%rip),%xmm0
call   1040 <tan@plt>
movsd  0xdcc(%rip),%xmm2
movsd  0xdbc(%rip),%xmm1
movsd  (%rsp),%xmm3
mulsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm0
ucomisd %xmm0,%xmm2
movsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
jbe    11a0 <solve+0x80>
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @solve(double %0, double %1) {
%3 = fmul double %1, 2.000000e+00
%4 = fdiv double %3, %0
%5 = tail call i32 @atan(double %4)
%6 = sitofp i32 %5 to double
%7 = fmul double %6, 5.000000e-01
%8 = tail call double @tan(double %7)
%9 = fmul double %8, %0
%10 = fmul double %9, 5.000000e-01
%11 = fcmp olt double %10, 0x3EB0C6F7A0B5ED8D
br i1 %11, label %33, label %12
12: ; preds = %2, %12
%13 = phi double [ %31, %12 ], [ %10, %2 ]
%14 = phi double [ %23, %12 ], [ %0, %2 ]
%15 = phi double [ %21, %12 ], [ %1, %2 ]
%16 = phi double [ %20, %12 ], [ 0.000000e+00, %2 ]
%17 = tail call i32 @atan(double 1.000000e+00)
%18 = shl nsw i32 %17, 3
%19 = sitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double %13, double %16)
%21 = tail call double @llvm.fmuladd.f64(double %13, double -2.000000e+00, double %15)
%22 = fmul double %14, %21
%23 = fdiv double %22, %15
%24 = fmul double %21, 2.000000e+00
%25 = fdiv double %24, %23
%26 = tail call i32 @atan(double %25)
%27 = sitofp i32 %26 to double
%28 = fmul double %27, 5.000000e-01
%29 = tail call double @tan(double %28)
%30 = fmul double %23, %29
%31 = fmul double %30, 5.000000e-01
%32 = fcmp olt double %31, 0x3EB0C6F7A0B5ED8D
br i1 %32, label %33, label %12
33: ; preds = %12, %2
%34 = phi double [ 0.000000e+00, %2 ], [ %20, %12 ]
ret double %34
}