CBMC
stdio.c
Go to the documentation of this file.
1 
2 /* FUNCTION: putchar */
3 
4 #ifndef __CPROVER_STDIO_H_INCLUDED
5 #include <stdio.h>
6 #define __CPROVER_STDIO_H_INCLUDED
7 #endif
8 
9 /* undefine macros in OpenBSD's stdio.h that are problematic to the checker. */
10 #if defined(__OpenBSD__)
11 #undef getchar
12 #undef putchar
13 #undef getc
14 #undef feof
15 #undef ferror
16 #undef fileno
17 #endif
18 
19 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
20 
21 int putchar(int c)
22 {
23  __CPROVER_HIDE:;
24  __CPROVER_bool error=__VERIFIER_nondet___CPROVER_bool();
25  __CPROVER_printf("%c", c);
26  return (error?-1:c);
27 }
28 
29 /* FUNCTION: puts */
30 
31 #ifndef __CPROVER_STDIO_H_INCLUDED
32 #include <stdio.h>
33 #define __CPROVER_STDIO_H_INCLUDED
34 #endif
35 
36 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
38 
39 int puts(const char *s)
40 {
41  __CPROVER_HIDE:;
42  __CPROVER_bool error=__VERIFIER_nondet___CPROVER_bool();
43  int ret=__VERIFIER_nondet_int();
44  __CPROVER_printf("%s\n", s);
45  if(error) ret=-1; else __CPROVER_assume(ret>=0);
46  return ret;
47 }
48 
49 /* FUNCTION: fclose_cleanup */
50 
51 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
52 void fclose_cleanup(void *stream)
53 {
54 __CPROVER_HIDE:;
56  !__CPROVER_get_must(stream, "open") || __CPROVER_get_must(stream, "closed"),
57  "resource leak: fopen file not closed");
58 }
59 #endif
60 
61 /* FUNCTION: fopen */
62 
63 #ifndef __CPROVER_STDIO_H_INCLUDED
64 #include <stdio.h>
65 #define __CPROVER_STDIO_H_INCLUDED
66 #endif
67 
68 #ifndef __CPROVER_STDLIB_H_INCLUDED
69 #include <stdlib.h>
70 #define __CPROVER_STDLIB_H_INCLUDED
71 #endif
72 
73 void fclose_cleanup(void *stream);
74 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
75 FILE *fopen64(const char *filename, const char *mode);
76 
77 FILE *fopen(const char *filename, const char *mode)
78 {
79 __CPROVER_HIDE:;
80  return fopen64(filename, mode);
81 }
82 
83 /* FUNCTION: _fopen */
84 
85 // This is for Apple; we cannot fall back to fopen as we need
86 // header files to have a definition of FILE available; the same
87 // header files rename fopen to _fopen and would thus yield
88 // unbounded recursion.
89 
90 #ifndef __CPROVER_STDIO_H_INCLUDED
91 # include <stdio.h>
92 # define __CPROVER_STDIO_H_INCLUDED
93 #endif
94 
95 #ifndef __CPROVER_STDLIB_H_INCLUDED
96 # include <stdlib.h>
97 # define __CPROVER_STDLIB_H_INCLUDED
98 #endif
99 
100 void fclose_cleanup(void *stream);
101 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
102 
103 #ifdef __APPLE__
104 FILE *_fopen(const char *filename, const char *mode)
105 {
106 __CPROVER_HIDE:;
107  (void)*filename;
108  (void)*mode;
109 # ifdef __CPROVER_STRING_ABSTRACTION
111  __CPROVER_is_zero_string(filename),
112  "fopen zero-termination of 1st argument");
114  __CPROVER_is_zero_string(mode), "fopen zero-termination of 2nd argument");
115 # endif
116 
117  FILE *fopen_result;
118 
119  __CPROVER_bool fopen_error = __VERIFIER_nondet___CPROVER_bool();
120 
121  fopen_result = fopen_error ? NULL : malloc(sizeof(FILE));
122 
123 # ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
124  __CPROVER_set_must(fopen_result, "open");
125  __CPROVER_cleanup(fopen_result, fclose_cleanup);
126 # endif
127 
128  return fopen_result;
129 }
130 #endif
131 
132 /* FUNCTION: fopen64 */
133 
134 #ifndef __CPROVER_STDIO_H_INCLUDED
135 # include <stdio.h>
136 # define __CPROVER_STDIO_H_INCLUDED
137 #endif
138 
139 #ifndef __CPROVER_STDLIB_H_INCLUDED
140 # include <stdlib.h>
141 # define __CPROVER_STDLIB_H_INCLUDED
142 #endif
143 
144 void fclose_cleanup(void *stream);
145 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
146 
147 FILE *fopen64(const char *filename, const char *mode)
148 {
149 __CPROVER_HIDE:;
150  (void)*filename;
151  (void)*mode;
152 #ifdef __CPROVER_STRING_ABSTRACTION
154  __CPROVER_is_zero_string(filename),
155  "fopen zero-termination of 1st argument");
157  __CPROVER_is_zero_string(mode), "fopen zero-termination of 2nd argument");
158 #endif
159 
160  FILE *fopen_result;
161 
162  __CPROVER_bool fopen_error = __VERIFIER_nondet___CPROVER_bool();
163 
164 #if !defined(__linux__) || defined(__GLIBC__)
165  fopen_result = fopen_error ? NULL : malloc(sizeof(FILE));
166 #else
167  // libraries need to expose the definition of FILE; this is the
168  // case for musl
169  fopen_result = fopen_error ? NULL : malloc(sizeof(int));
170 #endif
171 
172 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
173  __CPROVER_set_must(fopen_result, "open");
174  __CPROVER_cleanup(fopen_result, fclose_cleanup);
175 #endif
176 
177  return fopen_result;
178 }
179 
180 /* FUNCTION: freopen */
181 
182 #ifndef __CPROVER_STDIO_H_INCLUDED
183 #include <stdio.h>
184 #define __CPROVER_STDIO_H_INCLUDED
185 #endif
186 
187 FILE *freopen64(const char *filename, const char *mode, FILE *f);
188 
189 FILE *freopen(const char *filename, const char *mode, FILE *f)
190 {
191 __CPROVER_HIDE:;
192  return freopen64(filename, mode, f);
193 }
194 
195 /* FUNCTION: freopen64 */
196 
197 #ifndef __CPROVER_STDIO_H_INCLUDED
198 # include <stdio.h>
199 # define __CPROVER_STDIO_H_INCLUDED
200 #endif
201 
202 FILE *freopen64(const char *filename, const char *mode, FILE *f)
203 {
204  __CPROVER_HIDE:;
205  (void)*filename;
206  (void)*mode;
207 #if !defined(__linux__) || defined(__GLIBC__)
208  (void)*f;
209 #else
210  (void)*(char*)f;
211 #endif
212 
213  return f;
214 }
215 
216 /* FUNCTION: fclose */
217 
218 #ifndef __CPROVER_STDIO_H_INCLUDED
219 #include <stdio.h>
220 #define __CPROVER_STDIO_H_INCLUDED
221 #endif
222 
223 #ifndef __CPROVER_STDLIB_H_INCLUDED
224 #include <stdlib.h>
225 #define __CPROVER_STDLIB_H_INCLUDED
226 #endif
227 
228 int __VERIFIER_nondet_int(void);
229 
230 int fclose(FILE *stream)
231 {
232 __CPROVER_HIDE:;
233 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
234  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
235  "fclose file must be open");
236  __CPROVER_clear_must(stream, "open");
237  __CPROVER_set_must(stream, "closed");
238 #endif
239  int return_value=__VERIFIER_nondet_int();
240  free(stream);
241  return return_value;
242 }
243 
244 /* FUNCTION: fdopen */
245 
246 #ifndef __CPROVER_STDIO_H_INCLUDED
247 #include <stdio.h>
248 #define __CPROVER_STDIO_H_INCLUDED
249 #endif
250 
251 #ifndef __CPROVER_STDLIB_H_INCLUDED
252 #include <stdlib.h>
253 #define __CPROVER_STDLIB_H_INCLUDED
254 #endif
255 
256 FILE *fdopen(int handle, const char *mode)
257 {
258  __CPROVER_HIDE:;
259  (void)handle;
260  (void)*mode;
261 #ifdef __CPROVER_STRING_ABSTRACTION
263  "fdopen zero-termination of 2nd argument");
264 #endif
265 
266 #if !defined(__linux__) || defined(__GLIBC__)
267  FILE *f=malloc(sizeof(FILE));
268 #else
269  // libraries need to expose the definition of FILE; this is the
270  // case for musl
271  FILE *f=malloc(sizeof(int));
272 #endif
273 
274  return f;
275 }
276 
277 /* FUNCTION: _fdopen */
278 
279 // This is for Apple; we cannot fall back to fdopen as we need
280 // header files to have a definition of FILE available; the same
281 // header files rename fdopen to _fdopen and would thus yield
282 // unbounded recursion.
283 
284 #ifndef __CPROVER_STDIO_H_INCLUDED
285 #include <stdio.h>
286 #define __CPROVER_STDIO_H_INCLUDED
287 #endif
288 
289 #ifndef __CPROVER_STDLIB_H_INCLUDED
290 #include <stdlib.h>
291 #define __CPROVER_STDLIB_H_INCLUDED
292 #endif
293 
294 #ifdef __APPLE__
295 FILE *_fdopen(int handle, const char *mode)
296 {
297  __CPROVER_HIDE:;
298  (void)handle;
299  (void)*mode;
300 #ifdef __CPROVER_STRING_ABSTRACTION
302  "fdopen zero-termination of 2nd argument");
303 #endif
304 
305  FILE *f=malloc(sizeof(FILE));
306 
307  return f;
308 }
309 #endif
310 
311 /* FUNCTION: fgets */
312 
313 #ifndef __CPROVER_STDIO_H_INCLUDED
314 #include <stdio.h>
315 #define __CPROVER_STDIO_H_INCLUDED
316 #endif
317 
318 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
319 int __VERIFIER_nondet_int(void);
320 
321 char *fgets(char *str, int size, FILE *stream)
322 {
323 __CPROVER_HIDE:;
324  __CPROVER_bool error=__VERIFIER_nondet___CPROVER_bool();
325 
326  (void)size;
327  if(stream != stdin)
328  {
329 #if !defined(__linux__) || defined(__GLIBC__)
330  (void)*stream;
331 #else
332  (void)*(char *)stream;
333 #endif
334  }
335 
336 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
337  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
338  "fgets file must be open");
339 #endif
340 
341 #ifdef __CPROVER_STRING_ABSTRACTION
342  int resulting_size;
343  __CPROVER_assert(__CPROVER_buffer_size(str)>=size, "buffer-overflow in fgets");
344  if(size>0)
345  {
346  __CPROVER_assume(resulting_size<size);
347  __CPROVER_is_zero_string(str)=!error;
348  __CPROVER_zero_string_length(str)=resulting_size;
349  }
350 #else
351  if(size>0)
352  {
353  int str_length=__VERIFIER_nondet_int();
354  __CPROVER_assume(str_length >= 0 && str_length < size);
355  __CPROVER_precondition(__CPROVER_w_ok(str, size), "fgets buffer writable");
356  char contents_nondet[str_length];
357  __CPROVER_array_replace(str, contents_nondet);
358  if(!error)
359  str[str_length]='\0';
360  }
361 #endif
362 
363  return error?0:str;
364 }
365 
366 /* FUNCTION: __fgets_chk */
367 
368 #ifndef __CPROVER_STDIO_H_INCLUDED
369 # include <stdio.h>
370 # define __CPROVER_STDIO_H_INCLUDED
371 #endif
372 
373 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
374 int __VERIFIER_nondet_int(void);
375 
376 char *__fgets_chk(char *str, __CPROVER_size_t bufsize, int size, FILE *stream)
377 {
378 __CPROVER_HIDE:;
379  (void)bufsize;
380  __CPROVER_bool error = __VERIFIER_nondet___CPROVER_bool();
381 
382  (void)size;
383  if(stream != stdin)
384  {
385 #if !defined(__linux__) || defined(__GLIBC__)
386  (void)*stream;
387 #else
388  (void)*(char *)stream;
389 #endif
390  }
391 
392 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
394  __CPROVER_get_must(stream, "open"), "fgets file must be open");
395 #endif
396 
397 #ifdef __CPROVER_STRING_ABSTRACTION
398  int resulting_size;
400  __CPROVER_buffer_size(str) >= size, "buffer-overflow in fgets");
401  if(size > 0)
402  {
403  __CPROVER_assume(resulting_size < size);
404  __CPROVER_is_zero_string(str) = !error;
405  __CPROVER_zero_string_length(str) = resulting_size;
406  }
407 #else
408  if(size > 0)
409  {
410  int str_length = __VERIFIER_nondet_int();
411  __CPROVER_assume(str_length >= 0 && str_length < size);
412  __CPROVER_precondition(__CPROVER_w_ok(str, size), "fgets buffer writable");
413  char contents_nondet[str_length];
414  __CPROVER_array_replace(str, contents_nondet);
415  if(!error)
416  str[str_length] = '\0';
417  }
418 #endif
419 
420  return error ? 0 : str;
421 }
422 
423 /* FUNCTION: fread */
424 
425 #ifndef __CPROVER_STDIO_H_INCLUDED
426 #include <stdio.h>
427 #define __CPROVER_STDIO_H_INCLUDED
428 #endif
429 
432 
433 size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream)
434 {
435 __CPROVER_HIDE:;
436  size_t bytes_read = __VERIFIER_nondet_size_t();
437  size_t upper_bound = nitems * size;
438  __CPROVER_assume(bytes_read <= upper_bound);
439 
440  if(stream != stdin)
441  {
442 #if !defined(__linux__) || defined(__GLIBC__)
443  (void)*stream;
444 #else
445  (void)*(char *)stream;
446 #endif
447  }
448 
449 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
450  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
451  "fread file must be open");
452 #endif
453 
454  for(size_t i = 0; i < bytes_read && i < upper_bound; i++)
455  {
456  ((char *)ptr)[i] = __VERIFIER_nondet_char();
457  }
458 
459  return bytes_read / size;
460 }
461 
462 /* FUNCTION: __fread_chk */
463 
464 #ifndef __CPROVER_STDIO_H_INCLUDED
465 # include <stdio.h>
466 # define __CPROVER_STDIO_H_INCLUDED
467 #endif
468 
469 char __VERIFIER_nondet_char(void);
470 size_t __VERIFIER_nondet_size_t(void);
471 
472 size_t
473 __fread_chk(void *ptr, size_t ptrlen, size_t size, size_t nitems, FILE *stream)
474 {
475 __CPROVER_HIDE:;
476  size_t bytes_read = __VERIFIER_nondet_size_t();
477  size_t upper_bound = nitems * size;
478  __CPROVER_assume(bytes_read <= upper_bound);
479 
480  if(stream != stdin)
481  {
482 #if !defined(__linux__) || defined(__GLIBC__)
483  (void)*stream;
484 #else
485  (void)*(char *)stream;
486 #endif
487  }
488 
489 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
491  __CPROVER_get_must(stream, "open"), "fread file must be open");
492 #endif
493 
494  for(size_t i = 0; i < bytes_read && i < upper_bound && i < ptrlen; i++)
495  {
496  ((char *)ptr)[i] = __VERIFIER_nondet_char();
497  }
498 
499  return bytes_read / size;
500 }
501 
502 /* FUNCTION: feof */
503 
504 #ifndef __CPROVER_STDIO_H_INCLUDED
505 #include <stdio.h>
506 #define __CPROVER_STDIO_H_INCLUDED
507 #endif
508 
509 int __VERIFIER_nondet_int(void);
510 
511 int feof(FILE *stream)
512 {
513  // just return nondet
514  __CPROVER_HIDE:;
515  int return_value=__VERIFIER_nondet_int();
516 
517  if(stream != stdin)
518  {
519 #if !defined(__linux__) || defined(__GLIBC__)
520  (void)*stream;
521 #else
522  (void)*(char *)stream;
523 #endif
524  }
525 
526 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
527  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
528  "feof file must be open");
529 #endif
530 
531  return return_value;
532 }
533 
534 /* FUNCTION: ferror */
535 
536 #ifndef __CPROVER_STDIO_H_INCLUDED
537 #include <stdio.h>
538 #define __CPROVER_STDIO_H_INCLUDED
539 #endif
540 
541 int __VERIFIER_nondet_int(void);
542 
543 int ferror(FILE *stream)
544 {
545  // just return nondet
546  __CPROVER_HIDE:;
547  int return_value=__VERIFIER_nondet_int();
548 
549  if(stream != stdin)
550  {
551 #if !defined(__linux__) || defined(__GLIBC__)
552  (void)*stream;
553 #else
554  (void)*(char *)stream;
555 #endif
556  }
557 
558 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
559  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
560  "feof file must be open");
561 #endif
562 
563  return return_value;
564 }
565 
566 /* FUNCTION: fileno */
567 
568 #ifndef __CPROVER_STDIO_H_INCLUDED
569 #include <stdio.h>
570 #define __CPROVER_STDIO_H_INCLUDED
571 #endif
572 
573 int __VERIFIER_nondet_int(void);
574 
575 int fileno(FILE *stream)
576 {
577 __CPROVER_HIDE:;
578  if(stream == stdin)
579  return 0;
580  else if(stream == stdout)
581  return 1;
582  else if(stream == stderr)
583  return 2;
584 
585  int return_value=__VERIFIER_nondet_int();
586  __CPROVER_assume(return_value >= -1);
587 
588 #if !defined(__linux__) || defined(__GLIBC__)
589  (void)*stream;
590 #else
591  (void)*(char*)stream;
592 #endif
593 
594 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
595  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
596  "fileno file must be open");
597 #endif
598 
599  return return_value;
600 }
601 
602 /* FUNCTION: fputs */
603 
604 #ifndef __CPROVER_STDIO_H_INCLUDED
605 #include <stdio.h>
606 #define __CPROVER_STDIO_H_INCLUDED
607 #endif
608 
609 int __VERIFIER_nondet_int(void);
610 
611 int fputs(const char *s, FILE *stream)
612 {
613  // just return nondet
614  __CPROVER_HIDE:;
615  int return_value=__VERIFIER_nondet_int();
616 #ifdef __CPROVER_STRING_ABSTRACTION
617  __CPROVER_assert(__CPROVER_is_zero_string(s), "fputs zero-termination of 1st argument");
618 #endif
619  (void)*s;
620 
621  if(stream != stdout && stream != stderr)
622  {
623 #if !defined(__linux__) || defined(__GLIBC__)
624  (void)*stream;
625 #else
626  (void)*(char *)stream;
627 #endif
628  }
629 
630 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
631  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
632  "fputs file must be open");
633 #endif
634 
635  return return_value;
636 }
637 
638 /* FUNCTION: fflush */
639 
640 #ifndef __CPROVER_STDIO_H_INCLUDED
641 #include <stdio.h>
642 #define __CPROVER_STDIO_H_INCLUDED
643 #endif
644 
645 int __VERIFIER_nondet_int(void);
646 
647 int fflush(FILE *stream)
648 {
649  // just return nondet
650  __CPROVER_HIDE:;
651  int return_value=__VERIFIER_nondet_int();
652  (void)stream;
653 
654 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
655  if(stream)
656  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
657  "fflush file must be open");
658 #endif
659 
660  return return_value;
661 }
662 
663 /* FUNCTION: fpurge */
664 
665 #ifndef __CPROVER_STDIO_H_INCLUDED
666 #include <stdio.h>
667 #define __CPROVER_STDIO_H_INCLUDED
668 #endif
669 
670 int __VERIFIER_nondet_int(void);
671 
672 int fpurge(FILE *stream)
673 {
674  // just return nondet
675  __CPROVER_HIDE:;
676  int return_value=__VERIFIER_nondet_int();
677 
678  if(stream != stdin && stream != stdout && stream != stderr)
679  {
680 #if !defined(__linux__) || defined(__GLIBC__)
681  (void)*stream;
682 #else
683  (void)*(char *)stream;
684 #endif
685  }
686 
687 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
688  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
689  "fpurge file must be open");
690 #endif
691 
692  return return_value;
693 }
694 
695 /* FUNCTION: fgetc */
696 
697 #ifndef __CPROVER_STDIO_H_INCLUDED
698 #include <stdio.h>
699 #define __CPROVER_STDIO_H_INCLUDED
700 #endif
701 
702 int __VERIFIER_nondet_int(void);
703 
704 int fgetc(FILE *stream)
705 {
706  __CPROVER_HIDE:;
707  int return_value=__VERIFIER_nondet_int();
708 
709  if(stream != stdin)
710  {
711 #if !defined(__linux__) || defined(__GLIBC__)
712  (void)*stream;
713 #else
714  (void)*(char *)stream;
715 #endif
716  }
717 
718  // it's a byte or EOF (-1)
719  __CPROVER_assume(return_value>=-1 && return_value<=255);
720 
721  __CPROVER_input("fgetc", return_value);
722 
723 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
724  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
725  "fgetc file must be open");
726 #endif
727 
728  return return_value;
729 }
730 
731 /* FUNCTION: getc */
732 
733 #ifndef __CPROVER_STDIO_H_INCLUDED
734 #include <stdio.h>
735 #define __CPROVER_STDIO_H_INCLUDED
736 #endif
737 
738 int __VERIFIER_nondet_int(void);
739 
740 int getc(FILE *stream)
741 {
742  __CPROVER_HIDE:;
743  int return_value=__VERIFIER_nondet_int();
744 
745  if(stream != stdin)
746  {
747 #if !defined(__linux__) || defined(__GLIBC__)
748  (void)*stream;
749 #else
750  (void)*(char *)stream;
751 #endif
752  }
753 
754 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
755  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
756  "getc file must be open");
757 #endif
758 
759  // It's a byte or EOF, which we fix to -1.
760  __CPROVER_assume(return_value>=-1 && return_value<=255);
761 
762  __CPROVER_input("getc", return_value);
763 
764  return return_value;
765 }
766 
767 /* FUNCTION: getchar */
768 
769 #ifndef __CPROVER_STDIO_H_INCLUDED
770 #include <stdio.h>
771 #define __CPROVER_STDIO_H_INCLUDED
772 #endif
773 
774 int __VERIFIER_nondet_int(void);
775 
776 int getchar(void)
777 {
778  __CPROVER_HIDE:;
779  int return_value=__VERIFIER_nondet_int();
780  // it's a byte or EOF
781  __CPROVER_assume(return_value>=-1 && return_value<=255);
782  __CPROVER_input("getchar", return_value);
783  return return_value;
784 }
785 
786 /* FUNCTION: getw */
787 
788 #ifndef __CPROVER_STDIO_H_INCLUDED
789 #include <stdio.h>
790 #define __CPROVER_STDIO_H_INCLUDED
791 #endif
792 
793 int __VERIFIER_nondet_int(void);
794 
795 int getw(FILE *stream)
796 {
797  __CPROVER_HIDE:;
798  int return_value=__VERIFIER_nondet_int();
799 
800  if(stream != stdin)
801  {
802 #if !defined(__linux__) || defined(__GLIBC__)
803  (void)*stream;
804 #else
805  (void)*(char *)stream;
806 #endif
807  }
808 
809 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
810  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
811  "getw file must be open");
812 #endif
813 
814  __CPROVER_input("getw", return_value);
815 
816  // it's any int, no restriction
817  return return_value;
818 }
819 
820 /* FUNCTION: fseek */
821 
822 #ifndef __CPROVER_STDIO_H_INCLUDED
823 #include <stdio.h>
824 #define __CPROVER_STDIO_H_INCLUDED
825 #endif
826 
827 int __VERIFIER_nondet_int(void);
828 
829 int fseek(FILE *stream, long offset, int whence)
830 {
831  __CPROVER_HIDE:;
832  int return_value=__VERIFIER_nondet_int();
833 
834 #if !defined(__linux__) || defined(__GLIBC__)
835  (void)*stream;
836 #else
837  (void)*(char*)stream;
838 #endif
839  (void)offset;
840  (void)whence;
841 
842 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
843  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
844  "fseek file must be open");
845 #endif
846 
847  return return_value;
848 }
849 
850 /* FUNCTION: ftell */
851 
852 #ifndef __CPROVER_STDIO_H_INCLUDED
853 #include <stdio.h>
854 #define __CPROVER_STDIO_H_INCLUDED
855 #endif
856 
858 
859 long ftell(FILE *stream)
860 {
861  __CPROVER_HIDE:;
862  long return_value=__VERIFIER_nondet_long();
863 
864 #if !defined(__linux__) || defined(__GLIBC__)
865  (void)*stream;
866 #else
867  (void)*(char*)stream;
868 #endif
869 
870 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
871  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
872  "ftell file must be open");
873 #endif
874 
875  return return_value;
876 }
877 
878 /* FUNCTION: rewind */
879 
880 #ifndef __CPROVER_STDIO_H_INCLUDED
881 #include <stdio.h>
882 #define __CPROVER_STDIO_H_INCLUDED
883 #endif
884 
885 void rewind(FILE *stream)
886 {
887 __CPROVER_HIDE:
888 
889 #if !defined(__linux__) || defined(__GLIBC__)
890  (void)*stream;
891 #else
892  (void)*(char*)stream;
893 #endif
894 
895 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
896  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
897  "rewind file must be open");
898 #endif
899 }
900 
901 /* FUNCTION: fwrite */
902 
903 #ifndef __CPROVER_STDIO_H_INCLUDED
904 #include <stdio.h>
905 #define __CPROVER_STDIO_H_INCLUDED
906 #endif
907 
908 size_t __VERIFIER_nondet_size_t(void);
909 
910 size_t fwrite(
911  const void *ptr,
912  size_t size,
913  size_t nitems,
914  FILE *stream)
915 {
916  __CPROVER_HIDE:;
917  (void)*(char*)ptr;
918  (void)size;
919 
920  if(stream != stdout && stream != stderr)
921  {
922 #if !defined(__linux__) || defined(__GLIBC__)
923  (void)*stream;
924 #else
925  (void)*(char *)stream;
926 #endif
927  }
928 
929 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
930  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
931  "fwrite file must be open");
932 #endif
933 
934  size_t nwrite=__VERIFIER_nondet_size_t();
935  __CPROVER_assume(nwrite<=nitems);
936  return nwrite;
937 }
938 
939 /* FUNCTION: perror */
940 
941 #ifndef __CPROVER_STDIO_H_INCLUDED
942 #include <stdio.h>
943 #define __CPROVER_STDIO_H_INCLUDED
944 #endif
945 
946 void perror(const char *s)
947 {
948  __CPROVER_HIDE:;
949  if(s!=0)
950  {
951  #ifdef __CPROVER_STRING_ABSTRACTION
952  __CPROVER_assert(__CPROVER_is_zero_string(s), "perror zero-termination");
953  #endif
954  // should go to stderr
955  if(s[0]!=0)
956  __CPROVER_printf("%s: ", s);
957  }
958 
959  // TODO: print errno error
960 }
961 
962 /* FUNCTION: fscanf */
963 
964 #if !defined(__USE_ISOC99) || !defined(__REDIRECT)
965 
966 # ifndef __CPROVER_STDIO_H_INCLUDED
967 # include <stdio.h>
968 # define __CPROVER_STDIO_H_INCLUDED
969 # endif
970 
971 # ifndef __CPROVER_STDARG_H_INCLUDED
972 # include <stdarg.h>
973 # define __CPROVER_STDARG_H_INCLUDED
974 # endif
975 
976 int fscanf(FILE *restrict stream, const char *restrict format, ...)
977 {
978 __CPROVER_HIDE:;
979  va_list list;
980  va_start(list, format);
981  int result=vfscanf(stream, format, list);
982  va_end(list);
983  return result;
984 }
985 
986 #endif
987 
988 /* FUNCTION: __isoc99_fscanf */
989 
990 #ifndef __CPROVER_STDIO_H_INCLUDED
991 # include <stdio.h>
992 # define __CPROVER_STDIO_H_INCLUDED
993 #endif
994 
995 #ifndef __CPROVER_STDARG_H_INCLUDED
996 # include <stdarg.h>
997 # define __CPROVER_STDARG_H_INCLUDED
998 #endif
999 
1000 int __isoc99_fscanf(FILE *restrict stream, const char *restrict format, ...)
1001 {
1002 __CPROVER_HIDE:;
1003  va_list list;
1004  va_start(list, format);
1005  int result = vfscanf(stream, format, list);
1006  va_end(list);
1007  return result;
1008 }
1009 
1010 /* FUNCTION: scanf */
1011 
1012 #if !defined(__USE_ISOC99) || !defined(__REDIRECT)
1013 
1014 # ifndef __CPROVER_STDIO_H_INCLUDED
1015 # include <stdio.h>
1016 # define __CPROVER_STDIO_H_INCLUDED
1017 # endif
1018 
1019 # ifndef __CPROVER_STDARG_H_INCLUDED
1020 # include <stdarg.h>
1021 # define __CPROVER_STDARG_H_INCLUDED
1022 # endif
1023 
1024 int scanf(const char *restrict format, ...)
1025 {
1026 __CPROVER_HIDE:;
1027  va_list list;
1028  va_start(list, format);
1029  int result=vfscanf(stdin, format, list);
1030  va_end(list);
1031  return result;
1032 }
1033 
1034 #endif
1035 
1036 /* FUNCTION: __isoc99_scanf */
1037 
1038 #ifndef __CPROVER_STDIO_H_INCLUDED
1039 # include <stdio.h>
1040 # define __CPROVER_STDIO_H_INCLUDED
1041 #endif
1042 
1043 #ifndef __CPROVER_STDARG_H_INCLUDED
1044 # include <stdarg.h>
1045 # define __CPROVER_STDARG_H_INCLUDED
1046 #endif
1047 
1048 int __isoc99_scanf(const char *restrict format, ...)
1049 {
1050 __CPROVER_HIDE:;
1051  va_list list;
1052  va_start(list, format);
1053  int result = vfscanf(stdin, format, list);
1054  va_end(list);
1055  return result;
1056 }
1057 
1058 /* FUNCTION: sscanf */
1059 
1060 #if !defined(__USE_ISOC99) || !defined(__REDIRECT)
1061 
1062 # ifndef __CPROVER_STDIO_H_INCLUDED
1063 # include <stdio.h>
1064 # define __CPROVER_STDIO_H_INCLUDED
1065 # endif
1066 
1067 # ifndef __CPROVER_STDARG_H_INCLUDED
1068 # include <stdarg.h>
1069 # define __CPROVER_STDARG_H_INCLUDED
1070 # endif
1071 
1072 int sscanf(const char *restrict s, const char *restrict format, ...)
1073 {
1074 __CPROVER_HIDE:;
1075  va_list list;
1076  va_start(list, format);
1077  int result=vsscanf(s, format, list);
1078  va_end(list);
1079  return result;
1080 }
1081 
1082 #endif
1083 
1084 /* FUNCTION: __isoc99_sscanf */
1085 
1086 #ifndef __CPROVER_STDIO_H_INCLUDED
1087 # include <stdio.h>
1088 # define __CPROVER_STDIO_H_INCLUDED
1089 #endif
1090 
1091 #ifndef __CPROVER_STDARG_H_INCLUDED
1092 # include <stdarg.h>
1093 # define __CPROVER_STDARG_H_INCLUDED
1094 #endif
1095 
1096 int __isoc99_sscanf(const char *restrict s, const char *restrict format, ...)
1097 {
1098 __CPROVER_HIDE:;
1099  va_list list;
1100  va_start(list, format);
1101  int result = vsscanf(s, format, list);
1102  va_end(list);
1103  return result;
1104 }
1105 
1106 /* FUNCTION: vfscanf */
1107 
1108 #if !defined(__USE_ISOC99) || !defined(__REDIRECT)
1109 
1110 # ifndef __CPROVER_STDIO_H_INCLUDED
1111 # include <stdio.h>
1112 # define __CPROVER_STDIO_H_INCLUDED
1113 # endif
1114 
1115 # ifndef __CPROVER_STDARG_H_INCLUDED
1116 # include <stdarg.h>
1117 # define __CPROVER_STDARG_H_INCLUDED
1118 # endif
1119 
1120 int __VERIFIER_nondet_int(void);
1121 
1122 int vfscanf(FILE *restrict stream, const char *restrict format, va_list arg)
1123 {
1124  __CPROVER_HIDE:;
1125  int result=__VERIFIER_nondet_int();
1126 
1127  if(stream != stdin)
1128  {
1129 #if !defined(__linux__) || defined(__GLIBC__)
1130  (void)*stream;
1131 #else
1132  (void)*(char *)stream;
1133 #endif
1134  }
1135 
1136  (void)*format;
1137  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&arg) <
1138  __CPROVER_OBJECT_SIZE(arg))
1139  {
1140  void *a = va_arg(arg, void *);
1142  }
1143 
1144 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
1145  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
1146  "vfscanf file must be open");
1147 #endif
1148 
1149  return result;
1150 }
1151 
1152 #endif
1153 
1154 /* FUNCTION: __isoc99_vfscanf */
1155 
1156 #ifndef __CPROVER_STDIO_H_INCLUDED
1157 # include <stdio.h>
1158 # define __CPROVER_STDIO_H_INCLUDED
1159 #endif
1160 
1161 #ifndef __CPROVER_STDARG_H_INCLUDED
1162 # include <stdarg.h>
1163 # define __CPROVER_STDARG_H_INCLUDED
1164 #endif
1165 
1166 int __VERIFIER_nondet_int(void);
1167 
1169  FILE *restrict stream,
1170  const char *restrict format,
1171  va_list arg)
1172 {
1173 __CPROVER_HIDE:;
1174  int result = __VERIFIER_nondet_int();
1175 
1176  if(stream != stdin)
1177  {
1178 #if !defined(__linux__) || defined(__GLIBC__)
1179  (void)*stream;
1180 #else
1181  (void)*(char *)stream;
1182 #endif
1183  }
1184 
1185  (void)*format;
1186  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&arg) <
1187  __CPROVER_OBJECT_SIZE(*(void **)&arg))
1188  {
1189  void *a = va_arg(arg, void *);
1191  }
1192 
1193 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
1195  __CPROVER_get_must(stream, "open"), "vfscanf file must be open");
1196 #endif
1197 
1198  return result;
1199 }
1200 
1201 /* FUNCTION: __stdio_common_vfscanf */
1202 
1203 #ifdef _WIN32
1204 
1205 # ifndef __CPROVER_STDIO_H_INCLUDED
1206 # include <stdio.h>
1207 # define __CPROVER_STDIO_H_INCLUDED
1208 # endif
1209 
1210 # ifndef __CPROVER_STDARG_H_INCLUDED
1211 # include <stdarg.h>
1212 # define __CPROVER_STDARG_H_INCLUDED
1213 # endif
1214 
1215 int __VERIFIER_nondet_int(void);
1216 
1217 int __stdio_common_vfscanf(
1218  unsigned __int64 options,
1219  FILE *stream,
1220  char const *format,
1221  _locale_t locale,
1222  va_list args)
1223 {
1224  (void)options;
1225  (void)locale;
1226 
1227  int result = __VERIFIER_nondet_int();
1228 
1229  if(stream != stdin)
1230  {
1231  (void)*(char *)stream;
1232  }
1233 
1234  (void)*format;
1235  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&args) <
1236  __CPROVER_OBJECT_SIZE(args))
1237  {
1238  void *a = va_arg(args, void *);
1240  }
1241 
1242 # ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
1244  __CPROVER_get_must(stream, "open"), "vfscanf file must be open");
1245 # endif
1246 
1247  return result;
1248 }
1249 
1250 #endif
1251 
1252 /* FUNCTION: vscanf */
1253 
1254 #if !defined(__USE_ISOC99) || !defined(__REDIRECT)
1255 
1256 # ifndef __CPROVER_STDIO_H_INCLUDED
1257 # include <stdio.h>
1258 # define __CPROVER_STDIO_H_INCLUDED
1259 # endif
1260 
1261 # ifndef __CPROVER_STDARG_H_INCLUDED
1262 # include <stdarg.h>
1263 # define __CPROVER_STDARG_H_INCLUDED
1264 # endif
1265 
1266 int vscanf(const char *restrict format, va_list arg)
1267 {
1268  __CPROVER_HIDE:;
1269  return vfscanf(stdin, format, arg);
1270 }
1271 
1272 #endif
1273 
1274 /* FUNCTION: __isoc99_vscanf */
1275 
1276 #ifndef __CPROVER_STDIO_H_INCLUDED
1277 # include <stdio.h>
1278 # define __CPROVER_STDIO_H_INCLUDED
1279 #endif
1280 
1281 #ifndef __CPROVER_STDARG_H_INCLUDED
1282 # include <stdarg.h>
1283 # define __CPROVER_STDARG_H_INCLUDED
1284 #endif
1285 
1286 int __isoc99_vscanf(const char *restrict format, va_list arg)
1287 {
1288 __CPROVER_HIDE:;
1289  return vfscanf(stdin, format, arg);
1290 }
1291 
1292 /* FUNCTION: vsscanf */
1293 
1294 #if !defined(__USE_ISOC99) || !defined(__REDIRECT)
1295 
1296 # ifndef __CPROVER_STDIO_H_INCLUDED
1297 # include <stdio.h>
1298 # define __CPROVER_STDIO_H_INCLUDED
1299 # endif
1300 
1301 # ifndef __CPROVER_STDARG_H_INCLUDED
1302 # include <stdarg.h>
1303 # define __CPROVER_STDARG_H_INCLUDED
1304 # endif
1305 
1306 int __VERIFIER_nondet_int(void);
1307 
1308 int vsscanf(const char *restrict s, const char *restrict format, va_list arg)
1309 {
1310 __CPROVER_HIDE:;
1311  int result = __VERIFIER_nondet_int();
1312  (void)*s;
1313  (void)*format;
1314  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&arg) <
1315  __CPROVER_OBJECT_SIZE(arg))
1316  {
1317  void *a = va_arg(arg, void *);
1319  }
1320 
1321  return result;
1322 }
1323 
1324 #endif
1325 
1326 /* FUNCTION: __isoc99_vsscanf */
1327 
1328 #ifndef __CPROVER_STDIO_H_INCLUDED
1329 # include <stdio.h>
1330 # define __CPROVER_STDIO_H_INCLUDED
1331 #endif
1332 
1333 #ifndef __CPROVER_STDARG_H_INCLUDED
1334 # include <stdarg.h>
1335 # define __CPROVER_STDARG_H_INCLUDED
1336 #endif
1337 
1338 int __VERIFIER_nondet_int(void);
1339 
1341  const char *restrict s,
1342  const char *restrict format,
1343  va_list arg)
1344 {
1345 __CPROVER_HIDE:;
1346  int result = __VERIFIER_nondet_int();
1347  (void)*s;
1348  (void)*format;
1349  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&arg) <
1350  __CPROVER_OBJECT_SIZE(*(void **)&arg))
1351  {
1352  void *a = va_arg(arg, void *);
1354  }
1355 
1356  return result;
1357 }
1358 
1359 /* FUNCTION: __stdio_common_vsscanf */
1360 
1361 #ifdef _WIN32
1362 
1363 # ifndef __CPROVER_STDIO_H_INCLUDED
1364 # include <stdio.h>
1365 # define __CPROVER_STDIO_H_INCLUDED
1366 # endif
1367 
1368 # ifndef __CPROVER_STDARG_H_INCLUDED
1369 # include <stdarg.h>
1370 # define __CPROVER_STDARG_H_INCLUDED
1371 # endif
1372 
1373 int __VERIFIER_nondet_int(void);
1374 
1375 int __stdio_common_vsscanf(
1376  unsigned __int64 options,
1377  char const *s,
1378  size_t buffer_count,
1379  char const *format,
1380  _locale_t locale,
1381  va_list args)
1382 {
1383  (void)options;
1384  (void)locale;
1385 
1386  int result = __VERIFIER_nondet_int();
1387 
1388  (void)*s;
1389  (void)*format;
1390  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&args) <
1391  __CPROVER_OBJECT_SIZE(args))
1392  {
1393  void *a = va_arg(args, void *);
1395  }
1396 
1397  return result;
1398 }
1399 
1400 #endif
1401 
1402 /* FUNCTION: printf */
1403 
1404 #ifndef __CPROVER_STDIO_H_INCLUDED
1405 # include <stdio.h>
1406 # define __CPROVER_STDIO_H_INCLUDED
1407 #endif
1408 
1409 #ifndef __CPROVER_STDARG_H_INCLUDED
1410 # include <stdarg.h>
1411 # define __CPROVER_STDARG_H_INCLUDED
1412 #endif
1413 
1414 int __VERIFIER_nondet_int(void);
1415 
1416 int printf(const char *format, ...)
1417 {
1418 __CPROVER_HIDE:;
1419  int result = __VERIFIER_nondet_int();
1420  va_list list;
1421  va_start(list, format);
1422  __CPROVER_printf(format, list);
1423  va_end(list);
1424  return result;
1425 }
1426 
1427 /* FUNCTION: __printf_chk */
1428 
1429 #ifndef __CPROVER_STDIO_H_INCLUDED
1430 # include <stdio.h>
1431 # define __CPROVER_STDIO_H_INCLUDED
1432 #endif
1433 
1434 #ifndef __CPROVER_STDARG_H_INCLUDED
1435 # include <stdarg.h>
1436 # define __CPROVER_STDARG_H_INCLUDED
1437 #endif
1438 
1439 int __VERIFIER_nondet_int(void);
1440 
1441 int __printf_chk(int flag, const char *format, ...)
1442 {
1443 __CPROVER_HIDE:;
1444  (void)flag;
1445  int result = __VERIFIER_nondet_int();
1446  va_list list;
1447  va_start(list, format);
1448  __CPROVER_printf(format, list);
1449  va_end(list);
1450  return result;
1451 }
1452 
1453 /* FUNCTION: fprintf */
1454 
1455 #ifndef __CPROVER_STDIO_H_INCLUDED
1456 #include <stdio.h>
1457 #define __CPROVER_STDIO_H_INCLUDED
1458 #endif
1459 
1460 #ifndef __CPROVER_STDARG_H_INCLUDED
1461 #include <stdarg.h>
1462 #define __CPROVER_STDARG_H_INCLUDED
1463 #endif
1464 
1465 int fprintf(FILE *stream, const char *restrict format, ...)
1466 {
1467  __CPROVER_HIDE:;
1468  va_list list;
1469  va_start(list, format);
1470  int result=vfprintf(stream, format, list);
1471  va_end(list);
1472  return result;
1473 }
1474 
1475 /* FUNCTION: __fprintf_chk */
1476 
1477 #ifndef __CPROVER_STDIO_H_INCLUDED
1478 # include <stdio.h>
1479 # define __CPROVER_STDIO_H_INCLUDED
1480 #endif
1481 
1482 #ifndef __CPROVER_STDARG_H_INCLUDED
1483 # include <stdarg.h>
1484 # define __CPROVER_STDARG_H_INCLUDED
1485 #endif
1486 
1487 int __fprintf_chk(FILE *stream, int flag, const char *restrict format, ...)
1488 {
1489 __CPROVER_HIDE:;
1490  (void)flag;
1491  va_list list;
1492  va_start(list, format);
1493  int result = vfprintf(stream, format, list);
1494  va_end(list);
1495  return result;
1496 }
1497 
1498 /* FUNCTION: vfprintf */
1499 
1500 #ifndef __CPROVER_STDIO_H_INCLUDED
1501 #include <stdio.h>
1502 #define __CPROVER_STDIO_H_INCLUDED
1503 #endif
1504 
1505 #ifndef __CPROVER_STDARG_H_INCLUDED
1506 #include <stdarg.h>
1507 #define __CPROVER_STDARG_H_INCLUDED
1508 #endif
1509 
1510 int __VERIFIER_nondet_int(void);
1511 
1512 int vfprintf(FILE *stream, const char *restrict format, va_list arg)
1513 {
1514  __CPROVER_HIDE:;
1515 
1516  int result=__VERIFIER_nondet_int();
1517 
1518  if(stream != stdout && stream != stderr)
1519  {
1520 #if !defined(__linux__) || defined(__GLIBC__)
1521  (void)*stream;
1522 #else
1523  (void)*(char *)stream;
1524 #endif
1525  }
1526 
1527  (void)*format;
1528  (void)arg;
1529 
1530 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
1531  __CPROVER_assert(__CPROVER_get_must(stream, "open"),
1532  "vfprintf file must be open");
1533 #endif
1534 
1535  return result;
1536 }
1537 
1538 /* FUNCTION: __vfprintf_chk */
1539 
1540 #ifndef __CPROVER_STDIO_H_INCLUDED
1541 # include <stdio.h>
1542 # define __CPROVER_STDIO_H_INCLUDED
1543 #endif
1544 
1545 #ifndef __CPROVER_STDARG_H_INCLUDED
1546 # include <stdarg.h>
1547 # define __CPROVER_STDARG_H_INCLUDED
1548 #endif
1549 
1550 int __VERIFIER_nondet_int(void);
1551 
1553  FILE *stream,
1554  int flag,
1555  const char *restrict format,
1556  va_list arg)
1557 {
1558 __CPROVER_HIDE:;
1559  (void)flag;
1560 
1561  int result = __VERIFIER_nondet_int();
1562 
1563  if(stream != stdout && stream != stderr)
1564  {
1565 #if !defined(__linux__) || defined(__GLIBC__)
1566  (void)*stream;
1567 #else
1568  (void)*(char *)stream;
1569 #endif
1570  }
1571 
1572  (void)*format;
1573  (void)arg;
1574 
1575 #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
1577  __CPROVER_get_must(stream, "open"), "vfprintf file must be open");
1578 #endif
1579 
1580  return result;
1581 }
1582 
1583 /* FUNCTION: asprintf */
1584 
1585 #ifndef __CPROVER_STDARG_H_INCLUDED
1586 # include <stdarg.h>
1587 # define __CPROVER_STDARG_H_INCLUDED
1588 #endif
1589 
1590 // declare here instead of relying on stdio.h as even those platforms that do
1591 // have it at all may require _GNU_SOURCE to be set
1592 int vasprintf(char **ptr, const char *fmt, va_list ap);
1593 
1594 int asprintf(char **ptr, const char *fmt, ...)
1595 {
1596  va_list list;
1597  va_start(list, fmt);
1598  int result = vasprintf(ptr, fmt, list);
1599  va_end(list);
1600  return result;
1601 }
1602 
1603 /* FUNCTION: dprintf */
1604 
1605 #ifndef __CPROVER_STDIO_H_INCLUDED
1606 # include <stdio.h>
1607 # define __CPROVER_STDIO_H_INCLUDED
1608 #endif
1609 
1610 #ifndef __CPROVER_STDARG_H_INCLUDED
1611 # include <stdarg.h>
1612 # define __CPROVER_STDARG_H_INCLUDED
1613 #endif
1614 
1615 int dprintf(int fd, const char *restrict format, ...)
1616 {
1617 __CPROVER_HIDE:;
1618  va_list list;
1619  va_start(list, format);
1620  int result = vdprintf(fd, format, list);
1621  va_end(list);
1622  return result;
1623 }
1624 
1625 /* FUNCTION: vdprintf */
1626 
1627 #ifndef __CPROVER_STDIO_H_INCLUDED
1628 # include <stdio.h>
1629 # define __CPROVER_STDIO_H_INCLUDED
1630 #endif
1631 
1632 #ifndef __CPROVER_STDARG_H_INCLUDED
1633 # include <stdarg.h>
1634 # define __CPROVER_STDARG_H_INCLUDED
1635 #endif
1636 
1637 int __VERIFIER_nondet_int(void);
1638 
1639 int vdprintf(int fd, const char *restrict format, va_list arg)
1640 {
1641 __CPROVER_HIDE:;
1642 
1643  int result = __VERIFIER_nondet_int();
1644 
1645  (void)fd;
1646  (void)*format;
1647  (void)arg;
1648 
1649  return result;
1650 }
1651 
1652 /* FUNCTION: vasprintf */
1653 
1654 #ifndef __CPROVER_STDIO_H_INCLUDED
1655 #include <stdio.h>
1656 #define __CPROVER_STDIO_H_INCLUDED
1657 #endif
1658 
1659 #ifndef __CPROVER_STDARG_H_INCLUDED
1660 #include <stdarg.h>
1661 #define __CPROVER_STDARG_H_INCLUDED
1662 #endif
1663 
1664 #ifndef __CPROVER_STDLIB_H_INCLUDED
1665 #include <stdlib.h>
1666 #define __CPROVER_STDLIB_H_INCLUDED
1667 #endif
1668 
1669 char __VERIFIER_nondet_char(void);
1670 int __VERIFIER_nondet_int(void);
1671 
1672 int vasprintf(char **ptr, const char *fmt, va_list ap)
1673 {
1674  (void)*fmt;
1675  (void)ap;
1676 
1677  int result_buffer_size=__VERIFIER_nondet_int();
1678  if(result_buffer_size<=0)
1679  return -1;
1680 
1681  *ptr=malloc(result_buffer_size);
1682  if(!*ptr)
1683  return -1;
1684  int i=0;
1685  for( ; i<result_buffer_size; ++i)
1686  {
1687  char c=__VERIFIER_nondet_char();
1688  (*ptr)[i]=c;
1689  if(c=='\0')
1690  break;
1691  }
1692 
1693  __CPROVER_assume(i<result_buffer_size);
1694 
1695  return i;
1696 }
1697 
1698 /* FUNCTION: snprintf */
1699 
1700 #ifndef __CPROVER_STDIO_H_INCLUDED
1701 # include <stdio.h>
1702 # define __CPROVER_STDIO_H_INCLUDED
1703 #endif
1704 
1705 #ifndef __CPROVER_STDARG_H_INCLUDED
1706 # include <stdarg.h>
1707 # define __CPROVER_STDARG_H_INCLUDED
1708 #endif
1709 
1710 #undef snprintf
1711 
1712 int snprintf(char *str, size_t size, const char *fmt, ...)
1713 {
1714  va_list list;
1715  va_start(list, fmt);
1716  int result = vsnprintf(str, size, fmt, list);
1717  va_end(list);
1718  return result;
1719 }
1720 
1721 /* FUNCTION: __builtin___snprintf_chk */
1722 
1723 #ifndef __CPROVER_STDIO_H_INCLUDED
1724 # include <stdio.h>
1725 # define __CPROVER_STDIO_H_INCLUDED
1726 #endif
1727 
1728 #ifndef __CPROVER_STDARG_H_INCLUDED
1729 # include <stdarg.h>
1730 # define __CPROVER_STDARG_H_INCLUDED
1731 #endif
1732 
1734  char *str,
1735  size_t size,
1736  int flag,
1737  size_t bufsize,
1738  const char *fmt,
1739  va_list ap);
1740 
1742  char *str,
1743  size_t size,
1744  int flag,
1745  size_t bufsize,
1746  const char *fmt,
1747  ...)
1748 {
1749  va_list list;
1750  va_start(list, fmt);
1751  int result = __builtin___vsnprintf_chk(str, size, flag, bufsize, fmt, list);
1752  va_end(list);
1753  return result;
1754 }
1755 
1756 /* FUNCTION: vsnprintf */
1757 
1758 #ifndef __CPROVER_STDIO_H_INCLUDED
1759 # include <stdio.h>
1760 # define __CPROVER_STDIO_H_INCLUDED
1761 #endif
1762 
1763 #ifndef __CPROVER_STDARG_H_INCLUDED
1764 # include <stdarg.h>
1765 # define __CPROVER_STDARG_H_INCLUDED
1766 #endif
1767 
1768 #undef vsnprintf
1769 
1770 char __VERIFIER_nondet_char(void);
1771 
1772 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
1773 {
1774  (void)*fmt;
1775 
1776  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&ap) <
1778 
1779  {
1780  (void)va_arg(ap, int);
1783  "vsnprintf object overlap");
1784  }
1785 
1786  size_t i = 0;
1787  for(; i < size; ++i)
1788  {
1789  char c = __VERIFIER_nondet_char();
1790  str[i] = c;
1791  if(c == '\0')
1792  break;
1793  }
1794 
1795  return i;
1796 }
1797 
1798 /* FUNCTION: __builtin___vsnprintf_chk */
1799 
1800 #ifndef __CPROVER_STDIO_H_INCLUDED
1801 # include <stdio.h>
1802 # define __CPROVER_STDIO_H_INCLUDED
1803 #endif
1804 
1805 #ifndef __CPROVER_STDARG_H_INCLUDED
1806 # include <stdarg.h>
1807 # define __CPROVER_STDARG_H_INCLUDED
1808 #endif
1809 
1810 char __VERIFIER_nondet_char(void);
1811 
1813  char *str,
1814  size_t size,
1815  int flag,
1816  size_t bufsize,
1817  const char *fmt,
1818  va_list ap)
1819 {
1820  (void)flag;
1821  (void)bufsize;
1822  (void)*fmt;
1823 
1824  while((__CPROVER_size_t)__CPROVER_POINTER_OFFSET(*(void **)&ap) <
1826 
1827  {
1828  (void)va_arg(ap, int);
1831  "vsnprintf object overlap");
1832  }
1833 
1834  size_t i = 0;
1835  for(; i < size; ++i)
1836  {
1837  char c = __VERIFIER_nondet_char();
1838  str[i] = c;
1839  if(c == '\0')
1840  break;
1841  }
1842 
1843  return i;
1844 }
1845 
1846 /* FUNCTION: __acrt_iob_func */
1847 
1848 #ifdef _WIN32
1849 
1850 # ifndef __CPROVER_STDIO_H_INCLUDED
1851 # include <stdio.h>
1852 # define __CPROVER_STDIO_H_INCLUDED
1853 # endif
1854 
1855 FILE *__acrt_iob_func(unsigned fd)
1856 {
1857  static FILE stdin_file;
1858  static FILE stdout_file;
1859  static FILE stderr_file;
1860 
1861  switch(fd)
1862  {
1863  case 0:
1864  return &stdin_file;
1865  case 1:
1866  return &stdout_file;
1867  case 2:
1868  return &stderr_file;
1869  default:
1870  return (FILE *)0;
1871  }
1872 }
1873 
1874 #endif
1875 
1876 /* FUNCTION: __stdio_common_vfprintf */
1877 
1878 #ifdef _WIN32
1879 
1880 # ifndef __CPROVER_STDIO_H_INCLUDED
1881 # include <stdio.h>
1882 # define __CPROVER_STDIO_H_INCLUDED
1883 # endif
1884 
1885 # ifndef __CPROVER_STDARG_H_INCLUDED
1886 # include <stdarg.h>
1887 # define __CPROVER_STDARG_H_INCLUDED
1888 # endif
1889 
1890 int __stdio_common_vfprintf(
1891  unsigned __int64 options,
1892  FILE *stream,
1893  char const *format,
1894  _locale_t locale,
1895  va_list args)
1896 {
1897  (void)options;
1898  (void)locale;
1899 
1900  if(stream == __acrt_iob_func(1))
1901  __CPROVER_printf(format, args);
1902  return 0;
1903 }
1904 
1905 #endif
1906 
1907 /* FUNCTION: __stdio_common_vsprintf */
1908 
1909 #ifdef _WIN32
1910 
1911 # ifndef __CPROVER_STDIO_H_INCLUDED
1912 # include <stdio.h>
1913 # define __CPROVER_STDIO_H_INCLUDED
1914 # endif
1915 
1916 # ifndef __CPROVER_STDARG_H_INCLUDED
1917 # include <stdarg.h>
1918 # define __CPROVER_STDARG_H_INCLUDED
1919 # endif
1920 
1921 char __VERIFIER_nondet_char(void);
1922 
1923 int __stdio_common_vsprintf(
1924  unsigned __int64 options,
1925  char *str,
1926  size_t size,
1927  char const *fmt,
1928  _locale_t locale,
1929  va_list args)
1930 {
1931  (void)options;
1932  (void)*fmt;
1933  (void)locale;
1934  (void)args;
1935 
1936  size_t i = 0;
1937  for(; i < size; ++i)
1938  {
1939  char c = __VERIFIER_nondet_char();
1940  str[i] = c;
1941  if(c == '\0')
1942  break;
1943  }
1944 
1945  return i;
1946 }
1947 
1948 #endif
1949 
1950 /* FUNCTION: __srget */
1951 
1952 #ifdef __FreeBSD__
1953 
1954 # ifndef __CPROVER_STDIO_H_INCLUDED
1955 # include <stdio.h>
1956 # define __CPROVER_STDIO_H_INCLUDED
1957 # endif
1958 
1959 int __VERIFIER_nondet_int(void);
1960 
1961 int __srget(FILE *stream)
1962 {
1963  (void)*stream;
1964 
1965  // FreeBSD's implementation returns a character or EOF; __VERIFIER_nondet_int
1966  // will capture all these options
1967  return __VERIFIER_nondet_int();
1968 }
1969 
1970 #endif
1971 
1972 /* FUNCTION: __swbuf */
1973 
1974 #ifdef __FreeBSD__
1975 
1976 # ifndef __CPROVER_STDIO_H_INCLUDED
1977 # include <stdio.h>
1978 # define __CPROVER_STDIO_H_INCLUDED
1979 # endif
1980 
1981 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
1982 
1983 int __swbuf(int c, FILE *stream)
1984 {
1985  (void)c;
1986  (void)*stream;
1987 
1988  // FreeBSD's implementation returns `c` or or EOF in case writing failed; we
1989  // just non-deterministically choose between these
1991  return EOF;
1992  else
1993  return c;
1994 }
1995 
1996 #endif
__CPROVER_bool __CPROVER_w_ok(const void *,...)
__CPROVER_size_t __CPROVER_buffer_size(const void *)
void __CPROVER_printf(const char *format,...)
__CPROVER_size_t __CPROVER_OBJECT_SIZE(const void *)
void __CPROVER_clear_must(const void *, const char *)
void __CPROVER_assert(__CPROVER_bool assertion, const char *description)
void __CPROVER_array_replace(const void *dest, const void *src)
__CPROVER_size_t __CPROVER_POINTER_OFFSET(const void *)
__CPROVER_size_t __CPROVER_POINTER_OBJECT(const void *)
__CPROVER_size_t __CPROVER_zero_string_length(const void *)
__CPROVER_bool __CPROVER_get_must(const void *, const char *)
void __CPROVER_input(const char *id,...)
void __CPROVER_precondition(__CPROVER_bool precondition, const char *description)
_Bool __CPROVER_is_zero_string(const void *)
void __CPROVER_set_must(const void *, const char *)
void __CPROVER_cleanup(const void *, const void *)
void __CPROVER_assume(__CPROVER_bool assumption)
void __CPROVER_havoc_object(void *)
static format_containert< T > format(const T &o)
Definition: format.h:37
mini_bddt restrict(const mini_bddt &u, unsigned var, const bool value)
Definition: miniBDD.cpp:551
int __VERIFIER_nondet_int(void)
int vscanf(const char *restrict format, va_list arg)
Definition: stdio.c:1266
int __isoc99_sscanf(const char *restrict s, const char *restrict format,...)
Definition: stdio.c:1096
void fclose_cleanup(void *stream)
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
Definition: stdio.c:1772
int vasprintf(char **ptr, const char *fmt, va_list ap)
Definition: stdio.c:1672
int dprintf(int fd, const char *restrict format,...)
Definition: stdio.c:1615
int __isoc99_vscanf(const char *restrict format, va_list arg)
Definition: stdio.c:1286
int scanf(const char *restrict format,...)
Definition: stdio.c:1024
int snprintf(char *str, size_t size, const char *fmt,...)
Definition: stdio.c:1712
int getchar(void)
Definition: stdio.c:776
int __fprintf_chk(FILE *stream, int flag, const char *restrict format,...)
Definition: stdio.c:1487
int sscanf(const char *restrict s, const char *restrict format,...)
Definition: stdio.c:1072
int asprintf(char **ptr, const char *fmt,...)
Definition: stdio.c:1594
size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
Definition: stdio.c:910
FILE * fdopen(int handle, const char *mode)
Definition: stdio.c:256
size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream)
Definition: stdio.c:433
int ferror(FILE *stream)
Definition: stdio.c:543
int __isoc99_fscanf(FILE *restrict stream, const char *restrict format,...)
Definition: stdio.c:1000
int __printf_chk(int flag, const char *format,...)
Definition: stdio.c:1441
int vfscanf(FILE *restrict stream, const char *restrict format, va_list arg)
Definition: stdio.c:1122
int vsscanf(const char *restrict s, const char *restrict format, va_list arg)
Definition: stdio.c:1308
long ftell(FILE *stream)
Definition: stdio.c:859
int __isoc99_vsscanf(const char *restrict s, const char *restrict format, va_list arg)
Definition: stdio.c:1340
int __builtin___vsnprintf_chk(char *str, size_t size, int flag, size_t bufsize, const char *fmt, va_list ap)
Definition: stdio.c:1812
int fseek(FILE *stream, long offset, int whence)
Definition: stdio.c:829
char __VERIFIER_nondet_char(void)
int __builtin___snprintf_chk(char *str, size_t size, int flag, size_t bufsize, const char *fmt,...)
Definition: stdio.c:1741
int fputs(const char *s, FILE *stream)
Definition: stdio.c:611
int getw(FILE *stream)
Definition: stdio.c:795
int fclose(FILE *stream)
Definition: stdio.c:230
char * fgets(char *str, int size, FILE *stream)
Definition: stdio.c:321
int __isoc99_scanf(const char *restrict format,...)
Definition: stdio.c:1048
FILE * fopen64(const char *filename, const char *mode)
Definition: stdio.c:147
char * __fgets_chk(char *str, __CPROVER_size_t bufsize, int size, FILE *stream)
Definition: stdio.c:376
FILE * freopen64(const char *filename, const char *mode, FILE *f)
Definition: stdio.c:202
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void)
int printf(const char *format,...)
Definition: stdio.c:1416
size_t __VERIFIER_nondet_size_t(void)
int feof(FILE *stream)
Definition: stdio.c:511
void rewind(FILE *stream)
Definition: stdio.c:885
int fprintf(FILE *stream, const char *restrict format,...)
Definition: stdio.c:1465
int vdprintf(int fd, const char *restrict format, va_list arg)
Definition: stdio.c:1639
int __vfprintf_chk(FILE *stream, int flag, const char *restrict format, va_list arg)
Definition: stdio.c:1552
int fgetc(FILE *stream)
Definition: stdio.c:704
void perror(const char *s)
Definition: stdio.c:946
size_t __fread_chk(void *ptr, size_t ptrlen, size_t size, size_t nitems, FILE *stream)
Definition: stdio.c:473
int __isoc99_vfscanf(FILE *restrict stream, const char *restrict format, va_list arg)
Definition: stdio.c:1168
FILE * freopen(const char *filename, const char *mode, FILE *f)
Definition: stdio.c:189
int puts(const char *s)
Definition: stdio.c:39
int getc(FILE *stream)
Definition: stdio.c:740
int fflush(FILE *stream)
Definition: stdio.c:647
int vfprintf(FILE *stream, const char *restrict format, va_list arg)
Definition: stdio.c:1512
int putchar(int c)
Definition: stdio.c:21
int fpurge(FILE *stream)
Definition: stdio.c:672
int fileno(FILE *stream)
Definition: stdio.c:575
long __VERIFIER_nondet_long(void)
int fscanf(FILE *restrict stream, const char *restrict format,...)
Definition: stdio.c:976
FILE * fopen(const char *filename, const char *mode)
Definition: stdio.c:77
void * malloc(__CPROVER_size_t malloc_size)
Definition: stdlib.c:212
void free(void *ptr)
Definition: stdlib.c:317