#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 *, float, float *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, float, double, float);
int /*<<< orphan*/ printf(char *, ...);
double sin(float);
int main() {
  float yexact, ystar;
  float x[2], k1[2];
  float h = 0.1, t = 0.0, tmax = 15.0;
  int i;
  FILE *file;
  file = fopen("out_euler.txt", "w+");
  printf("Welcome to Euler - the ODE solver\n");
  x[0] = 0.0;
  x[1] = 1.0;
  printf("time(ms) input output\n");
  for (t = 0; t < tmax; t = t + h) {
    CalcDerivs(2, x, t, k1);
    ystar = x[0];
    printf("%7.2f %7.4f %7.4f\n", t, sin(t), ystar);
    fprintf(file, "%7.2f %7.4f %7.4f\n", t, sin(t), ystar);
    for (i = 0; i < 2; i++) {
      x[i] = x[i] + h * k1[i];
    }
  }
  printf("Program is done.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xea1(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xe88(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
lea    0xe84(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe4a(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm1
movss  -0x28(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    12d8 <main+0x188>
lea    -0x14(%rbp),%rsi
movss  -0x24(%rbp),%xmm0
lea    -0x1c(%rbp),%rdx
mov    $0x2,%edi
call   1040 <CalcDerivs@plt>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movss  -0x24(%rbp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe22(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x24(%rbp),%xmm0
call   1060 <sin@plt>
mov    -0x48(%rbp),%rdi
movaps %xmm0,%xmm1
movss  -0x3c(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
lea    0xde7(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    12bf <main+0x16f>
movslq -0x2c(%rbp),%rax
movss  -0x14(%rbp,%rax,4),%xmm1
movss  -0x20(%rbp),%xmm0
movslq -0x2c(%rbp),%rax
movss  -0x1c(%rbp,%rax,4),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movslq -0x2c(%rbp),%rax
movss  %xmm0,-0x14(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    127c <main+0x12c>
jmp    12c4 <main+0x174>
movss  -0x24(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11d1 <main+0x81>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe96(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
movabs $0x3f80000000000000,%rax
mov    %rax,0xc(%rsp)
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
lea    0xc(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0xe5d(%rip),%rbx
nopl   0x0(%rax)
movss  %xmm0,0x8(%rsp)
mov    $0x2,%edi
mov    %r14,%rsi
movss  0x8(%rsp),%xmm0
mov    %r15,%rdx
call   1050 <CalcDerivs@plt>
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x14(%rsp)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
movss  0x8(%rsp),%xmm0
call   1070 <sin@plt>
movaps %xmm0,%xmm1
movss  0x14(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
mov    %rbx,%rdi
movsd  0x20(%rsp),%xmm0
mov    $0x3,%al
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm0
call   1070 <sin@plt>
movaps %xmm0,%xmm1
mov    %r12,%rdi
mov    %rbx,%rsi
movss  0x8(%rsp),%xmm0
movss  0x14(%rsp),%xmm2
call   1060 <fprintf@plt>
movss  0x18(%rsp),%xmm0
movss  0xdaa(%rip),%xmm1
mulss  %xmm1,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x1c(%rsp),%xmm0
mulss  %xmm1,%xmm0
addss  0x10(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
movss  0x8(%rsp),%xmm0
addss  %xmm1,%xmm0
movss  0xd76(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     11c0 <main+0x60>
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%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 = [35 x i8] c"Welcome to Euler - the ODE solver\0A\00"
@.str.3 = [23 x i8] c"time(ms) input output\0A\00"
@.str.4 = [19 x i8] c"%7.2f %7.4f %7.4f\0A\00"
@.str.5 = [18 x i8] c"Program is done.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca [2 x float]
%5 = alloca [2 x float]
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %1
store float 0x3FB99999A0000000, float* %6
store float 0.000000e+00, float* %7
store float 1.500000e+01, float* %8
%11 = 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* %11, i32** %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [2 x float], [2 x float]* %4, i64 0, i64 0
store float 0.000000e+00, float* %13
%14 = getelementptr inbounds [2 x float], [2 x float]* %4, i64 0, i64 1
store float 1.000000e+00, float* %14
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store float 0.000000e+00, float* %7
br label %16
16: ; preds = %61, %0
%17 = load float, float* %7
%18 = load float, float* %8
%19 = fcmp olt float %17, %18
br i1 %19, label %20, label %65
20: ; preds = %16
%21 = getelementptr inbounds [2 x float], [2 x float]* %4, i64 0, i64 0
%22 = load float, float* %7
%23 = getelementptr inbounds [2 x float], [2 x float]* %5, i64 0, i64 0
%24 = call i32 @CalcDerivs(i32 2, float* %21, float %22, float* %23)
%25 = getelementptr inbounds [2 x float], [2 x float]* %4, i64 0, i64 0
%26 = load float, float* %25
store float %26, float* %3
%27 = load float, float* %7
%28 = fpext float %27 to double
%29 = load float, float* %7
%30 = call double @sin(float %29)
%31 = load float, float* %3
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %28, double %30, double %32)
%34 = load i32*, i32** %10
%35 = load float, float* %7
%36 = load float, float* %7
%37 = call double @sin(float %36)
%38 = load float, float* %3
%39 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), float %35, double %37, float %38)
store i32 0, i32* %9
br label %40
40: ; preds = %57, %20
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 2
br i1 %42, label %43, label %60
43: ; preds = %40
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2 x float], [2 x float]* %4, i64 0, i64 %45
%47 = load float, float* %46
%48 = load float, float* %6
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [2 x float], [2 x float]* %5, i64 0, i64 %50
%52 = load float, float* %51
%53 = call float @llvm.fmuladd.f32(float %48, float %52, float %47)
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [2 x float], [2 x float]* %4, i64 0, i64 %55
store float %53, float* %56
br label %57
57: ; preds = %43
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %40
60: ; preds = %40
br label %61
61: ; preds = %60
%62 = load float, float* %7
%63 = load float, float* %6
%64 = fadd float %62, %63
store float %64, float* %7
br label %16
65: ; preds = %16
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str = [14 x i8] c"out_euler.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.4 = [19 x i8] c"%7.2f %7.4f %7.4f\0A\00"
@str = [34 x i8] c"Welcome to Euler - the ODE solver\00"
@str.6 = [22 x i8] c"time(ms) input output\00"
@str.7 = [17 x i8] c"Program is done.\00"
define i32 @main() {
%1 = alloca [2 x float]
%2 = alloca [2 x float]
%3 = bitcast [2 x float]* %1 to i8*
%4 = bitcast [2 x float]* %2 to i8*
%5 = 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))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds [2 x float], [2 x float]* %1, i64 0, i64 0
store float 0.000000e+00, float* %7
%8 = getelementptr inbounds [2 x float], [2 x float]* %1, i64 0, i64 1
store float 1.000000e+00, float* %8
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%10 = getelementptr inbounds [2 x float], [2 x float]* %2, i64 0, i64 0
%11 = getelementptr inbounds [2 x float], [2 x float]* %2, i64 0, i64 1
br label %12
12: ; preds = %0, %12
%13 = phi float [ 0.000000e+00, %0 ], [ %28, %12 ]
%14 = call i32 @CalcDerivs(i32 2, float* %7, float %13, float* %10)
%15 = load float, float* %7
%16 = fpext float %13 to double
%17 = call double @sin(float %13)
%18 = fpext float %15 to double
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %16, double %17, double %18)
%20 = call double @sin(float %13)
%21 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), float %13, double %20, float %15)
%22 = load float, float* %7
%23 = load float, float* %10
%24 = call float @llvm.fmuladd.f32(float %23, float 0x3FB99999A0000000, float %22)
store float %24, float* %7
%25 = load float, float* %8
%26 = load float, float* %11
%27 = call float @llvm.fmuladd.f32(float %26, float 0x3FB99999A0000000, float %25)
store float %27, float* %8
%28 = fadd float %13, 0x3FB99999A0000000
%29 = fcmp olt float %28, 1.500000e+01
br i1 %29, label %12, label %30
30: ; preds = %12
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}