double addRecursiveDouble(int from, int to) {
  int N = 1 + to - from;
  int h;
  if (N < 1)
    return 0;
  if (N == 1)
    return 1.0 / (double)from;
  if (N == 2)
    return 1.0 / (double)from + 1.0 / (double)to;
  h = (to + from) / 2;
  return addRecursiveDouble(from, h) + addRecursiveDouble(h + 1, to);
}


x86 assembly (clang, -O0):
<addRecursiveDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1141 <addRecursiveDouble+0x31>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <addRecursiveDouble+0xd0>
cmpl   $0x1,-0x14(%rbp)
jne    1166 <addRecursiveDouble+0x56>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xea8(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <addRecursiveDouble+0xd0>
cmpl   $0x2,-0x14(%rbp)
jne    11a0 <addRecursiveDouble+0x90>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe83(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm2
movsd  0xe72(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <addRecursiveDouble+0xd0>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <addRecursiveDouble@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%esi
call   1030 <addRecursiveDouble@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addRecursiveDouble>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%eax
sub    %edi,%eax
add    $0x1,%eax
test   %eax,%eax
jle    113c <addRecursiveDouble+0x2c>
mov    %esi,%ebx
cmp    $0x2,%eax
je     1142 <addRecursiveDouble+0x32>
cmp    $0x1,%eax
jne    116c <addRecursiveDouble+0x5c>
cvtsi2sd %edi,%xmm1
movsd  0xeda(%rip),%xmm0
divsd  %xmm1,%xmm0
jmp    1195 <addRecursiveDouble+0x85>
xorpd  %xmm0,%xmm0
jmp    1195 <addRecursiveDouble+0x85>
movd   %ebx,%xmm0
movd   %edi,%xmm1
punpckldq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm0
movapd 0xea6(%rip),%xmm1
divpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
jmp    1195 <addRecursiveDouble+0x85>
lea    (%rbx,%rdi,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%esi
call   1030 <addRecursiveDouble@plt>
movsd  %xmm0,(%rsp)
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <addRecursiveDouble@plt>
addsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @addRecursiveDouble(i32 %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 1, %8
%10 = load i32, i32* %4
%11 = sub nsw i32 %9, %10
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %2
store double 0.000000e+00, double* %3
br label %46
15: ; preds = %2
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %4
%20 = sitofp i32 %19 to double
%21 = fdiv double 1.000000e+00, %20
store double %21, double* %3
br label %46
22: ; preds = %15
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i32, i32* %4
%27 = sitofp i32 %26 to double
%28 = fdiv double 1.000000e+00, %27
%29 = load i32, i32* %5
%30 = sitofp i32 %29 to double
%31 = fdiv double 1.000000e+00, %30
%32 = fadd double %28, %31
store double %32, double* %3
br label %46
33: ; preds = %22
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = add nsw i32 %34, %35
%37 = sdiv i32 %36, 2
store i32 %37, i32* %7
%38 = load i32, i32* %4
%39 = load i32, i32* %7
%40 = call double @addRecursiveDouble(i32 %38, i32 %39)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = load i32, i32* %5
%44 = call double @addRecursiveDouble(i32 %42, i32 %43)
%45 = fadd double %40, %44
store double %45, double* %3
br label %46
46: ; preds = %33, %25, %18, %14
%47 = load double, double* %3
ret double %47
}

LLVM IR (-O2):
define double @addRecursiveDouble(i32 %0, i32 %1) {
%3 = sub i32 1, %0
%4 = add i32 %3, %1
%5 = icmp slt i32 %4, 1
br i1 %5, label %18, label %6
6: ; preds = %2
switch i32 %4, label %20 [
i32 1, label %7
i32 2, label %10
]
7: ; preds = %6
%8 = sitofp i32 %0 to double
%9 = fdiv double 1.000000e+00, %8
br label %18
10: ; preds = %6
%11 = insertelement <2 x i32> poison, i32 %0, i64 0
%12 = insertelement <2 x i32> %11, i32 %1, i64 1
%13 = sitofp <2 x i32> %12 to <2 x double>
%14 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %13
%15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%16 = fadd <2 x double> %14, %15
%17 = extractelement <2 x double> %16, i64 0
br label %18
18: ; preds = %7, %10, %2, %20
%19 = phi double [ %26, %20 ], [ %9, %7 ], [ %17, %10 ], [ 0.000000e+00, %2 ]
ret double %19
20: ; preds = %6
%21 = add nsw i32 %1, %0
%22 = sdiv i32 %21, 2
%23 = tail call double @addRecursiveDouble(i32 %0, i32 %22)
%24 = add nsw i32 %22, 1
%25 = tail call double @addRecursiveDouble(i32 %24, i32 %1)
%26 = fadd double %23, %25
br label %18
}