double leapFrog(double (*f)(double, double), int timeSteps, double h) {
  double y, y1, x = h, y0 = 1.0;
  int i;
  y1 = y0 + h * f(0.0, y0);
  for (i = 1; i < timeSteps; i++) {
    y = y0 + h * 2 * f(x, y1);
    x = h * i;
    y0 = y1;
    y1 = y;
  }
  return y;
}


x86 assembly (clang, -O0):
<leapFrog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeda(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x38(%rbp),%xmm1
xorps  %xmm0,%xmm0
call   *%rax
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f5 <leapFrog+0xf5>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xe7c(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   *%rax
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    116e <leapFrog+0x6e>
movsd  -0x20(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leapFrog>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,(%rsp)
mov    %esi,%ebx
mov    %rdi,%r14
movsd  0xee7(%rip),%xmm1
xorpd  %xmm0,%xmm0
call   *%rdi
movapd %xmm0,%xmm1
cmp    $0x2,%ebx
jl     11ab <leapFrog+0xab>
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xec3(%rip),%xmm0
addsd  %xmm0,%xmm1
movapd %xmm2,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rsp)
add    $0xffffffff,%ebx
movapd %xmm0,%xmm3
movapd %xmm0,%xmm4
nopw   0x0(%rax,%rax,1)
movsd  %xmm4,0x10(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm3,0x20(%rsp)
movapd %xmm2,%xmm0
call   *%r14
movsd  0x20(%rsp),%xmm3
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movapd %xmm3,%xmm2
mulsd  (%rsp),%xmm2
addsd  0xe64(%rip),%xmm3
movsd  0x18(%rsp),%xmm4
movapd %xmm0,%xmm1
add    $0xffffffff,%ebx
jne    1160 <leapFrog+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @leapFrog(double (double, double)* %0, i32 %1, double %2) {
%4 = alloca double (double, double)*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double (double, double)* %0, double (double, double)** %4
store i32 %1, i32* %5
store double %2, double* %6
%12 = load double, double* %6
store double %12, double* %9
store double 1.000000e+00, double* %10
%13 = load double, double* %10
%14 = load double, double* %6
%15 = load double (double, double)*, double (double, double)** %4
%16 = load double, double* %10
%17 = call double %15(double 0.000000e+00, double %16)
%18 = call double @llvm.fmuladd.f64(double %14, double %17, double %13)
store double %18, double* %8
store i32 1, i32* %11
br label %19
19: ; preds = %38, %3
%20 = load i32, i32* %11
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %41
23: ; preds = %19
%24 = load double, double* %10
%25 = load double, double* %6
%26 = fmul double %25, 2.000000e+00
%27 = load double (double, double)*, double (double, double)** %4
%28 = load double, double* %9
%29 = load double, double* %8
%30 = call double %27(double %28, double %29)
%31 = call double @llvm.fmuladd.f64(double %26, double %30, double %24)
store double %31, double* %7
%32 = load double, double* %6
%33 = load i32, i32* %11
%34 = sitofp i32 %33 to double
%35 = fmul double %32, %34
store double %35, double* %9
%36 = load double, double* %8
store double %36, double* %10
%37 = load double, double* %7
store double %37, double* %8
br label %38
38: ; preds = %23
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %19
41: ; preds = %19
%42 = load double, double* %7
ret double %42
}

LLVM IR (-O2):
define double @leapFrog(double (double, double)* nocapture %0, i32 %1, double %2) {
%4 = tail call double %0(double 0.000000e+00, double 1.000000e+00)
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = tail call double @llvm.fmuladd.f64(double %2, double %4, double 1.000000e+00)
%8 = fmul double %2, 2.000000e+00
br label %9
9: ; preds = %6, %9
%10 = phi i32 [ 1, %6 ], [ %18, %9 ]
%11 = phi double [ 1.000000e+00, %6 ], [ %13, %9 ]
%12 = phi double [ %2, %6 ], [ %17, %9 ]
%13 = phi double [ %7, %6 ], [ %15, %9 ]
%14 = tail call double %0(double %12, double %13)
%15 = tail call double @llvm.fmuladd.f64(double %8, double %14, double %11)
%16 = sitofp i32 %10 to double
%17 = fmul double %16, %2
%18 = add nuw nsw i32 %10, 1
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %9
20: ; preds = %9, %3
%21 = phi double [ undef, %3 ], [ %15, %9 ]
ret double %21
}