double BesselI_0(const double x) {
  double term, sum, last_sum, x2, y;
  int i;
  term = 1.0;
  sum = 1.0;
  x2 = x / 2.0;
  i = 1;
  do {
    y = x2 / i;
    i++;
    last_sum = sum;
    term *= y * y;
    sum += term;
  } while (sum != last_sum);
  return sum;
}


x86 assembly (clang, -O0):
<BesselI_0>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  0xef7(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeea(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1140 <BesselI_0+0x40>
jp     1140 <BesselI_0+0x40>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<BesselI_0>:
mulsd  0xef8(%rip),%xmm0
mov    $0x1,%eax
movsd  0xef3(%rip),%xmm1
movapd %xmm1,%xmm2
nopl   0x0(%rax)
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
movapd %xmm1,%xmm4
movapd %xmm0,%xmm5
divsd  %xmm3,%xmm5
add    $0x1,%eax
mulsd  %xmm5,%xmm5
mulsd  %xmm5,%xmm2
addsd  %xmm2,%xmm1
ucomisd %xmm4,%xmm1
jne    1120 <BesselI_0+0x20>
jp     1120 <BesselI_0+0x20>
movapd %xmm1,%xmm0
ret

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

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