filefolder_name
stringlengths 4
88
| file_name
stringlengths 1
77
| input
stringlengths 84
5.03k
| output
stringlengths 136
5.55k
| source
stringclasses 3
values | instruct
stringclasses 1
value |
---|---|---|---|---|---|
suman1406_Q1 | Q1 | int grade;
int calculateGrade(int mark) {
if (mark >= 1 && mark <= 100) {
grade = 1;
return grade;
} else if (mark >= 101 && mark <= 200) {
grade = 2;
return grade;
} else if (mark >= 201 && mark <= 300) {
grade = 3;
return grade;
} else if (mark >= 301 && mark <= 400) {
grade = 4;
return grade;
}
return 0;
} | int grade;
/*@ requires mark >= 0;
ensures \result == 0 || \result == 1 || \result == 2 || \result == 3 || \result == 4;
behavior one:
assumes mark >= 1 && mark <= 100;
ensures \result == 1;
assigns grade;
behavior two:
assumes mark >= 101 && mark <= 200;
ensures \result == 2;
assigns grade;
behavior three:
assumes mark >= 201 && mark <= 300;
ensures \result == 3;
assigns grade;
behavior four:
assumes mark >= 301 && mark <= 400;
ensures \result == 4;
assigns grade;
behavior else:
assumes mark <= 0 || mark > 400;
ensures \result == 0;
assigns grade;
complete behaviors;
disjoint behaviors;
*/
int calculateGrade(int mark) {
if (mark >= 1 && mark <= 100) {
grade = 1;
return grade;
} else if (mark >= 101 && mark <= 200) {
grade = 2;
return grade;
} else if (mark >= 201 && mark <= 300) {
grade = 3;
return grade;
} else if (mark >= 301 && mark <= 400) {
grade = 4;
return grade;
}
return 0;
}
int main(){
int mark = 150;
int result = calculateGrade(mark);
//@ assert result == 2;
return 0;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_41 | 41 | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if ( unknown() ) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c != n) {
//@ assert c <= n;
}
} | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant n - c;
loop invariant c <= n;
loop invariant c <= n + 1;
loop invariant 0 <= c;
loop assigns c;
*/
while (unknown()) {
if ( unknown() ) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c != n) {
//@ assert c <= n;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
evdenis_proved_sign | sign | int spec_sign(int x)
{
return (x > 0) - (x < 0);
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int res = spec_sign(-10);
//@ assert res == -1;
return 0;
}
#endif | /*@
assigns \nothing;
ensures \result == 0 || \result == 1 || \result == -1;
behavior positive:
assumes x > 0;
ensures \result == 1;
behavior zero:
assumes x == 0;
ensures \result == 0;
behavior negative:
assumes x < 0;
ensures \result == -1;
complete behaviors;
disjoint behaviors;
*/
int spec_sign(int x)
{
return (x > 0) - (x < 0);
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int res = spec_sign(-10);
//@ assert res == -1;
return 0;
}
#endif | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
X509-parser_check_ia5_string | check_ia5_string | #include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
#define X509_FILE_NUM 1
#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000))
static int check_ia5_string(const u8 *buf, u32 len)
{
int ret;
u32 i;
if ((buf == NULL) || (len == 0)) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
for (i = 0; i < len; i++) {
if (buf[i] > 0x7f) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
}
ret = 0;
out:
return ret;
}
int main() {
u8 buf[5];
u32 len = 5;
int ret = check_ia5_string(&buf[0], len);
//@ assert ret == -X509_FILE_LINE_NUM_ERR ==> \exists integer i; 0 <= i < len && buf[i] > 0x7f;
//@ assert ret == 0 ==> \forall integer i; 0 <= i < len ==> (buf[i] <= 0x7f);
return ret;
} | #include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
#define X509_FILE_NUM 1
#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000))
/*@
requires buf != NULL && len > 0;
requires ((len > 0) && (buf != \null)) ==> \valid_read(buf + (0 .. (len - 1)));
ensures \result < 0 || \result == 0;
ensures (len == 0) ==> \result < 0;
ensures (buf == \null) ==> \result < 0;
ensures \result == 0 ==> \forall integer i; 0 <= i < len ==> (buf[i] <= 0x7f);
ensures \result == -X509_FILE_LINE_NUM_ERR ==> \exists integer i; 0 <= i < len && buf[i] > 0x7f;
ensures \exists integer i; 0 <= i < len && buf[i] > 0x7f ==> \result == -X509_FILE_LINE_NUM_ERR;
assigns \nothing;
*/
static int check_ia5_string(const u8 *buf, u32 len)
{
int ret;
u32 i;
if ((buf == NULL) || (len == 0)) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
/*@
loop invariant \forall integer x ; 0 <= x < i ==> (buf[x] <= 0x7f);
loop invariant ret ==0 ==> \forall integer x ; 0 <= x < i ==> (buf[x] <= 0x7f);
loop assigns i;
loop variant (len - i);
*/
for (i = 0; i < len; i++) {
if (buf[i] > 0x7f) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
}
ret = 0;
out:
return ret;
}
int main() {
u8 buf[5];
u32 len = 5;
int ret = check_ia5_string(&buf[0], len);
//@ assert ret == -X509_FILE_LINE_NUM_ERR ==> \exists integer i; 0 <= i < len && buf[i] > 0x7f;
//@ assert ret == 0 ==> \forall integer i; 0 <= i < len ==> (buf[i] <= 0x7f);
return ret;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_118 | 118 | /*@
requires size >= 1;
*/
void foo(int size) {
int i = 1;
int sn = 0;
while (i <= size) {
i = i + 1;
sn = sn + 1;
}
if(sn != size) {
//@ assert sn == 0;
}
} | /*@
requires size >= 1;
*/
void foo(int size) {
int i = 1;
int sn = 0;
/*@
loop invariant sn == i-1;
loop invariant sn == i - 1;
loop invariant i <= size+1;
loop invariant i <= size + 1;
loop invariant 1 <= i;
loop assigns sn;
loop assigns i;
*/
while (i <= size) {
i = i + 1;
sn = sn + 1;
}
if(sn != size) {
//@ assert sn == 0;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
general_wp_problem_max_of_2 | max_of_2 | #include <limits.h>
int max ( int x, int y ) {
if ( x >=y )
return x ;
return y ;
}
void foo()
{
int s = max(34,45);
//@ assert s==45;
int t = max(-43,34);
//@ assert t==34;
} | #include <limits.h>
/*@
requires INT_MIN<x && INT_MIN<y;
ensures \result>=x && \result>=y;
ensures \result==x || \result==y;
*/
int max ( int x, int y ) {
if ( x >=y )
return x ;
return y ;
}
void foo()
{
int s = max(34,45);
//@ assert s==45;
int t = max(-43,34);
//@ assert t==34;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
X509-parser_parse_null | parse_null | #include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
#define X509_FILE_NUM 0
#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)
/*@
predicate bmatch(u8 *b1, u8 *b2, u32 n) =
\forall integer i; 0 <= i < n ==> b1[i] == b2[i];
predicate bdiffer(u8 *b1, u8 *b2, u32 n) =
! bmatch(b1, b2, n);
*/
/*@
requires \valid_read(b1 + (0 .. n-1));
requires \valid_read(b2 + (0 .. n-1));
requires n >= 0;
ensures \result == 0 <==> bmatch(b1, b2, n);
ensures \result == 1 <==> bdiffer(b1, b2, n);
assigns \nothing;
*/
int bufs_differ(const u8 *b1, const u8 *b2, u32 n)
{
int ret = 0;
u32 i = 0;
/*@
loop invariant 0 <= i <= n;
loop invariant bmatch(b1, b2, i);
loop assigns i;
loop variant n - i;
*/
for (i = 0; i < n; i++) {
if(b1[i] != b2[i]) {
ret = 1;
break;
}
}
return ret;
}
static const u8 null_encoded_val[] = { 0x05, 0x00 };
int parse_null(const u8 *buf, u32 len, u32 *parsed)
{
int ret;
if ((len == 0) || (buf == NULL) || (parsed == NULL)) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
if (len != sizeof(null_encoded_val)) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
ret = bufs_differ(buf, null_encoded_val, sizeof(null_encoded_val));
if (ret) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
ret = 0;
*parsed = sizeof(null_encoded_val);
out:
return ret;
}
int main() {
const u8 b[] = { 0x05, 0x00 };
u32 parsed;
int ret = parse_null(b, sizeof(null_encoded_val), &parsed);
//@ assert parsed == sizeof(null_encoded_val);
//@ assert ret == 0;
return 0;
} | #include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
#define X509_FILE_NUM 0
#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)
/*@
predicate bmatch(u8 *b1, u8 *b2, u32 n) =
\forall integer i; 0 <= i < n ==> b1[i] == b2[i];
predicate bdiffer(u8 *b1, u8 *b2, u32 n) =
! bmatch(b1, b2, n);
*/
/*@
requires \valid_read(b1 + (0 .. n-1));
requires \valid_read(b2 + (0 .. n-1));
requires n >= 0;
ensures \result == 0 <==> bmatch(b1, b2, n);
ensures \result == 1 <==> bdiffer(b1, b2, n);
assigns \nothing;
*/
int bufs_differ(const u8 *b1, const u8 *b2, u32 n)
{
int ret = 0;
u32 i = 0;
/*@
loop invariant 0 <= i <= n;
loop invariant bmatch(b1, b2, i);
loop assigns i;
loop variant n - i;
*/
for (i = 0; i < n; i++) {
if(b1[i] != b2[i]) {
ret = 1;
break;
}
}
return ret;
}
static const u8 null_encoded_val[] = { 0x05, 0x00 };
/*@
requires ((len > 0) && (buf != \null)) ==> \valid_read(buf + (0 .. (len - 1)));
requires (parsed != NULL) ==> \valid(parsed);
requires \separated(parsed, buf+(..));
ensures \result < 0 || \result == 0;
ensures (len == sizeof(null_encoded_val) && len != 0 && buf != NULL && parsed != NULL) ==> (\result == 0 <==> bmatch(buf, &null_encoded_val[0], len));
ensures (\result == 0) ==> *parsed == 2;
ensures (buf == \null) ==> \result < 0;
assigns *parsed;
*/
int parse_null(const u8 *buf, u32 len, u32 *parsed)
{
int ret;
if ((len == 0) || (buf == NULL) || (parsed == NULL)) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
if (len != sizeof(null_encoded_val)) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
ret = bufs_differ(buf, null_encoded_val, sizeof(null_encoded_val));
if (ret) {
ret = -X509_FILE_LINE_NUM_ERR;
goto out;
}
ret = 0;
*parsed = sizeof(null_encoded_val);
out:
return ret;
}
int main() {
const u8 b[] = { 0x05, 0x00 };
u32 parsed;
int ret = parse_null(b, sizeof(null_encoded_val), &parsed);
//@ assert parsed == sizeof(null_encoded_val);
//@ assert ret == 0;
return 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_81 | 81 | /*@
requires x >= 0;
requires y >= 0;
requires x >= y;
*/
void foo(int x, int y) {
int i = 0;
while (unknown()) {
if ( (i < y) )
{
(i = (i + 1));
}
}
if (i < y) {
//@ assert 0 <= i;
}
} | /*@
requires x >= 0;
requires y >= 0;
requires x >= y;
*/
void foo(int x, int y) {
int i = 0;
/*@
loop invariant i <= y;
loop invariant 0 <= i;
loop assigns y,i;
*/
while (unknown()) {
if ( (i < y) )
{
(i = (i + 1));
}
}
if (i < y) {
//@ assert 0 <= i;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
corinnt_sort-3 | sort-3 | void order_3(int* a, int* b, int* c){
if(*a > *b){
int tmp = *b ; *b = *a ; *a = tmp ;
}
if(*a > *c){
int tmp = *c ; *c = *a ; *a = tmp ;
}
if(*b > *c){
int tmp = *b ; *b = *c ; *c = tmp ;
}
}
void test(){
int a1 = 5, b1 = 3, c1 = 4 ;
order_3(&a1, &b1, &c1);
//@ assert a1 == 3 && b1 == 4 && c1 == 5 ;
int a2 = 2, b2 = 2, c2 = 2 ;
order_3(&a2, &b2, &c2) ;
//@ assert a2 == 2 && b2 == 2 && c2 == 2 ;
int a3 = 4, b3 = 3, c3 = 4 ;
order_3(&a3, &b3, &c3) ;
//@ assert a3 == 3 && b3 == 4 && c3 == 4 ;
int a4 = 4, b4 = 5, c4 = 4 ;
order_3(&a4, &b4, &c4) ;
//@ assert a4 == 4 && b4 == 4 && c4 == 5 ;
} | /*@
requires \valid(a) && \valid(b) && \valid(c);
requires \separated(a, b, c);
assigns *a, *b, *c;
ensures sorted: *a <= *b <= *c ;
ensures has_all_values: { *a, *b, *c } == \old({ *a, *b, *c }) ;
ensures \old(*a == *b == *c) ==> *a == *b == *c ;
ensures \old(*a == *b < *c || *a == *c < *b || *b == *c < *a) ==> *a == *b ;
ensures \old(*a == *b > *c || *a == *c > *b || *b == *c > *a) ==> *b == *c ;
*/
void order_3(int* a, int* b, int* c){
if(*a > *b){
int tmp = *b ; *b = *a ; *a = tmp ;
}
if(*a > *c){
int tmp = *c ; *c = *a ; *a = tmp ;
}
if(*b > *c){
int tmp = *b ; *b = *c ; *c = tmp ;
}
}
void test(){
int a1 = 5, b1 = 3, c1 = 4 ;
order_3(&a1, &b1, &c1);
//@ assert a1 == 3 && b1 == 4 && c1 == 5 ;
int a2 = 2, b2 = 2, c2 = 2 ;
order_3(&a2, &b2, &c2) ;
//@ assert a2 == 2 && b2 == 2 && c2 == 2 ;
int a3 = 4, b3 = 3, c3 = 4 ;
order_3(&a3, &b3, &c3) ;
//@ assert a3 == 3 && b3 == 4 && c3 == 4 ;
int a4 = 4, b4 = 5, c4 = 4 ;
order_3(&a4, &b4, &c4) ;
//@ assert a4 == 4 && b4 == 4 && c4 == 5 ;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
general_wp_problem_swap | swap | void swap(int* a, int* b){
int tmp = *a;
*a = *b;
*b = tmp;
}
int main(){
int a = 42;
int b = 37;
swap(&a, &b);
//@ assert a == 37 && b == 42;
return 0;
} | /*@
requires \valid(a) && \valid(b);
assigns *a, *b;
ensures *a == \old(*b);
ensures *b == \old(*a);
*/
void swap(int* a, int* b){
int tmp = *a;
*a = *b;
*b = tmp;
}
int main(){
int a = 42;
int b = 37;
swap(&a, &b);
//@ assert a == 37 && b == 42;
return 0;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
count | count | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic UnchangedLemmas
{
lemma Unchanged_Shrink{K,L}:
\forall value_type *a, integer m, n, p, q;
m <= p <= q <= n ==>
Unchanged{K,L}(a, m, n) ==>
Unchanged{K,L}(a, p, q);
lemma Unchanged_Extend{K,L}:
\forall value_type *a, integer n;
Unchanged{K,L}(a, n) ==>
\at(a[n],K) == \at(a[n],L) ==>
Unchanged{K,L}(a, n+1);
lemma Unchanged_Symmetric{K,L}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,K}(a, m, n);
lemma Unchanged_Transitive{K,L,M}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,M}(a, m, n) ==>
Unchanged{K,M}(a, m, n);
}
*/
/*@
axiomatic Count
{
logic integer
Count(value_type* a, integer m, integer n, value_type v) =
n <= m ? 0 : Count(a, m, n-1, v) + (a[n-1] == v ? 1 : 0);
logic integer
Count(value_type* a, integer n, value_type v) = Count(a, 0, n, v);
lemma Count_Empty:
\forall value_type *a, v, integer m, n;
n <= m ==> Count(a, m, n, v) == 0;
lemma Count_Hit:
\forall value_type *a, v, integer n, m;
m < n ==>
a[n-1] == v ==>
Count(a, m, n, v) == Count(a, m, n-1, v) + 1;
lemma Count_Miss:
\forall value_type *a, v, integer n, m;
m < n ==>
a[n-1] != v ==>
Count(a, m, n, v) == Count(a, m, n-1, v);
lemma Count_One:
\forall value_type *a, v, integer m, n;
m <= n ==> Count(a, m, n+1, v) == Count(a, m, n, v) + Count(a, n, n+1, v);
lemma Count_Single{K,L}:
\forall value_type *a, *b, v, integer m, n;
\at(a[m],K) == \at(b[n],L) ==>
Count{K}(a, m, m+1, v) == Count{L}(b, n, n+1, v);
lemma Count_Single_Bounds:
\forall value_type *a, v, integer n;
0 <= Count(a, n, n+1, v) <= 1;
lemma Count_Single_Shift:
\forall value_type *a, v, integer n;
0 <= n ==> Count(a+n, 0, 1, v) == Count(a, n, n+1, v);
}
*/
size_type
count(const value_type* a, size_type n, value_type v)
{
size_type counted = 0u;
for (size_type i = 0u; i < n; ++i) {
if (a[i] == v) {
counted++;
}
}
//@ assert Count(a, n, v) == counted;
return counted;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic UnchangedLemmas
{
lemma Unchanged_Shrink{K,L}:
\forall value_type *a, integer m, n, p, q;
m <= p <= q <= n ==>
Unchanged{K,L}(a, m, n) ==>
Unchanged{K,L}(a, p, q);
lemma Unchanged_Extend{K,L}:
\forall value_type *a, integer n;
Unchanged{K,L}(a, n) ==>
\at(a[n],K) == \at(a[n],L) ==>
Unchanged{K,L}(a, n+1);
lemma Unchanged_Symmetric{K,L}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,K}(a, m, n);
lemma Unchanged_Transitive{K,L,M}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,M}(a, m, n) ==>
Unchanged{K,M}(a, m, n);
}
*/
/*@
axiomatic Count
{
logic integer
Count(value_type* a, integer m, integer n, value_type v) =
n <= m ? 0 : Count(a, m, n-1, v) + (a[n-1] == v ? 1 : 0);
logic integer
Count(value_type* a, integer n, value_type v) = Count(a, 0, n, v);
lemma Count_Empty:
\forall value_type *a, v, integer m, n;
n <= m ==> Count(a, m, n, v) == 0;
lemma Count_Hit:
\forall value_type *a, v, integer n, m;
m < n ==>
a[n-1] == v ==>
Count(a, m, n, v) == Count(a, m, n-1, v) + 1;
lemma Count_Miss:
\forall value_type *a, v, integer n, m;
m < n ==>
a[n-1] != v ==>
Count(a, m, n, v) == Count(a, m, n-1, v);
lemma Count_One:
\forall value_type *a, v, integer m, n;
m <= n ==> Count(a, m, n+1, v) == Count(a, m, n, v) + Count(a, n, n+1, v);
lemma Count_Single{K,L}:
\forall value_type *a, *b, v, integer m, n;
\at(a[m],K) == \at(b[n],L) ==>
Count{K}(a, m, m+1, v) == Count{L}(b, n, n+1, v);
lemma Count_Single_Bounds:
\forall value_type *a, v, integer n;
0 <= Count(a, n, n+1, v) <= 1;
lemma Count_Single_Shift:
\forall value_type *a, v, integer n;
0 <= n ==> Count(a+n, 0, 1, v) == Count(a, n, n+1, v);
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
assigns \nothing;
ensures bound: 0 <= \result <= n;
ensures count: \result == Count(a, n, v);
*/
size_type
count(const value_type* a, size_type n, value_type v)
{
size_type counted = 0u;
/*@
loop invariant bound: 0 <= i <= n;
loop invariant bound: 0 <= counted <= i;
loop invariant count: counted == Count(a, i, v);
loop assigns i, counted;
loop variant n-i;
*/
for (size_type i = 0u; i < n; ++i) {
if (a[i] == v) {
counted++;
}
}
//@ assert Count(a, n, v) == counted;
return counted;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_87 | 87 | void foo(int x, int y) {
int lock = 1;
while ((x != y)) {
if (unknown()) {
lock = 1;
x = y;
} else {
lock = 0;
x = y;
y = y + 1;
}
}
//@ assert lock == 1;
} | /*@
requires x == y;
*/
void foo(int x, int y) {
int lock = 1;
/*@
loop invariant x == y;
loop invariant lock == 1;
loop invariant lock == 1 || lock == 0;
loop invariant lock == 0 || lock == 1;
loop assigns y;
loop assigns x;
loop assigns lock;
*/
while ((x != y)) {
if (unknown()) {
lock = 1;
x = y;
} else {
lock = 0;
x = y;
y = y + 1;
}
}
//@ assert lock == 1;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_55 | 55 | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c < 0) {
if (c > n) {
//@ assert c == n;
}
}
} | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant n - c;
loop invariant c >= 0 && c <= n;
loop invariant c > n ==> c == n;
loop invariant c > n ==> c == n + 1;
loop invariant c <= n;
loop invariant \forall integer k; 1 <= k <= c ==> (\exists integer i; 1 <= i <= n && i == c);
loop invariant 0 <= c;
loop assigns n,c;
*/
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c < 0) {
if (c > n) {
//@ assert c == n;
}
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
arrays_and_loops_5 | 5 | int fun(int x, int y , int *r) {
*r = x;
int d = 0;
while (*r >= y) {
*r = *r - y;
d = d + 1;
}
return d;
}
int main() {
int a = 3;
int num = fun(1, 2, &a);
//@ assert a == 1;
//@ assert num == 0;
return 0;
} | /*@
requires x ==1 && y==2;
ensures *r < y;
ensures \result == 0 <==> x < y;
ensures x == \result*y + *r;
ensures \result ==0 ==> x == *r;
*/
int fun(int x, int y , int *r) {
*r = x;
int d = 0;
/*@
loop invariant d >= 0;
loop invariant *r <= x;
loop invariant *r < y ==> d == 0;
loop invariant *r == x - y*d;
loop assigns *r, d;
*/
while (*r >= y) {
*r = *r - y;
d = d + 1;
}
return d;
}
int main() {
int a = 3;
int num = fun(1, 2, &a);
//@ assert a == 1;
//@ assert num == 0;
return 0;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
21176_BL.EN.U4CSE21176_4a | BL.EN.U4CSE21176_4a | #include<limits.h>
int check(int n){
if(n%3==0)
return 1;
else
return 0;
}
int main(){
int a=9;
int r=check(a);
//@assert a==9;
} | #include<limits.h>
/*@
requires INT_MIN<=n;
requires INT_MAX>n;
ensures (n%3==0 ==> \result==1) && (n%3!=0 ==> \result==0);
*/
int check(int n){
if(n%3==0)
return 1;
else
return 0;
}
int main(){
int a=9;
int r=check(a);
//@assert a==9;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_130 | 130 | void foo(int x2, int x3) {
int d1 = 1;
int d2 = 1;
int d3 = 1;
int x1 = 1;
while(x1 > 0) {
if(x2 > 0) {
if(x3 > 0) {
x1 = x1 - d1;
x2 = x2 - d2;
x3 = x3 - d3;
}
}
}
//@ assert x2 >= 0;
} | void foo(int x2, int x3) {
int d1 = 1;
int d2 = 1;
int d3 = 1;
int x1 = 1;
/*@
loop invariant x1 > 0 || (x2 >= 0 && x3 >= 0);
loop invariant x1 > 0 ==> (x2 > 0 ==> x3 > 0 ==> x1 - d1 >= 0 && x2 - d2 >= 0 && x3 - d3 >= 0);
loop invariant x1 > 0 ==> (x2 > 0 ==> x3 > 0 ==> x1 - d1 < x1 && x2 - d2 < x2 && x3 - d3 < x3);
loop invariant d3 == 1;
loop invariant d2 == 1;
loop invariant d1 == 1;
loop invariant 0 <= x1;
loop invariant (x2 > 0 && x3 > 0) || (x2 <= 0 || x3 <= 0);
loop assigns x1,x2,x3,d1,d2,d3;
*/
while(x1 > 0) {
if(x2 > 0) {
if(x3 > 0) {
x1 = x1 - d1;
x2 = x2 - d2;
x3 = x3 - d3;
}
}
}
//@ assert x2 >= 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
remove_copy | remove_copy | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic SomeNone
{
predicate
SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =
\exists integer i; m <= i < n && a[i] == v;
predicate
SomeEqual{A}(value_type* a, integer n, value_type v) =
SomeEqual(a, 0, n, v);
predicate
NoneEqual(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> a[i] != v;
predicate
NoneEqual(value_type* a, integer n, value_type v) =
NoneEqual(a, 0, n, v);
lemma NotSomeEqual_NoneEqual:
\forall value_type *a, v, integer m, n;
!SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);
lemma NoneEqual_NotSomeEqual:
\forall value_type *a, v, integer m, n;
NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);
}
*/
size_type
remove_copy(const value_type *a, size_type n, value_type *b, value_type v)
{
size_type k = 0u;
for (size_type i = 0u; i < n; ++i) {
if (a[i] != v) {
b[k++] = a[i];
}
}
//@ assert NoneEqual(b, k, v);
return k;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic SomeNone
{
predicate
SomeEqual{A}(value_type* a, integer m, integer n, value_type v) =
\exists integer i; m <= i < n && a[i] == v;
predicate
SomeEqual{A}(value_type* a, integer n, value_type v) =
SomeEqual(a, 0, n, v);
predicate
NoneEqual(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> a[i] != v;
predicate
NoneEqual(value_type* a, integer n, value_type v) =
NoneEqual(a, 0, n, v);
lemma NotSomeEqual_NoneEqual:
\forall value_type *a, v, integer m, n;
!SomeEqual(a, m, n, v) ==> NoneEqual(a, m, n, v);
lemma NoneEqual_NotSomeEqual:
\forall value_type *a, v, integer m, n;
NoneEqual(a, m, n, v) ==> !SomeEqual(a, m, n, v);
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires valid: \valid(b + (0..n-1));
requires sep: \separated(a + (0..n-1), b + (0..n-1));
assigns b[0..n-1];
ensures bound: 0 <= \result <= n;
ensures discard: NoneEqual(b, \result, v);
ensures unchanged: Unchanged{Old,Here}(a, n);
ensures unchanged: Unchanged{Old,Here}(b, \result, n);
*/
size_type
remove_copy(const value_type *a, size_type n, value_type *b, value_type v)
{
size_type k = 0u;
/*@
loop invariant bound: 0 <= k <= i <= n;
loop invariant discard: NoneEqual(b, k, v);
loop invariant unchanged: Unchanged{Pre,Here}(b, k, n);
loop assigns k, i, b[0..n-1];
loop variant n-i;
*/
for (size_type i = 0u; i < n; ++i) {
if (a[i] != v) {
b[k++] = a[i];
}
}
//@ assert NoneEqual(b, k, v);
return k;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_113 | 113 | /*@
requires 1 <= n;
*/
void foo(int n) {
int i = 1;
int sn = 0;
while (i <= n) {
i = i + 1;
sn = sn + 1;
}
if (sn != 0) {
//@ assert sn == n;
}
} | /*@
requires 1 <= n;
*/
void foo(int n) {
int i = 1;
int sn = 0;
/*@
loop invariant sn == i-1;
loop invariant sn == i - 1;
loop invariant i <= n+1;
loop invariant i <= n + 1;
loop invariant 1 <= i;
loop assigns sn;
loop assigns i;
*/
while (i <= n) {
i = i + 1;
sn = sn + 1;
}
if (sn != 0) {
//@ assert sn == n;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_38 | 38 | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if(c == n) {
c = 1;
}
else {
c = c + 1;
}
}
if(c == n) {
//@ assert c >= 0;
//@ assert c <= n;
}
} | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant c <= n;
loop invariant 0 <= c;
loop invariant (c == n) ==> (c >= 0 && c <= n);
loop assigns c;
*/
while (unknown()) {
if(c == n) {
c = 1;
}
else {
c = c + 1;
}
}
if(c == n) {
//@ assert c >= 0;
//@ assert c <= n;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
arepina_distance_abs | distance_abs | #define SPEC_INT_MIN -2147483648
#define SPEC_INT_MAX 2147483647
unsigned distance_abs(int a, int b)
{
unsigned ua = a < 0 ? -a : a;
unsigned ub = b < 0 ? -b : b;
return ua > ub ? ua - ub : ub - ua;
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a = distance_abs(3, 30);
int b = distance_abs(-5, -20);
int c = distance_abs(7, -10);
int d = distance_abs(-2, 15);
//@ assert a == 27;
//@ assert b == 15;
//@ assert c == 17;
//@ assert d == 17;
return 0;
}
#endif | #define SPEC_INT_MIN -2147483648
#define SPEC_INT_MAX 2147483647
/*@ requires \true;
requires a > SPEC_INT_MIN;
requires b > SPEC_INT_MIN;
assigns \nothing;
ensures \result == \abs(\abs(a) - \abs(b));
*/
unsigned distance_abs(int a, int b)
{
unsigned ua = a < 0 ? -a : a;
unsigned ub = b < 0 ? -b : b;
return ua > ub ? ua - ub : ub - ua;
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a = distance_abs(3, 30);
int b = distance_abs(-5, -20);
int c = distance_abs(7, -10);
int d = distance_abs(-2, 15);
//@ assert a == 27;
//@ assert b == 15;
//@ assert c == 17;
//@ assert d == 17;
return 0;
}
#endif | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
suman1406_Q5 | Q5 | #include <limits.h>
int equ(int a[], int b[], int n)
{
for (int i = 0; i < n; i++)
{
if (a[i] != b[i])
{
return 0;
}
}
return 1;
}
int main(){
int a[10]={1,2,3,4,5,6,7,8,9,10};
int b[10]={1,2,3,4,5,6,7,8,9,10};
int c[10]={1,2,3,4,5,6,7,8,9,11};
int res=equ(a,b,10);
int res1=equ(a,c,10);
//@ assert res==1;
//@ assert res1==0;
} | #include <limits.h>
/*@
requires n>0 && n<INT_MAX;
requires \valid_read(a+(0..n-1));
requires \valid_read(b+(0..n-1));
assigns \nothing;
behavior same:
assumes \forall integer j;0<=j<n ==> a[j]==b[j];
ensures \result==1;
behavior notones:
assumes \exists integer j;0<=j<n && a[j]!=b[j];
ensures \result==0;
complete behaviors;
disjoint behaviors;
*/
int equ(int a[], int b[], int n)
{
/*@
loop invariant 0<=i<=n;
loop invariant \forall integer j;0<=j<i ==> a[j]==b[j];
loop assigns i;
loop variant n-i;
*/
for (int i = 0; i < n; i++)
{
if (a[i] != b[i])
{
return 0;
}
}
return 1;
}
int main(){
int a[10]={1,2,3,4,5,6,7,8,9,10};
int b[10]={1,2,3,4,5,6,7,8,9,10};
int c[10]={1,2,3,4,5,6,7,8,9,11};
int res=equ(a,b,10);
int res1=equ(a,c,10);
//@ assert res==1;
//@ assert res1==0;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_91 | 91 | int main(){
int x = 0;
int y = 0;
while(y >= 0){
y = y + x;
}
//@ assert y >= 0;
} | int main(){
int x = 0;
int y = 0;
/*@
loop invariant 0 <= y;
loop invariant 0 <= x;
loop assigns y;
loop assigns x;
*/
while(y >= 0){
y = y + x;
}
//@ assert y >= 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
X509-parser_time_components_to_comparable_u64 | time_components_to_comparable_u64 | #include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
u64 time_components_to_comparable_u64(u16 na_year, u8 na_month, u8 na_day,
u8 na_hour, u8 na_min, u8 na_sec)
{
u64 res, tmp;
res = ((u64)na_sec);
/*@ assert res < (1ULL << 6); */
tmp = ((u64)na_min) * (1ULL << 8);
/*@ assert tmp < (1ULL << 14); */
res += tmp;
/*@ assert res < (1ULL << 15); */
tmp = (((u64)na_hour) * (1ULL << 16));
/*@ assert tmp < (1ULL << 21); */
res += tmp;
/*@ assert res < (1ULL << 22); */
tmp = ((u64)na_day) * (1ULL << 24);
/*@ assert tmp < (1ULL << 29); */
res += tmp;
/*@ assert res < (1ULL << 30); */
tmp = ((u64)na_month) * (1ULL << 32);
/*@ assert tmp < (1ULL << 36); */
res += tmp;
/*@ assert res < (1ULL << 37); */
tmp = ((u64)na_year) * (1ULL << 40);
/*@ assert tmp < (1ULL << 54); */
res += tmp;
/*@ assert res < (1ULL << 55); */
return res;
}
int main(void)
{
u16 na_year = 2023;
u8 na_month = 12;
u8 na_day = 20;
u8 na_hour = 12;
u8 na_min = 00;
u8 na_sec = 00;
u64 res;
res = time_components_to_comparable_u64(na_year, na_month, na_day, na_hour, na_min, na_sec);
//@ assert res < (1ULL << 55);
return 0;
} | #include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
/*@
requires na_year <= 9999;
requires na_month <= 12;
requires na_day <= 31;
requires na_hour <= 23;
requires na_min <= 59;
requires na_sec <= 59;
ensures \result < (1ULL << 55);
assigns \nothing;
*/
u64 time_components_to_comparable_u64(u16 na_year, u8 na_month, u8 na_day,
u8 na_hour, u8 na_min, u8 na_sec)
{
u64 res, tmp;
res = ((u64)na_sec);
/*@ assert res < (1ULL << 6); */
tmp = ((u64)na_min) * (1ULL << 8);
/*@ assert tmp < (1ULL << 14); */
res += tmp;
/*@ assert res < (1ULL << 15); */
tmp = (((u64)na_hour) * (1ULL << 16));
/*@ assert tmp < (1ULL << 21); */
res += tmp;
/*@ assert res < (1ULL << 22); */
tmp = ((u64)na_day) * (1ULL << 24);
/*@ assert tmp < (1ULL << 29); */
res += tmp;
/*@ assert res < (1ULL << 30); */
tmp = ((u64)na_month) * (1ULL << 32);
/*@ assert tmp < (1ULL << 36); */
res += tmp;
/*@ assert res < (1ULL << 37); */
tmp = ((u64)na_year) * (1ULL << 40);
/*@ assert tmp < (1ULL << 54); */
res += tmp;
/*@ assert res < (1ULL << 55); */
return res;
}
int main(void)
{
u16 na_year = 2023;
u8 na_month = 12;
u8 na_day = 20;
u8 na_hour = 12;
u8 na_min = 00;
u8 na_sec = 00;
u64 res;
res = time_components_to_comparable_u64(na_year, na_month, na_day, na_hour, na_min, na_sec);
//@ assert res < (1ULL << 55);
return 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_110 | 110 | /*@
requires 1 <= n;
*/
void foo(int n) {
int i = 1;
int sn = 0;
while (i <= n) {
i = i + 1;
sn = sn + 1;
}
if (sn != n) {
//@ assert sn == 0;
}
} | /*@
requires 1 <= n;
*/
void foo(int n) {
int i = 1;
int sn = 0;
/*@
loop invariant sn == i-1;
loop invariant sn == i - 1;
loop invariant sn <= n;
loop invariant sn <= i-1;
loop invariant i <= n+1;
loop invariant i <= n + 1;
loop invariant 1 <= i;
loop invariant 0 <= sn;
loop assigns sn;
loop assigns i;
*/
while (i <= n) {
i = i + 1;
sn = sn + 1;
}
if (sn != n) {
//@ assert sn == 0;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
find | find | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
size_type
find(const value_type* a, size_type n, value_type v)
{
for (size_type i = 0u; i < n; i++) {
if (a[i] == v) {
//@ assert \exists integer k; 0 <= k < n && a[k] == v;
return i;
}
}
//@ assert \forall integer k; 0 <= k < n ==> a[k] != v;
return n;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
requires \valid_read(a + (0..n-1));
assigns \nothing;
ensures 0 <= \result <= n;
behavior some:
assumes \exists integer i; 0 <= i < n && a[i] == v;
assigns \nothing;
ensures 0 <= \result < n;
ensures a[\result] == v;
ensures \forall integer i; 0 <= i < \result ==> a[i] != v;
behavior none:
assumes \forall integer i; 0 <= i < n ==> a[i] != v;
assigns \nothing;
ensures \result == n;
complete behaviors;
disjoint behaviors;
*/
size_type
find(const value_type* a, size_type n, value_type v)
{
/*@
loop invariant 0 <= i <= n;
loop invariant \forall integer k; 0 <= k < i ==> a[k] != v;
loop assigns i;
loop variant n-i;
*/
for (size_type i = 0u; i < n; i++) {
if (a[i] == v) {
//@ assert \exists integer k; 0 <= k < n && a[k] == v;
return i;
}
}
//@ assert \forall integer k; 0 <= k < n ==> a[k] != v;
return n;
}
| fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_89 | 89 | /*@
requires x == y;
*/
void foo(int x, int y) {
int lock = 1;
while (x != y) {
if (unknown()) {
lock = 1;
x = y;
} else {
lock = 0;
x = y;
y = y + 1;
}
}
//@ assert lock == 1;
} | /*@
requires x == y;
*/
void foo(int x, int y) {
int lock = 1;
/*@
loop invariant x == y;
loop invariant lock == 1;
loop invariant lock == 1 || lock == 0;
loop invariant lock == 0 || lock == 1;
loop invariant lock != 1 ==> x == y;
loop invariant (lock == 1) || (lock == 0);
loop assigns x,y,lock;
*/
while (x != y) {
if (unknown()) {
lock = 1;
x = y;
} else {
lock = 0;
x = y;
y = y + 1;
}
}
//@ assert lock == 1;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_65 | 65 | int main() {
int x = 1;
int y = 0;
while (x <= 100) {
y = 100 - x;
x = x +1;
}
//@ assert y >= 0;
} | int main() {
int x = 1;
int y = 0;
/*@
loop invariant y <= 100;
loop invariant 0 <= y;
loop invariant -99 <= y;
loop invariant x <= 101;
loop invariant 1 <= x;
loop invariant 0 <= x;
loop assigns y,x;
*/
while (x <= 100) {
y = 100 - x;
x = x +1;
}
//@ assert y >= 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
corinnt_days | days | int day_of(int month){
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } ;
return days[month-1] ;
}
int main(){
int days2 = day_of(2);
//@ assert days2 == 28;
int days7 = day_of(7);
//@ assert days7 == 31;
} | /*@
requires input_range: 1 <= month <= 12;
assigns \nothing;
ensures result_options: \result \in {28, 30, 31};
behavior day_28:
assumes month == 2;
ensures \result == 28;
behavior day_30:
assumes month \in { 4, 6, 9, 11 } ;
ensures \result == 30;
behavior days_31:
assumes month \in {1, 3, 5, 7, 8, 10, 12};
ensures \result == 31;
complete behaviors;
disjoint behaviors;
*/
int day_of(int month){
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } ;
return days[month-1] ;
}
int main(){
int days2 = day_of(2);
//@ assert days2 == 28;
int days7 = day_of(7);
//@ assert days7 == 31;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
mismatch | mismatch | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
size_type
mismatch(const value_type* a, size_type n, const value_type* b)
{
for (size_type i = 0u; i < n; i++) {
if (a[i] != b[i]) {
//@ assert !Equal{Here,Here}(a, n, b);
return i;
}
}
//@ assert Equal{Here,Here}(a, n, b);
return n;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires valid: \valid_read(b + (0..n-1));
assigns \nothing;
ensures result: 0 <= \result <= n;
behavior all_equal:
assumes Equal{Here,Here}(a, n, b);
assigns \nothing;
ensures result: \result == n;
behavior some_not_equal:
assumes !Equal{Here,Here}(a, n, b);
assigns \nothing;
ensures bound: 0 <= \result < n;
ensures result: a[\result] != b[\result];
ensures first: Equal{Here,Here}(a, \result, b);
complete behaviors;
disjoint behaviors;
*/
size_type
mismatch(const value_type* a, size_type n, const value_type* b)
{
/*@
loop invariant bound: 0 <= i <= n;
loop invariant equal: Equal{Here,Here}(a, i, b);
loop assigns i;
loop variant n-i;
*/
for (size_type i = 0u; i < n; i++) {
if (a[i] != b[i]) {
//@ assert !Equal{Here,Here}(a, n, b);
return i;
}
}
//@ assert Equal{Here,Here}(a, n, b);
return n;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
evdenis_small-examples_lshift | lshift | #define INT_MAX 2147483647
unsigned lshift(unsigned a)
{
return a << 1;
}
int main() {
unsigned a = 5;
unsigned result = lshift(a);
//@ assert result == 10;
return 0;
} | #define INT_MAX 2147483647
/*@ requires (a * 2) <= INT_MAX;
assigns \nothing;
ensures \result == a * 2;
*/
unsigned lshift(unsigned a)
{
return a << 1;
}
int main() {
unsigned a = 5;
unsigned result = lshift(a);
//@ assert result == 10;
return 0;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
arrays_and_loops_4 | 4 | #include<limits.h>
int test(int x) {
int a = x;
int y = 0;
while(a != 0) {
y = y + 1;
a = a - 1;
}
return y;
}
int main() {
int num = test(3);
//@ assert num == 3;
return 0;
} | #include<limits.h>
/*@
requires x > 0 && x < INT_MAX;
ensures \result == x;
assigns \nothing;
*/
int test(int x) {
int a = x;
int y = 0;
/*@
loop invariant y + a == x;
loop invariant a > -1 && a <= x;
loop assigns a, y;
*/
while(a != 0) {
y = y + 1;
a = a - 1;
}
return y;
}
int main() {
int num = test(3);
//@ assert num == 3;
return 0;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_102 | 102 | /*@
requires n >= 0;
*/
void foo(int n) {
int x = 0;
while (x < n) {
x = x + 1;
}
if(n >= 0) {
//@ assert x == n;
}
} | /*@
requires n >= 0;
*/
void foo(int n) {
int x = 0;
/*@
loop invariant x <= n;
loop invariant 0 <= x;
loop assigns x;
loop assigns n;
*/
while (x < n) {
x = x + 1;
}
if(n >= 0) {
//@ assert x == n;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
corinnt_order_inc_max | order_inc_max | /*@
requires \valid(a) && \valid(b);
assigns *a, *b ;
behavior reorder:
assumes *a < *b ;
ensures *a == \old(*b) && *b == \old(*a) ;
behavior do_not_change:
assumes *a >= *b ;
ensures *a == \old(*a) && *b == \old(*b) ;
complete behaviors ;
disjoint behaviors ;
*/
void max_ptr(int* a, int* b){
if(*a < *b){
int tmp = *b ;
*b = *a ;
*a = tmp ;
}
//@ assert *a >= *b ;
}
/*@
requires \valid(a) && \valid(b);
assigns *a, *b ;
behavior reorder:
assumes *a > *b ;
ensures *a == \old(*b) && *b == \old(*a) ;
behavior do_not_change:
assumes *a <= *b ;
ensures *a == \old(*a) && *b == \old(*b) ;
complete behaviors ;
disjoint behaviors ;
*/
void min_ptr(int* a, int* b){
max_ptr(b, a);
//@ assert *a <= *b ;
}
void order_3_inc_max_min(int* a, int* b, int* c) {
max_ptr(c, b) ;
max_ptr(c, a) ;
max_ptr(b, a) ;
//@ assert *a <= *b && *b <= *c ;
}
| /*@
requires \valid(a) && \valid(b);
assigns *a, *b ;
behavior reorder:
assumes *a < *b ;
ensures *a == \old(*b) && *b == \old(*a) ;
behavior do_not_change:
assumes *a >= *b ;
ensures *a == \old(*a) && *b == \old(*b) ;
complete behaviors ;
disjoint behaviors ;
*/
void max_ptr(int* a, int* b){
if(*a < *b){
int tmp = *b ;
*b = *a ;
*a = tmp ;
}
//@ assert *a >= *b ;
}
/*@
requires \valid(a) && \valid(b);
assigns *a, *b ;
behavior reorder:
assumes *a > *b ;
ensures *a == \old(*b) && *b == \old(*a) ;
behavior do_not_change:
assumes *a <= *b ;
ensures *a == \old(*a) && *b == \old(*b) ;
complete behaviors ;
disjoint behaviors ;
*/
void min_ptr(int* a, int* b){
max_ptr(b, a);
//@ assert *a <= *b ;
}
/*@ requires \valid(a) && \valid(b) && \valid(c) ;
requires \separated(a, b, c);
assigns *a, *b, *c ;
ensures { \old(*a), \old(*b), \old(*c) } == { *a, *b, *c };
behavior all_equal:
assumes *a == *b == *c ;
ensures *a == *b == *c;
behavior all_uequal:
assumes *a != *b && *a != *c && *b != *c ;
ensures *a != *b && *a != *c && *b != *c ;
behavior two_eq_lt:
assumes *a == *b < *c ||
*a == *c < *b ||
*b == *c < *a;
ensures *a == *b;
behavior two_eq_gt:
assumes *a == *b > *c ||
*a == *c > *b ||
*b == *c > *a;
ensures *b == *c;
complete behaviors ;
disjoint behaviors ;
*/
void order_3_inc_max(int* a, int* b, int* c) {
max_ptr(c, b) ;
max_ptr(c, a) ;
max_ptr(b, a) ;
//@ assert *a <= *b && *b <= *c ;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_56 | 56 | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c == n) {
//@ assert n <= -1;
}
} | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant n - c;
loop invariant c <= n;
loop invariant c <= n+1;
loop invariant 0 <= c;
loop assigns n,c;
*/
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c == n) {
//@ assert n <= -1;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_99 | 99 | /*@
requires n >= 0;
*/
void foo(int n) {
int x = n;
int y = 0;
while (x > 0) {
y = y + 1;
x = x - 1;
}
//@ assert n == x + y;
} | /*@
requires n >= 0;
*/
void foo(int n) {
int x = n;
int y = 0;
/*@
loop invariant y == n - x;
loop invariant y <= n;
loop invariant x <= n;
loop invariant x + y == n;
loop invariant n == x + y;
loop invariant 0 <= y;
loop invariant 0 <= x;
loop assigns y;
loop assigns x;
*/
while (x > 0) {
y = y + 1;
x = x - 1;
}
//@ assert n == x + y;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
adjacent_difference | adjacent_difference | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Difference
{
logic integer
Difference{L}(value_type* a, integer n) =
n <= 0 ? a[0] : a[n] - a[n-1];
lemma Difference_Zero{L}:
\forall value_type *a; Difference(a, 0) == a[0];
lemma Difference_Next{L}:
\forall value_type *a, integer n;
0 < n ==> Difference(a, n) == a[n] - a[n-1];
lemma Difference_Unchanged{K,L}:
\forall value_type *a, integer n;
0 <= n ==> Unchanged{K,L}(a, n+1) ==>
Difference{K}(a, n) == Difference{L}(a, n);
}
*/
/*@
axiomatic AdjacentDifference
{
predicate
AdjacentDifference{L}(value_type* a, integer n, value_type* b) =
\forall integer i; 0 <= i < n ==> b[i] == Difference(a, i);
predicate
AdjacentDifferenceBounds(value_type* a, integer n) =
\forall integer i; 1 <= i < n ==>
VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;
lemma AdjacentDifference_Step{K,L}:
\forall value_type *a, *b, integer n;
AdjacentDifference{K}(a, n, b) ==>
Unchanged{K,L}(b, n) ==>
Unchanged{K,L}(a, n+1) ==>
\at(b[n],L) == Difference{L}(a, n) ==>
AdjacentDifference{L}(a, n+1, b);
lemma AdjacentDifference_Section{K}:
\forall value_type *a, *b, integer m, n;
0 <= m <= n ==>
AdjacentDifference{K}(a, n, b) ==>
AdjacentDifference{K}(a, m, b);
}
*/
size_type
adjacent_difference(const value_type* a, size_type n, value_type* b)
{
if (0u < n) {
b[0u] = a[0u];
for (size_type i = 1u; i < n; ++i) {
//@ assert bound: VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;
b[i] = a[i] - a[i - 1u];
//@ assert difference: AdjacentDifference(a, i+1, b);
}
}
return n;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Difference
{
logic integer
Difference{L}(value_type* a, integer n) =
n <= 0 ? a[0] : a[n] - a[n-1];
lemma Difference_Zero{L}:
\forall value_type *a; Difference(a, 0) == a[0];
lemma Difference_Next{L}:
\forall value_type *a, integer n;
0 < n ==> Difference(a, n) == a[n] - a[n-1];
lemma Difference_Unchanged{K,L}:
\forall value_type *a, integer n;
0 <= n ==> Unchanged{K,L}(a, n+1) ==>
Difference{K}(a, n) == Difference{L}(a, n);
}
*/
/*@
axiomatic AdjacentDifference
{
predicate
AdjacentDifference{L}(value_type* a, integer n, value_type* b) =
\forall integer i; 0 <= i < n ==> b[i] == Difference(a, i);
predicate
AdjacentDifferenceBounds(value_type* a, integer n) =
\forall integer i; 1 <= i < n ==>
VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;
lemma AdjacentDifference_Step{K,L}:
\forall value_type *a, *b, integer n;
AdjacentDifference{K}(a, n, b) ==>
Unchanged{K,L}(b, n) ==>
Unchanged{K,L}(a, n+1) ==>
\at(b[n],L) == Difference{L}(a, n) ==>
AdjacentDifference{L}(a, n+1, b);
lemma AdjacentDifference_Section{K}:
\forall value_type *a, *b, integer m, n;
0 <= m <= n ==>
AdjacentDifference{K}(a, n, b) ==>
AdjacentDifference{K}(a, m, b);
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires valid: \valid(b + (0..n-1));
requires sep: \separated(a + (0..n-1), b + (0..n-1));
requires bounds: AdjacentDifferenceBounds(a, n);
assigns b[0..n-1];
ensures result: \result == n;
ensures difference: AdjacentDifference(a, n, b);
ensures unchanged: Unchanged{Old,Here}(a, n);
*/
size_type
adjacent_difference(const value_type* a, size_type n, value_type* b)
{
if (0u < n) {
b[0u] = a[0u];
/*@
loop invariant index: 1 <= i <= n;
loop invariant unchanged: Unchanged{Pre,Here}(a, n);
loop invariant difference: AdjacentDifference(a, i, b);
loop assigns i, b[1..n-1];
loop variant n - i;
*/
for (size_type i = 1u; i < n; ++i) {
//@ assert bound: VALUE_TYPE_MIN <= Difference(a, i) <= VALUE_TYPE_MAX;
b[i] = a[i] - a[i - 1u];
//@ assert difference: AdjacentDifference(a, i+1, b);
}
}
return n;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_45 | 45 | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c != n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if(c != n) {
//@ assert c >= 0;
}
} | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant c == n ==> c == n;
loop invariant 0 <= c;
loop assigns n,c;
*/
while (unknown()) {
if (unknown()) {
if (c != n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if(c != n) {
//@ assert c >= 0;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
frama-c-wp-tutorial-en_18 | 18 | #include <stddef.h>
#include <limits.h>
int* search(int* array, size_t length, int element){
for(size_t i = 0; i < length; i++){
if(array[i] == element) return &array[i];
}
return NULL;
}
int main(){
int array[] = {1,2,3,4,5};
int *p = search(array,5,6);
//@ assert p == NULL;
} | #include <stddef.h>
#include <limits.h>
/*@
requires \valid_read(array+(0..length-1));
assigns \nothing;
behavior in:
assumes \exists size_t off;0<=off<length&&array[off]==element;
ensures array<=\result<array+length&&*\result==element;
behavior notin:
assumes \forall size_t off;0<=off<length==>array[off]!=element;
ensures \result==NULL;
disjoint behaviors;
complete behaviors;
*/
int* search(int* array, size_t length, int element) {
/*@
loop invariant 0<=i<=length;
loop invariant \forall size_t j;0<=j<i==>array[j]!=element;
loop assigns i;
loop variant length-i;
*/
for(size_t i = 0; i < length; i++)
if(array[i]==element) return &array[i];
return NULL;
}
int main(){
int array[] = {1,2,3,4,5};
int *p = search(array,5,6);
//@ assert p == NULL;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
21176_BL.EN.U4CSE21176_1 | BL.EN.U4CSE21176_1 | #include<limits.h>
int max(int a,int b){
return a>b?a:b;
}
int main(){
int x=4;
int y=5;
int r=max(x,y);
//@assert x==4 && y==5;
} | #include<limits.h>
/*@
requires INT_MIN<=a<INT_MAX;
requires INT_MIN<=b<INT_MAX;
ensures \result==a && \result>b || \result==b && \result>a || \result==a && \result==b;
*/
int max(int a,int b){
return a>b?a:b;
}
int main(){
int x=4;
int y=5;
int r=max(x,y);
//@assert x==4 && y==5;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
general_wp_problem_triangle_sides | triangle_sides | #include <stdio.h>
int validts(int a, int b, int c) {
int valid = 0;
if ((a+b>c) && (a+c>b) && (b+c>a) && 1) {
valid = 1;
} else {
valid = 0;
}
return valid;
}
void test() {
int valid = validts(2,3,4);
//@ assert valid == 1;
} | #include <stdio.h>
/*@
requires a>0 && b>0 && c>0;
ensures \result == 1 <==> (a+b>c) && (a+c>b) && (b+c>a);
ensures \result == 0 <==> !(a+b>c) || !(a+c>b) || !(b+c>a);
*/
int validts(int a, int b, int c) {
int valid = 0;
if ((a+b>c) && (a+c>b) && (b+c>a) && 1) {
valid = 1;
} else {
valid = 0;
}
return valid;
}
void test() {
int valid = validts(2,3,4);
//@ assert valid == 1;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
frama-c-wp-tutorial-en_9 | 9 | void max_ptr(int* a, int* b){
if(*a < *b){
int tmp = *b;
*b = *a;
*a = tmp;
}
}
int main(){
int x = 10, y = 20;
max_ptr(&x, &y);
//@ assert x == 20 && y == 10;
return 0;
} | /*@ requires \valid(a) && \valid(b);
assigns *a, *b;
ensures \old(*a) < \old(*b) ==> *a == \old(*b) && *b == \old(*a);
ensures \old(*a) >= \old(*b) ==> *a == \old(*a) && *b == \old(*b);
*/
void max_ptr(int* a, int* b){
if(*a < *b){
int tmp = *b;
*b = *a;
*a = tmp;
}
}
int main(){
int x = 10, y = 20;
max_ptr(&x, &y);
//@ assert x == 20 && y == 10;
return 0;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_71 | 71 | /*@
requires y >= 127;
*/
void foo(int y) {
int c = 0;
int z = 36 * y;
while (unknown()) {
if (c < 36)
{
z = z + 1;
c = c + 1;
}
}
if (c < 36) {
//@ assert z >= 0;
}
} | /*@
requires y >= 127;
*/
void foo(int y) {
int c = 0;
int z = 36 * y;
/*@
loop invariant z == 36*y + c;
loop invariant z == 36 * y + c;
loop invariant c <= 36;
loop invariant 36 * y <= z;
loop invariant 0 <= c;
loop assigns z;
loop assigns c;
*/
while (unknown()) {
if (c < 36)
{
z = z + 1;
c = c + 1;
}
}
if (c < 36) {
//@ assert z >= 0;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_107 | 107 | /*@
requires a <= m;
*/
void foo(int a, int m) {
int j = 0;
int k = 0;
while ( k < 1) {
if(m < a) {
m = a;
}
k = k + 1;
}
//@ assert a <= m;
} | /*@
requires a <= m;
*/
void foo(int a, int m) {
int j = 0;
int k = 0;
/*@
loop invariant k <= 1;
loop invariant a <= m;
loop invariant 0 <= k;
loop assigns m;
loop assigns k;
*/
while ( k < 1) {
if(m < a) {
m = a;
}
k = k + 1;
}
//@ assert a <= m;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
axiom_size_of_pop | axiom_size_of_pop | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
struct Stack
{
value_type* obj;
size_type capacity;
size_type size;
};
typedef struct Stack Stack;
/*@
axiomatic StackInvariant
{
logic integer
StackCapacity{L}(Stack* s) = s->capacity;
logic integer
StackSize{L}(Stack* s) = s->size;
logic value_type*
StackStorage{L}(Stack* s) = s->obj;
logic integer
StackTop{L}(Stack* s) = s->obj[s->size-1];
predicate
StackEmpty{L}(Stack* s) = StackSize(s) == 0;
predicate
StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);
predicate
StackInvariant{L}(Stack* s) =
0 < StackCapacity(s) &&
0 <= StackSize(s) <= StackCapacity(s) &&
\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&
\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));
}
*/
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic StackUtility
{
predicate
StackSeparated(Stack* s, Stack* t) =
\separated(s, s->obj + (0..s->capacity-1),
t, t->obj + (0..t->capacity-1));
predicate
StackUnchanged{K,L}(Stack* s) =
StackSize{K}(s) == StackSize{L}(s) &&
StackStorage{K}(s) == StackStorage{L}(s) &&
StackCapacity{K}(s) == StackCapacity{L}(s) &&
Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic StackEquality
{
predicate
StackEqual{S,T}(Stack* s, Stack* t) =
StackSize{S}(s) == StackSize{T}(t) &&
Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));
lemma StackEqual_Reflexive{S} :
\forall Stack* s; StackEqual{S,S}(s, s);
lemma StackEqual_Symmetric{S,T} :
\forall Stack *s, *t;
StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);
lemma StackEqual_Transitive{S,T,U}:
\forall Stack *s, *t, *u;
StackEqual{S,T}(s, t) ==>
StackEqual{T,U}(t, u) ==>
StackEqual{S,U}(s, u);
}
*/
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns s->size;
ensures valid: \valid(s) && StackInvariant(s);
behavior empty:
assumes StackEmpty(s);
assigns \nothing;
ensures empty: StackEmpty(s);
ensures unchanged: StackUnchanged{Old,Here}(s);
behavior not_empty:
assumes !StackEmpty(s);
assigns s->size;
ensures size: StackSize(s) == StackSize{Old}(s) - 1;
ensures full: !StackFull(s);
ensures storage: StackStorage(s) == StackStorage{Old}(s);
ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);
ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));
complete behaviors;
disjoint behaviors;
*/
void
stack_pop(Stack* s);
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns \nothing;
ensures size: \result == StackSize(s);
*/
size_type
stack_size(const Stack* s);
size_type
axiom_size_of_pop(Stack* s)
{
stack_pop(s);
//@ assert StackSize(s) == StackSize{Pre}(s) - 1;
return stack_size(s);
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
struct Stack
{
value_type* obj;
size_type capacity;
size_type size;
};
typedef struct Stack Stack;
/*@
axiomatic StackInvariant
{
logic integer
StackCapacity{L}(Stack* s) = s->capacity;
logic integer
StackSize{L}(Stack* s) = s->size;
logic value_type*
StackStorage{L}(Stack* s) = s->obj;
logic integer
StackTop{L}(Stack* s) = s->obj[s->size-1];
predicate
StackEmpty{L}(Stack* s) = StackSize(s) == 0;
predicate
StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);
predicate
StackInvariant{L}(Stack* s) =
0 < StackCapacity(s) &&
0 <= StackSize(s) <= StackCapacity(s) &&
\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&
\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));
}
*/
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic StackUtility
{
predicate
StackSeparated(Stack* s, Stack* t) =
\separated(s, s->obj + (0..s->capacity-1),
t, t->obj + (0..t->capacity-1));
predicate
StackUnchanged{K,L}(Stack* s) =
StackSize{K}(s) == StackSize{L}(s) &&
StackStorage{K}(s) == StackStorage{L}(s) &&
StackCapacity{K}(s) == StackCapacity{L}(s) &&
Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic StackEquality
{
predicate
StackEqual{S,T}(Stack* s, Stack* t) =
StackSize{S}(s) == StackSize{T}(t) &&
Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));
lemma StackEqual_Reflexive{S} :
\forall Stack* s; StackEqual{S,S}(s, s);
lemma StackEqual_Symmetric{S,T} :
\forall Stack *s, *t;
StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);
lemma StackEqual_Transitive{S,T,U}:
\forall Stack *s, *t, *u;
StackEqual{S,T}(s, t) ==>
StackEqual{T,U}(t, u) ==>
StackEqual{S,U}(s, u);
}
*/
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns s->size;
ensures valid: \valid(s) && StackInvariant(s);
behavior empty:
assumes StackEmpty(s);
assigns \nothing;
ensures empty: StackEmpty(s);
ensures unchanged: StackUnchanged{Old,Here}(s);
behavior not_empty:
assumes !StackEmpty(s);
assigns s->size;
ensures size: StackSize(s) == StackSize{Old}(s) - 1;
ensures full: !StackFull(s);
ensures storage: StackStorage(s) == StackStorage{Old}(s);
ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);
ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize(s));
complete behaviors;
disjoint behaviors;
*/
void
stack_pop(Stack* s);
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns \nothing;
ensures size: \result == StackSize(s);
*/
size_type
stack_size(const Stack* s);
/*@
requires valid: \valid(s) && StackInvariant(s);
requires empty: !StackEmpty(s);
assigns s->size;
ensures size: \result == StackSize{Old}(s) - 1;
*/
size_type
axiom_size_of_pop(Stack* s)
{
stack_pop(s);
//@ assert StackSize(s) == StackSize{Pre}(s) - 1;
return stack_size(s);
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_30 | 30 | /*@
requires (x == 100);
*/
void foo(int x) {
while (x > 0) {
x = x - 1;
}
//@ assert x == 0;
} | /*@
requires (x == 100);
*/
void foo(int x) {
// loop body
/*@
loop invariant x <= 100;
loop invariant 0 <= x;
loop assigns x;
*/
while (x > 0) {
x = x - 1;
}
// post-condition
//@ assert x == 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_127 | 127 | void foo(int x, int y) {
int i = x;
int j = y;
while (x != 0) {
x = x - 1;
y = y - 1;
}
if (y != 0) {
//@ assert i != j;
}
} | void foo(int x, int y) {
int i = x;
int j = y;
/*@
loop invariant y <= j;
loop invariant x <= i;
loop invariant j - y == i - x;
loop invariant i - x == j - y;
loop assigns x,y,i,j;
*/
while (x != 0) {
x = x - 1;
y = y - 1;
}
if (y != 0) {
//@ assert i != j;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
evdenis_proved_reverse_in_place | reverse_in_place | /*@
requires \valid(&a[i]);
requires \valid(&a[j]);
assigns a[i], a[j];
ensures a[i] == \old(a[j]);
ensures a[j] == \old(a[i]);
*/
void swap(int a[], int i, int j);
void reverse_in_place(int a[], int size)
{
int i;
for(i = 0; i < (size / 2); ++i) {
swap(a, i, size - i - 1);
}
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int size = sizeof(a) / sizeof(a[0]);
//@ assert a[0] == 1;
reverse_in_place(a, size);
//@ assert a[0] == 10;
}
#endif | /*@
requires \valid(&a[i]);
requires \valid(&a[j]);
assigns a[i], a[j];
ensures a[i] == \old(a[j]);
ensures a[j] == \old(a[i]);
*/
void swap(int a[], int i, int j);
/*@
predicate reverse{L1,L2}(int* a, integer size, integer i, integer j) =
\forall integer k; i <= k < j ==>
\at(a[k], L1) == \at(a[size - k - 1], L2);
predicate reverse{L1,L2}(int* a, integer size) = reverse{L1,L2}(a, size, 0, size);
*/
/*@
requires size >= 0;
requires \valid(a+(0..size-1));
assigns a[0..size-1];
ensures reverse{Pre,Here}(a, size);
ensures \forall integer i; 0 <= i < size ==>
\exists integer j; 0 <= j < size &&
\old(a[\at(i,Here)]) == a[j];
*/
void reverse_in_place(int a[], int size)
{
int i;
/*@ loop invariant 0 <= i <= size / 2;
loop invariant reverse{Pre,Here}(a, size, 0, i);
loop invariant \forall integer j; i <= j < size - i ==> a[j] == \at(a[\at(j,Here)],Pre);
loop invariant reverse{Pre,Here}(a, size, size - i, size);
loop assigns i, a[0..size-1];
loop variant size / 2 - i;
*/
for(i = 0; i < (size / 2); ++i) {
swap(a, i, size - i - 1);
}
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int size = sizeof(a) / sizeof(a[0]);
//@ assert a[0] == 1;
reverse_in_place(a, size);
//@ assert a[0] == 10;
}
#endif | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
stack_push_wd | stack_push_wd | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
struct Stack
{
value_type* obj;
size_type capacity;
size_type size;
};
typedef struct Stack Stack;
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic StackInvariant
{
logic integer
StackCapacity{L}(Stack* s) = s->capacity;
logic integer
StackSize{L}(Stack* s) = s->size;
logic value_type*
StackStorage{L}(Stack* s) = s->obj;
logic integer
StackTop{L}(Stack* s) = s->obj[s->size-1];
predicate
StackEmpty{L}(Stack* s) = StackSize(s) == 0;
predicate
StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);
predicate
StackInvariant{L}(Stack* s) =
0 < StackCapacity(s) &&
0 <= StackSize(s) <= StackCapacity(s) &&
\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&
\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));
}
*/
/*@
axiomatic StackUtility
{
predicate
StackSeparated(Stack* s, Stack* t) =
\separated(s, s->obj + (0..s->capacity-1),
t, t->obj + (0..t->capacity-1));
predicate
StackUnchanged{K,L}(Stack* s) =
StackSize{K}(s) == StackSize{L}(s) &&
StackStorage{K}(s) == StackStorage{L}(s) &&
StackCapacity{K}(s) == StackCapacity{L}(s) &&
Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));
}
*/
/*@
axiomatic StackEquality
{
predicate
StackEqual{S,T}(Stack* s, Stack* t) =
StackSize{S}(s) == StackSize{T}(t) &&
Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));
lemma StackEqual_Reflexive{S} :
\forall Stack* s; StackEqual{S,S}(s, s);
lemma StackEqual_Symmetric{S,T} :
\forall Stack *s, *t;
StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);
lemma StackEqual_Transitive{S,T,U}:
\forall Stack *s, *t, *u;
StackEqual{S,T}(s, t) ==>
StackEqual{T,U}(t, u) ==>
StackEqual{S,U}(s, u);
}
*/
/*@
axiomatic StackLemmas
{
lemma StackPush_Equal{K,L}:
\forall Stack *s, *t;
StackEqual{K,K}(s,t) ==>
StackSize{L}(s) == StackSize{K}(s) + 1 ==>
StackSize{L}(s) == StackSize{L}(t) ==>
StackTop{L}(s) == StackTop{L}(t) ==>
Equal{L,L}(StackStorage{L}(s),
StackSize{K}(s),
StackStorage{L}(t)) ==>
StackEqual{L,L}(s,t);
}
*/
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns s->size, s->obj[s->size];
behavior full:
assumes StackFull(s);
assigns \nothing;
ensures valid: \valid(s) && StackInvariant(s);
ensures full: StackFull(s);
ensures unchanged: StackUnchanged{Old,Here}(s);
behavior not_full:
assumes !StackFull(s);
assigns s->size;
assigns s->obj[s->size];
ensures valid: \valid(s) && StackInvariant(s);
ensures size: StackSize(s) == StackSize{Old}(s) + 1;
ensures top: StackTop(s) == v;
ensures storage: StackStorage(s) == StackStorage{Old}(s);
ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);
ensures not_empty: !StackEmpty(s);
ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));
complete behaviors;
disjoint behaviors;
*/
void
stack_push(Stack* s, value_type v);
void
stack_push_wd(Stack* s, Stack* t, value_type v)
{
stack_push(s, v);
stack_push(t, v);
//@ assert top: StackTop(s) == v;
//@ assert top: StackTop(t) == v;
//@ assert equal: Equal{Here,Here}(StackStorage(s), StackSize{Pre}(s), StackStorage(t));
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
struct Stack
{
value_type* obj;
size_type capacity;
size_type size;
};
typedef struct Stack Stack;
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic StackInvariant
{
logic integer
StackCapacity{L}(Stack* s) = s->capacity;
logic integer
StackSize{L}(Stack* s) = s->size;
logic value_type*
StackStorage{L}(Stack* s) = s->obj;
logic integer
StackTop{L}(Stack* s) = s->obj[s->size-1];
predicate
StackEmpty{L}(Stack* s) = StackSize(s) == 0;
predicate
StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);
predicate
StackInvariant{L}(Stack* s) =
0 < StackCapacity(s) &&
0 <= StackSize(s) <= StackCapacity(s) &&
\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&
\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));
}
*/
/*@
axiomatic StackUtility
{
predicate
StackSeparated(Stack* s, Stack* t) =
\separated(s, s->obj + (0..s->capacity-1),
t, t->obj + (0..t->capacity-1));
predicate
StackUnchanged{K,L}(Stack* s) =
StackSize{K}(s) == StackSize{L}(s) &&
StackStorage{K}(s) == StackStorage{L}(s) &&
StackCapacity{K}(s) == StackCapacity{L}(s) &&
Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));
}
*/
/*@
axiomatic StackEquality
{
predicate
StackEqual{S,T}(Stack* s, Stack* t) =
StackSize{S}(s) == StackSize{T}(t) &&
Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));
lemma StackEqual_Reflexive{S} :
\forall Stack* s; StackEqual{S,S}(s, s);
lemma StackEqual_Symmetric{S,T} :
\forall Stack *s, *t;
StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);
lemma StackEqual_Transitive{S,T,U}:
\forall Stack *s, *t, *u;
StackEqual{S,T}(s, t) ==>
StackEqual{T,U}(t, u) ==>
StackEqual{S,U}(s, u);
}
*/
/*@
axiomatic StackLemmas
{
lemma StackPush_Equal{K,L}:
\forall Stack *s, *t;
StackEqual{K,K}(s,t) ==>
StackSize{L}(s) == StackSize{K}(s) + 1 ==>
StackSize{L}(s) == StackSize{L}(t) ==>
StackTop{L}(s) == StackTop{L}(t) ==>
Equal{L,L}(StackStorage{L}(s),
StackSize{K}(s),
StackStorage{L}(t)) ==>
StackEqual{L,L}(s,t);
}
*/
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns s->size, s->obj[s->size];
behavior full:
assumes StackFull(s);
assigns \nothing;
ensures valid: \valid(s) && StackInvariant(s);
ensures full: StackFull(s);
ensures unchanged: StackUnchanged{Old,Here}(s);
behavior not_full:
assumes !StackFull(s);
assigns s->size;
assigns s->obj[s->size];
ensures valid: \valid(s) && StackInvariant(s);
ensures size: StackSize(s) == StackSize{Old}(s) + 1;
ensures top: StackTop(s) == v;
ensures storage: StackStorage(s) == StackStorage{Old}(s);
ensures capacity: StackCapacity(s) == StackCapacity{Old}(s);
ensures not_empty: !StackEmpty(s);
ensures unchanged: Unchanged{Old,Here}(StackStorage(s), StackSize{Old}(s));
complete behaviors;
disjoint behaviors;
*/
void
stack_push(Stack* s, value_type v);
/*@
requires valid: \valid(s) && StackInvariant(s);
requires valid: \valid(t) && StackInvariant(t);
requires equal: StackEqual{Here,Here}(s, t);
requires not_full: !StackFull(s) && !StackFull(t);
requires sep: StackSeparated(s, t);
assigns s->size, s->obj[s->size];
assigns t->size, t->obj[t->size];
ensures valid: StackInvariant(s) && StackInvariant(t);
ensures equal: StackEqual{Here,Here}(s, t);
*/
void
stack_push_wd(Stack* s, Stack* t, value_type v)
{
stack_push(s, v);
stack_push(t, v);
//@ assert top: StackTop(s) == v;
//@ assert top: StackTop(t) == v;
//@ assert equal: Equal{Here,Here}(StackStorage(s), StackSize{Pre}(s), StackStorage(t));
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
arepina_average | average | int average(int a, int b)
{
int average = 0;
int greater;
int smaller;
if (a > b) {
greater = a;
smaller = b;
} else {
greater = b;
smaller = a;
}
if (a >= 0 && b >= 0) {
average = smaller + (greater - smaller) / 2;
} else if (a < 0 && b < 0) {
average = greater + (smaller - greater) / 2;
} else if ((a >= 0 && b <= 0) || (a <= 0 && b >= 0)) {
average = (a + b) / 2;
}
return average;
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a = average(3,30);
int b = average(-5,-20);
int c = average(7,-10);
int d = average(-2,15);
//@ assert a == 16;
//@ assert b == -13;
//@ assert c == -3;
//@ assert d == 8;
return 0;
}
#endif | /*@ assigns \nothing;
ensures \result == (a+b)/2;
*/
int average(int a, int b)
{
int average = 0;
int greater;
int smaller;
if (a > b) {
greater = a;
smaller = b;
} else {
greater = b;
smaller = a;
}
if (a >= 0 && b >= 0) {
average = smaller + (greater - smaller) / 2;
} else if (a < 0 && b < 0) {
average = greater + (smaller - greater) / 2;
} else if ((a >= 0 && b <= 0) || (a <= 0 && b >= 0)) {
average = (a + b) / 2;
}
return average;
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a = average(3,30);
int b = average(-5,-20);
int c = average(7,-10);
int d = average(-2,15);
//@ assert a == 16;
//@ assert b == -13;
//@ assert c == -3;
//@ assert d == 8;
return 0;
}
#endif | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
21176_LogicFunction2 | LogicFunction2 | #include<limits.h>
/*@
logic integer ax_b(integer a,integer x,integer b) = a*x+b;
*/
/*@
assigns \nothing;
ensures \result==ax_b(a,x,4);
*/
int func(int a,int x){
return a*x+4;
}
void check(int a,int x,int y){
int fmin,fmax;
if(x>y){
fmin=func(a,x);
fmax=func(a,y);
}
else{
fmin=func(a,y);
fmax=func(a,x);
}
//@assert fmin<=fmax;
}
int main(){
int w=3;
int r=4;
int s=7;
int t=func(w,r);
check(w,r,s);
} | #include<limits.h>
/*@
logic integer ax_b(integer a,integer x,integer b) = a*x+b;
*/
/*@
assigns \nothing;
ensures \result==ax_b(a,x,4);
*/
int func(int a,int x){
return a*x+4;
}
/*@
requires INT_MIN<=a*x<INT_MAX;
requires INT_MIN<=a*y<INT_MAX;
requires a>0;
requires INT_MIN<=ax_b(a,x,4)<=INT_MAX;
requires INT_MIN<=ax_b(a,y,4)<=INT_MAX;
assigns \nothing;
*/
void check(int a,int x,int y){
int fmin,fmax;
if(x < y){}
else{
int temp = x;
x = y;
y = temp;
}
fmin=func(a,x);
fmax=func(a,y);
//@assert fmin== ax_b(a, (x < y ? x : y), 4);
}
int main(){
int w=3;
int r=4;
int s=7;
int t=func(w,r);
check(w,r,s);
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
frama-c-wp-tutorial-en_3 | 3 | #include<limits.h>
int plus_5(int* a) {
return *a + 5;
}
int main(){
int a = 10;
int b = plus_5(&a);
//@ assert b == 15;
} | #include<limits.h>
/*@
requires \valid_read(a);
requires *a <= INT_MAX - 5;
assigns \nothing;
ensures \result == *a + 5;
*/
int plus_5(int* a) {
return *a + 5;
}
int main(){
int a = 10;
int b = plus_5(&a);
//@ assert b == 15;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
corinnt_assigns | assigns | void foo(){
int h = 42 ;
int x = 0 ;
int e = 0 ;
PreLoop:
while(e < 10){
++ e ;
x += e * 2 ;
}
//@ assert h == 42 ;
} | void foo(){
int h = 42 ;
int x = 0 ;
int e = 0 ;
PreLoop:
/*@
loop invariant h == \at(h, PreLoop) ;
loop assigns e, x ;
loop variant 10 - e;
*/
while(e < 10){
++ e ;
x += e * 2 ;
}
//@ assert h == 42 ;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_96 | 96 | void foo(int x) {
int i = 0;
int j = 0;
int y = 0;
while (i <= x) {
i = i + 1;
j = j + y;
}
if (i != j) {
//@ assert y != 1;
}
} | void foo(int x) {
int i = 0;
int j = 0;
int y = 0;
/*@
loop invariant y == 0;
loop invariant j == y*i;
loop invariant j == y*(i-1);
loop invariant j == i*y;
loop invariant j == (i-1)*y;
loop invariant j <= y*(i-1);
loop invariant 0 <= j;
loop invariant 0 <= i;
loop assigns y,i,j;
*/
while (i <= x) {
i = i + 1;
j = j + y;
}
if (i != j) {
//@ assert y != 1;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_40 | 40 | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if ( (c != n) ) {
//@ assert (c >= 0) ;
}
} | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant n-c;
loop invariant n - c;
loop invariant c <= n;
loop invariant c <= n || c == 1;
loop invariant 0 <= c;
loop invariant (c <= n && c >= 0) || (c == n+1);
loop assigns c;
*/
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if ( (c != n) ) {
//@ assert (c >= 0) ;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
stack_empty_wd | stack_empty_wd | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
struct Stack
{
value_type* obj;
size_type capacity;
size_type size;
};
typedef struct Stack Stack;
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic StackInvariant
{
logic integer
StackCapacity{L}(Stack* s) = s->capacity;
logic integer
StackSize{L}(Stack* s) = s->size;
logic value_type*
StackStorage{L}(Stack* s) = s->obj;
logic integer
StackTop{L}(Stack* s) = s->obj[s->size-1];
predicate
StackEmpty{L}(Stack* s) = StackSize(s) == 0;
predicate
StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);
predicate
StackInvariant{L}(Stack* s) =
0 < StackCapacity(s) &&
0 <= StackSize(s) <= StackCapacity(s) &&
\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&
\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));
}
*/
/*@
axiomatic StackUtility
{
predicate
StackSeparated(Stack* s, Stack* t) =
\separated(s, s->obj + (0..s->capacity-1),
t, t->obj + (0..t->capacity-1));
predicate
StackUnchanged{K,L}(Stack* s) =
StackSize{K}(s) == StackSize{L}(s) &&
StackStorage{K}(s) == StackStorage{L}(s) &&
StackCapacity{K}(s) == StackCapacity{L}(s) &&
Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));
}
*/
/*@
axiomatic StackEquality
{
predicate
StackEqual{S,T}(Stack* s, Stack* t) =
StackSize{S}(s) == StackSize{T}(t) &&
Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));
lemma StackEqual_Reflexive{S} :
\forall Stack* s; StackEqual{S,S}(s, s);
lemma StackEqual_Symmetric{S,T} :
\forall Stack *s, *t;
StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);
lemma StackEqual_Transitive{S,T,U}:
\forall Stack *s, *t, *u;
StackEqual{S,T}(s, t) ==>
StackEqual{T,U}(t, u) ==>
StackEqual{S,U}(s, u);
}
*/
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns \nothing;
ensures empty: \result == 1 <==> StackEmpty(s);
ensures not_empty: \result == 0 <==> !StackEmpty(s);
*/
bool
stack_empty(const Stack* s);
bool
stack_empty_wd(const Stack* s, const Stack* t)
{
return stack_empty(s) == stack_empty(t);
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
struct Stack
{
value_type* obj;
size_type capacity;
size_type size;
};
typedef struct Stack Stack;
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic StackInvariant
{
logic integer
StackCapacity{L}(Stack* s) = s->capacity;
logic integer
StackSize{L}(Stack* s) = s->size;
logic value_type*
StackStorage{L}(Stack* s) = s->obj;
logic integer
StackTop{L}(Stack* s) = s->obj[s->size-1];
predicate
StackEmpty{L}(Stack* s) = StackSize(s) == 0;
predicate
StackFull{L}(Stack* s) = StackSize(s) == StackCapacity(s);
predicate
StackInvariant{L}(Stack* s) =
0 < StackCapacity(s) &&
0 <= StackSize(s) <= StackCapacity(s) &&
\valid(StackStorage(s) + (0..StackCapacity(s)-1)) &&
\separated(s, StackStorage(s) + (0..StackCapacity(s)-1));
}
*/
/*@
axiomatic StackUtility
{
predicate
StackSeparated(Stack* s, Stack* t) =
\separated(s, s->obj + (0..s->capacity-1),
t, t->obj + (0..t->capacity-1));
predicate
StackUnchanged{K,L}(Stack* s) =
StackSize{K}(s) == StackSize{L}(s) &&
StackStorage{K}(s) == StackStorage{L}(s) &&
StackCapacity{K}(s) == StackCapacity{L}(s) &&
Unchanged{K,L}(StackStorage{K}(s), StackSize{K}(s));
}
*/
/*@
axiomatic StackEquality
{
predicate
StackEqual{S,T}(Stack* s, Stack* t) =
StackSize{S}(s) == StackSize{T}(t) &&
Equal{S,T}(StackStorage{S}(s), StackSize{S}(s), StackStorage{T}(t));
lemma StackEqual_Reflexive{S} :
\forall Stack* s; StackEqual{S,S}(s, s);
lemma StackEqual_Symmetric{S,T} :
\forall Stack *s, *t;
StackEqual{S,T}(s, t) ==> StackEqual{T,S}(t, s);
lemma StackEqual_Transitive{S,T,U}:
\forall Stack *s, *t, *u;
StackEqual{S,T}(s, t) ==>
StackEqual{T,U}(t, u) ==>
StackEqual{S,U}(s, u);
}
*/
/*@
requires valid: \valid(s) && StackInvariant(s);
assigns \nothing;
ensures empty: \result == 1 <==> StackEmpty(s);
ensures not_empty: \result == 0 <==> !StackEmpty(s);
*/
bool
stack_empty(const Stack* s);
/*@
requires valid: \valid(s) && StackInvariant(s);
requires valid: \valid(t) && StackInvariant(t);
requires equal: StackEqual{Here,Here}(s, t);
assigns \nothing;
ensures StackEmpty(s) && StackEmpty(t) ==> \result == true;
ensures (!StackEmpty(s) && StackEmpty(t)) || (StackEmpty(s) && !StackEmpty(t)) || (!StackEmpty(s) && !StackEmpty(t)) ==> \result == false;
*/
bool
stack_empty_wd(const Stack* s, const Stack* t)
{
return stack_empty(s) && stack_empty(t);
}
int main(){
value_type a[5] = {1, 2, 3, 4, 5};
value_type b[5] = {1, 2, 3, 4, 5};
Stack s1, s2;
s1.capacity = 5;
s1.size = 5;
s1.obj = a;
s2.capacity = 5;
s2.size = 5;
s2.obj = b;
bool result = stack_empty_wd(&s1, &s2);
//@ assert result == false;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_54 | 54 | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c != n) {
//@ assert c <= n;
}
} | /*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
/*@
loop invariant n-c;
loop invariant n - c;
loop invariant c <= n;
loop invariant 0 <= c;
loop assigns c;
*/
while (unknown()) {
if (unknown()) {
if (c > n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c != n) {
//@ assert c <= n;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
evdenis_small-examples_divide | divide | int divide(int a, int b)
{
return a / b;
}
int main(){
int a = 10;
int b = 2;
int c = divide(a, b);
//@ assert c == 5;
} | /*@
requires b != 0;
requires b != -1;
assigns \nothing;
ensures \result == a / b;
*/
int divide(int a, int b)
{
return a / b;
}
int main(){
int a = 10;
int b = 2;
int c = divide(a, b);
//@ assert c == 5;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
swap_ranges | swap_ranges | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
requires \valid(a) && \valid(b);
assigns *a, *b;
ensures *a == \old(*b) && *b == \old(*a);
*/
void swap(int* a, int* b);
void
swap_ranges(value_type* a, size_type n, value_type* b)
{
for (size_type i = 0u; i < n; ++i) {
swap(a + i, b + i);
}
}
int main(){
value_type a[] = {1, 2, 3, 4, 5};
value_type b[] = {6, 7, 8, 9, 10};
int n = 5;
swap_ranges(a, n, b);
//@ assert a[0] == 6 && b[0] == 1;
//@ assert a[1] == 7 && b[1] == 2;
//@ assert a[2] == 8 && b[2] == 3;
//@ assert a[3] == 9 && b[3] == 4;
//@ assert a[4] == 10 && b[4] == 5;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
*/
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
requires \valid(a) && \valid(b);
assigns *a, *b;
ensures *a == \old(*b) && *b == \old(*a);
*/
void swap(int* a, int* b);
/*@
requires valid: \valid(a + (0..n-1));
requires valid: \valid(b + (0..n-1));
requires sep: \separated(a+(0..n-1), b+(0..n-1));
assigns a[0..n-1];
assigns b[0..n-1];
ensures equal: Equal{Old,Here}(a, n, b);
ensures equal: Equal{Old,Here}(b, n, a);
*/
void
swap_ranges(value_type* a, size_type n, value_type* b)
{
/*@
loop invariant bound: 0 <= i <= n;
loop invariant equal: Equal{Pre,Here}(a, i, b);
loop invariant equal: Equal{Pre,Here}(b, i, a);
loop invariant unchanged: Unchanged{Pre,Here}(a, i, n);
loop invariant unchanged: Unchanged{Pre,Here}(b, i, n);
loop assigns i, a[0..n-1], b[0..n-1];
loop variant n-i;
*/
for (size_type i = 0u; i < n; ++i) {
swap(a + i, b + i);
}
}
int main(){
value_type a[] = {1, 2, 3, 4, 5};
value_type b[] = {6, 7, 8, 9, 10};
int n = 5;
swap_ranges(a, n, b);
//@ assert a[0] == 6 && b[0] == 1;
//@ assert a[1] == 7 && b[1] == 2;
//@ assert a[2] == 8 && b[2] == 3;
//@ assert a[3] == 9 && b[3] == 4;
//@ assert a[4] == 10 && b[4] == 5;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
arepina_reverse | reverse | void reverse(int a[], int res[], int size)
{
int i;
for(i = size - 1; i >= 0; --i) {
res[i] = a[size - i - 1];
}
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int size = sizeof(a) / sizeof(a[0]);
reverse(a, b, size);
//@ assert \forall integer i; 0 <= i < size ==> b[i] == a[size - i - 1];
}
#endif | /*@ requires size >= 0;
requires \valid(a+(0..size-1));
requires \valid(res+(0..size-1));
assigns res[0..size-1];
ensures \forall integer i; 0 <= i < size ==> res[i] == a[size - i - 1];
*/
void reverse(int a[], int res[], int size)
{
int i;
/*@ loop invariant -1 <= i < size;
loop invariant \forall integer j; i < j < size ==> res[j] == a[size - j - 1];
loop assigns i, res[0..size-1];
loop variant i;
*/
for(i = size - 1; i >= 0; --i) {
res[i] = a[size - i - 1];
}
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int size = sizeof(a) / sizeof(a[0]);
reverse(a, b, size);
//@ assert \forall integer i; 0 <= i < size ==> b[i] == a[size - i - 1];
}
#endif | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
miscellaneous_array_max_advanced | array_max_advanced | int array_max_advanced(int* arr, int n) {
int max = arr[0];
for (int i = 0; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
//@ assert \forall integer j; 0 <= j < n ==> arr[j] <= max;
return max;
} | /*@
requires n > 0;
requires \valid(arr+(0..n-1));
ensures \forall integer i; 0 <= i < n ==> arr[i] <= \result;
assigns \nothing;
*/
int array_max_advanced(int* arr, int n) {
int max = arr[0];
/*@
loop invariant 0 <= i <= n;
loop invariant \forall integer j; 0 <= j < i ==> arr[j] <= max;
loop assigns i, max;
loop variant n - i;
*/
for (int i = 0; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
//@ assert \forall integer j; 0 <= j < n ==> arr[j] <= max;
return max;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_80 | 80 | /*@
requires x >= 0;
requires y >= 0;
requires x >= y;
*/
void foo(int x, int y) {
int i = 0;
while (unknown()) {
if (i < y)
{
i = i + 1;
}
}
if (i <= y) {
//@ assert i <= x;
}
} | /*@
requires x >= 0;
requires y >= 0;
requires x >= y;
*/
void foo(int x, int y) {
int i = 0;
/*@
loop invariant y <= x;
loop invariant i <= x;
loop invariant 0 <= y;
loop invariant 0 <= x;
loop invariant i <= y;
loop invariant i <= y + 1;
loop invariant 0 <= i;
loop assigns x,y,i;
*/
while (unknown()) {
if (i < y)
{
i = i + 1;
}
}
if (i <= y) {
//@ assert i <= x;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_83 | 83 | int main() {
int x = -5000;
int y = 0;
while ((x < 0)) {
x = x + y;
y = y + 1;
}
//@ assert y > 0;
} | int main() {
int x = -5000;
int y = 0;
/*@
loop invariant x >= 0 ==> y > 0;
loop invariant -5000 <= x;
loop invariant -5000 <= x + y;
loop invariant 0 <= y;
loop assigns y,x;
*/
while ((x < 0)) {
x = x + y;
y = y + 1;
}
//@ assert y > 0;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_100 | 100 | /*@
requires n >= 0;
*/
void foo(int n) {
int x = n;
int y = 0;
while (x > 0) {
y = y + 1;
x = x - 1;
}
//@ assert y == n;
} | /*@
requires n >= 0;
*/
void foo(int n) {
int x = n;
int y = 0;
/*@
loop invariant y == n - x;
loop invariant y <= n;
loop invariant y + x == n;
loop invariant x <= n;
loop invariant 0 <= y;
loop invariant 0 <= x;
loop assigns y;
loop assigns x;
*/
while (x > 0) {
y = y + 1;
x = x - 1;
}
//@ assert y == n;
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
lower_bound | lower_bound | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic WeaklyIncreasing
{
predicate
WeaklyIncreasing{L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n-1 ==> a[i] <= a[i+1];
predicate
WeaklyIncreasing{L}(value_type* a, integer n) = WeaklyIncreasing{L}(a, 0, n);
}
*/
/*@
axiomatic Increasing
{
predicate
Increasing{L}(value_type* a, integer m, integer n) =
\forall integer i, j; m <= i < j < n ==> a[i] <= a[j];
predicate
Increasing{L}(value_type* a, integer n) = Increasing{L}(a, 0, n);
}
*/
/*@
axiomatic ArrayBounds
{
predicate
LowerBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> v <= a[i];
predicate
LowerBound{L}(value_type* a, integer n, value_type v) =
LowerBound{L}(a, 0, n, v);
predicate
StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> v < a[i];
predicate
StrictLowerBound{L}(value_type* a, integer n, value_type v) =
StrictLowerBound{L}(a, 0, n, v);
predicate
UpperBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> a[i] <= v;
predicate
UpperBound{L}(value_type* a, integer n, value_type v) =
UpperBound{L}(a, 0, n, v);
predicate
StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> a[i] < v;
predicate
StrictUpperBound{L}(value_type* a, integer n, value_type v) =
StrictUpperBound{L}(a, 0, n, v);
}
*/
size_type
lower_bound(const value_type* a, size_type n, value_type v)
{
size_type left = 0u;
size_type right = n;
while (left < right) {
const size_type middle = left + (right - left) / 2u;
if (a[middle] < v) {
left = middle + 1u;
}
else {
right = middle;
}
}
//@ assert LowerBound(a, left, n, v);
return left;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic WeaklyIncreasing
{
predicate
WeaklyIncreasing{L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n-1 ==> a[i] <= a[i+1];
predicate
WeaklyIncreasing{L}(value_type* a, integer n) = WeaklyIncreasing{L}(a, 0, n);
}
*/
/*@
axiomatic Increasing
{
predicate
Increasing{L}(value_type* a, integer m, integer n) =
\forall integer i, j; m <= i < j < n ==> a[i] <= a[j];
predicate
Increasing{L}(value_type* a, integer n) = Increasing{L}(a, 0, n);
}
*/
/*@
axiomatic ArrayBounds
{
predicate
LowerBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> v <= a[i];
predicate
LowerBound{L}(value_type* a, integer n, value_type v) =
LowerBound{L}(a, 0, n, v);
predicate
StrictLowerBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> v < a[i];
predicate
StrictLowerBound{L}(value_type* a, integer n, value_type v) =
StrictLowerBound{L}(a, 0, n, v);
predicate
UpperBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> a[i] <= v;
predicate
UpperBound{L}(value_type* a, integer n, value_type v) =
UpperBound{L}(a, 0, n, v);
predicate
StrictUpperBound{L}(value_type* a, integer m, integer n, value_type v) =
\forall integer i; m <= i < n ==> a[i] < v;
predicate
StrictUpperBound{L}(value_type* a, integer n, value_type v) =
StrictUpperBound{L}(a, 0, n, v);
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires increasing: Increasing(a, n);
assigns \nothing;
ensures result: 0 <= \result <= n;
ensures left: StrictUpperBound(a, 0, \result, v);
ensures right: LowerBound(a, \result, n, v);
*/
size_type
lower_bound(const value_type* a, size_type n, value_type v)
{
size_type left = 0u;
size_type right = n;
/*@
loop invariant bound: 0 <= left <= right <= n;
loop invariant left: StrictUpperBound(a, 0, left, v);
loop invariant right: LowerBound(a, right, n, v);
loop assigns left, right;
loop variant right - left;
*/
while (left < right) {
const size_type middle = left + (right - left) / 2u;
if (a[middle] < v) {
left = middle + 1u;
}
else {
right = middle;
}
}
//@ assert LowerBound(a, left, n, v);
return left;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_76 | 76 | /*@
requires y >= 127;
*/
void foo(int y) {
int c = 0;
int z = 36 * y;
while (unknown()) {
if (c < 36)
{
z = z + 1;
c = c + 1;
}
}
if (z < 0) {
if (z >= 4608) {
//@ assert c >= 36;
}
}
} | /*@
requires y >= 127;
*/
void foo(int y) {
int c = 0;
int z = 36 * y;
/*@
loop invariant z == 36*y + c;
loop invariant z == 36 * y + c;
loop invariant z == (36 * y) + c;
loop invariant z <= 36 * y + 36;
loop invariant z < 0 ==> z >= 4608 ==> c >= 36;
loop invariant c <= 36;
loop invariant 36*y <= z;
loop invariant 36 * y <= z;
loop invariant 0 <= c;
loop assigns z;
loop assigns c;
*/
while (unknown()) {
if (c < 36)
{
z = z + 1;
c = c + 1;
}
}
if (z < 0) {
if (z >= 4608) {
//@ assert c >= 36;
}
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
nikunjjain02_Arrays_8 | Arrays_8 | #include<stdio.h>
int* reverse(int a[], int n, int b[]) {
int i = 0;
while(i<n) {
b[i]=a[n-i-1];
i++;
}
return b;
}
void main() {
int a[] = {21, 24, 23, 24, 25};
int b[10];
int* c = reverse(a, 5, b);
//@ assert \forall integer k; 0 <= k < 5 ==> c[k] == a[5-k-1];
} | #include<stdio.h>
/*@
requires n>=0&&\valid_read(a+(0..n-1));
assigns b[0..n-1];
ensures \forall integer k;0<=k<n==>a[n-k-1]==\result[k];
*/
int* reverse(int a[], int n, int b[]) {
int i = 0;
/*@
loop invariant 0<=i<=n;
loop invariant \forall integer k;0<=k<i==>a[n-k-1]==b[k];
loop assigns b[0..n-1],i;
loop variant n-i;
*/
while(i<n) {
b[i]=a[n-i-1];
i++;
}
return b;
}
void main() {
int a[] = {21, 24, 23, 24, 25};
int b[10];
int* c = reverse(a, 5, b);
//@ assert \forall integer k; 0 <= k < 5 ==> c[k] == a[5-k-1];
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_51 | 51 | void main() {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c != 4) {
c = c + 1;
}
} else {
if (c == 4) {
c = 1;
}
}
}
if (c != 4){
//@ assert c <= 4;
}
} | void main() {
int c = 0;
/*@
loop invariant c <= 4;
loop invariant c != 4 ==> c < 4;
loop invariant \exists integer k; 0 <= k <= 4 && c == k;
loop invariant 0 <= c;
loop assigns c;
*/
while (unknown()) {
if (unknown()) {
if (c != 4) {
c = c + 1;
}
} else {
if (c == 4) {
c = 1;
}
}
}
if (c != 4){
//@ assert c <= 4;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
accumulate | accumulate | #ifndef TYPEDEFS_H_INCLUDED
#define TYPEDEFS_H_INCLUDED
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
#endif
#include<limits.h>
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
axiomatic UnchangedLemmas
{
lemma Unchanged_Shrink{K,L}:
\forall value_type *a, integer m, n, p, q;
m <= p <= q <= n ==>
Unchanged{K,L}(a, m, n) ==>
Unchanged{K,L}(a, p, q);
lemma Unchanged_Extend{K,L}:
\forall value_type *a, integer n;
Unchanged{K,L}(a, n) ==>
\at(a[n],K) == \at(a[n],L) ==>
Unchanged{K,L}(a, n+1);
lemma Unchanged_Symmetric{K,L}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,K}(a, m, n);
lemma Unchanged_Transitive{K,L,M}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,M}(a, m, n) ==>
Unchanged{K,M}(a, m, n);
}
axiomatic Accumulate
{
logic integer
Accumulate{L}(value_type* a, integer n, integer init) =
n <= 0 ? init : Accumulate(a, n-1, init) + a[n-1];
predicate
AccumulateBounds{L}(value_type* a, integer n, value_type init) =
\forall integer i; 0 <= i <= n ==>
VALUE_TYPE_MIN <= Accumulate(a, i, init) <= VALUE_TYPE_MAX;
lemma Accumulate_Init:
\forall value_type *a, init, integer n;
n <= 0 ==> Accumulate(a, n, init) == init;
}
*/
value_type
accumulate(const value_type* a, size_type n, value_type init)
{
for (size_type i = 0u; i < n; ++i) {
//@ assert rte_help: init + a[i] == Accumulate(a, i+1, \at(init,Pre));
init = init + a[i];
}
return init;
} | #ifndef TYPEDEFS_H_INCLUDED
#define TYPEDEFS_H_INCLUDED
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
#endif
#include<limits.h>
/*@
axiomatic Unchanged
{
predicate
Unchanged{K,L}(value_type* a, integer m, integer n) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(a[i],L);
predicate
Unchanged{K,L}(value_type* a, integer n) = Unchanged{K,L}(a, 0, n);
}
axiomatic UnchangedLemmas
{
lemma Unchanged_Shrink{K,L}:
\forall value_type *a, integer m, n, p, q;
m <= p <= q <= n ==>
Unchanged{K,L}(a, m, n) ==>
Unchanged{K,L}(a, p, q);
lemma Unchanged_Extend{K,L}:
\forall value_type *a, integer n;
Unchanged{K,L}(a, n) ==>
\at(a[n],K) == \at(a[n],L) ==>
Unchanged{K,L}(a, n+1);
lemma Unchanged_Symmetric{K,L}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,K}(a, m, n);
lemma Unchanged_Transitive{K,L,M}:
\forall value_type *a, integer m, n;
Unchanged{K,L}(a, m, n) ==>
Unchanged{L,M}(a, m, n) ==>
Unchanged{K,M}(a, m, n);
}
axiomatic Accumulate
{
logic integer
Accumulate{L}(value_type* a, integer n, integer init) =
n <= 0 ? init : Accumulate(a, n-1, init) + a[n-1];
predicate
AccumulateBounds{L}(value_type* a, integer n, value_type init) =
\forall integer i; 0 <= i <= n ==>
VALUE_TYPE_MIN <= Accumulate(a, i, init) <= VALUE_TYPE_MAX;
lemma Accumulate_Init:
\forall value_type *a, init, integer n;
n <= 0 ==> Accumulate(a, n, init) == init;
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires bounds: AccumulateBounds(a, n, init);
assigns \nothing;
ensures result: \result == Accumulate(a, n, init);
*/
value_type
accumulate(const value_type* a, size_type n, value_type init)
{
/*@
loop invariant index: 0 <= i <= n;
loop invariant partial: init == Accumulate(a, i, \at(init,Pre));
loop assigns i, init;
loop variant n-i;
*/
for (size_type i = 0u; i < n; ++i) {
//@ assert rte_help: init + a[i] == Accumulate(a, i+1, \at(init,Pre));
init = init + a[i];
}
return init;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
find_end | find_end | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic HasSubRange
{
predicate
HasSubRange{L}(value_type* a, integer m, integer n, value_type* b, integer p) =
\exists integer k; (m <= k <= n-p) && Equal{L,L}(a+k, p, b);
predicate
HasSubRange{L}(value_type* a, integer n, value_type* b, integer p) =
HasSubRange{L}(a, 0, n, b, p);
lemma HasSubRange_Sizes:
\forall value_type *a, *b, integer m, n, p;
HasSubRange(a, m, n, b, p) ==> p <= n-m;
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires valid: \valid_read(b + (0..n-1));
assigns \nothing;
ensures result: \result <==> Equal{Here,Here}(a, n, b);
*/
bool
equal(const value_type* a, size_type n, const value_type* b);
size_type
find_end(const value_type* a, size_type n,
const value_type* b, size_type p)
{
size_type r = n;
if ((0u < p) && (p <= n)) {
for (size_type i = 0u; i <= n - p; ++i) {
if (equal(a + i, p, b)) {
r = i;
}
}
}
//@ assert !HasSubRange(a, r + 1, n, b, p);
return r;
} | #include <limits.h>
#ifndef __cplusplus
typedef int bool;
#define false ((bool)0)
#define true ((bool)1)
#endif
typedef int value_type;
#define VALUE_TYPE_MAX INT_MAX
#define VALUE_TYPE_MIN INT_MIN
typedef unsigned int size_type;
#define SIZE_TYPE_MAX UINT_MAX
/*@
axiomatic Equal
{
predicate
Equal{K,L}(value_type* a, integer m, integer n, value_type* b) =
\forall integer i; m <= i < n ==> \at(a[i],K) == \at(b[i],L);
predicate
Equal{K,L}(value_type* a, integer n, value_type* b) =
Equal{K,L}(a, 0, n, b);
predicate
Equal{K,L}(value_type* a, integer m, integer n,
value_type* b, integer p) = Equal{K,L}(a+m, n-m, b+p);
predicate
Equal{K,L}(value_type* a, integer m, integer n, integer p) =
Equal{K,L}(a, m, n, a, p);
}
*/
/*@
axiomatic HasSubRange
{
predicate
HasSubRange{L}(value_type* a, integer m, integer n, value_type* b, integer p) =
\exists integer k; (m <= k <= n-p) && Equal{L,L}(a+k, p, b);
predicate
HasSubRange{L}(value_type* a, integer n, value_type* b, integer p) =
HasSubRange{L}(a, 0, n, b, p);
lemma HasSubRange_Sizes:
\forall value_type *a, *b, integer m, n, p;
HasSubRange(a, m, n, b, p) ==> p <= n-m;
}
*/
/*@
requires valid: \valid_read(a + (0..n-1));
requires valid: \valid_read(b + (0..n-1));
assigns \nothing;
ensures result: \result <==> Equal{Here,Here}(a, n, b);
*/
bool
equal(const value_type* a, size_type n, const value_type* b);
/*@
requires valid: \valid_read(a + (0..n-1));
requires valid: \valid_read(b + (0..p-1));
assigns \nothing;
ensures result: 0 <= \result <= n;
behavior has_match:
assumes HasSubRange(a, n, b, p);
assigns \nothing;
ensures bound: 0 <= \result <= n-p;
ensures result: Equal{Here,Here}(a + \result, p, b);
ensures last: !HasSubRange(a, \result + 1, n, b, p);
behavior no_match:
assumes !HasSubRange(a, n, b, p);
assigns \nothing;
ensures result: \result == n;
complete behaviors;
disjoint behaviors;
*/
size_type
find_end(const value_type* a, size_type n,
const value_type* b, size_type p)
{
size_type r = n;
if ((0u < p) && (p <= n)) {
/*@
loop invariant bound : r <= n - p || r == n;
loop invariant not_found: r == n ==> !HasSubRange(a, p+i-1, b, p);
loop invariant found: r < n ==> Equal{Here,Here}(a+r, p, b);
loop invariant last: r < n ==> !HasSubRange(a, r+1, i+p-1, b, p);
loop assigns i, r;
loop variant n - i;
*/
for (size_type i = 0u; i <= n - p; ++i) {
if (equal(a + i, p, b)) {
r = i;
}
}
}
//@ assert !HasSubRange(a, r + 1, n, b, p);
return r;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
pointers_div_rem | div_rem | void div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r) {
*q = x / y;
*r = x % y;
}
void main() {
unsigned q, r;
div_rem(10, 3, &q, &r);
//@ assert q == 3;
//@ assert r == 1;
} | /*@
requires \valid(q) && \valid(r);
requires \separated(q, r);
requires y != 0;
assigns *q, *r;
ensures x == *q * y + *r;
ensures *r < y;
*/
void div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r) {
*q = x / y;
*r = x % y;
}
void main() {
unsigned q, r;
div_rem(10, 3, &q, &r);
//@ assert q == 3;
//@ assert r == 1;
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
evdenis_small-examples_factorial | factorial | /*@ axiomatic Factorial {
logic integer factorial(integer i);
axiom nil:
factorial(0) == 1;
axiom step:
\forall integer i; i >= 0 ==>
factorial(i) == factorial(i - 1) * i;
lemma non_negative:
\forall integer i; i >= 0 ==>
factorial(i) > 0;
}
*/
#define SPEC_ULONG_MAX 18446744073709551615UL
unsigned long factorial(unsigned i)
{
unsigned long f = 1;
while (i) {
f *= i--;
}
return f;
}
int main(){
unsigned long f = factorial(5);
//@ assert f == 120;
} | /*@ axiomatic Factorial {
logic integer factorial(integer i);
axiom nil:
factorial(0) == 1;
axiom step:
\forall integer i; i >= 0 ==>
factorial(i) == factorial(i - 1) * i;
lemma non_negative:
\forall integer i; i >= 0 ==>
factorial(i) > 0;
}
*/
#define SPEC_ULONG_MAX 18446744073709551615UL
/*@ requires factorial(i) <= SPEC_ULONG_MAX;
assigns \nothing;
ensures \result == factorial(i);
*/
unsigned long factorial(unsigned i)
{
unsigned long f = 1;
/*@ loop invariant 0 <= i;
loop assigns f, i;
loop variant i;
*/
while (i) {
f *= i--;
}
return f;
}
int main(){
unsigned long f = factorial(5);
//@ assert f == 120;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_111 | 111 | /*@
requires 1 <= n;
*/
void foo(int n) {
int i = 1;
int sn = 0;
while (i <= n) {
i = i + 1;
sn = sn + 1;
}
if (sn != 0) {
//@ assert sn == n;
}
} | /*@
requires 1 <= n;
*/
void foo(int n) {
int i = 1;
int sn = 0;
/*@
loop invariant sn == i-1;
loop invariant sn == i - 1;
loop invariant i <= n+1;
loop invariant 1 <= i;
loop assigns sn;
loop assigns i;
*/
while (i <= n) {
i = i + 1;
sn = sn + 1;
}
if (sn != 0) {
//@ assert sn == n;
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
increment_arr | increment_arr | void increment_array_by(int* arr, int n, int c) {
for (int i = 0; i < n; i++) {
arr[i] = arr[i] + c;
}
//@ assert \forall integer k; 0 <= k < n ==> arr[k] == (\at(arr[k], Pre) + c);
}
int main(){
int arr[10] = {1,2,3,4,5,6,7,8,9,10};
Label_a:
increment_array_by(arr, 10, 1);
//@ assert \forall integer k; 0 <= k < 10 ==> arr[k] == (\at(arr[k], Label_a) + 1);
} | /*@
requires n > 0;
requires \valid_read(arr+(0..n-1));
ensures \forall integer k; 0 <= k < n ==> arr[k] == (\at(arr[k], Pre) + c);
*/
void increment_array_by(int* arr, int n, int c) {
/*@
loop invariant 0 <= i <= n;
loop invariant \forall integer k; 0 <= k < i ==> arr[k] == \at(arr[k], Pre) + c;
loop invariant \forall integer k; i <= k < n ==> arr[k] == \at(arr[k], Pre);
loop assigns i, arr[0..n-1];
*/
for (int i = 0; i < n; i++) {
arr[i] = arr[i] + c;
}
}
int main(){
int arr[10] = {1,2,3,4,5,6,7,8,9,10};
Label_a:
increment_array_by(arr, 10, 1);
//@ assert \forall integer k; 0 <= k < 10 ==> arr[k] == (\at(arr[k], Label_a) + 1);
} | fmbench | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
corinnt_remainder | remainder | void div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r){
*q = x / y ;
*r = x % y ;
}
int main() {
unsigned x = 10, y = 3;
unsigned q, r;
div_rem(x, y, &q, &r);
//@ assert q == 3 && r == 1;
return 0;
} | /*@
requires valid_pointers: \valid(q) && \valid(r);
requires \separated(q, r);
requires no_divide_by_zero: y != 0;
assigns *q, *r;
ensures *q == x / y;
ensures *r == x % y;
*/
void div_rem(unsigned x, unsigned y, unsigned* q, unsigned* r){
*q = x / y ;
*r = x % y ;
}
int main() {
unsigned x = 10, y = 3;
unsigned q, r;
div_rem(x, y, &q, &r);
//@ assert q == 3 && r == 1;
return 0;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
nabinkrsah_Computing the mod with precondition and postcondition | Computing the integer square root with precondition and postcondition | int my_mod(int a, int b){
int c = a * a;
int d = c * 3;
return d % b;
}
void main(){
int x1 = 5;
int x2 = 10;
int y1 = my_mod(x1, 2);
int y2 = my_mod(x2, 2);
//@ assert y1 != y2;
} | /*@
requires b >= 0;
ensures \result == (a * a * 3) % b;
*/
int my_mod(int a, int b){
int c = a * a;
int d = c * 3;
return d % b;
}
void main(){
int x1 = 5;
int x2 = 10;
int y1 = my_mod(x1, 2);
int y2 = my_mod(x2, 2);
//@ assert y1 != y2;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
Tasmina0609_1 | 1 | int max3(int a,int b,int c) {
int max;
if((a >= b) && (a >= c)) {
max = a;
}
else if((b >= a) && (b >= c)) {
max = b;
}
else if((c >= a) && (c >= b)) {
max = c;
}
return max;
}
int main(){
int a = 10;
int b = 20;
int c = 30;
int max = max3(a,b,c);
//@ assert max == 30;
} | /*@
ensures \result>=a && \result>=b && \result>=c;
ensures \result==a || \result==b || \result==c;
ensures a>=b && a>=c ==> \result==a;
ensures b>=a && b>=c ==> \result==b;
ensures c>=a && c>=b ==> \result==c;
*/
int max3(int a,int b,int c) {
int max;
if((a >= b) && (a >= c)) {
max = a;
}
else if((b >= a) && (b >= c)) {
max = b;
}
else if((c >= a) && (c >= b)) {
max = c;
}
return max;
}
int main(){
int a = 10;
int b = 20;
int c = 30;
int max = max3(a,b,c);
//@ assert max == 30;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
gpetiot_Frama-C-StaDy_next_subset | next_subset | /*@
predicate is_dset{L}(int *a, integer n) =
\forall integer i; 0 <= i < n ==> (a[i] == 0 || a[i] == 1);
predicate is_eq{L1,L2}(int *a, integer n) =
\forall integer i; 0 <= i < n ==> \at(a[i],L1) == \at(a[i],L2);
predicate lt{L1,L2}(int* a, integer i) =
\at(a[i],L1) < \at(a[i],L2);
*/
int nextSubset(int s[], int n) {
int i,k;
for (k = n-1; k >= 0; k--) { if (s[k] == 0) { break; } }
if (k == -1) { return -1; }
s[k] = 1;
for (i = k+1; i < n; i++) { s[i] = 0; }
//@ assert is_dset(s,n);
return k;
} | /*@
predicate is_dset{L}(int *a, integer n) =
\forall integer i; 0 <= i < n ==> (a[i] == 0 || a[i] == 1);
predicate is_eq{L1,L2}(int *a, integer n) =
\forall integer i; 0 <= i < n ==> \at(a[i],L1) == \at(a[i],L2);
predicate lt{L1,L2}(int* a, integer i) =
\at(a[i],L1) < \at(a[i],L2);
*/
/*@
requires n >= 0 && n <= 3 && \valid(s+(0..n-1));
requires is_dset(s,n);
assigns s[0..n-1];
ensures is_dset(s,n);
ensures -1 <= \result < n;
ensures \result == -1 ==> is_eq{Pre,Post}(s,n);
ensures \result != -1 ==> is_eq{Pre,Post}(s,\result);
ensures \result != -1 ==> lt{Pre,Post}(s,\result);
*/
int nextSubset(int s[], int n) {
int i,k;
/*@ loop invariant -1 <= k <= n-1;
loop assigns k;
loop variant k; */
for (k = n-1; k >= 0; k--) { if (s[k] == 0) { break; } }
if (k == -1) { return -1; }
s[k] = 1;
/*@ loop invariant k+1 <= i <= n;
loop invariant is_dset(s,i);
loop assigns i,s[k+1..n-1];
loop variant n-i; */
for (i = k+1; i < n; i++) { s[i] = 0; }
//@ assert is_dset(s,n);
return k;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
arepina_factorial | factorial | /*@ axiomatic Factorial {
logic integer factorial(integer i);
axiom nil:
factorial(0) == 1;
axiom step:
\forall integer i; i >= 0 ==>
factorial(i) == factorial(i - 1) * i;
lemma non_negative:
\forall integer i; i >= 0 ==>
factorial(i) > 0;
}
*/
#define SPEC_ULONG_MAX 18446744073709551615UL
unsigned long factorial(unsigned i)
{
unsigned long f = 1;
while (i) {
f *= i--;
}
return f;
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a = factorial(5);
int b = factorial(0);
//@ assert a == 120;
//@ assert b == 1;
}
#endif | /*@ axiomatic Factorial {
logic integer factorial(integer i);
axiom nil:
factorial(0) == 1;
axiom step:
\forall integer i; i >= 0 ==>
factorial(i) == factorial(i - 1) * i;
lemma non_negative:
\forall integer i; i >= 0 ==>
factorial(i) > 0;
}
*/
#define SPEC_ULONG_MAX 18446744073709551615UL
/*@ requires factorial(i) <= SPEC_ULONG_MAX;
assigns \nothing;
ensures \result == factorial(i);
*/
unsigned long factorial(unsigned i)
{
unsigned long f = 1;
/*@ loop invariant 0 <= i;
loop assigns f, i;
loop variant i;
*/
while (i) {
f *= i--;
}
return f;
}
#ifdef OUT_OF_TASK
#include <stdio.h>
int main(void)
{
int a = factorial(5);
int b = factorial(0);
//@ assert a == 120;
//@ assert b == 1;
}
#endif | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
gpetiot_Frama-C-StaDy_inv_insuf_ok | inv_insuf_ok | int found;
/*@
requires \valid(t+(0..4));
*/
void f(int*t, int x) {
int i = 0;
found = 0;
first_loop:
for(; i <= 4; i++) {
if(t[i] == x)
found = 1;
}
//@ assert found <==> \exists integer i; 0 <= i <= 4 && t[i] == x;
} | int found;
/*@
requires \valid(t+(0..4));
*/
void f(int*t, int x) {
int i = 0;
found = 0;
first_loop:
/*@
loop invariant 0 <= i <= 5;
loop invariant found <==> (\exists integer k; 0 <= k < i && t[k] == x);
loop assigns found, i;
*/
for(; i <= 4; i++) {
if(t[i] == x)
found = 1;
}
//@ assert found <==> \exists integer i; 0 <= i <= 4 && t[i] == x;
} | githubRepository | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
code2_47 | 47 | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
while (unknown()) {
if (unknown()) {
if (c != n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c < 0) {
if (c > n) {
//@ assert c == n;
}
}
} | int unknown();
/*@
requires n > 0;
*/
void foo(int n) {
int c = 0;
// loop body
/*@
loop invariant 0 <= c;
loop assigns n,c;
*/
while (unknown()) {
if (unknown()) {
if (c != n) {
c = c + 1;
}
} else {
if (c == n) {
c = 1;
}
}
}
if (c < 0) {
if (c > n) {
//@ assert c == n;
}
}
} | autospec | Please write ACSL specification for the given C code ensuring its correctness.
You only need to return the completed ACSL formal specification together with C program without explanation. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.