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


x86 assembly (clang, -O0):
<RK4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe50(%rip),%rsi
mov    $0x2,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x44(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1245 <RK4+0xf5>
cvtsi2sdl -0x44(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x40(%rbp),%rdi
movsd  -0x20(%rbp),%xmm1
call   1030 <runge4@plt>
mov    -0x50(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
lea    0xdf6(%rip),%rsi
mov    $0x3,%al
call   1060 <fprintf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11c0 <RK4+0x70>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RK4>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movsd  %xmm4,0x8(%rsp)
movsd  %xmm3,0x28(%rsp)
movsd  %xmm2,(%rsp)
movsd  %xmm1,0x20(%rsp)
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
movsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%al
call   1060 <fprintf@plt>
movsd  0x20(%rsp),%xmm1
ucomisd (%rsp),%xmm1
jb     1247 <RK4+0xf7>
mov    $0x2,%ebp
lea    0x10(%rsp),%r14
lea    0xe3e(%rip),%r15
lea    0xe41(%rip),%r12
movsd  (%rsp),%xmm0
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
movsd  (%rsp),%xmm1
call   1030 <runge4@plt>
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
mov    %rbx,%rdi
mov    %r15,%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x3,%al
call   1060 <fprintf@plt>
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
mov    %r12,%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <printf@plt>
movsd  0x20(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  (%rsp),%xmm0
add    $0x1,%ebp
ucomisd %xmm0,%xmm1
jae    11e0 <RK4+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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