void velocity_verlet(double *time, double *vel, double pos, double acc,
                     double dt) {
  *vel = 0.0;
  *time = 0.0;
  while (pos > 0) {
    *time += dt;
    pos += (*vel) * dt + 0.5 * acc * dt * dt;
    *vel += acc * dt;
  }
}


x86 assembly (clang, -O0):
<velocity_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)
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    11ad <velocity_verlet+0xad>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xe97(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%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    1131 <velocity_verlet+0x31>
pop    %rbp
ret

x86 assembly (clang, -O2):
<velocity_verlet>:
movq   $0x0,(%rsi)
movq   $0x0,(%rdi)
xorpd  %xmm5,%xmm5
ucomisd %xmm5,%xmm0
jbe    119e <velocity_verlet+0x9e>
movsd  0xedc(%rip),%xmm3
mulsd  %xmm1,%xmm3
mulsd  %xmm2,%xmm3
mulsd  %xmm2,%xmm3
movapd %xmm2,%xmm4
addsd  %xmm5,%xmm4
movsd  %xmm4,(%rdi)
movsd  (%rsi),%xmm6
movapd %xmm6,%xmm4
mulsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
mulsd  %xmm2,%xmm1
addsd  %xmm1,%xmm6
movsd  %xmm6,(%rsi)
ucomisd %xmm5,%xmm4
jbe    119e <velocity_verlet+0x9e>
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
movsd  (%rdi),%xmm5
addsd  %xmm2,%xmm5
movsd  %xmm5,(%rdi)
movsd  (%rsi),%xmm5
movapd %xmm5,%xmm6
mulsd  %xmm2,%xmm6
addsd  %xmm3,%xmm6
addsd  %xmm6,%xmm4
addsd  %xmm1,%xmm5
movsd  %xmm5,(%rsi)
ucomisd %xmm0,%xmm4
ja     1170 <velocity_verlet+0x70>
ret

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

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