#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);
double sin(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%e\t%e\n", sin(t), y[0]);
  for (i = 1; i * step <= tmax; i++) {
    t = i * step;
    runge4(t, y, step);
    fprintf(file, "%f\t%e\t%e\n", t, sin(t), y[0]);
    printf("%f\t%e\t%e\n", t, sin(t), y[0]);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<RK4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    0xe70(%rip),%rsi
call   1080 <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),%rax
mov    %rax,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <sin@plt>
mov    -0x58(%rbp),%rdi
movsd  -0x40(%rbp),%xmm1
lea    0xe33(%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     128e <RK4+0x12e>
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),%rax
mov    %rax,-0x70(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <sin@plt>
mov    -0x70(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
lea    0xdbf(%rip),%rsi
mov    $0x3,%al
call   1060 <fprintf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
lea    0xd90(%rip),%rdi
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11dd <RK4+0x7d>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RK4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
movsd  %xmm4,0x40(%rsp)
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x38(%rsp)
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x38(%rsp),%xmm0
call   1070 <sin@plt>
lea    0xe41(%rip),%rsi
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1060 <fprintf@plt>
movsd  0x18(%rsp),%xmm1
ucomisd 0x10(%rsp),%xmm1
jb     1279 <RK4+0x119>
mov    $0x2,%ebp
lea    0x20(%rsp),%r14
lea    0xe17(%rip),%rbx
movsd  0x10(%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
movsd  0x10(%rsp),%xmm1
call   1030 <runge4@plt>
movsd  0x8(%rsp),%xmm0
call   1070 <sin@plt>
movaps %xmm0,%xmm1
movsd  0x20(%rsp),%xmm2
mov    %r15,%rdi
mov    %rbx,%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x3,%al
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
call   1070 <sin@plt>
movaps %xmm0,%xmm1
movsd  0x20(%rsp),%xmm2
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x10(%rsp),%xmm0
add    $0x1,%ebp
ucomisd %xmm0,%xmm1
jae    1200 <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 = [2 x i8] c"w\00"
@.str.1 = [9 x i8] c"0\09%e\09%e\0A\00"
@.str.2 = [10 x i8] c"%f\09%e\09%e\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 = load double, double* %8
%24 = call double @sin(double %23)
%25 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%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 = load double, double* %8
%47 = call double @sin(double %46)
%48 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%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 = load double, double* %8
%53 = call double @sin(double %52)
%54 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%55 = load double, double* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, 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%e\09%e\0A\00"
@.str.2 = [10 x i8] c"%f\09%e\09%e\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 double @sin(double %1)
%13 = 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 %12, double %4)
%14 = fcmp ugt double %3, %2
br i1 %14, label %29, label %15
15: ; preds = %6, %15
%16 = phi double [ %27, %15 ], [ %3, %6 ]
%17 = phi i32 [ %25, %15 ], [ 1, %6 ]
%18 = call i32 @runge4(double %16, double* %10, double %3)
%19 = call double @sin(double %16)
%20 = load double, double* %10
%21 = 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 %16, double %19, double %20)
%22 = call double @sin(double %16)
%23 = load double, double* %10
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, 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, %3
%28 = fcmp ugt double %27, %2
br i1 %28, label %29, label %15
29: ; preds = %15, %6
%30 = call i32 @fclose(i32* %9)
ret void
}