{"filefolder_name": "reverse_copy", "file_name": "reverse_copy", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Reverse\n {\n predicate\n Reverse{K,L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],K) == \\at(b[n-1-i], L);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Reverse{K,L}(a+m, n-m, b+p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, value_type* b) =\n Reverse{K,L}(a, m, n, b, m);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, integer p) =\n Reverse{K,L}(a, m, n, a, p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n) =\n Reverse{K,L}(a, m, n, m);\n predicate\n Reverse{K,L}(value_type* a, integer n) = Reverse{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\nvoid\nreverse_copy(const value_type* a, size_type n, value_type* b)\n{\n for (size_type i = 0u; i < n; ++i) {\n b[i] = a[n - 1u - i];\n }\n //@ assert Reverse{Pre,Here}(a, n, b);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Reverse\n {\n predicate\n Reverse{K,L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],K) == \\at(b[n-1-i], L);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Reverse{K,L}(a+m, n-m, b+p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, value_type* b) =\n Reverse{K,L}(a, m, n, b, m);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, integer p) =\n Reverse{K,L}(a, m, n, a, p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n) =\n Reverse{K,L}(a, m, n, m);\n predicate\n Reverse{K,L}(value_type* a, integer n) = Reverse{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a + (0..n-1), b + (0..n-1));\n assigns b[0..(n-1)];\n ensures reverse: Reverse{Old,Here}(a, n, b);\n ensures unchanged: Unchanged{Old,Here}(a, n);\n*/\nvoid\nreverse_copy(const value_type* a, size_type n, value_type* b)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant reverse: Reverse{Here,Pre}(b, 0, i, a, n-i);\n loop assigns i, b[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n b[i] = a[n - 1u - i];\n }\n //@ assert Reverse{Pre,Here}(a, n, b);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "ranilakshmi_is_sorted", "file_name": "is_sorted", "input": "int is_sorted(int a[],int n){\n for (int i=1;ia[i]){\n //@ assert \\exists integer j; 1<=j<=i && a[j]< a[j-1];\n return 0;\n }\n }\n //@ assert \\forall integer j; 1<=j a[j]>=a[j-1];\n return 1;\n}", "output": "/*@\n requires n>0;\n requires \\valid_read(a + (0..n-1));\n behavior sorted:\n assumes \\forall integer i;\n 1<=i a[i]>=a[i-1];\n ensures \\result ==1;\n behavior unsorted:\n assumes \\exists integer i;\n 1<=i a[j]>=a[j-1];\n loop invariant 1<= i <= n;\n loop assigns i;\n loop variant n-i;\n */\n for (int i=1;ia[i]){\n //@ assert \\exists integer j; 1<=j<=i && a[j]< a[j-1];\n return 0;\n }\n }\n //@ assert \\forall integer j; 1<=j a[j]>=a[j-1];\n return 1;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "immutable_array_check_evens_in_array", "file_name": "check_evens_in_array", "input": "int areElementsEven(int *a, int n) {\n int p = 0;\n while (p < n) {\n if (a[p] % 2 != 0) {\n return 0;\n }\n p = p + 1;\n }\n return 1;\n}\nvoid main() {\n int arr[] = {2,4,6,8,10};\n int res = areElementsEven(arr, 5);\n //@ assert res == 1;\n}", "output": "/*@\n requires n > 0;\n requires \\valid_read(a+(0..(n-1)));\n assigns \\nothing;\n behavior all_even:\n assumes \\forall integer k; 0 <= k < n ==> a[k]%2 == 0;\n ensures \\result == 1;\n behavior some_not_even:\n assumes \\exists integer k; 0 <= k < n && a[k]%2 != 0;\n ensures \\result == 0;\n disjoint behaviors;\n complete behaviors;\n*/\nint areElementsEven(int *a, int n) {\n int p = 0;\n /*@\n loop invariant 0 <= p <= n;\n loop invariant \\forall integer k; 0 <= k < p ==> a[k]%2 == 0;\n loop assigns p; \n */\n while (p < n) {\n if (a[p] % 2 != 0) {\n return 0;\n }\n p = p + 1;\n }\n return 1;\n}\nvoid main() {\n int arr[] = {2,4,6,8,10};\n int res = areElementsEven(arr, 5);\n //@ assert res == 1;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_acsl-examples_10_rec", "file_name": "10_rec", "input": "//@ logic integer sum_upto(integer n) = n*(n+1) / 2;\n/*@\n lemma sum_rec: \\forall integer n; n >=0 ==>\n sum_upto(n+1) == sum_upto(n)+n+1;\n*/\nlong sum(int x) {\n if (x == 0) return 0;\n else return x + sum (x-1);\n}\n\nint main () {\n long i = sum(8);\n //@ assert i == 36;\n}", "output": "//@ logic integer sum_upto(integer n) = n*(n+1) / 2;\n/*@\n lemma sum_rec: \\forall integer n; n >=0 ==>\n sum_upto(n+1) == sum_upto(n)+n+1;\n*/\n/*@ \n requires x >= 0;\n requires x <= 1000;\n decreases x;\n ensures \\result == sum_upto(x);\n*/\nlong sum(int x) {\n if (x == 0) return 0;\n else return x + sum (x-1);\n}\n\nint main () {\n long i = sum(8);\n //@ assert i == 36;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "more_arrays_equal_arrays", "file_name": "equal_arrays", "input": "int check(int *a, int *b, int n) {\n for (int i = 0; i < n; i++) {\n if (a[i] != b[i]) {\n return 0;\n }\n }\n return 1;\n}\nint main() {\n int a[] = {1,2,3,4,5};\n int b[] = {1,2,3,4,5};\n int res = check(a, b, 5);\n //@ assert res == 1;\n}", "output": "/*@ \n requires n > 0;\n requires \\valid_read (a + (0..n-1));\n requires \\valid_read (b + (0..n-1));\n assigns \\nothing;\n behavior equal:\n assumes \\forall integer k; 0 <= k < n ==> b[k] == a[k];\n ensures \\result == 1;\n behavior not_equal:\n assumes \\exists integer k; 0 <= k < n && b[k] != a[k];\n ensures \\result == 0;\n*/\nint check(int *a, int *b, int n) {\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; 0 <= k < i ==> a[k] == b[k];\n loop assigns i;\n */\n for (int i = 0; i < n; i++) {\n if (a[i] != b[i]) {\n return 0;\n }\n }\n return 1;\n}\nint main() {\n int a[] = {1,2,3,4,5};\n int b[] = {1,2,3,4,5};\n int res = check(a, b, 5);\n //@ assert res == 1;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_14", "file_name": "BL.EN.U4CSE21176_14", "input": "#include\nint check(int val){\nif(val>0)\nreturn val;\nelse if(val<0)\nreturn -val;\nelse\nreturn 0;\n}\nint main(){\nint x=4;\nint r=check(x);\n//@assert x==4;\n}", "output": "#include\n/*@\nrequires val>INT_MIN;\nassigns \\nothing;\nbehavior pos:\nassumes val>0;\nensures \\result==val;\nbehavior neg:\nassumes val<0;\nensures \\result==-val;\nbehavior eq:\nassumes val==0;\nensures \\result==0;\ncomplete behaviors;\ndisjoint behaviors;\n*/\nint check(int val){\nif(val>0)\nreturn val;\nelse if(val<0)\nreturn -val;\nelse\nreturn 0;\n}\nint main(){\nint x=4;\nint r=check(x);\n//@assert x==4;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_82", "file_name": "82", "input": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i >= x) {\n if (0 > i) {\n //@ assert i >= y;\n }\n }\n}", "output": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n /*@\n loop invariant i <= y;\n loop invariant i <= x;\n loop invariant 0 <= i;\n loop assigns i;\n */\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i >= x) {\n if (0 > i) {\n //@ assert i >= y;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_minus-4", "file_name": "minus-4", "input": "void minus_loop_2() {\n int x = -20 ;\n int rm = 5; \n while (x < 0){\n x += 4 ;\n rm -- ; \n }\n //@ assert x == 0 && rm == 0;\n}", "output": "void minus_loop_2() {\n int x = -20 ;\n int rm = 5; \n /*@\n loop invariant -20 <= x <= 0;\n loop invariant (-rm) * 4 == x; \n loop variant rm ; \n */\n while (x < 0){\n x += 4 ;\n rm -- ; \n }\n //@ assert x == 0 && rm == 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "MarcoGrillo_Minimum-Period-of-a-String_period", "file_name": "period", "input": "/*@\n predicate is_periodic(char* x, unsigned int p, unsigned int l) =\n (\\forall unsigned int i; 0 <= i < (l-p-1) ==> x[i] == x[i+p]) && (l%p == 0) || (p == l);\n*/\n/*@ \n requires \\valid(x+(0..l-1));\n requires l > 0;\n requires p > 0;\n assigns \\nothing;\n ensures is_periodic(x,p,l) ==> \\result == 1;\n ensures !is_periodic(x,p,l) ==> \\result == 0;\n*/\nunsigned has_period(const char x[], unsigned int p, unsigned l) {\n if (p == l) return 1;\n if ((l % p) != 0) return 0;\n /*@\n loop assigns i;\n loop invariant \\forall unsigned int j; 0 <= j < i ==> (x[j] == x[j+p]);\n loop invariant i <= l-p-1;\n loop invariant i >= 0;\n */\n for (unsigned i = 0 ; i < l-p-1 ; ++i) {\n if (x[i] != x[i + p])\n return 0;\n } \n return 1; \n}\nunsigned per(const char x[], unsigned l) {\n unsigned int p;\n for(p = 1; p < l; ++p) {\n if(has_period(x,p,l))\n return p;\n }\n //@ assert is_periodic(x,p,l);\n return p;\n}", "output": "/*@\n predicate is_periodic(char* x, unsigned int p, unsigned int l) =\n (\\forall unsigned int i; 0 <= i < (l-p-1) ==> x[i] == x[i+p]) && (l%p == 0) || (p == l);\n*/\n/*@ \n requires \\valid(x+(0..l-1));\n requires l > 0;\n requires p > 0;\n assigns \\nothing;\n ensures is_periodic(x,p,l) ==> \\result == 1;\n ensures !is_periodic(x,p,l) ==> \\result == 0;\n*/\nunsigned has_period(const char x[], unsigned int p, unsigned l) {\n if (p == l) return 1;\n if ((l % p) != 0) return 0;\n /*@\n loop assigns i;\n loop invariant \\forall unsigned int j; 0 <= j < i ==> (x[j] == x[j+p]);\n loop invariant i <= l-p-1;\n loop invariant i >= 0;\n */\n for (unsigned i = 0 ; i < l-p-1 ; ++i) {\n if (x[i] != x[i + p])\n return 0;\n } \n return 1; \n}\n/*@\n requires \\valid(x+(0..l-1));\n requires l > 0;\n ensures 1 <= \\result <= l;\n ensures is_periodic(x,\\result,l); \n ensures \\forall unsigned int p; 0 < p < \\result ==> !is_periodic(x,p,l); \n*/\nunsigned per(const char x[], unsigned l) {\n unsigned int p;\n /*@\n loop assigns p;\n loop invariant p >= 1;\n loop invariant p <= l;\n loop invariant \\forall unsigned int i; 0 < i < p ==> !is_periodic(x,i,l);\n loop variant l-p;\n */\n for(p = 1; p < l; ++p) {\n if(has_period(x,p,l))\n return p;\n }\n //@ assert is_periodic(x,p,l);\n return p;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_48", "file_name": "48", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if(unknown()) {\n if(c != n) {\n (c = (c + 1));\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c == n) {\n //@ assert n > -1;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant c == n ==> \\forall integer k; 0 <= k < c ==> k != n;\n loop invariant c != n || c <= n;\n loop invariant 0 <= c;\n loop invariant (c == n) ==> (n > -1);\n loop assigns n,c;\n */\n while (unknown()) {\n if(unknown()) {\n if(c != n) {\n (c = (c + 1));\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c == n) {\n //@ assert n > -1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_109", "file_name": "109", "input": "/*@\nrequires c>0;\n*/\nvoid foo(int a, int m, int c) {\n int j = 0;\n int k = 0;\n while ( k < c) {\n if(m < a) {\n m = a;\n }\n k = k + 1;\n }\n if(c > 0) {\n //@ assert a <= m;\n }\n}", "output": "/*@\nrequires c>0;\n*/\nvoid foo(int a, int m, int c) {\n int j = 0;\n int k = 0;\n /*@\n loop invariant m >= a || k == 0;\n loop invariant k <= c;\n loop invariant \\forall integer l; 0 <= l < k ==> m >= a;\n loop invariant \\forall integer l; 0 <= l < k ==> a <= m;\n loop invariant 0 <= k;\n loop assigns m;\n loop assigns k;\n */\n while ( k < c) {\n if(m < a) {\n m = a;\n }\n k = k + 1;\n }\n if(c > 0) {\n //@ assert a <= m;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_7", "file_name": "7", "input": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (x == 20) {\n //@ assert y != 0;\n }\n}", "output": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n /*@\n loop invariant x == 20 ==> y != 0;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (x == 20) {\n //@ assert y != 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_124", "file_name": "124", "input": "void foo(int x, int y) {\n int i = x;\n int j = y;\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if(i == j) {\n //@ assert y == 0;\n }\n}", "output": "void foo(int x, int y) {\n int i = x;\n int j = y;\n /*@\n loop invariant y <= j;\n loop invariant x <= i;\n loop invariant i - x == j - y;\n loop assigns x,y,i,j;\n */\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if(i == j) {\n //@ assert y == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "suman1406_ArrayDoubling1", "file_name": "ArrayDoubling1", "input": "void arraydouble(int *a, int n)\n{\n for (int p = 0; p < n; p++)\n {\n a[p] = a[p] * 2;\n }\n}\nint main(){\n int a[] = {0, 1, 2, 3, 4};\n int n = sizeof(a) / sizeof(a[0]);\n //@ assert \\forall integer k; 0 <= k < n ==> a[k] == k;\n arraydouble(a, 5);\n //@ assert a[0] == 0 && a[1] == 2 && a[2] == 4 && a[3] == 6 && a[4] == 8;\n return 0;\n}", "output": "/*@\nrequires n > 0;\nrequires \\valid(a + (0..n-1));\nrequires \\forall integer k; 0 <= k < n ==> a[k] == k;\nensures \\forall integer k; 0 <= k < n ==> a[k] == 2*k;\n*/\nvoid arraydouble(int *a, int n)\n{\n /*@\n loop invariant 0 <= p <= n;\n loop invariant \\forall integer k; 0 <= k < p ==> a[k] == 2*k;\n loop invariant \\forall integer k; p <= k < n ==> a[k] == k;\n loop assigns p, a[0..n-1];\n loop variant n-p;\n */\n for (int p = 0; p < n; p++)\n {\n a[p] = a[p] * 2;\n }\n}\nint main(){\n int a[] = {0, 1, 2, 3, 4};\n int n = sizeof(a) / sizeof(a[0]);\n //@ assert \\forall integer k; 0 <= k < n ==> a[k] == k;\n arraydouble(a, 5);\n //@ assert a[0] == 0 && a[1] == 2 && a[2] == 4 && a[3] == 6 && a[4] == 8;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_acsl-examples_11_gcd", "file_name": "11_gcd", "input": "/*@ \n inductive is_gcd(integer a, integer b, integer d) {\n case gcd_zero:\n \\forall integer n; is_gcd(n,0,n);\n case gcd_succ:\n \\forall integer a,b,d; is_gcd(b, a % b, d) ==> is_gcd(a,b,d);\n }\n */\n/*@ \n axiomatic gcd {\n logic integer gcd(integer a, integer b);\n axiom nil:\n \\forall integer n; gcd(n,0) == n;\n axiom next:\n \\forall integer a,b; gcd(b, a % b) == gcd(a,b);\n }\n */\nunsigned gcd_rec(unsigned a, unsigned b)\n{\n if (b == 0)\n return a;\n return gcd_rec(b, a % b);\n}\nint main()\n{\n unsigned a = 48;\n unsigned b = 18;\n unsigned result = gcd_rec(a, b);\n //@ assert result == 6;\n return 0;\n}", "output": "/*@ \n inductive is_gcd(integer a, integer b, integer d) {\n case gcd_zero:\n \\forall integer n; is_gcd(n,0,n);\n case gcd_succ:\n \\forall integer a,b,d; is_gcd(b, a % b, d) ==> is_gcd(a,b,d);\n }\n */\n/*@ \n axiomatic gcd {\n logic integer gcd(integer a, integer b);\n axiom nil:\n \\forall integer n; gcd(n,0) == n;\n axiom next:\n \\forall integer a,b; gcd(b, a % b) == gcd(a,b);\n }\n */\n/*@\n decreases b;\n assigns \\nothing;\n ensures is_gcd(a, b, \\result);\n ensures \\result == gcd(a, b);\n */\nunsigned gcd_rec(unsigned a, unsigned b)\n{\n if (b == 0)\n return a;\n return gcd_rec(b, a % b);\n}\nint main()\n{\n unsigned a = 48;\n unsigned b = 18;\n unsigned result = gcd_rec(a, b);\n //@ assert result == 6;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_86", "file_name": "86", "input": "int main() {\n int x = -50;\n int y = 0;\n while (x < 0) {\n x = x + y;\n y = y + 1;\n }\n //@ assert y > 0;\n}", "output": "int main() {\n int x = -50;\n int y = 0;\n /*@\n loop invariant x < 0 || 0 < y;\n loop invariant 0 <= y;\n loop assigns y,x;\n */\n while (x < 0) {\n x = x + y;\n y = y + 1;\n }\n //@ assert y > 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "adjacent_find", "file_name": "adjacent_find", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic HasEqualNeighbors\n {\n predicate\n HasEqualNeighbors{L}(value_type* a, integer n) =\n \\exists integer i; 0 <= i < n-1 && a[i] == a[i+1];\n }\n*/\nsize_type\nadjacent_find(const value_type* a, size_type n)\n{\n if (1u < n) {\n for (size_type i = 0u; i + 1u < n; ++i) {\n if (a[i] == a[i + 1u]) {\n //@ assert HasEqualNeighbors(a, i+2);\n return i;\n }\n }\n }\n //@ assert !HasEqualNeighbors(a, n);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic HasEqualNeighbors\n {\n predicate\n HasEqualNeighbors{L}(value_type* a, integer n) =\n \\exists integer i; 0 <= i < n-1 && a[i] == a[i+1];\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior some:\n assumes HasEqualNeighbors(a, n);\n assigns \\nothing;\n ensures result: 0 <= \\result < n-1;\n ensures adjacent: a[\\result] == a[\\result+1];\n ensures first: !HasEqualNeighbors(a, \\result);\n behavior none:\n assumes !HasEqualNeighbors(a, n);\n assigns \\nothing;\n ensures result: \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nadjacent_find(const value_type* a, size_type n)\n{\n if (1u < n) {\n /*@\n loop invariant bound: 0 <= i < n;\n loop invariant none: !HasEqualNeighbors(a, i+1);\n loop assigns i;\n loop variant n-i;\n */\n for (size_type i = 0u; i + 1u < n; ++i) {\n if (a[i] == a[i + 1u]) {\n //@ assert HasEqualNeighbors(a, i+2);\n return i;\n }\n }\n }\n //@ assert !HasEqualNeighbors(a, n);\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "is_heap_until", "file_name": "is_heap_until", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic HeapNodes\n {\n logic integer HeapLeft(integer i) = 2*i + 1;\n logic integer HeapRight(integer i) = 2*i + 2;\n logic integer HeapParent(integer i) = (i-1) / 2;\n lemma HeapParent_Zero{L}: HeapParent(0) == 0;\n lemma Heap_ParentLeft:\n \\forall integer p; 0 <= p ==> HeapParent(HeapLeft(p)) == p;\n lemma Heap_ParentRight:\n \\forall integer p; 0 <= p ==> HeapParent(HeapRight(p)) == p;\n lemma Heap_ParentChild:\n \\forall integer c, p;\n 0 < c ==> HeapParent(c) == p ==>\n (c == HeapLeft(p) || c == HeapRight(p));\n lemma Heap_Childs:\n \\forall integer a, b;\n 0 < a ==> 0 < b ==>\n HeapParent(a) == HeapParent(b) ==>\n (a == b || a+1 == b || a == b+1);\n lemma Heap_ParentBounds:\n \\forall integer c; 0 < c ==> 0 <= HeapParent(c) < c;\n lemma Heap_ChildBounds:\n \\forall integer p; 0 <= p ==> p < HeapLeft(p) < HeapRight(p);\n }\n*/\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\n/*@\n axiomatic At\n {\n logic value_type At{L}(value_type* x, integer i) = \\at(x[i],L);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic ArrayUpdate\n {\n predicate\n ArrayUpdate{K,L}(value_type* a, integer n, integer i, value_type v) =\n 0 <= i < n &&\n Unchanged{K,L}(a, 0, i) &&\n Unchanged{K,L}(a, i+1, n) &&\n At{K}(a, i) != v &&\n At{L}(a, i) == v;\n lemma ArrayUpdate_Shrink{K,L}:\n \\forall value_type *a, v, integer n, i;\n 0 <= i < n-1 ==>\n ArrayUpdate{K,L}(a, n, i, v) ==>\n ArrayUpdate{K,L}(a, n-1, i, v);\n lemma ArrayUpdate_UpperBound{K,L}:\n \\forall value_type *a, v, w, integer n, i;\n ArrayUpdate{K,L}(a, n, i, v) ==>\n v <= w ==> \n UpperBound{K}(a, n, w) ==>\n UpperBound{L}(a, n, w);\n }\n*/\n/*@\n axiomatic Heap\n {\n predicate\n Heap{L}(value_type* a, integer n) =\n \\forall integer i; 0 < i < n ==> a[i] <= a[HeapParent(i)];\n lemma Heap_Shrink{L}:\n \\forall value_type *a, integer m, n;\n 0 <= m <= n ==> Heap(a, n) ==> Heap(a, m);\n lemma Heap_Unchanged{K,L}:\n \\forall value_type *a, integer n;\n 0 <= n ==> Unchanged{K,L}(a, n) ==> Heap{K}(a, n) ==> Heap{L}(a, n);\n predicate\n HeapCompatible{L}(value_type* a, integer n, integer m, value_type v) =\n (0 <= m < n) &&\n (0 <= HeapParent(m) ==> v <= a[HeapParent(m)]) &&\n (HeapLeft(m) < n ==> a[HeapLeft(m)] <= v) &&\n (HeapRight(m) < n ==> a[HeapRight(m)] <= v);\n lemma HeapCompatible_Update{K,L}:\n \\forall value_type *a, v, integer m, n;\n 0 <= m < n ==>\n Heap{K}(a, n) ==>\n HeapCompatible{K}(a, n, m, v) ==>\n ArrayUpdate{K,L}(a, n, m, v) ==>\n Heap{L}(a, n);\n }\n*/\nsize_type\nis_heap_until(const value_type* a, size_type n)\n{\n size_type parent = 0u;\n for (size_type child = 1u; child < n; ++child) {\n if (a[parent] < a[child]) {\n return child;\n }\n if ((child % 2u) == 0u) {\n ++parent;\n }\n }\n //@ assert Heap(a, n);\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic HeapNodes\n {\n logic integer HeapLeft(integer i) = 2*i + 1;\n logic integer HeapRight(integer i) = 2*i + 2;\n logic integer HeapParent(integer i) = (i-1) / 2;\n lemma HeapParent_Zero{L}: HeapParent(0) == 0;\n lemma Heap_ParentLeft:\n \\forall integer p; 0 <= p ==> HeapParent(HeapLeft(p)) == p;\n lemma Heap_ParentRight:\n \\forall integer p; 0 <= p ==> HeapParent(HeapRight(p)) == p;\n lemma Heap_ParentChild:\n \\forall integer c, p;\n 0 < c ==> HeapParent(c) == p ==>\n (c == HeapLeft(p) || c == HeapRight(p));\n lemma Heap_Childs:\n \\forall integer a, b;\n 0 < a ==> 0 < b ==>\n HeapParent(a) == HeapParent(b) ==>\n (a == b || a+1 == b || a == b+1);\n lemma Heap_ParentBounds:\n \\forall integer c; 0 < c ==> 0 <= HeapParent(c) < c;\n lemma Heap_ChildBounds:\n \\forall integer p; 0 <= p ==> p < HeapLeft(p) < HeapRight(p);\n }\n*/\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\n/*@\n axiomatic At\n {\n logic value_type At{L}(value_type* x, integer i) = \\at(x[i],L);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic ArrayUpdate\n {\n predicate\n ArrayUpdate{K,L}(value_type* a, integer n, integer i, value_type v) =\n 0 <= i < n &&\n Unchanged{K,L}(a, 0, i) &&\n Unchanged{K,L}(a, i+1, n) &&\n At{K}(a, i) != v &&\n At{L}(a, i) == v;\n lemma ArrayUpdate_Shrink{K,L}:\n \\forall value_type *a, v, integer n, i;\n 0 <= i < n-1 ==>\n ArrayUpdate{K,L}(a, n, i, v) ==>\n ArrayUpdate{K,L}(a, n-1, i, v);\n lemma ArrayUpdate_UpperBound{K,L}:\n \\forall value_type *a, v, w, integer n, i;\n ArrayUpdate{K,L}(a, n, i, v) ==>\n v <= w ==> \n UpperBound{K}(a, n, w) ==>\n UpperBound{L}(a, n, w);\n }\n*/\n/*@\n axiomatic Heap\n {\n predicate\n Heap{L}(value_type* a, integer n) =\n \\forall integer i; 0 < i < n ==> a[i] <= a[HeapParent(i)];\n lemma Heap_Shrink{L}:\n \\forall value_type *a, integer m, n;\n 0 <= m <= n ==> Heap(a, n) ==> Heap(a, m);\n lemma Heap_Unchanged{K,L}:\n \\forall value_type *a, integer n;\n 0 <= n ==> Unchanged{K,L}(a, n) ==> Heap{K}(a, n) ==> Heap{L}(a, n);\n predicate\n HeapCompatible{L}(value_type* a, integer n, integer m, value_type v) =\n (0 <= m < n) &&\n (0 <= HeapParent(m) ==> v <= a[HeapParent(m)]) &&\n (HeapLeft(m) < n ==> a[HeapLeft(m)] <= v) &&\n (HeapRight(m) < n ==> a[HeapRight(m)] <= v);\n lemma HeapCompatible_Update{K,L}:\n \\forall value_type *a, v, integer m, n;\n 0 <= m < n ==>\n Heap{K}(a, n) ==>\n HeapCompatible{K}(a, n, m, v) ==>\n ArrayUpdate{K,L}(a, n, m, v) ==>\n Heap{L}(a, n);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures bound: 0 <= \\result <= n;\n ensures heap: Heap(a, \\result);\n ensures last: \\forall integer i; \\result < i <= n ==> !Heap(a, i);\n*/\nsize_type\nis_heap_until(const value_type* a, size_type n)\n{\n size_type parent = 0u;\n /*@\n loop invariant bound: 0 <= parent < child <= n+1;\n loop invariant parent: parent == HeapParent(child);\n loop invariant heap: Heap(a, child);\n loop invariant not_heap: a[parent] < a[child] ==> \\forall integer i; child < i <= n ==> !Heap(a, i);\n loop assigns child, parent;\n loop variant n - child;\n */\n for (size_type child = 1u; child < n; ++child) {\n if (a[parent] < a[child]) {\n return child;\n }\n if ((child % 2u) == 0u) {\n ++parent;\n }\n }\n //@ assert Heap(a, n);\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_simple_interest", "file_name": "simple_interest", "input": "#include\nint simple(int p,int n,int r)\n{\n int si;\n si = p*n*r/100;\n return si;\n}\nint main()\n{\n int s = simple(10000, 3,10);\n //@ assert s == 3000;\n return 0;\n}", "output": "#include\n/*@ \n requires p>=5000;\n requires r> 0 && r <15;\n requires n > 0 && n < 5;\n ensures \\result == p*n*r/100;\n@*/\nint simple(int p,int n,int r)\n{\n int si;\n si = p*n*r/100;\n return si;\n}\nint main()\n{\n int s = simple(10000, 3,10);\n //@ assert s == 3000;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_7", "file_name": "7", "input": "void reset_1st_if_2nd_is_true(int* a, int const* b){\n if(*b)\n *a = 0;\n}\nint main(){\n int a = 10;\n int b = 1; // true\n reset_1st_if_2nd_is_true(&a, &b);\n //@ assert a == 0;\n}", "output": "/*@ requires \\valid(a) && \\valid_read(b);\n requires \\separated(a, b);\n assigns *a;\n ensures \\old(*b) ==> *a == 0;\n ensures !\\old(*b) ==> *a == \\old(*a);\n ensures *b == \\old(*b);\n*/\nvoid reset_1st_if_2nd_is_true(int* a, int const* b){\n if(*b)\n *a = 0;\n}\nint main(){\n int a = 10;\n int b = 1; // true\n reset_1st_if_2nd_is_true(&a, &b);\n //@ assert a == 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_73", "file_name": "73", "input": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n while (unknown()) {\n if (c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (z < 0) {\n if(z >= 4608) {\n //@ assert (c >= 36) ;\n }\n }\n}", "output": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n /*@\n loop invariant z == 36*y + c;\n loop invariant z == 36 * y + c;\n loop invariant c <= 36;\n loop invariant \\forall integer i; 0 <= i < c ==> z >= 36*y + i;\n loop invariant 36 * y <= z;\n loop invariant 0 <= z;\n loop invariant 0 <= c;\n loop assigns z;\n loop assigns c;\n */\n while (unknown()) {\n if (c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (z < 0) {\n if(z >= 4608) {\n //@ assert (c >= 36) ;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_53", "file_name": "53", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n - c;\n loop invariant c == n ==> c == 1;\n loop invariant 0 <= c <= n;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_ani", "file_name": "ani", "input": "#include \nint fun(int n) {\n int i = 7;\n int x = 1;\n while(i <= n) {\n x += 1;\n i += 3;\n }\n return x;\n}\nint main() {\n int a = fun(10);\n //@ assert a == 3;\n}", "output": "#include \n/*@\n requires n > 7;\n ensures \\result == (n-1)/3;\n assigns \\nothing;\n*/\nint fun(int n) {\n int i = 7;\n int x = 1;\n /*@\n loop invariant i == 4 + 3*x;\n\tloop invariant i <= n + 3;\n\tloop assigns x, i;\n */\n while(i <= n) {\n x += 1;\n i += 3;\n }\n return x;\n}\nint main() {\n int a = fun(10);\n //@ assert a == 3;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "miscellaneous_array_swap", "file_name": "array_swap", "input": "void array_swap(int* arr, int n, int n1, int n2) {\n int temp = arr[n1];\n arr[n1] = arr[n2];\n arr[n2] = temp;\n}\nint main(){\n int arr[] = {1, 2, 3, 4, 5};\n array_swap(arr, 5, 1, 3);\n //@ assert arr[1] == 4;\n //@ assert arr[3] == 2;\n}", "output": "/*@\n requires n >= 0;\n requires 0 <= n1 < n && 0 <= n2 < n;\n requires \\valid(arr+(0..n-1));\n ensures (arr[n2] == \\old(arr[n1])) && (arr[n1] == \\old(arr[n2]));\n*/\nvoid array_swap(int* arr, int n, int n1, int n2) {\n int temp = arr[n1];\n arr[n1] = arr[n2];\n arr[n2] = temp;\n}\nint main(){\n int arr[] = {1, 2, 3, 4, 5};\n array_swap(arr, 5, 1, 3);\n //@ assert arr[1] == 4;\n //@ assert arr[3] == 2;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_125", "file_name": "125", "input": "void foo(int x, int y) {\n int i = x;\n int j = y;\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if(y != 0) {\n //@ assert i != j;\n }\n}", "output": "void foo(int x, int y) {\n int i = x;\n int j = y;\n /*@\n loop invariant y <= j;\n loop invariant x <= i;\n loop invariant i - x == j - y;\n loop invariant i - j == x - y;\n loop assigns x,y,i,j;\n */\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if(y != 0) {\n //@ assert i != j;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_3", "file_name": "BL.EN.U4CSE21176_3", "input": "#include\nint abs(int val){\nif(val<0)\nreturn -val;\nelse\nreturn val;\n}\nint main(){\nint x=4;\nint r=abs(x);\n//@assert x==4;\n}", "output": "#include\n/*@\nrequires INT_MIN<=val=0 ==> \\result == val) && (val<0 ==> \\result == -val);\n*/\nint abs(int val){\nif(val<0)\nreturn -val;\nelse\nreturn val;\n}\nint main(){\nint x=4;\nint r=abs(x);\n//@assert x==4;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "reverse", "file_name": "reverse", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid(p);\n requires valid: \\valid(q);\n assigns *p;\n assigns *q;\n ensures exchange: *p == \\old(*q);\n ensures exchange: *q == \\old(*p);\n*/\nvoid\nswap(value_type* p, value_type* q);\n/*@\n axiomatic Reverse\n {\n predicate\n Reverse{K,L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],K) == \\at(b[n-1-i], L);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Reverse{K,L}(a+m, n-m, b+p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, value_type* b) =\n Reverse{K,L}(a, m, n, b, m);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, integer p) =\n Reverse{K,L}(a, m, n, a, p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n) =\n Reverse{K,L}(a, m, n, m);\n predicate\n Reverse{K,L}(value_type* a, integer n) = Reverse{K,L}(a, 0, n);\n }\n*/\nvoid\nreverse(value_type* a, size_type n)\n{\n const size_type half = n / 2u;\n //@ assert half: half <= n - half;\n //@ assert half: 2*half <= n <= 2*half + 1;\n for (size_type i = 0u; i < half; ++i) {\n swap(&a[i], &a[n - 1u - i]);\n }\n //@ assert Reverse{Pre,Here}(a, n);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid(p);\n requires valid: \\valid(q);\n assigns *p;\n assigns *q;\n ensures exchange: *p == \\old(*q);\n ensures exchange: *q == \\old(*p);\n*/\nvoid\nswap(value_type* p, value_type* q);\n/*@\n axiomatic Reverse\n {\n predicate\n Reverse{K,L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],K) == \\at(b[n-1-i], L);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Reverse{K,L}(a+m, n-m, b+p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, value_type* b) =\n Reverse{K,L}(a, m, n, b, m);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, integer p) =\n Reverse{K,L}(a, m, n, a, p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n) =\n Reverse{K,L}(a, m, n, m);\n predicate\n Reverse{K,L}(value_type* a, integer n) = Reverse{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n assigns a[0..n-1];\n ensures reverse: Reverse{Old,Here}(a, n);\n*/\nvoid\nreverse(value_type* a, size_type n)\n{\n const size_type half = n / 2u;\n //@ assert half: half <= n - half;\n //@ assert half: 2*half <= n <= 2*half + 1;\n /*@\n loop invariant bound: 0 <= i <= half <= n-i;\n loop invariant left: Reverse{Pre,Here}(a, 0, i, n-i);\n loop invariant middle: Unchanged{Pre,Here}(a, i, n-i);\n loop invariant right: Reverse{Pre,Here}(a, n-i, n, 0);\n loop assigns i, a[0..n-1];\n loop variant half - i;\n */\n for (size_type i = 0u; i < half; ++i) {\n swap(&a[i], &a[n - 1u - i]);\n }\n //@ assert Reverse{Pre,Here}(a, n);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "array_double", "file_name": "array_double", "input": "void arrayDouble(int *a, int n) {\n int p = 0;\n while (p < n) {\n a[p] = a[p] * 2;\n p = p + 1;\n } \n}\nint main() {\n int arr[] = {0,1,2,3,4,5};\n arrayDouble(arr, 6);\n //@ assert \\forall integer k; 0 <= k < 6 ==> arr[k] == 2*k;\n}", "output": "/*@\n requires n > 0;\n requires \\valid_read(a+(0..n-1));\n requires \\forall integer k; 0 <= k < n ==> a[k] == k;\n ensures \\forall integer k; 0 <= k < n ==> a[k] == 2*k;\n*/\nvoid arrayDouble(int *a, int n) {\n int p = 0;\n /*@\n loop invariant 0 <= p <= n;\n loop invariant \\forall integer k; p <= k < n ==> a[k] == k;\n loop invariant \\forall integer k; 0 <= k < p ==> a[k] == 2*k;\n loop assigns p, a[0..n-1];\n */\n while (p < n) {\n a[p] = a[p] * 2;\n p = p + 1;\n } \n}\nint main() {\n int arr[] = {0,1,2,3,4,5};\n arrayDouble(arr, 6);\n //@ assert \\forall integer k; 0 <= k < 6 ==> arr[k] == 2*k;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_minimum element in the array", "file_name": "minimum element in the array", "input": "#include\nint min_in_array(int arr[],int n)\n{\n int min=arr[0];\n for(int i=0;i k<=arr[i];\nreturn 0;\n}", "output": "#include\n/*@\n requires 0 \\result<=arr[i];\n*/\nint min_in_array(int arr[],int n)\n{\n int min=arr[0];\n /*@\n loop invariant \\forall integer x;0<=x min<=arr[x];\n loop invariant 0<=i<=n;\n loop assigns i,min;\n loop variant n-i;\n */\n for(int i=0;i k<=arr[i];\nreturn 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_To check the given no. is odd or even and is divisible by 3", "file_name": "To check the given no. is odd or even and is divisible by 3", "input": "#include\n#include\nint div(int a)\n{\nif(a%2==0 || a%3==0)\nreturn 0;\nelse \nreturn 1;\n}\nint main()\n{\nint m=div(6);\n//@ assert m==0;\n}", "output": "//name:-Nabin kumar sah\n//reg no:-BL.EN.U4CSE21129\n#include\n#include\n/*@\nrequires INT_MIN \\result==0\n|| ( a%3==0) ==> \\result==0;\nensures (a%2!=0) ==> \\result==1\n|| (a%3!=0) ==> \\result==1;\n*/\nint div(int a)\n{\nif(a%2==0 || a%3==0)\nreturn 0;\nelse \nreturn 1;\n}\nint main()\n{\nint m=div(6);\n//@ assert m==0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "mutable_arrays_bubble_sort", "file_name": "bubble_sort", "input": "#include \nvoid bubbleSort(int *a, int n) {\n if (n <= 0) {\n return;\n }\n int i, j, temp;\n for(i=n-1; i>0; i--) {\n for(j=0; j a[j+1]) {\n temp = a[j];\n a[j] = a[j+1];\n a[j+1] = temp;\n }\n }\n }\n}\nvoid main() {\n int arr[5] = {5, 4, 3, 2, 1};\n bubbleSort(arr, 5);\n //@ assert \\forall int i; 0 <= i < 4 ==> arr[i] <= arr[i+1];\n}", "output": "#include \n/*@ \n requires \\valid(a+(0..n-1));\n requires n > 0;\n ensures \\forall integer i,j; 0<=i<=j<=n-1 ==> a[i]<=a[j];\n*/\nvoid bubbleSort(int *a, int n) {\n if (n <= 0) {\n return;\n }\n int i, j, temp;\n /*@ \n loop invariant \\forall integer p,q; i<=p<=q<=n-1 ==> a[p]<=a[q];\n loop invariant \\forall integer p,q; 0<=p a[p]<=a[q];\n loop invariant 0<=i0; i--) {\n /*@ loop invariant 0<=j<=i a[k] <= a[j];\n loop invariant \\forall integer p, q; 0<=p a[p]<=a[q];\n loop assigns j,temp,a[0..i];\n */\n for(j=0; j a[j+1]) {\n temp = a[j];\n a[j] = a[j+1];\n a[j+1] = temp;\n }\n }\n }\n}\nvoid main() {\n int arr[5] = {5, 4, 3, 2, 1};\n bubbleSort(arr, 5);\n //@ assert \\forall int i; 0 <= i < 4 ==> arr[i] <= arr[i+1];\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_68", "file_name": "68", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int y = 0;\n int x = 1;\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y <= n;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int y = 0;\n int x = 1;\n /*@\n loop invariant y <= n;\n loop invariant x <= n+1;\n loop invariant x <= n + 1;\n loop invariant 1 <= x;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y <= n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "X509-parser_verify_correct_time_use", "file_name": "verify_correct_time_use", "input": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\ntypedef enum {\n\tCLASS_UNIVERSAL = 0x00,\n\tCLASS_APPLICATION = 0x01,\n\tCLASS_CONTEXT_SPECIFIC = 0x02,\n\tCLASS_PRIVATE = 0x03\n} tag_class;\ntypedef enum {\n\tASN1_TYPE_BOOLEAN = 0x01,\n\tASN1_TYPE_INTEGER = 0x02,\n\tASN1_TYPE_BIT_STRING = 0x03,\n\tASN1_TYPE_OCTET_STRING = 0x04,\n\tASN1_TYPE_NULL = 0x05,\n\tASN1_TYPE_OID = 0x06,\n\tASN1_TYPE_ENUMERATED = 0x0a,\n\tASN1_TYPE_SEQUENCE = 0x10,\n\tASN1_TYPE_SET = 0x11,\n\tASN1_TYPE_PrintableString = 0x13,\n\tASN1_TYPE_T61String = 0x14,\n\tASN1_TYPE_IA5String = 0x16,\n\tASN1_TYPE_UTCTime = 0x17,\n\tASN1_TYPE_GeneralizedTime = 0x18,\n} asn1_type;\n#define X509_FILE_NUM 3\n#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)\nint verify_correct_time_use(u8 time_type, u16 yyyy)\n{\n\tint ret;\n\tswitch (time_type) {\n\tcase ASN1_TYPE_UTCTime:\n\t\tret = (yyyy <= 2049) ? 0 : -X509_FILE_LINE_NUM_ERR;\n\t\tbreak;\n\tcase ASN1_TYPE_GeneralizedTime:\n\t\tret = (yyyy >= 2050) ? 0 : -X509_FILE_LINE_NUM_ERR;\n\t\tbreak;\n\tdefault:\n\t\tret = -1;\n\t\tbreak;\n\t}\n\treturn ret;\n}\nint main() {\n\tu8 time_type = ASN1_TYPE_IA5String;\n\tu16 yyyy;\n\tint result = verify_correct_time_use(time_type, yyyy);\n\t//@ assert result == -1;\n\ttime_type = ASN1_TYPE_UTCTime;\n\tresult = verify_correct_time_use(time_type, yyyy);\n\t//@ assert result < 0 || result == 0;\n\treturn 0;\n}", "output": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\ntypedef enum {\n\tCLASS_UNIVERSAL = 0x00,\n\tCLASS_APPLICATION = 0x01,\n\tCLASS_CONTEXT_SPECIFIC = 0x02,\n\tCLASS_PRIVATE = 0x03\n} tag_class;\ntypedef enum {\n\tASN1_TYPE_BOOLEAN = 0x01,\n\tASN1_TYPE_INTEGER = 0x02,\n\tASN1_TYPE_BIT_STRING = 0x03,\n\tASN1_TYPE_OCTET_STRING = 0x04,\n\tASN1_TYPE_NULL = 0x05,\n\tASN1_TYPE_OID = 0x06,\n\tASN1_TYPE_ENUMERATED = 0x0a,\n\tASN1_TYPE_SEQUENCE = 0x10,\n\tASN1_TYPE_SET = 0x11,\n\tASN1_TYPE_PrintableString = 0x13,\n\tASN1_TYPE_T61String = 0x14,\n\tASN1_TYPE_IA5String = 0x16,\n\tASN1_TYPE_UTCTime = 0x17,\n\tASN1_TYPE_GeneralizedTime = 0x18,\n} asn1_type;\n#define X509_FILE_NUM 3 \n#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)\n/*@ ensures \\result < 0 || \\result == 0;\n ensures \\result == -1 ==> (time_type != ASN1_TYPE_UTCTime && time_type != ASN1_TYPE_GeneralizedTime);\n ensures (time_type != ASN1_TYPE_UTCTime && time_type != ASN1_TYPE_GeneralizedTime) ==> \\result == -1;\n assigns \\nothing;\n*/\nint verify_correct_time_use(u8 time_type, u16 yyyy)\n{\n\tint ret;\n\tswitch (time_type) {\n\tcase ASN1_TYPE_UTCTime:\n\t\tret = (yyyy <= 2049) ? 0 : -X509_FILE_LINE_NUM_ERR;\n\t\tbreak;\n\tcase ASN1_TYPE_GeneralizedTime:\n\t\tret = (yyyy >= 2050) ? 0 : -X509_FILE_LINE_NUM_ERR;\n\t\tbreak;\n\tdefault:\n\t\tret = -1;\n\t\tbreak;\n\t}\n\treturn ret;\n}\nint main() {\n\tu8 time_type = ASN1_TYPE_IA5String;\n\tu16 yyyy;\n\tint result = verify_correct_time_use(time_type, yyyy);\n\t//@ assert result == -1;\n\ttime_type = ASN1_TYPE_UTCTime;\n\tresult = verify_correct_time_use(time_type, yyyy);\n\t//@ assert result < 0 || result == 0;\n\treturn 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_74", "file_name": "74", "input": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n while (unknown()) {\n if(c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (c < 36) {\n //@ assert z >= 0;\n }\n}", "output": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n /*@\n loop invariant z == 36*y + c;\n loop invariant z == 36 * y + c;\n loop invariant c <= 36;\n loop invariant c < 36 || z >= 0;\n loop invariant c < 36 ==> z >= 0;\n loop invariant 36 * y <= z;\n loop invariant 0 <= c;\n loop assigns z;\n loop assigns c;\n */\n while (unknown()) {\n if(c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (c < 36) {\n //@ assert z >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "more_arrays_replace_evens", "file_name": "replace_evens", "input": "void func(int *a, int n) {\n for (int i = 0; i < n; i++) {\n if (i%2==0) \n a[i] = 0;\n }\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n func(arr, 5);\n //@ assert arr[0] == 0;\n //@ assert arr[2] == 0;\n //@ assert arr[4] == 0;\n}", "output": "/*@\n requires n > 0;\n requires \\valid_read(a + (0..n-1));\n ensures \\forall integer k; (0<=k (a[k] == 0);\n*/\nvoid func(int *a, int n) {\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; (0 <= k < i) && (k%2==0) ==> a[k] == 0;\n loop invariant \\forall integer k; (0 <= k < i) && (k%2==1) ==> a[k] == a[k];\n loop assigns i, a[0..(n-1)];\n */\n for (int i = 0; i < n; i++) {\n if (i%2==0) \n a[i] = 0;\n }\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n func(arr, 5);\n //@ assert arr[0] == 0;\n //@ assert arr[2] == 0;\n //@ assert arr[4] == 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "find_first_of", "file_name": "find_first_of", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic SomeNone\n {\n predicate\n SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] == v;\n predicate\n SomeEqual{A}(value_type* a, integer n, value_type v) =\n SomeEqual(a, 0, n, v);\n predicate\n NoneEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] != v;\n predicate\n NoneEqual(value_type* a, integer n, value_type v) =\n NoneEqual(a, 0, n, v);\n lemma NotSomeEqual_NoneEqual:\n \\forall value_type *a, v, integer m, n;\n !SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);\n lemma NoneEqual_NotSomeEqual:\n \\forall value_type *a, v, integer m, n;\n NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);\n }\n*/\n/*@\n axiomatic HasValueOf\n {\n predicate\n HasValueOf{A}(value_type* a, integer m, value_type* b, integer n) =\n \\exists integer i; 0 <= i < m && SomeEqual{A}(b, n, a[i]);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior some:\n assumes SomeEqual(a, n, v);\n assigns \\nothing;\n ensures bound: 0 <= \\result < n;\n ensures result: a[\\result] == v;\n ensures first: NoneEqual(a, \\result, v);\n behavior none:\n assumes NoneEqual(a, n, v);\n assigns \\nothing;\n ensures result: \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nfind2(const value_type* a, size_type n, value_type v);\nsize_type\nfind_first_of (const value_type* a, size_type m,\n const value_type* b, size_type n)\n{\n for (size_type i = 0u; i < m; i++) {\n if (find2(b, n, a[i]) < n) {\n //@ assert HasValueOf(a, i + 1, b, n);\n return i;\n }\n }\n //@ assert !HasValueOf(a, m, b, n);\n return m;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic SomeNone\n {\n predicate\n SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] == v;\n predicate\n SomeEqual{A}(value_type* a, integer n, value_type v) =\n SomeEqual(a, 0, n, v);\n predicate\n NoneEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] != v;\n predicate\n NoneEqual(value_type* a, integer n, value_type v) =\n NoneEqual(a, 0, n, v);\n lemma NotSomeEqual_NoneEqual:\n \\forall value_type *a, v, integer m, n;\n !SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);\n lemma NoneEqual_NotSomeEqual:\n \\forall value_type *a, v, integer m, n;\n NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);\n }\n*/\n/*@\n axiomatic HasValueOf\n {\n predicate\n HasValueOf{A}(value_type* a, integer m, value_type* b, integer n) =\n \\exists integer i; 0 <= i < m && SomeEqual{A}(b, n, a[i]);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior some:\n assumes SomeEqual(a, n, v);\n assigns \\nothing;\n ensures bound: 0 <= \\result < n;\n ensures result: a[\\result] == v;\n ensures first: NoneEqual(a, \\result, v);\n behavior none:\n assumes NoneEqual(a, n, v);\n assigns \\nothing;\n ensures result: \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nfind2(const value_type* a, size_type n, value_type v);\n/*@\n requires valid: \\valid_read(a + (0..m-1));\n requires valid: \\valid_read(b + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= m;\n behavior found:\n assumes HasValueOf(a, m, b, n);\n assigns \\nothing;\n ensures bound: 0 <= \\result < m;\n ensures result: SomeEqual(b, n, a[\\result]);\n ensures first: !HasValueOf(a, \\result, b, n);\n behavior not_found:\n assumes !HasValueOf(a, m, b, n);\n assigns \\nothing;\n ensures result: \\result == m;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nfind_first_of (const value_type* a, size_type m,\n const value_type* b, size_type n)\n{\n /*@\n loop invariant bound: 0 <= i <= m;\n loop invariant not_found: !HasValueOf(a, i, b, n);\n loop assigns i;\n loop variant m-i;\n */\n for (size_type i = 0u; i < m; i++) {\n if (find2(b, n, a[i]) < n) {\n //@ assert HasValueOf(a, i + 1, b, n);\n return i;\n }\n }\n //@ assert !HasValueOf(a, m, b, n);\n return m;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_119", "file_name": "119", "input": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n while (i <= size) { \n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == size;\n }\n}", "output": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= size+1;\n loop invariant i <= size + 1;\n loop invariant 1 <= i;\n loop invariant 0 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= size) { \n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == size;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_50", "file_name": "50", "input": "void main() {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != 4) {\n c = c + 1;\n }\n } else {\n if (c == 4) {\n c = 1;\n }\n }\n }\n if (c != 4) {\n //@ assert c >= 0;\n }\n}", "output": "void main() {\n int c = 0;\n /*@\n loop invariant c <= 4;\n loop invariant c != 4 || c >= 0;\n loop invariant 0 <= c;\n loop invariant (c == 4) || (c != 4);\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != 4) {\n c = c + 1;\n }\n } else {\n if (c == 4) {\n c = 1;\n }\n }\n }\n if (c != 4) {\n //@ assert c >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_distance", "file_name": "distance", "input": "unsigned distance(unsigned a, unsigned b)\n{\n return (a > b) ? (a - b) : (b - a);\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = distance(5, 3);\n //@ assert a == 2;\n int b = distance(3, 5);\n //@ assert b == 2;\n}\n#endif", "output": "/*@ \n requires \\true;\n assigns \\nothing;\n ensures \\result == \\max(a, b) - \\min(a, b);\n */\nunsigned distance(unsigned a, unsigned b)\n{\n return (a > b) ? (a - b) : (b - a);\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = distance(5, 3);\n //@ assert a == 2;\n int b = distance(3, 5);\n //@ assert b == 2;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_11", "file_name": "11", "input": "#include\n/*@\n logic integer ax_b(integer a, integer x, integer b) = a * x + b;\n*/\nint restricted(int x){\n return 3*x + 4;\n}\nint main(){\n int x = 10;\n int result = restricted(x);\n //@ assert result == 34;\n return 0;\n}", "output": "#include\n/*@\n logic integer ax_b(integer a, integer x, integer b) = a * x + b;\n*/\n/*@\n requires INT_MIN <= 3*x;\n requires INT_MIN <= ax_b(3, x, 4) <= INT_MAX;\n assigns \\nothing;\n ensures \\result == ax_b(3, x, 4);\n*/\nint restricted(int x){\n return 3*x + 4;\n}\nint main(){\n int x = 10;\n int result = restricted(x);\n //@ assert result == 34;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_122", "file_name": "122", "input": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n while (i <= size) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != size) {\n //@ assert sn == 0;\n }\n}", "output": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= size+1;\n loop invariant i <= size + 1;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= size) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != size) {\n //@ assert sn == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "copy_backward", "file_name": "copy_backward", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\nvoid\ncopy_backward(const value_type* a, size_type n, value_type* b)\n{\n for (size_type i = n; i > 0u; --i) {\n b[i - 1u] = a[i - 1u];\n }\n //@ assert Equal{Pre,Here}(a, n, b);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a + (0..n-1), b + n);\n assigns b[0..n-1];\n ensures equal: Equal{Old,Here}(a, n, b);\n*/\nvoid\ncopy_backward(const value_type* a, size_type n, value_type* b)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant equal: Equal{Pre,Here}(a, i, n, b);\n loop invariant unchanged: Unchanged{Pre,Here}(a, i);\n loop assigns i, b[0..n-1];\n loop variant i;\n */\n for (size_type i = n; i > 0u; --i) {\n b[i - 1u] = a[i - 1u];\n }\n //@ assert Equal{Pre,Here}(a, n, b);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_triangle", "file_name": "triangle", "input": "int last_angle(int first, int second){\n return 180 - first - second ;\n}\nint main(){\n int first = 45;\n int second = 45;\n int result = last_angle(first, second);\n //@ assert result == 90;\n}", "output": "/*@\n requires inputs: range: 0 < first < 180 &&\n 0 < second < 180;\n requires positive_remainder: first + second < 180; \n ensures sum_180: first + second + \\result == 180; \n assigns \\nothing; \n*/\nint last_angle(int first, int second){\n return 180 - first - second ;\n}\nint main(){\n int first = 45;\n int second = 45;\n int result = last_angle(first, second);\n //@ assert result == 90;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arrays_and_loops_3", "file_name": "3", "input": "int func(int a) {\n int x, y;\n int sum, res;\n if (a == 0){\n x = 0; y = 0;\n }\n else {\n x = 5; y = 5;\n }\n sum = x + y; \n res = 10/sum; \n return res;\n}\nint main(){\n int a = 1;\n int result = func(a);\n //@ assert result == 1;\n return 0;\n}", "output": "/*@ \n requires a!=0;\n ensures \\result == 1;\n assigns \\nothing;\n*/\nint func(int a) {\n int x, y;\n int sum, res;\n if (a == 0){\n x = 0; y = 0;\n }\n else {\n x = 5; y = 5;\n }\n sum = x + y; \n res = 10/sum; \n return res;\n}\nint main(){\n int a = 1;\n int result = func(a);\n //@ assert result == 1;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_condit-set", "file_name": "condit-set", "input": "void reset_1st_if_2nd_is_true(int* a, int const* b){\n if(*b) *a = 0 ;\n}\nint main(){\n int a = 5 ;\n int x = 0 ;\n reset_1st_if_2nd_is_true(&a, &x);\n //@ assert a == 5 ;\n //@ assert x == 0 ;\n int const b = 1 ;\n reset_1st_if_2nd_is_true(&a, &b);\n //@ assert a == 0 ;\n //@ assert b == 1 ;\n}", "output": "/*@ \n requires valid_ptrs: \\valid(a) && \\valid_read(b); \n requires diff_ptrs: \\separated(a, b); \n assigns val_to_first: *a; \n ensures unchanged_second: \\old(*b) == *b; \n behavior second_true: \n assumes *b; \n ensures *a == 0; \n behavior second_false: \n assumes !*b; \n ensures *a == \\old(*a); \n complete behaviors; \n disjoint behaviors; \n*/\nvoid reset_1st_if_2nd_is_true(int* a, int const* b){\n if(*b) *a = 0 ;\n}\nint main(){\n int a = 5 ;\n int x = 0 ;\n reset_1st_if_2nd_is_true(&a, &x);\n //@ assert a == 5 ;\n //@ assert x == 0 ;\n int const b = 1 ;\n reset_1st_if_2nd_is_true(&a, &b);\n //@ assert a == 0 ;\n //@ assert b == 1 ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_93", "file_name": "93", "input": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int i = 0;\n int x = 0;\n int y = 0;\n while (i < n) {\n i = i + 1;\n if (unknown()) {\n x = x + 1;\n y = y + 2;\n } else {\n x = x + 2;\n y = y + 1;\n }\n }\n //@ assert (3 * n) == (x + y);\n}", "output": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int i = 0;\n int x = 0;\n int y = 0;\n /*@\n loop invariant x + y == 3 * i;\n loop invariant i <= n;\n loop invariant 0 <= i;\n loop assigns x,y,i;\n */\n while (i < n) {\n i = i + 1;\n if (unknown()) {\n x = x + 1;\n y = y + 2;\n } else {\n x = x + 2;\n y = y + 1;\n }\n }\n //@ assert (3 * n) == (x + y);\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "loops_mult", "file_name": "mult", "input": "#include \nint mul(int a, int b) {\n int x = a, y = b, prod = 0;\n while(x >= 0) {\n prod = prod + y;\n x--;\n }\n return prod;\n}\nint main() {\n int pdt = mul(2, 5);\n //@ assert pdt == 15;\n}", "output": "#include \n/*@\n requires a >= 0 && b >= 0;\n requires a == 2 && b == 5;\n ensures \\result == \\old(a+1) * \\old(b);\n assigns \\nothing;\n*/\nint mul(int a, int b) {\n int x = a, y = b, prod = 0;\n /*@ \n loop invariant prod == (a-x)*y;\n loop invariant x == a - prod/y;\n loop invariant -1 <= x <= a;\n loop assigns prod, x;\n loop variant x;\n */\n while(x >= 0) {\n prod = prod + y;\n x--;\n }\n return prod;\n}\nint main() {\n int pdt = mul(2, 5);\n //@ assert pdt == 15;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "immutable_array_search", "file_name": "search", "input": "int arraysearch(int* a, int x, int n) { \n for (int p = 0; p < n; p++) {\n if (x == a[p]) \n return 1;\n }\n return 0;\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n int sum = arraysearch(arr, 3, 5);\n //@ assert sum == 1;\n}", "output": "/*@ \nrequires n > 0;\nrequires \\valid_read(a + (0..n-1));\nassigns \\nothing;\nbehavior present:\n assumes \\exists integer k; 0 <= k < n && x == a[k];\n ensures \\result == 1;\nbehavior not_present:\n assumes \\forall integer k; 0 <= k < n ==> x != a[k];\n ensures \\result == 0;\ndisjoint behaviors;\ncomplete behaviors;\n*/\nint arraysearch(int* a, int x, int n) { \n /*@ \n loop invariant 0 <= p <= n;\n loop invariant \\forall integer k; 0 <= k < p ==> x != a[k];\n loop assigns p;\n */\n for (int p = 0; p < n; p++) {\n if (x == a[p]) \n return 1;\n }\n return 0;\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n int sum = arraysearch(arr, 3, 5);\n //@ assert sum == 1;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_63", "file_name": "63", "input": "int main() {\n int x = 1;\n int y = 0;\n while (x <= 10) {\n y = 10 - x;\n x = x +1;\n }\n //@ assert y >= 0;\n //@ assert y <= 10;\n}", "output": "int main() {\n int x = 1;\n int y = 0;\n /*@\n loop invariant 0 <= y <= 10;\n loop invariant 1 <= x <= 11;\n loop assigns y,x;\n */\n while (x <= 10) {\n y = 10 - x;\n x = x +1;\n }\n //@ assert y >= 0;\n //@ assert y <= 10;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_66", "file_name": "66", "input": "int main() {\n int x = 1;\n int y = 0;\n while (x <= 100) {\n y = 100 - x;\n x = x +1;\n }\n //@ assert y < 100;\n}", "output": "int main() {\n int x = 1;\n int y = 0;\n /*@\n loop invariant y <= 100;\n loop invariant y <= 100 || y <= 100 - x;\n loop invariant y <= 100 || y < 100;\n loop invariant y <= 100 || 0 <= y;\n loop invariant y <= 100 - x || y < 100;\n loop invariant y <= 100 - x || 0 <= y;\n loop invariant y < 100;\n loop invariant y < 100 || 0 <= y;\n loop invariant 0 <= y;\n loop invariant x <= 101;\n loop invariant 1 <= x;\n loop assigns y,x;\n */\n while (x <= 100) {\n y = 100 - x;\n x = x +1;\n }\n //@ assert y < 100;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_17", "file_name": "17", "input": "/*@\nrequires n > 1;\n*/\nvoid foo(int n)\n{\n int x = 1;\n int m = 1;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 1) {\n //@ assert m < n;\n //@ assert m >= 1;\n }\n}", "output": "/*@\nrequires n > 1;\n*/\nvoid foo(int n)\n{\n int x = 1;\n int m = 1;\n /*@\n loop invariant 1 <= x <= n;\n loop invariant 1 <= m <= x;\n loop invariant m < x || m == 1;\n loop invariant m < n;\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 1) {\n //@ assert m < n;\n //@ assert m >= 1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_indaddr", "file_name": "indaddr", "input": "void indaddr(unsigned size, int arr[size], unsigned addr)\n{\n\tarr[arr[addr]] = 0;\n}\nint main(){\n\tunsigned size = 5;\n\tint arr[5] = {1, 2, 3, 4, 5};\n\tindaddr(size, arr, 2);\n\t//@ assert arr[3] == 0;\n}", "output": "/*@ requires \\valid(arr + (0..size-1));\n requires 0 <= addr < size;\n ensures arr[\\at(arr[addr],Pre)] == 0;\n */\nvoid indaddr(unsigned size, int arr[size], unsigned addr)\n{\n\tarr[arr[addr]] = 0;\n}\nint main(){\n\tunsigned size = 5;\n\tint arr[5] = {1, 2, 3, 4, 5};\n\tindaddr(size, arr, 2);\n\t//@ assert arr[3] == 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_10", "file_name": "10", "input": "void order_3(int* a, int* b, int* c){\n if(*a > *b){\n int tmp = *b;\n *b = *a;\n *a = tmp;\n }\n if(*a > *c){\n int tmp = *c;\n *c = *a;\n *a = tmp;\n }\n if(*b > *c){\n int tmp = *b;\n *b = *c;\n *c = tmp;\n }\n}\nint main(){\n int x = 10, y = 20, z = 15;\n order_3(&x, &y, &z);\n //@ assert x == 10 && y == 15 && z == 20;\n return 0;\n}", "output": "/*@ requires \\valid(a) && \\valid(b) && \\valid(c);\n requires \\separated(a, b, c);\n assigns *a, *b, *c;\n ensures *a <= *b <= *c;\n ensures { *a, *b, *c } == \\old({ *a, *b, *c });\n ensures (\\old(*a == *b < *c) || *a == *c < *b || *b == *c < *a) ==> *a == *b;\n ensures (\\old(*a == *b > *c) || *a == *c > *b || *b == *c > *a) ==> *b == *c;\n*/\nvoid order_3(int* a, int* b, int* c){\n if(*a > *b){\n int tmp = *b;\n *b = *a;\n *a = tmp;\n }\n if(*a > *c){\n int tmp = *c;\n *c = *a;\n *a = tmp;\n }\n if(*b > *c){\n int tmp = *b;\n *b = *c;\n *c = tmp;\n }\n}\nint main(){\n int x = 10, y = 20, z = 15;\n order_3(&x, &y, &z);\n //@ assert x == 10 && y == 15 && z == 20;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_21", "file_name": "21", "input": "int main()\n{\n int z1,z2,z3;\n int x = 1;\n int m = 1;\n int n;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 1) {\n //@ assert m < n;\n //@ assert m >= 1;\n }\n}", "output": "int main()\n{\n int z1,z2,z3;\n int x = 1;\n int m = 1;\n int n;\n /*@\n loop invariant n > 1 ==> 1 <= m < n;\n loop invariant m <= x;\n loop invariant 1 <= x;\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n //post-condition\n if(n > 1) {\n //@ assert m < n;\n //@ assert m >= 1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_19", "file_name": "19", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 0) {\n //@ assert m < n;\n //@ assert m >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n /*@\n loop invariant x == n ==> m >= 0;\n loop invariant x == n ==> m < n;\n loop invariant 0 <= x <= n;\n loop invariant m >= 0 && m <= x;\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n //post-condition\n if(n > 0) {\n //@ assert m < n;\n //@ assert m >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_abs", "file_name": "abs", "input": "#include \nint abs(int val){\n if (val < 0) {\n /*@ assert rte: signed_overflow: -2147483647 <= val; */\n return -val;\n } \n return val;\n}\n/*@\n requires d_input_not_min: INT_MIN < a; \n assigns \\nothing; \n*/\nvoid foo(int a){\n int b = abs(42);\n int c = abs(-42);\n //@ assert c == 42;\n int d = abs(a);\n int e = abs(INT_MIN + 1);\n //@ assert e == INT_MAX;\n}", "output": "#include \n/*@ \n requires INT_MIN < val;\n ensures positive_value: function_result: \\result >= 0;\n ensures (\\old(val) >= 0 ==> \\result == \\old(val)) &&\n (\\old(val) < 0 ==> \\result == -\\old(val));\n assigns \\nothing; \n*/\nint abs(int val){\n if (val < 0) {\n /*@ assert rte: signed_overflow: -2147483647 <= val; */\n return -val;\n } \n return val;\n}\n/*@\n requires d_input_not_min: INT_MIN < a; \n assigns \\nothing; \n*/\nvoid foo(int a){\n int b = abs(42);\n int c = abs(-42);\n //@ assert c == 42;\n int d = abs(a);\n int e = abs(INT_MIN + 1);\n //@ assert e == INT_MAX;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nikunjjain02_Basics_5", "file_name": "Basics_5", "input": "#include\n#include\nint check(int d)\n{\n if(d%10==0)\n { return (d+5); }\n else \n { return (d-2); }\n}\nvoid main()\n{\n int a = 20;\n //@ assert a == 20;\n int b = check(a);\n //@ assert b == 25;\n int c = 34;\n //@ assert c == 34;\n int e = check(c);\n //@ assert e == 32;\n}", "output": "#include\n#include\n/*@\n requires -1000 \\result == d + 5;\n ensures d % 10 != 0 ==> \\result == d - 2;\n*/\nint check(int d)\n{\n if(d%10==0)\n { return (d+5); }\n else \n { return (d-2); }\n}\nvoid main()\n{\n int a = 20;\n //@ assert a == 20;\n int b = check(a);\n //@ assert b == 25;\n int c = 34;\n //@ assert c == 34;\n int e = check(c);\n //@ assert e == 32;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_52", "file_name": "52", "input": "int main() {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != 4) {\n c = c + 1;\n }\n } else {\n if (c == 4) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > 4) {\n //@ assert c == 4;\n }\n }\n}", "output": "int main() {\n int c = 0;\n /*@\n loop invariant c <= 4;\n loop invariant \\exists integer k; 0 <= k <= 4 && c == k;\n loop invariant 0 <= c;\n loop invariant (c >= 0 && c <= 4) || (c == 0);\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != 4) {\n c = c + 1;\n }\n } else {\n if (c == 4) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > 4) {\n //@ assert c == 4;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_minus-loop", "file_name": "minus-loop", "input": "void minus_loop() {\n int x = 0 ;\n while (x > -10){\n -- x ;\n }\n //@ assert x == -10 ;\n}", "output": "void minus_loop() {\n int x = 0 ;\n /*@ loop invariant -10 <= x <= 0 ; \n loop assigns x ;\n loop variant x + 10 ; \n */\n while (x > -10){\n -- x ;\n }\n //@ assert x == -10 ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_12", "file_name": "12", "input": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n int z1;\n int z2;\n int z3;\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (y == 0) {\n //@ assert x != 20;\n }\n}", "output": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n int z1;\n int z2;\n int z3;\n /*@\n loop invariant y != 0 || x != 20;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns x,y;\n */\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (y == 0) {\n //@ assert x != 20;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "fill", "file_name": "fill", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic AllSomeNot\n {\n predicate\n AllEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] == v;\n predicate\n AllEqual(value_type* a, integer m, integer n) =\n AllEqual(a, m, n, a[m]);\n predicate\n AllEqual(value_type* a, integer n, value_type v) =\n AllEqual(a, 0, n, v);\n predicate\n SomeNotEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] != v;\n predicate\n SomeNotEqual{A}(value_type* a, integer n, value_type v) =\n SomeNotEqual(a, 0, n, v);\n lemma NotAllEqual_SomeNotEqual:\n \\forall value_type *a, v, integer m, n;\n !AllEqual(a, m, n, v) ==> SomeNotEqual(a, m, n, v);\n lemma SomeNotEqual_NotAllEqual:\n \\forall value_type *a, v, integer m, n;\n SomeNotEqual(a, m, n, v) ==> !AllEqual(a, m, n, v);\n }\n*/\nvoid\nfill(value_type* a, size_type n, value_type v)\n{\n for (size_type i = 0u; i < n; ++i) {\n a[i] = v;\n }\n //@ assert AllEqual(a, n, v);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic AllSomeNot\n {\n predicate\n AllEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] == v;\n predicate\n AllEqual(value_type* a, integer m, integer n) =\n AllEqual(a, m, n, a[m]);\n predicate\n AllEqual(value_type* a, integer n, value_type v) =\n AllEqual(a, 0, n, v);\n predicate\n SomeNotEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] != v;\n predicate\n SomeNotEqual{A}(value_type* a, integer n, value_type v) =\n SomeNotEqual(a, 0, n, v);\n lemma NotAllEqual_SomeNotEqual:\n \\forall value_type *a, v, integer m, n;\n !AllEqual(a, m, n, v) ==> SomeNotEqual(a, m, n, v);\n lemma SomeNotEqual_NotAllEqual:\n \\forall value_type *a, v, integer m, n;\n SomeNotEqual(a, m, n, v) ==> !AllEqual(a, m, n, v);\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n assigns a[0..n-1];\n ensures constant: AllEqual(a, n, v);\n*/\nvoid\nfill(value_type* a, size_type n, value_type v)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant constant: AllEqual(a, i, v);\n loop assigns i, a[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n a[i] = v;\n }\n //@ assert AllEqual(a, n, v);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_alphabet-letter", "file_name": "alphabet-letter", "input": "#include \nint alphabet_letter(char c){\n if( ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ) return 1 ;\n else return 0 ;\n}\nint main(){\n int r ;\n r = alphabet_letter('x') ;\n //@ assert r ;\n r = alphabet_letter('H') ;\n //@ assert r ;\n r = alphabet_letter(' ') ;\n //@ assert !r ;\n }", "output": "#include \n/*@ \n requires INT_MIN < c < INT_MAX;\n ensures character: function_result: \n 'a' <= c <= 'z' || 'A' <= c <= 'Z' \n <==> \\result == 1; \n ensures non_character: function_result: \n INT_MIN < c < 'A' || \n 'Z' < c < 'a' ||\n 'z' < c < INT_MAX \n <==> \\result == 0; \n assigns \\nothing; \n*/\nint alphabet_letter(char c){\n if( ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ) return 1 ;\n else return 0 ;\n}\nint main(){\n int r ;\n r = alphabet_letter('x') ;\n //@ assert r ;\n r = alphabet_letter('H') ;\n //@ assert r ;\n r = alphabet_letter(' ') ;\n //@ assert !r ;\n }", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_22", "file_name": "22", "input": "int main()\n{\n int x = 1;\n int m = 1;\n int n;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 1) {\n ////@ assert m < n;\n //@ assert m >= 1;\n }\n}", "output": "int main()\n{\n int x = 1;\n int m = 1;\n int n;\n /*@\n loop invariant n > 1 ==> m >= 1;\n loop invariant n > 1 ==> m < n;\n loop invariant m <= x;\n loop invariant 1 <= x;\n loop invariant 1 <= m;\n loop assigns x,n,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n //post-condition\n if(n > 1) {\n ////@ assert m < n;\n //@ assert m >= 1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_120", "file_name": "120", "input": "int main() {\n int i = 1;\n int sn = 0;\n while (i <= 8) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 8) {\n //@ assert sn == 0;\n }\n}", "output": "int main() {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= 9;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= 8) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 8) {\n //@ assert sn == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "random_number", "file_name": "random_number", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic C_Bit\n {\n lemma RandomNumberModulo:\n \\forall unsigned long long a;\n (a % (1ull << 48)) < (1ull << 48);\n }\n*/\n/*@\n requires valid: \\valid(seed + (0..2));\n assigns seed[0..2];\n ensures lower: 0 <= \\result;\n ensures upper: \\result <= 0x7fffffff;\n*/\nstatic long\nmy_lrand48(unsigned short* seed)\n{\n unsigned long long state = (unsigned long long)seed[0] << 32\n | (unsigned long long)seed[1] << 16\n | (unsigned long long)seed[2];\n state = (0x5deece66dull * state + 0xbull) % (1ull << 48);\n //@ assert lower: state < (1ull << 48);\n long result = state / (1ull << 17);\n //@ assert lower: 0 <= result;\n seed[0u] = state >> 32 & 0xffff;\n seed[1u] = state >> 16 & 0xffff;\n seed[2u] = state >> 8 & 0xffff;\n return result;\n}\nsize_type\nrandom_number(unsigned short* state, size_type n)\n{\n return my_lrand48(state) % n;\n}\n/*@\n requires \\valid(state + (0..2));\n assigns state[0..2];\n*/\nvoid\nrandom_init(unsigned short* state)\n{\n state[0] = 0x243f;\n state[1] = 0x6a88;\n state[2] = 0x85a3;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic C_Bit\n {\n lemma RandomNumberModulo:\n \\forall unsigned long long a;\n (a % (1ull << 48)) < (1ull << 48);\n }\n*/\n/*@\n requires valid: \\valid(seed + (0..2));\n assigns seed[0..2];\n ensures lower: 0 <= \\result;\n ensures upper: \\result <= 0x7fffffff;\n*/\nstatic long\nmy_lrand48(unsigned short* seed)\n{\n unsigned long long state = (unsigned long long)seed[0] << 32\n | (unsigned long long)seed[1] << 16\n | (unsigned long long)seed[2];\n state = (0x5deece66dull * state + 0xbull) % (1ull << 48);\n //@ assert lower: state < (1ull << 48);\n long result = state / (1ull << 17);\n //@ assert lower: 0 <= result;\n seed[0u] = state >> 32 & 0xffff;\n seed[1u] = state >> 16 & 0xffff;\n seed[2u] = state >> 8 & 0xffff;\n return result;\n}\n/*@\n requires pos: 0 < n;\n requires valid: \\valid(state + (0..2));\n assigns state[0..2];\n ensures result: 0 <= \\result < n;\n*/\nsize_type\nrandom_number(unsigned short* state, size_type n)\n{\n return my_lrand48(state) % n;\n}\n/*@\n requires \\valid(state + (0..2));\n assigns state[0..2];\n*/\nvoid\nrandom_init(unsigned short* state)\n{\n state[0] = 0x243f;\n state[1] = 0x6a88;\n state[2] = 0x85a3;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_16", "file_name": "16", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 0) {\n //@ assert m >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n /*@\n loop invariant 0 <= x <= n;\n loop invariant 0 <= m <= x;\n loop invariant m <= n;\n loop invariant (m < x) || (m >= x);\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 0) {\n //@ assert m >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_77", "file_name": "77", "input": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i <= y) {\n //@ assert i <= x;\n }\n}", "output": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n /*@\n loop invariant y <= x;\n loop invariant i <= x;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop invariant i <= y;\n loop invariant 0 <= i;\n loop assigns y;\n loop assigns x;\n loop assigns i;\n */\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i <= y) {\n //@ assert i <= x;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_98", "file_name": "98", "input": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 2;\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (i != j) {\n //@ assert y != 1;\n }\n}", "output": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 2;\n /*@\n loop invariant y == 2;\n loop invariant j == y*i;\n loop invariant j == i*y;\n loop invariant j == 2*i;\n loop invariant 0 <= i;\n loop assigns y,i,j;\n */\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (i != j) {\n //@ assert y != 1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Maximum_element_in_an_array", "file_name": "Maximum_element_in_an_array", "input": "#include\nint Max_in_Array(int arr[],int n)\n{\n int max=arr[0];\n for(int j=0;jmax)\n {\n max=arr[j];\n }\n }\n return max;\n}\nint main()\n{\nint n=5;\nint arr[]={50,44,33,2,88};\nint k=Max_in_Array(arr,n);\n//@ assert \\forall integer i; 0<=i k>=arr[i];\n}", "output": "#include\n/*@\n requires 0 \\result>=arr[i];\n*/\nint Max_in_Array(int arr[],int n)\n{\n int max=arr[0];\n /*@\n loop invariant \\forall integer i;\n 0<=i max>=arr[i];\n loop invariant 0<=j<=n;\n loop assigns j,max; \n loop variant n-j; \n */\n for(int j=0;jmax)\n {\n max=arr[j];\n }\n }\n return max;\n}\nint main()\n{\nint n=5;\nint arr[]={50,44,33,2,88};\nint k=Max_in_Array(arr,n);\n//@ assert \\forall integer i; 0<=i k>=arr[i];\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_25", "file_name": "25", "input": "/*@\nrequires (x == 10000);\n*/\nvoid foo(int x) {\n while ((x > 0)) {\n (x = (x - 1));\n }\n //@ assert (x == 0) ;\n}", "output": "/*@\nrequires (x == 10000);\n*/\nvoid foo(int x) {\n // loop body\n /*@\n loop invariant x <= 10000;\n loop invariant 0 <= x;\n loop assigns x;\n */\n while ((x > 0)) {\n (x = (x - 1));\n }\n // post-condition\n //@ assert (x == 0) ;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_add-ptr", "file_name": "add-ptr", "input": "#include \nint add(int* p, int* q, int* r){\n int result = *p + *q; \n *r = result;\n return result;\n}\nint main(){\n int a = 24 ;\n int b = 42 ;\n int res; \n int x;\n x = add(&a, &b, &res) ;\n //@ assert x == a + b ;\n //@ assert x == 66 ;\n x = add(&a, &a, &res) ;\n //@ assert x == a + a ;\n //@ assert x == 48 ;\n}", "output": "#include \n/*@\n requires \\valid_read(p) && \\valid_read(q) && \\valid(r); \n requires INT_MIN < *p < INT_MAX &&\n INT_MIN < *q < INT_MAX &&\n INT_MIN < *p + *q < INT_MAX;\n requires separate_r: \\separated(p, r) && \\separated(q, r); \n assigns *r; \n ensures correct_r: *r == \\old(*p) + \\old(*q); \n ensures *r == \\result; \n ensures no_other_effects: *p == \\old(*p) && *q == \\old(*q); \n*/\nint add(int* p, int* q, int* r){\n int result = *p + *q; \n *r = result;\n return result;\n}\nint main(){\n int a = 24 ;\n int b = 42 ;\n int res; \n int x;\n x = add(&a, &b, &res) ;\n //@ assert x == a + b ;\n //@ assert x == 66 ;\n x = add(&a, &a, &res) ;\n //@ assert x == a + a ;\n //@ assert x == 48 ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_43", "file_name": "43", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c == n) {\n //@ assert n > -1;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n-c;\n loop invariant n - c;\n loop invariant c >= 0 && c <= n;\n loop invariant c == n ==> n > -1;\n loop invariant 0 <= c <= n;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c == n) {\n //@ assert n > -1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nikunjjain02_Arrays_9", "file_name": "Arrays_9", "input": "#include\nvoid search_and_replace(int* array, size_t length, int old, int new) {\n\tfor(size_t i = 0;i < length; ++i) {\n\t\tif(array[i]==old) array[i]=new;\n\t}\n}\nvoid main() {\n\tint a[] = {1, 2, 4, 5};\n\tsearch_and_replace(a, 4, 2, 3);\n\t//@ assert a[0] == 1 && a[1] == 3 && a[2] == 4 && a[3] == 5;\n}\t", "output": "#include\n/*@\n\trequires \\valid(array+(0..length-1));\n\tassigns array[0..length-1];\n\tensures \\forall size_t i;0<=iarray[i]==new;\n\tensures \\forall size_t i;0<=iarray[i]==\\old(array[i]);\n*/\nvoid search_and_replace(int* array, size_t length, int old, int new) {\n\t/*@\n\t\tloop invariant 0<=i<=length;\n\t\tloop invariant \\forall size_t j;0<=jarray[j]==new;\n\t\tloop invariant \\forall size_t j;0<=jarray[j]==\\at(array[j],Pre);\n\t\tloop invariant \\forall size_t j;i<=jarray[j]==\\at(array[j],Pre);\n\t\tloop assigns i,array[0..length-1];\n\t\tloop variant length-i;\n\t*/\n\tfor(size_t i = 0;i < length; ++i) {\n\t\tif(array[i]==old) array[i]=new;\n\t}\n}\nvoid main() {\n\tint a[] = {1, 2, 4, 5};\n\tsearch_and_replace(a, 4, 2, 3);\n\t//@ assert a[0] == 1 && a[1] == 3 && a[2] == 4 && a[3] == 5;\n}\t", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_103", "file_name": "103", "input": "int main() {\n int x = 0;\n while (x < 100) {\n x = x + 1;\n }\n //@ assert x == 100;\n}", "output": "int main() {\n int x = 0;\n /*@\n loop invariant x <= 100;\n loop invariant 0 <= x;\n loop assigns x;\n */\n while (x < 100) {\n x = x + 1;\n }\n //@ assert x == 100;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_97", "file_name": "97", "input": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 2;\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (y == 1) {\n //@ assert i == j;\n }\n}", "output": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 2;\n /*@\n loop invariant y == 2;\n loop invariant j == i*2;\n loop invariant j == i * 2;\n loop invariant j == 2*i;\n loop invariant 0 <= j;\n loop invariant 0 <= i;\n loop assigns y,i,j;\n */\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (y == 1) {\n //@ assert i == j;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_108", "file_name": "108", "input": "/*@\nrequires a <= m;\n*/\nvoid foo(int a, int m, int c) {\n int j = 0;\n int k = 0;\n while (k < c) {\n if(m < a) {\n m = a;\n }\n k = k + 1;\n }\n //@ assert a <= m;\n}", "output": "/*@\nrequires a <= m;\n*/\nvoid foo(int a, int m, int c) {\n int j = 0;\n int k = 0;\n /*@\n loop invariant a <= m;\n loop invariant 0 <= k;\n loop invariant (m < a ==> m == a);\n loop assigns m,k,a;\n */\n while (k < c) {\n if(m < a) {\n m = a;\n }\n k = k + 1;\n }\n //@ assert a <= m;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_11", "file_name": "11", "input": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (x == 20) {\n //@ assert y != 0;\n }\n}", "output": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n /*@\n loop invariant x != 20 || y != 0;\n loop invariant 0 <= y + 10;\n loop invariant 0 <= x + 10;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (x == 20) {\n //@ assert y != 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_max-ptr", "file_name": "max-ptr", "input": "#include \n#include \nvoid max_ptr(int* a, int* b) {\n if(*a < *b) {\n int tmp = *b ;\n *b = *a ;\n *a = tmp; \n }\n}\nextern int h ;\nint main() {\n h = 42 ;\n int a = 24 ;\n int b = 42 ;\n max_ptr(&a, &b) ;\n //@ assert a == 42 ;\n //@ assert b == 24 ;\n}", "output": "#include \n#include \n/*@ requires \\valid(a) && \\valid(b); \n assigns *a, *b; \n ensures a_in_nums: *a \\in { \\old(*a), \\old(*b) } ; \n ensures b_in_nums: *b \\in { \\old(*a), \\old(*b) } ; \n ensures a_is_max: *a >= \\old(*a) && *a >= \\old(*b); \n ensures b_is_min: *b <= \\old(*a) && *b <= \\old(*b); \n behavior a_max:\n assumes *a > *b; \n ensures *a == \\old(*a) && *b == \\old(*b); \n behavior b_max: \n assumes *b > *a;\n ensures *a == \\old(*b) && *b == \\old(*a); \n behavior equals: \n assumes *a == *b; \n ensures *a == \\old(*a) && *b == \\old(*b); \n complete behaviors; \n disjoint behaviors; \n*/\nvoid max_ptr(int* a, int* b) {\n if(*a < *b) {\n int tmp = *b ;\n *b = *a ;\n *a = tmp; \n }\n}\nextern int h ;\nint main() {\n h = 42 ;\n int a = 24 ;\n int b = 42 ;\n max_ptr(&a, &b) ;\n //@ assert a == 42 ;\n //@ assert b == 24 ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Compute the factorial of a given no. with precondition and postcondition", "file_name": "Compute the factorial of a given no. with precondition and postcondition", "input": "#include\n/*@\nlogic integer fact(integer n)=(n<1)? 1:n*fact(n-1);\n*/\nint fact(int n)\n{\nif(n<2)\nreturn 1;\nint f=1;\nint i;\nfor(i=1;i<=n;i++)\n{\nf=f*i;\n}\nreturn f;\n}\nint main()\n{\nint k=fact(5);\n//@ assert k==120;\n}", "output": "#include\n/*@\nlogic integer fact(integer n)=(n<1)? 1:n*fact(n-1);\n*/\n/*@ \nassigns \\nothing;\nensures \\result==fact(n);\n*/\nint fact(int n)\n{\nif(n<2)\nreturn 1;\nint f=1;\nint i;\n/*@\nloop invariant 1<=i<=n+1;\nloop invariant f==fact(i-1);\nloop assigns i,f;\nloop variant n-i;\n*/\nfor(i=1;i<=n;i++)\n{\nf=f*i;\n}\nreturn f;\n}\nint main()\n{\nint k=fact(5);\n//@ assert k==120;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "ranilakshmi_last_angle", "file_name": "last_angle", "input": "int last_angle(int first,int second){\n if(first < 0 || first > 180 || second < 0 || second > 180 || first + second > 180){\n return -1;\n }\n return 180 - first - second;\n}\nint main(){\n int first = 60;\n int second = 90;\n int result = last_angle(first,second);\n //@ assert result == 30;\n\n first = 100;\n second = 100;\n result = last_angle(first,second);\n //@ assert result == -1;\n return 0;\n}", "output": "/*@\n behavior error:\n assumes first < 0 || first > 180 || second < 0 || second > 180 || first + second > 180;\n ensures \\result == -1;\n behavior valid:\n assumes first >= 0 && first <= 180 && second >= 0 && second <= 180 && first + second <= 180;\n ensures \\result == 180 - first - second;\n complete behaviors;\n disjoint behaviors;\n*/\nint last_angle(int first,int second){\n if(first < 0 || first > 180 || second < 0 || second > 180 || first + second > 180){\n return -1;\n }\n return 180 - first - second;\n}\nint main(){\n int first = 60;\n int second = 90;\n int result = last_angle(first,second);\n //@ assert result == 30;\n\n first = 100;\n second = 100;\n result = last_angle(first,second);\n //@ assert result == -1;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_79", "file_name": "79", "input": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i >= x) {\n if (0 > i) {\n //@ assert i >= y;\n }\n }\n}", "output": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n /*@\n loop invariant i <= y;\n loop invariant 0 <= i;\n loop assigns x,y,i;\n */\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i >= x) {\n if (0 > i) {\n //@ assert i >= y;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Sum of first n numbers using ‘while’ loop with precondition and postcondition", "file_name": "Sum of first n numbers using ‘while’ loop with precondition and postcondition", "input": "#include\n#include\nint add(int n)\n{\nint i=1;\nint s=0;\nwhile(i<=n)\n{\ns=s+i;\ni++;\n}\nreturn s;\n}\nint main()\n{\nint k;\nk=add(5);\n//@ assert k==15;\n}", "output": "#include\n#include\n/*@\nrequires n>0;\nensures \\result==n*(n+1)/2;\n*/\nint add(int n)\n{\nint i=1;\nint s=0;\n/*@\nloop invariant s==(i-1)*i/2;\nloop invariant 1<=i<=n+1;\nloop assigns i,s;\nloop variant n-i;\n*/\nwhile(i<=n)\n{\ns=s+i;\ni++;\n}\nreturn s;\n}\nint main()\n{\nint k;\nk=add(5);\n//@ assert k==15;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_2", "file_name": "BL.EN.U4CSE21176_2", "input": "#include\nint foo(int a,int b){\nif(a>=0){\na++;\n}\nelse{\na+=b;\n}\nreturn a;\n}\nint main(){\nint x=-99;\nint y=100;\nint r=foo(x,y);\n//@assert x==-99 && y==100 && r==1;\n}", "output": "#include\n/*@\nrequires INT_MIN<=a=0;\n ensures \\result == a + 1;\nbehavior a_neg:\n assumes a < 0;\n ensures \\result == a + b;\ndisjoint behaviors;\ncomplete behaviors;\n*/\nint foo(int a,int b){\nif(a>=0){\na++;\n}\nelse{\na+=b;\n}\nreturn a;\n}\nint main(){\nint x=-99;\nint y=100;\nint r=foo(x,y);\n//@assert x==-99 && y==100 && r==1;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_sum of number divisble by 3", "file_name": "sum of number divisble by 3", "input": "#include\nint dsum(int n)\n{\nint i=1;\nint sum=0;\nfor(i=1;i<=n;i++)\n{\nsum=sum+3*i;\n}\nreturn sum;\n}\nint main()\n{\nint k=dsum(3);\n//@ assert k==18;\n}", "output": "#include\n/*@ \nrequires n>0;\nensures \\result==(3*(n*(n+1)/2));\n*/\nint dsum(int n)\n{\nint i=1;\nint sum=0;\n/*@\nloop invariant 1<=i<=n+1;\nloop invariant sum==(3*((i-1)*i/2));\nloop assigns sum,i;\nloop variant n-i;\n*/\nfor(i=1;i<=n;i++)\n{\nsum=sum+3*i;\n}\nreturn sum;\n}\nint main()\n{\nint k=dsum(3);\n//@ assert k==18;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "loops_3", "file_name": "3", "input": "#include \nint func(int c) {\n int x = c;\n int y = 0;\n while(x > 0) {\n x = x - 1;\n y = y + 1;\n }\n return y;\n}\nvoid main() {\n int t = func(5);\n //@ assert t == 5;\n}", "output": "#include \n/*@\n requires c > 0;\n ensures \\result == c;\n assigns \\nothing;\n*/\nint func(int c) {\n int x = c;\n int y = 0;\n /*@\n loop invariant c == x + y && x >= 0;\n loop assigns x, y;\n */\n while(x > 0) {\n x = x - 1;\n y = y + 1;\n }\n return y;\n}\nvoid main() {\n int t = func(5);\n //@ assert t == 5;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_acsl-examples_04_max_seq", "file_name": "04_max_seq", "input": "/*@ requires n >= 0;\n requires \\valid(a + (0..n-1));\n assigns \\nothing;\n behavior empty:\n assumes n == 0;\n ensures \\result == 0;\n behavior not_empty:\n assumes 0 < n;\n ensures 0 <= \\result < n;\n ensures \\forall integer i; 0 <= i < n ==> a[i] <= a[\\result];\n ensures \\forall integer i; 0 <= i < \\result ==> a[i] < a[\\result];\n complete behaviors;\n disjoint behaviors;\n*/\nint max_element(int* a, int n)\n{\n if (n == 0) {\n return 0;\n }\n int max = 0;\n /*@\n loop invariant 0 <= i <= n;\n loop invariant 0 <= max < n;\n loop invariant \\forall integer k; 0 <= k < i ==> a[k] <= a[max];\n loop invariant \\forall integer k; 0 <= k < max ==> a[k] < a[max];\n loop assigns max, i;\n loop variant n-i;\n */\n for (int i = 1; i < n; i++) {\n if (a[max] < a[i]) {\n max = i;\n }\n }\n return max;\n}\nint max_seq(int* p, int n)\n{\n return p[max_element(p, n)];\n}\nint main()\n{\n int a[] = {1, 2, 3, 4, 5};\n int n = 5;\n int max_value = max_seq(a, n);\n //@ assert max_value == 5;\n}", "output": "/*@ requires n >= 0;\n requires \\valid(a + (0..n-1));\n assigns \\nothing;\n behavior empty:\n assumes n == 0;\n ensures \\result == 0;\n behavior not_empty:\n assumes 0 < n;\n ensures 0 <= \\result < n;\n ensures \\forall integer i; 0 <= i < n ==> a[i] <= a[\\result];\n ensures \\forall integer i; 0 <= i < \\result ==> a[i] < a[\\result];\n complete behaviors;\n disjoint behaviors;\n*/\nint max_element(int* a, int n)\n{\n if (n == 0) {\n return 0;\n }\n int max = 0;\n /*@\n loop invariant 0 <= i <= n;\n loop invariant 0 <= max < n;\n loop invariant \\forall integer k; 0 <= k < i ==> a[k] <= a[max];\n loop invariant \\forall integer k; 0 <= k < max ==> a[k] < a[max];\n loop assigns max, i;\n loop variant n-i;\n */\n for (int i = 1; i < n; i++) {\n if (a[max] < a[i]) {\n max = i;\n }\n }\n return max;\n}\n/*@ requires n > 0;\n requires \\valid(p + (0..n-1));\n assigns \\nothing;\n ensures \\forall integer i; 0 <= i <= n-1 ==> \\result >= p[i];\n ensures \\exists integer e; 0 <= e <= n-1 && \\result == p[e];\n*/\nint max_seq(int* p, int n)\n{\n return p[max_element(p, n)];\n}\nint main()\n{\n int a[] = {1, 2, 3, 4, 5};\n int n = 5;\n int max_value = max_seq(a, n);\n //@ assert max_value == 5;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_69", "file_name": "69", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int x = 1;\n int y = 0;\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int x = 1;\n int y = 0;\n /*@\n loop invariant y <= n - 1;\n loop invariant 0 <= y;\n loop assigns n;\n loop invariant x <= n+1;\n loop invariant x <= n + 1;\n loop invariant 1 <= x;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "max_element", "file_name": "max_element", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nsize_type\nmax_element(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type max = 0u;\n for (size_type i = 1u; i < n; i++) {\n if (a[max] < a[i]) {\n max = i;\n }\n }\n //@ assert \\forall integer i; 0 <= i < n ==> a[i] <= a[max];\n return max;\n }\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior empty:\n assumes n == 0;\n assigns \\nothing;\n ensures result: \\result == 0;\n behavior not_empty:\n assumes 0 < n;\n assigns \\nothing;\n ensures result: 0 <= \\result < n;\n ensures upper: \\forall integer i; 0 <= i < n ==> a[i] <= a[\\result];\n ensures first: \\forall integer i; 0 <= i < \\result ==> a[i] < a[\\result];\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nmax_element(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type max = 0u;\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant max: 0 <= max < n;\n loop invariant upper: \\forall integer k; 0 <= k < i ==> a[k] <= a[max];\n loop invariant first: \\forall integer k; 0 <= k < max ==> a[k] < a[max];\n loop assigns max, i;\n loop variant n-i;\n */\n for (size_type i = 1u; i < n; i++) {\n if (a[max] < a[i]) {\n max = i;\n }\n }\n //@ assert \\forall integer i; 0 <= i < n ==> a[i] <= a[max];\n return max;\n }\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_92", "file_name": "92", "input": "int main(){\n int x = 0;\n int y = 0;\n while(y >= 0){\n y = y + x;\n }\n //@ assert y >= 0;\n}", "output": "int main(){\n int x = 0;\n int y = 0;\n /*@\n loop invariant x == 0;\n loop invariant \\forall integer k; 0<= k < x ==> y >= 0;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while(y >= 0){\n y = y + x;\n }\n //@ assert y >= 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_128", "file_name": "128", "input": "void foo(int y) {\n int x = 1;\n while (x < y) {\n x = x + x;\n }\n //@ assert x >= 1;\n}", "output": "void foo(int y) {\n int x = 1;\n /*@\n loop invariant 1 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x < y) {\n x = x + x;\n }\n //@ assert x >= 1;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "immutable_array_sample", "file_name": "sample", "input": "int fun(int x, int y) {\n int r = x;\n int d = 0;\n while (r >= y) {\n printf(\"r = %d d = %d y = %d x = %d\\n\", r, d, y, x);\n r = r - y;\n d = d + 1;\n }\n //@ assert r + d*y == x;\n return d;\n}", "output": "int fun(int x, int y) {\n int r = x;\n int d = 0;\n /*@\n loop invariant r + d*y == x;\n */\n while (r >= y) {\n printf(\"r = %d d = %d y = %d x = %d\\n\", r, d, y, x);\n r = r - y;\n d = d + 1;\n }\n //@ assert r + d*y == x;\n return d;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "search", "file_name": "search", "input": "int arraysearch(int* a, int x, int n) { \n for (int p = 0; p < n; p++) {\n if (x == a[p]) \n //@ assert \\exists integer k; 0 <= k <= p && x == a[k];\n return 1;\n }\n return 0;\n} ", "output": "/*@ \nrequires n > 0;\nrequires \\valid_read(a + (0..n-1));\nassigns \\nothing;\nbehavior present:\n assumes \\exists integer k; 0 <= k < n && x == a[k];\n ensures \\result == 1;\nbehavior not_present:\n assumes \\forall integer k; 0 <= k < n ==> x != a[k];\n ensures \\result == 0;\ndisjoint behaviors;\ncomplete behaviors;\n*/\nint arraysearch(int* a, int x, int n) { \n /*@ \n loop invariant 0 <= p <= n;\n loop invariant \\forall integer k; 0 <= k < p ==> x != a[k];\n loop assigns p;\n */\n for (int p = 0; p < n; p++) {\n if (x == a[p]) \n //@ assert \\exists integer k; 0 <= k <= p && x == a[k];\n return 1;\n }\n return 0;\n} ", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_114", "file_name": "114", "input": "int main() {\n int sn = 0;\n int x = 0;\n while (unknown()) {\n x = x + 1;\n sn = sn + 1;\n }\n if(sn != x) {\n //@ assert sn == -1;\n }\n}", "output": "int main() {\n int sn = 0;\n int x = 0;\n /*@\n loop invariant x == sn;\n loop invariant x <= sn;\n loop invariant sn == x;\n loop invariant sn <= x;\n loop invariant 0 <= x;\n loop invariant 0 <= sn;\n loop assigns x;\n loop assigns sn;\n */\n while (unknown()) {\n x = x + 1;\n sn = sn + 1;\n }\n if(sn != x) {\n //@ assert sn == -1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "axiom_size_of_push", "file_name": "axiom_size_of_push", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid stack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type stack_size(const Stack* s);\nsize_type axiom_size_of_push(Stack* s, value_type v)\n{\n stack_push(s, v);\n //@ assert StackSize(s) == StackSize{Pre}(s) + 1;\n return stack_size(s);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires not_full: !StackFull(s);\n assigns s->size, s->obj[s->size];\n ensures size: \\result == StackSize{Old}(s) + 1;\n ensures valid: StackInvariant(s);\n*/\nsize_type\naxiom_size_of_push(Stack* s, value_type v)\n{\n stack_push(s, v);\n //@ assert StackSize(s) == StackSize{Pre}(s) + 1;\n return stack_size(s);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "iota", "file_name": "iota", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic IotaGenerate\n {\n predicate\n IotaGenerate(value_type* a, integer n, value_type v) =\n \\forall integer i; 0 <= i < n ==> a[i] == v+i;\n }\n*/\nvoid\niota(value_type* a, size_type n, value_type v)\n{\n for (size_type i = 0u; i < n; ++i) {\n a[i] = v++;\n }\n}\nint main(){\n value_type a[10];\n iota(a, 10, 1);\n //@ assert \\forall integer i; 0 <= i < 10 ==> a[i] == i + 1;\n return 0;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic IotaGenerate\n {\n predicate\n IotaGenerate(value_type* a, integer n, value_type v) =\n \\forall integer i; 0 <= i < n ==> a[i] == v+i;\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n requires limit: v + n <= VALUE_TYPE_MAX;\n assigns a[0..n-1];\n ensures increment: IotaGenerate(a, n, v);\n*/\nvoid\niota(value_type* a, size_type n, value_type v)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant limit: v == \\at(v, Pre) + i;\n loop invariant increment: IotaGenerate(a, i, \\at(v, Pre));\n loop assigns i, v, a[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n a[i] = v++;\n }\n}\nint main(){\n value_type a[10];\n iota(a, 10, 1);\n //@ assert \\forall integer i; 0 <= i < 10 ==> a[i] == i + 1;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "pointers_incr_a_by_b", "file_name": "incr_a_by_b", "input": "int incr_a_by_b(int* a, int const* b){\n *a += *b;\n return *a;\n}\nvoid main() {\n int a = 10;\n int b = 20;\n incr_a_by_b(&a, &b);\n //@ assert a == 30;\n //@ assert b == 20;\n}", "output": "/*@\n requires \\valid(a) && \\valid_read(b);\n requires \\separated(a, b);\n assigns *a;\n ensures *a == \\old(*a) + *b;\n ensures *b == \\old(*b);\n*/\nint incr_a_by_b(int* a, int const* b){\n *a += *b;\n return *a;\n}\nvoid main() {\n int a = 10;\n int b = 20;\n incr_a_by_b(&a, &b);\n //@ assert a == 30;\n //@ assert b == 20;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_8", "file_name": "BL.EN.U4CSE21176_8", "input": "#include\ndouble Sqrt(double x){\t\n\treturn sqrt(x);\n}\nint main(){\n\tdouble x = 9;\n\tdouble y;\n\ty = Sqrt(x);\n\t//@assert y == sqrt(x); \n\treturn 0;\n}", "output": "#include\n/*@\n\trequires \\is_finite(x);\n\trequires x >= -0.;\n\tensures \\result >= -0.;\n\tensures \\is_finite(\\result);\n\tensures \\result == sqrt(x);\n\tassigns \\result;\n*/\ndouble Sqrt(double x){\t\n\treturn sqrt(x);\n}\nint main(){\n\tdouble x = 9;\n\tdouble y;\n\ty = Sqrt(x);\n\t//@assert y == sqrt(x); \n\treturn 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "max_element2", "file_name": "max_element2", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\nsize_type\nmax_element2(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type max = 0u;\n for (size_type i = 0u; i < n; i++) {\n if (a[max] < a[i]) {\n max = i;\n }\n }\n //@ assert MaxElement(a, n, max);\n return max;\n }\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior empty:\n assumes n == 0;\n assigns \\nothing;\n ensures result: \\result == 0;\n behavior not_empty:\n assumes 0 < n;\n assigns \\nothing;\n ensures result: 0 <= \\result < n;\n ensures max: MaxElement(a, n, \\result);\n ensures first: StrictUpperBound(a, \\result, a[\\result]);\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nmax_element2(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type max = 0u;\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant max: 0 <= max < n;\n loop invariant upper: UpperBound(a, i, a[max]);\n loop invariant first: StrictUpperBound(a, max, a[max]);\n loop assigns max, i;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; i++) {\n if (a[max] < a[i]) {\n max = i;\n }\n }\n //@ assert MaxElement(a, n, max);\n return max;\n }\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_58", "file_name": "58", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c != n) {\n //@ assert c >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant 0 <= c;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c != n) {\n //@ assert c >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "count2", "file_name": "count2", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic UnchangedLemmas\n {\n lemma Unchanged_Shrink{K,L}:\n \\forall value_type *a, integer m, n, p, q;\n m <= p <= q <= n ==>\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{K,L}(a, p, q);\n lemma Unchanged_Extend{K,L}:\n \\forall value_type *a, integer n;\n Unchanged{K,L}(a, n) ==>\n \\at(a[n],K) == \\at(a[n],L) ==>\n Unchanged{K,L}(a, n+1);\n lemma Unchanged_Symmetric{K,L}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,K}(a, m, n);\n lemma Unchanged_Transitive{K,L,M}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,M}(a, m, n) ==>\n Unchanged{K,M}(a, m, n);\n }\n*/\n/*@\n inductive CountInd{L}(value_type *a, integer n, value_type v, integer sum)\n {\n case Nil{L}:\n \\forall value_type *a, v, integer n;\n n <= 0 ==> CountInd{L}(a, n, v, 0);\n case Hit{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n && a[n-1] == v && CountInd{L}(a, n-1, v, sum) ==>\n CountInd{L}(a, n, v, sum + 1);\n case Miss{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n && a[n-1] != v && CountInd{L}(a, n-1, v, sum) ==>\n CountInd{L}(a, n, v, sum);\n }\n*/\n/*@\n axiomatic CountIndImplicit\n {\n lemma CountInd_Empty{L}:\n \\forall value_type *a, v, integer n;\n n <= 0 ==> CountInd(a, n, v, 0);\n lemma CountInd_Hit{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n ==>\n a[n-1] == v ==>\n CountInd(a, n-1, v, sum) ==>\n CountInd(a, n, v, sum+1);\n lemma CountInd_Miss{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n ==>\n a[n-1] != v ==>\n CountInd(a, n-1, v, sum) ==>\n CountInd(a, n, v, sum);\n }\n*/\n/*@\n axiomatic Count\n {\n logic integer\n Count(value_type* a, integer m, integer n, value_type v) =\n n <= m ? 0 : Count(a, m, n-1, v) + (a[n-1] == v ? 1 : 0);\n logic integer\n Count(value_type* a, integer n, value_type v) = Count(a, 0, n, v);\n lemma Count_Empty:\n \\forall value_type *a, v, integer m, n;\n n <= m ==> Count(a, m, n, v) == 0;\n lemma Count_Hit:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] == v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v) + 1;\n lemma Count_Miss:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] != v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v);\n lemma Count_One:\n \\forall value_type *a, v, integer m, n;\n m <= n ==> Count(a, m, n+1, v) == Count(a, m, n, v) + Count(a, n, n+1, v);\n lemma Count_Single{K,L}:\n \\forall value_type *a, *b, v, integer m, n;\n \\at(a[m],K) == \\at(b[n],L) ==>\n Count{K}(a, m, m+1, v) == Count{L}(b, n, n+1, v);\n lemma Count_Single_Bounds:\n \\forall value_type *a, v, integer n;\n 0 <= Count(a, n, n+1, v) <= 1;\n lemma Count_Single_Shift:\n \\forall value_type *a, v, integer n;\n 0 <= n ==> Count(a+n, 0, 1, v) == Count(a, n, n+1, v);\n }\n*/\n/*@\n axiomatic CountIndLemmas\n {\n lemma CountInd_Inverse:\n \\forall value_type *a, v, integer n, sum;\n CountInd(a, n, v, sum) ==>\n (n <= 0 && sum == 0) ||\n (0 < n && a[n-1] != v && CountInd(a, n-1, v, sum)) ||\n (0 < n && a[n-1] == v && CountInd(a, n-1, v, sum-1));\n }\n*/\nsize_type\ncount2(const value_type* a, size_type n, value_type v)\n{\n size_type counted = 0u;\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] == v) {\n counted++;\n //@ assert count: CountInd(a, i+1, v, counted);\n }\n }\n return counted;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic UnchangedLemmas\n {\n lemma Unchanged_Shrink{K,L}:\n \\forall value_type *a, integer m, n, p, q;\n m <= p <= q <= n ==>\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{K,L}(a, p, q);\n lemma Unchanged_Extend{K,L}:\n \\forall value_type *a, integer n;\n Unchanged{K,L}(a, n) ==>\n \\at(a[n],K) == \\at(a[n],L) ==>\n Unchanged{K,L}(a, n+1);\n lemma Unchanged_Symmetric{K,L}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,K}(a, m, n);\n lemma Unchanged_Transitive{K,L,M}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,M}(a, m, n) ==>\n Unchanged{K,M}(a, m, n);\n }\n*/\n/*@\n inductive CountInd{L}(value_type *a, integer n, value_type v, integer sum)\n {\n case Nil{L}:\n \\forall value_type *a, v, integer n;\n n <= 0 ==> CountInd{L}(a, n, v, 0);\n case Hit{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n && a[n-1] == v && CountInd{L}(a, n-1, v, sum) ==>\n CountInd{L}(a, n, v, sum + 1);\n case Miss{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n && a[n-1] != v && CountInd{L}(a, n-1, v, sum) ==>\n CountInd{L}(a, n, v, sum);\n }\n*/\n/*@\n axiomatic CountIndImplicit\n {\n lemma CountInd_Empty{L}:\n \\forall value_type *a, v, integer n;\n n <= 0 ==> CountInd(a, n, v, 0);\n lemma CountInd_Hit{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n ==>\n a[n-1] == v ==>\n CountInd(a, n-1, v, sum) ==>\n CountInd(a, n, v, sum+1);\n lemma CountInd_Miss{L}:\n \\forall value_type *a, v, integer n, sum;\n 0 < n ==>\n a[n-1] != v ==>\n CountInd(a, n-1, v, sum) ==>\n CountInd(a, n, v, sum);\n }\n*/\n/*@\n axiomatic Count\n {\n logic integer\n Count(value_type* a, integer m, integer n, value_type v) =\n n <= m ? 0 : Count(a, m, n-1, v) + (a[n-1] == v ? 1 : 0);\n logic integer\n Count(value_type* a, integer n, value_type v) = Count(a, 0, n, v);\n lemma Count_Empty:\n \\forall value_type *a, v, integer m, n;\n n <= m ==> Count(a, m, n, v) == 0;\n lemma Count_Hit:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] == v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v) + 1;\n lemma Count_Miss:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] != v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v);\n lemma Count_One:\n \\forall value_type *a, v, integer m, n;\n m <= n ==> Count(a, m, n+1, v) == Count(a, m, n, v) + Count(a, n, n+1, v);\n lemma Count_Single{K,L}:\n \\forall value_type *a, *b, v, integer m, n;\n \\at(a[m],K) == \\at(b[n],L) ==>\n Count{K}(a, m, m+1, v) == Count{L}(b, n, n+1, v);\n lemma Count_Single_Bounds:\n \\forall value_type *a, v, integer n;\n 0 <= Count(a, n, n+1, v) <= 1;\n lemma Count_Single_Shift:\n \\forall value_type *a, v, integer n;\n 0 <= n ==> Count(a+n, 0, 1, v) == Count(a, n, n+1, v);\n }\n*/\n/*@\n axiomatic CountIndLemmas\n {\n lemma CountInd_Inverse:\n \\forall value_type *a, v, integer n, sum;\n CountInd(a, n, v, sum) ==>\n (n <= 0 && sum == 0) ||\n (0 < n && a[n-1] != v && CountInd(a, n-1, v, sum)) ||\n (0 < n && a[n-1] == v && CountInd(a, n-1, v, sum-1));\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures bound: 0 <= \\result <= n;\n ensures count: CountInd(a, n, v, \\result);\n*/\nsize_type\ncount2(const value_type* a, size_type n, value_type v)\n{\n size_type counted = 0u;\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant bound: 0 <= counted <= i;\n loop invariant count: CountInd(a, i, v, counted);\n loop assigns i, counted;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] == v) {\n counted++;\n //@ assert count: CountInd(a, i+1, v, counted);\n }\n }\n return counted;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_1", "file_name": "1", "input": "void main() {\n int x;\n int y;\n x = 1;\n y = 0;\n while (y < 100000) {\n x = x + y;\n y = y + 1;\n }\n //@ assert (x >= y) ;\n}", "output": "void main() {\n int x;\n int y;\n x = 1;\n y = 0;\n /*@\n loop invariant y <= x;\n loop invariant 0 <= y <= 100000;\n loop invariant 1 <= x;\n loop assigns y,x;\n */\n while (y < 100000) {\n x = x + y;\n y = y + 1;\n }\n //@ assert (x >= y) ;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "stack_pop_wd", "file_name": "stack_pop_wd", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\nvoid\nstack_pop_wd(Stack* s, Stack* t)\n{\n //@ assert StackEqual{Here,Here}(s, t);\n stack_pop(s);\n stack_pop(t);\n //@ assert StackEqual{Here,Here}(s, t);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires valid: \\valid(t) && StackInvariant(t);\n requires equal: StackEqual{Here,Here}(s, t);\n requires sep: StackSeparated(s, t);\n assigns s->size;\n assigns t->size;\n ensures valid: StackInvariant(s);\n ensures valid: StackInvariant(t);\n ensures equal: StackEqual{Here,Here}(s, t);\n*/\nvoid\nstack_pop_wd(Stack* s, Stack* t)\n{\n //@ assert StackEqual{Here,Here}(s, t);\n stack_pop(s);\n stack_pop(t);\n //@ assert StackEqual{Here,Here}(s, t);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_add", "file_name": "add", "input": "#include \nint add(int x, int y) {\n return x+y;\n}\nvoid foo() {\n int a = add(1, 43);\n //@ assert a == 44;\n int b = add(INT_MAX, INT_MAX);\n}", "output": "#include \n/*@\n requires x >= INT_MIN && y >= INT_MIN;\n ensures \\result == x+y;\n*/\nint add(int x, int y) {\n return x+y;\n}\nvoid foo() {\n int a = add(1, 43);\n //@ assert a == 44;\n int b = add(INT_MAX, INT_MAX);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "find2", "file_name": "find2", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic SomeNone\n {\n predicate\n SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] == v;\n predicate\n SomeEqual{A}(value_type* a, integer n, value_type v) =\n SomeEqual(a, 0, n, v);\n predicate\n NoneEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] != v;\n predicate\n NoneEqual(value_type* a, integer n, value_type v) =\n NoneEqual(a, 0, n, v);\n lemma NotSomeEqual_NoneEqual:\n \\forall value_type *a, v, integer m, n;\n !SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);\n lemma NoneEqual_NotSomeEqual:\n \\forall value_type *a, v, integer m, n;\n NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);\n }\n*/\nsize_type\nfind2(const value_type* a, size_type n, value_type v)\n{\n for (size_type i = 0u; i < n; i++) {\n if (a[i] == v) {\n //@ assert SomeEqual(a, i+1, v);\n return i;\n }\n }\n //@ assert NoneEqual(a, n, v);\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic SomeNone\n {\n predicate\n SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] == v;\n predicate\n SomeEqual{A}(value_type* a, integer n, value_type v) =\n SomeEqual(a, 0, n, v);\n predicate\n NoneEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] != v;\n predicate\n NoneEqual(value_type* a, integer n, value_type v) =\n NoneEqual(a, 0, n, v);\n lemma NotSomeEqual_NoneEqual:\n \\forall value_type *a, v, integer m, n;\n !SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);\n lemma NoneEqual_NotSomeEqual:\n \\forall value_type *a, v, integer m, n;\n NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior some:\n assumes SomeEqual(a, n, v);\n assigns \\nothing;\n ensures bound: 0 <= \\result < n;\n ensures result: a[\\result] == v;\n ensures first: NoneEqual(a, \\result, v);\n behavior none:\n assumes NoneEqual(a, n, v);\n assigns \\nothing;\n ensures result: \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nfind2(const value_type* a, size_type n, value_type v)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant not_found: NoneEqual(a, i, v);\n loop assigns i;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; i++) {\n if (a[i] == v) {\n //@ assert SomeEqual(a, i+1, v);\n return i;\n }\n }\n //@ assert NoneEqual(a, n, v);\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_78", "file_name": "78", "input": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i < y) {\n //@ assert 0 <= i;\n }\n}", "output": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n /*@\n loop invariant i <= y;\n loop invariant 0 <= i;\n loop assigns i;\n */\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i < y) {\n //@ assert 0 <= i;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_88", "file_name": "88", "input": "void foo(int x) {\n int lock = 0;\n int y = x + 1;\n while (x != y) {\n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1;\n }\n }\n //@ assert lock == 1;\n}", "output": "void foo(int x) {\n int lock = 0;\n int y = x + 1;\n /*@\n loop invariant y <= x || x <= y;\n loop invariant x <= y;\n loop invariant x != y || x != y + 1;\n loop invariant lock == 1 || lock != 1;\n loop invariant lock == 1 ==> x == y;\n loop invariant lock == 0 ==> y == x + 1;\n loop invariant lock == 0 ==> x != y;\n loop invariant x == y || x == y - 1;\n loop invariant x == y || x != y;\n loop invariant lock == 1 || lock == 0;\n loop invariant lock == 0 || lock == 1;\n loop invariant lock == 0 ==> lock != 1;\n loop assigns x,y,lock;\n */\n while (x != y) {\n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1;\n }\n }\n //@ assert lock == 1;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "replace_copy", "file_name": "replace_copy", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Replace\n {\n predicate\n Replace{K,L}(value_type* a, integer n, value_type* b,\n value_type v, value_type w) =\n \\forall integer i; 0 <= i < n ==>\n \\let ai = \\at(a[i],K);\n \\let bi = \\at(b[i],L);\n (ai == v ==> bi == w) && (ai != v ==> bi == ai) ;\n predicate\n Replace{K,L}(value_type* a, integer n, value_type v, value_type w) =\n Replace{K,L}(a, n, a, v, w);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\nsize_type\nreplace_copy(const value_type* a, size_type n, value_type* b, value_type v,\n value_type w)\n{\n for (size_type i = 0u; i < n; ++i) {\n b[i] = (a[i] == v ? w : a[i]);\n }\n //@ assert Replace{Pre,Here}(a, n, b, v, w);\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Replace\n {\n predicate\n Replace{K,L}(value_type* a, integer n, value_type* b,\n value_type v, value_type w) =\n \\forall integer i; 0 <= i < n ==>\n \\let ai = \\at(a[i],K);\n \\let bi = \\at(b[i],L);\n (ai == v ==> bi == w) && (ai != v ==> bi == ai) ;\n predicate\n Replace{K,L}(value_type* a, integer n, value_type v, value_type w) =\n Replace{K,L}(a, n, a, v, w);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a + (0..n-1), b + (0..n-1));\n assigns b[0..n-1];\n ensures result: \\result == n;\n ensures replace: Replace{Old,Here}(a, n, b, v, w);\n ensures unchanged: Unchanged{Old,Here}(a, n);\n*/\nsize_type\nreplace_copy(const value_type* a, size_type n, value_type* b, value_type v,\n value_type w)\n{\n /*@\n loop invariant bounds: 0 <= i <= n;\n loop invariant replace: Replace{Pre,Here}(a, i, b, v, w);\n loop assigns i, b[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n b[i] = (a[i] == v ? w : a[i]);\n }\n //@ assert Replace{Pre,Here}(a, n, b, v, w);\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_133", "file_name": "133", "input": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = 0;\n while (x < n) {\n x = x + 1;\n }\n //@ assert x == n;\n}", "output": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = 0;\n /*@\n loop invariant x <= n;\n loop invariant 0 <= x;\n loop assigns x;\n */\n while (x < n) {\n x = x + 1;\n }\n //@ assert x == n;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_triangle_angles", "file_name": "triangle_angles", "input": "int triangle(int a, int b, int c) {\n if ((a+b+c == 180) && a > 0 && b > 0 && c > 0) {\n return 1;\n } else {\n return 0;\n }\n}\nvoid check_validity() {\n int res = triangle(90, 45, 45);\n //@ assert res == 1;\n res = triangle(90, 145, 145);\n //@ assert res == 0;\n}", "output": "/*@\n requires a>0 && b>0 && c>0;\n ensures \\result == 1 <==> (a+b+c == 180) && (a > 0) && (b > 0) && (c > 0);\n ensures \\result == 0 <==> (a+b+c != 180) || (a <= 0) || (b <= 0) || (c <= 0);\n*/\nint triangle(int a, int b, int c) {\n if ((a+b+c == 180) && a > 0 && b > 0 && c > 0) {\n return 1;\n } else {\n return 0;\n }\n}\nvoid check_validity() {\n int res = triangle(90, 45, 45);\n //@ assert res == 1;\n res = triangle(90, 145, 145);\n //@ assert res == 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arrays_and_loops_1", "file_name": "1", "input": "int area(int base, int height){\n int res = (base * height)/2;\n return res;\n}\nint main() {\n int a = area(4, 5);\n //@ assert a == 10;\n}", "output": "/*@\n requires base >= 0 && height >= 0;\n ensures \\result == (base * height)/2;\n*/\nint area(int base, int height){\n int res = (base * height)/2;\n return res;\n}\nint main() {\n int a = area(4, 5);\n //@ assert a == 10;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "pointers_max_pointer", "file_name": "max_pointers", "input": "int max_ptr(int *a, int *b){\n return (*a < *b) ? *b : *a ;\n}\nextern int h;\nint main() {\n h = 42;\n int a = 24;\n int b = 42;\n int x = max_ptr(&a, &b);\n //@ assert x == 42;\n //@ assert h == 42;\n}", "output": "/*@\n requires \\valid_read(a) && \\valid_read(b);\n requires \\separated(a, b);\n assigns \\nothing;\n ensures \\result >= *a && \\result >= *b;\n ensures \\result == *a || \\result == *b;\n*/\nint max_ptr(int *a, int *b){\n return (*a < *b) ? *b : *a ;\n}\nextern int h;\nint main() {\n h = 42;\n int a = 24;\n int b = 42;\n int x = max_ptr(&a, &b);\n //@ assert x == 42;\n //@ assert h == 42;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_sign", "file_name": "sign", "input": "int spec_sign(int x)\n{\n return (x > 0) - (x < 0);\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = spec_sign(10);\n //@ assert a == 1;\n int b = spec_sign(0);\n //@ assert b == 0;\n}\n#endif", "output": "/*@ assigns \\nothing;\n ensures \\result == 0 || \\result == 1 || \\result == -1;\n behavior positive:\n assumes x > 0;\n ensures \\result == 1;\n behavior zero:\n assumes x == 0;\n ensures \\result == 0;\n behavior negative:\n assumes x < 0;\n ensures \\result == -1;\n complete behaviors;\n disjoint behaviors;\n */\nint spec_sign(int x)\n{\n return (x > 0) - (x < 0);\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = spec_sign(10);\n //@ assert a == 1;\n int b = spec_sign(0);\n //@ assert b == 0;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_132", "file_name": "132", "input": "void foo(int j, int c, int t) {\n int i = 0;\n while(unknown()) {\n if(c > 48) {\n if (c < 57) {\n j = i + i;\n t = c - 48;\n i = j + t;\n }\n }\n } \n //@ assert i >= 0;\n}", "output": "void foo(int j, int c, int t) {\n int i = 0;\n /*@\n loop invariant 0 <= i;\n loop assigns t,j,i,c;\n */\n while(unknown()) {\n if(c > 48) {\n if (c < 57) {\n j = i + i;\n t = c - 48;\n i = j + t;\n }\n }\n } \n //@ assert i >= 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "loops_fact", "file_name": "fact", "input": "#include \n/*@\n axiomatic Factorial {\n logic integer fact(integer n);\n axiom case_n:\n \\forall integer n;\n n >= 1 ==> fact(n) == n*fact(n-1);\n axiom case_0:\n fact(0) == 1;\n }\n*/\nint factorial(int n) {\n int i = 1;\n int f = 1;\n while (i <= n) {\n f = f * i;\n i = i + 1;\n }\n return f;\n}\nvoid main() {\n int t = factorial(5);\n //@ assert t == 120;\n}", "output": "#include \n/*@\n axiomatic Factorial {\n logic integer fact(integer n);\n axiom case_n:\n \\forall integer n;\n n >= 1 ==> fact(n) == n*fact(n-1);\n axiom case_0:\n fact(0) == 1;\n }\n*/\n/*@\n requires n >= 0;\n ensures \\result == fact(n);\n assigns \\nothing ; \n*/\nint factorial(int n) {\n int i = 1;\n int f = 1;\n /*@\n loop invariant f == fact(i-1);\n loop invariant 0 < i <= n+1;\n loop assigns i, f; \n */\n while (i <= n) {\n f = f * i;\n i = i + 1;\n }\n return f;\n}\nvoid main() {\n int t = factorial(5);\n //@ assert t == 120;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Linear Search problem using behavior", "file_name": "Linear Search problem using behavior", "input": "#include \nint* search(int* array, size_t length, int element) {\n\tfor(size_t i = 0; i < length; i++) \n\t\tif(array[i]==element) return &array[i];\n\treturn NULL;\n}\nvoid main() {\n\tint a[] = {1, 5, 6, 7};\n\tint* res = search(a, 4, 5);\n}", "output": "#include \n/*@\n\trequires \\valid_read(array+(0..length-1));\n\tassigns \\nothing;\n\tbehavior in:\n\t\tassumes \\exists size_t off;0<=offarray[off]!=element;\n\t\tensures \\result==NULL;\n\tdisjoint behaviors;\t\n\tcomplete behaviors;\t\n*/\nint* search(int* array, size_t length, int element) {\n\t/*@\n\t\tloop invariant 0<=i<=length;\n\t\tloop invariant \\forall size_t j;0<=jarray[j]!=element;\n\t\tloop assigns i;\t\n\t\tloop variant length-i;\n\t*/\n\tfor(size_t i = 0; i < length; i++) \n\t\tif(array[i]==element) return &array[i];\n\treturn NULL;\n}\nvoid main() {\n\tint a[] = {1, 5, 6, 7};\n\tint* res = search(a, 4, 5);\n\t//@ assert *res == 5;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_vowel-or-cons", "file_name": "vowel-or-cons", "input": "enum Kind { VOWEL, CONSONANT };\nenum Kind kind_of_letter(char c) {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){\n return VOWEL; \n }\n return CONSONANT;\n}\nvoid test(){\n char a = 'a', b = 'b', c = 'c', e = 'e', z = 'z'; \n enum Kind kind_a = kind_of_letter(a); \n //@ assert kind_a == VOWEL ;\n enum Kind kind_b = kind_of_letter(b); \n //@ assert kind_b == CONSONANT ;\n enum Kind kind_c = kind_of_letter(c); \n //@ assert kind_c == CONSONANT ;\n enum Kind kind_e = kind_of_letter(e); \n //@ assert kind_e == VOWEL ;\n enum Kind kind_z = kind_of_letter(z); \n //@ assert kind_z == CONSONANT ;\n}", "output": "enum Kind { VOWEL, CONSONANT };\n/*@ \n requires lowercase: 'a' <= c <= 'z' ; \n assigns \\nothing ; \n behavior vowel: \n assumes c \\in {'a', 'e', 'i', 'o', 'u'} ; \n ensures \\result == VOWEL ; \n behavior consonant: \n assumes !(c \\in {'a', 'e', 'i', 'o', 'u'}) ;\n ensures \\result == CONSONANT ; \n complete behaviors; \n disjoint behaviors; \n*/\nenum Kind kind_of_letter(char c) {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){\n return VOWEL; \n }\n return CONSONANT;\n}\nvoid test(){\n char a = 'a', b = 'b', c = 'c', e = 'e', z = 'z'; \n enum Kind kind_a = kind_of_letter(a); \n //@ assert kind_a == VOWEL ;\n enum Kind kind_b = kind_of_letter(b); \n //@ assert kind_b == CONSONANT ;\n enum Kind kind_c = kind_of_letter(c); \n //@ assert kind_c == CONSONANT ;\n enum Kind kind_e = kind_of_letter(e); \n //@ assert kind_e == VOWEL ;\n enum Kind kind_z = kind_of_letter(z); \n //@ assert kind_z == CONSONANT ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "miscellaneous_increment_arr", "file_name": "increment_arr", "input": "void increment_array_by(int* arr, int n, int c) {\n for (int i = 0; i < n; i++) {\n arr[i] = arr[i] + c;\n }\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n increment_array_by(arr, 5, 2);\n //@ assert arr[0] == 3;\n //@ assert arr[1] == 4;\n //@ assert arr[2] == 5;\n //@ assert arr[3] == 6;\n //@ assert arr[4] == 7;\n}", "output": "/*@\n requires n > 0;\n requires \\valid_read(arr+(0..n-1));\n ensures \\forall integer k; 0 <= k < n ==> arr[k] == (\\at(arr[k], Pre) + c);\n*/\nvoid increment_array_by(int* arr, int n, int c) {\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; 0 <= k < i ==> arr[k] == \\at(arr[k], Pre) + c;\n loop invariant \\forall integer k; i <= k < n ==> arr[k] == \\at(arr[k], Pre);\n loop assigns i, arr[0..n-1];\n */\n for (int i = 0; i < n; i++) {\n arr[i] = arr[i] + c;\n }\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n increment_array_by(arr, 5, 2);\n //@ assert arr[0] == 3;\n //@ assert arr[1] == 4;\n //@ assert arr[2] == 5;\n //@ assert arr[3] == 6;\n //@ assert arr[4] == 7;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_70", "file_name": "70", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int x = 1;\n int y = 0;\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y < n;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int x = 1;\n int y = 0;\n /*@\n loop invariant n > 0 ==> y >= 0;\n loop invariant n > 0 ==> y < n;\n loop invariant y <= n;\n loop invariant x <= n+1;\n loop invariant x <= n + 1;\n loop invariant 1 <= x;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y < n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_121", "file_name": "121", "input": "int main() {\n int i = 1;\n int sn = 0;\n while (i <= 8) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == 8;\n }\n}", "output": "int main() {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= 9;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= 8) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == 8;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_105", "file_name": "105", "input": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = 0;\n while (x < n) {\n x = x + 1;\n }\n if (n >= 0) {\n //@ assert x == n;\n }\n}", "output": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = 0;\n /*@\n loop invariant x <= n;\n loop invariant 0 <= x;\n loop assigns x;\n */\n while (x < n) {\n x = x + 1;\n }\n if (n >= 0) {\n //@ assert x == n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_49", "file_name": "49", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (n <= -1) {\n //@ assert c != n;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant \\exists integer k; k < 0 && c == n ==> c == 1;\n loop invariant 0 <= c;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (n <= -1) {\n //@ assert c != n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Binary Search problem using behavior", "file_name": "Binary Search problem using behavior", "input": "#include\n/*@\npredicate sorted(int* a, int length)=\\forall integer i,j;0<=ia[i]<=a[j];\n*/\nint binary_search(int* a, int n, int v) {\n\tint l=0,u=n-1;\n\twhile(l<=u) {\n\t\tint m=l+(u-l)/2;\n\t\tif(a[m]==v) return m;\n\t\telse if(a[m]\n/*@\npredicate sorted(int* a, int length)=\\forall integer i,j;0<=ia[i]<=a[j];\n*/\n/*@\n\trequires n>=0&&\\valid_read(a+(0..n-1));\n \trequires sorted(a,n);\n\tassigns \\nothing;\n\tbehavior exists:\n\t\tassumes \\exists integer i;0<=ia[i]!=v;\n\t\tensures \\result==-1;\n\tcomplete behaviors;\n\tdisjoint behaviors;\n*/\nint binary_search(int* a, int n, int v) {\n\tint l=0,u=n-1;\n\t/*@\n\t\tloop invariant 0<=l<=u+1;\n\t\tloop invariant ua[k]a[k]>v;\n\t\tloop variant u-l;\n\t*/\n\twhile(l<=u) {\n\t\tint m=l+(u-l)/2;\n\t\tif(a[m]==v) return m;\n\t\telse if(a[m]\n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\nsize_type\nmin_element(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type min = 0u;\n for (size_type i = 0u; i < n; i++) {\n if (a[i] < a[min]) {\n min = i;\n }\n }\n //@ assert MinElement(a, n, min);\n return min;\n }\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior empty:\n assumes n == 0;\n assigns \\nothing;\n ensures result: \\result == 0;\n behavior not_empty:\n assumes 0 < n;\n assigns \\nothing;\n ensures result: 0 <= \\result < n;\n ensures min: MinElement(a, n, \\result);\n ensures first: StrictLowerBound(a, \\result, a[\\result]);\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nmin_element(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type min = 0u;\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant min: 0 <= min < n;\n loop invariant lower: LowerBound(a, i, a[min]);\n loop invariant first: StrictLowerBound(a, min, a[min]);\n loop assigns min, i;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; i++) {\n if (a[i] < a[min]) {\n min = i;\n }\n }\n //@ assert MinElement(a, n, min);\n return min;\n }\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_dist", "file_name": "dist", "input": "#include \nint distance(int a, int b) {\n if (a < b) return b - a; \n else return a - b; \n}\nint main(){\n int a = -10;\n int b = 10;\n int result = distance(a, b);\n //@ assert result == 20;\n return 0;\n}", "output": "#include \n/*@ \n requires INT_MIN < a - b < INT_MAX ||\n INT_MIN < b - a < INT_MAX; \n ensures positive_value: function_result: \\result >= 0;\n ensures correct_sum: (a - b) >= 0 <==> \\result == (a - b) &&\n (a - b) <= 0 <==> \\result == (b - a);\n assigns \\nothing; \n*/\nint distance(int a, int b) {\n if (a < b) return b - a; \n else return a - b; \n}\nint main(){\n int a = -10;\n int b = 10;\n int result = distance(a, b);\n //@ assert result == 20;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "axiom_top_of_push", "file_name": "axiom_top_of_push", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures top: !StackEmpty(s) ==> \\result == StackTop(s);\n*/\nvalue_type\nstack_top(const Stack* s);\nvalue_type\naxiom_top_of_push(Stack* s, value_type v)\n{\n stack_push(s, v);\n //@ assert StackTop(s) == v;\n return stack_top(s);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures top: !StackEmpty(s) ==> \\result == StackTop(s);\n*/\nvalue_type\nstack_top(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires not_full: !StackFull(s);\n assigns s->size, s->obj[s->size];\n ensures top: \\result == v;\n*/\nvalue_type\naxiom_top_of_push(Stack* s, value_type v)\n{\n stack_push(s, v);\n //@ assert StackTop(s) == v;\n return stack_top(s);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "mutable_arrays_array_double", "file_name": "array_double", "input": "void arrayDouble(int *a, unsigned int n) {\n int p = 0;\n while (p < n) {\n a[p] = a[p] * 2;\n p = p + 1;\n } \n}\nint main() {\n int arr[] = {0,1,2,3,4,5};\n arrayDouble(arr, 6);\n //@ assert arr[0] == 0;\n //@ assert arr[1] == 2;\n //@ assert arr[2] == 4;\n //@ assert arr[3] == 6;\n //@ assert arr[4] == 8;\n //@ assert arr[5] == 10;\n}", "output": "/*@\n requires n > 0;\n requires \\valid_read(a+(0..n-1));\n ensures \\forall integer k; 0 <= k < n ==> a[k] == \\old(a[k])*2;\n*/\nvoid arrayDouble(int *a, unsigned int n) {\n int p = 0;\n /*@\n loop invariant 0 <= p <= n;\n loop invariant \\forall integer k; 0 <= k < p ==> a[k] == \\at(a[k], Pre) * 2;\n loop invariant \\forall integer k; p <= k < n ==> a[k] == \\at(a[k], Pre);\n loop assigns p, a[0..n-1];\n loop variant n - p;\n */\n while (p < n) {\n a[p] = a[p] * 2;\n p = p + 1;\n } \n}\nint main() {\n int arr[] = {1,3,5,7,8};\n arrayDouble(arr, 5);\n //@ assert arr[0] == 2;\n //@ assert arr[1] == 6;\n //@ assert arr[2] == 10; \n //@ assert arr[3] == 14;\n //@ assert arr[4] == 16;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_diff", "file_name": "diff", "input": "#include \nint diff (int x, int y) {\n return x-y;\n}\nvoid main() {\n int t = diff(10, 5);\n //@ assert t == 5;\n}", "output": "#include \n/*@\n requires (x > INT_MIN) && (y > INT_MIN);\n ensures y == x-\\result;\n*/\nint diff (int x, int y) {\n return x-y;\n}\nvoid main() {\n int t = diff(10, 5);\n //@ assert t == 5;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_59", "file_name": "59", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c <= n;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant 0 <= c <= n;\n loop invariant c <= n || 0 < n;\n loop invariant 0 < n;\n loop invariant (c == n || c != n);\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c <= n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_lower_bound", "file_name": "lower_bound", "input": "unsigned lower_bound(const int *a, unsigned n, int val)\n{\n\tunsigned left = 0;\n\tunsigned right = n;\n\tunsigned middle = 0;\n\twhile (left < right) {\n\t\tmiddle = left + (right - left) / 2;\n\t\tif (a[middle] < val) {\n\t\t\t//@ assert \\forall integer i; 0 <= i < middle+1 ==> a[i] < val;\n\t\t\tleft = middle + 1;\n\t\t} else right = middle;\n\t}\n\treturn left;\n}\nint main(){\n\tunsigned n = 5;\n\tint a[5] = {1, 2, 3, 4, 5};\n\tunsigned result = lower_bound(a, n, 3);\n\t//@ assert result == 2;\n\treturn 0;\n}", "output": "/*@ requires \\valid(a + (0..n-1));\n requires \\forall integer i, integer j; 0 <= i < j < n ==> a[i] <= a[j];\n assigns \\nothing;\n ensures 0 <= \\result <= n;\n ensures \\forall integer k; 0 <= k < \\result ==> a[k] < val;\n ensures \\forall integer k; \\result <= k < n ==> val <= a[k];\n*/\nunsigned lower_bound(const int *a, unsigned n, int val)\n{\n\tunsigned left = 0;\n\tunsigned right = n;\n\tunsigned middle = 0;\n\t/*@ loop invariant 0 <= left <= right <= n;\n\t loop assigns middle, left, right;\n\t loop invariant \\forall integer i; 0 <= i < left ==> a[i] < val;\n\t loop invariant \\forall integer i; right <= i < n ==> val <= a[i];\n\t loop variant right - left;\n\t */\n\twhile (left < right) {\n\t\tmiddle = left + (right - left) / 2;\n\t\tif (a[middle] < val) {\n\t\t\t//@ assert \\forall integer i; 0 <= i < middle+1 ==> a[i] < val;\n\t\t\tleft = middle + 1;\n\t\t} else right = middle;\n\t}\n\treturn left;\n}\nint main(){\n\tunsigned n = 5;\n\tint a[5] = {1, 2, 3, 4, 5};\n\tunsigned result = lower_bound(a, n, 3);\n\t//@ assert result == 2;\n\treturn 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "suman1406_FindMaxElement", "file_name": "FindMaxElement", "input": "int findMax(int arr[], int n) {\n int max = arr[0];\n for (int i = 1; i < n; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n return max;\n}\nint main(){\n int arr[] = {0, 1, 2, 3, 4};\n int n = sizeof(arr) / sizeof(arr[0]);\n int max = findMax(arr, n);\n //@ assert \\forall integer i; 0 <= i < n ==> arr[i] <= max;\n return 0;\n}", "output": "/*@ requires n > 0;\n requires \\valid(arr + (0..n-1));\n assigns \\nothing;\n ensures \\forall integer i; 0 <= i < n ==> arr[i] <= \\result;\n*/\nint findMax(int arr[], int n) {\n int max = arr[0];\n /*@ loop invariant 1 <= i <= n;\n loop invariant \\forall integer j; 0 <= j < i ==> arr[j] <= max;\n loop assigns i,max;\n loop variant n - i;\n */\n for (int i = 1; i < n; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n return max;\n}\nint main(){\n int arr[] = {0, 1, 2, 3, 4};\n int n = sizeof(arr) / sizeof(arr[0]);\n int max = findMax(arr, n);\n //@ assert \\forall integer i; 0 <= i < n ==> arr[i] <= max;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_9", "file_name": "9", "input": "/*@\n requires 0 <= x <= 2;\n requires 0 <= y <= 2;\n*/\nvoid foo(int x, int y) {\n while (unknown()) {\n x = x + 2;\n y = y + 2;\n }\n if (x == 4) {\n //@ assert y != 0;\n }\n}", "output": "/*@\n requires 0 <= x <= 2;\n requires 0 <= y <= 2;\n*/\nvoid foo(int x, int y) {\n /*@\n loop invariant x == 4 ==> y != 0;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (unknown()) {\n x = x + 2;\n y = y + 2;\n }\n if (x == 4) {\n //@ assert y != 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "gpetiot_Frama-C-StaDy_first_subset", "file_name": "first_subset", "input": "void firstSubset(int s[], int n) {\n int k;\n for ( k = 0; k < n; k++) {\n s[k] = 0;\n }\n}\nint main(){\n int s[3];\n firstSubset(s, 3);\n //@ assert s[0] == 0 && s[1] == 0 && s[2] == 0;\n}", "output": "/*@\n requires \\valid(s + (0 .. n - 1)) && n >= 1;\n assigns s[0 .. n - 1];\n ensures \\forall integer k; 0 <= k < n ==> s[k] == 0;\n*/\nvoid firstSubset(int s[], int n) {\n /*@\n loop invariant 0 <= k <= n;\n loop invariant \\forall integer i; 0 <= i < k ==> s[i] == 0;\n loop assigns k, s[0 .. n - 1];\n loop variant n - k;\n */\n for (int k = 0; k < n; k++) {\n s[k] = 0;\n }\n}\nint main(){\n int s[3];\n firstSubset(s, 3);\n //@ assert s[0] == 0 && s[1] == 0 && s[2] == 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "loops_1", "file_name": "1", "input": "int main(){\n int i=0;\n while (i<30){\n ++i;\n }\n //@assert i==30;\n}", "output": "int main(){\n int i=0;\n /*@\n loop invariant 0 <= i <= 30;\n */\n while (i<30){\n ++i;\n }\n //@assert i==30;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_gcd", "file_name": "gcd", "input": "/*@\n logic integer gcd(integer a, integer b) = \n (a==0)?b:\n (b==0)?a:\n (a==b)?a:\n (a>b)? gcd(a-b, b) : gcd(a, b-a);\n*/\nint gcd(int a, int b) {\n if (a == 0)\n return b;\n if (b == 0)\n return a;\n if (a == b)\n return a;\n if (a > b)\n return gcd(a-b, b);\n return gcd(a, b-a);\n}\nint main()\n{\n int a = 98, b = 56;\n int c = gcd(a, b);\n //@ assert c == 14;\n return 0;\n}", "output": "/*@\n logic integer gcd(integer a, integer b) = \n (a==0)?b:\n (b==0)?a:\n (a==b)?a:\n (a>b)? gcd(a-b, b) : gcd(a, b-a);\n*/\n/*@\n requires a>0 && b>0;\n assigns \\nothing;\n behavior exit1:\n assumes a == 0;\n ensures \\result == b;\n behavior exit2:\n assumes b == 0;\n ensures \\result == a;\n behavior exit3:\n assumes a == b;\n ensures \\result == a;\n behavior exit4:\n assumes a > b;\n ensures \\result == gcd(a-b,b);\n behavior exit5:\n assumes a < b;\n ensures \\result == gcd(a,b-a);\n complete behaviors;\n disjoint behaviors;\n*/\nint gcd(int a, int b) {\n if (a == 0)\n return b;\n if (b == 0)\n return a;\n if (a == b)\n return a;\n if (a > b)\n return gcd(a-b, b);\n return gcd(a, b-a);\n}\nint main()\n{\n int a = 98, b = 56;\n int c = gcd(a, b);\n //@ assert c == 14;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_mod", "file_name": "mod", "input": "int mod(int a, int b)\n{\n\treturn a % b;\n}\nint main(){\n int a = 10000;\n int b = 3;\n int c = mod(a,b);\n //@ assert c == 1;\n}", "output": "/*@ requires b != 0;\n assigns \\nothing;\n ensures \\result == (a % b);\n */\nint mod(int a, int b)\n{\n\treturn a % b;\n}\nint main(){\n int a = 10000;\n int b = 3;\n int c = mod(a,b);\n //@ assert c == 1;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_129", "file_name": "129", "input": "void foo(int y) {\n int x = 1;\n while (x < y) {\n x = x + x;\n }\n //@ assert x >= 1;\n}", "output": "void foo(int y) {\n int x = 1;\n /*@\n loop invariant 1 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x < y) {\n x = x + x;\n }\n //@ assert x >= 1;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_42", "file_name": "42", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > n) {\n //@ assert c == n;\n }\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant c > n ==> c == n + 1;\n loop invariant c <= n;\n loop invariant c <= 1 || c > n;\n loop invariant c < 0 ==> c == n;\n loop invariant c != n;\n loop invariant c != -1;\n loop invariant 0 <= c;\n loop invariant (c > n) || (c <= n);\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > n) {\n //@ assert c == n;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "copy", "file_name": "copy", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\nvoid\ncopy(const value_type* a, size_type n, value_type* b)\n{\n for (size_type i = 0u; i < n; ++i) {\n b[i] = a[i];\n }\n //@ assert Equal{Pre,Here}(a, n, b);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a + (0..n-1), b);\n assigns b[0..n-1];\n ensures equal: Equal{Old,Here}(a, n, b);\n*/\nvoid\ncopy(const value_type* a, size_type n, value_type* b)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant equal: Equal{Pre,Here}(a, i, b);\n loop invariant unchanged: Unchanged{Pre,Here}(a, i, n);\n loop assigns i, b[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n b[i] = a[i];\n }\n //@ assert Equal{Pre,Here}(a, n, b);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "miscellaneous_array_find", "file_name": "array_find", "input": "int array_find(int* arr, int n, int x) {\n int i = 0;\n for (i = 0; i < n; i++) {\n if (arr[i] == x) {\n return i;\n }\n }\n return -1;\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n int index = array_find(arr, 5, 3);\n //@ assert index == 2;\n}", "output": "/*@\n requires n >= 0;\n requires \\valid_read(arr+(0..n-1));\n assigns \\nothing;\n ensures -1 <= \\result < n;\n ensures 0 <= \\result < n ==> arr[\\result] == x;\n ensures (\\result == -1) ==> (\\forall integer i; 0 <= i < n ==> arr[i] != x);\n assigns \\nothing;\n*/\nint array_find(int* arr, int n, int x) {\n int i = 0;\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; 0 <= k < i ==> arr[k] != x;\n loop assigns i;\n loop variant n-i;\n */\n for (i = 0; i < n; i++) {\n if (arr[i] == x) {\n return i;\n }\n }\n return -1;\n}\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n int index = array_find(arr, 5, 3);\n //@ assert index == 2;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_rshift", "file_name": "rshift", "input": "unsigned rshift(unsigned a)\n{\n\treturn a >> 1;\n}\nint main(){\n\tunsigned a = 10;\n\tunsigned b = rshift(a);\n\t//@ assert b == 5;\n}", "output": "/*@ assigns \\nothing;\n ensures \\result == a / 2;\n */\nunsigned rshift(unsigned a)\n{\n\treturn a >> 1;\n}\nint main(){\n\tunsigned a = 10;\n\tunsigned b = rshift(a);\n\t//@ assert b == 5;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_abs_impletentation", "file_name": "abs_impletentation", "input": "#define SPEC_INT_MIN -2147483648\n#define SPEC_INT_MAX 2147483647\nlong spec_abs1(int a)\n{\n long abs;\n abs = a;\n if (a < 0) {\n abs = -abs;\n }\n return abs;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = spec_abs1(SPEC_INT_MIN+1);\n //@ assert a == SPEC_INT_MAX;\n}\n#endif", "output": "#define SPEC_INT_MIN -2147483648\n#define SPEC_INT_MAX 2147483647\n/*@ assigns \\nothing;\n ensures \\result >= 0;\n behavior positive:\n assumes a > 0;\n ensures \\result == a;\n behavior zero:\n assumes a == 0;\n ensures \\result == 0;\n ensures \\result == a;\n behavior negative:\n assumes a < 0;\n ensures \\result == -a;\n complete behaviors;\n disjoint behaviors;\n */\nlong spec_abs1(int a)\n{\n long abs;\n abs = a;\n if (a < 0) {\n abs = -abs;\n }\n return abs;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = spec_abs1(SPEC_INT_MIN+1);\n //@ assert a == SPEC_INT_MAX;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_90", "file_name": "90", "input": "void foo(int x) {\n int lock = 0;\n int y = x + 1;\n while (x != y) {\n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1;\n }\n }\n //@ assert lock == 1;\n}", "output": "void foo(int x) {\n int lock = 0;\n int y = x + 1;\n /*@\n loop invariant x <= y;\n loop invariant x != y ==> lock == 0;\n loop invariant lock == 0 ==> x + 1 == y;\n loop invariant x == y || x == y - 1;\n loop invariant x == y || x + 1 == y;\n loop invariant lock == 1 ==> x == y;\n loop invariant lock == 0 || lock == 1;\n loop invariant lock <= 1;\n loop invariant 0 <= lock;\n loop assigns x,y,lock;\n */\n while (x != y) {\n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1;\n }\n }\n //@ assert lock == 1;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "rotate", "file_name": "rotate", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Reverse\n {\n predicate\n Reverse{K,L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],K) == \\at(b[n-1-i], L);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Reverse{K,L}(a+m, n-m, b+p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, value_type* b) =\n Reverse{K,L}(a, m, n, b, m);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, integer p) =\n Reverse{K,L}(a, m, n, a, p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n) =\n Reverse{K,L}(a, m, n, m);\n predicate\n Reverse{K,L}(value_type* a, integer n) = Reverse{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n assigns a[0..n-1];\n ensures reverse: Reverse{Old,Here}(a, n);\n*/\nvoid\nreverse(value_type* a, size_type n);\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\nsize_type\nrotate(value_type* a, size_type m, size_type n)\n{\n if ((0u < m) && (m < n)) {\n reverse(a, m);\n reverse(a + m, n - m);\n reverse(a, n);\n //@ assert left: Equal{Pre,Here}(a, 0, m, n-m);\n //@ assert right: Equal{Pre,Here}(a, m, n, 0);\n }\n return n - m;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Reverse\n {\n predicate\n Reverse{K,L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],K) == \\at(b[n-1-i], L);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Reverse{K,L}(a+m, n-m, b+p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, value_type* b) =\n Reverse{K,L}(a, m, n, b, m);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n, integer p) =\n Reverse{K,L}(a, m, n, a, p);\n predicate\n Reverse{K,L}(value_type* a, integer m, integer n) =\n Reverse{K,L}(a, m, n, m);\n predicate\n Reverse{K,L}(value_type* a, integer n) = Reverse{K,L}(a, 0, n);\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n assigns a[0..n-1];\n ensures reverse: Reverse{Old,Here}(a, n);\n*/\nvoid\nreverse(value_type* a, size_type n);\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n requires bound: m <= n;\n assigns a[0..n-1];\n ensures result: \\result == n-m;\n ensures left: Equal{Old,Here}(a, 0, m, n-m);\n ensures right: Equal{Old,Here}(a, m, n, 0);\n*/\nsize_type\nrotate(value_type* a, size_type m, size_type n)\n{\n if ((0u < m) && (m < n)) {\n reverse(a, m);\n reverse(a + m, n - m);\n /*@\n requires left: Reverse{Pre,Here}(a, 0, m, 0);\n requires right: Reverse{Pre,Here}(a, m, n, m);\n assigns a[0..n-1];\n ensures left: Reverse{Old,Here}(a, 0, m, n-m);\n ensures right: Reverse{Old,Here}(a, m, n, 0);\n */\n reverse(a, n);\n //@ assert left: Equal{Pre,Here}(a, 0, m, n-m);\n //@ assert right: Equal{Pre,Here}(a, m, n, 0);\n }\n return n - m;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Increment function with precondition and postcondition.", "file_name": "Increment function with precondition and postcondition.", "input": "#include\n#include\nint inc(int n)\n{\nreturn n+1;\n}\nvoid main()\n{\nint a=10;\nint k=inc(a);\n//@ assert k==11;\n}", "output": "#include\n#include\n/*@ requires -100000<=n<=100000;\nensures \\result==n+1;\n*/\nint inc(int n)\n{\nreturn n+1;\n}\nvoid main()\n{\nint a=10;\nint k=inc(a);\n//@ assert k==11;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_lower_bound", "file_name": "lower_bound", "input": "unsigned lower_bound(const int *a, unsigned n, int val)\n{\n unsigned left = 0;\n unsigned right = n;\n unsigned middle = 0;\n while (left < right) {\n middle = left + (right - left) / 2;\n if (a[middle] < val) {\n //@ assert \\forall integer i; 0 <= i < middle+1 ==> a[i] < val;\n left = middle + 1;\n } else right = middle;\n }\n return left;\n}\n#ifdef OUT_OF_TASK\n#include \n#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))\nint main(void)\n{\n int a[] = {0};\n int b[] = {0,1};\n int c[] = {0,1,2,3,4,5};\n int res;\n res = lower_bound(a, ARRAY_SIZE(a), 0);\n printf(\"res: %d\\n\", res);\n res = lower_bound(b, ARRAY_SIZE(b), 1);\n printf(\"res: %d\\n\", res);\n res = lower_bound(c, ARRAY_SIZE(c), 10);\n printf(\"res: %d\\n\", res);\n}\n#endif", "output": "/*@ requires \\valid(a + (0..n-1));\n requires \\forall integer i, integer j; 0 <= i < j < n ==> a[i] <= a[j];\n assigns \\nothing;\n ensures 0 <= \\result <= n;\n ensures \\forall integer k; 0 <= k < \\result ==> a[k] < val;\n ensures \\forall integer k; \\result <= k < n ==> val <= a[k];\n*/\nunsigned lower_bound(const int *a, unsigned n, int val)\n{\n unsigned left = 0;\n unsigned right = n;\n unsigned middle = 0;\n /*@ loop invariant 0 <= left <= right <= n;\n loop assigns middle, left, right;\n loop invariant \\forall integer i; 0 <= i < left ==> a[i] < val;\n loop invariant \\forall integer i; right <= i < n ==> val <= a[i];\n loop variant right - left;\n */\n while (left < right) {\n middle = left + (right - left) / 2;\n if (a[middle] < val) {\n //@ assert \\forall integer i; 0 <= i < middle+1 ==> a[i] < val;\n left = middle + 1;\n } else right = middle;\n }\n return left;\n}\n#ifdef OUT_OF_TASK\n#include \n#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))\nint main(void)\n{\n int a[] = {0};\n int b[] = {0,1};\n int c[] = {0,1,2,3,4,5};\n int res;\n res = lower_bound(a, ARRAY_SIZE(a), 0);\n printf(\"res: %d\\n\", res);\n res = lower_bound(b, ARRAY_SIZE(b), 1);\n printf(\"res: %d\\n\", res);\n res = lower_bound(c, ARRAY_SIZE(c), 10);\n printf(\"res: %d\\n\", res);\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_15", "file_name": "15", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 0) {\n //@ assert m < n;\n //@ assert m >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n /*@\n loop invariant x <= n;\n loop invariant n > 0 ==> m >= 0;\n loop invariant n > 0 ==> m < n;\n loop invariant m <= x;\n loop invariant 0 <= x;\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 0) {\n //@ assert m < n;\n //@ assert m >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "X509-parser_bufs_differ", "file_name": "bufs_differ", "input": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n#define X509_FILE_NUM 0\n/*@\n predicate bmatch(u8 *b1, u8 *b2, u32 n) =\n \\forall integer i; 0 <= i < n ==> b1[i] == b2[i];\n predicate bdiffer(u8 *b1, u8 *b2, u32 n) =\n ! bmatch(b1, b2, n);\n*/\nint bufs_differ(const u8 *b1, const u8 *b2, u32 n)\n{\n\tint ret = 0;\n\tu32 i = 0;\n\tfor (i = 0; i < n; i++) {\n\t\tif(b1[i] != b2[i]) {\n\t\t\tret = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn ret;\n}\nint main() {\n u8 b1[10] = {1,2,3,4,5,6,7,8,9,10};\n u8 b2[10] = {10,9,8,7,6,5,4,3,2,1};\n u8 b3[10] = {1,2,3,4,5,6,7,8,9,10};\n u32 n = 10;\n int ret1 = bufs_differ(b1, b3, n);\n //@ assert ret1 == 0;\n int ret2 = bufs_differ(b1, b2, n);\n //@ assert ret2 == 1;\n return 0;\n}", "output": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n#define X509_FILE_NUM 0\n/*@\n predicate bmatch(u8 *b1, u8 *b2, u32 n) =\n \\forall integer i; 0 <= i < n ==> b1[i] == b2[i];\n predicate bdiffer(u8 *b1, u8 *b2, u32 n) =\n ! bmatch(b1, b2, n);\n*/\n/*@\n requires \\valid_read(b1 + (0 .. n-1));\n requires \\valid_read(b2 + (0 .. n-1));\n requires \\valid(b1 + (0 .. n-1));\n requires \\valid(b2 + (0 .. n-1));\n requires n >= 0;\n ensures \\result == 0 <==> bmatch(b1, b2, n);\n ensures \\result == 1 <==> bdiffer(b1, b2, n);\n assigns \\nothing;\n*/\nint bufs_differ(const u8 *b1, const u8 *b2, u32 n)\n{\n\tint ret = 0;\n\tu32 i = 0;\n\t/*@\n\t loop invariant 0 <= i <= n;\n\t loop invariant bmatch(b1, b2, i);\n\t loop assigns i;\n\t loop variant n - i;\n\t*/\n\tfor (i = 0; i < n; i++) {\n\t\tif(b1[i] != b2[i]) {\n\t\t\tret = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn ret;\n}\nint main() {\n u8 b1[10] = {1,2,3,4,5,6,7,8,9,10};\n u8 b2[10] = {10,9,8,7,6,5,4,3,2,1};\n u8 b3[10] = {1,2,3,4,5,6,7,8,9,10};\n u32 n = 10;\n int ret1 = bufs_differ(b1, b3, n);\n //@ assert ret1 == 0;\n int ret2 = bufs_differ(b1, b2, n);\n //@ assert ret2 == 1;\n return 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_67", "file_name": "67", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int y = 0;\n int x = 1;\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int y = 0;\n int x = 1;\n /*@\n loop invariant y <= n;\n loop invariant x <= n+1;\n loop invariant x <= n + 1;\n loop invariant 1 <= x;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (x <= n) {\n y = n - x;\n x = x +1;\n }\n if (n > 0) {\n //@ assert y >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "pointers_reset_1st", "file_name": "reset_1st", "input": "void reset_1st_if_2nd_is_true(int* a, int const* b){\n if(*b) *a = 0 ;\n}\nint main(){\n int a = 5 ;\n int x = 0 ;\n reset_1st_if_2nd_is_true(&a, &x);\n //@ assert a == 5 ;\n //@ assert x == 0 ;\n int const b = 1 ;\n reset_1st_if_2nd_is_true(&a, &b);\n //@ assert a == 0 ;\n //@ assert b == 1 ;\n}", "output": "/*@\n requires \\valid(a) && \\valid_read(b);\n requires \\separated(a, b);\n assigns *a;\n ensures \\old(*b) ==> *a == 0;\n ensures ! \\old(*b) ==> *a == \\old(*a);\n ensures *b == \\old(*b);\n*/\nvoid reset_1st_if_2nd_is_true(int* a, int const* b){\n if(*b) *a = 0 ;\n}\nint main(){\n int a = 5 ;\n int x = 0 ;\n reset_1st_if_2nd_is_true(&a, &x);\n //@ assert a == 5 ;\n //@ assert x == 0 ;\n int const b = 1 ;\n reset_1st_if_2nd_is_true(&a, &b);\n //@ assert a == 0 ;\n //@ assert b == 1 ;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_64", "file_name": "64", "input": "int main() {\n int x = 1;\n int y = 0;\n while (x <= 10) {\n y = 10 - x;\n x = x +1;\n }\n //@ assert y < 10;\n}", "output": "int main() {\n int x = 1;\n int y = 0;\n /*@\n loop invariant y < 10;\n loop invariant y <= 10;\n loop invariant x <= 11;\n loop invariant 1 <= x;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (x <= 10) {\n y = 10 - x;\n x = x +1;\n }\n //@ assert y < 10;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_115", "file_name": "115", "input": "int main() {\n int sn = 0;\n int x = 0;\n while (unknown()) {\n x = x + 1;\n sn = sn + 1;\n }\n if (sn != -1) {\n //@ assert sn == x;\n }\n}", "output": "int main() {\n int sn = 0;\n int x = 0;\n /*@\n loop invariant x == sn;\n loop invariant sn == x;\n loop invariant 0 <= x;\n loop invariant 0 <= sn;\n loop assigns x;\n loop assigns sn;\n */\n while (unknown()) {\n x = x + 1;\n sn = sn + 1;\n }\n if (sn != -1) {\n //@ assert sn == x;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_wp1", "file_name": "wp1", "input": "#include \nint function(int x, int y) {\n int res ;\n y += 10 ;\n x -= 5 ;\n res = x + y ;\n //@ assert -15 <= res <= 5;\n return res ;\n}\nvoid main() {\n int t = function(-5, 5);\n //@ assert t == 5;\n}", "output": "#include \n/*@\n requires INT_MIN <= x <= INT_MAX;\n requires INT_MIN <= y <= INT_MAX;\n requires -20 <= x + y <= 0;\n ensures \\result == x + y + 5;\n*/\nint function(int x, int y) {\n int res ;\n y += 10 ;\n x -= 5 ;\n res = x + y ;\n //@ assert -15 <= res <= 5;\n return res ;\n}\n// write a test\nvoid main() {\n int t = function(-5, 5);\n // -5 -5 + 5 + 10 = 5\n //@ assert t == 5;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "suman1406_Q4", "file_name": "Q4", "input": "#include \nint unknown1();\nint unknown2();\nint unknown3();\nint unknown4();\nint main() {\n int w = 1;\n int z = 0;\n int x = 0;\n int y = 0;\n while (unknown2()) {\n if (w % 2 == 1) {\n x++;\n w++;\n }\n if (z % 2 == 0) {\n y++;\n z++;\n }\n }\n //@ assert x <= 1;\n return 0;\n}", "output": "#include \nint unknown1();\nint unknown2();\nint unknown3();\nint unknown4();\nint main() {\n int w = 1;\n int z = 0;\n int x = 0;\n int y = 0;\n /*@\n loop invariant z % 2 == 0 ==> y == z;\n loop invariant x <= 1;\n loop invariant w % 2 == 1 ==> x == w - 1;\n loop invariant z % 2 == y;\n loop invariant y == z;\n loop invariant w == z || w == z + 1;\n loop invariant w == 2 * x || w == 2 * x + 1;\n loop invariant 1 <= w;\n loop assigns x,y,w,z;\n */\n while (unknown2()) {\n if (w % 2 == 1) {\n x++;\n w++;\n }\n if (z % 2 == 0) {\n y++;\n z++;\n }\n }\n //@ assert x <= 1;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "pointers_add_pointers", "file_name": "add_pointers", "input": "#include \nint add(int *p, int *q) {\n return *p + *q;\n}\nint main() {\n int a = 24;\n int b = 32;\n int x;\n x = add(&a, &b) ;\n //@ assert x == a + b ;\n //@ assert x == 56 ;\n x = add(&a, &a) ;\n //@ assert x == a + a ;\n //@ assert x == 48 ;\n}", "output": "#include \n/*@\n requires \\valid_read(p) && \\valid_read(q);\n requires *p + *q <= INT_MAX;\n requires *p + *q >= INT_MIN;\n assigns \\nothing;\n ensures \\result == *p + *q;\n*/\nint add(int *p, int *q) {\n return *p + *q;\n}\nint main() {\n int a = 24;\n int b = 32;\n int x;\n x = add(&a, &b) ;\n //@ assert x == a + b ;\n //@ assert x == 56 ;\n x = add(&a, &a) ;\n //@ assert x == a + a ;\n //@ assert x == 48 ;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_clamp", "file_name": "clamp", "input": "int clamp(int v, int min, int max)\n{\n\tint low = v > min ? v : min;\n\treturn low < max ? low : max;\n}\nint main(){\n\tint a = 10;\n\tint b = 20;\n\tint c = clamp(a, b, 15);\n\t//@ assert c == 15;\n}", "output": "/*@ \n\tassigns \\nothing;\n ensures \\result == \\min(\\max(min, v), max);\n */\nint clamp(int v, int min, int max)\n{\n\tint low = v > min ? v : min;\n\treturn low < max ? low : max;\n}\nint main(){\n\tint a = 10;\n\tint b = 20;\n\tint c = clamp(a, b, 15);\n\t//@ assert c == 15;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Examples illustrating the usage of labels", "file_name": "Examples illustrating the usage of labels", "input": "#include\n#include\nvoid function(int* a, int const* b)\n{\n*a += *b;\n}\nvoid main() {\nint a = 6;\nint b = 4;\nL1:\nfunction(&a, &b);\n//@assert \\at(a,Here)==10 && b==4;\n//@assert \\at(a,L1)==6 && \\at(b,L1)==4;\n} ", "output": "#include\n#include\n/*@ \t\n requires INT_MIN<=*a+*b<=INT_MAX;\n requires \\valid(a) && \\valid_read(b);\n requires \\separated(a, b);\n assigns *a;\t\n ensures *a==\\old(*a)+*b;\n ensures *b==\\old(*b);\n*/\nvoid function(int* a, int const* b)\n{\n*a += *b;\n}\nvoid main() {\nint a = 6;\nint b = 4;\nL1:\nfunction(&a, &b);\n//@assert \\at(a,Here)==10 && b==4;\n//@assert \\at(a,L1)==6 && \\at(b,L1)==4;\n} ", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_4", "file_name": "BL.EN.U4CSE21176_4", "input": "#include\nint check(int n){\nif(n%2==0)\nreturn 1;\nelse\nreturn 0;\n}\nint main(){\nint a=4;\nint r=check(a);\n//@assert a==4;\n}", "output": "#include\n/*@\nrequires INT_MIN<=n \\result==1) && (n%2!=0 ==> \\result==0);\n*/\nint check(int n){\nif(n%2==0)\nreturn 1;\nelse\nreturn 0;\n}\nint main(){\nint a=4;\nint r=check(a);\n//@assert a==4;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_8", "file_name": "8", "input": "int day_of(int m){\n int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n return days[m-1];\n}\nint main(){\n int m2 = day_of(2);\n //@ assert m2 == 28;\n int m1 = day_of(1);\n //@ assert m1 == 31;\n int m4 = day_of(4);\n //@ assert m4 == 30;\n return 0;\n}", "output": "/*@\n requires 1 <= m <= 12;\n ensures m \\in {2} ==> \\result == 28;\n ensures m \\in {1, 3, 5, 7, 8, 10, 12} ==> \\result == 31;\n ensures m \\in {4, 6, 9, 11} ==> \\result == 30;\n*/\nint day_of(int m){\n int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n return days[m-1];\n}\nint main(){\n int m2 = day_of(2);\n //@ assert m2 == 28;\n int m1 = day_of(1);\n //@ assert m1 == 31;\n int m4 = day_of(4);\n //@ assert m4 == 30;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_8", "file_name": "8", "input": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (y == 0) {\n //@ assert x != 20;\n }\n}", "output": "/*@\n requires 0 <= x <= 10;\n requires 0 <= y <= 10;\n*/\nvoid foo(int x, int y) {\n /*@\n loop invariant y == 0 ==> x != 20;\n loop invariant y <= x + 10;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (unknown()) {\n x = x + 10;\n y = y + 10;\n }\n if (y == 0) {\n //@ assert x != 20;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_95", "file_name": "95", "input": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 0;\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (y == 1) {\n //@ assert i == j;\n }\n}", "output": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 0;\n /*@\n loop invariant y == 0 || y == 1;\n loop invariant y <= 1;\n loop invariant j == y*i;\n loop invariant j == y*(i-1);\n loop invariant j == y * i;\n loop invariant j <= y*(x+1);\n loop invariant j <= i*y;\n loop invariant 0 <= y;\n loop invariant 0 <= j;\n loop invariant 0 <= i;\n loop assigns y,i,j;\n */\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (y == 1) {\n //@ assert i == j;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "axiom_push_of_pop_top", "file_name": "axiom_push_of_pop_top", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures top: !StackEmpty(s) ==> \\result == StackTop(s);\n*/\nvalue_type\nstack_top(const Stack* s);\nvoid\naxiom_push_of_pop_top(Stack* s)\n{\n const value_type v = stack_top(s);\n //@ assert StackTop(s) == v;\n stack_pop(s);\n stack_push(s, v);\n //@ assert StackTop(s) == v;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures top: !StackEmpty(s) ==> \\result == StackTop(s);\n*/\nvalue_type\nstack_top(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires not_empty: !StackEmpty(s);\n assigns s->size, s->obj[s->size-1];\n ensures equal: StackEqual{Old,Here}(s, s);\n*/\nvoid\naxiom_push_of_pop_top(Stack* s)\n{\n const value_type v = stack_top(s);\n //@ assert StackTop(s) == v;\n stack_pop(s);\n stack_push(s, v);\n //@ assert StackTop(s) == v;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_123", "file_name": "123", "input": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n while (i <= size) {\n i = i + 1;\n sn = sn + 1;\n }\n if(sn != 0) {\n //@ assert sn == size;\n }\n}", "output": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant sn <= size;\n loop invariant i <= size+1;\n loop invariant i <= size + 1;\n loop invariant 1 <= i;\n loop invariant 0 <= sn;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= size) {\n i = i + 1;\n sn = sn + 1;\n }\n if(sn != 0) {\n //@ assert sn == size;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_18", "file_name": "18", "input": "/*@\nrequires n > 1;\n*/\nvoid foo(int n)\n{\n int x = 1;\n int m = 1;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 1) {\n //@ assert m < n;\n //@ assert m >= 1;\n }\n}", "output": "/*@\nrequires n > 1;\n*/\nvoid foo(int n)\n{\n int x = 1;\n int m = 1;\n /*@\n loop invariant 1 <= x <= n;\n loop invariant 1 <= m <= x;\n loop invariant m <= n;\n loop invariant (m == 1 || (m >= 1 && m < x));\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 1) {\n //@ assert m < n;\n //@ assert m >= 1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_order_inc_min", "file_name": "order_inc_min", "input": "/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a < *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a >= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid max_ptr(int* a, int* b){\n if(*a < *b){\n int tmp = *b ;\n *b = *a ;\n *a = tmp ;\n }\n //@ assert *a >= *b ;\n}\n/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a > *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a <= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid min_ptr(int* a, int* b){\n max_ptr(b, a);\n //@ assert *a <= *b ;\n}\n\nvoid order_3_inc_min(int* a, int* b, int* c) {\n min_ptr(a, b) ;\n min_ptr(a, c); \n min_ptr(b, c);\n //@ assert *a <= *b && *b <= *c ;\n}", "output": "/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a < *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a >= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid max_ptr(int* a, int* b){\n if(*a < *b){\n int tmp = *b ;\n *b = *a ;\n *a = tmp ;\n }\n //@ assert *a >= *b ;\n}\n/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a > *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a <= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid min_ptr(int* a, int* b){\n max_ptr(b, a);\n //@ assert *a <= *b ;\n}\n/*@ requires \\valid(a) && \\valid(b) && \\valid(c) ;\n requires \\separated(a, b, c); \n assigns *a, *b, *c ;\n ensures { \\old(*a), \\old(*b), \\old(*c) } == { *a, *b, *c }; \n behavior all_equal: \n assumes *a == *b == *c ; \n ensures *a == *b == *c; \n behavior all_uequal: \n assumes *a != *b && *a != *c && *b != *c ; \n ensures *a != *b && *a != *c && *b != *c ;\n behavior two_eq_lt: \n assumes *a == *b < *c || \n *a == *c < *b ||\n *b == *c < *a; \n ensures *a == *b; \n behavior two_eq_gt: \n assumes *a == *b > *c || \n *a == *c > *b ||\n *b == *c > *a; \n ensures *b == *c; \n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid order_3_inc_min(int* a, int* b, int* c) {\n min_ptr(a, b) ;\n min_ptr(a, c); \n min_ptr(b, c);\n //@ assert *a <= *b && *b <= *c ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "loops_2", "file_name": "2", "input": "#include \nint sum(char n) {\n int s = 0;\n char k = 0;\n while(k <= n) { \n s = s + (int)k;\n k = k + 1;\n }\n //@ assert s == (int)((n+1)*(n)/2);\n return (int)s;\n}\nint main() {\n int s = sum(5);\n //@ assert s == 15;\n}", "output": "#include \n/*@\n requires n >= 0 && n <= 100;\n ensures \\result >= 0;\n ensures \\result == (int)((n+1)*(n)/2);\n assigns \\nothing;\n*/\nint sum(char n) {\n int s = 0;\n char k = 0;\n /*@\n loop invariant 0 <= k <= n+1;\n loop invariant s == (k-1)*(k)/2;\n loop assigns k, s;\n loop variant n - k;\n */\n while(k <= n) { \n s = s + (int)k;\n k = k + 1;\n }\n //@ assert s == (int)((n+1)*(n)/2);\n return (int)s;\n}\nint main() {\n int s = sum(5);\n //@ assert s == 15;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_20", "file_name": "20", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n if(n > 0) {\n //@ assert m < n;\n //@ assert m >= 0;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n)\n{\n int x = 0;\n int m = 0;\n /*@\n loop invariant 0 <= x <= n;\n loop invariant 0 <= m <= x;\n loop invariant m < n;\n loop assigns x,m;\n */\n while (x < n) {\n if (unknown()) {\n m = x;\n }\n x = x + 1;\n }\n //post-condition\n if(n > 0) {\n //@ assert m < n;\n //@ assert m >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "miscellaneous_max_of_2", "file_name": "max_of_2", "input": "int max(int x, int y) {\n if (x >= y) {\n return x;\n }\n return y;\n}\nint main() {\n int a = 5;\n int b = 10;\n int result = max(a, b);\n //@ assert result == 10;\n return 0;\n}", "output": "/*@\n ensures \\result == x || \\result == y;\n ensures \\result >= x && \\result >= y;\n*/\nint max(int x, int y) {\n if (x >= y) {\n return x;\n }\n return y;\n}\nint main() {\n int a = 5;\n int b = 10;\n int result = max(a, b);\n //@ assert result == 10;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nikunjjain02_Arrays_4", "file_name": "Arrays_4", "input": "#include\n/*@predicate sorted(int* a, int length)=\\forall integer i,j;0<=i<=ja[i]<=a[j];\n*/\nint binary_search(int* a, int n, int v) {\n\tint l=0,u=n-1;\n\twhile(l<=u) {\n\t\tint m=l+(u-l)/2;\n\t\tif(a[m]==v) return m;\n\t\telse if(a[m]\n/*@predicate sorted(int* a, int length)=\\forall integer i,j;0<=i<=ja[i]<=a[j];\n*/\n/*@\n\trequires n>=0&&\\valid_read(a+(0..n-1));\n \trequires sorted(a,n);\n\tassigns \\nothing;\n\tbehavior exists:\n\t\tassumes \\exists integer i;0<=ia[i]!=v;\n\t\tensures \\result==-1;\n\tcomplete behaviors;\n\tdisjoint behaviors;\n*/\nint binary_search(int* a, int n, int v) {\n\tint l=0,u=n-1;\n\t/*@\n\t\tloop invariant 0<=l<=u+1;\n\t\tloop invariant ua[k]a[k]>v;\n\t\tloop variant u-l;\n\t*/\n\twhile(l<=u) {\n\t\tint m=l+(u-l)/2;\n\t\tif(a[m]==v) return m;\n\t\telse if(a[m] 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (n <= -1) {\n //@ assert c != n;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n - c;\n loop invariant c != n;\n loop invariant 0 <= c <= n;\n loop invariant 0 < n;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (n <= -1) {\n //@ assert c != n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_112", "file_name": "112", "input": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if(sn != n) {\n //@ assert sn == 0;\n }\n}", "output": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= n+1;\n loop invariant i <= n + 1;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if(sn != n) {\n //@ assert sn == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_22", "file_name": "BL.EN.U4CSE21176_22", "input": "#include\nvoid reset(int* array,size_t length){\nfor(size_t i=0;i\n/*@\nrequires \\valid(array + (0..length-1));\nassigns array[0..length-1];\nensures \\forall size_t i; 0 <= i < length ==> array[i] == 0;\n*/\nvoid reset(int* array,size_t length){\n/*@\nloop invariant 0 <= i <=length;\nloop invariant \\forall size_t j; 0 <= j < i ==> array[j] == 0;\nloop assigns i,array[0..length-1];\nloop variant length-i;\n*/\nfor(size_t i=0;i 0;\n ensures \\forall integer k; 0 <= k < n ==> \\result >= a[k];\n ensures \\exists integer k; 0 <= k < n && \\result == a[k];\n assigns \\nothing;\n*/\nint arraymax(int* a, int n) {\n int i = 1;\n int max = a[0];\n /*@ \n loop invariant \\forall integer k; 0 <= k < i ==> max >= a[k];\n loop invariant \\exists integer k; 0 <= k < i && max == a[k];\n loop invariant 0 <= i <= n;\n loop assigns i,max;\n */\n while (i < n) {\n if (max < a[i])\n max = a[i];\n i = i + 1;\n }\n return max;\n}\n// write a test\nvoid main() {\n int arr[5] = {1, 2, 3, 4, 5};\n int sum = arraymax(arr, 5);\n //@ assert sum == 5;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_lower_bound_raw", "file_name": "lower_bound_raw", "input": "unsigned lower_bound_raw(const int *a, unsigned n, int val)\n{\n unsigned i = 0;\n for(; i < n; ++i) {\n if (a[i] >= val) {\n break;\n }\n }\n //@ assert \\forall integer k; 0 <= k < i ==> a[k] < val;\n return i;\n}", "output": "/*@ requires \\valid(a + (0..n-1));\n requires \\forall integer i, integer j; 0 <= i < j < n ==> a[i] <= a[j];\n assigns \\nothing;\n ensures 0 <= \\result <= n;\n ensures \\forall integer k; 0 <= k < \\result ==> a[k] < val;\n ensures \\forall integer k; \\result <= k < n ==> val <= a[k];\n*/\nunsigned lower_bound_raw(const int *a, unsigned n, int val)\n{\n unsigned i = 0;\n /*@ loop invariant 0 <= i <= n;\n loop assigns i;\n loop invariant \\forall integer k; 0 <= k < i ==> a[k] < val;\n loop invariant \\forall integer k; i <= k < n ==> a[k] >= a[i];\n loop variant n - i;\n */\n for(; i < n; ++i) {\n if (a[i] >= val) {\n break;\n }\n }\n //@ assert \\forall integer k; 0 <= k < i ==> a[k] < val;\n return i;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_117", "file_name": "117", "input": "int main() {\n int sn = 0;\n int x = 0;\n while (unknown()) {\n x = x + 1;\n sn = sn + 1;\n }\n if (sn != -1) {\n //@ assert sn == x;\n }\n}", "output": "int main() {\n int sn = 0;\n int x = 0;\n /*@\n loop invariant x == sn;\n loop invariant sn == x;\n loop invariant 0 <= x;\n loop invariant 0 <= sn;\n loop assigns x;\n loop assigns sn;\n */\n while (unknown()) {\n x = x + 1;\n sn = sn + 1;\n }\n if (sn != -1) {\n //@ assert sn == x;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "minmax_element", "file_name": "minmax_element", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct size_type_pair {\n size_type first;\n size_type second;\n};\ntypedef struct size_type_pair size_type_pair;\n/*@\n assigns \\nothing;\n ensures result: \\result.first == first;\n ensures result: \\result.second == second;\n*/\nstatic inline\nsize_type_pair\nmake_pair(size_type first, size_type second)\n{\n size_type_pair pair;\n pair.first = first;\n pair.second = second;\n return pair;\n}\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result.first <= n;\n ensures result: 0 <= \\result.second <= n;\n behavior empty:\n assumes 0 == n;\n assigns \\nothing;\n ensures result: \\result.first == 0;\n ensures result: \\result.second == 0;\n behavior not_empty:\n assumes 0 < n;\n assigns \\nothing;\n ensures result: 0 <= \\result.first < n;\n ensures result: 0 <= \\result.second < n;\n ensures min: MinElement(a, n, \\result.first);\n ensures first: StrictLowerBound(a, \\result.first, a[\\result.first]);\n ensures max: MaxElement(a, n, \\result.second);\n ensures last: StrictUpperBound(a, \\result.second+1, n, a[\\result.second]);\n*/\nsize_type_pair\nminmax_element(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type min = 0u;\n size_type max = 0u;\n for (size_type i = 0u; i < n; i++) {\n if (a[i] >= a[max]) {\n max = i;\n }\n if (a[i] < a[min]) {\n min = i;\n }\n }\n //@ assert MinElement(a, n, min) && MaxElement(a, n, max);\n return make_pair(min, max);\n }\n return make_pair(n, n);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct size_type_pair {\n size_type first;\n size_type second;\n};\ntypedef struct size_type_pair size_type_pair;\n/*@\n assigns \\nothing;\n ensures result: \\result.first == first;\n ensures result: \\result.second == second;\n*/\nstatic inline\nsize_type_pair\nmake_pair(size_type first, size_type second)\n{\n size_type_pair pair;\n pair.first = first;\n pair.second = second;\n return pair;\n}\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n axiomatic ArrayExtrema\n {\n predicate\n MaxElement{L}(value_type* a, integer n, integer max) =\n 0 <= max < n && UpperBound(a, n, a[max]);\n predicate\n MinElement{L}(value_type* a, integer n, integer min) =\n 0 <= min < n && LowerBound(a, n, a[min]);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result.first <= n;\n ensures result: 0 <= \\result.second <= n;\n behavior empty:\n assumes 0 == n;\n assigns \\nothing;\n ensures result: \\result.first == 0;\n ensures result: \\result.second == 0;\n behavior not_empty:\n assumes 0 < n;\n assigns \\nothing;\n ensures result: 0 <= \\result.first < n;\n ensures result: 0 <= \\result.second < n;\n ensures min: MinElement(a, n, \\result.first);\n ensures first: StrictLowerBound(a, \\result.first, a[\\result.first]);\n ensures max: MaxElement(a, n, \\result.second);\n ensures last: StrictUpperBound(a, \\result.second+1, n, a[\\result.second]);\n*/\nsize_type_pair\nminmax_element(const value_type* a, size_type n)\n{\n if (0u < n) {\n size_type min = 0u;\n size_type max = 0u;\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant min: 0 <= min < n;\n loop invariant max: 0 <= max < n;\n loop invariant lower: LowerBound(a, i, a[min]);\n loop invariant upper: UpperBound(a, i, a[max]);\n loop invariant first: StrictLowerBound(a, min, a[min]);\n loop invariant last: StrictUpperBound(a, max+1, i, a[max]);\n loop assigns min, max, i;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; i++) {\n if (a[i] >= a[max]) {\n max = i;\n }\n if (a[i] < a[min]) {\n min = i;\n }\n }\n //@ assert MinElement(a, n, min) && MaxElement(a, n, max);\n return make_pair(min, max);\n }\n return make_pair(n, n);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "axiom_size_of_init", "file_name": "axiom_size_of_init", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s);\n requires capacity: 0 < capacity;\n requires storage: \\valid(storage + (0..capacity-1));\n requires sep: \\separated(s, storage + (0..capacity-1));\n assigns s->obj, s->capacity, s->size;\n ensures valid: \\valid(s);\n ensures capacity: StackCapacity(s) == capacity;\n ensures storage: StackStorage(s) == storage;\n ensures invariant: StackInvariant(s);\n ensures empty: StackEmpty(s);\n*/\nvoid\nstack_init(Stack* s, value_type* storage, size_type capacity);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\nsize_type\naxiom_size_of_init(Stack* s, value_type* a, size_type n)\n{\n stack_init(s, a, n);\n //@ assert StackSize(s) == 0;\n return stack_size(s);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s);\n requires capacity: 0 < capacity;\n requires storage: \\valid(storage + (0..capacity-1));\n requires sep: \\separated(s, storage + (0..capacity-1));\n assigns s->obj, s->capacity, s->size;\n ensures valid: \\valid(s);\n ensures capacity: StackCapacity(s) == capacity;\n ensures storage: StackStorage(s) == storage;\n ensures invariant: StackInvariant(s);\n ensures empty: StackEmpty(s);\n*/\nvoid\nstack_init(Stack* s, value_type* storage, size_type capacity);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\n/*@\n requires valid: \\valid(s);\n requires valid: \\valid(a + (0..n-1));\n requires sep: \\separated(s, a + (0..n-1));\n requires pos: 0 < n;\n assigns s->obj, s->capacity, s->size;\n ensures size: \\result == 0;\n ensures valid: StackInvariant(s);\n*/\nsize_type\naxiom_size_of_init(Stack* s, value_type* a, size_type n)\n{\n stack_init(s, a, n);\n //@ assert StackSize(s) == 0;\n return stack_size(s);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_max3", "file_name": "max3", "input": "int max3(int a, int b, int c)\n{\n\treturn a > b ? (a > c ? a : c) : (b > c ? b : c);\n}\nint main(){\n\tint a = 1;\n\tint b = 2;\n\tint c = 3;\n\tint d = max3(a, b, c);\n //@ assert d == 3;\n}", "output": "/*@ assigns \\nothing;\n ensures \\result == \\max(\\max(a, b), \\max(b, c));\n */\nint max3(int a, int b, int c)\n{\n\treturn a > b ? (a > c ? a : c) : (b > c ? b : c);\n}\nint main(){\n\tint a = 1;\n\tint b = 2;\n\tint c = 3;\n\tint d = max3(a, b, c);\n //@ assert d == 3;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_60", "file_name": "60", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c < 0) {\n if(c > n) {\n //@ assert c == n;\n }\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant c > 0 ==> c <= n;\n loop invariant c <= n;\n loop invariant 0 <= c;\n loop invariant (c == n) || (c < n);\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c < 0) {\n if(c > n) {\n //@ assert c == n;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "upper_bound", "file_name": "upper_bound", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic WeaklyIncreasing\n {\n predicate\n WeaklyIncreasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n-1 ==> a[i] <= a[i+1];\n predicate\n WeaklyIncreasing{L}(value_type* a, integer n) = WeaklyIncreasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Increasing\n {\n predicate\n Increasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i, j; m <= i < j < n ==> a[i] <= a[j];\n predicate\n Increasing{L}(value_type* a, integer n) = Increasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\nsize_type\nupper_bound(const value_type* a, size_type n, value_type v)\n{\n size_type left = 0u;\n size_type right = n;\n while (left < right) {\n const size_type middle = left + (right - left) / 2u;\n if (a[middle] <= v) {\n left = middle + 1u;\n }\n else {\n right = middle;\n }\n }\n //@ assert UpperBound(a, 0, right, v);\n return right;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic WeaklyIncreasing\n {\n predicate\n WeaklyIncreasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n-1 ==> a[i] <= a[i+1];\n predicate\n WeaklyIncreasing{L}(value_type* a, integer n) = WeaklyIncreasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Increasing\n {\n predicate\n Increasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i, j; m <= i < j < n ==> a[i] <= a[j];\n predicate\n Increasing{L}(value_type* a, integer n) = Increasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires increasing: Increasing(a, n);\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n ensures left: UpperBound(a, 0, \\result, v);\n ensures right: StrictLowerBound(a, \\result, n, v);\n*/\nsize_type\nupper_bound(const value_type* a, size_type n, value_type v)\n{\n size_type left = 0u;\n size_type right = n;\n /*@\n loop invariant bound: 0 <= left <= right <= n;\n loop invariant left: UpperBound(a, 0, left, v);\n loop invariant right: StrictLowerBound(a, right, n, v);\n loop assigns left, right;\n loop variant right - left;\n */\n while (left < right) {\n const size_type middle = left + (right - left) / 2u;\n if (a[middle] <= v) {\n left = middle + 1u;\n }\n else {\n right = middle;\n }\n }\n //@ assert UpperBound(a, 0, right, v);\n return right;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nikunjjain02_Arrays_7", "file_name": "Arrays_7", "input": "#include\n/*@\n\trequires n>=0&&\\valid_read(a+(0..n-1));\n\tassigns \\nothing;\n\tensures \\forall integer k;0<=k\\result>=a[k];\n*/\nint max(int a[], int n) {\n\tint max = a[0];\n\tint i = 0;\n\t/*@\n\t\tloop invariant 0<=i<=n;\n\t\tloop invariant \\forall integer k;0<=kmax>=a[k];\n\t\tloop assigns i,max;\n\t\tloop variant n-i;\n\t*/\n\twhile(imax) \n\t\t\tmax = a[i];\n\t\ti++;\n\t}\n\treturn max;\n}\nint min(int a[], int n) {\n\tint min = a[0];\n\tint i = 0;\n\twhile(i max_val >= a[k];\n\tint min_val = min(a, 6);\n\t//@ assert \\forall integer k; 0 <= k < 6 ==> min_val <= a[k];\n}", "output": "#include\n/*@\n\trequires n>=0&&\\valid_read(a+(0..n-1));\n\tassigns \\nothing;\n\tensures \\forall integer k;0<=k\\result>=a[k];\n*/\nint max(int a[], int n) {\n\tint max = a[0];\n\tint i = 0;\n\t/*@\n\t\tloop invariant 0<=i<=n;\n\t\tloop invariant \\forall integer k;0<=kmax>=a[k];\n\t\tloop assigns i,max;\n\t\tloop variant n-i;\n\t*/\n\twhile(imax) \n\t\t\tmax = a[i];\n\t\ti++;\n\t}\n\treturn max;\n}\n/*@\n\trequires n>=0&&\\valid_read(a+(0..n-1));\n\tassigns \\nothing;\n\tensures \\forall integer k;0<=k\\result<=a[k];\n*/\nint min(int a[], int n) {\n\tint min = a[0];\n\tint i = 0;\n\t/*@\n\t\tloop invariant 0<=i<=n;\n\t\tloop invariant \\forall integer k;0<=kmin<=a[k];\n\t\tloop assigns i,min;\n\t\tloop variant n-i;\n\t*/\n\twhile(i max_val >= a[k];\n\tint min_val = min(a, 6);\n\t//@ assert \\forall integer k; 0 <= k < 6 ==> min_val <= a[k];\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "replace", "file_name": "replace", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Replace\n {\n predicate\n Replace{K,L}(value_type* a, integer n, value_type* b,\n value_type v, value_type w) =\n \\forall integer i; 0 <= i < n ==>\n \\let ai = \\at(a[i],K);\n \\let bi = \\at(b[i],L);\n (ai == v ==> bi == w) && (ai != v ==> bi == ai) ;\n predicate\n Replace{K,L}(value_type* a, integer n, value_type v, value_type w) =\n Replace{K,L}(a, n, a, v, w);\n }\n*/\nvoid\nreplace(value_type* a, size_type n, value_type v, value_type w)\n{\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] == v) {\n a[i] = w;\n }\n }\n //@ assert Replace{Pre,Here}(a, n, v, w);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Replace\n {\n predicate\n Replace{K,L}(value_type* a, integer n, value_type* b,\n value_type v, value_type w) =\n \\forall integer i; 0 <= i < n ==>\n \\let ai = \\at(a[i],K);\n \\let bi = \\at(b[i],L);\n (ai == v ==> bi == w) && (ai != v ==> bi == ai) ;\n predicate\n Replace{K,L}(value_type* a, integer n, value_type v, value_type w) =\n Replace{K,L}(a, n, a, v, w);\n }\n*/\n/*@\n requires valid: \\valid(a + (0..n-1));\n assigns a[0..n-1];\n ensures replace: Replace{Old,Here}(a, n, v, w);\n*/\nvoid\nreplace(value_type* a, size_type n, value_type v, value_type w)\n{\n /*@\n loop invariant bounds: 0 <= i <= n;\n loop invariant replace: Replace{Pre,Here}(a, i, v, w);\n loop invariant unchanged: Unchanged{Pre,Here}(a, i, n);\n loop assigns i, a[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] == v) {\n a[i] = w;\n }\n }\n //@ assert Replace{Pre,Here}(a, n, v, w);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "stack_top_wd", "file_name": "stack_top_wd", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures top: !StackEmpty(s) ==> \\result == StackTop(s);\n*/\nvalue_type\nstack_top(const Stack* s);\nbool\nstack_top_wd(const Stack* s, const Stack* t)\n{\n return stack_top(s) == stack_top(t);\n}\nint main(){\n Stack s1, s2;\n value_type arr1[3] = {1, 2, 3};\n value_type arr2[3] = {1, 2, 3};\n s1.obj = arr1;\n s1.capacity = 3;\n s1.size = 3;\n s2.obj = arr2;\n s2.capacity = 3;\n s2.size = 3;\n bool result = stack_top_wd(&s1, &s2);\n //@ assert result == true;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures top: !StackEmpty(s) ==> \\result == StackTop(s);\n*/\nvalue_type\nstack_top(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s) && !StackEmpty(s);\n requires valid: \\valid(t) && StackInvariant(t) && !StackEmpty(t);\n requires equal: StackEqual{Here,Here}(s, t);\n assigns \\nothing;\n ensures equal: \\result == true <==> StackTop(s) == StackTop(t);\n ensures not_equal: \\result == false <==> StackTop(s) != StackTop(t);\n*/\nbool\nstack_top_wd(const Stack* s, const Stack* t)\n{\n return stack_top(s) == stack_top(t);\n}\nint main(){\n Stack s1, s2;\n value_type arr1[3] = {1, 2, 3};\n value_type arr2[3] = {1, 2, 3};\n s1.obj = arr1;\n s1.capacity = 3;\n s1.size = 3;\n s2.obj = arr2;\n s2.capacity = 3;\n s2.size = 3;\n bool result = stack_top_wd(&s1, &s2);\n //@ assert result == true;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "axiom_pop_of_push", "file_name": "axiom_pop_of_push", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\nvoid\naxiom_pop_of_push(Stack* s, value_type v)\n{\n stack_push(s, v);\n stack_pop(s);\n //@ assert StackEqual{Pre,Here}(s, s);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires not_full: !StackFull(s);\n assigns s->size, s->obj[s->size];\n ensures equal: StackEqual{Old,Here}(s, s);\n*/\nvoid\naxiom_pop_of_push(Stack* s, value_type v)\n{\n stack_push(s, v);\n stack_pop(s);\n //@ assert StackEqual{Pre,Here}(s, s);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nikunjjain02_Arrays_1", "file_name": "Arrays_1", "input": "#include\nvoid reset(int* array,size_t length)\n{\n for(size_t i =0;i a[i] == 0;\n}", "output": "#include\n/*@\n requires \\valid(array +(0 .. length-1));\n assigns array[0..length-1];\n ensures \\forall size_t i; 0<= iarray[i] ==0;\n*/\nvoid reset(int* array,size_t length)\n{\n /*@\n loop invariant 0<= i<=length;\n loop invariant \\forall size_t j; 0<= j array[j] ==0;\n loop assigns i,array[0..length-1];\n loop variant length-i;\n */\n for(size_t i =0;i a[i] == 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arrays_and_loops_2", "file_name": "2", "input": "int arraymax(int* a, int n) {\n int i = 1;\n int max = a[0];\n while (i < n) {\n if (max < a[i])\n max = a[i];\n i = i + 1;\n }\n //@ assert \\forall integer k; 0 <= k < n ==> max >= a[k];\n return max;\n} ", "output": "/*@ \n requires \\valid_read(a + (0..n-1));\n requires n > 0;\n ensures \\forall integer k; 0 <= k < n ==> \\result >= a[k];\n ensures \\exists integer k; 0 <= k < n && \\result == a[k];\n assigns \\nothing;\n*/\nint arraymax(int* a, int n) {\n int i = 1;\n int max = a[0];\n /*@ \n loop invariant \\forall integer k; 0 <= k < i ==> max >= a[k];\n loop invariant \\exists integer k; 0 <= k < i && max == a[k];\n loop invariant 0 <= i <= n;\n loop assigns i,max;\n */\n while (i < n) {\n if (max < a[i])\n max = a[i];\n i = i + 1;\n }\n //@ assert \\forall integer k; 0 <= k < n ==> max >= a[k];\n return max;\n} ", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-acsl-implementation_1", "file_name": "1", "input": "void f(int n, int *p, int *q) {\n if (n > 0) *p = n;\n else *q = n;\n}\nint main(){\n int n = 10;\n int p = 1,q = 2;\n f(n, &p, &q);\n //@ assert p == 10;\n n = -10;\n f(n, &p, &q);\n //@ assert q == -10;\n}", "output": "/*@ behavior p_changed:\n assumes n > 0;\n requires \\valid(p);\n assigns *p;\n ensures *p == n;\n behavior q_changed:\n assumes n <= 0;\n requires \\valid(q);\n assigns *q;\n ensures *q == n;\n*/\nvoid f(int n, int *p, int *q) {\n if (n > 0) *p = n;\n else *q = n;\n}\nint main(){\n int n = 10;\n int p = 1,q = 2;\n f(n, &p, &q);\n //@ assert p == 10;\n n = -10;\n f(n, &p, &q);\n //@ assert q == -10;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_14", "file_name": "14", "input": "/*@\n requires 0 <= x <= 2;\n requires 0 <= y <= 2;\n*/\nvoid foo(int x, int y) {\n int z1;\n int z2;\n int z3;\n while (unknown()) {\n x = x + 2;\n y = y + 2;\n }\n if (y == 0) {\n //@ assert x != 4;\n }\n}", "output": "/*@\n requires 0 <= x <= 2;\n requires 0 <= y <= 2;\n*/\nvoid foo(int x, int y) {\n int z1;\n int z2;\n int z3;\n /*@\n loop invariant y == 0 ==> x != 4;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns x,y;\n */\n while (unknown()) {\n x = x + 2;\n y = y + 2;\n }\n if (y == 0) {\n //@ assert x != 4;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_126", "file_name": "126", "input": "void foo(int x, int y) {\n int i = x;\n int j = y;\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if (i == j) {\n //@ assert y == 0;\n }\n}", "output": "void foo(int x, int y) {\n int i = x;\n int j = y;\n /*@\n loop invariant y <= j;\n loop invariant x <= i;\n loop invariant j == y + i - x;\n loop invariant j - i == y - x;\n loop invariant i == x + j - y;\n loop invariant i - x == j - y;\n loop invariant \\forall integer k; 0 <= k < x ==> j - i - k == (j - i) - k;\n loop assigns x,y,i,j;\n */\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if (i == j) {\n //@ assert y == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_avr", "file_name": "avr", "input": "int avr(int a, int b)\n{\n\tint avr;\n\tif (a >= 0 && b >= 0) {\n\t\tif (b > a) {\n\t\t\tavr = a + (b - a) / 2;\n\t\t} else {\n\t\t\tavr = b + (a - b) / 2;\n\t\t}\n\t} else if (a < 0 && b < 0) {\n\t\tif (b > a) {\n\t\t\tavr = b + (a - b) / 2;\n\t\t} else {\n\t\t\tavr = a + (b - a) / 2;\n\t\t}\n\t} else {\n\t\tavr = (a + b) / 2;\n\t}\n\treturn avr;\n}\nint main(){\n\tint a = 10;\n\tint b = 20;\n\tint c = avr(a,b);\n\t//@ assert c == 15;\n}", "output": "/*@ assigns \\nothing;\n ensures \\result == (a + b) / 2;\n */\nint avr(int a, int b)\n{\n\tint avr;\n\tif (a >= 0 && b >= 0) {\n\t\tif (b > a) {\n\t\t\tavr = a + (b - a) / 2;\n\t\t} else {\n\t\t\tavr = b + (a - b) / 2;\n\t\t}\n\t} else if (a < 0 && b < 0) {\n\t\tif (b > a) {\n\t\t\tavr = b + (a - b) / 2;\n\t\t} else {\n\t\t\tavr = a + (b - a) / 2;\n\t\t}\n\t} else {\n\t\tavr = (a + b) / 2;\n\t}\n\treturn avr;\n}\nint main(){\n\tint a = 10;\n\tint b = 20;\n\tint c = avr(a,b);\n\t//@ assert c == 15;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "pointers_add_pointers_3_vars", "file_name": "add_pointers_3_vars", "input": "#include \nint add(int *a, int *b, int *r) {\n return *a + *b + *r;\n}\nint main() {\n int a = 24;\n int b = 32;\n int r = 12;\n int x;\n x = add(&a, &b, &r) ;\n //@ assert x == a + b + r;\n //@ assert x == 68 ;\n x = add(&a, &a, &a) ;\n //@ assert x == a + a + a;\n //@ assert x == 72 ;\n}", "output": "#include \n/*@\n requires \\valid_read(a) && \\valid_read(b) && \\valid_read(r);\n requires *a + *b + *r <= INT_MAX;\n requires *a + *b + *r >= INT_MIN;\n assigns \\nothing;\n ensures \\result == *a + *b + *r;\n*/\nint add(int *a, int *b, int *r) {\n return *a + *b + *r;\n}\nint main() {\n int a = 24;\n int b = 32;\n int r = 12;\n int x;\n x = add(&a, &b, &r) ;\n //@ assert x == a + b + r;\n //@ assert x == 68 ;\n x = add(&a, &a, &a) ;\n //@ assert x == a + a + a;\n //@ assert x == 72 ;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "search_n", "file_name": "search_n", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic AllSomeNot\n {\n predicate\n AllEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] == v;\n predicate\n AllEqual(value_type* a, integer m, integer n) =\n AllEqual(a, m, n, a[m]);\n predicate\n AllEqual(value_type* a, integer n, value_type v) =\n AllEqual(a, 0, n, v);\n predicate\n SomeNotEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] != v;\n predicate\n SomeNotEqual{A}(value_type* a, integer n, value_type v) =\n SomeNotEqual(a, 0, n, v);\n lemma NotAllEqual_SomeNotEqual:\n \\forall value_type *a, v, integer m, n;\n !AllEqual(a, m, n, v) ==> SomeNotEqual(a, m, n, v);\n lemma SomeNotEqual_NotAllEqual:\n \\forall value_type *a, v, integer m, n;\n SomeNotEqual(a, m, n, v) ==> !AllEqual(a, m, n, v);\n }\n*/\n/*@\n axiomatic HasConstantSubRange\n {\n predicate\n HasConstantSubRange{L}(value_type* a, integer m, integer n, value_type v, integer p) =\n \\exists integer k; m <= k <= n-p && AllEqual(a, k, k+p, v);\n predicate\n HasConstantSubRange{L}(value_type* a, integer n, value_type v, integer p) =\n HasConstantSubRange(a, 0, n, v, p);\n lemma HasConstantSubRange_Sizes:\n \\forall value_type *a, v, integer n, p;\n HasConstantSubRange(a, n, v, p) ==> p <= n;\n }\n*/\nsize_type\nsearch_n(const value_type* a, size_type n, value_type v, size_type p)\n{\n if (0u < p) {\n if (p <= n) {\n size_type start = 0u;\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] != v) {\n start = i + 1u;\n //@ assert not_found: !HasConstantSubRange(a, i+1, v, p);\n }\n else {\n //@ assert match: a[i] == v;\n //@ assert match: AllEqual(a, start, i+1, v);\n if (p == i + 1u - start) {\n //@ assert bound: start + p == i + 1;\n //@ assert match: AllEqual(a, start, start+p, v);\n //@ assert match: \\exists integer k; 0 <= k <= n-p && AllEqual(a, k, k+p, v);\n //@ assert match: HasConstantSubRange(a, n, v, p);\n return start;\n }\n else {\n //@ assert bound: i + 1 < start + p;\n continue;\n }\n }\n //@ assert not_found: !HasConstantSubRange(a, i+1, v, p);\n }\n //@ assert not_found: !HasConstantSubRange(a, n, v, p);\n return n;\n }\n else {\n //@ assert not_found: n < p;\n //@ assert not_found: !HasConstantSubRange(a, n, v, p);\n return n;\n }\n }\n else {\n //@ assert bound: p == 0;\n //@ assert match: AllEqual(a, 0, 0, v);\n //@ assert match: HasConstantSubRange(a, n, v, 0);\n return 0u;\n }\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic AllSomeNot\n {\n predicate\n AllEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] == v;\n predicate\n AllEqual(value_type* a, integer m, integer n) =\n AllEqual(a, m, n, a[m]);\n predicate\n AllEqual(value_type* a, integer n, value_type v) =\n AllEqual(a, 0, n, v);\n predicate\n SomeNotEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] != v;\n predicate\n SomeNotEqual{A}(value_type* a, integer n, value_type v) =\n SomeNotEqual(a, 0, n, v);\n lemma NotAllEqual_SomeNotEqual:\n \\forall value_type *a, v, integer m, n;\n !AllEqual(a, m, n, v) ==> SomeNotEqual(a, m, n, v);\n lemma SomeNotEqual_NotAllEqual:\n \\forall value_type *a, v, integer m, n;\n SomeNotEqual(a, m, n, v) ==> !AllEqual(a, m, n, v);\n }\n*/\n/*@\n axiomatic HasConstantSubRange\n {\n predicate\n HasConstantSubRange{L}(value_type* a, integer m, integer n, value_type v, integer p) =\n \\exists integer k; m <= k <= n-p && AllEqual(a, k, k+p, v);\n predicate\n HasConstantSubRange{L}(value_type* a, integer n, value_type v, integer p) =\n HasConstantSubRange(a, 0, n, v, p);\n lemma HasConstantSubRange_Sizes:\n \\forall value_type *a, v, integer n, p;\n HasConstantSubRange(a, n, v, p) ==> p <= n;\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior has_match:\n assumes HasConstantSubRange(a, n, v, p);\n assigns \\nothing;\n ensures result: 0 <= \\result <= n-p;\n ensures match: AllEqual(a, \\result, \\result+p, v);\n ensures first: !HasConstantSubRange(a, \\result+p-1, v, p);\n behavior no_match:\n assumes !HasConstantSubRange(a, n, v, p);\n assigns \\nothing;\n ensures result: \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nsearch_n(const value_type* a, size_type n, value_type v, size_type p)\n{\n if (0u < p) {\n if (p <= n) {\n size_type start = 0u;\n /*@\n loop invariant match: AllEqual(a, start, i, v);\n loop invariant start: 0 < start ==> a[start-1] != v;\n loop invariant bound: start <= i + 1 <= start + p;\n loop invariant not_found: !HasConstantSubRange(a, i, v, p);\n loop assigns i, start;\n loop variant n - i;\n */\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] != v) {\n start = i + 1u;\n //@ assert not_found: !HasConstantSubRange(a, i+1, v, p);\n }\n else {\n //@ assert match: a[i] == v;\n //@ assert match: AllEqual(a, start, i+1, v);\n if (p == i + 1u - start) {\n //@ assert bound: start + p == i + 1;\n //@ assert match: AllEqual(a, start, start+p, v);\n //@ assert match: \\exists integer k; 0 <= k <= n-p && AllEqual(a, k, k+p, v);\n //@ assert match: HasConstantSubRange(a, n, v, p);\n return start;\n }\n else {\n //@ assert bound: i + 1 < start + p;\n continue;\n }\n }\n //@ assert not_found: !HasConstantSubRange(a, i+1, v, p);\n }\n //@ assert not_found: !HasConstantSubRange(a, n, v, p);\n return n;\n }\n else {\n //@ assert not_found: n < p;\n //@ assert not_found: !HasConstantSubRange(a, n, v, p);\n return n;\n }\n }\n else {\n //@ assert bound: p == 0;\n //@ assert match: AllEqual(a, 0, 0, v);\n //@ assert match: HasConstantSubRange(a, n, v, 0);\n return 0u;\n }\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_absolute_value", "file_name": "absolute_value", "input": "#include \nint abs(int val) {\n if(val < 0) return -val;\n return val;\n}\nvoid foo(int a) {\n int b = abs(-42);\n //@ assert b == 42;\n int c = abs(42);\n //@ assert c == 42;\n int e = abs(INT_MIN);\n}", "output": "#include \n/*@ \n requires INT_MIN <= val < INT_MAX; \n ensures \\result >= 0;\n behavior positive:\n assumes val >= 0;\n ensures \\result == val;\n behavior negative:\n assumes val < 0;\n ensures \\result == -val;\n assigns \\nothing;\n*/\nint abs(int val) {\n if(val < 0) return -val;\n return val;\n}\nvoid foo(int a) {\n int b = abs(-42);\n //@ assert b == 42;\n int c = abs(42);\n //@ assert c == 42;\n int e = abs(INT_MIN);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_39", "file_name": "39", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if(c == n) {\n c = 1;\n }\n else {\n c = c + 1;\n }\n }\n if(c == n) {\n //@ assert c >= 0;\n //@ assert c <= n;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant c <= n;\n loop invariant 0 <= c;\n loop assigns c;\n */\n while (unknown()) {\n if(c == n) {\n c = 1;\n }\n else {\n c = c + 1;\n }\n }\n if(c == n) {\n //@ assert c >= 0;\n //@ assert c <= n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_57", "file_name": "57", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (n > -1) {\n //@ assert c != n;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n-c;\n loop invariant n > -1 ==> c != n;\n loop invariant c >= 0 && c <= n+1;\n loop invariant 0 <= c <= n;\n loop invariant c != n;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (n > -1) {\n //@ assert c != n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "stack_size_wd", "file_name": "stack_size_wd", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\nbool\nstack_size_wd(const Stack* s, const Stack* t)\n{\n return stack_size(s) == stack_size(t);\n}\nint main(){\n value_type a[5] = {1, 2, 3, 4, 5};\n value_type b[5] = {1, 2, 3, 4, 5};\n Stack s1, s2;\n s1.capacity = 5;\n s1.size = 5;\n s1.obj = a;\n s2.capacity = 5;\n s2.size = 5;\n s2.obj = b;\n bool result = stack_size_wd(&s1, &s2);\n //@ assert result == true;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires valid: \\valid(t) && StackInvariant(t);\n requires equal: StackEqual{Here,Here}(s, t);\n assigns \\nothing;\n ensures equal: \\result == true <==> StackSize(s) == StackSize(t);\n ensures not_equal: \\result == false <==> StackSize(s) != StackSize(t);\n*/\nbool\nstack_size_wd(const Stack* s, const Stack* t)\n{\n return stack_size(s) == stack_size(t);\n}\nint main(){\n value_type a[5] = {1, 2, 3, 4, 5};\n value_type b[5] = {1, 2, 3, 4, 5};\n Stack s1, s2;\n s1.capacity = 5;\n s1.size = 5;\n s1.obj = a;\n s2.capacity = 5;\n s2.size = 5;\n s2.obj = b;\n bool result = stack_size_wd(&s1, &s2);\n //@ assert result == true;\n}\n", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "equal_arrays", "file_name": "equal_arrays", "input": "int check(int *a, int *b, int n) {\n for (int i = 0; i < n; i++) {\n if (a[i] != b[i]) {\n return 0;\n }\n }\n return 1;\n}\nint main() {\n int a[] = {1,2,3,4,5};\n int b[] = {1,2,3,4,5};\n int ans = check(a, b, 5);\n //@ assert ans == 1;\n}", "output": "/*@ \n requires n > 0;\n requires \\valid_read (a + (0..n-1));\n requires \\valid_read (b + (0..n-1));\n assigns \\nothing;\n behavior equal:\n assumes \\forall integer k; 0 <= k < n ==> b[k] == a[k];\n ensures \\result == 1;\n behavior not_equal:\n assumes \\exists integer k; 0 <= k < n && b[k] != a[k];\n ensures \\result == 0;\n*/\nint check(int *a, int *b, int n) {\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; 0 <= k < i ==> a[k] == b[k];\n loop assigns i;\n */\n for (int i = 0; i < n; i++) {\n if (a[i] != b[i]) {\n return 0;\n }\n }\n return 1;\n}\nint main() {\n int a[] = {1,2,3,4,5};\n int b[] = {1,2,3,4,5};\n int ans = check(a, b, 5);\n //@ assert ans == 1;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_85", "file_name": "85", "input": "int main() {\n int x = -15000;\n int y = 0;\n while (x < 0) {\n x = x + y;\n y = y + 1;\n }\n //@ assert y > 0;\n}", "output": "int main() {\n int x = -15000;\n int y = 0;\n /*@\n loop invariant x <= -15000 || 1 <= y;\n loop invariant x <= -15000 || 0 <= y;\n loop invariant x < 0 || 1 <= y;\n loop invariant x < 0 || 0 <= y;\n loop invariant x < 0 || -15000 <= x;\n loop invariant 1 <= y || x <= 0;\n loop invariant 1 <= y || 0 <= y;\n loop invariant 1 <= y || -15000 <= x;\n loop invariant 0 <= y || x <= 0;\n loop invariant 0 <= y || -15000 <= x;\n loop invariant -15000 <= x || x <= 0;\n loop assigns x,y;\n loop invariant 0 <= y;\n loop invariant -15000 <= x;\n */\n while (x < 0) {\n x = x + y;\n y = y + 1;\n }\n //@ assert y > 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_35", "file_name": "35", "input": "int unknown();\nint main() {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != 40) {\n c = c + 1;\n }\n } else {\n if (c == 40) {\n c = 1;\n }\n }\n }\n if (c != 40) {\n //@ assert c >= 0;\n }\n}", "output": "int unknown();\nint main() {\n int c = 0;\n /*@\n loop invariant c <= 40;\n loop invariant c != 40 ==> c >= 0;\n loop invariant 0 <= c;\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != 40) {\n c = c + 1;\n }\n } else {\n if (c == 40) {\n c = 1;\n }\n }\n }\n // post-condition\n if (c != 40) {\n //@ assert c >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Compute the GCD of two numbers with precondition and postcondition", "file_name": "Compute the GCD of two numbers with precondition and postcondition", "input": "#include \n/*@\n axiomatic GCD {\n logic integer Gcd(integer p, integer q);\n axiom Gcd1:\n \\forall integer m, n;\n m > n ==> Gcd(m,n) == Gcd(m-n, n);\n axiom Gcd2:\n \\forall integer m, n;\n n > m ==> Gcd(m,n) == Gcd(m, n-m);\n axiom Gcd3:\n \\forall integer m, n;\n m == n ==> Gcd(m,n) == m;\n }\n*/\nint gcd(int p, int q) {\nwhile (p != q) {\n if (p > q) \np = p - q;\n if (q > p) \nq = q - p;\n}\nreturn p;\n}\nint main() {\n int p = 48;\n int q = 18;\n int result = gcd(p, q);\n //@ assert result == 6;\n return 0;\n}", "output": "#include \n/*@\n axiomatic GCD {\n logic integer Gcd(integer p, integer q);\n axiom Gcd1:\n \\forall integer m, n;\n m > n ==> Gcd(m,n) == Gcd(m-n, n);\n axiom Gcd2:\n \\forall integer m, n;\n n > m ==> Gcd(m,n) == Gcd(m, n-m);\n axiom Gcd3:\n \\forall integer m, n;\n m == n ==> Gcd(m,n) == m;\n }\n*/\n/*@\n requires p >= 1;\n requires p >= 1;\n ensures \\result == Gcd(\\old(p), \\old(q));\n assigns \\nothing; \n*/\nint gcd(int p, int q) {\n/*@ loop invariant Gcd(p,q) == \n Gcd(\\at(p,Pre), \\at(q,Pre));\n loop assigns p, q;\n*/\nwhile (p != q) {\n if (p > q) \np = p - q;\n if (q > p) \nq = q - p;\n}\nreturn p;\n}\nint main() {\n int p = 48;\n int q = 18;\n int result = gcd(p, q);\n //@ assert result == 6;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "suman1406_Q1", "file_name": "Q1", "input": "int grade;\nint calculateGrade(int mark) {\n if (mark >= 1 && mark <= 100) {\n grade = 1;\n return grade;\n } else if (mark >= 101 && mark <= 200) {\n grade = 2;\n return grade;\n } else if (mark >= 201 && mark <= 300) {\n grade = 3;\n return grade;\n } else if (mark >= 301 && mark <= 400) {\n grade = 4;\n return grade;\n }\n return 0;\n}", "output": "int grade;\n/*@ requires mark >= 0;\n ensures \\result == 0 || \\result == 1 || \\result == 2 || \\result == 3 || \\result == 4;\n behavior one:\n assumes mark >= 1 && mark <= 100;\n ensures \\result == 1;\n assigns grade;\n behavior two:\n assumes mark >= 101 && mark <= 200;\n ensures \\result == 2;\n assigns grade;\n behavior three:\n assumes mark >= 201 && mark <= 300;\n ensures \\result == 3;\n assigns grade;\n behavior four:\n assumes mark >= 301 && mark <= 400;\n ensures \\result == 4;\n assigns grade;\n behavior else:\n assumes mark <= 0 || mark > 400;\n ensures \\result == 0;\n assigns grade; \n complete behaviors;\n disjoint behaviors;\n*/\nint calculateGrade(int mark) {\n if (mark >= 1 && mark <= 100) {\n grade = 1;\n return grade;\n } else if (mark >= 101 && mark <= 200) {\n grade = 2;\n return grade;\n } else if (mark >= 201 && mark <= 300) {\n grade = 3;\n return grade;\n } else if (mark >= 301 && mark <= 400) {\n grade = 4;\n return grade;\n }\n return 0;\n}\nint main(){\n int mark = 150;\n int result = calculateGrade(mark);\n //@ assert result == 2;\n return 0;\n\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_41", "file_name": "41", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if ( unknown() ) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c <= n;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n - c;\n loop invariant c <= n;\n loop invariant c <= n + 1;\n loop invariant 0 <= c;\n loop assigns c;\n */\n while (unknown()) {\n if ( unknown() ) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c <= n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_proved_sign", "file_name": "sign", "input": "int spec_sign(int x)\n{\n return (x > 0) - (x < 0);\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int res = spec_sign(-10);\n //@ assert res == -1;\n return 0;\n}\n#endif", "output": "/*@ \n assigns \\nothing;\n ensures \\result == 0 || \\result == 1 || \\result == -1;\n behavior positive:\n assumes x > 0;\n ensures \\result == 1;\n behavior zero:\n assumes x == 0;\n ensures \\result == 0;\n behavior negative:\n assumes x < 0;\n ensures \\result == -1;\n complete behaviors;\n disjoint behaviors;\n */\nint spec_sign(int x)\n{\n return (x > 0) - (x < 0);\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int res = spec_sign(-10);\n //@ assert res == -1;\n return 0;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "X509-parser_check_ia5_string", "file_name": "check_ia5_string", "input": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n#define X509_FILE_NUM 1 \n#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000))\nstatic int check_ia5_string(const u8 *buf, u32 len)\n{\n\tint ret;\n\tu32 i;\n\tif ((buf == NULL) || (len == 0)) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tfor (i = 0; i < len; i++) {\n\t\tif (buf[i] > 0x7f) {\n\t\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\t\tgoto out;\n\t\t}\n\t}\n\tret = 0;\nout:\n\treturn ret;\n}\nint main() {\n\tu8 buf[5];\n\tu32 len = 5;\n\tint ret = check_ia5_string(&buf[0], len);\n\t//@ assert ret == -X509_FILE_LINE_NUM_ERR ==> \\exists integer i; 0 <= i < len && buf[i] > 0x7f;\n\t//@ assert ret == 0 ==> \\forall integer i; 0 <= i < len ==> (buf[i] <= 0x7f);\n\treturn ret;\n}", "output": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n#define X509_FILE_NUM 1\n#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000))\n/*@\n requires buf != NULL && len > 0;\n requires ((len > 0) && (buf != \\null)) ==> \\valid_read(buf + (0 .. (len - 1)));\n ensures \\result < 0 || \\result == 0;\n ensures (len == 0) ==> \\result < 0;\n ensures (buf == \\null) ==> \\result < 0;\n ensures \\result == 0 ==> \\forall integer i; 0 <= i < len ==> (buf[i] <= 0x7f);\n ensures \\result == -X509_FILE_LINE_NUM_ERR ==> \\exists integer i; 0 <= i < len && buf[i] > 0x7f;\n ensures \\exists integer i; 0 <= i < len && buf[i] > 0x7f ==> \\result == -X509_FILE_LINE_NUM_ERR;\n assigns \\nothing;\n*/\nstatic int check_ia5_string(const u8 *buf, u32 len)\n{\n\tint ret;\n\tu32 i;\n\tif ((buf == NULL) || (len == 0)) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\t/*@\n\t loop invariant \\forall integer x ; 0 <= x < i ==> (buf[x] <= 0x7f);\n\t loop invariant ret ==0 ==> \\forall integer x ; 0 <= x < i ==> (buf[x] <= 0x7f);\n\t loop assigns i;\n\t loop variant (len - i);\n\t*/\n\tfor (i = 0; i < len; i++) {\n\t\tif (buf[i] > 0x7f) {\n\t\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\t\tgoto out;\n\t\t}\n\t}\n\tret = 0;\nout:\n\treturn ret;\n}\nint main() {\n\tu8 buf[5];\n\tu32 len = 5;\n\tint ret = check_ia5_string(&buf[0], len);\n\t//@ assert ret == -X509_FILE_LINE_NUM_ERR ==> \\exists integer i; 0 <= i < len && buf[i] > 0x7f;\n\t//@ assert ret == 0 ==> \\forall integer i; 0 <= i < len ==> (buf[i] <= 0x7f);\n\treturn ret;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_118", "file_name": "118", "input": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n while (i <= size) {\n i = i + 1;\n sn = sn + 1;\n }\n if(sn != size) {\n //@ assert sn == 0;\n }\n}", "output": "/*@\nrequires size >= 1;\n*/\nvoid foo(int size) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= size+1;\n loop invariant i <= size + 1;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= size) {\n i = i + 1;\n sn = sn + 1;\n }\n if(sn != size) {\n //@ assert sn == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_max_of_2", "file_name": "max_of_2", "input": "#include \nint max ( int x, int y ) {\n if ( x >=y ) \n return x ;\n return y ;\n}\nvoid foo()\n{\n int s = max(34,45);\n //@ assert s==45;\n int t = max(-43,34);\n //@ assert t==34;\n}", "output": "#include \n/*@\nrequires INT_MIN=x && \\result>=y;\nensures \\result==x || \\result==y; \n*/\nint max ( int x, int y ) {\n if ( x >=y ) \n return x ;\n return y ;\n}\nvoid foo()\n{\n int s = max(34,45);\n //@ assert s==45;\n int t = max(-43,34);\n //@ assert t==34;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "X509-parser_parse_null", "file_name": "parse_null", "input": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n#define X509_FILE_NUM 0 \n#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)\n/*@\n predicate bmatch(u8 *b1, u8 *b2, u32 n) =\n \\forall integer i; 0 <= i < n ==> b1[i] == b2[i];\n \n predicate bdiffer(u8 *b1, u8 *b2, u32 n) =\n ! bmatch(b1, b2, n);\n*/\n/*@\n requires \\valid_read(b1 + (0 .. n-1));\n requires \\valid_read(b2 + (0 .. n-1));\n requires n >= 0;\n ensures \\result == 0 <==> bmatch(b1, b2, n);\n ensures \\result == 1 <==> bdiffer(b1, b2, n);\n assigns \\nothing;\n*/\nint bufs_differ(const u8 *b1, const u8 *b2, u32 n)\n{\n\tint ret = 0;\n\tu32 i = 0;\n\t/*@\n\t loop invariant 0 <= i <= n;\n\t loop invariant bmatch(b1, b2, i);\n\t loop assigns i;\n\t loop variant n - i;\n\t*/\n\tfor (i = 0; i < n; i++) {\n\t\tif(b1[i] != b2[i]) {\n\t\t\tret = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn ret;\n}\nstatic const u8 null_encoded_val[] = { 0x05, 0x00 };\nint parse_null(const u8 *buf, u32 len, u32 *parsed)\n{\n\tint ret;\n\tif ((len == 0) || (buf == NULL) || (parsed == NULL)) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tif (len != sizeof(null_encoded_val)) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tret = bufs_differ(buf, null_encoded_val, sizeof(null_encoded_val));\n\tif (ret) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tret = 0;\n\t*parsed = sizeof(null_encoded_val);\nout:\n\treturn ret;\n}\nint main() {\n const u8 b[] = { 0x05, 0x00 };\n u32 parsed;\n int ret = parse_null(b, sizeof(null_encoded_val), &parsed);\n //@ assert parsed == sizeof(null_encoded_val);\n //@ assert ret == 0;\n return 0;\n}", "output": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n#define X509_FILE_NUM 0 \n#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)\n/*@\n predicate bmatch(u8 *b1, u8 *b2, u32 n) =\n \\forall integer i; 0 <= i < n ==> b1[i] == b2[i];\n \n predicate bdiffer(u8 *b1, u8 *b2, u32 n) =\n ! bmatch(b1, b2, n);\n*/\n/*@\n requires \\valid_read(b1 + (0 .. n-1));\n requires \\valid_read(b2 + (0 .. n-1));\n requires n >= 0;\n ensures \\result == 0 <==> bmatch(b1, b2, n);\n ensures \\result == 1 <==> bdiffer(b1, b2, n);\n assigns \\nothing;\n*/\nint bufs_differ(const u8 *b1, const u8 *b2, u32 n)\n{\n\tint ret = 0;\n\tu32 i = 0;\n\t/*@\n\t loop invariant 0 <= i <= n;\n\t loop invariant bmatch(b1, b2, i);\n\t loop assigns i;\n\t loop variant n - i;\n\t*/\n\tfor (i = 0; i < n; i++) {\n\t\tif(b1[i] != b2[i]) {\n\t\t\tret = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn ret;\n}\nstatic const u8 null_encoded_val[] = { 0x05, 0x00 };\n/*@\n requires ((len > 0) && (buf != \\null)) ==> \\valid_read(buf + (0 .. (len - 1)));\n requires (parsed != NULL) ==> \\valid(parsed);\n requires \\separated(parsed, buf+(..));\n ensures \\result < 0 || \\result == 0;\n ensures (len == sizeof(null_encoded_val) && len != 0 && buf != NULL && parsed != NULL) ==> (\\result == 0 <==> bmatch(buf, &null_encoded_val[0], len));\n ensures (\\result == 0) ==> *parsed == 2;\n ensures (buf == \\null) ==> \\result < 0;\n assigns *parsed;\n*/\nint parse_null(const u8 *buf, u32 len, u32 *parsed)\n{\n\tint ret;\n\tif ((len == 0) || (buf == NULL) || (parsed == NULL)) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tif (len != sizeof(null_encoded_val)) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tret = bufs_differ(buf, null_encoded_val, sizeof(null_encoded_val));\n\tif (ret) {\n\t\tret = -X509_FILE_LINE_NUM_ERR;\n\t\tgoto out;\n\t}\n\tret = 0;\n\t*parsed = sizeof(null_encoded_val);\nout:\n\treturn ret;\n}\nint main() {\n const u8 b[] = { 0x05, 0x00 };\n u32 parsed;\n int ret = parse_null(b, sizeof(null_encoded_val), &parsed);\n //@ assert parsed == sizeof(null_encoded_val);\n //@ assert ret == 0;\n return 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_81", "file_name": "81", "input": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n while (unknown()) {\n if ( (i < y) )\n {\n (i = (i + 1));\n }\n }\n if (i < y) {\n //@ assert 0 <= i;\n }\n}", "output": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n /*@\n loop invariant i <= y;\n loop invariant 0 <= i;\n loop assigns y,i;\n */\n while (unknown()) {\n if ( (i < y) )\n {\n (i = (i + 1));\n }\n }\n if (i < y) {\n //@ assert 0 <= i;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_sort-3", "file_name": "sort-3", "input": "void order_3(int* a, int* b, int* c){\n if(*a > *b){\n int tmp = *b ; *b = *a ; *a = tmp ;\n }\n if(*a > *c){\n int tmp = *c ; *c = *a ; *a = tmp ;\n }\n if(*b > *c){\n int tmp = *b ; *b = *c ; *c = tmp ;\n }\n}\nvoid test(){\n int a1 = 5, b1 = 3, c1 = 4 ;\n order_3(&a1, &b1, &c1); \n //@ assert a1 == 3 && b1 == 4 && c1 == 5 ;\n int a2 = 2, b2 = 2, c2 = 2 ;\n order_3(&a2, &b2, &c2) ;\n //@ assert a2 == 2 && b2 == 2 && c2 == 2 ;\n int a3 = 4, b3 = 3, c3 = 4 ; \n order_3(&a3, &b3, &c3) ;\n //@ assert a3 == 3 && b3 == 4 && c3 == 4 ;\n int a4 = 4, b4 = 5, c4 = 4 ;\n order_3(&a4, &b4, &c4) ;\n //@ assert a4 == 4 && b4 == 4 && c4 == 5 ;\n}", "output": "/*@ \n requires \\valid(a) && \\valid(b) && \\valid(c); \n requires \\separated(a, b, c); \n assigns *a, *b, *c; \n ensures sorted: *a <= *b <= *c ;\n ensures has_all_values: { *a, *b, *c } == \\old({ *a, *b, *c }) ;\n ensures \\old(*a == *b == *c) ==> *a == *b == *c ; \n ensures \\old(*a == *b < *c || *a == *c < *b || *b == *c < *a) ==> *a == *b ; \n ensures \\old(*a == *b > *c || *a == *c > *b || *b == *c > *a) ==> *b == *c ;\n*/\nvoid order_3(int* a, int* b, int* c){\n if(*a > *b){\n int tmp = *b ; *b = *a ; *a = tmp ;\n }\n if(*a > *c){\n int tmp = *c ; *c = *a ; *a = tmp ;\n }\n if(*b > *c){\n int tmp = *b ; *b = *c ; *c = tmp ;\n }\n}\nvoid test(){\n int a1 = 5, b1 = 3, c1 = 4 ;\n order_3(&a1, &b1, &c1); \n //@ assert a1 == 3 && b1 == 4 && c1 == 5 ;\n int a2 = 2, b2 = 2, c2 = 2 ;\n order_3(&a2, &b2, &c2) ;\n //@ assert a2 == 2 && b2 == 2 && c2 == 2 ;\n int a3 = 4, b3 = 3, c3 = 4 ; \n order_3(&a3, &b3, &c3) ;\n //@ assert a3 == 3 && b3 == 4 && c3 == 4 ;\n int a4 = 4, b4 = 5, c4 = 4 ;\n order_3(&a4, &b4, &c4) ;\n //@ assert a4 == 4 && b4 == 4 && c4 == 5 ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_swap", "file_name": "swap", "input": " void swap(int* a, int* b){\n int tmp = *a;\n *a = *b;\n *b = tmp;\n }\n int main(){\n int a = 42;\n int b = 37;\n swap(&a, &b);\n //@ assert a == 37 && b == 42;\n return 0;\n }", "output": " /*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b;\n ensures *a == \\old(*b);\n ensures *b == \\old(*a);\n */\n void swap(int* a, int* b){\n int tmp = *a;\n *a = *b;\n *b = tmp;\n }\n int main(){\n int a = 42;\n int b = 37;\n swap(&a, &b);\n //@ assert a == 37 && b == 42;\n return 0;\n }", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "count", "file_name": "count", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic UnchangedLemmas\n {\n lemma Unchanged_Shrink{K,L}:\n \\forall value_type *a, integer m, n, p, q;\n m <= p <= q <= n ==>\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{K,L}(a, p, q);\n lemma Unchanged_Extend{K,L}:\n \\forall value_type *a, integer n;\n Unchanged{K,L}(a, n) ==>\n \\at(a[n],K) == \\at(a[n],L) ==>\n Unchanged{K,L}(a, n+1);\n lemma Unchanged_Symmetric{K,L}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,K}(a, m, n);\n lemma Unchanged_Transitive{K,L,M}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,M}(a, m, n) ==>\n Unchanged{K,M}(a, m, n);\n }\n*/\n/*@\n axiomatic Count\n {\n logic integer\n Count(value_type* a, integer m, integer n, value_type v) =\n n <= m ? 0 : Count(a, m, n-1, v) + (a[n-1] == v ? 1 : 0);\n logic integer\n Count(value_type* a, integer n, value_type v) = Count(a, 0, n, v);\n lemma Count_Empty:\n \\forall value_type *a, v, integer m, n;\n n <= m ==> Count(a, m, n, v) == 0;\n lemma Count_Hit:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] == v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v) + 1;\n lemma Count_Miss:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] != v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v);\n lemma Count_One:\n \\forall value_type *a, v, integer m, n;\n m <= n ==> Count(a, m, n+1, v) == Count(a, m, n, v) + Count(a, n, n+1, v);\n lemma Count_Single{K,L}:\n \\forall value_type *a, *b, v, integer m, n;\n \\at(a[m],K) == \\at(b[n],L) ==>\n Count{K}(a, m, m+1, v) == Count{L}(b, n, n+1, v);\n lemma Count_Single_Bounds:\n \\forall value_type *a, v, integer n;\n 0 <= Count(a, n, n+1, v) <= 1;\n lemma Count_Single_Shift:\n \\forall value_type *a, v, integer n;\n 0 <= n ==> Count(a+n, 0, 1, v) == Count(a, n, n+1, v);\n }\n*/\nsize_type\ncount(const value_type* a, size_type n, value_type v)\n{\n size_type counted = 0u;\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] == v) {\n counted++;\n }\n }\n //@ assert Count(a, n, v) == counted;\n return counted;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic UnchangedLemmas\n {\n lemma Unchanged_Shrink{K,L}:\n \\forall value_type *a, integer m, n, p, q;\n m <= p <= q <= n ==>\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{K,L}(a, p, q);\n lemma Unchanged_Extend{K,L}:\n \\forall value_type *a, integer n;\n Unchanged{K,L}(a, n) ==>\n \\at(a[n],K) == \\at(a[n],L) ==>\n Unchanged{K,L}(a, n+1);\n lemma Unchanged_Symmetric{K,L}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,K}(a, m, n);\n lemma Unchanged_Transitive{K,L,M}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,M}(a, m, n) ==>\n Unchanged{K,M}(a, m, n);\n }\n*/\n/*@\n axiomatic Count\n {\n logic integer\n Count(value_type* a, integer m, integer n, value_type v) =\n n <= m ? 0 : Count(a, m, n-1, v) + (a[n-1] == v ? 1 : 0);\n logic integer\n Count(value_type* a, integer n, value_type v) = Count(a, 0, n, v);\n lemma Count_Empty:\n \\forall value_type *a, v, integer m, n;\n n <= m ==> Count(a, m, n, v) == 0;\n lemma Count_Hit:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] == v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v) + 1;\n lemma Count_Miss:\n \\forall value_type *a, v, integer n, m;\n m < n ==>\n a[n-1] != v ==>\n Count(a, m, n, v) == Count(a, m, n-1, v);\n lemma Count_One:\n \\forall value_type *a, v, integer m, n;\n m <= n ==> Count(a, m, n+1, v) == Count(a, m, n, v) + Count(a, n, n+1, v);\n lemma Count_Single{K,L}:\n \\forall value_type *a, *b, v, integer m, n;\n \\at(a[m],K) == \\at(b[n],L) ==>\n Count{K}(a, m, m+1, v) == Count{L}(b, n, n+1, v);\n lemma Count_Single_Bounds:\n \\forall value_type *a, v, integer n;\n 0 <= Count(a, n, n+1, v) <= 1;\n lemma Count_Single_Shift:\n \\forall value_type *a, v, integer n;\n 0 <= n ==> Count(a+n, 0, 1, v) == Count(a, n, n+1, v);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures bound: 0 <= \\result <= n;\n ensures count: \\result == Count(a, n, v);\n*/\nsize_type\ncount(const value_type* a, size_type n, value_type v)\n{\n size_type counted = 0u;\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant bound: 0 <= counted <= i;\n loop invariant count: counted == Count(a, i, v);\n loop assigns i, counted;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] == v) {\n counted++;\n }\n }\n //@ assert Count(a, n, v) == counted;\n return counted;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_87", "file_name": "87", "input": "void foo(int x, int y) {\n int lock = 1;\n while ((x != y)) {\n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1;\n }\n }\n //@ assert lock == 1;\n}", "output": "/*@\nrequires x == y;\n*/\nvoid foo(int x, int y) {\n int lock = 1;\n /*@\n loop invariant x == y;\n loop invariant lock == 1;\n loop invariant lock == 1 || lock == 0;\n loop invariant lock == 0 || lock == 1;\n loop assigns y;\n loop assigns x;\n loop assigns lock;\n */\n while ((x != y)) {\n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1;\n }\n }\n //@ assert lock == 1;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_55", "file_name": "55", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) { \n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > n) {\n //@ assert c == n;\n }\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n - c;\n loop invariant c >= 0 && c <= n;\n loop invariant c > n ==> c == n;\n loop invariant c > n ==> c == n + 1;\n loop invariant c <= n;\n loop invariant \\forall integer k; 1 <= k <= c ==> (\\exists integer i; 1 <= i <= n && i == c);\n loop invariant 0 <= c;\n loop assigns n,c;\n */\n while (unknown()) { \n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > n) {\n //@ assert c == n;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arrays_and_loops_5", "file_name": "5", "input": "int fun(int x, int y , int *r) {\n *r = x;\n int d = 0;\n while (*r >= y) {\n *r = *r - y;\n d = d + 1;\n }\n return d;\n}\nint main() {\n int a = 3;\n int num = fun(1, 2, &a);\n //@ assert a == 1;\n //@ assert num == 0;\n return 0;\n}", "output": "/*@\n requires x ==1 && y==2;\n ensures *r < y;\n ensures \\result == 0 <==> x < y;\n ensures x == \\result*y + *r;\n ensures \\result ==0 ==> x == *r;\n*/\nint fun(int x, int y , int *r) {\n *r = x;\n int d = 0;\n /*@\n loop invariant d >= 0;\n loop invariant *r <= x;\n loop invariant *r < y ==> d == 0;\n loop invariant *r == x - y*d;\n loop assigns *r, d;\n */\n while (*r >= y) {\n *r = *r - y;\n d = d + 1;\n }\n return d;\n}\nint main() {\n int a = 3;\n int num = fun(1, 2, &a);\n //@ assert a == 1;\n //@ assert num == 0;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_4a", "file_name": "BL.EN.U4CSE21176_4a", "input": "#include\nint check(int n){\nif(n%3==0)\nreturn 1;\nelse\nreturn 0;\n}\nint main(){\nint a=9;\nint r=check(a);\n//@assert a==9;\n}", "output": "#include\n/*@\nrequires INT_MIN<=n;\nrequires INT_MAX>n;\nensures (n%3==0 ==> \\result==1) && (n%3!=0 ==> \\result==0);\n*/\nint check(int n){\nif(n%3==0)\nreturn 1;\nelse\nreturn 0;\n}\nint main(){\nint a=9;\nint r=check(a);\n//@assert a==9;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_130", "file_name": "130", "input": "void foo(int x2, int x3) {\n int d1 = 1;\n int d2 = 1;\n int d3 = 1;\n int x1 = 1;\n while(x1 > 0) {\n if(x2 > 0) {\n if(x3 > 0) {\n x1 = x1 - d1;\n x2 = x2 - d2;\n x3 = x3 - d3;\n }\n }\n }\n //@ assert x2 >= 0;\n}", "output": "void foo(int x2, int x3) {\n int d1 = 1;\n int d2 = 1;\n int d3 = 1;\n int x1 = 1;\n /*@\n loop invariant x1 > 0 || (x2 >= 0 && x3 >= 0);\n loop invariant x1 > 0 ==> (x2 > 0 ==> x3 > 0 ==> x1 - d1 >= 0 && x2 - d2 >= 0 && x3 - d3 >= 0);\n loop invariant x1 > 0 ==> (x2 > 0 ==> x3 > 0 ==> x1 - d1 < x1 && x2 - d2 < x2 && x3 - d3 < x3);\n loop invariant d3 == 1;\n loop invariant d2 == 1;\n loop invariant d1 == 1;\n loop invariant 0 <= x1;\n loop invariant (x2 > 0 && x3 > 0) || (x2 <= 0 || x3 <= 0);\n loop assigns x1,x2,x3,d1,d2,d3;\n */\n while(x1 > 0) {\n if(x2 > 0) {\n if(x3 > 0) {\n x1 = x1 - d1;\n x2 = x2 - d2;\n x3 = x3 - d3;\n }\n }\n }\n //@ assert x2 >= 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "remove_copy", "file_name": "remove_copy", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic SomeNone\n {\n predicate\n SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] == v;\n predicate\n SomeEqual{A}(value_type* a, integer n, value_type v) =\n SomeEqual(a, 0, n, v);\n predicate\n NoneEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] != v;\n predicate\n NoneEqual(value_type* a, integer n, value_type v) =\n NoneEqual(a, 0, n, v);\n lemma NotSomeEqual_NoneEqual:\n \\forall value_type *a, v, integer m, n;\n !SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);\n lemma NoneEqual_NotSomeEqual:\n \\forall value_type *a, v, integer m, n;\n NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);\n }\n*/\nsize_type\nremove_copy(const value_type *a, size_type n, value_type *b, value_type v)\n{\n size_type k = 0u;\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] != v) {\n b[k++] = a[i];\n }\n }\n //@ assert NoneEqual(b, k, v);\n return k;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic SomeNone\n {\n predicate\n SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =\n \\exists integer i; m <= i < n && a[i] == v;\n predicate\n SomeEqual{A}(value_type* a, integer n, value_type v) =\n SomeEqual(a, 0, n, v);\n predicate\n NoneEqual(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] != v;\n predicate\n NoneEqual(value_type* a, integer n, value_type v) =\n NoneEqual(a, 0, n, v);\n lemma NotSomeEqual_NoneEqual:\n \\forall value_type *a, v, integer m, n;\n !SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);\n lemma NoneEqual_NotSomeEqual:\n \\forall value_type *a, v, integer m, n;\n NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a + (0..n-1), b + (0..n-1));\n assigns b[0..n-1];\n ensures bound: 0 <= \\result <= n;\n ensures discard: NoneEqual(b, \\result, v);\n ensures unchanged: Unchanged{Old,Here}(a, n);\n ensures unchanged: Unchanged{Old,Here}(b, \\result, n);\n*/\nsize_type\nremove_copy(const value_type *a, size_type n, value_type *b, value_type v)\n{\n size_type k = 0u;\n /*@\n loop invariant bound: 0 <= k <= i <= n;\n loop invariant discard: NoneEqual(b, k, v);\n loop invariant unchanged: Unchanged{Pre,Here}(b, k, n);\n loop assigns k, i, b[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n if (a[i] != v) {\n b[k++] = a[i];\n }\n }\n //@ assert NoneEqual(b, k, v);\n return k;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_113", "file_name": "113", "input": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == n;\n }\n}", "output": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= n+1;\n loop invariant i <= n + 1;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_38", "file_name": "38", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if(c == n) {\n c = 1;\n }\n else {\n c = c + 1;\n }\n }\n if(c == n) {\n //@ assert c >= 0;\n //@ assert c <= n;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant c <= n;\n loop invariant 0 <= c;\n loop invariant (c == n) ==> (c >= 0 && c <= n);\n loop assigns c;\n */\n while (unknown()) {\n if(c == n) {\n c = 1;\n }\n else {\n c = c + 1;\n }\n }\n if(c == n) {\n //@ assert c >= 0;\n //@ assert c <= n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_distance_abs", "file_name": "distance_abs", "input": "#define SPEC_INT_MIN -2147483648\n#define SPEC_INT_MAX 2147483647\nunsigned distance_abs(int a, int b)\n{\n unsigned ua = a < 0 ? -a : a;\n unsigned ub = b < 0 ? -b : b;\n return ua > ub ? ua - ub : ub - ua;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = distance_abs(3, 30);\n int b = distance_abs(-5, -20);\n int c = distance_abs(7, -10);\n int d = distance_abs(-2, 15);\n //@ assert a == 27;\n //@ assert b == 15;\n //@ assert c == 17;\n //@ assert d == 17;\n return 0;\n}\n#endif", "output": "#define SPEC_INT_MIN -2147483648\n#define SPEC_INT_MAX 2147483647\n/*@ requires \\true;\n requires a > SPEC_INT_MIN; \n requires b > SPEC_INT_MIN; \n assigns \\nothing;\n ensures \\result == \\abs(\\abs(a) - \\abs(b));\n */\nunsigned distance_abs(int a, int b)\n{\n unsigned ua = a < 0 ? -a : a;\n unsigned ub = b < 0 ? -b : b;\n return ua > ub ? ua - ub : ub - ua;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = distance_abs(3, 30);\n int b = distance_abs(-5, -20);\n int c = distance_abs(7, -10);\n int d = distance_abs(-2, 15);\n //@ assert a == 27;\n //@ assert b == 15;\n //@ assert c == 17;\n //@ assert d == 17;\n return 0;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "suman1406_Q5", "file_name": "Q5", "input": "#include \nint equ(int a[], int b[], int n)\n{\n for (int i = 0; i < n; i++)\n {\n if (a[i] != b[i])\n {\n return 0;\n }\n }\n return 1;\n}\nint main(){\n int a[10]={1,2,3,4,5,6,7,8,9,10};\n int b[10]={1,2,3,4,5,6,7,8,9,10};\n int c[10]={1,2,3,4,5,6,7,8,9,11};\n\n int res=equ(a,b,10);\n int res1=equ(a,c,10);\n //@ assert res==1;\n //@ assert res1==0;\n}", "output": "#include \n/*@\nrequires n>0 && n a[j]==b[j];\n ensures \\result==1;\nbehavior notones:\n assumes \\exists integer j;0<=j a[j]==b[j];\n loop assigns i;\n loop variant n-i;\n */\n for (int i = 0; i < n; i++)\n {\n if (a[i] != b[i])\n {\n return 0;\n }\n }\n return 1;\n}\nint main(){\n int a[10]={1,2,3,4,5,6,7,8,9,10};\n int b[10]={1,2,3,4,5,6,7,8,9,10};\n int c[10]={1,2,3,4,5,6,7,8,9,11};\n\n int res=equ(a,b,10);\n int res1=equ(a,c,10);\n //@ assert res==1;\n //@ assert res1==0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_91", "file_name": "91", "input": "int main(){\n int x = 0;\n int y = 0;\n while(y >= 0){\n y = y + x;\n }\n //@ assert y >= 0;\n}", "output": "int main(){\n int x = 0;\n int y = 0;\n /*@\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while(y >= 0){\n y = y + x;\n }\n //@ assert y >= 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "X509-parser_time_components_to_comparable_u64", "file_name": "time_components_to_comparable_u64", "input": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\nu64 time_components_to_comparable_u64(u16 na_year, u8 na_month, u8 na_day,\n\t\t\t\t u8 na_hour, u8 na_min, u8 na_sec)\n{\n\tu64 res, tmp;\n\tres = ((u64)na_sec); \n\t/*@ assert res < (1ULL << 6); */\n\ttmp = ((u64)na_min) * (1ULL << 8); \n\t/*@ assert tmp < (1ULL << 14); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 15); */\n\ttmp = (((u64)na_hour) * (1ULL << 16)); \n\t/*@ assert tmp < (1ULL << 21); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 22); */\n\ttmp = ((u64)na_day) * (1ULL << 24); \n\t/*@ assert tmp < (1ULL << 29); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 30); */\n\ttmp = ((u64)na_month) * (1ULL << 32); \n\t/*@ assert tmp < (1ULL << 36); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 37); */\n\ttmp = ((u64)na_year) * (1ULL << 40); \n\t/*@ assert tmp < (1ULL << 54); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 55); */\n\treturn res;\n}\nint main(void)\n{\n\tu16 na_year = 2023; \n\tu8 na_month = 12; \n\tu8 na_day = 20;\n\tu8 na_hour = 12; \n\tu8 na_min = 00; \n\tu8 na_sec = 00;\n\tu64 res;\n\tres = time_components_to_comparable_u64(na_year, na_month, na_day, na_hour, na_min, na_sec);\n\t//@ assert res < (1ULL << 55);\n\treturn 0;\n}", "output": "#include \n#include \n#include \ntypedef uint8_t\t u8;\ntypedef uint16_t u16;\ntypedef uint32_t u32;\ntypedef uint64_t u64;\n/*@\n requires na_year <= 9999;\n requires na_month <= 12;\n requires na_day <= 31;\n requires na_hour <= 23;\n requires na_min <= 59;\n requires na_sec <= 59;\n ensures \\result < (1ULL << 55);\n assigns \\nothing;\n*/\nu64 time_components_to_comparable_u64(u16 na_year, u8 na_month, u8 na_day,\n\t\t\t\t u8 na_hour, u8 na_min, u8 na_sec)\n{\n\tu64 res, tmp;\n\tres = ((u64)na_sec); \n\t/*@ assert res < (1ULL << 6); */\n\ttmp = ((u64)na_min) * (1ULL << 8); \n\t/*@ assert tmp < (1ULL << 14); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 15); */\n\ttmp = (((u64)na_hour) * (1ULL << 16)); \n\t/*@ assert tmp < (1ULL << 21); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 22); */\n\ttmp = ((u64)na_day) * (1ULL << 24); \n\t/*@ assert tmp < (1ULL << 29); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 30); */\n\ttmp = ((u64)na_month) * (1ULL << 32); \n\t/*@ assert tmp < (1ULL << 36); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 37); */\n\ttmp = ((u64)na_year) * (1ULL << 40); \n\t/*@ assert tmp < (1ULL << 54); */\n\tres += tmp;\n\t/*@ assert res < (1ULL << 55); */\n\treturn res;\n}\nint main(void)\n{\n\tu16 na_year = 2023; \n\tu8 na_month = 12; \n\tu8 na_day = 20;\n\tu8 na_hour = 12; \n\tu8 na_min = 00; \n\tu8 na_sec = 00;\n\tu64 res;\n\tres = time_components_to_comparable_u64(na_year, na_month, na_day, na_hour, na_min, na_sec);\n\t//@ assert res < (1ULL << 55);\n\treturn 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_110", "file_name": "110", "input": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != n) {\n //@ assert sn == 0;\n }\n}", "output": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant sn <= n;\n loop invariant sn <= i-1;\n loop invariant i <= n+1;\n loop invariant i <= n + 1;\n loop invariant 1 <= i;\n loop invariant 0 <= sn;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != n) {\n //@ assert sn == 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "find", "file_name": "find", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nsize_type\nfind(const value_type* a, size_type n, value_type v)\n{\n for (size_type i = 0u; i < n; i++) {\n if (a[i] == v) {\n //@ assert \\exists integer k; 0 <= k < n && a[k] == v;\n return i;\n }\n }\n //@ assert \\forall integer k; 0 <= k < n ==> a[k] != v;\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n requires \\valid_read(a + (0..n-1));\n assigns \\nothing;\n ensures 0 <= \\result <= n;\n behavior some:\n assumes \\exists integer i; 0 <= i < n && a[i] == v;\n assigns \\nothing;\n ensures 0 <= \\result < n;\n ensures a[\\result] == v;\n ensures \\forall integer i; 0 <= i < \\result ==> a[i] != v;\n behavior none:\n assumes \\forall integer i; 0 <= i < n ==> a[i] != v;\n assigns \\nothing;\n ensures \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nfind(const value_type* a, size_type n, value_type v)\n{\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; 0 <= k < i ==> a[k] != v;\n loop assigns i;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; i++) {\n if (a[i] == v) {\n //@ assert \\exists integer k; 0 <= k < n && a[k] == v;\n return i;\n }\n }\n //@ assert \\forall integer k; 0 <= k < n ==> a[k] != v;\n return n;\n}\n", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_89", "file_name": "89", "input": "/*@\nrequires x == y;\n*/\nvoid foo(int x, int y) {\n int lock = 1;\n while (x != y) { \n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1; \n }\n }\n //@ assert lock == 1;\n}", "output": "/*@\nrequires x == y;\n*/\nvoid foo(int x, int y) {\n int lock = 1;\n /*@\n loop invariant x == y;\n loop invariant lock == 1;\n loop invariant lock == 1 || lock == 0;\n loop invariant lock == 0 || lock == 1;\n loop invariant lock != 1 ==> x == y;\n loop invariant (lock == 1) || (lock == 0);\n loop assigns x,y,lock;\n */\n while (x != y) { \n if (unknown()) {\n lock = 1;\n x = y;\n } else {\n lock = 0;\n x = y;\n y = y + 1; \n }\n }\n //@ assert lock == 1;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_65", "file_name": "65", "input": "int main() {\n int x = 1;\n int y = 0;\n while (x <= 100) {\n y = 100 - x;\n x = x +1;\n }\n //@ assert y >= 0;\n}", "output": "int main() {\n int x = 1;\n int y = 0;\n /*@\n loop invariant y <= 100;\n loop invariant 0 <= y;\n loop invariant -99 <= y;\n loop invariant x <= 101;\n loop invariant 1 <= x;\n loop invariant 0 <= x;\n loop assigns y,x;\n */\n while (x <= 100) {\n y = 100 - x;\n x = x +1;\n }\n //@ assert y >= 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_days", "file_name": "days", "input": "int day_of(int month){\n int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } ;\n return days[month-1] ;\n}\nint main(){\n int days2 = day_of(2);\n //@ assert days2 == 28;\n int days7 = day_of(7);\n //@ assert days7 == 31;\n}", "output": "/*@ \n requires input_range: 1 <= month <= 12; \n assigns \\nothing; \n ensures result_options: \\result \\in {28, 30, 31}; \n behavior day_28:\n assumes month == 2;\n ensures \\result == 28; \n behavior day_30:\n assumes month \\in { 4, 6, 9, 11 } ;\n ensures \\result == 30; \n behavior days_31:\n assumes month \\in {1, 3, 5, 7, 8, 10, 12};\n ensures \\result == 31; \n complete behaviors; \n disjoint behaviors; \n*/\nint day_of(int month){\n int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } ;\n return days[month-1] ;\n}\nint main(){\n int days2 = day_of(2);\n //@ assert days2 == 28;\n int days7 = day_of(7);\n //@ assert days7 == 31;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "mismatch", "file_name": "mismatch", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\nsize_type\nmismatch(const value_type* a, size_type n, const value_type* b)\n{\n for (size_type i = 0u; i < n; i++) {\n if (a[i] != b[i]) {\n //@ assert !Equal{Here,Here}(a, n, b);\n return i;\n }\n }\n //@ assert Equal{Here,Here}(a, n, b);\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid_read(b + (0..n-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior all_equal:\n assumes Equal{Here,Here}(a, n, b);\n assigns \\nothing;\n ensures result: \\result == n;\n behavior some_not_equal:\n assumes !Equal{Here,Here}(a, n, b);\n assigns \\nothing;\n ensures bound: 0 <= \\result < n;\n ensures result: a[\\result] != b[\\result];\n ensures first: Equal{Here,Here}(a, \\result, b);\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nmismatch(const value_type* a, size_type n, const value_type* b)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant equal: Equal{Here,Here}(a, i, b);\n loop assigns i;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; i++) {\n if (a[i] != b[i]) {\n //@ assert !Equal{Here,Here}(a, n, b);\n return i;\n }\n }\n //@ assert Equal{Here,Here}(a, n, b);\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_lshift", "file_name": "lshift", "input": "#define INT_MAX 2147483647\nunsigned lshift(unsigned a)\n{\n\treturn a << 1;\n}\nint main() {\n unsigned a = 5;\n unsigned result = lshift(a);\n //@ assert result == 10;\n return 0;\n}", "output": "#define INT_MAX 2147483647\n/*@ requires (a * 2) <= INT_MAX;\n assigns \\nothing;\n ensures \\result == a * 2;\n */\nunsigned lshift(unsigned a)\n{\n\treturn a << 1;\n}\nint main() {\n unsigned a = 5;\n unsigned result = lshift(a);\n //@ assert result == 10;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arrays_and_loops_4", "file_name": "4", "input": "#include\nint test(int x) {\n int a = x;\n int y = 0;\n while(a != 0) {\n y = y + 1;\n a = a - 1;\n }\n return y;\n}\nint main() {\n int num = test(3);\n //@ assert num == 3;\n return 0;\n}", "output": "#include\n/*@\n requires x > 0 && x < INT_MAX;\n ensures \\result == x;\n assigns \\nothing;\n*/\nint test(int x) {\n int a = x;\n int y = 0;\n /*@ \n loop invariant y + a == x;\n loop invariant a > -1 && a <= x;\n loop assigns a, y;\n */\n while(a != 0) {\n y = y + 1;\n a = a - 1;\n }\n return y;\n}\nint main() {\n int num = test(3);\n //@ assert num == 3;\n return 0;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_102", "file_name": "102", "input": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = 0;\n while (x < n) {\n x = x + 1;\n }\n if(n >= 0) {\n //@ assert x == n;\n }\n}", "output": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = 0;\n /*@\n loop invariant x <= n;\n loop invariant 0 <= x;\n loop assigns x;\n loop assigns n;\n */\n while (x < n) {\n x = x + 1;\n }\n if(n >= 0) {\n //@ assert x == n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_order_inc_max", "file_name": "order_inc_max", "input": "/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a < *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a >= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid max_ptr(int* a, int* b){\n if(*a < *b){\n int tmp = *b ;\n *b = *a ;\n *a = tmp ;\n }\n //@ assert *a >= *b ;\n}\n/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a > *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a <= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid min_ptr(int* a, int* b){\n max_ptr(b, a);\n //@ assert *a <= *b ;\n}\n\nvoid order_3_inc_max_min(int* a, int* b, int* c) {\n max_ptr(c, b) ;\n max_ptr(c, a) ;\n max_ptr(b, a) ;\n //@ assert *a <= *b && *b <= *c ;\n}\n", "output": "/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a < *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a >= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid max_ptr(int* a, int* b){\n if(*a < *b){\n int tmp = *b ;\n *b = *a ;\n *a = tmp ;\n }\n //@ assert *a >= *b ;\n}\n/*@\n requires \\valid(a) && \\valid(b);\n assigns *a, *b ;\n behavior reorder:\n assumes *a > *b ;\n ensures *a == \\old(*b) && *b == \\old(*a) ;\n behavior do_not_change:\n assumes *a <= *b ;\n ensures *a == \\old(*a) && *b == \\old(*b) ;\n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid min_ptr(int* a, int* b){\n max_ptr(b, a);\n //@ assert *a <= *b ;\n}\n/*@ requires \\valid(a) && \\valid(b) && \\valid(c) ;\n requires \\separated(a, b, c); \n assigns *a, *b, *c ;\n ensures { \\old(*a), \\old(*b), \\old(*c) } == { *a, *b, *c }; \n behavior all_equal: \n assumes *a == *b == *c ; \n ensures *a == *b == *c; \n behavior all_uequal: \n assumes *a != *b && *a != *c && *b != *c ; \n ensures *a != *b && *a != *c && *b != *c ;\n behavior two_eq_lt: \n assumes *a == *b < *c || \n *a == *c < *b ||\n *b == *c < *a; \n ensures *a == *b; \n behavior two_eq_gt: \n assumes *a == *b > *c || \n *a == *c > *b ||\n *b == *c > *a; \n ensures *b == *c; \n complete behaviors ;\n disjoint behaviors ;\n*/\nvoid order_3_inc_max(int* a, int* b, int* c) {\n max_ptr(c, b) ;\n max_ptr(c, a) ;\n max_ptr(b, a) ;\n //@ assert *a <= *b && *b <= *c ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_56", "file_name": "56", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c == n) {\n //@ assert n <= -1;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n - c;\n loop invariant c <= n;\n loop invariant c <= n+1;\n loop invariant 0 <= c;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c == n) {\n //@ assert n <= -1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_99", "file_name": "99", "input": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = n;\n int y = 0;\n while (x > 0) {\n y = y + 1;\n x = x - 1;\n }\n //@ assert n == x + y;\n}", "output": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = n;\n int y = 0;\n /*@\n loop invariant y == n - x;\n loop invariant y <= n;\n loop invariant x <= n;\n loop invariant x + y == n;\n loop invariant n == x + y;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x > 0) {\n y = y + 1;\n x = x - 1;\n }\n //@ assert n == x + y;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "adjacent_difference", "file_name": "adjacent_difference", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Difference\n {\n logic integer\n Difference{L}(value_type* a, integer n) =\n n <= 0 ? a[0] : a[n] - a[n-1];\n lemma Difference_Zero{L}:\n \\forall value_type *a; Difference(a, 0) == a[0];\n lemma Difference_Next{L}:\n \\forall value_type *a, integer n;\n 0 < n ==> Difference(a, n) == a[n] - a[n-1];\n lemma Difference_Unchanged{K,L}:\n \\forall value_type *a, integer n;\n 0 <= n ==> Unchanged{K,L}(a, n+1) ==>\n Difference{K}(a, n) == Difference{L}(a, n);\n }\n*/\n/*@\n axiomatic AdjacentDifference\n {\n predicate\n AdjacentDifference{L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> b[i] == Difference(a, i);\n predicate\n AdjacentDifferenceBounds(value_type* a, integer n) =\n \\forall integer i; 1 <= i < n ==>\n VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;\n lemma AdjacentDifference_Step{K,L}:\n \\forall value_type *a, *b, integer n;\n AdjacentDifference{K}(a, n, b) ==>\n Unchanged{K,L}(b, n) ==>\n Unchanged{K,L}(a, n+1) ==>\n \\at(b[n],L) == Difference{L}(a, n) ==>\n AdjacentDifference{L}(a, n+1, b);\n lemma AdjacentDifference_Section{K}:\n \\forall value_type *a, *b, integer m, n;\n 0 <= m <= n ==>\n AdjacentDifference{K}(a, n, b) ==>\n AdjacentDifference{K}(a, m, b);\n }\n*/\nsize_type\nadjacent_difference(const value_type* a, size_type n, value_type* b)\n{\n if (0u < n) {\n b[0u] = a[0u];\n for (size_type i = 1u; i < n; ++i) {\n //@ assert bound: VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;\n b[i] = a[i] - a[i - 1u];\n //@ assert difference: AdjacentDifference(a, i+1, b);\n }\n }\n return n;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Difference\n {\n logic integer\n Difference{L}(value_type* a, integer n) =\n n <= 0 ? a[0] : a[n] - a[n-1];\n lemma Difference_Zero{L}:\n \\forall value_type *a; Difference(a, 0) == a[0];\n lemma Difference_Next{L}:\n \\forall value_type *a, integer n;\n 0 < n ==> Difference(a, n) == a[n] - a[n-1];\n lemma Difference_Unchanged{K,L}:\n \\forall value_type *a, integer n;\n 0 <= n ==> Unchanged{K,L}(a, n+1) ==>\n Difference{K}(a, n) == Difference{L}(a, n);\n }\n*/\n/*@\n axiomatic AdjacentDifference\n {\n predicate\n AdjacentDifference{L}(value_type* a, integer n, value_type* b) =\n \\forall integer i; 0 <= i < n ==> b[i] == Difference(a, i);\n predicate\n AdjacentDifferenceBounds(value_type* a, integer n) =\n \\forall integer i; 1 <= i < n ==>\n VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;\n lemma AdjacentDifference_Step{K,L}:\n \\forall value_type *a, *b, integer n;\n AdjacentDifference{K}(a, n, b) ==>\n Unchanged{K,L}(b, n) ==>\n Unchanged{K,L}(a, n+1) ==>\n \\at(b[n],L) == Difference{L}(a, n) ==>\n AdjacentDifference{L}(a, n+1, b);\n lemma AdjacentDifference_Section{K}:\n \\forall value_type *a, *b, integer m, n;\n 0 <= m <= n ==>\n AdjacentDifference{K}(a, n, b) ==>\n AdjacentDifference{K}(a, m, b);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a + (0..n-1), b + (0..n-1));\n requires bounds: AdjacentDifferenceBounds(a, n);\n assigns b[0..n-1];\n ensures result: \\result == n;\n ensures difference: AdjacentDifference(a, n, b);\n ensures unchanged: Unchanged{Old,Here}(a, n);\n*/\nsize_type\nadjacent_difference(const value_type* a, size_type n, value_type* b)\n{\n if (0u < n) {\n b[0u] = a[0u];\n /*@\n loop invariant index: 1 <= i <= n;\n loop invariant unchanged: Unchanged{Pre,Here}(a, n);\n loop invariant difference: AdjacentDifference(a, i, b);\n loop assigns i, b[1..n-1];\n loop variant n - i;\n */\n for (size_type i = 1u; i < n; ++i) {\n //@ assert bound: VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;\n b[i] = a[i] - a[i - 1u];\n //@ assert difference: AdjacentDifference(a, i+1, b);\n }\n }\n return n;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_45", "file_name": "45", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c != n) {\n //@ assert c >= 0;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant c == n ==> c == n;\n loop invariant 0 <= c;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if(c != n) {\n //@ assert c >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_18", "file_name": "18", "input": "#include \n#include \nint* search(int* array, size_t length, int element){\n for(size_t i = 0; i < length; i++){\n if(array[i] == element) return &array[i];\n }\n return NULL;\n}\nint main(){\n int array[] = {1,2,3,4,5};\n int *p = search(array,5,6);\n //@ assert p == NULL;\n}", "output": "#include \n#include \n/*@\n\trequires \\valid_read(array+(0..length-1));\n\tassigns \\nothing;\n\tbehavior in:\n\t\tassumes \\exists size_t off;0<=offarray[off]!=element;\n\t\tensures \\result==NULL;\n\tdisjoint behaviors;\t\n\tcomplete behaviors;\t\n*/\nint* search(int* array, size_t length, int element) {\n\t/*@\n\t\tloop invariant 0<=i<=length;\n\t\tloop invariant \\forall size_t j;0<=jarray[j]!=element;\n\t\tloop assigns i;\t\n\t\tloop variant length-i;\n\t*/\n\tfor(size_t i = 0; i < length; i++) \n\t\tif(array[i]==element) return &array[i];\n\treturn NULL;\n}\nint main(){\n int array[] = {1,2,3,4,5};\n int *p = search(array,5,6);\n //@ assert p == NULL;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_BL.EN.U4CSE21176_1", "file_name": "BL.EN.U4CSE21176_1", "input": "#include\nint max(int a,int b){\nreturn a>b?a:b;\n}\nint main(){\nint x=4;\nint y=5;\nint r=max(x,y);\n//@assert x==4 && y==5;\n}", "output": "#include\n/*@\nrequires INT_MIN<=ab || \\result==b && \\result>a || \\result==a && \\result==b;\n*/\nint max(int a,int b){\nreturn a>b?a:b;\n}\nint main(){\nint x=4;\nint y=5;\nint r=max(x,y);\n//@assert x==4 && y==5;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "general_wp_problem_triangle_sides", "file_name": "triangle_sides", "input": "#include \nint validts(int a, int b, int c) {\n int valid = 0;\n if ((a+b>c) && (a+c>b) && (b+c>a) && 1) {\n valid = 1;\n } else {\n valid = 0;\n }\n return valid;\n}\nvoid test() {\n int valid = validts(2,3,4);\n //@ assert valid == 1;\n}", "output": "#include \n/*@\n requires a>0 && b>0 && c>0;\n ensures \\result == 1 <==> (a+b>c) && (a+c>b) && (b+c>a);\n ensures \\result == 0 <==> !(a+b>c) || !(a+c>b) || !(b+c>a);\n*/\nint validts(int a, int b, int c) {\n int valid = 0;\n if ((a+b>c) && (a+c>b) && (b+c>a) && 1) {\n valid = 1;\n } else {\n valid = 0;\n }\n return valid;\n}\nvoid test() {\n int valid = validts(2,3,4);\n //@ assert valid == 1;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_9", "file_name": "9", "input": "void max_ptr(int* a, int* b){\n if(*a < *b){\n int tmp = *b;\n *b = *a;\n *a = tmp;\n }\n}\nint main(){\n int x = 10, y = 20;\n max_ptr(&x, &y);\n //@ assert x == 20 && y == 10;\n return 0;\n}", "output": "/*@ requires \\valid(a) && \\valid(b);\n assigns *a, *b;\n ensures \\old(*a) < \\old(*b) ==> *a == \\old(*b) && *b == \\old(*a);\n ensures \\old(*a) >= \\old(*b) ==> *a == \\old(*a) && *b == \\old(*b);\n*/\nvoid max_ptr(int* a, int* b){\n if(*a < *b){\n int tmp = *b;\n *b = *a;\n *a = tmp;\n }\n}\nint main(){\n int x = 10, y = 20;\n max_ptr(&x, &y);\n //@ assert x == 20 && y == 10;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_71", "file_name": "71", "input": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n while (unknown()) {\n if (c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (c < 36) {\n //@ assert z >= 0;\n }\n}", "output": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n /*@\n loop invariant z == 36*y + c;\n loop invariant z == 36 * y + c;\n loop invariant c <= 36;\n loop invariant 36 * y <= z;\n loop invariant 0 <= c;\n loop assigns z;\n loop assigns c;\n */\n while (unknown()) {\n if (c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (c < 36) {\n //@ assert z >= 0;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_107", "file_name": "107", "input": "/*@\nrequires a <= m;\n*/\nvoid foo(int a, int m) {\n int j = 0;\n int k = 0;\n while ( k < 1) {\n if(m < a) {\n m = a;\n }\n k = k + 1;\n }\n //@ assert a <= m;\n}", "output": "/*@\nrequires a <= m;\n*/\nvoid foo(int a, int m) {\n int j = 0;\n int k = 0;\n /*@\n loop invariant k <= 1;\n loop invariant a <= m;\n loop invariant 0 <= k;\n loop assigns m;\n loop assigns k;\n */\n while ( k < 1) {\n if(m < a) {\n m = a;\n }\n k = k + 1;\n }\n //@ assert a <= m;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "axiom_size_of_pop", "file_name": "axiom_size_of_pop", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\nsize_type\naxiom_size_of_pop(Stack* s)\n{\n stack_pop(s);\n //@ assert StackSize(s) == StackSize{Pre}(s) - 1;\n return stack_size(s);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size;\n ensures valid: \\valid(s) && StackInvariant(s);\n behavior empty:\n assumes StackEmpty(s);\n assigns \\nothing;\n ensures empty: StackEmpty(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_empty:\n assumes !StackEmpty(s);\n assigns s->size;\n ensures size: StackSize(s) == StackSize{Old}(s) - 1;\n ensures full: !StackFull(s);\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_pop(Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures size: \\result == StackSize(s);\n*/\nsize_type\nstack_size(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires empty: !StackEmpty(s);\n assigns s->size;\n ensures size: \\result == StackSize{Old}(s) - 1;\n*/\nsize_type\naxiom_size_of_pop(Stack* s)\n{\n stack_pop(s);\n //@ assert StackSize(s) == StackSize{Pre}(s) - 1;\n return stack_size(s);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_30", "file_name": "30", "input": "/*@\nrequires (x == 100);\n*/\nvoid foo(int x) { \n while (x > 0) {\n x = x - 1;\n }\n //@ assert x == 0;\n}", "output": "/*@\nrequires (x == 100);\n*/\nvoid foo(int x) { \n // loop body\n /*@\n loop invariant x <= 100;\n loop invariant 0 <= x;\n loop assigns x;\n */\n while (x > 0) {\n x = x - 1;\n }\n // post-condition\n //@ assert x == 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_127", "file_name": "127", "input": "void foo(int x, int y) {\n int i = x;\n int j = y;\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if (y != 0) {\n //@ assert i != j;\n }\n}", "output": "void foo(int x, int y) {\n int i = x;\n int j = y;\n /*@\n loop invariant y <= j;\n loop invariant x <= i;\n loop invariant j - y == i - x;\n loop invariant i - x == j - y;\n loop assigns x,y,i,j;\n */\n while (x != 0) {\n x = x - 1;\n y = y - 1;\n }\n if (y != 0) {\n //@ assert i != j;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_proved_reverse_in_place", "file_name": "reverse_in_place", "input": "/*@ \n requires \\valid(&a[i]);\n requires \\valid(&a[j]);\n assigns a[i], a[j];\n ensures a[i] == \\old(a[j]);\n ensures a[j] == \\old(a[i]);\n */\nvoid swap(int a[], int i, int j);\nvoid reverse_in_place(int a[], int size)\n{\n int i;\n for(i = 0; i < (size / 2); ++i) {\n swap(a, i, size - i - 1);\n }\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a[] = {1,2,3,4,5,6,7,8,9,10};\n int size = sizeof(a) / sizeof(a[0]);\n //@ assert a[0] == 1;\n reverse_in_place(a, size);\n //@ assert a[0] == 10;\n}\n#endif", "output": "/*@ \n requires \\valid(&a[i]);\n requires \\valid(&a[j]);\n assigns a[i], a[j];\n ensures a[i] == \\old(a[j]);\n ensures a[j] == \\old(a[i]);\n */\nvoid swap(int a[], int i, int j);\n/*@ \n predicate reverse{L1,L2}(int* a, integer size, integer i, integer j) =\n \\forall integer k; i <= k < j ==>\n \\at(a[k], L1) == \\at(a[size - k - 1], L2);\n predicate reverse{L1,L2}(int* a, integer size) = reverse{L1,L2}(a, size, 0, size);\n*/\n/*@ \n requires size >= 0;\n requires \\valid(a+(0..size-1));\n assigns a[0..size-1];\n ensures reverse{Pre,Here}(a, size);\n ensures \\forall integer i; 0 <= i < size ==>\n \\exists integer j; 0 <= j < size &&\n \\old(a[\\at(i,Here)]) == a[j];\n */\nvoid reverse_in_place(int a[], int size)\n{\n int i;\n /*@ loop invariant 0 <= i <= size / 2;\n loop invariant reverse{Pre,Here}(a, size, 0, i);\n loop invariant \\forall integer j; i <= j < size - i ==> a[j] == \\at(a[\\at(j,Here)],Pre);\n loop invariant reverse{Pre,Here}(a, size, size - i, size);\n loop assigns i, a[0..size-1];\n loop variant size / 2 - i;\n */\n for(i = 0; i < (size / 2); ++i) {\n swap(a, i, size - i - 1);\n }\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a[] = {1,2,3,4,5,6,7,8,9,10};\n int size = sizeof(a) / sizeof(a[0]);\n //@ assert a[0] == 1;\n reverse_in_place(a, size);\n //@ assert a[0] == 10;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "stack_push_wd", "file_name": "stack_push_wd", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n axiomatic StackLemmas\n {\n lemma StackPush_Equal{K,L}:\n \\forall Stack *s, *t;\n StackEqual{K,K}(s,t) ==>\n StackSize{L}(s) == StackSize{K}(s) + 1 ==>\n StackSize{L}(s) == StackSize{L}(t) ==>\n StackTop{L}(s) == StackTop{L}(t) ==>\n Equal{L,L}(StackStorage{L}(s),\n StackSize{K}(s),\n StackStorage{L}(t)) ==>\n StackEqual{L,L}(s,t);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\nvoid\nstack_push_wd(Stack* s, Stack* t, value_type v)\n{\n stack_push(s, v);\n stack_push(t, v);\n //@ assert top: StackTop(s) == v;\n //@ assert top: StackTop(t) == v;\n //@ assert equal: Equal{Here,Here}(StackStorage(s), StackSize{Pre}(s), StackStorage(t));\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n axiomatic StackLemmas\n {\n lemma StackPush_Equal{K,L}:\n \\forall Stack *s, *t;\n StackEqual{K,K}(s,t) ==>\n StackSize{L}(s) == StackSize{K}(s) + 1 ==>\n StackSize{L}(s) == StackSize{L}(t) ==>\n StackTop{L}(s) == StackTop{L}(t) ==>\n Equal{L,L}(StackStorage{L}(s),\n StackSize{K}(s),\n StackStorage{L}(t)) ==>\n StackEqual{L,L}(s,t);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns s->size, s->obj[s->size];\n behavior full:\n assumes StackFull(s);\n assigns \\nothing;\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures full: StackFull(s);\n ensures unchanged: StackUnchanged{Old,Here}(s);\n behavior not_full:\n assumes !StackFull(s);\n assigns s->size;\n assigns s->obj[s->size];\n ensures valid: \\valid(s) && StackInvariant(s);\n ensures size: StackSize(s) == StackSize{Old}(s) + 1;\n ensures top: StackTop(s) == v;\n ensures storage: StackStorage(s) == StackStorage{Old}(s);\n ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);\n ensures not_empty: !StackEmpty(s);\n ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));\n complete behaviors;\n disjoint behaviors;\n*/\nvoid\nstack_push(Stack* s, value_type v);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires valid: \\valid(t) && StackInvariant(t);\n requires equal: StackEqual{Here,Here}(s, t);\n requires not_full: !StackFull(s) && !StackFull(t);\n requires sep: StackSeparated(s, t);\n assigns s->size, s->obj[s->size];\n assigns t->size, t->obj[t->size];\n ensures valid: StackInvariant(s) && StackInvariant(t);\n ensures equal: StackEqual{Here,Here}(s, t);\n*/\nvoid\nstack_push_wd(Stack* s, Stack* t, value_type v)\n{\n stack_push(s, v);\n stack_push(t, v);\n //@ assert top: StackTop(s) == v;\n //@ assert top: StackTop(t) == v;\n //@ assert equal: Equal{Here,Here}(StackStorage(s), StackSize{Pre}(s), StackStorage(t));\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_average", "file_name": "average", "input": "int average(int a, int b)\n{\n int average = 0;\n\tint greater;\n\tint smaller;\n\tif (a > b) {\n\t greater = a;\n\t smaller = b;\n\t} else {\n\t greater = b;\n\t smaller = a;\n\t}\n\tif (a >= 0 && b >= 0) {\n\t average = smaller + (greater - smaller) / 2;\n\t} else if (a < 0 && b < 0) {\n\t average = greater + (smaller - greater) / 2;\n\t} else if ((a >= 0 && b <= 0) || (a <= 0 && b >= 0)) {\n\t average = (a + b) / 2;\n\t}\n return average;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = average(3,30);\n int b = average(-5,-20);\n int c = average(7,-10);\n int d = average(-2,15);\n //@ assert a == 16;\n //@ assert b == -13;\n //@ assert c == -3;\n //@ assert d == 8;\n return 0;\n}\n#endif", "output": "/*@ assigns \\nothing;\n ensures \\result == (a+b)/2;\n*/\nint average(int a, int b)\n{\n int average = 0;\n\tint greater;\n\tint smaller;\n\tif (a > b) {\n\t greater = a;\n\t smaller = b;\n\t} else {\n\t greater = b;\n\t smaller = a;\n\t}\n\tif (a >= 0 && b >= 0) {\n\t average = smaller + (greater - smaller) / 2;\n\t} else if (a < 0 && b < 0) {\n\t average = greater + (smaller - greater) / 2;\n\t} else if ((a >= 0 && b <= 0) || (a <= 0 && b >= 0)) {\n\t average = (a + b) / 2;\n\t}\n return average;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = average(3,30);\n int b = average(-5,-20);\n int c = average(7,-10);\n int d = average(-2,15);\n //@ assert a == 16;\n //@ assert b == -13;\n //@ assert c == -3;\n //@ assert d == 8;\n return 0;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "21176_LogicFunction2", "file_name": "LogicFunction2", "input": "#include\n/*@\nlogic integer ax_b(integer a,integer x,integer b) = a*x+b;\n*/\n/*@\nassigns \\nothing;\nensures \\result==ax_b(a,x,4);\n*/\nint func(int a,int x){\nreturn a*x+4;\n}\nvoid check(int a,int x,int y){\nint fmin,fmax;\nif(x>y){\nfmin=func(a,x);\nfmax=func(a,y);\n}\nelse{\nfmin=func(a,y);\nfmax=func(a,x);\n}\n//@assert fmin<=fmax;\n}\nint main(){\nint w=3;\nint r=4;\nint s=7;\nint t=func(w,r);\ncheck(w,r,s);\n}", "output": "#include\n/*@\nlogic integer ax_b(integer a,integer x,integer b) = a*x+b;\n*/\n/*@\nassigns \\nothing;\nensures \\result==ax_b(a,x,4);\n*/\nint func(int a,int x){\nreturn a*x+4;\n}\n/*@\nrequires INT_MIN<=a*x0;\nrequires INT_MIN<=ax_b(a,x,4)<=INT_MAX;\nrequires INT_MIN<=ax_b(a,y,4)<=INT_MAX;\nassigns \\nothing;\n*/\nvoid check(int a,int x,int y){\nint fmin,fmax;\nif(x < y){}\nelse{\n int temp = x;\n x = y;\n y = temp;\n}\nfmin=func(a,x);\nfmax=func(a,y);\n//@assert fmin== ax_b(a, (x < y ? x : y), 4);\n}\nint main(){\nint w=3;\nint r=4;\nint s=7;\nint t=func(w,r);\ncheck(w,r,s);\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "frama-c-wp-tutorial-en_3", "file_name": "3", "input": "#include\nint plus_5(int* a) {\n return *a + 5;\n}\nint main(){\n int a = 10;\n int b = plus_5(&a);\n //@ assert b == 15; \n}", "output": "#include\n/*@\n requires \\valid_read(a);\n requires *a <= INT_MAX - 5;\n assigns \\nothing;\n ensures \\result == *a + 5;\n*/\nint plus_5(int* a) {\n return *a + 5;\n}\nint main(){\n int a = 10;\n int b = plus_5(&a);\n //@ assert b == 15; \n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_assigns", "file_name": "assigns", "input": "void foo(){\n int h = 42 ;\n int x = 0 ;\n int e = 0 ;\n PreLoop:\n while(e < 10){\n ++ e ;\n x += e * 2 ;\n }\n //@ assert h == 42 ;\n}", "output": "void foo(){\n int h = 42 ;\n int x = 0 ;\n int e = 0 ;\n PreLoop:\n /*@ \n loop invariant h == \\at(h, PreLoop) ; \n loop assigns e, x ; \n loop variant 10 - e;\n */\n while(e < 10){\n ++ e ;\n x += e * 2 ;\n }\n //@ assert h == 42 ;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_96", "file_name": "96", "input": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 0;\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (i != j) {\n //@ assert y != 1;\n }\n}", "output": "void foo(int x) {\n int i = 0;\n int j = 0;\n int y = 0;\n /*@\n loop invariant y == 0;\n loop invariant j == y*i;\n loop invariant j == y*(i-1);\n loop invariant j == i*y;\n loop invariant j == (i-1)*y;\n loop invariant j <= y*(i-1);\n loop invariant 0 <= j;\n loop invariant 0 <= i;\n loop assigns y,i,j;\n */\n while (i <= x) {\n i = i + 1;\n j = j + y;\n }\n if (i != j) {\n //@ assert y != 1;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_40", "file_name": "40", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if ( (c != n) ) {\n //@ assert (c >= 0) ;\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n-c;\n loop invariant n - c;\n loop invariant c <= n;\n loop invariant c <= n || c == 1;\n loop invariant 0 <= c;\n loop invariant (c <= n && c >= 0) || (c == n+1);\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if ( (c != n) ) {\n //@ assert (c >= 0) ;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "stack_empty_wd", "file_name": "stack_empty_wd", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures empty: \\result == 1 <==> StackEmpty(s);\n ensures not_empty: \\result == 0 <==> !StackEmpty(s);\n*/\nbool\nstack_empty(const Stack* s);\nbool\nstack_empty_wd(const Stack* s, const Stack* t)\n{\n return stack_empty(s) == stack_empty(t);\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\nstruct Stack\n{\n value_type* obj;\n size_type capacity;\n size_type size;\n};\ntypedef struct Stack Stack;\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic StackInvariant\n {\n logic integer\n StackCapacity{L}(Stack* s) = s->capacity;\n logic integer\n StackSize{L}(Stack* s) = s->size;\n logic value_type*\n StackStorage{L}(Stack* s) = s->obj;\n logic integer\n StackTop{L}(Stack* s) = s->obj[s->size-1];\n predicate\n StackEmpty{L}(Stack* s) = StackSize(s) == 0;\n predicate\n StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);\n predicate\n StackInvariant{L}(Stack* s) =\n 0 < StackCapacity(s) &&\n 0 <= StackSize(s) <= StackCapacity(s) &&\n \\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&\n \\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));\n }\n*/\n/*@\n axiomatic StackUtility\n {\n predicate\n StackSeparated(Stack* s, Stack* t) =\n \\separated(s, s->obj + (0..s->capacity-1),\n t, t->obj + (0..t->capacity-1));\n predicate\n StackUnchanged{K,L}(Stack* s) =\n StackSize{K}(s) == StackSize{L}(s) &&\n StackStorage{K}(s) == StackStorage{L}(s) &&\n StackCapacity{K}(s) == StackCapacity{L}(s) &&\n Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));\n }\n*/\n/*@\n axiomatic StackEquality\n {\n predicate\n StackEqual{S,T}(Stack* s, Stack* t) =\n StackSize{S}(s) == StackSize{T}(t) &&\n Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));\n lemma StackEqual_Reflexive{S} :\n \\forall Stack* s; StackEqual{S,S}(s, s);\n lemma StackEqual_Symmetric{S,T} :\n \\forall Stack *s, *t;\n StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);\n lemma StackEqual_Transitive{S,T,U}:\n \\forall Stack *s, *t, *u;\n StackEqual{S,T}(s, t) ==>\n StackEqual{T,U}(t, u) ==>\n StackEqual{S,U}(s, u);\n }\n*/\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n assigns \\nothing;\n ensures empty: \\result == 1 <==> StackEmpty(s);\n ensures not_empty: \\result == 0 <==> !StackEmpty(s);\n*/\nbool\nstack_empty(const Stack* s);\n/*@\n requires valid: \\valid(s) && StackInvariant(s);\n requires valid: \\valid(t) && StackInvariant(t);\n requires equal: StackEqual{Here,Here}(s, t);\n assigns \\nothing;\n ensures StackEmpty(s) && StackEmpty(t) ==> \\result == true;\n ensures (!StackEmpty(s) && StackEmpty(t)) || (StackEmpty(s) && !StackEmpty(t)) || (!StackEmpty(s) && !StackEmpty(t)) ==> \\result == false;\n*/\nbool\nstack_empty_wd(const Stack* s, const Stack* t)\n{\n return stack_empty(s) && stack_empty(t);\n}\nint main(){\n value_type a[5] = {1, 2, 3, 4, 5};\n value_type b[5] = {1, 2, 3, 4, 5};\n Stack s1, s2;\n s1.capacity = 5;\n s1.size = 5;\n s1.obj = a;\n s2.capacity = 5;\n s2.size = 5;\n s2.obj = b;\n bool result = stack_empty_wd(&s1, &s2);\n //@ assert result == false;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_54", "file_name": "54", "input": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c <= n;\n }\n}", "output": "/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n /*@\n loop invariant n-c;\n loop invariant n - c;\n loop invariant c <= n;\n loop invariant 0 <= c;\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c > n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c != n) {\n //@ assert c <= n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_divide", "file_name": "divide", "input": "int divide(int a, int b)\n{\n\treturn a / b;\n}\nint main(){\n\tint a = 10;\n int b = 2;\n int c = divide(a, b);\n //@ assert c == 5;\n}", "output": "/*@ \n requires b != 0;\n requires b != -1;\n assigns \\nothing;\n ensures \\result == a / b;\n */\nint divide(int a, int b)\n{\n\treturn a / b;\n}\nint main(){\n\tint a = 10;\n int b = 2;\n int c = divide(a, b);\n //@ assert c == 5;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "swap_ranges", "file_name": "swap_ranges", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\nrequires \\valid(a) && \\valid(b);\nassigns *a, *b;\nensures *a == \\old(*b) && *b == \\old(*a);\n*/\nvoid swap(int* a, int* b);\nvoid\nswap_ranges(value_type* a, size_type n, value_type* b)\n{\n for (size_type i = 0u; i < n; ++i) {\n swap(a + i, b + i);\n }\n}\nint main(){\n value_type a[] = {1, 2, 3, 4, 5};\n value_type b[] = {6, 7, 8, 9, 10};\n int n = 5;\n swap_ranges(a, n, b);\n //@ assert a[0] == 6 && b[0] == 1;\n //@ assert a[1] == 7 && b[1] == 2;\n //@ assert a[2] == 8 && b[2] == 3;\n //@ assert a[3] == 9 && b[3] == 4;\n //@ assert a[4] == 10 && b[4] == 5;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\nrequires \\valid(a) && \\valid(b);\nassigns *a, *b;\nensures *a == \\old(*b) && *b == \\old(*a);\n*/\nvoid swap(int* a, int* b);\n/*@\n requires valid: \\valid(a + (0..n-1));\n requires valid: \\valid(b + (0..n-1));\n requires sep: \\separated(a+(0..n-1), b+(0..n-1));\n assigns a[0..n-1];\n assigns b[0..n-1];\n ensures equal: Equal{Old,Here}(a, n, b);\n ensures equal: Equal{Old,Here}(b, n, a);\n*/\nvoid\nswap_ranges(value_type* a, size_type n, value_type* b)\n{\n /*@\n loop invariant bound: 0 <= i <= n;\n loop invariant equal: Equal{Pre,Here}(a, i, b);\n loop invariant equal: Equal{Pre,Here}(b, i, a);\n loop invariant unchanged: Unchanged{Pre,Here}(a, i, n);\n loop invariant unchanged: Unchanged{Pre,Here}(b, i, n);\n loop assigns i, a[0..n-1], b[0..n-1];\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n swap(a + i, b + i);\n }\n}\nint main(){\n value_type a[] = {1, 2, 3, 4, 5};\n value_type b[] = {6, 7, 8, 9, 10};\n int n = 5;\n swap_ranges(a, n, b);\n //@ assert a[0] == 6 && b[0] == 1;\n //@ assert a[1] == 7 && b[1] == 2;\n //@ assert a[2] == 8 && b[2] == 3;\n //@ assert a[3] == 9 && b[3] == 4;\n //@ assert a[4] == 10 && b[4] == 5;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_reverse", "file_name": "reverse", "input": "void reverse(int a[], int res[], int size)\n{\n int i;\n for(i = size - 1; i >= 0; --i) {\n res[i] = a[size - i - 1];\n }\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a[] = {1,2,3,4,5,6,7,8,9,10};\n int size = sizeof(a) / sizeof(a[0]);\n reverse(a, b, size);\n //@ assert \\forall integer i; 0 <= i < size ==> b[i] == a[size - i - 1];\n}\n#endif", "output": "/*@ requires size >= 0;\n requires \\valid(a+(0..size-1));\n requires \\valid(res+(0..size-1));\n assigns res[0..size-1];\n ensures \\forall integer i; 0 <= i < size ==> res[i] == a[size - i - 1];\n */\nvoid reverse(int a[], int res[], int size)\n{\n int i;\n /*@ loop invariant -1 <= i < size; \n loop invariant \\forall integer j; i < j < size ==> res[j] == a[size - j - 1];\n loop assigns i, res[0..size-1];\n loop variant i;\n */\n for(i = size - 1; i >= 0; --i) {\n res[i] = a[size - i - 1];\n }\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a[] = {1,2,3,4,5,6,7,8,9,10};\n int size = sizeof(a) / sizeof(a[0]);\n reverse(a, b, size);\n //@ assert \\forall integer i; 0 <= i < size ==> b[i] == a[size - i - 1];\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "miscellaneous_array_max_advanced", "file_name": "array_max_advanced", "input": "int array_max_advanced(int* arr, int n) {\n int max = arr[0];\n for (int i = 0; i < n; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n //@ assert \\forall integer j; 0 <= j < n ==> arr[j] <= max;\n return max;\n}", "output": "/*@\n requires n > 0;\n requires \\valid(arr+(0..n-1));\n ensures \\forall integer i; 0 <= i < n ==> arr[i] <= \\result;\n assigns \\nothing;\n*/\nint array_max_advanced(int* arr, int n) {\n int max = arr[0];\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer j; 0 <= j < i ==> arr[j] <= max;\n loop assigns i, max;\n loop variant n - i;\n */\n for (int i = 0; i < n; i++) {\n if (arr[i] > max) {\n max = arr[i];\n }\n }\n //@ assert \\forall integer j; 0 <= j < n ==> arr[j] <= max;\n return max;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_80", "file_name": "80", "input": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i <= y) {\n //@ assert i <= x;\n }\n}", "output": "/*@\nrequires x >= 0;\nrequires y >= 0;\nrequires x >= y;\n*/\nvoid foo(int x, int y) {\n int i = 0;\n /*@\n loop invariant y <= x;\n loop invariant i <= x;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop invariant i <= y;\n loop invariant i <= y + 1;\n loop invariant 0 <= i;\n loop assigns x,y,i;\n */\n while (unknown()) {\n if (i < y)\n {\n i = i + 1;\n }\n }\n if (i <= y) {\n //@ assert i <= x;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_83", "file_name": "83", "input": "int main() {\n int x = -5000;\n int y = 0;\n while ((x < 0)) {\n x = x + y;\n y = y + 1;\n }\n //@ assert y > 0;\n}", "output": "int main() {\n int x = -5000;\n int y = 0;\n /*@\n loop invariant x >= 0 ==> y > 0;\n loop invariant -5000 <= x;\n loop invariant -5000 <= x + y;\n loop invariant 0 <= y;\n loop assigns y,x;\n */\n while ((x < 0)) {\n x = x + y;\n y = y + 1;\n }\n //@ assert y > 0;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_100", "file_name": "100", "input": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = n;\n int y = 0;\n while (x > 0) {\n y = y + 1;\n x = x - 1;\n }\n //@ assert y == n;\n}", "output": "/*@\nrequires n >= 0;\n*/\nvoid foo(int n) {\n int x = n;\n int y = 0;\n /*@\n loop invariant y == n - x;\n loop invariant y <= n;\n loop invariant y + x == n;\n loop invariant x <= n;\n loop invariant 0 <= y;\n loop invariant 0 <= x;\n loop assigns y;\n loop assigns x;\n */\n while (x > 0) {\n y = y + 1;\n x = x - 1;\n }\n //@ assert y == n;\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "lower_bound", "file_name": "lower_bound", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic WeaklyIncreasing\n {\n predicate\n WeaklyIncreasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n-1 ==> a[i] <= a[i+1];\n predicate\n WeaklyIncreasing{L}(value_type* a, integer n) = WeaklyIncreasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Increasing\n {\n predicate\n Increasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i, j; m <= i < j < n ==> a[i] <= a[j];\n predicate\n Increasing{L}(value_type* a, integer n) = Increasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\nsize_type\nlower_bound(const value_type* a, size_type n, value_type v)\n{\n size_type left = 0u;\n size_type right = n;\n while (left < right) {\n const size_type middle = left + (right - left) / 2u;\n if (a[middle] < v) {\n left = middle + 1u;\n }\n else {\n right = middle;\n }\n }\n //@ assert LowerBound(a, left, n, v);\n return left;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic WeaklyIncreasing\n {\n predicate\n WeaklyIncreasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n-1 ==> a[i] <= a[i+1];\n predicate\n WeaklyIncreasing{L}(value_type* a, integer n) = WeaklyIncreasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic Increasing\n {\n predicate\n Increasing{L}(value_type* a, integer m, integer n) =\n \\forall integer i, j; m <= i < j < n ==> a[i] <= a[j];\n predicate\n Increasing{L}(value_type* a, integer n) = Increasing{L}(a, 0, n);\n }\n*/\n/*@\n axiomatic ArrayBounds\n {\n predicate\n LowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v <= a[i];\n predicate\n LowerBound{L}(value_type* a, integer n, value_type v) =\n LowerBound{L}(a, 0, n, v);\n predicate\n StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> v < a[i];\n predicate\n StrictLowerBound{L}(value_type* a, integer n, value_type v) =\n StrictLowerBound{L}(a, 0, n, v);\n predicate\n UpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] <= v;\n predicate\n UpperBound{L}(value_type* a, integer n, value_type v) =\n UpperBound{L}(a, 0, n, v);\n predicate\n StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =\n \\forall integer i; m <= i < n ==> a[i] < v;\n predicate\n StrictUpperBound{L}(value_type* a, integer n, value_type v) =\n StrictUpperBound{L}(a, 0, n, v);\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires increasing: Increasing(a, n);\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n ensures left: StrictUpperBound(a, 0, \\result, v);\n ensures right: LowerBound(a, \\result, n, v);\n*/\nsize_type\nlower_bound(const value_type* a, size_type n, value_type v)\n{\n size_type left = 0u;\n size_type right = n;\n /*@\n loop invariant bound: 0 <= left <= right <= n;\n loop invariant left: StrictUpperBound(a, 0, left, v);\n loop invariant right: LowerBound(a, right, n, v);\n loop assigns left, right;\n loop variant right - left;\n */\n while (left < right) {\n const size_type middle = left + (right - left) / 2u;\n if (a[middle] < v) {\n left = middle + 1u;\n }\n else {\n right = middle;\n }\n }\n //@ assert LowerBound(a, left, n, v);\n return left;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_76", "file_name": "76", "input": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n while (unknown()) {\n if (c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (z < 0) {\n if (z >= 4608) {\n //@ assert c >= 36;\n }\n }\n}", "output": "/*@\nrequires y >= 127;\n*/\nvoid foo(int y) {\n int c = 0;\n int z = 36 * y;\n /*@\n loop invariant z == 36*y + c;\n loop invariant z == 36 * y + c;\n loop invariant z == (36 * y) + c;\n loop invariant z <= 36 * y + 36;\n loop invariant z < 0 ==> z >= 4608 ==> c >= 36;\n loop invariant c <= 36;\n loop invariant 36*y <= z;\n loop invariant 36 * y <= z;\n loop invariant 0 <= c;\n loop assigns z;\n loop assigns c;\n */\n while (unknown()) {\n if (c < 36)\n {\n z = z + 1;\n c = c + 1;\n }\n }\n if (z < 0) {\n if (z >= 4608) {\n //@ assert c >= 36;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nikunjjain02_Arrays_8", "file_name": "Arrays_8", "input": "#include\nint* reverse(int a[], int n, int b[]) {\n\tint i = 0;\n\twhile(i c[k] == a[5-k-1];\n}", "output": "#include\n/*@\n\trequires n>=0&&\\valid_read(a+(0..n-1));\n\tassigns b[0..n-1];\n\tensures \\forall integer k;0<=ka[n-k-1]==\\result[k]; \t\n*/\nint* reverse(int a[], int n, int b[]) {\n\tint i = 0;\n\t/*@\n\t\tloop invariant 0<=i<=n;\n\t\tloop invariant \\forall integer k;0<=ka[n-k-1]==b[k];\n\t\tloop assigns b[0..n-1],i;\n\t\tloop variant n-i;\n\t*/\n\twhile(i c[k] == a[5-k-1];\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_51", "file_name": "51", "input": "void main() {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != 4) {\n c = c + 1;\n }\n } else {\n if (c == 4) {\n c = 1;\n }\n }\n }\n if (c != 4){\n //@ assert c <= 4;\n }\n}", "output": "void main() {\n int c = 0;\n /*@\n loop invariant c <= 4;\n loop invariant c != 4 ==> c < 4;\n loop invariant \\exists integer k; 0 <= k <= 4 && c == k;\n loop invariant 0 <= c;\n loop assigns c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != 4) {\n c = c + 1;\n }\n } else {\n if (c == 4) {\n c = 1;\n }\n }\n }\n if (c != 4){\n //@ assert c <= 4;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "accumulate", "file_name": "accumulate", "input": "#ifndef TYPEDEFS_H_INCLUDED\n#define TYPEDEFS_H_INCLUDED\n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n#endif\n#include\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n axiomatic UnchangedLemmas\n {\n lemma Unchanged_Shrink{K,L}:\n \\forall value_type *a, integer m, n, p, q;\n m <= p <= q <= n ==>\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{K,L}(a, p, q);\n lemma Unchanged_Extend{K,L}:\n \\forall value_type *a, integer n;\n Unchanged{K,L}(a, n) ==>\n \\at(a[n],K) == \\at(a[n],L) ==>\n Unchanged{K,L}(a, n+1);\n lemma Unchanged_Symmetric{K,L}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,K}(a, m, n);\n lemma Unchanged_Transitive{K,L,M}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,M}(a, m, n) ==>\n Unchanged{K,M}(a, m, n);\n }\n axiomatic Accumulate\n {\n logic integer\n Accumulate{L}(value_type* a, integer n, integer init) =\n n <= 0 ? init : Accumulate(a, n-1, init) + a[n-1];\n predicate\n AccumulateBounds{L}(value_type* a, integer n, value_type init) =\n \\forall integer i; 0 <= i <= n ==>\n VALUE_TYPE_MIN <= Accumulate(a, i, init) <= VALUE_TYPE_MAX;\n lemma Accumulate_Init:\n \\forall value_type *a, init, integer n;\n n <= 0 ==> Accumulate(a, n, init) == init;\n }\n*/\nvalue_type\naccumulate(const value_type* a, size_type n, value_type init)\n{\n for (size_type i = 0u; i < n; ++i) {\n //@ assert rte_help: init + a[i] == Accumulate(a, i+1, \\at(init,Pre));\n init = init + a[i];\n }\n return init;\n}", "output": "#ifndef TYPEDEFS_H_INCLUDED\n#define TYPEDEFS_H_INCLUDED\n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n#endif\n#include\n/*@\n axiomatic Unchanged\n {\n predicate\n Unchanged{K,L}(value_type* a, integer m, integer n) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(a[i],L);\n predicate\n Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);\n }\n axiomatic UnchangedLemmas\n {\n lemma Unchanged_Shrink{K,L}:\n \\forall value_type *a, integer m, n, p, q;\n m <= p <= q <= n ==>\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{K,L}(a, p, q);\n lemma Unchanged_Extend{K,L}:\n \\forall value_type *a, integer n;\n Unchanged{K,L}(a, n) ==>\n \\at(a[n],K) == \\at(a[n],L) ==>\n Unchanged{K,L}(a, n+1);\n lemma Unchanged_Symmetric{K,L}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,K}(a, m, n);\n lemma Unchanged_Transitive{K,L,M}:\n \\forall value_type *a, integer m, n;\n Unchanged{K,L}(a, m, n) ==>\n Unchanged{L,M}(a, m, n) ==>\n Unchanged{K,M}(a, m, n);\n }\n axiomatic Accumulate\n {\n logic integer\n Accumulate{L}(value_type* a, integer n, integer init) =\n n <= 0 ? init : Accumulate(a, n-1, init) + a[n-1];\n predicate\n AccumulateBounds{L}(value_type* a, integer n, value_type init) =\n \\forall integer i; 0 <= i <= n ==>\n VALUE_TYPE_MIN <= Accumulate(a, i, init) <= VALUE_TYPE_MAX;\n lemma Accumulate_Init:\n \\forall value_type *a, init, integer n;\n n <= 0 ==> Accumulate(a, n, init) == init;\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires bounds: AccumulateBounds(a, n, init);\n assigns \\nothing;\n ensures result: \\result == Accumulate(a, n, init);\n*/\nvalue_type\naccumulate(const value_type* a, size_type n, value_type init)\n{\n /*@\n loop invariant index: 0 <= i <= n;\n loop invariant partial: init == Accumulate(a, i, \\at(init,Pre));\n loop assigns i, init;\n loop variant n-i;\n */\n for (size_type i = 0u; i < n; ++i) {\n //@ assert rte_help: init + a[i] == Accumulate(a, i+1, \\at(init,Pre));\n init = init + a[i];\n }\n return init;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "find_end", "file_name": "find_end", "input": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic HasSubRange\n {\n predicate\n HasSubRange{L}(value_type* a, integer m, integer n, value_type* b, integer p) =\n \\exists integer k; (m <= k <= n-p) && Equal{L,L}(a+k, p, b);\n predicate\n HasSubRange{L}(value_type* a, integer n, value_type* b, integer p) =\n HasSubRange{L}(a, 0, n, b, p);\n lemma HasSubRange_Sizes:\n \\forall value_type *a, *b, integer m, n, p;\n HasSubRange(a, m, n, b, p) ==> p <= n-m;\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid_read(b + (0..n-1));\n assigns \\nothing;\n ensures result: \\result <==> Equal{Here,Here}(a, n, b);\n*/\nbool\nequal(const value_type* a, size_type n, const value_type* b);\nsize_type\nfind_end(const value_type* a, size_type n,\n const value_type* b, size_type p)\n{\n size_type r = n;\n if ((0u < p) && (p <= n)) {\n for (size_type i = 0u; i <= n - p; ++i) {\n if (equal(a + i, p, b)) {\n r = i;\n }\n }\n }\n //@ assert !HasSubRange(a, r + 1, n, b, p);\n return r;\n}", "output": "#include \n#ifndef __cplusplus\ntypedef int bool;\n#define false\t\t((bool)0)\n#define true\t\t((bool)1)\n#endif\ntypedef int value_type;\n#define VALUE_TYPE_MAX INT_MAX\n#define VALUE_TYPE_MIN INT_MIN\ntypedef unsigned int size_type;\n#define SIZE_TYPE_MAX UINT_MAX\n/*@\n axiomatic Equal\n {\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =\n \\forall integer i; m <= i < n ==> \\at(a[i],K) == \\at(b[i],L);\n predicate\n Equal{K,L}(value_type* a, integer n, value_type* b) =\n Equal{K,L}(a, 0, n, b);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n,\n value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);\n predicate\n Equal{K,L}(value_type* a, integer m, integer n, integer p) =\n Equal{K,L}(a, m, n, a, p);\n }\n*/\n/*@\n axiomatic HasSubRange\n {\n predicate\n HasSubRange{L}(value_type* a, integer m, integer n, value_type* b, integer p) =\n \\exists integer k; (m <= k <= n-p) && Equal{L,L}(a+k, p, b);\n predicate\n HasSubRange{L}(value_type* a, integer n, value_type* b, integer p) =\n HasSubRange{L}(a, 0, n, b, p);\n lemma HasSubRange_Sizes:\n \\forall value_type *a, *b, integer m, n, p;\n HasSubRange(a, m, n, b, p) ==> p <= n-m;\n }\n*/\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid_read(b + (0..n-1));\n assigns \\nothing;\n ensures result: \\result <==> Equal{Here,Here}(a, n, b);\n*/\nbool\nequal(const value_type* a, size_type n, const value_type* b);\n/*@\n requires valid: \\valid_read(a + (0..n-1));\n requires valid: \\valid_read(b + (0..p-1));\n assigns \\nothing;\n ensures result: 0 <= \\result <= n;\n behavior has_match:\n assumes HasSubRange(a, n, b, p);\n assigns \\nothing;\n ensures bound: 0 <= \\result <= n-p;\n ensures result: Equal{Here,Here}(a + \\result, p, b);\n ensures last: !HasSubRange(a, \\result + 1, n, b, p);\n behavior no_match:\n assumes !HasSubRange(a, n, b, p);\n assigns \\nothing;\n ensures result: \\result == n;\n complete behaviors;\n disjoint behaviors;\n*/\nsize_type\nfind_end(const value_type* a, size_type n,\n const value_type* b, size_type p)\n{\n size_type r = n;\n if ((0u < p) && (p <= n)) {\n /*@\n loop invariant bound : r <= n - p || r == n;\n loop invariant not_found: r == n ==> !HasSubRange(a, p+i-1, b, p);\n loop invariant found: r < n ==> Equal{Here,Here}(a+r, p, b);\n loop invariant last: r < n ==> !HasSubRange(a, r+1, i+p-1, b, p);\n loop assigns i, r;\n loop variant n - i;\n */\n for (size_type i = 0u; i <= n - p; ++i) {\n if (equal(a + i, p, b)) {\n r = i;\n }\n }\n }\n //@ assert !HasSubRange(a, r + 1, n, b, p);\n return r;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "pointers_div_rem", "file_name": "div_rem", "input": "void div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r) {\n *q = x / y;\n *r = x % y;\n}\nvoid main() {\n unsigned q, r;\n div_rem(10, 3, &q, &r);\n //@ assert q == 3;\n //@ assert r == 1;\n}", "output": "/*@\n requires \\valid(q) && \\valid(r);\n requires \\separated(q, r);\n requires y != 0;\n assigns *q, *r;\n ensures x == *q * y + *r;\n ensures *r < y;\n*/\nvoid div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r) {\n *q = x / y;\n *r = x % y;\n}\nvoid main() {\n unsigned q, r;\n div_rem(10, 3, &q, &r);\n //@ assert q == 3;\n //@ assert r == 1;\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "evdenis_small-examples_factorial", "file_name": "factorial", "input": "/*@ axiomatic Factorial {\n logic integer factorial(integer i);\n axiom nil:\n factorial(0) == 1;\n axiom step:\n \\forall integer i; i >= 0 ==>\n factorial(i) == factorial(i - 1) * i;\n lemma non_negative:\n \\forall integer i; i >= 0 ==>\n factorial(i) > 0;\n }\n */\n#define SPEC_ULONG_MAX 18446744073709551615UL\nunsigned long factorial(unsigned i)\n{\n\tunsigned long f = 1;\n\twhile (i) {\n\t\tf *= i--;\n\t}\n\treturn f;\n}\nint main(){\n unsigned long f = factorial(5);\n //@ assert f == 120;\n}", "output": "/*@ axiomatic Factorial {\n logic integer factorial(integer i);\n axiom nil:\n factorial(0) == 1;\n axiom step:\n \\forall integer i; i >= 0 ==>\n factorial(i) == factorial(i - 1) * i;\n lemma non_negative:\n \\forall integer i; i >= 0 ==>\n factorial(i) > 0;\n }\n */\n#define SPEC_ULONG_MAX 18446744073709551615UL\n/*@ requires factorial(i) <= SPEC_ULONG_MAX;\n assigns \\nothing;\n ensures \\result == factorial(i);\n */\nunsigned long factorial(unsigned i)\n{\n\tunsigned long f = 1;\n\t/*@ loop invariant 0 <= i;\n\t loop assigns f, i;\n\t loop variant i;\n\t */\n\twhile (i) {\n\t\tf *= i--;\n\t}\n\treturn f;\n}\nint main(){\n unsigned long f = factorial(5);\n //@ assert f == 120;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_111", "file_name": "111", "input": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == n;\n }\n}", "output": "/*@\nrequires 1 <= n;\n*/\nvoid foo(int n) {\n int i = 1;\n int sn = 0;\n /*@\n loop invariant sn == i-1;\n loop invariant sn == i - 1;\n loop invariant i <= n+1;\n loop invariant 1 <= i;\n loop assigns sn;\n loop assigns i;\n */\n while (i <= n) {\n i = i + 1;\n sn = sn + 1;\n }\n if (sn != 0) {\n //@ assert sn == n;\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "increment_arr", "file_name": "increment_arr", "input": "void increment_array_by(int* arr, int n, int c) {\n for (int i = 0; i < n; i++) {\n arr[i] = arr[i] + c;\n }\n //@ assert \\forall integer k; 0 <= k < n ==> arr[k] == (\\at(arr[k], Pre) + c);\n}\nint main(){\n int arr[10] = {1,2,3,4,5,6,7,8,9,10};\n Label_a:\n increment_array_by(arr, 10, 1);\n //@ assert \\forall integer k; 0 <= k < 10 ==> arr[k] == (\\at(arr[k], Label_a) + 1);\n}", "output": "/*@\n requires n > 0;\n requires \\valid_read(arr+(0..n-1));\n ensures \\forall integer k; 0 <= k < n ==> arr[k] == (\\at(arr[k], Pre) + c);\n*/\nvoid increment_array_by(int* arr, int n, int c) {\n /*@\n loop invariant 0 <= i <= n;\n loop invariant \\forall integer k; 0 <= k < i ==> arr[k] == \\at(arr[k], Pre) + c;\n loop invariant \\forall integer k; i <= k < n ==> arr[k] == \\at(arr[k], Pre);\n loop assigns i, arr[0..n-1];\n */\n for (int i = 0; i < n; i++) {\n arr[i] = arr[i] + c;\n }\n}\nint main(){\n int arr[10] = {1,2,3,4,5,6,7,8,9,10};\n Label_a:\n increment_array_by(arr, 10, 1);\n //@ assert \\forall integer k; 0 <= k < 10 ==> arr[k] == (\\at(arr[k], Label_a) + 1);\n}", "source": "fmbench", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "corinnt_remainder", "file_name": "remainder", "input": "void div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r){\n *q = x / y ;\n *r = x % y ;\n}\nint main() {\n unsigned x = 10, y = 3;\n unsigned q, r;\n div_rem(x, y, &q, &r);\n //@ assert q == 3 && r == 1;\n return 0;\n}", "output": "/*@ \n requires valid_pointers: \\valid(q) && \\valid(r);\n requires \\separated(q, r); \n requires no_divide_by_zero: y != 0; \n assigns *q, *r; \n ensures *q == x / y; \n ensures *r == x % y; \n*/\nvoid div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r){\n *q = x / y ;\n *r = x % y ;\n}\nint main() {\n unsigned x = 10, y = 3;\n unsigned q, r;\n div_rem(x, y, &q, &r);\n //@ assert q == 3 && r == 1;\n return 0;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "nabinkrsah_Computing the mod with precondition and postcondition", "file_name": "Computing the integer square root with precondition and postcondition", "input": "int my_mod(int a, int b){\n\tint c = a * a;\n\tint d = c * 3;\n\treturn d % b;\n}\n\nvoid main(){\n\tint x1 = 5;\n\tint x2 = 10;\n\tint y1 = my_mod(x1, 2);\n\tint y2 = my_mod(x2, 2);\n\t//@ assert y1 != y2;\n}", "output": "/*@\n\trequires b >= 0;\n\tensures \\result == (a * a * 3) % b;\n*/\nint my_mod(int a, int b){\n\tint c = a * a;\n\tint d = c * 3;\n\treturn d % b;\n}\n\nvoid main(){\n\tint x1 = 5;\n\tint x2 = 10;\n\tint y1 = my_mod(x1, 2);\n\tint y2 = my_mod(x2, 2);\n\t//@ assert y1 != y2;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "Tasmina0609_1", "file_name": "1", "input": "int max3(int a,int b,int c) {\n int max;\n if((a >= b) && (a >= c)) {\n max = a;\n }\n else if((b >= a) && (b >= c)) {\n max = b;\n }\n else if((c >= a) && (c >= b)) {\n max = c;\n }\n return max;\n}\nint main(){\n int a = 10;\n int b = 20;\n int c = 30;\n int max = max3(a,b,c);\n //@ assert max == 30;\n}", "output": "/*@ \n ensures \\result>=a && \\result>=b && \\result>=c;\n ensures \\result==a || \\result==b || \\result==c;\n ensures a>=b && a>=c ==> \\result==a;\n ensures b>=a && b>=c ==> \\result==b;\n ensures c>=a && c>=b ==> \\result==c;\n*/\nint max3(int a,int b,int c) {\n int max;\n if((a >= b) && (a >= c)) {\n max = a;\n }\n else if((b >= a) && (b >= c)) {\n max = b;\n }\n else if((c >= a) && (c >= b)) {\n max = c;\n }\n return max;\n}\nint main(){\n int a = 10;\n int b = 20;\n int c = 30;\n int max = max3(a,b,c);\n //@ assert max == 30;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "gpetiot_Frama-C-StaDy_next_subset", "file_name": "next_subset", "input": "/*@ \npredicate is_dset{L}(int *a, integer n) =\n \\forall integer i; 0 <= i < n ==> (a[i] == 0 || a[i] == 1);\npredicate is_eq{L1,L2}(int *a, integer n) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],L1) == \\at(a[i],L2);\npredicate lt{L1,L2}(int* a, integer i) =\n \\at(a[i],L1) < \\at(a[i],L2); \n*/\nint nextSubset(int s[], int n) {\n int i,k;\n for (k = n-1; k >= 0; k--) { if (s[k] == 0) { break; } }\n if (k == -1) { return -1; }\n s[k] = 1;\n for (i = k+1; i < n; i++) { s[i] = 0; }\n //@ assert is_dset(s,n);\n return k;\n}", "output": "/*@ \npredicate is_dset{L}(int *a, integer n) =\n \\forall integer i; 0 <= i < n ==> (a[i] == 0 || a[i] == 1);\npredicate is_eq{L1,L2}(int *a, integer n) =\n \\forall integer i; 0 <= i < n ==> \\at(a[i],L1) == \\at(a[i],L2);\npredicate lt{L1,L2}(int* a, integer i) =\n \\at(a[i],L1) < \\at(a[i],L2); \n*/\n/*@ \nrequires n >= 0 && n <= 3 && \\valid(s+(0..n-1));\nrequires is_dset(s,n);\nassigns s[0..n-1];\n ensures is_dset(s,n);\n ensures -1 <= \\result < n;\nensures \\result == -1 ==> is_eq{Pre,Post}(s,n);\nensures \\result != -1 ==> is_eq{Pre,Post}(s,\\result);\nensures \\result != -1 ==> lt{Pre,Post}(s,\\result);\n*/\nint nextSubset(int s[], int n) {\n int i,k;\n /*@ loop invariant -1 <= k <= n-1;\n loop assigns k;\n loop variant k; */\n for (k = n-1; k >= 0; k--) { if (s[k] == 0) { break; } }\n if (k == -1) { return -1; }\n s[k] = 1;\n /*@ loop invariant k+1 <= i <= n;\n loop invariant is_dset(s,i);\n loop assigns i,s[k+1..n-1];\n loop variant n-i; */\n for (i = k+1; i < n; i++) { s[i] = 0; }\n //@ assert is_dset(s,n);\n return k;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "arepina_factorial", "file_name": "factorial", "input": "/*@ axiomatic Factorial {\n logic integer factorial(integer i);\n axiom nil:\n factorial(0) == 1;\n axiom step:\n \\forall integer i; i >= 0 ==>\n factorial(i) == factorial(i - 1) * i;\n lemma non_negative:\n \\forall integer i; i >= 0 ==>\n factorial(i) > 0;\n }\n */\n#define SPEC_ULONG_MAX 18446744073709551615UL\nunsigned long factorial(unsigned i)\n{\n unsigned long f = 1;\n while (i) {\n f *= i--;\n }\n return f;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = factorial(5);\n int b = factorial(0);\n //@ assert a == 120;\n //@ assert b == 1;\n}\n#endif", "output": "/*@ axiomatic Factorial {\n logic integer factorial(integer i);\n axiom nil:\n factorial(0) == 1;\n axiom step:\n \\forall integer i; i >= 0 ==>\n factorial(i) == factorial(i - 1) * i;\n lemma non_negative:\n \\forall integer i; i >= 0 ==>\n factorial(i) > 0;\n }\n */\n#define SPEC_ULONG_MAX 18446744073709551615UL\n/*@ requires factorial(i) <= SPEC_ULONG_MAX;\n assigns \\nothing;\n ensures \\result == factorial(i);\n */\nunsigned long factorial(unsigned i)\n{\n unsigned long f = 1;\n /*@ loop invariant 0 <= i;\n loop assigns f, i;\n loop variant i;\n */\n while (i) {\n f *= i--;\n }\n return f;\n}\n#ifdef OUT_OF_TASK\n#include \nint main(void)\n{\n int a = factorial(5);\n int b = factorial(0);\n //@ assert a == 120;\n //@ assert b == 1;\n}\n#endif", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "gpetiot_Frama-C-StaDy_inv_insuf_ok", "file_name": "inv_insuf_ok", "input": "int found;\n/*@ \nrequires \\valid(t+(0..4));\n*/\nvoid f(int*t, int x) {\n int i = 0;\n found = 0;\n first_loop:\n for(; i <= 4; i++) {\n if(t[i] == x)\n found = 1;\n }\n //@ assert found <==> \\exists integer i; 0 <= i <= 4 && t[i] == x;\n}", "output": "int found;\n/*@ \nrequires \\valid(t+(0..4));\n*/\nvoid f(int*t, int x) {\n int i = 0;\n found = 0;\n first_loop:\n /*@ \n loop invariant 0 <= i <= 5;\n loop invariant found <==> (\\exists integer k; 0 <= k < i && t[k] == x);\n loop assigns found, i;\n */\n for(; i <= 4; i++) {\n if(t[i] == x)\n found = 1;\n }\n //@ assert found <==> \\exists integer i; 0 <= i <= 4 && t[i] == x;\n}", "source": "githubRepository", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."} {"filefolder_name": "code2_47", "file_name": "47", "input": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > n) {\n //@ assert c == n;\n }\n }\n}", "output": "int unknown();\n/*@\nrequires n > 0;\n*/\nvoid foo(int n) {\n int c = 0;\n // loop body\n /*@\n loop invariant 0 <= c;\n loop assigns n,c;\n */\n while (unknown()) {\n if (unknown()) {\n if (c != n) {\n c = c + 1;\n }\n } else {\n if (c == n) {\n c = 1;\n }\n }\n }\n if (c < 0) {\n if (c > n) {\n //@ assert c == n;\n }\n }\n}", "source": "autospec", "instruct": "Please write ACSL specification for the given C code ensuring its correctness.\nYou only need to return the completed ACSL formal specification together with C program without explanation."}