(bind-func advance
(lambda (nbodies:i64 bodies:planet* dt)
(let ((i:i64 0) (j:i64 0)
(dx 0.0) (dy 0.0) (dz 0.0) (distance 0.0) (mag 0.0)
(b:planet* null)
(b2:planet* null)
(b3:planet* null))
(dotimes (i nbodies)
(set! b (pref-ptr bodies i))
(dotimes (j (+ i 1) (- nbodies (+ i 1)))
(set! b2 (pref-ptr bodies j))
(set! dx (- (tref b 0) (tref b2 0)))
(set! dy (- (tref b 1) (tref b2 1)))
(set! dz (- (tref b 2) (tref b2 2)))
(set! distance (sqrt (+ (* dx dx) (* dy dy) (* dz dz))))
(set! mag (/ dt (* distance distance distance)))
(tset! b 3 (- (tref b 3) (* dx (tref b2 6) mag)))
(tset! b 4 (- (tref b 4) (* dy (tref b2 6) mag)))
(tset! b 5 (- (tref b 5) (* dz (tref b2 6) mag)))
(tset! b2 3 (+ (tref b2 3) (* dx (tref b 6) mag)))
(tset! b2 4 (+ (tref b2 4) (* dy (tref b 6) mag)))
(tset! b2 5 (+ (tref b2 5) (* dz (tref b 6) mag)))))
(dotimes (i nbodies)
(set! b3 (pref-ptr bodies i))
(tset! b3 0 (+ (tref b3 0) (* dt (tref b3 3))))
(tset! b3 1 (+ (tref b3 1) (* dt (tref b3 4))))
(tset! b3 2 (+ (tref b3 2) (* dt (tref b3 5)))))
void)))