double rungeKuttaFourthOrder(double (*f)(double, double), int timeSteps,
                             double h) {
  double k1, k2, k3, k4, y = 1.0, x;
  int i;
  for (i = 0; i < timeSteps; i++) {
    x = h * i;
    k1 = f(x, y) * h;
    x = x + h / 2;
    k2 = f(x, y + k1 / 2) * h;
    k3 = f(x, y + k2 / 2) * h;
    x = x + h / 2;
    k4 = f(x, y + k3) * h;
    y = y + ((k1 + 2.0 * k2 + 2.0 * k3 + k4) / 6.0);
  }
  return y;
}


x86 assembly (clang, -O0):
<rungeKuttaFourthOrder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xee4(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1268 <rungeKuttaFourthOrder+0x168>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x4c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   *%rax
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe9d(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xe75(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
call   *%rax
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  0xe46(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
call   *%rax
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe20(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
call   *%rax
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
addsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x30(%rbp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
addsd  -0x38(%rbp),%xmm1
movsd  0xdbb(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1128 <rungeKuttaFourthOrder+0x28>
movsd  -0x40(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rungeKuttaFourthOrder>:
push   %r14
push   %rbx
sub    $0x48,%rsp
movsd  %xmm0,0x8(%rsp)
test   %esi,%esi
jle    123d <rungeKuttaFourthOrder+0x13d>
mov    %esi,%ebx
mov    %rdi,%r14
movsd  0xee6(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0xeca(%rip),%xmm1
xorpd  %xmm2,%xmm2
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x40(%rsp)
movapd %xmm2,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   *%r14
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0x10(%rsp),%xmm2
addsd  0x20(%rsp),%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm0,%xmm1
movsd  0xe7f(%rip),%xmm0
mulsd  %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
movapd %xmm2,%xmm0
call   *%r14
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
movapd %xmm0,%xmm1
mulsd  0xe56(%rip),%xmm1
addsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
call   *%r14
movapd %xmm0,%xmm2
mulsd  0x8(%rsp),%xmm2
movsd  %xmm2,0x28(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm2,%xmm1
call   *%r14
movsd  0x18(%rsp),%xmm1
movsd  0x40(%rsp),%xmm2
mulsd  0x8(%rsp),%xmm0
movsd  0x30(%rsp),%xmm3
addsd  %xmm3,%xmm3
addsd  0x38(%rsp),%xmm3
movsd  0x28(%rsp),%xmm4
addsd  %xmm4,%xmm4
addsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
divsd  0xdea(%rip),%xmm4
addsd  %xmm4,%xmm1
addsd  0xdce(%rip),%xmm2
add    $0xffffffff,%ebx
jne    1140 <rungeKuttaFourthOrder+0x40>
jmp    1245 <rungeKuttaFourthOrder+0x145>
movsd  0xdbb(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @rungeKuttaFourthOrder(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 double
%12 = alloca double
%13 = alloca i32
store double (double, double)* %0, double (double, double)** %4
store i32 %1, i32* %5
store double %2, double* %6
store double 1.000000e+00, double* %11
store i32 0, i32* %13
br label %14
14: ; preds = %73, %3
%15 = load i32, i32* %13
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %76
18: ; preds = %14
%19 = load double, double* %6
%20 = load i32, i32* %13
%21 = sitofp i32 %20 to double
%22 = fmul double %19, %21
store double %22, double* %12
%23 = load double (double, double)*, double (double, double)** %4
%24 = load double, double* %12
%25 = load double, double* %11
%26 = call double %23(double %24, double %25)
%27 = load double, double* %6
%28 = fmul double %26, %27
store double %28, double* %7
%29 = load double, double* %12
%30 = load double, double* %6
%31 = fdiv double %30, 2.000000e+00
%32 = fadd double %29, %31
store double %32, double* %12
%33 = load double (double, double)*, double (double, double)** %4
%34 = load double, double* %12
%35 = load double, double* %11
%36 = load double, double* %7
%37 = fdiv double %36, 2.000000e+00
%38 = fadd double %35, %37
%39 = call double %33(double %34, double %38)
%40 = load double, double* %6
%41 = fmul double %39, %40
store double %41, double* %8
%42 = load double (double, double)*, double (double, double)** %4
%43 = load double, double* %12
%44 = load double, double* %11
%45 = load double, double* %8
%46 = fdiv double %45, 2.000000e+00
%47 = fadd double %44, %46
%48 = call double %42(double %43, double %47)
%49 = load double, double* %6
%50 = fmul double %48, %49
store double %50, double* %9
%51 = load double, double* %12
%52 = load double, double* %6
%53 = fdiv double %52, 2.000000e+00
%54 = fadd double %51, %53
store double %54, double* %12
%55 = load double (double, double)*, double (double, double)** %4
%56 = load double, double* %12
%57 = load double, double* %11
%58 = load double, double* %9
%59 = fadd double %57, %58
%60 = call double %55(double %56, double %59)
%61 = load double, double* %6
%62 = fmul double %60, %61
store double %62, double* %10
%63 = load double, double* %11
%64 = load double, double* %7
%65 = load double, double* %8
%66 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %65, double %64)
%67 = load double, double* %9
%68 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %67, double %66)
%69 = load double, double* %10
%70 = fadd double %68, %69
%71 = fdiv double %70, 6.000000e+00
%72 = fadd double %63, %71
store double %72, double* %11
br label %73
73: ; preds = %18
%74 = load i32, i32* %13
%75 = add nsw i32 %74, 1
store i32 %75, i32* %13
br label %14
76: ; preds = %14
%77 = load double, double* %11
ret double %77
}

LLVM IR (-O2):
define double @rungeKuttaFourthOrder(double (double, double)* nocapture %0, i32 %1, double %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %34
5: ; preds = %3
%6 = fmul double %2, 5.000000e-01
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ 0, %5 ], [ %32, %7 ]
%9 = phi double [ 1.000000e+00, %5 ], [ %31, %7 ]
%10 = sitofp i32 %8 to double
%11 = fmul double %10, %2
%12 = tail call double %0(double %11, double %9)
%13 = fmul double %12, %2
%14 = fadd double %6, %11
%15 = fmul double %13, 5.000000e-01
%16 = fadd double %9, %15
%17 = tail call double %0(double %14, double %16)
%18 = fmul double %17, %2
%19 = fmul double %18, 5.000000e-01
%20 = fadd double %9, %19
%21 = tail call double %0(double %14, double %20)
%22 = fmul double %21, %2
%23 = fadd double %6, %14
%24 = fadd double %9, %22
%25 = tail call double %0(double %23, double %24)
%26 = fmul double %25, %2
%27 = tail call double @llvm.fmuladd.f64(double %18, double 2.000000e+00, double %13)
%28 = tail call double @llvm.fmuladd.f64(double %22, double 2.000000e+00, double %27)
%29 = fadd double %28, %26
%30 = fdiv double %29, 6.000000e+00
%31 = fadd double %9, %30
%32 = add nuw nsw i32 %8, 1
%33 = icmp eq i32 %32, %1
br i1 %33, label %34, label %7
34: ; preds = %7, %3
%35 = phi double [ 1.000000e+00, %3 ], [ %31, %7 ]
ret double %35
}