double euler(double initialx, double finalx, double initialy, double accuracy,
             double (*df)(double x, double y)) {
  double interval = finalx - initialx, finalynminus1, finalyn = 0, ei = exp(1);
  int i = 1, j;
  printf("EULER METHOD:\n\ni\t|dx|\t\ty(x)\t\t|ei|\t\t|log(ei)/log(e(i-1))|\n");
  do {
    finalynminus1 = finalyn;
    finalyn = initialy;
    interval /= 2;
    j = 1;
    do
      finalyn += interval * df(initialx + j * interval, finalyn);
    while (initialx + (++j) * interval <= finalx);
    printf("%02d\t%+09g\t%+09g\t%+09g\t%+09g\n", i++, interval, finalyn,
           abslt(finalyn - finalynminus1),
           abslt(log(abslt(finalyn - finalynminus1)) / log(ei)));
    ei = abslt(finalyn - finalynminus1);
  } while (abslt(finalyn - finalynminus1) > accuracy);
  return finalyn;
}


x86 assembly (clang, -O0):
<euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe7e(%rip),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe46(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
call   *%rax
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
cvtsi2sd %eax,%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jae    11d2 <euler+0x92>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x74(%rbp)
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,-0x5c(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    -0x74(%rbp),%esi
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mov    -0x5c(%rbp),%edx
mov    %eax,%ecx
lea    0xd7b(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     11a1 <euler+0x61>
movsd  -0x40(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
movsd  %xmm3,0x38(%rsp)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm1,0x48(%rsp)
movsd  %xmm0,0x28(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
movsd  0xe75(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm1,%xmm1
lea    0xe74(%rip),%r14
nopl   0x0(%rax)
movsd  %xmm1,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe54(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0x2,%ebp
movsd  0x30(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
lea    -0x1(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movaps %xmm2,%xmm1
call   *%rbx
movsd  0x28(%rsp),%xmm1
movapd %xmm0,%xmm2
movsd  0x10(%rsp),%xmm3
mulsd  %xmm3,%xmm2
addsd  0x8(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%ebp
movsd  0x48(%rsp),%xmm3
ucomisd %xmm0,%xmm3
jae    11d0 <euler+0x90>
lea    0x1(%r15),%r12d
movapd %xmm2,%xmm0
subsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
movsd  %xmm2,0x18(%rsp)
call   1030 <abslt@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x20(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x40(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %r14,%rdi
mov    %r15d,%esi
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
movsd  0x18(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd 0x38(%rsp),%xmm1
movapd %xmm0,%xmm1
mov    %r12d,%r15d
ja     11a0 <euler+0x60>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"EULER METHOD:\0A\0Ai\09|dx|\09\09y(x)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\0A\00"
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
define double @euler(double %0, double %1, double %2, double %3, double (double, double)* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double (double, double)*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double (double, double)* %4, double (double, double)** %10
%17 = load double, double* %7
%18 = load double, double* %6
%19 = fsub double %17, %18
store double %19, double* %11
store double 0.000000e+00, double* %13
%20 = call double @exp(double 1.000000e+00)
store double %20, double* %14
store i32 1, i32* %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %73, %5
%23 = load double, double* %13
store double %23, double* %12
%24 = load double, double* %8
store double %24, double* %13
%25 = load double, double* %11
%26 = fdiv double %25, 2.000000e+00
store double %26, double* %11
store i32 1, i32* %16
br label %27
27: ; preds = %39, %22
%28 = load double, double* %11
%29 = load double (double, double)*, double (double, double)** %10
%30 = load double, double* %6
%31 = load i32, i32* %16
%32 = sitofp i32 %31 to double
%33 = load double, double* %11
%34 = call double @llvm.fmuladd.f64(double %32, double %33, double %30)
%35 = load double, double* %13
%36 = call double %29(double %34, double %35)
%37 = load double, double* %13
%38 = call double @llvm.fmuladd.f64(double %28, double %36, double %37)
store double %38, double* %13
br label %39
39: ; preds = %27
%40 = load double, double* %6
%41 = load i32, i32* %16
%42 = add nsw i32 %41, 1
store i32 %42, i32* %16
%43 = sitofp i32 %42 to double
%44 = load double, double* %11
%45 = call double @llvm.fmuladd.f64(double %43, double %44, double %40)
%46 = load double, double* %7
%47 = fcmp ole double %45, %46
br i1 %47, label %27, label %48
48: ; preds = %39
%49 = load i32, i32* %15
%50 = add nsw i32 %49, 1
store i32 %50, i32* %15
%51 = load double, double* %11
%52 = load double, double* %13
%53 = load double, double* %13
%54 = load double, double* %12
%55 = fsub double %53, %54
%56 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %55)
%57 = load double, double* %13
%58 = load double, double* %12
%59 = fsub double %57, %58
%60 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %59)
%61 = sitofp i32 %60 to double
%62 = call double @log(double %61)
%63 = load double, double* %14
%64 = call double @log(double %63)
%65 = fdiv double %62, %64
%66 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %65)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %49, double %51, double %52, i32 %56, i32 %66)
%68 = load double, double* %13
%69 = load double, double* %12
%70 = fsub double %68, %69
%71 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %70)
%72 = sitofp i32 %71 to double
store double %72, double* %14
br label %73
73: ; preds = %48
%74 = load double, double* %13
%75 = load double, double* %12
%76 = fsub double %74, %75
%77 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %76)
%78 = sitofp i32 %77 to double
%79 = load double, double* %9
%80 = fcmp ogt double %78, %79
br i1 %80, label %22, label %81
81: ; preds = %73
%82 = load double, double* %13
ret double %82
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
@str = [57 x i8] c"EULER METHOD:\0A\0Ai\09|dx|\09\09y(x)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\00"
define double @euler(double %0, double %1, double %2, double %3, double (double, double)* nocapture %4) {
%6 = fsub double %1, %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %25, %5
%9 = phi double [ %6, %5 ], [ %13, %25 ]
%10 = phi double [ 0.000000e+00, %5 ], [ %20, %25 ]
%11 = phi double [ 0x4005BF0A8B145769, %5 ], [ %37, %25 ]
%12 = phi i32 [ 1, %5 ], [ %26, %25 ]
%13 = fmul double %9, 5.000000e-01
br label %14
14: ; preds = %14, %8
%15 = phi double [ %2, %8 ], [ %20, %14 ]
%16 = phi i32 [ 1, %8 ], [ %21, %14 ]
%17 = sitofp i32 %16 to double
%18 = tail call double @llvm.fmuladd.f64(double %17, double %13, double %0)
%19 = tail call double %4(double %18, double %15)
%20 = tail call double @llvm.fmuladd.f64(double %13, double %19, double %15)
%21 = add nuw nsw i32 %16, 1
%22 = sitofp i32 %21 to double
%23 = tail call double @llvm.fmuladd.f64(double %22, double %13, double %0)
%24 = fcmp ugt double %23, %1
br i1 %24, label %25, label %14
25: ; preds = %14
%26 = add nuw nsw i32 %12, 1
%27 = fsub double %20, %10
%28 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %27)
%29 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %27)
%30 = sitofp i32 %29 to double
%31 = tail call double @log(double %30)
%32 = tail call double @log(double %11)
%33 = fdiv double %31, %32
%34 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %33)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %12, double %13, double %20, i32 %28, i32 %34)
%36 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %27)
%37 = sitofp i32 %36 to double
%38 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %27)
%39 = sitofp i32 %38 to double
%40 = fcmp ogt double %39, %3
br i1 %40, label %8, label %41
41: ; preds = %25
ret double %20
}