/* This program is part of the TACLeBench benchmark suite. Version V 1.x Name: fac Author: unknown Function: fac is a program to calculate factorials. This program computes the sum of the factorials from zero to five. Source: MRTC http://www.mrtc.mdh.se/projects/wcet/wcet_bench/fac/fac.c Changes: CS 2006/05/19: Changed loop bound from constant to variable. License: public domain */ /* Forward declaration of functions */ // Wasm loop bounds __attribute__((import_module("__pragma"), import_name("loopbound"))) extern void __pragma_loopbound(unsigned int min_bound, unsigned int max_bound); int fac_fac(int n); void fac_init(); int fac_return(); __attribute__((noinline)) __attribute__((export_name("entrypoint"))) void fac_main(); __attribute__((noinline)) __attribute__((export_name("main"))) int main(void); /* Declaration of global variables */ int fac_s; volatile int fac_n; /* Initialization- and return-value-related functions */ void fac_init() { fac_s = 0; fac_n = 5; } int fac_return() { int expected_result = 154; return fac_s - expected_result; } /* Arithmetic math functions */ int fac_fac(int n) { if (n == 0) return 1; else return (n * fac_fac(n - 1)); } /* Main functions */ __attribute__((noinline)) __attribute__((export_name("entrypoint"))) void fac_main() { int i; __pragma_loopbound(6, 6); for (i = 0; i <= fac_n; i++) { _Pragma("marker recursivecall") fac_s += fac_fac(i); _Pragma("flowrestriction 1*fac_fac <= 6*recursivecall") } } __attribute__((noinline)) __attribute__((export_name("main"))) int main(void) { fac_init(); fac_main(); return (fac_return()); }