double besselI0(double x) {
  double temp;
  double sum = 1.0;
  double u = 1.0;
  double halfx = x / 2.0;
  int n = 1;
  do {
    temp = halfx / (double)n;
    u *= temp * temp;
    sum += u;
    n++;
  } while (u >= 1E-21 * sum);
  return (sum);
}


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

x86 assembly (clang, -O2):
<besselI0>:
mulsd  0xef8(%rip),%xmm0
mov    $0x1,%eax
movsd  0xef3(%rip),%xmm2
movsd  0xef3(%rip),%xmm3
movapd %xmm2,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
movapd %xmm0,%xmm5
divsd  %xmm4,%xmm5
mulsd  %xmm5,%xmm5
mulsd  %xmm5,%xmm2
addsd  %xmm2,%xmm1
add    $0x1,%eax
movapd %xmm1,%xmm4
mulsd  %xmm3,%xmm4
ucomisd %xmm4,%xmm2
jae    1130 <besselI0+0x30>
movapd %xmm1,%xmm0
ret

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

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