Dataset Viewer
file_content
stringlengths 65
76k
| goals
int64 1
283
|
---|---|
/*@ assigns \nothing;
ensures \result == \min(\max(min, v), max);
*/
int clamp(int v, int min, int max)
{
int low = v > min ? v : min;
return low < max ? low : max;
}
| 7 |
/*@ requires n > 0;
assigns \nothing;
ensures 0 <= \result && \result < n;
*/
int pick_index(int n) { return 0; }
/*@ requires n > 0 && \valid(p+ (0..n-1));
assigns \nothing;
*/
int pick_element(int* p, int n) {
int i = pick_index(n);
//@ assert (0 <= i && i < n);
return p[i];
}
/*@
requires \valid(p);
assigns \nothing;
ensures \result == p[0];
*/
int pick_first(int* p) {
return p[0];
}
| 18 |
/*@ requires n>0 && \valid(s+(0..n-1)) && \valid(t+(0..n-1));
assigns s[0..n-1];
ensures \forall integer i; 0<=i<n ==> s[i]==t[i];
*/
void copy1(int s[], int t[], int n) {
/*@ loop invariant 0<=i<=n;
loop invariant \forall integer j; 0<=j<i ==> s[j]==t[j];
loop variant n-i;
*/
for(int i=0;i<n;i++){
s[i]=t[i];
}
} | 18 |
#include <limits.h>
#include <string.h>
/*@ predicate matcher_ab(char * x0) = ((((x0[0]=='\0')) ? (\false) : (((x0[0]=='a') &&
\false))) || (((x0[0]=='\0')) ? (\false) : (((x0[0]=='a') &&
((((x0+1)[0]=='\0')) ? (\false) : ((((x0+1)[0]=='b') &&
(((x0+1)+1)[0]=='\0'))))))));*/
/*@
requires ((strlen(x0)>=0) &&
\valid(x0+(0..(strlen(x0)+1)-1)));
assigns \nothing;
ensures \result <==> matcher_ab(x0);
*/
int matcher_ab(char * x0) {
char x2 = x0[0];
int x3 = x2 == '\0';
int x7;
if (x3) {
x7 = 0/*false*/;
} else {
int x4 = x2 == 'a';
int x6;
if (x4) {
x6 = 0/*false*/;
} else {
x6 = 0/*false*/;
}
x7 = x6;
}
int x17;
if (x3) {
x17 = 0/*false*/;
} else {
int x4 = x2 == 'a';
int x16;
if (x4) {
char *x5 = x0+1;
char x8 = x5[0];
int x9 = x8 == '\0';
int x15;
if (x9) {
x15 = 0/*false*/;
} else {
int x10 = x8 == 'b';
int x14;
if (x10) {
char *x11 = x5+1;
char x12 = x11[0];
int x13 = x12 == '\0';
x14 = x13;
} else {
x14 = 0/*false*/;
}
x15 = x14;
}
x16 = x15;
} else {
x16 = 0/*false*/;
}
x17 = x16;
}
int x18 = x7 || x17;
return x18;
}
| 21 |
/*@
requires n>0;
requires 0<=k<n;
requires\valid(a+ (0..n-1));
ensures\forall integer i;
0<= i<=k ==>a[k]>=a[i];
*/
void q2(int a[],int n,int k)
{
/*@
loop invariant\forall integer i;
0<= i<j ==> a[j]>=a[i];loop invariant 0<=j<=k;
loop assigns j,a[0..j+1];
loop variant k-j;
*/
for (int j=0;j<k;j++)
{
if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
} | 23 |
/*@
requires n>0;
requires\valid(a+ (0..n-1));
ensures\forall integer i;
0<= i<n-1 ==>a[n-1]>=a[i];
*/
void bubbleinnerloop(int a[], int n)
{
/*@
loop invariant\forall integer i;
0<= i<j ==> a[j]>=a[i];loop invariant 0<=j<=n-1;
loop assigns j,a[0..j+1];
loop variant n-1-j;
*/
for (int j = 0; j < n - 1; j++)
{
if (a[j] > a[j + 1])
{
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
| 24 |
#include <limits.h>
/*@
requires (\valid(x0+x1) &&
\valid(x0+x2));
ensures ((x0[x1]==\old(x0[x2])) &&
(x0[x2]==\old(x0[x1])));
assigns x0[x1], x0[x2];
*/
void inswap(int * x0, int x1, int x2) {
int x4 = x0[x1];
int x5 = x0[x2];
x0[x1] = x5;
x0[x2] = x4;
}
/*@
requires ((x26>0) &&
\valid(x25+(0..x26-1)));
ensures (\forall int x203; (((0<=x203) &&
(x203<(x26-1))) ==> (x25[x203]<=x25[(x203+1)])));
assigns x25[(0..x26-1)];
*/
void insort(int * x25, int x26) {
int x29 = x26;
/*@
loop invariant ((((0<=x29) &&
(x29<=x26)) &&
(\forall int x152; (((x29<=x152) &&
(x152<(x26-1))) ==> (x25[x152]<=x25[(x152+1)])))) &&
(\forall int x168; ((((0<=x168) &&
(x168<x29)) &&
(x29<=(x26-1))) ==> (x25[x168]<=x25[x29]))));
loop assigns x29, x25[(0..x26-1)];
loop variant x29;
*/
for (;;) {
int x30 = x29;
int x31 = x30 > 1;
if (!x31) break;
int x33 = 0;
int x34 = x29;
/*@
loop invariant ((((((((0<=x29) &&
(x29<=x26)) &&
(0<=x36)) &&
(x36<=x29)) &&
(0<=x33)) &&
(x33<=(x29-1))) &&
((x29-1)<x26)) &&
(\forall int x74; (((0<=x74) &&
(x74<x36)) ==> (x25[x74]<=x25[x33]))));
loop assigns x36, x33;
loop variant (x29-x36);
*/
for(int x36=0; x36 < x34; x36++) {
int x37 = x25[x36];
int x38 = x33;
int x39 = x25[x38];
int x40 = x37 >= x39;
if (x40) {
x33 = x36;
} else {
}
}
int x96 = x33;
int x95 = x34 - 1;
inswap(x25,x95,x96);
/*@assert (\forall int x98; ((((x29-1)<x98) &&
(x98<(x26-1))) ==> (x25[x98]<=x25[(x98+1)])));*/
/*@assert ((x29<=(x26-1)) ==> (x25[(x29-1)]<=x25[x29]));*/
/*@assert (\forall int x127; (((0<=x127) &&
(x127<x29)) ==> (x25[x127]<=x25[(x29-1)])));*/
x29 = x95;
}
}
| 37 |
#include<stdio.h>
enum type1 {scalene,isoscele,equilateral};
enum type2 {right,acute,obtuse};
/*@
requires a>=b &&a>=c;
behavior eq:
assumes a==b &&b==c;
ensures \result==equilateral;
behavior is:
assumes a==b && b!=c|| b==c && c!=a|| c==a && a!=b;
ensures \result==isoscele;
behavior sc:
assumes a!=b && b!=c && c!=a;
ensures \result==scalene;
complete behaviors;
disjoint behaviors;
*/
enum type1 func1(int a,int b,int c){
if(a==b && b==c) return equilateral;
else if(a==b || b==c || c==a) return isoscele;
else return scalene;
}
/*@
requires a>=b>0 && a>=c>0 && a*a<=10000000 && c*c<=10000000 && b*b<=10000000;
behavior ri:
assumes a*a==b*b+c*c;
ensures \result==right;
behavior ac:
assumes a*a<b*b+c*c;
ensures \result==acute;
behavior ob:
assumes a*a>b*b+c*c;
ensures \result==obtuse;
complete behaviors;
disjoint behaviors;
*/
enum type2 func2(int a,int b,int c){
//since a is assumed as hypotenuse
if(a*a==b*b+c*c) return right;
else if (a*a<b*b+c*c) return acute;
else return obtuse;
}
| 30 |
#define LENGTH 100
int vec[LENGTH];
int max;
/*@ requires \valid(u+(0..size-1)) && 0 < size;
@ ensures 0 <= \result < size &&
@ (\forall integer a; 0 <= a < size ==> u[a] <= u[\result]);
@ assigns max;
@*/
int maxarray(int u[], int size) {
int i = 1;
max = 0;
/*@ loop invariant
@ 0 <= max < i <= size &&
@ (\forall integer a;
@ 0 <= a < i ==> u[a] <= u[max]);
@ loop assigns i, max;
@ loop variant size-i;
@*/
while (i < size) {
if (u[i] > u[max]) { max = i; }
i++;
}
return max;
}
void main() {
max = maxarray(vec, LENGTH);
/*@ assert 0 <= max < LENGTH &&
@ (\forall integer a;
@ 0 <= a < LENGTH ==> vec[a] <= vec[max]);
@*/
}
| 17 |
/*@
requires n > 0;
requires \valid(t+(0..(n-1)));
ensures 0 <= \result < n;
ensures \forall integer k; 0 <= k < n ==> t[k] >= t[\result];
ensures \forall integer k; 0 <= k < \result ==> t[k] > t[\result];
*/
int min(int * t, int n) {
int minInd = 0, i =0;
/*@
loop assigns i, minInd;
loop invariant 0 <= i < n;
loop invariant 0 <= minInd < n;
loop invariant 0 <= minInd <= i;
loop invariant \forall integer k; 0 <= k <= i ==> t[minInd] <= t[k];
loop invariant \forall integer k; 0 <= k < minInd ==> t[k] > t[minInd];
loop variant n-1-i;
*/
while(i<n-1)
if (t[++i] < t[minInd])
minInd = i;
//@ assert i == n-1;
return minInd;
}
| 23 |
#include <limits.h>
/*@
assigns \nothing;
ensures (\result==(x0*x0));
*/
int square(int x0) {
int x2 = x0 * x0;
return x2;
}
/*@
assigns \nothing;
ensures (\result==(((x6*x6)*x6)*x6));
*/
int pow4(int x6) {
int x8 = square(x6);
int x9 = square(x8);
return x9;
}
/*@
assigns \nothing;
ensures (\result==(((x15*x15)*x15)*x15));
*/
int pow4b(int x15) {
int x17 = square(x15);
int x18 = x17 * x17;
return x18;
}
| 23 |
/*@ requires 0 <= from <= to;
@ requires \valid(s+(0..to-1));
@ ensures -1 == \result || from <= \result < to;
@ ensures \result == -1 ==>
@ (\forall int i; from <= i < to ==> s[i] != c);
@ ensures from <= \result < to ==>
@ s[\result] == c &&
@ (\forall int i; from <= i < \result ==> s[i] != c);
@ assigns \nothing;
@*/
static int indexOf(char* s, char c, int from, int to) {
/*@ loop invariant from <= k <= to;
@ loop invariant \forall int i; from <= i < k ==> s[i] != c;
@ loop assigns k;
@ loop variant to - k;
@*/
for(int k = from; k < to; k++) {
if(s[k] == c) {
return k;
}
}
return -1;
}
/*@ predicate replace_space_by_new_line{L1,L2}(char* s, int n) =
@ \forall int i; 0 <= i < n && \at(s[i], L1) != \at(s[i],L2) ==>
@ \at(s[i], L1) == ' ' && \at(s[i],L2) == '\n';
*/
/*@ predicate at_least_lineLength(char* s, int lineLength, int n) =
@ \forall int i,j; 0 <= i < j < n && s[i] == '\n' && s[j] == '\n' ==> j-i >= lineLength;
*/
/*@ requires lineLength > 0;
@ requires 0 < n;
@ requires \valid(s+(0..n-1));
@ requires \forall int i; 0 <= i < n ==> s[i] != '\n';
@ ensures replace_space_by_new_line{Pre,Post}(s,n);
@ ensures at_least_lineLength(s,lineLength,n);
@ assigns s[0 .. n -1];
@*/
void wrapLines_simpl(char* s, int lineLength, int n) {
int lastBreak = -1;
int lastSpace = indexOf(s, ' ', 0, n);
/*@ loop invariant -1 <= lastSpace < n;
@ loop invariant -1 <= lastBreak < n;
@ loop invariant lastSpace == -1 || (lastBreak < lastSpace < n && s[lastSpace] == ' ');
@ loop invariant \forall int i; lastBreak < i < n ==> \at(s[i], LoopEntry) == s[i];
@ loop invariant replace_space_by_new_line{LoopEntry,Here}(s,n);
@ loop invariant at_least_lineLength(s,lineLength,n);
@ loop assigns s[0..n-1],lastBreak,lastSpace;
@ loop variant lastSpace == -1 ? 0 : n + 1 - lastSpace;
@*/
while(lastSpace != -1) {
if(lastSpace - lastBreak > lineLength) {
s[lastSpace] = '\n';
lastBreak = lastSpace;
}
lastSpace = indexOf(s, ' ', lastSpace+1, n);
}
return;
}
/*@ predicate impossible_to_break(char* s, int length, int n) =
@ \forall int i; 0 <= i < n - length ==>
@ (\forall int j; i <= j <= i + length ==> s[j] != '\n') ==>
@ (\forall int j; i <= j <= i + length ==> s[j] != ' ');
*/
/*@ predicate break_largest{L1,L2}(char* s, int length, int n) =
@ \forall int a, b, c; 0 <= a < b < c < n &&
@ (a == -1 || \at(s[a],L2) == '\n') &&
@ \at(s[b],L2) == '\n' && \at(s[b],L1) == ' ' &&
@ (\at(s[c],L2) == ' ' || \at(s[c],L2) == '\n') ==>
@ c - a > length;
*/
/*@ requires 0 < length;
@ requires 0 < n < 2147483646; // the length of array is limited to MAX_INT -1 because of an overflow
@ requires \valid(s+(0..n-1));
@ ensures replace_space_by_new_line{Pre,Post}(s,n);
@ ensures impossible_to_break(s,length,n);
@ ensures break_largest{Pre,Post}(s, length, n);
@ assigns s[0 .. n-1];
@*/
void wrapLines(char* s, int length, int n) {
int lastChange = -1;
int lastSpace = -1;
/*@ loop invariant -1 <= lastSpace < n;
@ loop invariant -1 <= lastChange <= lastSpace;
@ loop invariant lastSpace <= lastChange + length + 1;
@ loop invariant lastChange == -1 || s[lastChange] == '\n';
@ loop invariant 0 <= lastSpace ==> \at(s[\at(lastSpace,Here)],LoopEntry) == ' ' || \at(s[\at(lastSpace,Here)],LoopEntry) == '\n';
@ loop invariant \forall int x; lastChange < x < n ==> s[x] == \at(s[x],LoopEntry);
@ loop invariant \forall int x; lastChange < x <= lastSpace ==> s[x] != '\n';
@ loop invariant replace_space_by_new_line{LoopEntry,Here}(s,n);
@ loop invariant impossible_to_break(s, length, lastSpace);
@ loop invariant \forall int a, b, c; 0 <= a < b < c < n &&
b <= lastChange && (a == -1 || s[a] == '\n') &&
s[b] == '\n' && \at(s[b],LoopEntry) == ' ' &&
(s[c] == ' ' || s[c] == '\n') ==> c - a > length;
@ loop assigns s[0 .. n-1],lastChange, lastSpace;
@ loop variant 2*n - lastSpace - lastChange;
@*/
while(1) {
int nextSpace = indexOf(s, ' ', lastSpace + 1,n);
int nextNewLine = indexOf(s, '\n', lastSpace + 1,n);
if(nextSpace == -1) {
/*n - lastChange can overflow if the array contain no space and is of size MAX_INT*/
if(n - lastChange > length &&
(nextNewLine - lastChange > length || nextNewLine == -1) &&
lastSpace >= 0) {
s[lastSpace] = '\n';
}
return;
}
if(0 <= nextNewLine && nextNewLine < nextSpace) {
if(nextNewLine - lastChange > length && lastSpace >= 0) {
s[lastSpace] = '\n';
}
lastChange = lastSpace = nextNewLine;
} else {
if(nextSpace - lastChange > length) {
if(lastChange == lastSpace) {
s[nextSpace] = '\n';
lastChange = lastSpace = nextSpace;
} else {
s[lastSpace] = '\n';
lastChange = lastSpace;
}
} else {
lastSpace = nextSpace;
}
}
}
return;
}
| 114 |
#include <limits.h>
#include <string.h>
/*@
requires ((strlen(x0)>=0) &&
\valid(x0+(0..strlen(x0))));
*/
int matcher(char * x0) {
int x2 = strlen(x0);
int x3 = 0 < x2;
int x6;
if (x3) {
char x4 = x0[0];
int x5 = 'a' == x4;
x6 = x5;
} else {
x6 = 0/*false*/;
}
int x7;
if (x6) {
x7 = 1/*true*/;
} else {
x7 = 0/*false*/;
}
return x7;
}
| 4 |
/*@ requires \valid(i) && \valid(j);
@ requires r == \null || \valid(r);
@ assigns *r;
@ behavior zero:
@ assumes r == \null;
@ assigns \nothing;
@ ensures \result == -1;
@ behavior normal:
@ assumes \valid(r);
@ assigns *r;
@ ensures *r == ((*i < *j) ? *j : *i);
@ ensures \result == 0;
@*/
int max2(int *r, int* i, int* j) {
if (!r) return -1;
*r = (*i < *j) ? *j : *i;
return 0;
}
| 23 |
/* run.config
EXECNOW: make tests/aorai/Aorai_test.cmxs
OPT: -aorai-ltl tests/aorai/test_switch2.ltl -aorai-test 1 -aorai-acceptance -load-module tests/aorai/Aorai_test.cmxs -aorai-test-number @PTEST_NUMBER@
*/
int status=0;
int rr=1;
//@ global invariant inv : 0<=rr<=50;
/*@ requires rr<50;
@ behavior j :
@ ensures rr<51;
*/
void opa() {
rr++;
}
void opb () {
status=1;
}
void opc() {
rr=9000;
}
int main(){
switch (rr) {
case 1 :
opa();
break;
case 3 :
opa();
default :
opc();
}
opb();
return 1;
}
| 14 |
/*@
requires n>0;
requires \valid_read(a + (0..n-1));
behavior sorted:
assumes \forall integer i;
1<=i<n ==> a[i]>=a[i-1];
ensures \result ==1;
behavior unsorted:
assumes \exists integer i;
1<=i<n && a[i]< a[i-1];
ensures \result ==0;
complete behaviors;
disjoint behaviors;
*/
int is_sorted(int a[],int n){
/*@
loop invariant \forall integer j;
1<=j<i ==> a[j]>=a[j-1];
loop invariant 1<= i <= n;
loop assigns i;
loop variant n-i;
*/
for (int i=1;i<n;i++){
if (a[i-1]>a[i]){
return 0;
}
}
return 1;
}
| 17 |
/*@
behavior a_less:
assumes a<b;
ensures \result == a;
behavior b_less:
assumes a>=b;
ensures \result == b;
*/
int min(int a, int b){
if(a<b)
return a;
else
return b;
} | 4 |
/* run.config
OPT: -obfuscate
*/
int my_var = 0;
/*@ global invariant I: my_var >= 0; */
enum my_enum {
first, second, third = 4
};
/*@ requires my_var > 0;
ensures my_var > \old(my_var);
ensures \forall integer x; x == x; */
int my_func () {
enum my_enum x = first;
/*@ assert my_var >= first; */
my_var++;
if (!my_var) goto end;
return my_var + x;
end: ;
return -1;
}
/*@ requires \valid(p);
ensures *p == 0;
*/
void f(int* p);
/*@ behavior bhv:
exits never: \false;
complete behaviors bhv;
disjoint behaviors bhv; */
int logic(int f1)
{
int V1;
V1 = 0;
if (f1) goto end;
V1 ++;
/*@ assert property: V1 ? 1: 0; */ ;
end: ;
return V1;
}
int main(int* p) {
if ("ti\rti" == "ti\rti") f(p);
}
/* Obfuscate logic types and logic constructors. */
/*@ type t = T | F; */
#include "stdint.h"
/* Do not obfuscate builtins and stdlib types and functions. */
int builtin_and_stdlib () {
int32_t x = 42;
Frama_C_show_each(x);
/*@ assert \true; */
return 1;
}
/* obfuscate names of arguments of function pointers. */
typedef void (*fct_ptr)(int x, int y);
struct S { fct_ptr my_func; };
void implem(int c, int d) { };
struct S example_struct = { .my_func = implem };
void test_func(struct S* s) { s->my_func(3,4); example_struct.my_func(5,6); }
| 4 |
/*@
requires n > 0;
requires \valid_read (a + (0..n-1));
requires \valid_read (b + (0..n-1));
assigns \nothing;
behavior equal:
assumes \forall integer k; 0 <= k < n ==> b[k] == a[k];
ensures \result == 1;
behavior not_equal:
assumes \exists integer k; 0 <= k < n && b[k] != a[k];
ensures \result == 0;
*/
int check(int *a, int *b, int n) {
/*@
loop invariant 0 <= i <= n;
loop invariant \forall integer k; 0 <= k < i ==> a[k] == b[k];
loop assigns i;
*/
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
return 0;
}
}
return 1;
}
int main() {
int a[] = {1,2,3,4,5};
int b[] = {1,2,3,4,5};
check(a, b, 5);
} | 4 |
#include <limits.h>
/*@ predicate is_pos(int x0) = (x0>0);*/
/*@
assigns \nothing;
ensures \result <==> is_pos(x0);
*/
int is_pos(int x0) {
int x2 = x0 > 0;
return x2;
}
/*@ predicate is_nat(int x3) = (x3>=0);*/
/*@
assigns \nothing;
ensures \result <==> is_nat(x3);
*/
int is_nat(int x3) {
int x5 = x3 >= 0;
return x5;
}
/*@
requires is_pos(x6);
assigns \nothing;
ensures is_nat(\result);
*/
int minus1(int x6) {
int x8 = x6 - 1;
return x8;
}
| 13 |
/*@
requires \valid(a) && \valid(b);
ensures *a == \old(*b) && *b == \old(*a);
*/
void swap(int* a, int* b){
int tmp = *a;
*a = *b;
*b = tmp;
}
int main()
{
int a=13,b=14;
swap(&a,&b);
}
| 10 |
/* run.config
OPT: -wp-no-print -wp-rte
*/
/* run.config_qualif
OPT: -then -wp-rte -wp
*/
/* ************/
/* Solution de TP donné par Julien à L'IFIPS */
/* ************/
#define BOUND 100
/* La fonction [pair(a, len)] prend en entrée un tableau [a] de longueur
[len] ne contenant que des valeurs entre 0 et [BOUND-1] (inclus) et retourne
[-1] si [a] ne contient pas deux éléments de même valeur et retourne un des
indices correspondant à une valeur en double sinon. */
/*
Questions:
1. Définir un prédicat [has_pair(a, len)] qui est valide si et seulement s'il
existe (au moins) deux éléments du tableau [a] de longueur [len] qui sont
égaux.
2. En utilisant des comportements (behaviors), donner une spécification en
ACSL de la fonction [pair].
3. Prouver cette fonction en utilisant le WP et Alt-Ergo. La preuve doit
inclure la terminaison et l'absence d'erreur à l'exécution.
*/
/*@ predicate has_pair(int *a, integer len) =
\exists integer i, j; 0 <= i < j < len && a[i] == a[j]; */
/*@ requires len >= 0;
@ requires \valid(a+(0.. len-1));
@ requires \forall integer i; 0 <= i < len ==> 0 <= a[i] < BOUND;
@ assigns \nothing;
@
@ behavior no_pair:
@ assumes ! has_pair(a, len);
@ ensures \result == -1;
@
@ behavior has_pair:
@ assumes has_pair(a, len);
@ ensures \exists integer i;
@ 0 <= i < len && i != \result && a[\result] == a[i];
@
@ complete behaviors;
@ disjoint behaviors;
@ */
int pair(int *a, int len)
{
char seen[BOUND];
/*@ loop invariant 0 <= i <= BOUND;
@ loop invariant \forall integer j; 0 <= j < i ==> seen[j] == 0;
@
@ loop assigns i, seen[0.. BOUND-1];
@ loop variant BOUND-i; */
for(int i = 0; i < BOUND; i++)
seen[i] = 0;
/*@ loop invariant 0 <= i <= len;
@
@ loop invariant
@ \forall integer v; 0 <= v < BOUND ==> seen[v]
@ ==> \exists integer j; 0 <= j < i && a[j] == v;
@
@ loop invariant
@ \forall integer v; 0 <= v < BOUND ==> ! seen[v]
@ ==> \forall integer j; 0 <= j < i ==> a[j] != v;
@
@ loop invariant !has_pair(a, i);
@
@ loop assigns i, seen[0.. BOUND-1];
@ loop variant len-i; */
for(int i = 0; i < len; i++) {
int v = a[i];
if (seen[v]) return i;
else seen[v] = 1;
}
return -1;
}
| 37 |
#define INT_MIN (-2147483648)
/*@ requires v != INT_MIN;
assigns \nothing;
ensures \result == \abs(v);
*/
int abs(int v)
{
return v >= 0 ? v : -v;
}
| 6 |
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <stdbool.h>
#define boxArea(box) (box >= 1 && box <= 9 ? TRUE : FALSE)
#define validCoord(x, y) ((x < 0 || x > N-1 || y < 0 || y > N-1) ? FALSE : TRUE)
#define emptyBox(box) (box == ' ' ? TRUE : FALSE)
#define OTHER(player) (player == playerX ? playerO : playerX)
//#define playerX 'X'
//#define playerO 'O'
#define TRUE 1
#define FALSE 0
// #define open_spot ((char)' ')
#define GAMEWIN 1
#define GAMETIE 0
#define GAMELOSE -1
#define INCOMPLETE 2
#define value_type char
#define N 3
const char playerX = 'X';
const char playerO = 'O';
const char open_spot=' ';
int game_result = -15;
// **Functions**
void initialize(char board[N][N]);
void print_board(char board[N][N]);
int comp_turn(char board[N][N], char player);
int player_turn(char board[N][N], char player);
bool gridTurn(char board[N][N], char player, int grid_var);
int coordTurn(char board[N][N], char player, int x, int y);
int win_check(char board[N][N], char player);
int diag_check(char board[N][N], char player);
int tie_check(char board[N][N]);
int minNum(char board[N][N], char player);
int maxNum(char board[N][N], char player);
void new_board_check(char board[N][N], char new_board[N][N]);
void minimax(char board[N][N], char player);
bool end_game(int play);
/*@
predicate zeroed(char *a, integer numCols) =
\forall int i; 0<=i<numCols ==> a[i] == ' ';
predicate zeroed2d(char (*a)[N], integer numRows) =
\forall int i; 0<=i<numRows ==> zeroed(&a[i][0], N);
*/
// predicate zeroed2d{A}(char **a, integer n, integer m) =
// \forall int i; 0<=i<n ==> zeroed(a[i], m);
/*@
predicate
HasValue(char* a, integer m, integer n, char v) =
\exists integer i; m <= i < n && a[i] == v;
predicate
HasValue(char* a, integer n, char v) =
HasValue(a, 0, n, v);
predicate
HasValue2d(char (*a)[N], integer numRows, char v) =
\exists integer i; 0<=i<numRows && HasValue(&a[i][0], N, v);
*/
/*@
predicate Won(char (*a)[N], char p) =
(\exists integer i; 0<=i<N && \forall integer j; 0<=j<N==>a[i][j]== p) ||
(\exists integer i; 0<=i<N && \forall integer j; 0<=j<N==>a[j][i]== p) ||
(\forall integer i; 0<=i<N==>a[i][i]==p) ||
(a[2][0]==p && a[1][1]==p && a[0][2]);
@*/
int main() {
char board[N][N];
initialize(board);
print_board(board);
while (TRUE) {
if (player_turn(board, playerX) == TRUE)
break;
if (comp_turn(board, playerO) == TRUE)
break;
}
return 0;
}
// Initialize board
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns board[0.. (N-1) ][0..2];
@ ensures zeroed2d(board,N);
@*/
void initialize(char board[N][N]) {
/*@
@ loop invariant 0<=i<=N;
@ loop invariant zeroed2d(board, i);
@ loop assigns i, board[0.. (N-1) ][0..2];
@ loop variant N-i;
@*/
for (int i = 0; i < N; ++i) {
/*@ loop invariant 0<=i<= N && 0<=j<=N;
@ loop invariant zeroed2d(board, i);
@ loop invariant zeroed(&board[i][0],j);
@ loop assigns j, board[0.. (N-1) ][0..2];
@ loop variant N-j;
@*/
for (int j = 0; j < N; ++j) {
board[i][j] = ' ';
}
}
}
/*@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns board[0..(N-1)][0..2];
@*/
void print_board(char board[N][N]) {
//printf("\n");
int i;
/*@ loop invariant 0<=i<=N;
@ loop assigns i, board[0.. (N-1)][0..2];
@ loop variant N-i;
@*/
for (i = 0; i < N; ++i) {
//printf("| %c | %c | %c |\n", board[0][i], board[1][i], board[2][i]);
}
//printf("\n");
}
/*@
@ assigns \nothing;
@ behavior GameWin:
assumes play == GAMEWIN;
ensures \result == TRUE;
@ behavior GameTie:
assumes play == GAMETIE;
ensures \result == TRUE;
@ behavior return_false:
assumes play != GAMEWIN && play != GAMETIE;
ensures \result == FALSE;
@*/
bool end_game(int play) {
if (play == GAMEWIN) {
//printf("\nWinner is: Computer\n");
return TRUE;
} else if (play == GAMETIE) {
//printf("\nTie game\n");
return TRUE;
}
return FALSE;
}
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns board[0.. (N-1) ][0..2], game_result;
@*/
int comp_turn(char board[N][N], char player) {
//printf("\t\t\tComputer's turn\n");
minimax(board, player);
print_board(board);
int play = win_check(board, player);
return end_game(play);
}
// Player's turn
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns board[0.. (N-1) ][0..2], game_result;
@*/
int player_turn(char board[N][N], char player) {
int grid_var;
/*@
@ loop assigns grid_var, board[0.. (N-1) ][0..2], game_result;
@*/
while (TRUE) {
//printf("Enter number: "); // Allows the user to pick a spot according to the diagram
//scanf("%d", &grid_var);
//printf("\t\t\tPlayer's turn\n");
if (gridTurn(board, player, grid_var) == 0) // If incorrect location is chosen, make user try again
break;
//printf("Wrong selection, try again\n");
}
print_board(board);
int play = win_check(board, player);
return end_game(play);
}
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns board[0.. (N-1) ][0..2];
@ behavior box_area:
assumes boxArea(grid_var) == FALSE;
ensures \result == TRUE;
@*/
bool gridTurn(char board[N][N], char player, int grid_var) {
if (boxArea(grid_var) == FALSE) {
return TRUE;
}
//Calculates i, j coordinates on grid
int i, j;
/*@
@ ensures j >= 0;
@ ensures emptyBox(board[i][j]) == FALSE ==> TRUE;
@ ensures grid_var < 4 ==> j == 0;
@ ensures j == 1 ==> grid_var < 7;
@ ensures j == 2 ==> grid_var < 10;
@ assigns i,j, grid_var;
@*/
if (grid_var < 4) {
j = 0;
} else if (grid_var < 7) {
j = 1;
} else {
j = 2;
}
i = grid_var - 1 - (j * N);
/*@
@ ensures i == grid_var-1-(j*N);
@ ensures \forall integer i, j; emptyBox(board[i][j]) == FALSE ==> TRUE;
@*/
if (emptyBox(board[i][j]) == FALSE) {
return TRUE;
}
board[i][j] = player;
return FALSE;
}
/*@
@ behavior validCoord:
assumes validCoord(x,y) == FALSE;
ensures \result == TRUE;
@ behavior emptyBox:
assumes emptyBox(board[x][y]) == FALSE;
ensures \result == TRUE;
@ behavior return_false:
assumes validCoord(x,y) == TRUE && emptyBox(board[x][y]) == TRUE;
ensures board[x][y] == player;
ensures \result == FALSE;
complete behaviors validCoord, emptyBox, return_false;
@*/
int coordTurn(char board[N][N], char player, int x, int y) {
// Check if coordinates are valid
if (validCoord(x, y) == FALSE) {
return TRUE;
}
if (emptyBox(board[x][y]) == FALSE) {
return TRUE;
}
board[x][y] = player;
return FALSE;
}
/*@
@ requires \valid_read(board[0..(N-1)]+(0..2));
@ assigns \nothing;
@ ensures (board[0][0] != open_spot && board[0][0] == board[1][0] && board[1][0] == board[2][0]) && board[0][0] == player ==> GAMEWIN;
@ ensures (board[0][1] != open_spot && board[0][1] == board[1][1] && board[1][1] == board[2][1]) && board[0][1] == player ==> GAMEWIN;
@ ensures (board[0][2] != open_spot && board[0][2] == board[1][2] && board[1][2] == board[2][2]) && board[0][2] == player ==> GAMEWIN;
@ ensures (board[0][0] != open_spot && board[0][0] == board[1][0] && board[1][0] == board[2][0]) && board[0][0] != player ==> GAMELOSE;
@ ensures (board[0][1] != open_spot && board[0][1] == board[1][1] && board[1][1] == board[2][1]) && board[0][1] != player ==> GAMELOSE;
@ ensures (board[0][2] != open_spot && board[0][2] == board[1][2] && board[1][2] == board[2][2]) && board[0][2] != player ==> GAMELOSE;
@ ensures (board[0][0] != open_spot && board[0][0] == board[0][1] && board[0][1] == board[0][2]) && board[0][0] == player ==> GAMEWIN;
@ ensures (board[1][0] != open_spot && board[1][0] == board[1][1] && board[1][1] == board[1][2]) && board[1][0] == player ==> GAMEWIN;
@ ensures (board[2][0] != open_spot && board[2][0] == board[2][1] && board[2][1] == board[2][2]) && board[2][0] == player ==> GAMEWIN;
@ ensures (board[0][0] != open_spot && board[0][0] == board[0][1] && board[0][1] == board[0][2]) && board[0][0] != player ==> GAMELOSE;
@ ensures (board[1][0] != open_spot && board[1][0] == board[1][1] && board[1][1] == board[1][2]) && board[1][0] != player ==> GAMELOSE;
@ ensures (board[2][0] != open_spot && board[2][0] == board[2][1] && board[2][1] == board[2][2]) && board[2][0] != player ==> GAMELOSE;
@ ensures \forall integer diag; diag ==> (diag != FALSE);
@*/
int win_check(char board[N][N], char player) {
int i, j;
// For rows and columns
/*@
@ loop invariant win_check_outerLoop: 0<=i<=N;
@ loop assigns i;
@ loop variant N-i;
@*/
for (i = 0; i < N; ++i) {
// Row
if (board[0][i] != open_spot) {
if (board[0][i] == board[1][i] && board[1][i] == board[2][i]) {
return board[0][i] == player ? GAMEWIN : GAMELOSE;
}
}
// Column
if (board[i][0] != open_spot) {
if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) {
return board[i][0] == player ? GAMEWIN : GAMELOSE;
}
}
}
//check the diagonal
int diag = diag_check(board, player);
if (diag != FALSE){
return diag;
}
// check for a tie
return tie_check(board);
}
/*@
@ requires \valid_read(board[0..(N-1)]+(0.. (N-1)));
@ assigns \nothing;
@ behavior left_true:
assumes board[0][0] != open_spot && board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] == player;
ensures \result == GAMEWIN;
@ behavior right_true:
assumes board[0][0] != open_spot && board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != player;
ensures \result == GAMELOSE;
@ behavior left_false:
assumes board[2][0] != open_spot && board[2][0] == board[1][1] && board[1][1] == board[0][2] && board[2][0] == player;
ensures \result == GAMEWIN;
@ behavior right_false:
assumes board[2][0] != open_spot && board[2][0] == board[1][1] && board[1][1] == board[0][2] && board[2][0] != player;
ensures \result == GAMELOSE;
@*/
int diag_check(char board[N][N], char player){
// Check left diagonal
if (board[0][0] != open_spot && board[0][0] == board[1][1] && board[1][1] == board[2][2]) {
return board[0][0] == player ? GAMEWIN : GAMELOSE;
}
// Check right diagonal
if (board[2][0] != open_spot && board[2][0] == board[1][1] && board[1][1] == board[0][2]) {
return board[2][0] == player ? GAMEWIN : GAMELOSE;
}
return FALSE;
}
/*@
@ requires \valid_read(board[0..(N-1)]+(0.. (N-1)));
@ assigns \nothing;
@ behavior incomplete_game:
assumes HasValue2d(board, N, open_spot);
ensures \result == INCOMPLETE;
@ behavior tie_game:
assumes !HasValue2d(board, N, open_spot);
ensures \result == GAMETIE;
@*/
int tie_check(char board[N][N]){
// Check for a tie
/*@
@ loop invariant outer: 0<=i<=N;
@ loop invariant outer_prev_rows: !HasValue2d(board, i, open_spot);
@ loop assigns i;
@ loop variant N-i;
@*/
for (int i = 0; i < N; ++i) {
/*@
@ loop invariant inner_range: 0<=i<=N && 0<=j<=N;
@ loop invariant inner_prev_rows: !HasValue2d(board, i, open_spot);
@ loop invariant inner_left: !HasValue(&board[i][0], j, open_spot);
@ loop assigns j;
@ loop variant N-j;
@*/
for (int j = 0; j < N; ++j) {
if (board[i][j] == open_spot)
// Incomplete board
return INCOMPLETE;
}
}
return GAMETIE;
}
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns func_min_assign: game_result, board[0.. (N-1) ][0..2];
@
@ behavior test:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot;
ensures \result == game_result;
@ behavior test2:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot && Won(board,player);
ensures game_result == GAMEWIN && \result == game_result ;
@ behavior test3:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot && Won(board,player);
ensures game_result == GAMELOSE && \result == game_result ;
@ behavior test4:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot && !Won(board,playerX) && !Won(board, playerO);
ensures game_result == GAMETIE && \result == game_result ;
@
@*/
int minNum(char board[N][N], char player) {
game_result = win_check(board, OTHER(player));
if (game_result != INCOMPLETE)
return game_result;
int min = 10;
/*@
@ loop invariant 0<=i<=N;
@ loop assigns i, min, game_result;
@ loop variant N-i;
@*/
for (int i = 0; i < N; ++i) {
/*@
@ loop invariant 0<=i<=N && 0<=j<=N;
@ loop assigns j, min, game_result;
@ loop variant N-j;
@*/
for (int j = 0; j < N; ++j) {
if (board[i][j] != ' ')
continue;
char new_board[N][N];
new_board_check( board, new_board);
new_board[i][j] = player;
int temp = maxNum(new_board, OTHER(player));
if (temp < min)
min = temp;
}
}
return min;
}
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns funct_assign: game_result, board[0.. (N-1) ][0..2];
@
@ behavior test:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot;
ensures \result == game_result;
@ behavior test2:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot && Won(board,player);
ensures game_result == GAMEWIN && \result == game_result ;
@ behavior test3:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot && Won(board,player);
ensures game_result == GAMELOSE && \result == game_result ;
@ behavior test4:
assumes \forall int i, j; 0<=j<=i<=N && board[i][j] != open_spot && !Won(board,playerX) && !Won(board, playerO);
ensures game_result == GAMETIE && \result == game_result ;
@
@*/
int maxNum(char board[N][N], char player) {
game_result = win_check(board, player);
if (game_result != INCOMPLETE)
return game_result;
int max = -10;
/*@
@ loop invariant outerloop: 0<=i<=N;
@ loop assigns outer_assign: i, max, game_result;
@ loop variant N-i;
@*/
for (int i = 0; i < N; ++i) {
/*@
@ loop invariant inner_loop: 0<=i<=N && 0<=j<=N;
@ loop assigns inner_assign: j, max, game_result;
@ loop variant N-j;
@*/
for (int j = 0; j < N; ++j) {
if (board[i][j] != ' ')
continue;
char new_board[N][N];
new_board_check( board, new_board);
new_board[i][j] = player;
int temp = minNum(new_board, OTHER(player));
if (temp > max)
max = temp;
}
}
return max;
}
/*@
@ requires \valid_read(board[0..(N-1)]+(0..2));
@ requires \valid(new_board[0..(N-1)]+(0..2));
@ assigns new_board[0.. (N-1) ][0..2];
@ ensures \forall int i,j; 0<=i<=N && 0<=j<=N ==> new_board[i][j] == board[i][j];
@*/
void new_board_check(char board[N][N], char new_board[N][N]){
/*@
@ loop invariant 0<=x<=N;
@ loop assigns x, new_board[0.. (N-1) ][0..2];
@ loop variant N-x;
@*/
for (int x = 0; x < N; ++x) {
/*@
@ loop invariant 0<=x<=N && 0<=y<=N;
@ loop assigns y, new_board[0.. (N-1) ][0..2];
@ loop variant N-y;
@*/
for (int y = 0; y < N; ++y) {
new_board[x][y] = board[x][y];
}
}
}
/*@
@ requires \valid(board[0..(N-1)]+(0.. (N-1)));
@ assigns board[0.. (N-1) ][0..2], game_result;
@*/
void minimax(char board[N][N], char player) {
//@ assigns max, mval_i, mval_j;
int max, mval_i, mval_j;
max = -10;
/*@
@ loop invariant minimax_first_loop: 0<=i<=N;
@ loop assigns i, max,mval_i,mval_j, game_result;
@ loop variant N-i;
@*/
for (int i = 0; i < N; ++i) {
/*@
@ loop invariant minimax_second_loop: 0<=i<=N && 0<=j<=N;
@ loop assigns j, max,mval_i,mval_j, game_result;
@ loop variant N-j;
@*/
for (int j = 0; j < N; ++j) {
if (board[i][j] != ' ')
continue;
char new_board[N][N];
new_board_check( board, new_board);
new_board[i][j] = player;
int temp = minNum(new_board, OTHER(player)); // Computer is at top of tree
if (temp > max) { // Finish with the highest outcome of minNum loop
max = temp;
mval_i = i;
mval_j = j;
}
}
}
if (coordTurn(board, player, mval_i, mval_j) == TRUE) {
//printf("Minimax error\n");
exit(0);
}
}
| 6 |
/*@
ensures (('a'<=c && c<='z') || ('A'<=c && c<='Z')) ==> \result==1;
ensures !(('a'<=c && c<='z') || ('A'<=c && c<='Z'))==> \result==0;
*/
int alphabet_letter(char c){
if( ('a'<= c && c <='z') || ('A' <= c && c <='Z') ) return 1;
else return 0;
}
int main(){
int ch ;
ch = alphabet_letter('x') ;
//@ assert ch==1 ;
ch = alphabet_letter('H') ;
//@ assert ch==1 ;
ch = alphabet_letter(' ') ;
//@ assert !ch ;
}
| 9 |
typedef struct _vc {
int n;
char* a;
} vc;
typedef struct _vvc {
int n;
struct _vc* a;
} vvc;
/*@
// Invariant and equality spec for Vector[Char]
predicate spec_Inv_VC(vc v) =
v.n==0 || (v.n>0 && \valid(v.a+(0..v.n-1)));
predicate spec_Eq_VC(vc v1, vc v2) =
(v1.n==v2.n) &&
(\forall int j; (0<=j<v1.n) ==> v1.a[j] == v2.a[j]);
// Invariant and equality spec for Vector[Vector[Char]]
predicate spec_Inv_VVC(vvc v) =
v.n==0 || (v.n>0 && \valid(v.a+(0..v.n-1))) &&
(\forall int j; (0<=j<v.n) ==> spec_Inv_VC(v.a[j]));
predicate spec_Eq_VVC(vvc v1, vvc v2) =
(v1.n==v2.n) &&
(\forall int j; (0<=j<v1.n) ==> spec_Eq_VC(v1.a[j],v2.a[j]));
*/
// Contract and implementation for Vector[Char] equality
/*@ requires spec_Inv_VC(v1) && spec_Inv_VC(v2);
ensures (\result == 1) || (\result == 0);
ensures (\result == 1) <==> spec_Eq_VC(v1, v2);
ensures (\result == 0) <==> !spec_Eq_VC(v1, v2);
assigns \nothing; */
int eq_VC(vc v1, vc v2) {
if (v1.n != v2.n) return 0;
/*@ loop invariant (0 <= i <= v1.n);
loop invariant \forall int j; (0 <= j < i) ==> v1.a[j]==v2.a[j];
loop assigns i;
loop variant (v1.n-i); */
for (int i = 0; i < v1.n; i++) {
if (v1.a[i] != v2.a[i]) return 0;
}
return 1;
}
// Contract and implementation for Vector[Vector[Char]] equality
/*@ requires spec_Inv_VVC(v1) && spec_Inv_VVC(v2);
ensures (\result == 1) || (\result == 0);
ensures (\result == 1) <==> spec_Eq_VVC(v1, v2);
ensures (\result == 0) <==> !spec_Eq_VVC(v1, v2);
assigns \nothing; */
int eq_VVC(vvc v1, vvc v2) {
if (v1.n != v2.n) return 0;
/*@ loop invariant (0 <= i <= v1.n);
loop invariant \forall int j; (0 <= j < i) ==> spec_Eq_VC(v1.a[j],v2.a[j]);
loop assigns i;
loop variant (v1.n-i); */
for (int i = 0; i < v1.n; i++) {
if (eq_VC(v1.a[i],v2.a[i]) != 1) return 0;
}
return 1;
}
| 44 |
#include<assert.h>
/*@
@ ensures \result == 1;
@
*/
int gimmeOne() {
return 1;
}
int main() {
int x = gimmeOne();
assert(x == 1);
}
| 6 |
#include <string.h>
/*@
requires strlen(input)>=0 && \valid(input+(0..strlen(input)));
assigns \nothing;
ensures \result==0 || \result==1;
*/
int dfa_aabany(char* input) {
if (*input == '\0') return 0/*false*/;
int id = 0;
char c;
/*@
loop invariant strlen(input)>0 && \valid(input+(0..strlen(input)));
loop invariant id == 17 || id == 14 || id == 11 || id == 6 || id == 3 || id == 0;
loop assigns id, c, input;
loop variant strlen(input);
*/
while (input[1] != '\0') {
c = *input++;
if (id == 17) {
char x18 = c;
int x19 = x18 == 'A';
int x23;
if (x19) {
return 1/*true*/;
} else {
return 1/*true*/;
}
id = x23;
}
else if (id == 14) {
char x15 = c;
int x16 = x15 == 'A';
int x24;
if (x16) {
return 1/*true*/;
} else {
return 1/*true*/;
}
id = x24;
}
else if (id == 11) {
char x12 = c;
int x13 = x12 == 'A';
int x26;
if (x13) {
return 1/*true*/;
} else {
return 1/*true*/;
}
id = x26;
}
else if (id == 6) {
char x7 = c;
int x8 = x7 == 'A';
int x29;
if (x8) {
x29 = 6;
} else {
int x10 = x7 == 'B';
int x28;
if (x10) {
return 1/*true*/;
} else {
x28 = 0;
}
x29 = x28;
}
id = x29;
}
else if (id == 3) {
char x4 = c;
int x5 = x4 == 'A';
int x30;
if (x5) {
x30 = 6;
} else {
x30 = 0;
}
id = x30;
}
else if (id == 0) {
char x1 = c;
int x2 = x1 == 'A';
int x32;
if (x2) {
x32 = 3;
} else {
x32 = 0;
}
id = x32;
}
else { return -1; /*error: invalid state*/ }
}
c = *input;
if (id == 17) {
char x18 = c;
int x19 = x18 == 'A';
int x23;
if (x19) {
x23 = 1/*true*/;
} else {
x23 = 1/*true*/;
}
id = x23;
}
else if (id == 14) {
char x15 = c;
int x16 = x15 == 'A';
int x24;
if (x16) {
x24 = 1/*true*/;
} else {
x24 = 1/*true*/;
}
id = x24;
}
else if (id == 11) {
char x12 = c;
int x13 = x12 == 'A';
int x26;
if (x13) {
x26 = 1/*true*/;
} else {
x26 = 1/*true*/;
}
id = x26;
}
else if (id == 6) {
char x7 = c;
int x8 = x7 == 'A';
int x29;
if (x8) {
x29 = 0/*false*/;
} else {
int x10 = x7 == 'B';
int x28;
if (x10) {
x28 = 1/*true*/;
} else {
x28 = 0/*false*/;
}
x29 = x28;
}
id = x29;
}
else if (id == 3) {
char x4 = c;
int x5 = x4 == 'A';
int x30;
if (x5) {
x30 = 0/*false*/;
} else {
x30 = 0/*false*/;
}
id = x30;
}
else if (id == 0) {
char x1 = c;
int x2 = x1 == 'A';
int x32;
if (x2) {
x32 = 0/*false*/;
} else {
x32 = 0/*false*/;
}
id = x32;
}
else { return -1; /*error: invalid state */ }
return id;
}
| 58 |
#define value_type unsigned int
/////////////// Base definition
/*@
@ logic integer occurence{L}( value_type* a, integer l, integer h, value_type e ) =
@ l >= h ? 0 : ( a[l] == e ? 1 : 0 ) + occurence( a, l+1, h, e );
@
*/
/////// Axioms with functions as proof
// range
/*@ requires l <= h;
@ assigns \nothing;
@ ensures 0 <= occurence( a, l, h, e ) <= h - l;
*/
void occurence_range_proof( value_type* a, unsigned int l, unsigned int h, value_type e ){
/*@ loop invariant l <= i <= h;
@ loop invariant 0 <= occurence( a, l, i, e ) <= i - l;
@ loop assigns i;
@ loop variant (h - i);
*/
for (unsigned int i = l; i != h; ++i){}
}
/*@
@ axiomatic Occurence_range {
@
@ axiom occurence_n_range: \forall value_type* a, integer l, h, value_type e, integer n;
@ l <= h ==> 0 <= occurence( a, l, h, e ) <= h - l;
@ }
@
*/
// reverse
/*@ requires l < h;
@ assigns \nothing;
@ ensures occurence( a, l, h, e ) == (a[h-1] == e ? 1 : 0) + occurence( a, l, h-1, e);
*/
void occurence_reverse_proof( value_type* a, unsigned int l, unsigned int h, value_type e ){
/*@ loop invariant l <= i < h;
@ loop invariant occurence( a, i, h, e ) == (a[h-1] == e ? 1 : 0) + occurence( a, i, h-1, e);
@ loop assigns i;
@ loop variant (i - l);
*/
for (unsigned int i = h-1; i != l; --i){}
}
/*@
@ axiomatic Occurence_reverse {
@
@ axiom occurence_reverse: \forall value_type* a, integer l, h, value_type e, integer n;
@ l < h ==> occurence( a, l, h, e ) == (a[h-1] == e ? 1 : 0) + occurence( a, l, h-1, e);
@ }
@
*/
// split
/*@ requires l <= cut <= h;
@ assigns \nothing;
@ ensures occurence( a, l, h, e ) == occurence( a, l, cut, e ) + occurence( a, cut, h, e );
*/
void occurence_split_proof( value_type* a, unsigned int l, unsigned int h, value_type e, unsigned int cut ){
/*@ loop invariant cut <= i <= h;
@ loop invariant occurence( a, l, i, e ) == occurence( a, l, cut, e ) + occurence( a, cut, i, e );
@ loop assigns i;
@ loop variant (h - i);
*/
for (unsigned int i = cut; i != h; ++i){}
}
/*@
@ axiomatic Occurence_split{
@
@ axiom occurence_split: \forall value_type* a, integer l, h, value_type e, integer cut;
@ l <= cut <= h ==> occurence( a, l, h, e ) == occurence( a, l, cut, e ) + occurence( a, cut, h, e );
@ }
@
*/
/////// a function computing the occurence
/*@ requires \valid( a+(l..h-1) );
@ requires l < h;
@
@ assigns \nothing;
@
@ ensures \result == occurence( a, l, h, e );
*/
unsigned int occurence( value_type* a, unsigned int l, unsigned int h, value_type e ){
unsigned int result = 0;
/*@ loop invariant occurence_i_range: l <= i <= h;
@ loop invariant always_valid: \valid( a+(l..h-1) );
@ loop invariant occurence_result_prefix: occurence( a, l, h, e ) == result + occurence( a, i, h, e );
@ loop assigns i, result;
@ loop variant (h - i);
*/
for (unsigned int i = l; i != h; ++i){
if (a[i] == e)
result += 1;
}
return result;
}
////// permutation definition
/*@
@ predicate permutation{L1, L2}( value_type* a, integer l, integer h ) =
@ \forall value_type e; occurence{L1}( a, l, h, e ) == occurence{L2}( a, l, h, e );
*/
/// swap
/*@
@ requires l <= i1 < h;
@ requires l <= i2 < h;
@ requires \valid( a+(l..h-1) );
@
@ assigns a[i1], a[i2];
@
@ ensures \at( a[i1], Post ) == \at( a[i2], Pre );
@ ensures \at( a[i2], Post ) == \at( a[i1], Pre );
@ //ensures permutation{ Pre, Post }( a, l, h );
*/
void swap( value_type* a, unsigned int l, unsigned int h, unsigned int i1, unsigned int i2 ){
value_type tmp = a[i2];
// ghost call is like instantiation of quantifier / SMT triggering
/*@ ghost occurence_split_proof( a, l, h, a[i2], i2 ); */
//@assert A1: occurence( a, l, h, a[i2] ) == occurence( a, l, i2, a[i2] ) + occurence( a, i2, h, a[i2] );
//@assert A2: occurence( a, l, h, a[i2] ) == occurence( a, l, i2, a[i2] ) + 1 + occurence( a, i2+1, h, a[i2] );
a[i2] = a[i1];
a[i1] = tmp;
}
/*@ predicate ordered( value_type* a, integer l, integer h ) =
@ \forall integer k1, k2; l <= k1 <= k2 < h ==> a[k1] <= a[k2];
*/
/*@ requires \valid( a+(l..h-1) );
@ requires l < h;
@
@ assigns a[l..h-1];
@
@ ensures l <= \result < h;
@ ensures \forall integer k; l <= k <= \result ==> a[k] <= a[\result];
@ ensures \forall integer k; \result <= k < h ==> a[\result] <= a[k];
@ ensures permutation{Pre, Post}( a, l, h );
*/
unsigned int partition( value_type* a, unsigned int l, unsigned int h ){
const unsigned int pivot_index = l + (h - l)/2;
const value_type pivot_value = a[pivot_index];
swap( a, l, h, pivot_index, h-1 );
unsigned int store_index = l;
/*@ loop invariant i_range: l <= i <= h;
@ loop invariant store_index_rage: l <= store_index <= i;
@ loop invariant lt_pivot: \forall integer k; l <= k < store_index ==> a[k] < pivot_value;
@ loop invariant geq_pivot: \forall integer k; store_index <= k < i ==> a[k] >= pivot_value;
@ loop invariant pivot_value_inv: a[h] == pivot_value;
@ loop invariant is_permut: permutation{Pre, Here}(a, l, h);
@ loop assigns a[l..h-1], store_index, i;
@ loop variant (h - i);
*/
for (unsigned int i = l; i != h; ++i){
if (a[i] < pivot_value){
swap( a, l, h, i, store_index );
++store_index;
}
}
swap( a, l, h, store_index, h-1 );
return store_index;
}
/*@ requires \valid( a+(l..h-1) );
@ requires l < h;
@
@ assigns a[l..h-1];
@
@ ensures ordered( a, l, h );
@ ensures permutation{Pre, Post}( a, l, h );
*/
void qsort( value_type* a, unsigned int l, unsigned int h ){
unsigned int p = partition( a, l, h );
if (l < p)
qsort( a, l, p );
if(p < h-1)
qsort( a, p+1, h );
return;
}
| 58 |
#include <limits.h>
#include <string.h>
/*@ predicate matcher_a_or_b(char * x0) = ((((x0[0]=='\0')) ? (\false) : (((x0[0]=='a') &&
((x0+1)[0]=='\0')))) || (((x0[0]=='\0')) ? (\false) : (((x0[0]=='b') &&
((x0+1)[0]=='\0')))));*/
/*@
requires ((strlen(x0)>=0) &&
\valid(x0+(0..(strlen(x0)+1)-1)));
assigns \nothing;
ensures \result <==> matcher_a_or_b(x0);
*/
int matcher_a_or_b(char * x0) {
char x2 = x0[0];
int x3 = x2 == '\0';
int x9;
if (x3) {
x9 = 0/*false*/;
} else {
int x4 = x2 == 'a';
int x8;
if (x4) {
char *x5 = x0+1;
char x6 = x5[0];
int x7 = x6 == '\0';
x8 = x7;
} else {
x8 = 0/*false*/;
}
x9 = x8;
}
int x12;
if (x3) {
x12 = 0/*false*/;
} else {
int x10 = x2 == 'b';
int x11;
if (x10) {
char *x5 = x0+1;
char x6 = x5[0];
int x7 = x6 == '\0';
x11 = x7;
} else {
x11 = 0/*false*/;
}
x12 = x11;
}
int x13 = x9 || x12;
return x13;
}
| 17 |
/*@ requires \valid(p) && \valid(q);
ensures *p <= *q;
behavior p_minimum:
assumes *p < *q;
ensures *p == \old(*p) && *q == \old(*q);
behavior q_minimum:
assumes *p >= *q;
ensures *p == \old(*q) && *q == \old(*p);
complete behaviors p_minimum, q_minimum;
disjoint behaviors p_minimum, q_minimum;
*/
void max_ptr(int*p, int*q) {
if (*p > *q) {
int tmp = *p;
*p = *q;
*q = tmp;
}
} | 13 |
#include <limits.h>
#include <string.h>
/*@
requires (((strlen(x0)>=0) &&
\valid(x0+(0..strlen(x0)))) &&
(strlen(x0)<=INT_MAX));
assigns \nothing;
*/
int dfa(char * x0) {
int x2 = 1/*true*/;
int x3 = 0;
//@ ghost int x4 = 0;
char *x5 = x0;
/*@
loop invariant (((((strlen(x0)>=0) &&
\valid(x0+(0..strlen(x0)))) &&
((0<=x4) &&
(x4<=strlen(x0)))) &&
(x5==(x0+x4))) &&
((strlen((x0+x4))>=0) &&
\valid((x0+x4)+(0..strlen((x0+x4))))));
loop invariant ((x5[0]=='\0') ==> (strlen(x0)==x4));
loop invariant ((!(x5[0]=='\0')) ==> (strlen(x0)!=x4));
loop invariant ((x3==2) || ((x3==1) || (x3==0)));
loop assigns x5, x4, x3, x2;
loop variant strlen(x5);
*/
for (;;) {
char *x7 = x5;
char x8 = x7[0];
int x9 = x8 == '\0';
int x13;
if (x9) {
x13 = 0/*false*/;
} else {
int x11 = x2;
x13 = x11;
}
if (!x13) break;
char *x37 = x5;
char *x38 = x37+1;
x5 = x38;
/*@ghost x4 = (x4+1);*/
}
char *x84 = x5;
char x85 = x84[0];
int x86 = x85 == '\0';
int x89;
if (x86) {
int x87 = x2;
x89 = x87;
} else {
x89 = 0/*false*/;
}
int x93;
if (x89) {
int x90 = x3;
int x91 = x90 == 2;
x93 = x91;
} else {
x93 = 0/*false*/;
}
/*@assert ((x5[0]=='\0') || (!x2));*/
return x93;
}
| 26 |
/*@ requires 0 <= p <= r && \valid(A+(p..r));
@*/
int partition (int A[], int p, int r)
{
int x = A[r];
int tmp, j, i = p-1;
/*@ loop invariant p <= j <= r && p-1 <= i < j;
@ loop assigns tmp, i, j, A[p..r];
@ loop variant r-j;
@*/
for(j=p; j<r; j++)
if (A[j] <= x) {
i++;
tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
tmp = A[i+1];
A[i+1] = A[r];
A[r] = tmp;
return i+1;
}
| 26 |
/*@ ensures \result >= a && \result >= b ;
ensures \result == a || \result == b ; */
int max(int a, int b);
extern int v ;
int main(){
v = 3;
int r = max(4,2);
//@ assert v == 3 ;
}
| 3 |
// TODO : mettre les bonnes annotations...
/*@
requires n >= 0;
requires \valid_read(src+(0..n-1));
requires \valid(dst+(0..n-1));
assigns dst[0..n-1];
ensures dst[0..n-1] == \old(src[0..n-1]);
*/
void array_copy(int *src, int *dst, int n) {
if (src < dst) {
// recopier de droite à gauche
/*@
loop invariant -1 <= i <= n-1;
loop invariant
\forall int k; i < k <= n-1 ==> dst[k] == \at(src[k], Pre);
loop invariant
\forall int k; 0 <= k <= i ==> src[k] == \at(src[k], Pre);
loop assigns i, dst[0..n-1];
loop variant i+1;
*/
for (int i = n-1; -1 < i; i--) {
dst[i] = src[i];
}
} else {
// recopier de gauche à droite
/*@
loop invariant 0 <= i <= n;
loop invariant
\forall int k; 0 <= k < i ==> dst[k] == \at(src[k], Pre);
loop invariant
\forall int k; i <= k < n ==> src[k] == \at(src[k], Pre);
loop assigns i, dst[0..n-1];
loop variant n-i;
*/
for (int i = 0; i < n; i++) {
dst[i] = src[i];
}
}
}
| 33 |
// __out o, __in i
/*@ requires \valid(i) && \valid(o);
@ assigns *o;
@ ensures *o == *i;
*/
void OutAndIn(int *i, int *o) {
*o = *i;
}
void OutAndIn_test()
{
int a = 5;
int b = 0;
OutAndIn(&a, &b);
//@ assert a == b;
}
| 10 |
/* ****************************************************************************
MAXIMUM D'UN TABLEAU
L'énoncé est introduit sous la forme de commentaires C. Les différents
morceaux de programme et de spécification à considérer sont mentionnés en
programmation littéraire :
https://en.wikipedia.org/wiki/Literate_programming
************************************************************************* */
/* ---------------------------------------------------------------------------
Cet exercice est une variation de l'exercice "Maximum d'un tableau" du TD
6. Cet exercice n'a pas été corrigé en cours, mais si vous avez pris le temps
de le faire par vous-même comme je l'avais demandé, cela devrait vous
permettre de gagner un peu de temps pour ce TP noté...
------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
La fonction [max_idx] est une fonction auxiliaire de la fonction principale
[max_seq], définie juste après. Nous ne donnons ici que sa déclaration. Sa
définition est fournie en fin de fichier.
------------------------------------------------------------------------- */
#include <limits.h>
int max_idx(unsigned int *t, int len);
/* ---------------------------------------------------------------------------
La fonction [max_seq] retourne la valeur maximale contenue dans
le tableau [t] de longueur [len]. Elle retourne -1 si le tableau est vide.
Question 1 : spécifier cette fonction en utilisant des comportements ACSL.
Question 2 : prouver cette fonction, y compris sa terminaison et l'absence
d'erreurs à l'exécution. On prendra garde à ne spécifier que les
préconditions strictement nécessaires pour garantir l'absence d'erreurs à
l'exécution.
Indice : il est autorisé d'inclure un fichier de la bibliothèque standard du
C (déjà utilisé en TD dans des cas similaires).
------------------------------------------------------------------------- */
/*@ requires \valid(t+(0..len-1));
@ requires len >= 0;
@ requires \forall integer n; 0 <= n < len ==> t[n] <= INT_MAX;
@ assigns \nothing;
@ behavior t_vide:
@ assumes len == 0;
@ ensures \result == -1;
@ behavior t_max:
@ assumes len > 0;
@ ensures \forall integer n; 0 <= n < len ==> \result >= t[n];
@ ensures \exists int e; 0 <= e < len && \result == t[e];
@ ensures \result >= 0;
@ complete behaviors;
@ disjoint behaviors;
@ */
int max_seq(unsigned int *t, int len) {
if (len <= 0) return -1;
return t[max_idx(t, len)];
}
/* ---------------------------------------------------------------------------
Ci-après, la définition de la fonction [max_idx].
------------------------------------------------------------------------- */
/*@ requires \valid(t+(0..len-1));
@ requires len > 0;
@ assigns \nothing;
@ ensures len == 0 ==> \result == 0;
@ ensures \forall integer n; 0 <= n < len ==> t[\result] >= t[n];
@ ensures 0 <= \result < len;
@ */
int max_idx(unsigned int *t, int len) {
int max = 0;
/*@loop invariant 1 <= i <= len;
@loop invariant \forall integer n; 0 <= n < i ==> t[max] >= t[n];
@loop invariant 0 <= max < len;
@loop assigns i, max;
@loop variant len - i;
@ */
for(int i = 1; i < len; i++)
if (t[max] < t[i])
max = i;
return max;
}
| 34 |
#include <limits.h>
/*@
requires ((((((((0<x0) &&
(x0<100)) &&
(0<x1)) &&
(x1<100)) &&
(0<=x2)) &&
(0<=x3)) &&
(x2<x0)) &&
(x3<x1));
assigns \nothing;
ensures ((0<=\result) &&
(\result<(x0*x1)));
*/
int index(int x0, int x1, int x2, int x3) {
int x5 = x2 * x1;
int x6 = x5 + x3;
return x6;
}
/*@ predicate inv_matrix_Boolean(int * x26, integer x27, integer x28) = (((((x27<100) &&
(x28<100)) &&
(0<x27)) &&
(0<x28)) &&
(((x27*x28)>0) &&
\valid(x26+(0..(x27*x28)-1))));*/
/*@
requires (((inv_matrix_Boolean(x63,x64,x65) &&
inv_matrix_Boolean(x66,x67,x68)) &&
inv_matrix_Boolean(x69,x70,x71)) &&
((((x64==x67) &&
(x64==x70)) &&
(x65==x68)) &&
(x65==x71)));
ensures ((inv_matrix_Boolean(x63,x64,x65) &&
inv_matrix_Boolean(x66,x67,x68)) &&
inv_matrix_Boolean(x69,x70,x71));
*/
void add(int * x63, int x64, int x65, int * x66, int x67, int x68, int * x69, int x70, int x71) {
/*@
loop invariant 0<=x76<=x70;
loop assigns x76, x69[(0..(x70*x71)-1)];
loop variant x70-x76;
*/
for(int x76=0; x76 < x70; x76++) {
/*@
loop invariant 0<=x78<=x71;
loop assigns x78, x69[(0..(x70*x71)-1)];
loop variant x71-x78;
*/
for(int x78=0; x78 < x71; x78++) {
int x79 = index(x64,x65,x76,x78);
int x80 = x63[x79];
int x81 = index(x67,x68,x76,x78);
int x82 = x66[x81];
int x83 = x80 || x82;
int x84 = index(x70,x71,x76,x78);
x69[x84] = x83;
}
}
}
/*@
requires ((inv_matrix_Boolean(x111,x112,x113) &&
inv_matrix_Boolean(x114,x115,x116)) &&
((x112==x115) &&
(x113==x116)));
ensures (inv_matrix_Boolean(x111,x112,x113) &&
inv_matrix_Boolean(x114,x115,x116));
*/
void scalar_mult(int x110, int * x111, int x112, int x113, int * x114, int x115, int x116) {
/*@
loop invariant 0<=x121<=x115;
loop assigns x121, x114[(0..(x115*x116)-1)];
loop variant x115-x121;
*/
for(int x121=0; x121 < x115; x121++) {
/*@
loop invariant 0<=x123<=x116;
loop assigns x123, x114[(0..(x115*x116)-1)];
loop variant x116-x123;
*/
for(int x123=0; x123 < x116; x123++) {
int x126;
if (x110) {
int x124 = index(x112,x113,x121,x123);
int x125 = x111[x124];
x126 = x125;
} else {
x126 = 0/*false*/;
}
int x127 = index(x115,x116,x121,x123);
x114[x127] = x126;
}
}
}
| 66 |
#include <stdbool.h>
/*@ predicate is_equal(int *a, int n, int *b) =
\forall integer i; 0 <= i < n ==> a[i] == b[i];
*/
/*@ requires n >= 0;
requires \valid(a + (0 .. n-1));
requires \valid(b + (0 .. n-1));
assigns \nothing;
ensures is_equal(a, n, b) ? \result : !\result;
*/
bool equal(int *a, int n, int *b)
{
/*@ loop invariant 0 <= i <= n;
loop invariant is_equal(a, i, b);
loop variant n - i;
*/
for(int i = 0; i < n; ++i) {
if (a[i] != b[i]) {
return false;
}
}
return true;
}
| 66 |
/*@
requires -1000000000<a<1000000000;
requires -1000000000<b<1000000000;
ensures b==\result+a && b>a || b==a-\result && a>=b;
*/
int distance(int a,int b){
if(a < b)
return b - a ;
else
return a - b ;
}
| 7 |
/*@ requires size >= 0;
requires \valid(a+(0..size-1));
requires \valid(res+(0..size-1));
assigns res[0..size-1];
ensures \forall integer i; 0 <= i < size ==> res[i] == a[size - i - 1];
*/
void reverse(int a[], int res[], int size)
{
int i;
/*@ loop invariant -1 <= i < size;
loop invariant \forall integer j; i < j < size ==> res[j] == a[size - j - 1];
loop assigns i, res[0..size-1];
loop variant i;
*/
for(i = size - 1; i >= 0; --i) {
res[i] = a[size - i - 1];
}
}
| 20 |
#include<string.h>
/*@
predicate matchhere(char* r, char* s) =
(r[0]=='\0') ||
(r[0]!='\0' && r[1]=='*' &&
(\exists int i; 0 <= i <= strlen(s) && matchhere(r+2, s+i) &&
(r[0]=='.' || (\forall int j; 0 <= j < i ==> r[0]==s[j])))) ||
(r[0]=='$' && r[1]=='\0' && s[0]=='\0') ||
((s[0]!='\0' && (r[0]=='.' || r[0]==s[0])) &&
matchhere(r+1, s+1));
*/
/*@
requires strlen(r)>=0 && \valid(r+(0..strlen(r)));
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires r[0]=='.' && r[1]=='*' && r[2]=='A' && r[3]=='A' && r[4]=='B' && r[5]=='\0';
requires s[0]=='A' && s[1]=='A' && s[2]=='B' && s[3]=='\0';
ensures matchhere(r, s);
assigns \nothing;
*/
void dfa_spec_aab1(char* r, char* s) {}
/*@
requires strlen(r)>=0 && \valid(r+(0..strlen(r)));
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires r[0]=='.' && r[1]=='*' && r[2]=='A' && r[3]=='A' && r[4]=='B' && r[5]=='\0';
requires s[0]=='A' && s[1]=='A' && s[2]=='A' && s[3]=='B' && s[4]=='\0';
ensures matchhere(r, s);
assigns \nothing;
*/
void dfa_spec_aab1_1(char* r, char* s) {}
/*@
requires strlen(r)>=0 && \valid(r+(0..strlen(r)));
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires r[0]=='.' && r[1]=='*' && r[2]=='A' && r[3]=='A' && r[4]=='B' && r[5]=='\0';
requires s[0]=='A' && s[1]=='A' && s[2]=='X' && s[3]=='\0';
ensures !matchhere(r, s);
assigns \nothing;
*/
void dfa_spec_aab0(char* r, char* s) {}
| 12 |
/*@ ensures \result==0 || \result==1;
assigns \nothing;
*/
int predicate(int v) {
return v % 2 == 0;
}
/*@ requires n > 0;
requires \valid(v+(0..n-1));
requires \valid(o+(0..n-1));
ensures 0 <= \result <= n;
ensures \forall int i; 0 <= i < \result ==> 0 <= o[i] < n;
ensures \forall int i; 0 < i < \result ==> o[i-1] < o[i];
assigns o[0..n-1];
*/
int index_where(int* v, int n, int* o) {
int r = 0;
/*@
loop invariant 0 <= i <= n;
loop invariant 0 <= r <= i;
loop invariant \forall int j; 0 <= j < r ==> 0 <= o[j] < i;
loop invariant \forall int j; 0 < j < r ==> o[j-1] < o[j];
loop assigns i, r, o[0..n-1];
loop variant n-i;
*/
for (int i = 0; i < n; i++) {
if (predicate(v[i])) {
o[r++] = i;
}
}
return r;
}
| 31 |
int m = 0;
int t[10];
int *q = &m;
/*@ requires *p <= 100 && *p >= -100 && \valid(p);
ensures \result == \old(*p)+ 1 ; */
int incr(int *p)
{
q = p;
*p = *p + 1;
return *p;
};
| 7 |
#include <limits.h>
#include <string.h>
/*@
requires (((strlen(x0)>=0) &&
\valid(x0+(0..strlen(x0)))) &&
(strlen(x0)<=INT_MAX));
assigns \nothing;
*/
int dfa(char * x0) {
int x2 = 1/*true*/;
int x3 = 0;
//@ ghost int x4 = 0;
char *x5 = x0;
/*@
loop invariant (((((strlen(x0)>=0) &&
\valid(x0+(0..strlen(x0)))) &&
((0<=x4) &&
(x4<=strlen(x0)))) &&
(x5==(x0+x4))) &&
((strlen((x0+x4))>=0) &&
\valid((x0+x4)+(0..strlen((x0+x4))))));
loop invariant ((x5[0]=='\0') ==> (strlen(x0)==x4));
loop invariant ((!(x5[0]=='\0')) ==> (strlen(x0)!=x4));
loop invariant ((x3==3) || ((x3==2) || ((x3==1) || (x3==0))));
loop assigns x5, x4, x3, x2;
loop variant strlen(x5);
*/
for (;;) {
char *x7 = x5;
char x8 = x7[0];
int x9 = x8 == '\0';
int x13;
if (x9) {
x13 = 0/*false*/;
} else {
int x11 = x2;
x13 = x11;
}
if (!x13) break;
char *x39 = x5;
char *x40 = x39+1;
x5 = x40;
/*@ghost x4 = (x4+1);*/
}
char *x86 = x5;
char x87 = x86[0];
int x88 = x87 == '\0';
int x91;
if (x88) {
int x89 = x2;
x91 = x89;
} else {
x91 = 0/*false*/;
}
int x95;
if (x91) {
int x92 = x3;
int x93 = x92 == 3;
x95 = x93;
} else {
x95 = 0/*false*/;
}
/*@assert ((x5[0]=='\0') || (!x2));*/
return x95;
}
| 26 |
#define INT_MAX 2147483647
/*@ requires (a * 2) <= INT_MAX;
assigns \nothing;
ensures \result == a * 2;
*/
unsigned lshift(unsigned a)
{
return a << 1;
}
| 4 |
struct S {
int t1[2];
int t2[2];
};
struct T {
struct S *t[2];
};
/*@ requires \valid(s) && \valid(s->t[0]);
@*/
void f(struct T *s) {
s->t[0]->t1[0] = 1;
}
int main(struct T s, struct S a) {
s.t[0] = &a;
f(&s);
return 0;
}
/* on veut :
zones globales :
Zone 0: {s.t[0]; };
Zone 1: {a.t1[0]; };
zones locales :
f:
Zone 4: { *s; }
Zone 5: { s->t[0]; }
Appels:
f(..) ligne 25: zone 4 -> zone 0, zone 5 -> zone 1
*/
| 7 |
/*@ requires n>0 && \valid(t+(0..n-1));
ensures \forall integer i; 0<=i<n ==> t[i] == val;
*/
void fill(int t[],int val,int n) {
/*@ loop invariant 0<=i<=n;
loop invariant \forall integer j; 0<=j<i ==> t[j] == val;
loop variant n-i;
*/
for(int i=0;i<n;i++) {
t[i]=val;
}
} | 21 |
/*@
requires \valid(a) && \valid(b);
requires -10000000<*a<10000000 && -10000000<*b<10000000;
ensures \result==*a && \result>=*b || \result==*b && \result>=*a;
*/
int max_ptr(int* a,int* b){
return(*a > *b) ? *a: *b ;
}
extern int h ;
int main(){
h =42;
int a =24,b =42;
int x= max_ptr(&a,&b);
}
| 11 |
/*@
requires \valid(a) && \valid(b);
assigns *a, *b;
ensures *a == \old(*b);
ensures *b == \old(*a);
*/
void swap(int* a, int* b){
int tmp = *a;
*a = *b;
*b = tmp;
}
int main(){
int a = 42;
int b = 37;
swap(&a, &b);
//@ assert a == 37 && b == 42;
return 0;
}
| 14 |
// adding the assertions help prove preservation of the loop invariant. assert itself only proved by z3.
/*@ axiomatic Predicate_remove_copy {
logic integer predicate_remove_copy{La,Lb}(int* a, int* b, integer i_a, integer i_b, int value);
axiom predicate_remove_copy_empty{La,Lb}:
\forall int* a, int* b, value, integer i_a, i_b;
0 > i_a && 0 > i_b ==> predicate_remove_copy{La,Lb}(a, b, i_a, i_b, value) == 0;
axiom predicate_remove_copy_equal_value{La,Lb}:
\forall int* a, int* b, value, integer i_a, i_b;
0 <= i_a && \at(a[i_a],La) == value ==>
predicate_remove_copy{La,Lb}(a, b, i_a, i_b, value) ==
predicate_remove_copy{La,Lb}(a, b, i_a-1, i_b, value);
axiom predicate_remove_copy_not_equal_value{La,Lb}:
\forall int* a, int* b, value, integer i_a, i_b;
0 <= i_a && 0 <= i_b && (\at(a[i_a],La) != value <==> \at(a[i_a],La) == \at(b[i_b],Lb)) ==>
predicate_remove_copy{La,Lb}(a, b, i_a, i_b, value) ==
predicate_remove_copy{La,Lb}(a, b, i_a-1, i_b-1, value)+1;
axiom predicate_remove_copy_label{La,Lb1,Lb2}:
\forall int* a, int* b, value, integer i_a, i_b;
(\forall integer i; 0<= i <= i_b ==>
\at(b[i],Lb1) == \at(b[i],Lb2)) ==>
predicate_remove_copy{La,Lb1}(a,b,i_a,i_b,value) ==
predicate_remove_copy{La,Lb2}(a,b,i_a,i_b,value);
}
*/
/*@
requires 0 <= length;
requires \valid_range (a, 0, length-1);
requires \valid_range (dest, 0, length-1);
ensures 0 <= \result <= length;
ensures \forall integer k; 0 <= k < \result ==> dest[k] != value;
ensures \result == predicate_remove_copy{Old,Here}(a, dest, length-1, \result-1, value);
*/
int remove_copy_array (int* a, int length, int* dest, int value )
{
int i_a = 0;
int i_dest = 0;
/*@
loop invariant 0 <= i_a <= length;
loop invariant i_dest <= i_a;
loop invariant 0 <= i_dest <= length;
loop invariant \forall integer k; 0 <= k < i_dest ==> dest[k] != value;
loop invariant i_dest == predicate_remove_copy{Pre,Here}(a, dest, i_a-1, i_dest-1, value);
*/
for ( ; i_a != length; ++i_a)
if (a[i_a] != value)
{
dest[i_dest] = a[i_a];
/*@assert
i_dest+1==predicate_remove_copy{Pre,Here}(a,dest,i_a,i_dest,value);
*/
++i_dest;
}
return i_dest;
}
| 14 |
#include <limits.h>
#include <string.h>
char * p_HTTP(char * x1096);
char * p_(char * x1098);
char * p_ContentLength(char * x1100);
/*@
requires ((strlen(x0)>=0) &&
\valid(x0+(0..strlen(x0))));
assigns \nothing;
*/
int p(char * x0) {
int x2 = -1;
char *x3 = p_HTTP(x0);
int x5 = 1/*true*/;
int x6 = 0;
char *x7 = 0/*null*/;
int x8 = 1/*true*/;
int x9 = 0;
char *x10 = 0/*null*/;
int x11 = 1/*true*/;
int x12 = 0;
char *x13 = 0/*null*/;
int x14 = 1/*true*/;
int x15 = 0;
char *x16 = 0/*null*/;
int x17 = 1/*true*/;
char *x19 = 0/*null*/;
int x20 = 1/*true*/;
char *x22 = 0/*null*/;
int x23 = 1/*true*/;
char x24 = '\0';
char *x25 = 0/*null*/;
int x26 = 1/*true*/;
char *x28 = 0/*null*/;
int x29 = 1/*true*/;
char *x31 = 0/*null*/;
int x32 = 0 == x3;
if (x32) {
x31 = x0;
} else {
x29 = 0/*false*/;
x31 = x3;
}
int x40 = x29;
if (x40) {
char *x41 = x31;
x28 = x41;
} else {
char *x45 = x31;
int x52 = 1/*true*/;
char x53 = '\0';
char *x54 = 0/*null*/;
char x46 = x45[0];
int x47 = x46 == '\0';
if (x47) {
x54 = x45;
} else {
int x48 = x46 >= '0';
int x50;
if (x48) {
int x49 = x46 <= '9';
x50 = x49;
} else {
x50 = 0/*false*/;
}
if (x50) {
x52 = 0/*false*/;
x53 = x46;
char *x51 = x45+1;
x54 = x51;
} else {
x54 = x45;
}
}
int x66 = x52;
if (x66) {
char *x67 = x54;
x28 = x67;
} else {
char x70 = x53;
char *x71 = x54;
char *x72 = x71;
int x73 = 1/*true*/;
/*@
loop invariant ((strlen(x72)>=0) &&
\valid(x72+(0..strlen(x72))));
loop assigns x72, x73;
*/
for (;;) {
int x74 = x73;
if (!x74) break;
char *x76 = x72;
char x77 = x76[0];
int x78 = x77 == '\0';
if (x78) {
x73 = 0/*false*/;
} else {
int x79 = x77 >= '0';
int x81;
if (x79) {
int x80 = x77 <= '9';
x81 = x80;
} else {
x81 = 0/*false*/;
}
if (x81) {
char *x82 = x76+1;
x72 = x82;
} else {
x73 = 0/*false*/;
}
}
}
char *x106 = x72;
x26 = 0/*false*/;
x28 = x106;
}
}
int x114 = x26;
if (x114) {
char *x115 = x28;
x25 = x115;
} else {
char *x119 = x28;
char x120 = x119[0];
int x121 = x120 == '\0';
if (x121) {
x25 = x119;
} else {
int x122 = x120 == '.';
if (x122) {
x23 = 0/*false*/;
x24 = x120;
char *x123 = x119+1;
x25 = x123;
} else {
x25 = x119;
}
}
}
int x137 = x23;
if (x137) {
char *x138 = x25;
x22 = x138;
} else {
char x141 = x24;
char *x142 = x25;
int x149 = 1/*true*/;
char x150 = '\0';
char *x151 = 0/*null*/;
char x143 = x142[0];
int x144 = x143 == '\0';
if (x144) {
x151 = x142;
} else {
int x145 = x143 >= '0';
int x147;
if (x145) {
int x146 = x143 <= '9';
x147 = x146;
} else {
x147 = 0/*false*/;
}
if (x147) {
x149 = 0/*false*/;
x150 = x143;
char *x148 = x142+1;
x151 = x148;
} else {
x151 = x142;
}
}
int x163 = x149;
if (x163) {
char *x164 = x151;
x22 = x164;
} else {
char x167 = x150;
char *x168 = x151;
char *x169 = x168;
int x170 = 1/*true*/;
/*@
loop invariant ((strlen(x169)>=0) &&
\valid(x169+(0..strlen(x169))));
loop assigns x169, x170;
*/
for (;;) {
int x171 = x170;
if (!x171) break;
char *x173 = x169;
char x174 = x173[0];
int x175 = x174 == '\0';
if (x175) {
x170 = 0/*false*/;
} else {
int x176 = x174 >= '0';
int x178;
if (x176) {
int x177 = x174 <= '9';
x178 = x177;
} else {
x178 = 0/*false*/;
}
if (x178) {
char *x179 = x173+1;
x169 = x179;
} else {
x170 = 0/*false*/;
}
}
}
char *x203 = x169;
x20 = 0/*false*/;
x22 = x203;
}
}
int x211 = x20;
if (x211) {
char *x212 = x22;
x19 = x212;
} else {
char *x216 = x22;
char *x217 = x216;
int x218 = 1/*true*/;
/*@
loop invariant ((strlen(x217)>=0) &&
\valid(x217+(0..strlen(x217))));
loop assigns x217, x218;
*/
for (;;) {
int x219 = x218;
if (!x219) break;
char *x221 = x217;
char x222 = x221[0];
int x223 = x222 == '\0';
if (x223) {
x218 = 0/*false*/;
} else {
int x224 = x222 == ' ';
if (x224) {
char *x225 = x221+1;
x217 = x225;
} else {
x218 = 0/*false*/;
}
}
}
char *x249 = x217;
x17 = 0/*false*/;
x19 = x249;
}
int x255 = x17;
if (x255) {
char *x256 = x19;
x16 = x256;
} else {
char *x260 = x19;
int x267 = 1/*true*/;
int x268 = 0;
char *x269 = 0/*null*/;
int x270 = 1/*true*/;
char x271 = '\0';
char *x272 = 0/*null*/;
char x261 = x260[0];
int x262 = x261 == '\0';
if (x262) {
x272 = x260;
} else {
int x263 = x261 >= '0';
int x265;
if (x263) {
int x264 = x261 <= '9';
x265 = x264;
} else {
x265 = 0/*false*/;
}
if (x265) {
x270 = 0/*false*/;
x271 = x261;
char *x266 = x260+1;
x272 = x266;
} else {
x272 = x260;
}
}
int x284 = x270;
if (x284) {
char *x285 = x272;
x269 = x285;
} else {
char x288 = x271;
char *x290 = x272;
x267 = 0/*false*/;
char x289 = x288 - '0';
x268 = x289;
x269 = x290;
}
int x296 = x267;
if (x296) {
char *x297 = x269;
x16 = x297;
} else {
int x300 = x268;
char *x301 = x269;
char *x302 = x301;
int x303 = 1/*true*/;
int x304 = x300;
int x337 = INT_MAX;
int x338 = x337 / 10;
int x339 = x338 - 10;
/*@
loop invariant (((strlen(x302)>=0) &&
\valid(x302+(0..strlen(x302)))) &&
((x304==-1) || (0<=x304)));
loop assigns x302, x303, x304;
*/
for (;;) {
int x305 = x303;
if (!x305) break;
char *x307 = x302;
int x314 = 1/*true*/;
char x315 = '\0';
char *x316 = 0/*null*/;
char x308 = x307[0];
int x309 = x308 == '\0';
if (x309) {
x316 = x307;
} else {
int x310 = x308 >= '0';
int x312;
if (x310) {
int x311 = x308 <= '9';
x312 = x311;
} else {
x312 = 0/*false*/;
}
if (x312) {
x314 = 0/*false*/;
x315 = x308;
char *x313 = x307+1;
x316 = x313;
} else {
x316 = x307;
}
}
int x328 = x314;
if (x328) {
char *x329 = x316;
x303 = 0/*false*/;
} else {
char x332 = x315;
char *x334 = x316;
int x335 = x304;
int x336 = x335 < 0;
int x344;
if (x336) {
x344 = x335;
} else {
int x340 = x335 > x339;
int x343;
if (x340) {
x343 = -1;
} else {
char x333 = x332 - '0';
int x341 = x335 * 10;
int x342 = x341 + x333;
x343 = x342;
}
x344 = x343;
}
x304 = x344;
x302 = x334;
}
}
int x370 = x304;
char *x371 = x302;
x14 = 0/*false*/;
x15 = x370;
x16 = x371;
}
}
int x379 = x14;
if (x379) {
char *x380 = x16;
x13 = x380;
} else {
int x383 = x15;
char *x384 = x16;
char *x385 = x384;
int x386 = 1/*true*/;
/*@
loop invariant ((strlen(x385)>=0) &&
\valid(x385+(0..strlen(x385))));
loop assigns x385, x386;
*/
for (;;) {
int x387 = x386;
if (!x387) break;
char *x389 = x385;
char x390 = x389[0];
int x391 = x390 == '\0';
if (x391) {
x386 = 0/*false*/;
} else {
int x396 = x390 == '\r';
if (x396) {
x386 = 0/*false*/;
} else {
char *x393 = x389+1;
x385 = x393;
}
}
}
char *x418 = x385;
int x419 = 1/*true*/;
char *x421 = 0/*null*/;
x419 = 0/*false*/;
x421 = x418;
int x425 = x419;
if (x425) {
char *x426 = x421;
x13 = x426;
} else {
char *x430 = x421;
char *x431 = p_(x430);
int x433 = 1/*true*/;
char *x435 = 0/*null*/;
int x436 = 0 == x431;
if (x436) {
x435 = x430;
} else {
x433 = 0/*false*/;
x435 = x431;
}
int x444 = x433;
if (x444) {
char *x445 = x435;
x13 = x445;
} else {
char *x449 = x435;
x11 = 0/*false*/;
x12 = x383;
x13 = x449;
}
}
}
int x459 = x11;
if (x459) {
char *x460 = x13;
x10 = x460;
} else {
int x463 = x12;
char *x464 = x13;
char *x465 = x464;
int x466 = 1/*true*/;
int x467 = 0;
int x337 = INT_MAX;
int x338 = x337 / 10;
int x339 = x338 - 10;
int x953 = -2 == -2;
/*@
loop invariant ((strlen(x465)>=0) &&
\valid(x465+(0..strlen(x465))));
loop assigns x465, x466, x467;
*/
for (;;) {
int x468 = x466;
if (!x468) break;
char *x470 = x465;
char *x471 = p_ContentLength(x470);
int x473 = 1/*true*/;
int x474 = 0;
char *x475 = 0/*null*/;
int x476 = 1/*true*/;
int x477 = 0;
char *x478 = 0/*null*/;
int x479 = 1/*true*/;
int x480 = 0;
char *x481 = 0/*null*/;
int x482 = 1/*true*/;
int x483 = 0;
char *x484 = 0/*null*/;
int x485 = 1/*true*/;
int x486 = 0;
char *x487 = 0/*null*/;
int x488 = 1/*true*/;
char *x490 = 0/*null*/;
int x491 = 0 == x471;
if (x491) {
x490 = x470;
} else {
x488 = 0/*false*/;
x490 = x471;
}
int x499 = x488;
if (x499) {
char *x500 = x490;
} else {
char *x503 = x490;
x485 = 0/*false*/;
x486 = 1;
x487 = x503;
}
int x509 = x485;
if (x509) {
char *x510 = x470;
int x511 = 1/*true*/;
/*@
loop invariant ((strlen(x510)>=0) &&
\valid(x510+(0..strlen(x510))));
loop assigns x510, x511;
*/
for (;;) {
int x512 = x511;
if (!x512) break;
char *x514 = x510;
char x515 = x514[0];
int x516 = x515 == '\0';
if (x516) {
x511 = 0/*false*/;
} else {
int x518 = x515 == ':';
int x520;
if (x518) {
x520 = 0/*false*/;
} else {
int x519 = x515 != ' ';
x520 = x519;
}
if (x520) {
char *x521 = x514+1;
x510 = x521;
} else {
x511 = 0/*false*/;
}
}
}
char *x545 = x510;
x482 = 0/*false*/;
x483 = 0;
x484 = x545;
} else {
int x550 = x486;
char *x551 = x487;
x482 = 0/*false*/;
x483 = x550;
x484 = x551;
}
int x557 = x482;
if (x557) {
char *x558 = x484;
x481 = x558;
} else {
int x561 = x483;
char *x562 = x484;
char *x563 = x562;
int x564 = 1/*true*/;
/*@
loop invariant ((strlen(x563)>=0) &&
\valid(x563+(0..strlen(x563))));
loop assigns x563, x564;
*/
for (;;) {
int x565 = x564;
if (!x565) break;
char *x567 = x563;
char x568 = x567[0];
int x569 = x568 == '\0';
if (x569) {
x564 = 0/*false*/;
} else {
int x570 = x568 == ' ';
if (x570) {
char *x571 = x567+1;
x563 = x571;
} else {
x564 = 0/*false*/;
}
}
}
char *x595 = x563;
x479 = 0/*false*/;
x480 = x561;
x481 = x595;
}
int x601 = x479;
if (x601) {
char *x602 = x481;
x478 = x602;
} else {
int x605 = x480;
char *x606 = x481;
int x611 = 1/*true*/;
char x612 = '\0';
char *x613 = 0/*null*/;
char x607 = x606[0];
int x608 = x607 == '\0';
if (x608) {
x613 = x606;
} else {
int x609 = x607 == ':';
if (x609) {
x611 = 0/*false*/;
x612 = x607;
char *x610 = x606+1;
x613 = x610;
} else {
x613 = x606;
}
}
int x625 = x611;
if (x625) {
char *x626 = x613;
x478 = x626;
} else {
char x629 = x612;
char *x630 = x613;
x476 = 0/*false*/;
x477 = x605;
x478 = x630;
}
}
int x638 = x476;
if (x638) {
char *x639 = x478;
x475 = x639;
} else {
int x642 = x477;
char *x643 = x478;
char *x644 = x643;
int x645 = 1/*true*/;
/*@
loop invariant ((strlen(x644)>=0) &&
\valid(x644+(0..strlen(x644))));
loop assigns x644, x645;
*/
for (;;) {
int x646 = x645;
if (!x646) break;
char *x648 = x644;
char x649 = x648[0];
int x650 = x649 == '\0';
if (x650) {
x645 = 0/*false*/;
} else {
int x651 = x649 == ' ';
if (x651) {
char *x652 = x648+1;
x644 = x652;
} else {
x645 = 0/*false*/;
}
}
}
char *x676 = x644;
x473 = 0/*false*/;
x474 = x642;
x475 = x676;
}
int x682 = x473;
if (x682) {
char *x683 = x475;
x466 = 0/*false*/;
} else {
int x686 = x474;
char *x687 = x475;
char *x695 = x687;
int x696 = 1/*true*/;
/*@
loop invariant ((strlen(x695)>=0) &&
\valid(x695+(0..strlen(x695))));
loop assigns x695, x696;
*/
for (;;) {
int x697 = x696;
if (!x697) break;
char *x699 = x695;
char x700 = x699[0];
int x701 = x700 == '\0';
if (x701) {
x696 = 0/*false*/;
} else {
int x706 = x700 == '\r';
if (x706) {
x696 = 0/*false*/;
} else {
char *x703 = x699+1;
x695 = x703;
}
}
}
char *x728 = x695;
int x688 = x686 == 1;
if (x688) {
int x729 = 1/*true*/;
int x730 = 0;
char *x731 = 0/*null*/;
int x732 = 1/*true*/;
int x733 = 0;
char *x734 = 0/*null*/;
int x735 = 1/*true*/;
int x736 = 0;
char *x737 = 0/*null*/;
int x738 = 1/*true*/;
char x739 = '\0';
char *x740 = 0/*null*/;
char x689 = x687[0];
int x690 = x689 == '\0';
if (x690) {
x740 = x687;
} else {
int x691 = x689 >= '0';
int x693;
if (x691) {
int x692 = x689 <= '9';
x693 = x692;
} else {
x693 = 0/*false*/;
}
if (x693) {
x738 = 0/*false*/;
x739 = x689;
char *x694 = x687+1;
x740 = x694;
} else {
x740 = x687;
}
}
int x752 = x738;
if (x752) {
char *x753 = x740;
x737 = x753;
} else {
char x756 = x739;
char *x758 = x740;
x735 = 0/*false*/;
char x757 = x756 - '0';
x736 = x757;
x737 = x758;
}
int x764 = x735;
if (x764) {
char *x765 = x737;
x734 = x765;
} else {
int x768 = x736;
char *x769 = x737;
char *x770 = x769;
int x771 = 1/*true*/;
int x772 = x768;
/*@
loop invariant (((strlen(x770)>=0) &&
\valid(x770+(0..strlen(x770)))) &&
((x772==-1) || (0<=x772)));
loop assigns x770, x771, x772;
*/
for (;;) {
int x773 = x771;
if (!x773) break;
char *x775 = x770;
int x782 = 1/*true*/;
char x783 = '\0';
char *x784 = 0/*null*/;
char x776 = x775[0];
int x777 = x776 == '\0';
if (x777) {
x784 = x775;
} else {
int x778 = x776 >= '0';
int x780;
if (x778) {
int x779 = x776 <= '9';
x780 = x779;
} else {
x780 = 0/*false*/;
}
if (x780) {
x782 = 0/*false*/;
x783 = x776;
char *x781 = x775+1;
x784 = x781;
} else {
x784 = x775;
}
}
int x796 = x782;
if (x796) {
char *x797 = x784;
x771 = 0/*false*/;
} else {
char x800 = x783;
char *x802 = x784;
int x803 = x772;
int x804 = x803 < 0;
int x809;
if (x804) {
x809 = x803;
} else {
int x805 = x803 > x339;
int x808;
if (x805) {
x808 = -1;
} else {
char x801 = x800 - '0';
int x806 = x803 * 10;
int x807 = x806 + x801;
x808 = x807;
}
x809 = x808;
}
x772 = x809;
x770 = x802;
}
}
int x835 = x772;
char *x836 = x770;
x732 = 0/*false*/;
x733 = x835;
x734 = x836;
}
int x842 = x732;
if (x842) {
char *x843 = x734;
x731 = x843;
} else {
int x846 = x733;
char *x847 = x734;
char *x848 = x847;
int x849 = 1/*true*/;
/*@
loop invariant ((strlen(x848)>=0) &&
\valid(x848+(0..strlen(x848))));
loop assigns x848, x849;
*/
for (;;) {
int x850 = x849;
if (!x850) break;
char *x852 = x848;
char x853 = x852[0];
int x854 = x853 == '\0';
if (x854) {
x849 = 0/*false*/;
} else {
int x855 = x853 == ' ';
if (x855) {
char *x856 = x852+1;
x848 = x856;
} else {
x849 = 0/*false*/;
}
}
}
char *x880 = x848;
x729 = 0/*false*/;
x730 = x846;
x731 = x880;
}
int x886 = x729;
if (x886) {
char *x887 = x731;
x466 = 0/*false*/;
} else {
int x890 = x730;
char *x891 = x731;
char *x892 = p_(x891);
int x894 = 1/*true*/;
char *x896 = 0/*null*/;
int x897 = 0 == x892;
if (x897) {
x896 = x891;
} else {
x894 = 0/*false*/;
x896 = x892;
}
int x905 = x894;
if (x905) {
char *x906 = x896;
x466 = 0/*false*/;
} else {
char *x910 = x896;
int x911 = x467;
int x912 = x890 == -2;
int x913;
if (x912) {
x913 = x911;
} else {
x913 = x890;
}
x467 = x913;
x465 = x910;
}
}
} else {
int x921 = 1/*true*/;
char *x923 = 0/*null*/;
x921 = 0/*false*/;
x923 = x728;
int x927 = x921;
if (x927) {
char *x928 = x923;
x466 = 0/*false*/;
} else {
char *x932 = x923;
char *x933 = p_(x932);
int x935 = 1/*true*/;
char *x937 = 0/*null*/;
int x938 = 0 == x933;
if (x938) {
x937 = x932;
} else {
x935 = 0/*false*/;
x937 = x933;
}
int x946 = x935;
if (x946) {
char *x947 = x937;
x466 = 0/*false*/;
} else {
char *x951 = x937;
int x952 = x467;
int x954;
if (x953) {
x954 = x952;
} else {
x954 = -2;
}
x467 = x954;
x465 = x951;
}
}
}
}
}
int x981 = x467;
char *x982 = x465;
x8 = 0/*false*/;
x9 = x981;
x10 = x982;
}
int x988 = x8;
if (x988) {
char *x989 = x10;
x7 = x989;
} else {
int x992 = x9;
char *x993 = x10;
char *x994 = p_(x993);
int x996 = 1/*true*/;
char *x998 = 0/*null*/;
int x999 = 0 == x994;
if (x999) {
x998 = x993;
} else {
x996 = 0/*false*/;
x998 = x994;
}
int x1007 = x996;
if (x1007) {
char *x1008 = x998;
x7 = x1008;
} else {
char *x1012 = x998;
x5 = 0/*false*/;
x6 = x992;
x7 = x1012;
}
}
int x1020 = x5;
if (x1020) {
char *x1021 = x7;
} else {
int x1023 = x6;
char *x1024 = x7;
int x1026 = 1/*true*/;
char *x1027 = x1024;
/*@
loop invariant ((0<=x1029) &&
((strlen(x1027)>=0) &&
\valid(x1027+(0..strlen(x1027)))));
loop assigns x1029, x1026, x1027;
loop variant (x6-x1029);
*/
for(int x1029=0; x1029 < x1023; x1029++) {
int x1030 = x1026;
if (x1030) {
char *x1031 = x1027;
char x1032 = x1031[0];
int x1033 = x1032 == '\0';
if (x1033) {
x1026 = 0/*false*/;
} else {
char *x1034 = x1031+1;
x1027 = x1034;
}
} else {
}
}
int x1060 = x1026;
char *x1061 = x1027;
int x1025 = x1023 < 0;
if (x1025) {
} else {
int x1062 = 1/*true*/;
char *x1064 = 0/*null*/;
if (x1060) {
x1062 = 0/*false*/;
x1064 = x1061;
} else {
x1064 = x1024;
}
int x1072 = x1062;
if (x1072) {
char *x1073 = x1064;
} else {
char *x1076 = x1064;
char x1077 = x1076[0];
int x1078 = x1077 == '\0';
if (x1078) {
x2 = x1023;
} else {
}
}
}
}
int x1088 = x2;
return x1088;
}
/*@
requires ((strlen(x1102)>=0) &&
\valid(x1102+(0..strlen(x1102))));
assigns \nothing;
ensures ((0==\result) || ((strlen(\result)>=0) &&
\valid(\result+(0..strlen(\result)))));
*/
char * p_HTTP(char * x1102) {
char *x1104 = x1102;
int x1109 = 1/*true*/;
char x1110 = '\0';
char *x1111 = 0/*null*/;
char x1105 = x1102[0];
int x1106 = x1105 == '\0';
if (x1106) {
x1111 = x1102;
} else {
int x1107 = x1105 == 'H';
if (x1107) {
x1109 = 0/*false*/;
x1110 = x1105;
char *x1108 = x1102+1;
x1111 = x1108;
} else {
x1111 = x1102;
}
}
int x1123 = x1109;
if (x1123) {
char *x1124 = x1111;
x1104 = 0;
} else {
char x1127 = x1110;
char *x1128 = x1111;
int x1133 = 1/*true*/;
char x1134 = '\0';
char *x1135 = 0/*null*/;
char x1129 = x1128[0];
int x1130 = x1129 == '\0';
if (x1130) {
x1135 = x1128;
} else {
int x1131 = x1129 == 'T';
if (x1131) {
x1133 = 0/*false*/;
x1134 = x1129;
char *x1132 = x1128+1;
x1135 = x1132;
} else {
x1135 = x1128;
}
}
int x1147 = x1133;
if (x1147) {
char *x1148 = x1135;
x1104 = 0;
} else {
char x1151 = x1134;
char *x1152 = x1135;
int x1157 = 1/*true*/;
char x1158 = '\0';
char *x1159 = 0/*null*/;
char x1153 = x1152[0];
int x1154 = x1153 == '\0';
if (x1154) {
x1159 = x1152;
} else {
int x1155 = x1153 == 'T';
if (x1155) {
x1157 = 0/*false*/;
x1158 = x1153;
char *x1156 = x1152+1;
x1159 = x1156;
} else {
x1159 = x1152;
}
}
int x1171 = x1157;
if (x1171) {
char *x1172 = x1159;
x1104 = 0;
} else {
char x1175 = x1158;
char *x1176 = x1159;
int x1181 = 1/*true*/;
char x1182 = '\0';
char *x1183 = 0/*null*/;
char x1177 = x1176[0];
int x1178 = x1177 == '\0';
if (x1178) {
x1183 = x1176;
} else {
int x1179 = x1177 == 'P';
if (x1179) {
x1181 = 0/*false*/;
x1182 = x1177;
char *x1180 = x1176+1;
x1183 = x1180;
} else {
x1183 = x1176;
}
}
int x1195 = x1181;
if (x1195) {
char *x1196 = x1183;
x1104 = 0;
} else {
char x1199 = x1182;
char *x1200 = x1183;
int x1205 = 1/*true*/;
char x1206 = '\0';
char *x1207 = 0/*null*/;
char x1201 = x1200[0];
int x1202 = x1201 == '\0';
if (x1202) {
x1207 = x1200;
} else {
int x1203 = x1201 == '/';
if (x1203) {
x1205 = 0/*false*/;
x1206 = x1201;
char *x1204 = x1200+1;
x1207 = x1204;
} else {
x1207 = x1200;
}
}
int x1219 = x1205;
if (x1219) {
char *x1220 = x1207;
x1104 = 0;
} else {
char x1223 = x1206;
char *x1224 = x1207;
x1104 = x1224;
}
}
}
}
}
char *x1236 = x1104;
return x1236;
}
/*@
requires ((strlen(x1252)>=0) &&
\valid(x1252+(0..strlen(x1252))));
assigns \nothing;
ensures ((0==\result) || ((strlen(\result)>=0) &&
\valid(\result+(0..strlen(\result)))));
*/
char * p_(char * x1252) {
char *x1254 = x1252;
int x1259 = 1/*true*/;
char x1260 = '\0';
char *x1261 = 0/*null*/;
char x1255 = x1252[0];
int x1256 = x1255 == '\0';
if (x1256) {
x1261 = x1252;
} else {
int x1257 = x1255 == '\r';
if (x1257) {
x1259 = 0/*false*/;
x1260 = x1255;
char *x1258 = x1252+1;
x1261 = x1258;
} else {
x1261 = x1252;
}
}
int x1273 = x1259;
if (x1273) {
char *x1274 = x1261;
x1254 = 0;
} else {
char x1277 = x1260;
char *x1278 = x1261;
int x1283 = 1/*true*/;
char x1284 = '\0';
char *x1285 = 0/*null*/;
char x1279 = x1278[0];
int x1280 = x1279 == '\0';
if (x1280) {
x1285 = x1278;
} else {
int x1281 = x1279 == '\n';
if (x1281) {
x1283 = 0/*false*/;
x1284 = x1279;
char *x1282 = x1278+1;
x1285 = x1282;
} else {
x1285 = x1278;
}
}
int x1297 = x1283;
if (x1297) {
char *x1298 = x1285;
x1254 = 0;
} else {
char x1301 = x1284;
char *x1302 = x1285;
x1254 = x1302;
}
}
char *x1308 = x1254;
return x1308;
}
/*@
requires ((strlen(x1324)>=0) &&
\valid(x1324+(0..strlen(x1324))));
assigns \nothing;
ensures ((0==\result) || ((strlen(\result)>=0) &&
\valid(\result+(0..strlen(\result)))));
*/
char * p_ContentLength(char * x1324) {
char *x1326 = x1324;
int x1331 = 1/*true*/;
char x1332 = '\0';
char *x1333 = 0/*null*/;
char x1327 = x1324[0];
int x1328 = x1327 == '\0';
if (x1328) {
x1333 = x1324;
} else {
int x1329 = x1327 == 'C';
if (x1329) {
x1331 = 0/*false*/;
x1332 = x1327;
char *x1330 = x1324+1;
x1333 = x1330;
} else {
x1333 = x1324;
}
}
int x1345 = x1331;
if (x1345) {
char *x1346 = x1333;
x1326 = 0;
} else {
char x1349 = x1332;
char *x1350 = x1333;
int x1355 = 1/*true*/;
char x1356 = '\0';
char *x1357 = 0/*null*/;
char x1351 = x1350[0];
int x1352 = x1351 == '\0';
if (x1352) {
x1357 = x1350;
} else {
int x1353 = x1351 == 'o';
if (x1353) {
x1355 = 0/*false*/;
x1356 = x1351;
char *x1354 = x1350+1;
x1357 = x1354;
} else {
x1357 = x1350;
}
}
int x1369 = x1355;
if (x1369) {
char *x1370 = x1357;
x1326 = 0;
} else {
char x1373 = x1356;
char *x1374 = x1357;
int x1379 = 1/*true*/;
char x1380 = '\0';
char *x1381 = 0/*null*/;
char x1375 = x1374[0];
int x1376 = x1375 == '\0';
if (x1376) {
x1381 = x1374;
} else {
int x1377 = x1375 == 'n';
if (x1377) {
x1379 = 0/*false*/;
x1380 = x1375;
char *x1378 = x1374+1;
x1381 = x1378;
} else {
x1381 = x1374;
}
}
int x1393 = x1379;
if (x1393) {
char *x1394 = x1381;
x1326 = 0;
} else {
char x1397 = x1380;
char *x1398 = x1381;
int x1403 = 1/*true*/;
char x1404 = '\0';
char *x1405 = 0/*null*/;
char x1399 = x1398[0];
int x1400 = x1399 == '\0';
if (x1400) {
x1405 = x1398;
} else {
int x1401 = x1399 == 't';
if (x1401) {
x1403 = 0/*false*/;
x1404 = x1399;
char *x1402 = x1398+1;
x1405 = x1402;
} else {
x1405 = x1398;
}
}
int x1417 = x1403;
if (x1417) {
char *x1418 = x1405;
x1326 = 0;
} else {
char x1421 = x1404;
char *x1422 = x1405;
int x1427 = 1/*true*/;
char x1428 = '\0';
char *x1429 = 0/*null*/;
char x1423 = x1422[0];
int x1424 = x1423 == '\0';
if (x1424) {
x1429 = x1422;
} else {
int x1425 = x1423 == 'e';
if (x1425) {
x1427 = 0/*false*/;
x1428 = x1423;
char *x1426 = x1422+1;
x1429 = x1426;
} else {
x1429 = x1422;
}
}
int x1441 = x1427;
if (x1441) {
char *x1442 = x1429;
x1326 = 0;
} else {
char x1445 = x1428;
char *x1446 = x1429;
int x1451 = 1/*true*/;
char x1452 = '\0';
char *x1453 = 0/*null*/;
char x1447 = x1446[0];
int x1448 = x1447 == '\0';
if (x1448) {
x1453 = x1446;
} else {
int x1449 = x1447 == 'n';
if (x1449) {
x1451 = 0/*false*/;
x1452 = x1447;
char *x1450 = x1446+1;
x1453 = x1450;
} else {
x1453 = x1446;
}
}
int x1465 = x1451;
if (x1465) {
char *x1466 = x1453;
x1326 = 0;
} else {
char x1469 = x1452;
char *x1470 = x1453;
int x1475 = 1/*true*/;
char x1476 = '\0';
char *x1477 = 0/*null*/;
char x1471 = x1470[0];
int x1472 = x1471 == '\0';
if (x1472) {
x1477 = x1470;
} else {
int x1473 = x1471 == 't';
if (x1473) {
x1475 = 0/*false*/;
x1476 = x1471;
char *x1474 = x1470+1;
x1477 = x1474;
} else {
x1477 = x1470;
}
}
int x1489 = x1475;
if (x1489) {
char *x1490 = x1477;
x1326 = 0;
} else {
char x1493 = x1476;
char *x1494 = x1477;
int x1499 = 1/*true*/;
char x1500 = '\0';
char *x1501 = 0/*null*/;
char x1495 = x1494[0];
int x1496 = x1495 == '\0';
if (x1496) {
x1501 = x1494;
} else {
int x1497 = x1495 == '-';
if (x1497) {
x1499 = 0/*false*/;
x1500 = x1495;
char *x1498 = x1494+1;
x1501 = x1498;
} else {
x1501 = x1494;
}
}
int x1513 = x1499;
if (x1513) {
char *x1514 = x1501;
x1326 = 0;
} else {
char x1517 = x1500;
char *x1518 = x1501;
int x1523 = 1/*true*/;
char x1524 = '\0';
char *x1525 = 0/*null*/;
char x1519 = x1518[0];
int x1520 = x1519 == '\0';
if (x1520) {
x1525 = x1518;
} else {
int x1521 = x1519 == 'L';
if (x1521) {
x1523 = 0/*false*/;
x1524 = x1519;
char *x1522 = x1518+1;
x1525 = x1522;
} else {
x1525 = x1518;
}
}
int x1537 = x1523;
if (x1537) {
char *x1538 = x1525;
x1326 = 0;
} else {
char x1541 = x1524;
char *x1542 = x1525;
int x1547 = 1/*true*/;
char x1548 = '\0';
char *x1549 = 0/*null*/;
char x1543 = x1542[0];
int x1544 = x1543 == '\0';
if (x1544) {
x1549 = x1542;
} else {
int x1545 = x1543 == 'e';
if (x1545) {
x1547 = 0/*false*/;
x1548 = x1543;
char *x1546 = x1542+1;
x1549 = x1546;
} else {
x1549 = x1542;
}
}
int x1561 = x1547;
if (x1561) {
char *x1562 = x1549;
x1326 = 0;
} else {
char x1565 = x1548;
char *x1566 = x1549;
int x1571 = 1/*true*/;
char x1572 = '\0';
char *x1573 = 0/*null*/;
char x1567 = x1566[0];
int x1568 = x1567 == '\0';
if (x1568) {
x1573 = x1566;
} else {
int x1569 = x1567 == 'n';
if (x1569) {
x1571 = 0/*false*/;
x1572 = x1567;
char *x1570 = x1566+1;
x1573 = x1570;
} else {
x1573 = x1566;
}
}
int x1585 = x1571;
if (x1585) {
char *x1586 = x1573;
x1326 = 0;
} else {
char x1589 = x1572;
char *x1590 = x1573;
int x1595 = 1/*true*/;
char x1596 = '\0';
char *x1597 = 0/*null*/;
char x1591 = x1590[0];
int x1592 = x1591 == '\0';
if (x1592) {
x1597 = x1590;
} else {
int x1593 = x1591 == 'g';
if (x1593) {
x1595 = 0/*false*/;
x1596 = x1591;
char *x1594 = x1590+1;
x1597 = x1594;
} else {
x1597 = x1590;
}
}
int x1609 = x1595;
if (x1609) {
char *x1610 = x1597;
x1326 = 0;
} else {
char x1613 = x1596;
char *x1614 = x1597;
int x1619 = 1/*true*/;
char x1620 = '\0';
char *x1621 = 0/*null*/;
char x1615 = x1614[0];
int x1616 = x1615 == '\0';
if (x1616) {
x1621 = x1614;
} else {
int x1617 = x1615 == 't';
if (x1617) {
x1619 = 0/*false*/;
x1620 = x1615;
char *x1618 = x1614+1;
x1621 = x1618;
} else {
x1621 = x1614;
}
}
int x1633 = x1619;
if (x1633) {
char *x1634 = x1621;
x1326 = 0;
} else {
char x1637 = x1620;
char *x1638 = x1621;
int x1643 = 1/*true*/;
char x1644 = '\0';
char *x1645 = 0/*null*/;
char x1639 = x1638[0];
int x1640 = x1639 == '\0';
if (x1640) {
x1645 = x1638;
} else {
int x1641 = x1639 == 'h';
if (x1641) {
x1643 = 0/*false*/;
x1644 = x1639;
char *x1642 = x1638+1;
x1645 = x1642;
} else {
x1645 = x1638;
}
}
int x1657 = x1643;
if (x1657) {
char *x1658 = x1645;
x1326 = 0;
} else {
char x1661 = x1644;
char *x1662 = x1645;
x1326 = x1662;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
char *x1692 = x1326;
return x1692;
}
| 14 |
/*@ predicate allequ{L}(integer i, int *x, integer res) =
@ \forall integer j; (i <= j <= res+i-1) ==> (\at(x[i], L)==\at(x[j], L));
@*/
//Examines equality between between all elemnts in [i,i+res-1]
/*@ predicate ismax{L}(integer i, int *x, integer res,integer N) =
@ \forall integer j; (0 < j <= N-1 && j!=i) ==> (\forall integer rp; (1 < rp < N && allequ(j,x,rp)) ==> (rp <= res));
@*/
//Examines that res is the max res the you can get in length N
//For every r that satisfies allequ this r must be smaller-equal from res
/*@ predicate cond{L}(integer N, int *x, integer res) =
@ \exists integer i; (0 <= i < N-res) ==> (allequ(i,x,res) && ismax(i,x,res,N));
@*/
//For something to satisfy the given condition there must exist an integer such that for i to
// i+res-1 positions we will have equality and this will be the max length
/*@ requires N > 0;
@ requires \valid(x + (0..N-1));
@ ensures cond(N, x,\result);
@*/
int countSameConsecutive(int N, int x[]) {
int best = 0, i = 0;
// we try to maintain an essence of current best in order to reach total (best)
// for that we replace N <- i+1 (to look until i array positions)
/*@ loop invariant 0 <= i <= N;
@ loop invariant 0 <= best <= N;
@ loop invariant 0 < i <==> 0 < best;
@ loop invariant (0 < best <==> allequ(i,x,best)) || (best == 0 <==> i==0) ;
@ loop invariant (0 < best <==> ismax(i,x,best,i+1)) || (best == 0 <==> i==0);
@ loop invariant ((0 < i < N && 0 < best) <==> cond(i+1,x,best)) || (best == 0 <==> i==0);
@ loop assigns i, best;
@ loop variant N-i;
@*/
while (i < N) {
int j = i+1;
// while we are inside the second loop everything allequ for j-i
// (starting from i) matrix positions is maintained
/*@ loop invariant i+1 <= j <= N;
@ loop invariant (x[j] == x[i]) ==> allequ(i,x,j-i);
@ loop assigns j;
@ loop variant N-j;
@*/
while (j < N && x[j] == x[i]) ++j;
if (j-i > best) best = j-i;
i = j;
}
return best;
}
| 34 |
#include <string.h>
/*@
logic integer d(integer c) = (0 <= c - '0' <= 9) ? c - '0' : -1;
logic integer e(integer i) = (0 <= i <= 9) ? i + '0' : ' ';
*/
/*@
assigns \nothing;
ensures -1<=\result<=9;
ensures d(c)==\result;
*/
int d(char c) {
return ('0' <= c && c <= '9') ? c - '0' : -1;
}
/*@
assigns \nothing;
ensures '0'<=\result<='9' || \result==' ';
ensures e(i)==\result;
*/
char e(int i) {
return (0 <= i && i <= 9) ? i + '0' : ' ';
}
/*@
assigns \nothing;
ensures '0'<=c<='9' ==> \result==c;
ensures c!=\result ==> \result==' ';
ensures e(d(c))==\result;
*/
char ed(char c) {
return e(d(c));
}
/*@
assigns \nothing;
ensures 0<=i<=9 ==> \result==i;
ensures i!=\result ==> \result==-1;
ensures d(e(i))==\result;
*/
int de(int i) {
return d(e(i));
}
/*@
assigns \nothing;
ensures d(e(d(c)))==d(c);
*/
int ded(char c) {
return d(e(d(c)));
}
/*@
assigns \nothing;
ensures e(d(e(i)))==e(i);
*/
char ede(int i) {
return e(d(e(i)));
}
| 57 |
/*@
// Invariant and equality spec for Vector[Char]
predicate spec_Inv_VC(char *a1, int n) =
n==0 || (n>0 && \valid(a1+(0..n-1)));
predicate spec_Eq_VC(char *a1, char *a2, int n1, int n2) =
(n1==n2) &&
(\forall int j; (0<=j<n1) ==> a1[j] == a2[j]);
// Invariant and equality spec for Vector[Vector[Char]]
predicate spec_Inv_VVC(char **a1, int *an1, int n) =
n==0 || (n>0 && \valid(a1+(0..n-1)) && \valid(an1+(0..n-1))) &&
(\forall int j; (0<=j<n) ==> spec_Inv_VC(a1[j],an1[j]));
predicate spec_Eq_VVC(char **a1, char **a2, int *an1, int *an2, int n1, int n2) =
(n1==n2) &&
(\forall int j; (0<=j<n1) ==> spec_Eq_VC(a1[j],a2[j],an1[j],an2[j]));
*/
// Contract and implementation for Vector[Char] equality
/*@ requires spec_Inv_VC(a1,n1) && spec_Inv_VC(a2,n2);
ensures (\result == 1) || (\result == 0);
ensures (\result == 1) <==> spec_Eq_VC(a1,a2,n1,n2);
ensures (\result == 0) <==> !spec_Eq_VC(a1,a2,n1,n2);
assigns \nothing; */
int eq_VC(char *a1, char *a2, int n1, int n2) {
if (n1 != n2) return 0;
/*@ loop invariant (0 <= i <= n1);
loop invariant \forall int j; (0 <= j < i) ==> a1[j]==a2[j];
loop assigns i;
loop variant (n1-i); */
for (int i = 0; i < n1; i++) {
if (a1[i] != a2[i]) return 0;
}
return 1;
}
// Contract and implementation for Vector[Vector[Char]] equality
/*@ requires spec_Inv_VVC(a1,an1,n1) && spec_Inv_VVC(a2,an2,n2);
ensures (\result == 1) || (\result == 0);
ensures (\result == 1) <==> spec_Eq_VVC(a1,a2,an1,an2,n1,n2);
ensures (\result == 0) <==> !spec_Eq_VVC(a1,a2,an1,an2,n1,n2);
assigns \nothing; */
int eq_VVC(char **a1, char **a2, int *an1, int *an2, int n1, int n2) {
if (n1 != n2) return 0;
/*@ loop invariant (0 <= i <= n1);
loop invariant \forall int j; (0 <= j < i) ==> spec_Eq_VC(a1[j],a2[j],an1[j],an2[j]);
loop assigns i;
loop variant (n1-i); */
for (int i = 0; i < n1; i++) {
if (eq_VC(a1[i],a2[i],an1[i],an2[i]) != 1) return 0;
}
return 1;
}
| 46 |
#include <limits.h>
/*@ predicate inv_vec_Int(int * x0, int x1) = ((x1==0) || ((x1>0) &&
\valid(x0+(0..x1-1))));*/
/*@ predicate eq_vec_Int(int * x16, int x17, int * x18, int x19) = ((x17==x19) &&
(\forall int x23; (0<=x23<x17) ==> (x16[x23]==x18[x23])));*/
/*@
requires (inv_vec_Int(x16,x17) &&
inv_vec_Int(x18,x19));
assigns \nothing;
ensures (inv_vec_Int(x16,x17) &&
inv_vec_Int(x18,x19));
ensures \result <==> eq_vec_Int(x16, x17, x18, x19);
*/
int eq_vec_Int(int * x16, int x17, int * x18, int x19) {
int x21 = x17 == x19;
int x33;
if (x21) {
int x32 = 1;
/*@ loop invariant (0 <= x24 <= x17);
loop invariant \forall int x23; (0 <= x23 < x24) ==> (x16[x23]==x18[x23]);
loop assigns x24;
loop variant (x17-x24); */
for (int x24 = 0; x24 < x17; x24++) {
int x29 = x16[x24];
int x30 = x18[x24];
int x31 = x29 == x30;
if (!x31) { x32 = 0; break; }
}
x33 = x32;
} else {
x33 = 0/*false*/;
}
return x33;
}
/*@ predicate inv_vec_vec_Int(int * * x37, int * x38, int x39) = (((x39==0) || ((x39>0) &&
(\valid(x37+(0..x39-1)) &&
\valid(x38+(0..x39-1))))) &&
(\forall int x49; (0<=x49<x39) ==> inv_vec_Int(x37[x49],x38[x49])));*/
/*@ predicate eq_vec_vec_Int(int * * x61, int * x62, int x63, int * * x64, int * x65, int x66) = ((x63==x66) &&
(\forall int x70; (0<=x70<x63) ==> eq_vec_Int(x61[x70],x62[x70],x64[x70],x65[x70])));*/
/*@
requires (inv_vec_vec_Int(x61,x62,x63) &&
inv_vec_vec_Int(x64,x65,x66));
assigns \nothing;
ensures (inv_vec_vec_Int(x61,x62,x63) &&
inv_vec_vec_Int(x64,x65,x66));
ensures \result <==> eq_vec_vec_Int(x61, x62, x63, x64, x65, x66);
*/
int eq_vec_vec_Int(int * * x61, int * x62, int x63, int * * x64, int * x65, int x66) {
int x68 = x63 == x66;
int x84;
if (x68) {
int x83 = 1;
/*@ loop invariant (0 <= x71 <= x63);
loop invariant \forall int x70; (0 <= x70 < x71) ==> eq_vec_Int(x61[x70],x62[x70],x64[x70],x65[x70]);
loop assigns x71;
loop variant (x63-x71); */
for (int x71 = 0; x71 < x63; x71++) {
int *x78 = x61[x71];
int x79 = x62[x71];
int *x80 = x64[x71];
int x81 = x65[x71];
int x82 = eq_vec_Int(x78,x79,x80,x81);
if (!x82) { x83 = 0; break; }
}
x84 = x83;
} else {
x84 = 0/*false*/;
}
return x84;
}
| 44 |
#include<limits.h>
#include<string.h>
/*@
predicate star_A(char* s, integer i, integer j) =
i==j || (j>i && (s[i]=='A' && star_A(s, i+1, j)));
predicate match_aapb(char* s, integer i, integer j) =
s[i]=='A' && \exists integer m; i<m<j && star_A(s,i+1,m) && s[m]=='B' && s[m+1]=='\0' && m+1==j;
predicate bwd0(char* s, integer i, integer j) = i>=j;
predicate bwd1(char* s, integer i, integer j) = s[i]=='A' && \exists integer m; i<m<=j && star_A(s,i+1,m) && m>=j;
predicate bwd2(char* s, integer i, integer j) =
s[i]=='A' && \exists integer m; i<m<j && star_A(s,i+1,m) && s[m]=='B' && m+1>=j;
*/
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=j<=strlen(s);
requires star_A(s, i, j);
ensures \forall integer m; 0<=i<=m<j ==> s[m]=='A';
assigns \nothing;
*/
void lemma_star_A_all(char* s, int i, int j) {
int x = i;
/*@
loop invariant 0 <= i <= x <= j <= strlen(s);
loop invariant star_A(s, x, j);
loop invariant \forall integer m; i<=m<x ==> s[m]=='A';
loop assigns x;
loop variant j-x;
*/
while (x < j) {
x++;
}
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=j<=strlen(s);
requires \forall integer m; 0<=i<=m<j ==> s[m]=='A';
ensures star_A(s, i, j);
assigns \nothing;
*/
void lemma_all_star_A(char* s, int i, int j) {
int x = j;
/*@
loop invariant 0 <= i <= x <= j <= strlen(s);
loop invariant star_A(s, x, j);
loop invariant \forall integer m; 0<=i<=m<j ==> s[m]=='A';
loop assigns x;
loop variant x;
*/
while (i < x) {
x--;
}
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=m<j<=strlen(s);
requires s[m]!='A';
ensures !star_A(s, i, j);
assigns \nothing;
*/
void lemma_star_A_not(char* s, int i, int m, int j) {
int x = m;
/*@
loop invariant 0<=i<=x<=m<j;
loop invariant !star_A(s, x, j);
loop assigns x;
loop variant x;
*/
while (i < x) {
x--;
}
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=strlen(s);
requires 0<=j<=strlen(s);
requires i<j;
requires star_A(s, i, j);
ensures star_A(s, i, j-1);
assigns \nothing;
*/
void lemma_star_A_dec(char* s, int i, int j) {
//@ghost lemma_star_A_all(s, i, j);
//@ghost lemma_all_star_A(s, i, j-1);
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=j<=n<=strlen(s);
requires star_A(s, i, j);
requires star_A(s, j, n);
ensures star_A(s, i, n);
assigns \nothing;
*/
void lemma_star_A(char* s, int i, int j, int n) {
int x = j;
/*@
loop invariant 0 <= i <= x <= j <= n <= strlen(s);
loop invariant star_A(s, x, n);
loop invariant star_A(s, i, x);
loop assigns x;
loop variant x;
*/
while (i < x) {
//@ghost lemma_star_A_dec(s, i, x);
//@assert i<x;
//@ghost lemma_star_A_all(s, i, x);
//@assert s[x-1]=='A';
//@assert star_A(s, x, n);
//@assert star_A(s, x-1, n);
x--;
}
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=strlen(s);
requires 0<=j<=strlen(s);
requires i<=j;
requires bwd0(s, 0, j);
requires s[j]=='A';
ensures bwd1(s, 0, j+1);
assigns \nothing;
*/
void lemma01(char* s, int i, int j) {
//@assert j==0;
//@assert star_A(s, j+1, j+1);
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=strlen(s);
requires 0<=j<=strlen(s);
requires i<=j;
requires bwd1(s, 0, j);
requires s[j]=='A';
ensures bwd1(s, 0, j+1);
assigns \nothing;
*/
void lemma11(char* s, int i, int j) {
//@assert s[0]=='A';
//@assert star_A(s, 1, j);
//@assert s[j]=='A';
//@assert star_A(s, j+1, j+1);
//@ghost lemma_star_A(s, 1, j, j+1);
//@assert star_A(s, 1, j+1);
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=strlen(s);
requires 0<=j<=strlen(s);
requires bwd1(s, i, j);
requires s[j]=='B';
ensures bwd2(s, i, j+1);
assigns \nothing;
*/
void lemma12(char* s, int i, int j) {
//@assert bwd1(s, i, j);
//@assert s[i]=='A';
//@assert star_A(s, i+1, j);
//@assert s[j]=='B';
//@assert bwd2(s, i, j+1);
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
requires 0<=i<=strlen(s);
requires 0<=j<=strlen(s);
requires bwd2(s, i, j);
ensures s[j]=='\0' ==> match_aapb(s, i, j);
assigns \nothing;
*/
void lemma2f(char* s, int i, int j) {
//@assert bwd2(s, i, j);
//@assert s[i]=='A';
//@assert star_A(s, i+1, j-1);
//@assert s[j-1]=='B';
//@assert s[j]=='\0' ==> match_aapb(s, i, j);
}
/*@
requires strlen(s)>=0 && \valid(s+(0..strlen(s)));
requires strlen(s)<=INT_MAX;
ensures match_aapb(s, 0, strlen(s)) ==> \result==1;
ensures \result==1 ==> match_aapb(s, 0, strlen(s));
assigns \nothing;
*/
int m_aapb(char* s) {
char* cur = s;
int id = 0;
int m = 1;
//@ghost int i = 0;
/*@
loop invariant strlen(s)>=0 && \valid(s+(0..strlen(s)));
loop invariant strlen(cur)>=0 && \valid(cur+(0..strlen(cur)));
loop invariant 0<=i<=strlen(s);
loop invariant (id == 0) && m ==> bwd0(s, 0, i);
loop invariant (id == 1) && m ==> bwd1(s, 0, i);
loop invariant (id == 2) && m ==> bwd2(s, 0, i);
loop invariant (m == 0) ==> !bwd0(s, 0, i) && !bwd1(s, 0, i) && !bwd2(s, 0, i);
loop invariant (id == 0) && !m ==> s[0]!='A';
loop invariant (id == 1) && !m ==> s[i-1]!='A' && s[i-1]!='B';
loop invariant (id == 2) && !m ==> s[i-2]=='B';
loop invariant (id == 0) && !m ==> bwd0(s, 0, i-1);
loop invariant (id == 1) && !m ==> bwd1(s, 0, i-1);
loop invariant (id == 2) && !m ==> bwd2(s, 0, i-1);
loop invariant (id == 2) && cur[0]=='\0' && m ==> match_aapb(s, 0, i);
loop invariant (id != 2) || cur[0]!='\0' || !m ==> !match_aapb(s, 0, i);
loop invariant (id == 0) || (id == 1) || (id == 2);
loop invariant cur==s+i;
loop invariant cur[0]==s[i];
loop assigns cur, id, i, m;
loop variant strlen(cur);
*/
while (cur[0]!='\0' && m) {
m = 0;
if (id == 0) {
//@assert (id == 0) ==> bwd0(s, 0, i);
//@assert bwd0(s, 0, i);
//@assert i==0;
if (cur[0] == 'A') {
id = 1;
//@ghost lemma01(s, 0, i);
//@assert bwd1(s, 0, i+1);
m = 1;
} else {
//@assert !bwd0(s, 0, i+1) && !bwd1(s, 0, i+1) && !bwd2(s, 0, i+1);
}
} else if (id == 1) {
//@assert (id == 1) ==> bwd1(s, 0, i);
//@assert bwd1(s, 0, i);
if (cur[0] == 'A') {
//@ghost lemma11(s, 0, i);
id = 1;
//@assert bwd1(s, 0, i+1);
m = 1;
} else if (cur[0] == 'B') {
//@ghost lemma12(s, 0, i);
id = 2;
//@assert bwd2(s, 0, i+1);
//@ghost lemma2f(s, 0, i+1);
m = 1;
} else {
//@assert !bwd0(s, 0, i+1);
//@assert s[i]!='A';
//@ghost lemma_star_A_not(s, 1, i, i+1);
//@assert !bwd1(s, 0, i+1);
//@assert !bwd2(s, 0, i+1);
}
} else if (id == 2) {
//@assert (id == 2) ==> bwd2(s, 0, i);
//@assert bwd2(s, 0, i);
//@assert !bwd0(s, 0, i+1);
//@assert s[i-1]!='A';
//@ghost lemma_star_A_not(s, 1, i-1, i+1);
//@assert !star_A(s, 1, i+1);
//@assert !bwd1(s, 0, i+1);
//@ghost lemma_star_A_not(s, 1, i-1, i);
//@assert !star_A(s, 1, i);
//@assert !bwd2(s, 0, i+1);
} else {
//@assert \false;
}
cur++;
//@ghost i++;
}
int res = id==2 && cur[0]=='\0' && m;
/*@ghost
if (!res) {
if (!m) {
//@assert i>=1;
//@assert !match_aapb(s, 0, i);
//@assert !bwd2(s, 0, i);
int x = i;
int j = strlen(s);
if (id==0) {
//@assert s[0]!='A';
//@assert !bwd2(s, 0, j);
} else if (id==1) {
//@assert s[i-1]!='A' && s[i-1]!='B';
//@assert s[i-1]!='A';
if (i-1<j-1) {
//@ghost lemma_star_A_not(s, 1, i-1, j-1);
} else {
//@assert i==j;
}
//@assert !bwd2(s, 0, j);
} else if (id==2) {
//@assert s[i-2]=='B';
//@assert s[i-2]!='A';
//@ghost lemma_star_A_not(s, 1, i-2, j-1);
//@assert !bwd2(s, 0, j);
}
//@assert !bwd2(s, 0, strlen(s));
//@assert !match_aapb(s, 0, strlen(s));
}
}
*/
return res;
}
| 283 |
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 3