double fibonacciDubs(double num) {
  double a = 0, b = 1;
  double fib = 1;
  int i;
  if (num == 1)
    return 0;
  for (i = 2; i < num; i++) {
    fib = a + b;
    a = b;
    b = fib;
  }
  return fib;
}


x86 assembly (clang, -O0):
<fibonacciDubs>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xee7(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeda(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xec8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1155 <fibonacciDubs+0x55>
jp     1155 <fibonacciDubs+0x55>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ab <fibonacciDubs+0xab>
movl   $0x2,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a1 <fibonacciDubs+0xa1>
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)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115c <fibonacciDubs+0x5c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacciDubs>:
xorpd  %xmm1,%xmm1
ucomisd 0xef4(%rip),%xmm0
jne    1110 <fibonacciDubs+0x10>
jnp    1150 <fibonacciDubs+0x50>
ucomisd 0xef0(%rip),%xmm0
jbe    1155 <fibonacciDubs+0x55>
xorpd  %xmm2,%xmm2
movsd  0xeda(%rip),%xmm1
mov    $0x3,%eax
nopl   0x0(%rax,%rax,1)
movapd %xmm1,%xmm3
movapd %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
addsd  %xmm3,%xmm1
add    $0x1,%eax
ucomisd %xmm2,%xmm0
movapd %xmm3,%xmm2
ja     1130 <fibonacciDubs+0x30>
movapd %xmm1,%xmm0
ret
movsd  0xea3(%rip),%xmm0
ret

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

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