double euler(double (*f)(double, double), int timeSteps, double h) {
  double y = 1.0, x;
  int i;
  for (i = 0; i < timeSteps; i++) {
    x = h * i;
    y = y + h * f(x, y);
  }
  return y;
}


x86 assembly (clang, -O0):
<euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xee4(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1193 <euler+0x93>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   *%rax
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1128 <euler+0x28>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    116f <euler+0x6f>
movapd %xmm0,%xmm2
mov    %esi,%ebx
mov    %rdi,%r14
movsd  0xee4(%rip),%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm2,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm2,%xmm0
call   *%r14
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  0xe98(%rip),%xmm0
add    $0xffffffff,%ebx
jne    1130 <euler+0x30>
jmp    1177 <euler+0x77>
movsd  0xe89(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @euler(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 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* %7
store i32 0, i32* %9
br label %10
10: ; preds = %26, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load double, double* %6
%16 = load i32, i32* %9
%17 = sitofp i32 %16 to double
%18 = fmul double %15, %17
store double %18, double* %8
%19 = load double, double* %7
%20 = load double, double* %6
%21 = load double (double, double)*, double (double, double)** %4
%22 = load double, double* %8
%23 = load double, double* %7
%24 = call double %21(double %22, double %23)
%25 = call double @llvm.fmuladd.f64(double %20, double %24, double %19)
store double %25, double* %7
br label %26
26: ; preds = %14
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %10
29: ; preds = %10
%30 = load double, double* %7
ret double %30
}

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