void stormer_verlet(double *time, double *vel, double pos, double acc,
                    double dt) {
  double prev_pos, temp_pos;
  prev_pos = pos;
  *vel = 0.0;
  *time = 0.0;
  while (pos > 0) {
    *time += dt;
    temp_pos = pos;
    pos = pos * 2 - prev_pos + acc * dt * dt;
    prev_pos = temp_pos;
    *vel += acc * dt;
  }
}


x86 assembly (clang, -O0):
<stormer_verlet>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11da <stormer_verlet+0xda>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
jmp    113b <stormer_verlet+0x3b>
pop    %rbp
ret

x86 assembly (clang, -O2):
<stormer_verlet>:
movq   $0x0,(%rsi)
movq   $0x0,(%rdi)
xorpd  %xmm5,%xmm5
ucomisd %xmm5,%xmm0
jbe    1192 <stormer_verlet+0x92>
mulsd  %xmm2,%xmm1
movapd %xmm2,%xmm3
addsd  %xmm5,%xmm3
movsd  %xmm3,(%rdi)
movapd %xmm0,%xmm3
addsd  %xmm0,%xmm3
subsd  %xmm0,%xmm3
movapd %xmm1,%xmm4
mulsd  %xmm2,%xmm4
addsd  %xmm4,%xmm3
movsd  (%rsi),%xmm6
addsd  %xmm1,%xmm6
movsd  %xmm6,(%rsi)
ucomisd %xmm5,%xmm3
jbe    1192 <stormer_verlet+0x92>
xorpd  %xmm5,%xmm5
cs nopw 0x0(%rax,%rax,1)
movapd %xmm3,%xmm6
movsd  (%rdi),%xmm7
addsd  %xmm2,%xmm7
movsd  %xmm7,(%rdi)
addsd  %xmm3,%xmm3
subsd  %xmm0,%xmm3
addsd  %xmm4,%xmm3
movsd  (%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsi)
ucomisd %xmm5,%xmm3
movapd %xmm6,%xmm0
ja     1160 <stormer_verlet+0x60>
ret

LLVM IR (-O0):
define void @stormer_verlet(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 double
%12 = alloca double
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
%13 = load double, double* %8
store double %13, double* %11
%14 = load double*, double** %7
store double 0.000000e+00, double* %14
%15 = load double*, double** %6
store double 0.000000e+00, double* %15
br label %16
16: ; preds = %19, %5
%17 = load double, double* %8
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %40
19: ; preds = %16
%20 = load double, double* %10
%21 = load double*, double** %6
%22 = load double, double* %21
%23 = fadd double %22, %20
store double %23, double* %21
%24 = load double, double* %8
store double %24, double* %12
%25 = load double, double* %8
%26 = load double, double* %11
%27 = fneg double %26
%28 = call double @llvm.fmuladd.f64(double %25, double 2.000000e+00, double %27)
%29 = load double, double* %9
%30 = load double, double* %10
%31 = fmul double %29, %30
%32 = load double, double* %10
%33 = call double @llvm.fmuladd.f64(double %31, double %32, double %28)
store double %33, double* %8
%34 = load double, double* %12
store double %34, double* %11
%35 = load double, double* %9
%36 = load double, double* %10
%37 = load double*, double** %7
%38 = load double, double* %37
%39 = call double @llvm.fmuladd.f64(double %35, double %36, double %38)
store double %39, double* %37
br label %16
40: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @stormer_verlet(double* nocapture %0, double* nocapture %1, double %2, double %3, double %4) {
store double 0.000000e+00, double* %1
store double 0.000000e+00, double* %0
%6 = fcmp ogt double %2, 0.000000e+00
br i1 %6, label %7, label %27
7: ; preds = %5
%8 = fmul double %3, %4
%9 = fadd double %4, 0.000000e+00
store double %9, double* %0
%10 = fneg double %2
%11 = tail call double @llvm.fmuladd.f64(double %2, double 2.000000e+00, double %10)
%12 = tail call double @llvm.fmuladd.f64(double %8, double %4, double %11)
%13 = load double, double* %1
%14 = tail call double @llvm.fmuladd.f64(double %3, double %4, double %13)
store double %14, double* %1
%15 = fcmp ogt double %12, 0.000000e+00
br i1 %15, label %16, label %27
16: ; preds = %7, %16
%17 = phi double [ %23, %16 ], [ %12, %7 ]
%18 = phi double [ %17, %16 ], [ %2, %7 ]
%19 = load double, double* %0
%20 = fadd double %19, %4
store double %20, double* %0
%21 = fneg double %18
%22 = tail call double @llvm.fmuladd.f64(double %17, double 2.000000e+00, double %21)
%23 = tail call double @llvm.fmuladd.f64(double %8, double %4, double %22)
%24 = load double, double* %1
%25 = tail call double @llvm.fmuladd.f64(double %3, double %4, double %24)
store double %25, double* %1
%26 = fcmp ogt double %23, 0.000000e+00
br i1 %26, label %16, label %27
27: ; preds = %16, %7, %5
ret void
}