double bessel(double x) {
  double xh, sum, pow, ds;
  int k;
  xh = (double)0.5 * x;
  sum = 1.0;
  pow = 1.0;
  k = 0;
  ds = 1.0;
  while (ds > sum * 1E-16) {
    ++k;
    pow = pow * (xh / k);
    ds = pow * pow;
    sum = sum + ds;
  }
  return sum;
}


x86 assembly (clang, -O0):
<bessel>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  0xef7(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xedd(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xeba(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ad <bessel+0xad>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1149 <bessel+0x49>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<bessel>:
mulsd  0xef8(%rip),%xmm0
movsd  0xef8(%rip),%xmm2
mov    $0x1,%eax
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,%xmm2
movapd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
addsd  %xmm4,%xmm1
movapd %xmm1,%xmm5
mulsd  %xmm3,%xmm5
add    $0x1,%eax
ucomisd %xmm5,%xmm4
ja     1130 <bessel+0x30>
movapd %xmm1,%xmm0
ret

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

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