double fibonacci(double n) {
  if (n == 1.0) {
    return 1.0;
  } else if (n == 2.0) {
    return 1.0;
  } else if (n == 0.0) {
    return 0;
  }
  return fibonacci(n - 1.0) + fibonacci(n - 2.0);
}


x86 assembly (clang, -O0):
<fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    114c <fibonacci+0x3c>
jp     114c <fibonacci+0x3c>
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <fibonacci+0xdc>
movsd  -0x10(%rbp),%xmm0
movsd  0xeaf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    117b <fibonacci+0x6b>
jp     117b <fibonacci+0x6b>
movsd  0xe8f(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <fibonacci+0xdc>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a0 <fibonacci+0x90>
jp     11a0 <fibonacci+0x90>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <fibonacci+0xdc>
jmp    11a5 <fibonacci+0x95>
jmp    11aa <fibonacci+0x9a>
movsd  -0x10(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fibonacci@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe36(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fibonacci@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
movsd  0xee0(%rip),%xmm0
ucomisd %xmm0,%xmm1
jne    1128 <fibonacci+0x18>
jnp    1140 <fibonacci+0x30>
ucomisd 0xed8(%rip),%xmm1
jne    1134 <fibonacci+0x24>
jnp    1140 <fibonacci+0x30>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1145 <fibonacci+0x35>
jp     1145 <fibonacci+0x35>
add    $0x18,%rsp
ret
movsd  0xec3(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1030 <fibonacci@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xea8(%rip),%xmm0
call   1030 <fibonacci@plt>
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @fibonacci(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = fcmp oeq double %4, 1.000000e+00
br i1 %5, label %6, label %7
6: ; preds = %1
store double 1.000000e+00, double* %2
br label %25
7: ; preds = %1
%8 = load double, double* %3
%9 = fcmp oeq double %8, 2.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %7
store double 1.000000e+00, double* %2
br label %25
11: ; preds = %7
%12 = load double, double* %3
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11
store double 0.000000e+00, double* %2
br label %25
15: ; preds = %11
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
%18 = load double, double* %3
%19 = fsub double %18, 1.000000e+00
%20 = call double @fibonacci(double %19)
%21 = load double, double* %3
%22 = fsub double %21, 2.000000e+00
%23 = call double @fibonacci(double %22)
%24 = fadd double %20, %23
store double %24, double* %2
br label %25
25: ; preds = %17, %14, %10, %6
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
define double @fibonacci(double %0) {
%2 = fcmp oeq double %0, 1.000000e+00
%3 = fcmp oeq double %0, 2.000000e+00
%4 = or i1 %2, %3
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = fcmp oeq double %0, 0.000000e+00
br i1 %6, label %7, label %9
7: ; preds = %1, %5, %9
%8 = phi double [ %14, %9 ], [ 1.000000e+00, %1 ], [ 0.000000e+00, %5 ]
ret double %8
9: ; preds = %5
%10 = fadd double %0, -1.000000e+00
%11 = tail call double @fibonacci(double %10)
%12 = fadd double %0, -2.000000e+00
%13 = tail call double @fibonacci(double %12)
%14 = fadd double %11, %13
br label %7
}