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


x86 assembly (clang, -O0):
<verlet>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ad <verlet+0xad>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    112c <verlet+0x2c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<verlet>:
movq   $0x0,(%rdi)
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jbe    1152 <verlet+0x52>
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
xorpd  %xmm4,%xmm4
movapd %xmm0,%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm0,%xmm6
addsd  %xmm2,%xmm4
addsd  %xmm0,%xmm0
subsd  %xmm5,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
movapd %xmm6,%xmm5
ja     1130 <verlet+0x30>
movsd  %xmm4,(%rdi)
ret

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

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