double fibonacci(double n) {
  double m, i = 0, j = 1, k = 0;
  if (1 == n) {
    k = 0;
  } else if (2 == n) {
    k = 1;
  } else {
    for (m = 2; m < n; m++) {
      k = i + j;
      i = j;
      j = k;
    }
  }
  return k;
}


x86 assembly (clang, -O0):
<fibonacci>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xee7(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xed2(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    114c <fibonacci+0x4c>
jp     114c <fibonacci+0x4c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11dc <fibonacci+0xdc>
movsd  0xeb4(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    1177 <fibonacci+0x77>
jp     1177 <fibonacci+0x77>
movsd  0xe93(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d7 <fibonacci+0xd7>
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d2 <fibonacci+0xd2>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe3d(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1184 <fibonacci+0x84>
jmp    11d7 <fibonacci+0xd7>
jmp    11dc <fibonacci+0xdc>
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci>:
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd 0xef0(%rip),%xmm1
jne    1115 <fibonacci+0x15>
jp     1115 <fibonacci+0x15>
ret
ucomisd 0xeeb(%rip),%xmm1
jne    112a <fibonacci+0x2a>
jp     112a <fibonacci+0x2a>
movsd  0xed7(%rip),%xmm0
ret
jbe    1114 <fibonacci+0x14>
movsd  0xed4(%rip),%xmm2
xorpd  %xmm4,%xmm4
movsd  0xec0(%rip),%xmm3
movapd %xmm3,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd %xmm0,%xmm5
movapd %xmm4,%xmm0
addsd  %xmm5,%xmm0
addsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm1
movapd %xmm5,%xmm4
ja     1150 <fibonacci+0x50>
jmp    1114 <fibonacci+0x14>

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

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