#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double, ...);
int /*<<< orphan*/ printf(char *, double, double, double);
int /*<<< orphan*/ runge4(double, double *, double);
void RK4(double t, double tmax, double step, double x_0, double v_0) {
  double y[4];
  int i;
  FILE *file;
  file = fopen("RK4.txt", "w");
  y[0] = 1;
  y[1] = 0;
  y[2] = 0;
  y[3] = .1;
  fprintf(file, "0\t%f\t%f\n", y[1], y[0]);
  for (i = 1; i * step <= tmax; i++) {
    t = i * step;
    runge4(t, y, step);
    fprintf(file, "%f\t%f\t%f\n", t, y[1], y[0]);
    printf("%f\t%f\t%f\n", t, y[0], y[1]);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<RK4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
lea    0xe98(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x60(%rbp)
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe53(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x60(%rbp),%rdi
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
lea    0xe53(%rip),%rsi
mov    $0x2,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x54(%rbp)
cvtsi2sdl -0x54(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     125a <RK4+0x10a>
cvtsi2sdl -0x54(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x50(%rbp),%rdi
movsd  -0x18(%rbp),%xmm1
call   1030 <runge4@plt>
mov    -0x60(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
lea    0xdf9(%rip),%rsi
mov    $0x3,%al
call   1060 <fprintf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11d5 <RK4+0x85>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RK4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
lea    0xe9b(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
movabs $0x3ff0000000000000,%rax
mov    %rax,0x20(%rsp)
xorpd  %xmm0,%xmm0
movupd %xmm0,0x28(%rsp)
movabs $0x3fb999999999999a,%rax
99 b9 3f
mov    %rax,0x38(%rsp)
lea    0xe67(%rip),%rsi
movsd  0xe4d(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x2,%al
call   1060 <fprintf@plt>
movsd  0x10(%rsp),%xmm1
ucomisd 0x8(%rsp),%xmm1
jb     1259 <RK4+0x109>
mov    $0x2,%ebp
lea    0x20(%rsp),%r14
lea    0xe37(%rip),%rbx
movsd  0x8(%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x18(%rsp)
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm1
call   1030 <runge4@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
mov    %r15,%rdi
mov    %rbx,%rsi
movsd  0x18(%rsp),%xmm0
mov    $0x3,%al
call   1060 <fprintf@plt>
movsd  0x20(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
mov    %rbx,%rdi
movsd  0x18(%rsp),%xmm0
call   1050 <printf@plt>
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
add    $0x1,%ebp
ucomisd %xmm0,%xmm1
jae    11f0 <RK4+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"RK4.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [9 x i8] c"0\09%f\09%f\0A\00"
@.str.3 = [10 x i8] c"%f\09%f\09%f\0A\00"
define void @RK4(double %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca [4 x double]
%12 = alloca i32
%13 = alloca i32*
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
%14 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %13
%15 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
store double 1.000000e+00, double* %15
%16 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 1
store double 0.000000e+00, double* %16
%17 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 2
store double 0.000000e+00, double* %17
%18 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 3
store double 1.000000e-01, double* %18
%19 = load i32*, i32** %13
%20 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 1
%21 = load double, double* %20
%22 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%23 = load double, double* %22
%24 = call i32 (i32*, i8*, double, double, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %21, double %23)
store i32 1, i32* %12
br label %25
25: ; preds = %54, %5
%26 = load i32, i32* %12
%27 = sitofp i32 %26 to double
%28 = load double, double* %8
%29 = fmul double %27, %28
%30 = load double, double* %7
%31 = fcmp ole double %29, %30
br i1 %31, label %32, label %57
32: ; preds = %25
%33 = load i32, i32* %12
%34 = sitofp i32 %33 to double
%35 = load double, double* %8
%36 = fmul double %34, %35
store double %36, double* %6
%37 = load double, double* %6
%38 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%39 = load double, double* %8
%40 = call i32 @runge4(double %37, double* %38, double %39)
%41 = load i32*, i32** %13
%42 = load double, double* %6
%43 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 1
%44 = load double, double* %43
%45 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%46 = load double, double* %45
%47 = call i32 (i32*, i8*, double, double, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %42, double %44, double %46)
%48 = load double, double* %6
%49 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%50 = load double, double* %49
%51 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 1
%52 = load double, double* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %48, double %50, double %52)
br label %54
54: ; preds = %32
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %25
57: ; preds = %25
%58 = load i32*, i32** %13
%59 = call i32 @fclose(i32* %58)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"RK4.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [9 x i8] c"0\09%f\09%f\0A\00"
@.str.3 = [10 x i8] c"%f\09%f\09%f\0A\00"
define void @RK4(double %0, double %1, double %2, double %3, double %4) {
%6 = alloca [4 x double]
%7 = bitcast [4 x double]* %6 to i8*
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
store double 1.000000e+00, double* %9
%10 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 1
%11 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 3
%12 = bitcast double* %10 to i8*
store double 1.000000e-01, double* %11
%13 = tail call i32 (i32*, i8*, double, double, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double 0.000000e+00, double 1.000000e+00)
%14 = fcmp ugt double %2, %1
br i1 %14, label %29, label %15
15: ; preds = %5, %15
%16 = phi double [ %27, %15 ], [ %2, %5 ]
%17 = phi i32 [ %25, %15 ], [ 1, %5 ]
%18 = call i32 @runge4(double %16, double* %9, double %2)
%19 = load double, double* %10
%20 = load double, double* %9
%21 = call i32 (i32*, i8*, double, double, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %16, double %19, double %20)
%22 = load double, double* %9
%23 = load double, double* %10
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %16, double %22, double %23)
%25 = add nuw nsw i32 %17, 1
%26 = sitofp i32 %25 to double
%27 = fmul double %26, %2
%28 = fcmp ugt double %27, %1
br i1 %28, label %29, label %15
29: ; preds = %15, %5
%30 = call i32 @fclose(i32* %8)
ret void
}