#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CalcDerivs(int, float *, double, float *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double, float);
int /*<<< orphan*/ printf(char *, double, double, float);
double sin(double);
int euler(char *fout, double t, double tmax, double step, double x, double v) {
  float ystar;
  float xs[2], k1[2];
  int i;
  FILE *file;
  file = fopen(fout, "w");
  xs[0] = x;
  xs[1] = v;
  for (t = 0; t < tmax; t = t + step) {
    CalcDerivs(2, xs, t, k1);
    printf("%f\t%e\t%e\n", t, sin(t), xs[0]);
    fprintf(file, "%f\t%e\t%e\n", t, sin(t), xs[0]);
    for (i = 0; i < 2; i++) {
      xs[i] = xs[i] + step * k1[i];
    }
  }
}


x86 assembly (clang, -O0):
<euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  %xmm4,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12ad <euler+0x15d>
lea    -0x44(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
lea    -0x4c(%rbp),%rdx
mov    $0x2,%edi
call   1040 <CalcDerivs@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
movss  -0x44(%rbp),%xmm2
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <sin@plt>
mov    -0x68(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
movss  -0x44(%rbp),%xmm2
lea    0xdc9(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x50(%rbp)
cmpl   $0x2,-0x50(%rbp)
jge    1294 <euler+0x144>
movslq -0x50(%rbp),%rax
movss  -0x44(%rbp,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movslq -0x50(%rbp),%rax
movss  -0x4c(%rbp,%rax,4),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x50(%rbp),%rax
movss  %xmm0,-0x44(%rbp,%rax,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1245 <euler+0xf5>
jmp    1299 <euler+0x149>
movsd  -0x18(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ad <euler+0x5d>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm4,0x8(%rsp)
movsd  %xmm3,0x28(%rsp)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm1,0x18(%rsp)
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
movsd  0x18(%rsp),%xmm1
movsd  0x28(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
xorps  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    12ab <euler+0x15b>
mov    %rax,%r12
lea    0x10(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xe3c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm0
mov    %r15,%rdx
call   1040 <CalcDerivs@plt>
movsd  0x8(%rsp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movss  0x10(%rsp),%xmm2
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movss  0x10(%rsp),%xmm2
mov    %r12,%rdi
mov    %rbx,%rsi
movsd  0x8(%rsp),%xmm0
call   1050 <fprintf@plt>
movss  0x10(%rsp),%xmm0
movss  0x14(%rsp),%xmm1
cvtss2sd %xmm0,%xmm0
movss  0x20(%rsp),%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0x30(%rsp),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
movss  0x24(%rsp),%xmm2
movss  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movsd  0x18(%rsp),%xmm1
movss  %xmm0,0x14(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  %xmm3,%xmm0
ucomisd %xmm0,%xmm1
ja     11d0 <euler+0x80>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [10 x i8] c"%f\09%e\09%e\0A\00"
define i32 @euler(i8* %0, double %1, double %2, double %3, double %4, double %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca float
%15 = alloca [2 x float]
%16 = alloca [2 x float]
%17 = alloca i32
%18 = alloca i32*
store i8* %0, i8** %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double %5, double* %13
%19 = load i8*, i8** %8
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %18
%21 = load double, double* %12
%22 = fptrunc double %21 to float
%23 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 0
store float %22, float* %23
%24 = load double, double* %13
%25 = fptrunc double %24 to float
%26 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 1
store float %25, float* %26
store double 0.000000e+00, double* %9
br label %27
27: ; preds = %73, %6
%28 = load double, double* %9
%29 = load double, double* %10
%30 = fcmp olt double %28, %29
br i1 %30, label %31, label %77
31: ; preds = %27
%32 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 0
%33 = load double, double* %9
%34 = getelementptr inbounds [2 x float], [2 x float]* %16, i64 0, i64 0
%35 = call i32 @CalcDerivs(i32 2, float* %32, double %33, float* %34)
%36 = load double, double* %9
%37 = load double, double* %9
%38 = call double @sin(double %37)
%39 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 0
%40 = load float, float* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %36, double %38, float %40)
%42 = load i32*, i32** %18
%43 = load double, double* %9
%44 = load double, double* %9
%45 = call double @sin(double %44)
%46 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 0
%47 = load float, float* %46
%48 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %43, double %45, float %47)
store i32 0, i32* %17
br label %49
49: ; preds = %69, %31
%50 = load i32, i32* %17
%51 = icmp slt i32 %50, 2
br i1 %51, label %52, label %72
52: ; preds = %49
%53 = load i32, i32* %17
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 %54
%56 = load float, float* %55
%57 = fpext float %56 to double
%58 = load double, double* %11
%59 = load i32, i32* %17
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [2 x float], [2 x float]* %16, i64 0, i64 %60
%62 = load float, float* %61
%63 = fpext float %62 to double
%64 = call double @llvm.fmuladd.f64(double %58, double %63, double %57)
%65 = fptrunc double %64 to float
%66 = load i32, i32* %17
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 %67
store float %65, float* %68
br label %69
69: ; preds = %52
%70 = load i32, i32* %17
%71 = add nsw i32 %70, 1
store i32 %71, i32* %17
br label %49
72: ; preds = %49
br label %73
73: ; preds = %72
%74 = load double, double* %9
%75 = load double, double* %11
%76 = fadd double %74, %75
store double %76, double* %9
br label %27
77: ; preds = %27
%78 = load i32, i32* %7
ret i32 %78
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [10 x i8] c"%f\09%e\09%e\0A\00"
define i32 @euler(i8* nocapture %0, double %1, double %2, double %3, double %4, double %5) {
%7 = alloca [2 x float]
%8 = alloca [2 x float]
%9 = bitcast [2 x float]* %7 to i8*
%10 = bitcast [2 x float]* %8 to i8*
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = fptrunc double %4 to float
%13 = getelementptr inbounds [2 x float], [2 x float]* %7, i64 0, i64 0
store float %12, float* %13
%14 = fptrunc double %5 to float
%15 = getelementptr inbounds [2 x float], [2 x float]* %7, i64 0, i64 1
store float %14, float* %15
%16 = fcmp ogt double %2, 0.000000e+00
br i1 %16, label %17, label %43
17: ; preds = %6
%18 = getelementptr inbounds [2 x float], [2 x float]* %8, i64 0, i64 0
%19 = getelementptr inbounds [2 x float], [2 x float]* %8, i64 0, i64 1
br label %20
20: ; preds = %17, %20
%21 = phi double [ 0.000000e+00, %17 ], [ %41, %20 ]
%22 = call i32 @CalcDerivs(i32 2, float* %13, double %21, float* %18)
%23 = call double @sin(double %21)
%24 = load float, float* %13
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %21, double %23, float %24)
%26 = call double @sin(double %21)
%27 = load float, float* %13
%28 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %21, double %26, float %27)
%29 = load float, float* %13
%30 = fpext float %29 to double
%31 = load float, float* %18
%32 = fpext float %31 to double
%33 = call double @llvm.fmuladd.f64(double %3, double %32, double %30)
%34 = fptrunc double %33 to float
store float %34, float* %13
%35 = load float, float* %15
%36 = fpext float %35 to double
%37 = load float, float* %19
%38 = fpext float %37 to double
%39 = call double @llvm.fmuladd.f64(double %3, double %38, double %36)
%40 = fptrunc double %39 to float
store float %40, float* %15
%41 = fadd double %21, %3
%42 = fcmp olt double %41, %2
br i1 %42, label %20, label %43
43: ; preds = %20, %6
ret i32 undef
}