#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(double t, double tmax, double step, double x, double v) {
  float yexact, ystar;
  float xs[4], k1[4];
  int i;
  FILE *file;
  file = fopen("out_euler.txt", "w+");
  xs[0] = x;
  xs[1] = v;
  for (t = 0; t < tmax; t = t + step) {
    CalcDerivs(4, xs, t, k1);
    ystar = xs[0];
    printf("%f\t%f\t%f\n", t, sin(t), ystar);
    fprintf(file, "%f\t%f\t%f\n", t, sin(t), ystar);
    for (i = 0; i < 4; i++) {
      xs[i] = xs[i] + step * k1[i];
    }
  }
}


x86 assembly (clang, -O0):
<euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12bf <euler+0x16f>
lea    -0x50(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
lea    -0x60(%rbp),%rdx
mov    $0x4,%edi
call   1040 <CalcDerivs@plt>
movss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
movss  -0x38(%rbp),%xmm2
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <sin@plt>
mov    -0x80(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
movss  -0x38(%rbp),%xmm2
lea    0xdc6(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jge    12a6 <euler+0x156>
movslq -0x64(%rbp),%rax
movss  -0x50(%rbp,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movslq -0x64(%rbp),%rax
movss  -0x60(%rbp,%rax,4),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x64(%rbp),%rax
movss  %xmm0,-0x50(%rbp,%rax,4)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1257 <euler+0x107>
jmp    12ab <euler+0x15b>
movsd  -0x10(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11af <euler+0x5f>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
movsd  %xmm4,(%rsp)
movsd  %xmm3,0x8(%rsp)
movapd %xmm2,0x30(%rsp)
movsd  %xmm1,0x28(%rsp)
lea    0xe87(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
movsd  0x28(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
xorps  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    12a0 <euler+0x150>
mov    %rax,%r12
movapd 0x30(%rsp),%xmm2
unpcklpd %xmm2,%xmm2
movapd %xmm2,0x50(%rsp)
lea    0x10(%rsp),%r14
lea    0x40(%rsp),%r15
lea    0xe36(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    $0x4,%edi
mov    %r14,%rsi
movsd  (%rsp),%xmm0
mov    %r15,%rdx
call   1040 <CalcDerivs@plt>
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  (%rsp),%xmm0
movss  0x8(%rsp),%xmm2
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
mov    %r12,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movss  0x8(%rsp),%xmm2
call   1050 <fprintf@plt>
cvtps2pd 0x18(%rsp),%xmm0
cvtps2pd 0x10(%rsp),%xmm1
cvtps2pd 0x48(%rsp),%xmm2
cvtps2pd 0x40(%rsp),%xmm3
movapd 0x50(%rsp),%xmm4
mulpd  %xmm4,%xmm3
mulpd  %xmm4,%xmm2
addpd  %xmm0,%xmm2
cvtpd2ps %xmm2,%xmm0
addpd  %xmm1,%xmm3
cvtpd2ps %xmm3,%xmm1
unpcklpd %xmm0,%xmm1
movsd  (%rsp),%xmm0
movapd %xmm1,0x10(%rsp)
movsd  0x28(%rsp),%xmm1
addsd  0x30(%rsp),%xmm0
ucomisd %xmm0,%xmm1
ja     11e0 <euler+0x90>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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