/* Geometric Series computes x = sum(z^k)[k=0..k-1], y = z^(k-1) */ void abort() { }; extern void abort(); extern int __VERIFIER_nondet_int(); void assume_abort_if_not(int cond) { if(!cond) {abort();} } /*@ requires ((1 <= cond)) && (cond != 0); ensures ((1 <= cond)) && (1); @*/ void __VERIFIER_assert(int cond) { if (!(cond)) { ERROR: {/*@ assert(0); */;} } return; } int main() { int z, a, k; long long x, y, c, az; z = __VERIFIER_nondet_int(); assume_abort_if_not(z>=0 && z<=2); a = __VERIFIER_nondet_int(); assume_abort_if_not(a>=0 && a<=2); k = __VERIFIER_nondet_int(); assume_abort_if_not(k>=0 && k<=2); x = a; y = 1; c = 1; az = (long long) a * z; /*@ loop invariant (((((__int128) y * az) + x) == (((__int128) z * x) + a))); @*/ while (1) { __VERIFIER_assert(z*x - x + a - az*y == 0); if (!(c < k)) break; c = c + 1; x = x * z + a; y = y * z; } __VERIFIER_assert(z*x - x + a - az*y == 0); return x; }