file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/50243.c
#include <stdio.h> #include <stdlib.h> int** createRaggedArray(int rows, int* columnsArray) { int** pointersArray = malloc(sizeof(int*)*rows); for (int i = 0; i<rows; i++) { int *raggedArray = malloc(sizeof(int)*columnsArray[i]); for (int t = 0; t<columnsArray[i]; t++) { raggedArray[t] = i+t + i*t; printf("Array %i number %i %d\n", i, t, i+t + i*t); } pointersArray[i] = raggedArray; } return pointersArray; } int main() { int *sizes = (int[5]) {6,5,3,5,4}; int **ragged = createRaggedArray(5, sizes); printf("%d", ragged[1][3]); return 0; }
the_stack_data/1008310.c
/* Portable version of bzero for systems without it. This function is in the public domain. */ /* @deftypefn Supplemental void bzero (char *@var{mem}, int @var{count}) Zeros @var{count} bytes starting at @var{mem}. Use of this function is deprecated in favor of @code{memset}. @end deftypefn */ void bzero (to, count) char *to; int count; { while (count-- > 0) { *to++ = 0; } }
the_stack_data/167330154.c
/* Prime gaps histogram animation * $ cc -Ofast -o primegaps primegaps.c -lm * $ ./primegaps | mpv --fps=60 --no-correct-pts - * $ ./primegaps | x264 --fps=60 -o primegaps.mp4 /dev/stdin * Ref: https://www.youtube.com/watch?v=SMsTXQYgbiQ * This is free and unencumbered software released into the public domain. */ #include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define WIDTH 1200 #define HEIGHT 800 #define COLOR 0x7f7fff #define NBINS 150 #define BINMAX 17 #define MAXPRIME 3121238909 // 150 millionth prime #define LLONG_BIT (sizeof(unsigned long long) * CHAR_BIT) #define GET(a, i) (a[(i) / LLONG_BIT] >> ((i) % LLONG_BIT) & 1ULL) #define SET(a, i) (a[(i) / LLONG_BIT] |= 1ULL << ((i) % LLONG_BIT)) struct primesieve { long long n; long long max; long long sieve[]; }; static struct primesieve * primesieve_create(long long max) { struct primesieve *ps; size_t size = (max + LLONG_BIT - 1) / LLONG_BIT * sizeof(ps->sieve[0]); ps = calloc(1, sizeof(*ps) + size); if (ps) { ps->n = 0; ps->max = max; } return ps; } static long long primesieve_next(struct primesieve *ps) { if (!ps->n++) return 2; for (; ps->n * 2 - 1 < ps->max; ps->n++) { long long x = ps->n * 2 - 1; if (!GET(ps->sieve, x / 2)) { for (long long i = x * 3; i < ps->max; i += x * 2) SET(ps->sieve, i / 2); return x; } } return 0; } int main(void) { #ifdef _WIN32 int _setmode(int, int); _setmode(1, 0x8000); /* stdout to binary mode. */ #endif static long bins[NBINS]; struct primesieve *ps = primesieve_create(MAXPRIME + 1); long long last = primesieve_next(ps); last = primesieve_next(ps); long long lastskip = 0; long long skip = 0; for (long long n = 3; ; n++) { long long next = primesieve_next(ps); if (!next) break; long long gap = (next - last)/2 - 1; if (gap < NBINS) { bins[gap]++; } last = next; /* render at this prime? */ if (last < MAXPRIME && skip--) continue; fprintf(stderr, "%lld %llu\n", n, last); lastskip += pow(log(n), 2.8); skip = lastskip; /* render a semilog plot of the bins */ static unsigned char ppm[HEIGHT][WIDTH][3]; memset(ppm, 0, sizeof(ppm)); for (int y = 0; y < HEIGHT; y++) { double iy = HEIGHT - y - 1; for (int x = 0; x < WIDTH; x++) { double v = log(bins[x/(WIDTH/NBINS)]); if (v > iy/(HEIGHT/BINMAX)) { ppm[y][x][0] = 0xff & COLOR >> 16; ppm[y][x][1] = 0xff & COLOR >> 8; ppm[y][x][2] = 0xff & COLOR >> 0; } } } for (int i = 0; i < (last == MAXPRIME ? 60*3 : 1); i++) { printf("P6\n%d %d\n255\n", WIDTH, HEIGHT); if (!fwrite(ppm, sizeof(ppm), 1, stdout)) return 1; } } free(ps); }
the_stack_data/97043.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]/df(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) */ /* > \brief \b DCOMBSSQ adds two scaled sum of squares quantities. */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* Definition: */ /* =========== */ /* SUBROUTINE DCOMBSSQ( V1, V2 ) */ /* DOUBLE PRECISION V1( 2 ), V2( 2 ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > DCOMBSSQ adds two scaled sum of squares quantities, V1 := V1 + V2. */ /* > That is, */ /* > */ /* > V1_scale**2 * V1_sumsq := V1_scale**2 * V1_sumsq */ /* > + V2_scale**2 * V2_sumsq */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in,out] V1 */ /* > \verbatim */ /* > V1 is DOUBLE PRECISION array, dimension (2). */ /* > The first scaled sum. */ /* > V1(1) = V1_scale, V1(2) = V1_sumsq. */ /* > \endverbatim */ /* > */ /* > \param[in] V2 */ /* > \verbatim */ /* > V2 is DOUBLE PRECISION array, dimension (2). */ /* > The second scaled sum. */ /* > V2(1) = V2_scale, V2(2) = V2_sumsq. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date November 2018 */ /* > \ingroup OTHERauxiliary */ /* ===================================================================== */ /* Subroutine */ int dcombssq_(doublereal *v1, doublereal *v2) { /* System generated locals */ doublereal d__1; /* -- LAPACK auxiliary 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..-- */ /* November 2018 */ /* ===================================================================== */ /* Parameter adjustments */ --v2; --v1; /* Function Body */ if (v1[1] >= v2[1]) { if (v1[1] != 0.) { /* Computing 2nd power */ d__1 = v2[1] / v1[1]; v1[2] += d__1 * d__1 * v2[2]; } else { v1[2] += v2[2]; } } else { /* Computing 2nd power */ d__1 = v1[1] / v2[1]; v1[2] = v2[2] + d__1 * d__1 * v1[2]; v1[1] = v2[1]; } return 0; /* End of DCOMBSSQ */ } /* dcombssq_ */
the_stack_data/38801.c
/*********************************************************************** * * * $Id: hpgsmkrop.c 270 2006-01-29 21:12:23Z softadm $ * * * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * * API for rendering a scene and thus renders to a variety of * * devices and fileformats. * * * * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * * * * Author: Wolfgang Glas * * * * hpgs 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. * * * * hpgs 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 this library; if not, write to the * * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * * Boston, MA 02111-1307 USA * * * *********************************************************************** * * * A small programm, which generates the raster operations hpgsrop.c * * * ***********************************************************************/ #include <stdio.h> #include <stdarg.h> #include <string.h> #include <time.h> #include <errno.h> #ifdef __GNUC__ __attribute__((format(printf,4,5))) #endif static int apprintf (char *str, size_t str_sz, size_t *str_len, const char *fmt, ...) { int n; va_list ap; va_start(ap, fmt); n = vsnprintf(str+*str_len,str_sz-*str_len,fmt,ap); va_end(ap); if (n<0) { perror("snprintf"); return -1; } *str_len+=n; return 0; } static void mk_operand (char *operand, size_t operand_sz, const char *stack, int i) { switch (stack[i]) { case 'D': strcpy(operand,"*D"); break; case 'S': case 'T': operand[0] = stack[i]; operand[1] = '\0'; break; default: snprintf(operand,operand_sz,"stk%d",i+1); } } static void mk_xoperand (char *operand, size_t operand_sz, const char *stack, int i) { switch (stack[i]) { case 'D': strcpy(operand,"D"); break; case 'S': case 'T': operand[0] = stack[i]; operand[1] = '\0'; break; default: snprintf(operand,operand_sz,"stk%d",i+1); } } /* This function converts a ROP3 description cf. to PCL 5 Comparison Guide, Edition 2, 6/2003, Hewlett Packard (May be downloaded as bpl13206.pdf from http://www.hp.com) into 4 C-programs for all transparency modes supported by HPGL/2 and PCL. Additional information may be found under http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50grfTernaryRasterOperations.asp (especially typos in HP's documentation are corrected from this source of information). */ static int write_rop3_func(FILE *out, int irop, const char *ropstr) { int stacksz = 0; int max_stacksz = 0; char stack[32]; char operand[32]; char operand2[32]; const char *c; int D_used = 0; int S_used = 0; int T_used = 0; char defn[2048],op; size_t defn_len=0; char xdefn[2048]; size_t xdefn_len=0; int i; defn[0] = '\0'; xdefn[0] = '\0'; for (c=ropstr;*c;++c) switch (*c) { case '0': case '1': i = (*c == '0') ? 0 : 255; max_stacksz = stacksz = 1; if (c!=ropstr || *(c+1)) { fprintf (stderr,"Misplaced %c in rop string %s.\n", *c,ropstr); return -1; } if (apprintf(defn,sizeof(defn),&defn_len, " stk1 = %d;\n",i )) return -1; if (apprintf(xdefn,sizeof(xdefn),&xdefn_len, " stk1 = %s;\n", (*c == '0') ? "0x0000" : "0xffff")) return -1; break; case 'S': case 'T': case 'D': if (stacksz >= sizeof(stack)-1) { fprintf (stderr,"Stack overflow in rop string %s.\n",ropstr); return -1; } stack[stacksz] = *c; ++stacksz; if (*c == 'D') D_used = 1; if (*c == 'T') T_used = 1; if (*c == 'S') S_used = 1; break; case 'o': case 'a': case 'x': if (stacksz<1) { fprintf (stderr,"Stack underflow in rop string %s.\n",ropstr); return -1; } mk_operand(operand,sizeof(operand),stack,stacksz-2); mk_operand(operand2,sizeof(operand),stack,stacksz-1); op = (*c == 'o') ? '|' : ((*c == 'a') ? '&' : '^'); if (apprintf(defn,sizeof(defn),&defn_len, " stk%d = %s %c %s;\n", stacksz-1,operand,op,operand2 )) return -1; mk_xoperand(operand,sizeof(operand),stack,stacksz-2); mk_xoperand(operand2,sizeof(operand),stack,stacksz-1); if (apprintf(xdefn,sizeof(xdefn),&xdefn_len, " stk%d = %s %c %s;\n", stacksz-1,operand,op,operand2 )) return -1; --stacksz; // account for the max intermediate result on the stack. if (stacksz > max_stacksz) max_stacksz = stacksz; stack[stacksz-1] = '\0'; break; case 'n': mk_operand(operand,sizeof(operand),stack,stacksz-1); if (apprintf(defn,sizeof(defn),&defn_len, " stk%d = ~%s;\n", stacksz,operand )) return -1; mk_xoperand(operand,sizeof(operand),stack,stacksz-1); if (apprintf(xdefn,sizeof(xdefn),&xdefn_len, " stk%d = ~%s;\n", stacksz,operand )) return -1; // account for the max intermediate result on the stack. if (stacksz > max_stacksz) max_stacksz = stacksz; stack[stacksz-1] = '\0'; break; default: fprintf (stderr,"Illegal character %c in rop string %s.\n", *c,ropstr); return -1; } if (stacksz!=1) { fprintf (stderr,"Unbalanced shift/reduce in rop string %s.\n",ropstr); return -1; } mk_operand(operand,sizeof(operand),stack,0); // ******** normal ROP functions // case 1: source/pattern opaque. fprintf (out, "/* %s source/pattern opaque. */\n" "static void rop3_%d_0_0 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", ropstr,irop); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned char stk%d;\n",i); fputs(defn,out); // optimize for noop. if (stack[0] != 'D') fprintf(out," *D = %s;\n",operand); fprintf(out,"}\n\n"); // case 2: source opaque/pattern transparent. fprintf (out, "/* %s source opaque/pattern transparent. */\n" "static void rop3_%d_0_1 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", ropstr,irop); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned char stk%d;\n",i); fputs(defn,out); // Image_A = Temporary_ROP3, & Not Src. // Image_B = Temporary_ROP3 & Pattern. // Image_C = Not Pattern & Src & Dest. // Return Image_A | Image_B | Image_C fprintf(out," *D = (%s & S) | (%s & (~T)) | (T & (~S) & *D);\n",operand,operand); fprintf(out,"}\n\n"); // case 3: source transparent/pattern opaque. fprintf (out, "/* %s source transparent/pattern opaque. */\n" "static void rop3_%d_1_0 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", ropstr,irop); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned char stk%d;\n",i); fputs(defn,out); // Image_A = Temporary_ROP3 & Src. // Image_B = Dest & Not Src. // Return Image_A | Image_B fprintf(out," *D = (%s & (~S)) | (*D & S);\n",operand); fprintf(out,"}\n\n"); // case 4: source/pattern transparent. fprintf (out, "/* %s source/pattern transparent. */\n" "static void rop3_%d_1_1 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", ropstr,irop); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned char stk%d;\n",i); fputs(defn,out); // Image_A = Temporary_ROP3 & Src & Pattern. // Image_B = Dest & Not Src. // Image_C = Dest & Not Pattern. // Return Image_A | Image_B | Image_C. fprintf(out," *D = (%s & (~S) & (~T)) | (*D & S) | (*D & T);\n",operand); fprintf(out,"}\n\n"); // ******** ROP transfer functions mk_xoperand(operand,sizeof(operand),stack,0); // case 1: source/pattern opaque. fprintf (out, "/* %s source/pattern opaque. */\n" "static unsigned xrop3_%d_0_0 (unsigned char s, unsigned char t)\n{\n", ropstr,irop); if (D_used) fprintf (out," unsigned D = 0x00ff;\n"); if (S_used) fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); if (T_used) fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned stk%d;\n",i); fputs(xdefn,out); fprintf(out," return %s;\n",operand); fprintf(out,"}\n\n"); // case 2: source opaque/pattern transparent. fprintf (out, "/* %s source opaque/pattern transparent. */\n" "static unsigned xrop3_%d_0_1 (unsigned char s, unsigned char t)\n{\n", ropstr,irop); fprintf (out," unsigned D = 0x00ff;\n"); fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned stk%d;\n",i); fputs(xdefn,out); // Image_A = Temporary_ROP3, & Not Src. // Image_B = Temporary_ROP3 & Pattern. // Image_C = Not Pattern & Src & Dest. // Return Image_A | Image_B | Image_C fprintf(out," return (%s & S) | (%s & (~T)) | (T & (~S) & D);\n",operand,operand); fprintf(out,"}\n\n"); // case 3: source transparent/pattern opaque. fprintf (out, "/* %s source transparent/pattern opaque. */\n" "static unsigned xrop3_%d_1_0 (unsigned char s, unsigned char t)\n{\n", ropstr,irop); fprintf (out," unsigned D = 0x00ff;\n"); fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); if (T_used) fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned stk%d;\n",i); fputs(xdefn,out); // Image_A = Temporary_ROP3 & Src. // Image_B = Dest & Not Src. // Return Image_A | Image_B fprintf(out," return (%s & (~S)) | (D & S);\n",operand); fprintf(out,"}\n\n"); // case 4: source/pattern transparent. fprintf (out, "/* %s source/pattern transparent. */\n" "static unsigned xrop3_%d_1_1 (unsigned char s, unsigned char t)\n{\n", ropstr,irop); fprintf (out," unsigned D = 0x00ff;\n"); fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); for (i=1;i<=max_stacksz;++i) fprintf(out," unsigned stk%d;\n",i); fputs(xdefn,out); // Image_A = Temporary_ROP3 & Src & Pattern. // Image_B = Dest & Not Src. // Image_C = Dest & Not Pattern. // Return Image_A | Image_B | Image_C. fprintf(out," return (%s & (~S) & (~T)) | (D & S) | (D & T);\n",operand); fprintf(out,"}\n\n"); return 0; } int main (int argc, const char *argv[]) { FILE *in=0; FILE *out=0; int irop=0,i; char ropstr[32]; int ret = 0; time_t now; if (argc != 3) { fprintf(stderr,"usage: %s <in> <out>.\n",argv[0]); return 1; } in = fopen(argv[1],"rb"); if (!in) { fprintf(stderr,"%s: Error opening file <%s>: %s.\n", argv[0],argv[1],strerror(errno)); ret = 1; goto cleanup; } out = fopen(argv[2],"wb"); if (!out) { fprintf(stderr,"%s: Error opening file <%s>: %s.\n", argv[0],argv[2],strerror(errno)); ret = 1; goto cleanup; } now = time(0); fprintf(out,"/* Generated automatically by %s at %.24s.\n",argv[0],ctime(&now)); fprintf(out," Do not edit!\n"); fprintf(out," */\n"); fprintf(out,"#include <hpgs.h>\n\n"); // go through all ROP descritions in hpgsrop.dat while (fscanf(in,"%d %31s",&i,ropstr) == 2) { if (i!=irop) { fprintf(stderr,"%s: Illegal count %d in stanza %d.\n", argv[0],i,irop); ret = 1; goto cleanup; } if (write_rop3_func(out,irop,ropstr)) goto cleanup; ++irop; } // Collect all rop function in one big lookup table... fprintf(out, "static hpgs_rop3_func_t rop3_table[][2][2] = {\n"); for (i=0;i<irop;++i) fprintf(out, " {{rop3_%d_0_0,rop3_%d_0_1},{rop3_%d_1_0,rop3_%d_1_1}}%s\n", i,i,i,i,i<irop-1 ? "," : ""); fprintf(out, "};\n\n"); // generate our public interface hpgs_rop3_func. fprintf(out, "hpgs_rop3_func_t hpgs_rop3_func(int rop3,\n" " hpgs_bool src_transparency,\n" " hpgs_bool pattern_transparency)\n" "{\n" " if (rop3 < 0 || rop3 >= %d) return 0;\n" " return rop3_table[rop3][src_transparency!=0][pattern_transparency!=0];\n" "}\n", irop); // Collect all rop xfer function in one big lookup table... fprintf(out, "static hpgs_xrop3_func_t xrop3_table[][2][2] = {\n"); for (i=0;i<irop;++i) fprintf(out, " {{xrop3_%d_0_0,xrop3_%d_0_1},{xrop3_%d_1_0,xrop3_%d_1_1}}%s\n", i,i,i,i,i<irop-1 ? "," : ""); fprintf(out, "};\n\n"); // generate our public interface hpgs_xrop3_func. fprintf(out, "hpgs_xrop3_func_t hpgs_xrop3_func(int rop3,\n" " hpgs_bool src_transparency,\n" " hpgs_bool pattern_transparency)\n" "{\n" " if (rop3 < 0 || rop3 >= %d) return 0;\n" " return xrop3_table[rop3][src_transparency!=0][pattern_transparency!=0];\n" "}\n", irop); cleanup: if (in) fclose(in); if (out) fclose(out); return ret; }
the_stack_data/86074845.c
#include <stdio.h> int main(){ short int a,b; // range at least 16-bits [-32768, 32767]✅ [0, 65535]; 4 byte =32 bits 2 byte = 16 A 16-bit integer can store 216 (or 65,536); 2^16=65536 scanf("%hi %hi",&a,&b); printf("a=%hi b=%hi \n\n",a,b); do { printf("%hi\t",a); //hi =singed intger; hu=unsigned =+ve a++; } while (a<=b); return 0; }
the_stack_data/89287.c
#include <stdio.h> #include <stdlib.h> void check_comment(char); void block_comment(); void single_comment(); FILE *from, *target; int main() { char c; char filename[100]; char targetfilename[100]; printf("Please enter the resource filename\n"); scanf("%s", filename); printf("Please enter the target filename\n"); scanf("%s", targetfilename); from = fopen(filename, "r"); target = fopen(targetfilename, "w"); while ((c = fgetc(from)) != EOF) check_comment(c); fclose(from); fclose(target); return 0; } void check_comment(char c) { char d; if (c == '/') { if ((d = fgetc(from)) == '*') { block_comment(); } else if (d == '/') { single_comment(); fputc('\n', target); } else { fputc(c, target); fputc(d, target); } } else fputc(c, target); } void block_comment() { char d, e; while ((d = fgetc(from)) != EOF) { if (d == '*') { e = fgetc(from); if (e == '/') return; } if (d == '/' && e == '*') { return; } } } void single_comment() { char d, e; while ((d = fgetc(from)) != EOF) { if (d == '\n') { return; } } }
the_stack_data/109832.c
// Copyright 2017 Capsule8, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <stdlib.h> #include <unistd.h> int main() { exit(EXIT_FAILURE); }
the_stack_data/68449.c
/* Exercise 1 - Calculations Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */ #include <stdio.h> int main() { int mark1,mark2; float avg; printf("Enter marks(subject1-)"); scanf("%d",&mark1); printf("Enter marks(subject2-)"); scanf("%d",&mark2); avg=(mark1+mark2)/2; printf("%f",avg); return 0; }
the_stack_data/20451533.c
#include<stdio.h> #include<string.h> unsigned char code[] = \ "\xeb\x16\x5e\x31\xc9\xb1\x0d\x8a\x06\x46\x8a\x26\x88\x06\x4e\x88\x26\x83\xc6\x02\xe2\xf1\xeb\x05\xe8\xe5\xff\xff\xff\xc0\x31\x68\x50\x2f\x2f\x68\x73\x2f\x68\x69\x62\x89\x6e\x50\xe3\xe2\x89\x89\x53\xb0\xe1\xcd\x0b\x90\x80" ; main() { printf("Shellcode Length: %d\n", strlen(code)); int (*ret)() = (int(*)())code; ret(); }
the_stack_data/146536.c
/* This file is obj-generic.c and is intended to be a template for object format specific source files. Copyright (C) 1987-1992 Free Software Foundation, Inc. This file is part of GAS, the GNU Assembler. GAS 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 2, or (at your option) any later version. GAS 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 GAS; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Chars that can be used to separate mant from exp in floating point nums */ char EXP_CHARS[] = "eE"; /* Chars that mean this number is a floating point constant */ /* As in 0f12.456 */ /* or 0d1.2345e12 */ char FLT_CHARS[] = "rRsSfFdDxXpP"; /* These chars start a comment anywhere in a source file (except inside another comment */ const char comment_chars[] = "#"; /* * Local Variables: * comment-column: 0 * fill-column: 131 * End: */ /* end of obj-generic.c */
the_stack_data/61075149.c
#define t(x,y,z) x ## y ## z int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), t(10,,), t(,11,), t(,,12), t(,,) };
the_stack_data/111078040.c
//Syed Saifuddin //L20410735 //Echo Server Program #include <stdio.h> #include <stdlib.h> #include<string.h> #include<sys/socket.h> #include<arpa/inet.h> int main(int argc , char *argv[]) { int sock; struct sockaddr_in server; char message[1000], reply[1000]; /*Create a Socket*/ sock = socket(AF_INET , SOCK_STREAM , 0); if (sock == -1) { printf("**SOCKET NOT CREATED**\n"); } else printf("**SOCKET READY**\n"); server.sin_addr.s_addr = inet_addr("127.0.0.1"); //IP Address server.sin_family = AF_INET; server.sin_port = htons(5004); //Port Number /*Establish Connection to Server*/ if( connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0) { printf("**CONNECTION ERROR**\n"); return 1; } else printf("**CONNECTED**\n"); /*Reading from input11.dat*/ FILE *fp; /* opening file for reading */ fp = fopen("input2.dat" , "r"); if(fp == NULL) { perror("**ERROR OPENING FILE**\n"); return(-1); } if( fgets (message,100, fp)!=NULL ) { /* writing content to stdout */ printf("Sending to Server:"); puts(message); } fclose(fp); /*Communicate with Server*/ /*Send your Message*/ if( send(sock , message , strlen(message) , 0) < 0) { printf("**Sending Error**\n"); return 1; } /*Reply from Server*/ if( recv(sock , reply , 2000 , 0) < 0) { printf("**Recieve Error**\n"); exit(0); // break; } printf("Server reply:%s\n ",reply); FILE *fp1 = fopen("output2.txt","w" ); if (fp1 != NULL) { fputs(reply, fp1); fclose(fp1); } close (sock); //Close the socket return 0; }
the_stack_data/243585.c
#include <stdio.h> #include <string.h> #include <stdlib.h> char retornaLetra(){ return 'a'; } int main(){ char letra; letra = retornaLetra(); printf("%c", letra); return 0; }
the_stack_data/765916.c
#include <stdlib.h> void recursive(int num, int N, int K, int *res, int *size) { if (N == 0) { res[(*size)++] = num; return; } if (num % 10 + K <= 9) recursive(num * 10 + num % 10 + K, N - 1, K, res, size); if (num % 10 - K >= 0 && K > 0) recursive(num * 10 + num % 10 - K, N - 1, K, res, size); } /** * Note: The returned array must be malloced, assume caller calls free(). */ int *numsSameConsecDiff(int n, int k, int *returnSize) { int *res = (int *)malloc(sizeof(int) * 2000); *returnSize = 0; if (n < 2) return NULL; for (int i = 1; i <= 9; ++i) recursive(i, n - 1, k, res, returnSize); return res; }
the_stack_data/181394259.c
#include <stdio.h> /* This is a comment. */ int main(int argc, char *argv[]) { int distance = 100; // this is also a comment printf("You are %d miles away.\n", distance); // Something more complex printf("This is %d complex stuff.\n", 1); return 0; }
the_stack_data/25555.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 75 int main( ) { int a[ N ]; int i = 0; int x; int y; while ( i < N ) { int k = i + 1; int s = i; while ( k < N ) { if ( a[k] < a[s] ) { s = k; } k = k+1; } if ( s != i ) { int tmp = a[s]; a[s] = a[i]; a[i] = tmp; } for ( x = 0 ; x < i ; x++ ) { for ( y = x + 1 ; y < i ; y++ ) { __VERIFIER_assert( a[x] <= a[y] ); } } for ( x = 0 ; x < N ; x++ ) { __VERIFIER_assert( a[x] >= a[i] ); } i = i+1; } for ( x = 0 ; x < N ; x++ ) { for ( y = x + 1 ; y < N ; y++ ) { __VERIFIER_assert( a[x] <= a[y] ); } } return 0; }
the_stack_data/45450303.c
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct node { int data; struct node * next; } node; const int BUFF = 256; node * llbuild(); node * addnode(node *, int); node * traverse(node *, int); int length(node *); void display(node *); int main() { node * head = NULL; head = llbuild(); // display(head); //pairwise swap node * cur, *prev; for(cur = head, prev = NULL; cur && cur->next; prev = cur->next, cur = cur->next->next) { node * tmp; tmp = cur->next; cur->next = cur->next->next; tmp->next = cur; cur = tmp; if(prev) prev->next = cur; else head = cur; } //display display(head); return 0; } void display(node * list) { node * new = list; while(new != NULL) { printf("%d -> ", new->data); new = new->next; } printf("NULL\n"); } node * traverse(node * list, int index) { node * cur = list; for(int i = 2; i <= index; i++) cur = cur->next; return cur; } int length(node * list) { int count = 1; node * cur = list; if(cur == NULL) return 0; while(cur->next != NULL) { cur = cur->next; count++; } return count; } node * addnode(node * list, int value) { node * end = traverse(list, length(list)); node * new = malloc(sizeof(node)); *new = (node){value, NULL}; if(end == NULL) list = new; else end->next = new; return list; } node * llbuild() { char * list = malloc(BUFF); scanf("%[^\n]", list); node * head = NULL; char * token = strtok(list, " "); while(token != NULL) { char * endptr = NULL; int val = strtol(token, &endptr, 10); if(!*endptr) head = addnode(head, val); token = strtok(NULL, " "); } return head; }
the_stack_data/178264770.c
#include<stdio.h> #include<stdlib.h> #include<stdbool.h> bool retornaBooleano(){ return true; } int main(){ //Definindo variáveis. bool variavelBooleana; //Variável ecebendo booleano. variavelBooleana = retornaBooleano(); //Se for verdadeiro executa o primeiro bloco. if(variavelBooleana){ printf("Eh verdadeiro!\n"); }//Senão executa o segundo bloco. else{ printf("Eh falso!\n"); } printf("%d\n", variavelBooleana); //Retorno da função. return 0; }
the_stack_data/444173.c
int x, x = 3, x; int main() { if (x != 3) return 0; x = 0; return x; }
the_stack_data/132952691.c
#include <stdio.h> #include <string.h> #include <stdbool.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> void decStr(char* str) { int len = strlen(str); for (int i=0; i<len; i++) { str[i] ^= 181; } } bool testPassword(char* attempt) { if (strlen(attempt) != 8) return false; char password[] = {197, 212, 198, 198, 194, 218, 199, 209}; decStr(attempt); for (int i=0; i < 8; i++) { if (attempt[i] != password[i]) return false; } return true; } void moved() { printf("Enter password: "); fflush(stdout); char buff[200]; fgets(buff, sizeof(buff), stdin); // get input buff[strlen(buff) - 1] = '\0'; // remove the newline if (testPassword(buff)) { puts("You win!"); } else { puts("You fail"); } exit(EXIT_SUCCESS); } int main(int argc, char** argv) { struct sigaction sigint = {}; sigint.sa_flags = SA_SIGINFO; sigint.sa_sigaction = moved; sigaction(SIGTRAP, &sigint, NULL); // send SIGTRAP kill(getpid(), SIGTRAP); puts("No debugging!"); }
the_stack_data/198579518.c
#define _GNU_SOURCE #include <sys/uio.h> #include <errno.h> #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <limits.h> int main(){ ssize_t nread; unsigned long nr_segs = 200; nread = splice(STDIN_FILENO, NULL, STDOUT_FILENO, NULL, INT_MAX, SPLICE_F_MOVE); if (-1 == nread) { printf("errno = %d\n", errno); perror("splice"); return 1; } return 0; }
the_stack_data/23576013.c
// Used to avoid llvm to optimize away extern void read(int); extern int unknown(); #define MAX_ARRAY 10 // To test loops int main(int argc, char **argv) { int i, j; int a[MAX_ARRAY][MAX_ARRAY]; for (i = 0; i < MAX_ARRAY; i++) { for (j = 0; j < MAX_ARRAY; j++) a[i][j + 1] = unknown(); } for (i = 0; i < MAX_ARRAY; i++) { read(a[i][i]); } return 42; }
the_stack_data/59512678.c
/* * (c) Copyright 1993, Silicon Graphics, Inc. * ALL RIGHTS RESERVED * Permission to use, copy, modify, and distribute this software for * any purpose and without fee is hereby granted, provided that the above * copyright notice appear in all copies and that both the copyright notice * and this permission notice appear in supporting documentation, and that * the name of Silicon Graphics, Inc. not be used in advertising * or publicity pertaining to distribution of the software without specific, * written prior permission. * * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. * * US Government Users Restricted Rights * Use, duplication, or disclosure by the Government is subject to * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph * (c)(1)(ii) of the Rights in Technical Data and Computer Software * clause at DFARS 252.227-7013 and/or in similar or successor * clauses in the FAR or the DOD or NASA FAR Supplement. * Unpublished-- rights reserved under the copyright laws of the * United States. Contractor/manufacturer is Silicon Graphics, * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. * * OpenGL(TM) is a trademark of Silicon Graphics, Inc. */ /* chess.c * This program texture maps a checkerboard image onto * two rectangles. The texture coordinates for the * rectangles are 0.0 to 3.0. */ #include <GL/gl.h> #include <GL/glu.h> #include <stdlib.h> #include <math.h> #define checkImageWidth 64 #define checkImageHeight 64 GLubyte checkImage[checkImageWidth][checkImageHeight][3]; void makecheckimage(void) { int i, j, r, c; for (i = 0; i < checkImageWidth; i++) { for (j = 0; j < checkImageHeight; j++) { c = ((((i&0x8)==0)^((j&0x8))==0))*255; checkImage[i][j][0] = (GLubyte) c; checkImage[i][j][1] = (GLubyte) c; checkImage[i][j][2] = (GLubyte) c; } } } void myinit(void) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); makecheckimage(); glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, &checkImage[0][0][0]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glEnable(GL_TEXTURE_2D); glShadeModel(GL_FLAT); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); glTexCoord2f(0.0, 3.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(3.0, 3.0); glVertex3f(0.0, 1.0, 0.0); glTexCoord2f(3.0, 0.0); glVertex3f(0.0, -1.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glTexCoord2f(0.0, 3.0); glVertex3f(1.0, 1.0, 0.0); glTexCoord2f(3.0, 3.0); glVertex3f(2.41421, 1.0, -1.41421); glTexCoord2f(3.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421); glEnd(); glFlush(); } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -3.6); } int gl_width=500; int gl_height=500; void render_image(void) { myinit(); myReshape(gl_width,gl_height); display(); }
the_stack_data/161080819.c
/* Tester for string functions. Copyright (C) 1995-2001, 2003, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif /* Make sure we don't test the optimized inline functions if we want to test the real implementation. */ #if !defined DO_STRING_INLINES #undef __USE_STRING_INLINES #endif #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <fcntl.h> #ifdef __UCLIBC__ # define __TEST_BSD_FUNCS__ #else # undef __TEST_BSD_FUNCS__ #endif #if defined(__UCLIBC_SUSV3_LEGACY__) || defined(__UCLIBC_SUSV3_LEGACY_MACROS__) # define __TEST_SUSV3_LEGACY__ #else # undef __TEST_SUSV3_LEGACY__ #endif #define STREQ(a, b) (strcmp((a), (b)) == 0) const char *it = "<UNSET>"; /* Routine name for message routines. */ size_t errors = 0; /* Complain if condition is not true. */ static void check (int thing, int number) { if (!thing) { printf("%s flunked test %d\n", it, number); ++errors; } } /* Complain if first two args don't strcmp as equal. */ static void equal (const char *a, const char *b, int number) { check(a != NULL && b != NULL && STREQ (a, b), number); } char one[50]; char two[50]; char *cp; static void test_strcmp (void) { it = "strcmp"; check (strcmp ("", "") == 0, 1); /* Trivial case. */ check (strcmp ("a", "a") == 0, 2); /* Identity. */ check (strcmp ("abc", "abc") == 0, 3); /* Multicharacter. */ check (strcmp ("abc", "abcd") < 0, 4); /* Length mismatches. */ check (strcmp ("abcd", "abc") > 0, 5); check (strcmp ("abcd", "abce") < 0, 6); /* Honest miscompares. */ check (strcmp ("abce", "abcd") > 0, 7); check (strcmp ("a\203", "a") > 0, 8); /* Tricky if char signed. */ check (strcmp ("a\203", "a\003") > 0, 9); { char buf1[0x40], buf2[0x40]; int i, j; for (i=0; i < 0x10; i++) for (j = 0; j < 0x10; j++) { int k; for (k = 0; k < 0x3f; k++) { buf1[k] = '0' ^ (k & 4); buf2[k] = '4' ^ (k & 4); } buf1[i] = buf1[0x3f] = 0; buf2[j] = buf2[0x3f] = 0; for (k = 0; k < 0xf; k++) { int cnum = 0x10+0x10*k+0x100*j+0x1000*i; check (strcmp (buf1+i,buf2+j) == 0, cnum); buf1[i+k] = 'A' + i + k; buf1[i+k+1] = 0; check (strcmp (buf1+i,buf2+j) > 0, cnum+1); check (strcmp (buf2+j,buf1+i) < 0, cnum+2); buf2[j+k] = 'B' + i + k; buf2[j+k+1] = 0; check (strcmp (buf1+i,buf2+j) < 0, cnum+3); check (strcmp (buf2+j,buf1+i) > 0, cnum+4); buf2[j+k] = 'A' + i + k; buf1[i] = 'A' + i + 0x80; check (strcmp (buf1+i,buf2+j) > 0, cnum+5); check (strcmp (buf2+j,buf1+i) < 0, cnum+6); buf1[i] = 'A' + i; } } } } #define SIMPLE_COPY(fn, n, str, ntest) \ do { \ int __n; \ for (__n = 0; __n < (int) sizeof (one); ++__n) \ one[__n] = 'Z'; \ fn (one, str); \ for (cp = one, __n = 0; __n < n; ++__n, ++cp) \ check (*cp == '0' + (n % 10), ntest); \ check (*cp == '\0', ntest); \ } while (0) static void test_strcpy (void) { int i; it = "strcpy"; check (strcpy (one, "abcd") == one, 1); /* Returned value. */ equal (one, "abcd", 2); /* Basic test. */ (void) strcpy (one, "x"); equal (one, "x", 3); /* Writeover. */ equal (one+2, "cd", 4); /* Wrote too much? */ (void) strcpy (two, "hi there"); (void) strcpy (one, two); equal (one, "hi there", 5); /* Basic test encore. */ equal (two, "hi there", 6); /* Stomped on source? */ (void) strcpy (one, ""); equal (one, "", 7); /* Boundary condition. */ for (i = 0; i < 16; i++) { (void) strcpy (one + i, "hi there"); /* Unaligned destination. */ equal (one + i, "hi there", 8 + (i * 2)); (void) strcpy (two, one + i); /* Unaligned source. */ equal (two, "hi there", 9 + (i * 2)); } SIMPLE_COPY(strcpy, 0, "", 41); SIMPLE_COPY(strcpy, 1, "1", 42); SIMPLE_COPY(strcpy, 2, "22", 43); SIMPLE_COPY(strcpy, 3, "333", 44); SIMPLE_COPY(strcpy, 4, "4444", 45); SIMPLE_COPY(strcpy, 5, "55555", 46); SIMPLE_COPY(strcpy, 6, "666666", 47); SIMPLE_COPY(strcpy, 7, "7777777", 48); SIMPLE_COPY(strcpy, 8, "88888888", 49); SIMPLE_COPY(strcpy, 9, "999999999", 50); SIMPLE_COPY(strcpy, 10, "0000000000", 51); SIMPLE_COPY(strcpy, 11, "11111111111", 52); SIMPLE_COPY(strcpy, 12, "222222222222", 53); SIMPLE_COPY(strcpy, 13, "3333333333333", 54); SIMPLE_COPY(strcpy, 14, "44444444444444", 55); SIMPLE_COPY(strcpy, 15, "555555555555555", 56); SIMPLE_COPY(strcpy, 16, "6666666666666666", 57); /* Simple test using implicitly coerced `void *' arguments. */ const void *src = "frobozz"; void *dst = one; check (strcpy (dst, src) == dst, 1); equal (dst, "frobozz", 2); } static void test_stpcpy (void) { it = "stpcpy"; check ((stpcpy (one, "a") - one) == 1, 1); equal (one, "a", 2); check ((stpcpy (one, "ab") - one) == 2, 3); equal (one, "ab", 4); check ((stpcpy (one, "abc") - one) == 3, 5); equal (one, "abc", 6); check ((stpcpy (one, "abcd") - one) == 4, 7); equal (one, "abcd", 8); check ((stpcpy (one, "abcde") - one) == 5, 9); equal (one, "abcde", 10); check ((stpcpy (one, "abcdef") - one) == 6, 11); equal (one, "abcdef", 12); check ((stpcpy (one, "abcdefg") - one) == 7, 13); equal (one, "abcdefg", 14); check ((stpcpy (one, "abcdefgh") - one) == 8, 15); equal (one, "abcdefgh", 16); check ((stpcpy (one, "abcdefghi") - one) == 9, 17); equal (one, "abcdefghi", 18); check ((stpcpy (one, "x") - one) == 1, 19); equal (one, "x", 20); /* Writeover. */ equal (one+2, "cdefghi", 21); /* Wrote too much? */ check ((stpcpy (one, "xx") - one) == 2, 22); equal (one, "xx", 23); /* Writeover. */ equal (one+3, "defghi", 24); /* Wrote too much? */ check ((stpcpy (one, "xxx") - one) == 3, 25); equal (one, "xxx", 26); /* Writeover. */ equal (one+4, "efghi", 27); /* Wrote too much? */ check ((stpcpy (one, "xxxx") - one) == 4, 28); equal (one, "xxxx", 29); /* Writeover. */ equal (one+5, "fghi", 30); /* Wrote too much? */ check ((stpcpy (one, "xxxxx") - one) == 5, 31); equal (one, "xxxxx", 32); /* Writeover. */ equal (one+6, "ghi", 33); /* Wrote too much? */ check ((stpcpy (one, "xxxxxx") - one) == 6, 34); equal (one, "xxxxxx", 35); /* Writeover. */ equal (one+7, "hi", 36); /* Wrote too much? */ check ((stpcpy (one, "xxxxxxx") - one) == 7, 37); equal (one, "xxxxxxx", 38); /* Writeover. */ equal (one+8, "i", 39); /* Wrote too much? */ check ((stpcpy (stpcpy (stpcpy (one, "a"), "b"), "c") - one) == 3, 40); equal (one, "abc", 41); equal (one + 4, "xxx", 42); SIMPLE_COPY(stpcpy, 0, "", 43); SIMPLE_COPY(stpcpy, 1, "1", 44); SIMPLE_COPY(stpcpy, 2, "22", 45); SIMPLE_COPY(stpcpy, 3, "333", 46); SIMPLE_COPY(stpcpy, 4, "4444", 47); SIMPLE_COPY(stpcpy, 5, "55555", 48); SIMPLE_COPY(stpcpy, 6, "666666", 49); SIMPLE_COPY(stpcpy, 7, "7777777", 50); SIMPLE_COPY(stpcpy, 8, "88888888", 51); SIMPLE_COPY(stpcpy, 9, "999999999", 52); SIMPLE_COPY(stpcpy, 10, "0000000000", 53); SIMPLE_COPY(stpcpy, 11, "11111111111", 54); SIMPLE_COPY(stpcpy, 12, "222222222222", 55); SIMPLE_COPY(stpcpy, 13, "3333333333333", 56); SIMPLE_COPY(stpcpy, 14, "44444444444444", 57); SIMPLE_COPY(stpcpy, 15, "555555555555555", 58); SIMPLE_COPY(stpcpy, 16, "6666666666666666", 59); } static void test_stpncpy (void) { it = "stpncpy"; memset (one, 'x', sizeof (one)); check (stpncpy (one, "abc", 2) == one + 2, 1); check (stpncpy (one, "abc", 3) == one + 3, 2); check (stpncpy (one, "abc", 4) == one + 3, 3); check (one[3] == '\0' && one[4] == 'x', 4); check (stpncpy (one, "abcd", 5) == one + 4, 5); check (one[4] == '\0' && one[5] == 'x', 6); check (stpncpy (one, "abcd", 6) == one + 4, 7); check (one[4] == '\0' && one[5] == '\0' && one[6] == 'x', 8); } static void test_strcat (void) { it = "strcat"; (void) strcpy (one, "ijk"); check (strcat (one, "lmn") == one, 1); /* Returned value. */ equal (one, "ijklmn", 2); /* Basic test. */ (void) strcpy (one, "x"); (void) strcat (one, "yz"); equal (one, "xyz", 3); /* Writeover. */ equal (one+4, "mn", 4); /* Wrote too much? */ (void) strcpy (one, "gh"); (void) strcpy (two, "ef"); (void) strcat (one, two); equal (one, "ghef", 5); /* Basic test encore. */ equal (two, "ef", 6); /* Stomped on source? */ (void) strcpy (one, ""); (void) strcat (one, ""); equal (one, "", 7); /* Boundary conditions. */ (void) strcpy (one, "ab"); (void) strcat (one, ""); equal (one, "ab", 8); (void) strcpy (one, ""); (void) strcat (one, "cd"); equal (one, "cd", 9); } static void test_strncat (void) { /* First test it as strcat, with big counts, then test the count mechanism. */ it = "strncat"; (void) strcpy (one, "ijk"); check (strncat (one, "lmn", 99) == one, 1); /* Returned value. */ equal (one, "ijklmn", 2); /* Basic test. */ (void) strcpy (one, "x"); (void) strncat (one, "yz", 99); equal (one, "xyz", 3); /* Writeover. */ equal (one+4, "mn", 4); /* Wrote too much? */ (void) strcpy (one, "gh"); (void) strcpy (two, "ef"); (void) strncat (one, two, 99); equal (one, "ghef", 5); /* Basic test encore. */ equal (two, "ef", 6); /* Stomped on source? */ (void) strcpy (one, ""); (void) strncat (one, "", 99); equal (one, "", 7); /* Boundary conditions. */ (void) strcpy (one, "ab"); (void) strncat (one, "", 99); equal (one, "ab", 8); (void) strcpy (one, ""); (void) strncat (one, "cd", 99); equal (one, "cd", 9); (void) strcpy (one, "ab"); (void) strncat (one, "cdef", 2); equal (one, "abcd", 10); /* Count-limited. */ (void) strncat (one, "gh", 0); equal (one, "abcd", 11); /* Zero count. */ (void) strncat (one, "gh", 2); equal (one, "abcdgh", 12); /* Count and length equal. */ (void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */ equal (one, "abcdghij", 13); } static void test_strlcat (void) { #ifdef __TEST_BSD_FUNCS__ /* First test it as strcat, with big counts, then test the count mechanism. */ it = "strlcat"; (void) strcpy (one, "ijk"); check (strlcat (one, "lmn", 99) == 6, 1); /* Returned value. */ equal (one, "ijklmn", 2); /* Basic test. */ (void) strcpy (one, "x"); (void) strlcat (one, "yz", 99); equal (one, "xyz", 3); /* Writeover. */ equal (one+4, "mn", 4); /* Wrote too much? */ (void) strcpy (one, "gh"); (void) strcpy (two, "ef"); (void) strlcat (one, two, 99); equal (one, "ghef", 5); /* Basic test encore. */ equal (two, "ef", 6); /* Stomped on source? */ (void) strcpy (one, ""); (void) strlcat (one, "", 99); equal (one, "", 7); /* Boundary conditions. */ (void) strcpy (one, "ab"); (void) strlcat (one, "", 99); equal (one, "ab", 8); (void) strcpy (one, ""); (void) strlcat (one, "cd", 99); equal (one, "cd", 9); (void) strcpy (one, "ab"); (void) strlcat (one, "cdef", 2); equal (one, "ab", 10); /* Count-limited. */ (void) strlcat (one, "gh", 0); equal (one, "ab", 11); /* Zero count. */ (void) strlcat (one, "gh", 4); equal (one, "abg", 12); /* Count and length equal. */ (void) strlcat (one, "ij", (size_t)-1); /* set sign bit in count */ equal (one, "abgij", 13); #endif } static void test_strncmp (void) { /* First test as strcmp with big counts, then test count code. */ it = "strncmp"; check (strncmp ("", "", 99) == 0, 1); /* Trivial case. */ check (strncmp ("a", "a", 99) == 0, 2); /* Identity. */ check (strncmp ("abc", "abc", 99) == 0, 3); /* Multicharacter. */ check (strncmp ("abc", "abcd", 99) < 0, 4); /* Length unequal. */ check (strncmp ("abcd", "abc", 99) > 0, 5); check (strncmp ("abcd", "abce", 99) < 0, 6); /* Honestly unequal. */ check (strncmp ("abce", "abcd", 99) > 0, 7); check (strncmp ("a\203", "a", 2) > 0, 8); /* Tricky if '\203' < 0 */ check (strncmp ("a\203", "a\003", 2) > 0, 9); check (strncmp ("abce", "abcd", 3) == 0, 10); /* Count limited. */ check (strncmp ("abce", "abc", 3) == 0, 11); /* Count == length. */ check (strncmp ("abcd", "abce", 4) < 0, 12); /* Nudging limit. */ check (strncmp ("abc", "def", 0) == 0, 13); /* Zero count. */ check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */ check (strncmp ("abc", "abc", (size_t)-2) == 0, 15); } static void test_strncpy (void) { /* Testing is a bit different because of odd semantics. */ it = "strncpy"; check (strncpy (one, "abc", 4) == one, 1); /* Returned value. */ equal (one, "abc", 2); /* Did the copy go right? */ (void) strcpy (one, "abcdefgh"); (void) strncpy (one, "xyz", 2); equal (one, "xycdefgh", 3); /* Copy cut by count. */ (void) strcpy (one, "abcdefgh"); (void) strncpy (one, "xyz", 3); /* Copy cut just before NUL. */ equal (one, "xyzdefgh", 4); (void) strcpy (one, "abcdefgh"); (void) strncpy (one, "xyz", 4); /* Copy just includes NUL. */ equal (one, "xyz", 5); equal (one+4, "efgh", 6); /* Wrote too much? */ (void) strcpy (one, "abcdefgh"); (void) strncpy (one, "xyz", 5); /* Copy includes padding. */ equal (one, "xyz", 7); equal (one+4, "", 8); equal (one+5, "fgh", 9); (void) strcpy (one, "abc"); (void) strncpy (one, "xyz", 0); /* Zero-length copy. */ equal (one, "abc", 10); (void) strncpy (one, "", 2); /* Zero-length source. */ equal (one, "", 11); equal (one+1, "", 12); equal (one+2, "c", 13); (void) strcpy (one, "hi there"); (void) strncpy (two, one, 9); equal (two, "hi there", 14); /* Just paranoia. */ equal (one, "hi there", 15); /* Stomped on source? */ } static void test_strlcpy (void) { #ifdef __TEST_BSD_FUNCS__ /* Testing is a bit different because of odd semantics. */ it = "strlcpy"; check (strlcpy (one, "abc", sizeof(one)) == 3, 1); /* Returned value. */ equal (one, "abc", 2); /* Did the copy go right? */ (void) strcpy (one, "abcdefgh"); (void) strlcpy (one, "xyz", 2); equal (one, "x\0cdefgh", 3); /* Copy cut by count. */ (void) strcpy (one, "abcdefgh"); (void) strlcpy (one, "xyz", 3); /* Copy cut just before NUL. */ equal (one, "xy\0defgh", 4); (void) strcpy (one, "abcdefgh"); (void) strlcpy (one, "xyz", 4); /* Copy just includes NUL. */ equal (one, "xyz", 5); equal (one+4, "efgh", 6); /* Wrote too much? */ (void) strcpy (one, "abcdefgh"); (void) strlcpy (one, "xyz", 5); /* Copy includes padding. */ equal (one, "xyz", 7); equal (one+3, "", 8); equal (one+4, "efgh", 9); (void) strcpy (one, "abc"); (void) strlcpy (one, "xyz", 0); /* Zero-length copy. */ equal (one, "abc", 10); (void) strlcpy (one, "", 2); /* Zero-length source. */ equal (one, "", 11); equal (one+1, "bc", 12); equal (one+2, "c", 13); (void) strcpy (one, "hi there"); (void) strlcpy (two, one, 9); equal (two, "hi there", 14); /* Just paranoia. */ equal (one, "hi there", 15); /* Stomped on source? */ #endif } static void test_strlen (void) { it = "strlen"; check (strlen ("") == 0, 1); /* Empty. */ check (strlen ("a") == 1, 2); /* Single char. */ check (strlen ("abcd") == 4, 3); /* Multiple chars. */ { char buf[4096]; int i; char *p; for (i=0; i < 0x100; i++) { p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i; strcpy (p, "OK"); strcpy (p+3, "BAD/WRONG"); check (strlen (p) == 2, 4+i); } } } static void test_strnlen (void) { it = "strnlen"; check (strnlen ("", 10) == 0, 1); /* Empty. */ check (strnlen ("a", 10) == 1, 2); /* Single char. */ check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */ check (strnlen ("foo", (size_t)-1) == 3, 4); /* limits of n. */ { char buf[4096]; int i; char *p; for (i=0; i < 0x100; i++) { p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i; strcpy (p, "OK"); strcpy (p+3, "BAD/WRONG"); check (strnlen (p, 100) == 2, 5+i); } } } static void test_strchr (void) { it = "strchr"; check (strchr ("abcd", 'z') == NULL, 1); /* Not found. */ (void) strcpy (one, "abcd"); check (strchr (one, 'c') == one+2, 2); /* Basic test. */ check (strchr (one, 'd') == one+3, 3); /* End of string. */ check (strchr (one, 'a') == one, 4); /* Beginning. */ check (strchr (one, '\0') == one+4, 5); /* Finding NUL. */ (void) strcpy (one, "ababa"); check (strchr (one, 'b') == one+1, 6); /* Finding first. */ (void) strcpy (one, ""); check (strchr (one, 'b') == NULL, 7); /* Empty string. */ check (strchr (one, '\0') == one, 8); /* NUL in empty string. */ { char buf[4096]; int i; char *p; for (i=0; i < 0x100; i++) { p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; strcpy (p, "OK"); strcpy (p+3, "BAD/WRONG"); check (strchr (p, '/') == NULL, 9+i); } } } static void test_strchrnul (void) { const char *os; it = "strchrnul"; cp = strchrnul ((os = "abcd"), 'z'); check (*cp == '\0', 1); /* Not found. */ check (cp == os + 4, 2); (void) strcpy (one, "abcd"); check (strchrnul (one, 'c') == one+2, 3); /* Basic test. */ check (strchrnul (one, 'd') == one+3, 4); /* End of string. */ check (strchrnul (one, 'a') == one, 5); /* Beginning. */ check (strchrnul (one, '\0') == one+4, 6); /* Finding NUL. */ (void) strcpy (one, "ababa"); check (strchrnul (one, 'b') == one+1, 7); /* Finding first. */ (void) strcpy (one, ""); check (strchrnul (one, 'b') == one, 8); /* Empty string. */ check (strchrnul (one, '\0') == one, 9); /* NUL in empty string. */ { char buf[4096]; int i; char *p; for (i=0; i < 0x100; i++) { p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; strcpy (p, "OK"); strcpy (p+3, "BAD/WRONG"); cp = strchrnul (p, '/'); check (*cp == '\0', 9+2*i); check (cp == p+2, 10+2*i); } } } static void test_rawmemchr (void) { it = "rawmemchr"; (void) strcpy (one, "abcd"); check (rawmemchr (one, 'c') == one+2, 1); /* Basic test. */ check (rawmemchr (one, 'd') == one+3, 2); /* End of string. */ check (rawmemchr (one, 'a') == one, 3); /* Beginning. */ check (rawmemchr (one, '\0') == one+4, 4); /* Finding NUL. */ (void) strcpy (one, "ababa"); check (rawmemchr (one, 'b') == one+1, 5); /* Finding first. */ (void) strcpy (one, ""); check (rawmemchr (one, '\0') == one, 6); /* NUL in empty string. */ { char buf[4096]; int i; char *p; for (i=0; i < 0x100; i++) { p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; strcpy (p, "OK"); strcpy (p+3, "BAD/WRONG"); check (rawmemchr (p, 'R') == p+8, 6+i); } } } static void test_index (void) { #ifdef __TEST_SUSV3_LEGACY__ it = "index"; check (index ("abcd", 'z') == NULL, 1); /* Not found. */ (void) strcpy (one, "abcd"); check (index (one, 'c') == one+2, 2); /* Basic test. */ check (index (one, 'd') == one+3, 3); /* End of string. */ check (index (one, 'a') == one, 4); /* Beginning. */ check (index (one, '\0') == one+4, 5); /* Finding NUL. */ (void) strcpy (one, "ababa"); check (index (one, 'b') == one+1, 6); /* Finding first. */ (void) strcpy (one, ""); check (index (one, 'b') == NULL, 7); /* Empty string. */ check (index (one, '\0') == one, 8); /* NUL in empty string. */ #endif } static void test_strrchr (void) { it = "strrchr"; check (strrchr ("abcd", 'z') == NULL, 1); /* Not found. */ (void) strcpy (one, "abcd"); check (strrchr (one, 'c') == one+2, 2); /* Basic test. */ check (strrchr (one, 'd') == one+3, 3); /* End of string. */ check (strrchr (one, 'a') == one, 4); /* Beginning. */ check (strrchr (one, '\0') == one+4, 5); /* Finding NUL. */ (void) strcpy (one, "ababa"); check (strrchr (one, 'b') == one+3, 6); /* Finding last. */ (void) strcpy (one, ""); check (strrchr (one, 'b') == NULL, 7); /* Empty string. */ check (strrchr (one, '\0') == one, 8); /* NUL in empty string. */ { char buf[4096]; int i; char *p; for (i=0; i < 0x100; i++) { p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; strcpy (p, "OK"); strcpy (p+3, "BAD/WRONG"); check (strrchr (p, '/') == NULL, 9+i); } } } static void test_memrchr (void) { size_t l; it = "memrchr"; check (memrchr ("abcd", 'z', 5) == NULL, 1); /* Not found. */ (void) strcpy (one, "abcd"); l = strlen (one) + 1; check (memrchr (one, 'c', l) == one+2, 2); /* Basic test. */ check (memrchr (one, 'd', l) == one+3, 3); /* End of string. */ check (memrchr (one, 'a', l) == one, 4); /* Beginning. */ check (memrchr (one, '\0', l) == one+4, 5); /* Finding NUL. */ (void) strcpy (one, "ababa"); l = strlen (one) + 1; check (memrchr (one, 'b', l) == one+3, 6); /* Finding last. */ (void) strcpy (one, ""); l = strlen (one) + 1; check (memrchr (one, 'b', l) == NULL, 7); /* Empty string. */ check (memrchr (one, '\0', l) == one, 8); /* NUL in empty string. */ /* now test all possible alignment and length combinations to catch bugs due to unrolled loops (assuming unrolling is limited to no more than 128 byte chunks: */ { char buf[128 + sizeof(long)]; long align, len, i, pos; for (align = 0; align < (long) sizeof(long); ++align) { for (len = 0; len < (long) (sizeof(buf) - align); ++len) { for (i = 0; i < len; ++i) buf[align + i] = 'x'; /* don't depend on memset... */ for (pos = len - 1; pos >= 0; --pos) { #if 0 printf("align %d, len %d, pos %d\n", align, len, pos); #endif check(memrchr(buf + align, 'x', len) == buf + align + pos, 9); check(memrchr(buf + align + pos + 1, 'x', len - (pos + 1)) == NULL, 10); buf[align + pos] = '-'; } } } } } static void test_rindex (void) { #ifdef __TEST_SUSV3_LEGACY__ it = "rindex"; check (rindex ("abcd", 'z') == NULL, 1); /* Not found. */ (void) strcpy (one, "abcd"); check (rindex (one, 'c') == one+2, 2); /* Basic test. */ check (rindex (one, 'd') == one+3, 3); /* End of string. */ check (rindex (one, 'a') == one, 4); /* Beginning. */ check (rindex (one, '\0') == one+4, 5); /* Finding NUL. */ (void) strcpy (one, "ababa"); check (rindex (one, 'b') == one+3, 6); /* Finding last. */ (void) strcpy (one, ""); check (rindex (one, 'b') == NULL, 7); /* Empty string. */ check (rindex (one, '\0') == one, 8); /* NUL in empty string. */ #endif } static void test_strpbrk (void) { it = "strpbrk"; check(strpbrk("abcd", "z") == NULL, 1); /* Not found. */ (void) strcpy(one, "abcd"); check(strpbrk(one, "c") == one+2, 2); /* Basic test. */ check(strpbrk(one, "d") == one+3, 3); /* End of string. */ check(strpbrk(one, "a") == one, 4); /* Beginning. */ check(strpbrk(one, "") == NULL, 5); /* Empty search list. */ check(strpbrk(one, "cb") == one+1, 6); /* Multiple search. */ (void) strcpy(one, "abcabdea"); check(strpbrk(one, "b") == one+1, 7); /* Finding first. */ check(strpbrk(one, "cb") == one+1, 8); /* With multiple search. */ check(strpbrk(one, "db") == one+1, 9); /* Another variant. */ (void) strcpy(one, ""); check(strpbrk(one, "bc") == NULL, 10); /* Empty string. */ (void) strcpy(one, ""); check(strpbrk(one, "bcd") == NULL, 11); /* Empty string. */ (void) strcpy(one, ""); check(strpbrk(one, "bcde") == NULL, 12); /* Empty string. */ check(strpbrk(one, "") == NULL, 13); /* Both strings empty. */ (void) strcpy(one, "abcabdea"); check(strpbrk(one, "befg") == one+1, 14); /* Finding first. */ check(strpbrk(one, "cbr") == one+1, 15); /* With multiple search. */ check(strpbrk(one, "db") == one+1, 16); /* Another variant. */ check(strpbrk(one, "efgh") == one+6, 17); /* And yet another. */ } static void test_strstr (void) { it = "strstr"; check(strstr("abcd", "z") == NULL, 1); /* Not found. */ check(strstr("abcd", "abx") == NULL, 2); /* Dead end. */ (void) strcpy(one, "abcd"); check(strstr(one, "c") == one+2, 3); /* Basic test. */ check(strstr(one, "bc") == one+1, 4); /* Multichar. */ check(strstr(one, "d") == one+3, 5); /* End of string. */ check(strstr(one, "cd") == one+2, 6); /* Tail of string. */ check(strstr(one, "abc") == one, 7); /* Beginning. */ check(strstr(one, "abcd") == one, 8); /* Exact match. */ check(strstr(one, "abcde") == NULL, 9); /* Too long. */ check(strstr(one, "de") == NULL, 10); /* Past end. */ check(strstr(one, "") == one, 11); /* Finding empty. */ (void) strcpy(one, "ababa"); check(strstr(one, "ba") == one+1, 12); /* Finding first. */ (void) strcpy(one, ""); check(strstr(one, "b") == NULL, 13); /* Empty string. */ check(strstr(one, "") == one, 14); /* Empty in empty string. */ (void) strcpy(one, "bcbca"); check(strstr(one, "bca") == one+2, 15); /* False start. */ (void) strcpy(one, "bbbcabbca"); check(strstr(one, "bbca") == one+1, 16); /* With overlap. */ } static void test_strspn (void) { it = "strspn"; check(strspn("abcba", "abc") == 5, 1); /* Whole string. */ check(strspn("abcba", "ab") == 2, 2); /* Partial. */ check(strspn("abc", "qx") == 0, 3); /* None. */ check(strspn("", "ab") == 0, 4); /* Null string. */ check(strspn("abc", "") == 0, 5); /* Null search list. */ } static void test_strcspn (void) { it = "strcspn"; check(strcspn("abcba", "qx") == 5, 1); /* Whole string. */ check(strcspn("abcba", "cx") == 2, 2); /* Partial. */ check(strcspn("abc", "abc") == 0, 3); /* None. */ check(strcspn("", "ab") == 0, 4); /* Null string. */ check(strcspn("abc", "") == 3, 5); /* Null search list. */ } static void test_strtok (void) { it = "strtok"; (void) strcpy(one, "first, second, third"); equal(strtok(one, ", "), "first", 1); /* Basic test. */ equal(one, "first", 2); equal(strtok((char *)NULL, ", "), "second", 3); equal(strtok((char *)NULL, ", "), "third", 4); check(strtok((char *)NULL, ", ") == NULL, 5); (void) strcpy(one, ", first, "); equal(strtok(one, ", "), "first", 6); /* Extra delims, 1 tok. */ check(strtok((char *)NULL, ", ") == NULL, 7); (void) strcpy(one, "1a, 1b; 2a, 2b"); equal(strtok(one, ", "), "1a", 8); /* Changing delim lists. */ equal(strtok((char *)NULL, "; "), "1b", 9); equal(strtok((char *)NULL, ", "), "2a", 10); (void) strcpy(two, "x-y"); equal(strtok(two, "-"), "x", 11); /* New string before done. */ equal(strtok((char *)NULL, "-"), "y", 12); check(strtok((char *)NULL, "-") == NULL, 13); (void) strcpy(one, "a,b, c,, ,d"); equal(strtok(one, ", "), "a", 14); /* Different separators. */ equal(strtok((char *)NULL, ", "), "b", 15); equal(strtok((char *)NULL, " ,"), "c", 16); /* Permute list too. */ equal(strtok((char *)NULL, " ,"), "d", 17); check(strtok((char *)NULL, ", ") == NULL, 18); check(strtok((char *)NULL, ", ") == NULL, 19); /* Persistence. */ (void) strcpy(one, ", "); check(strtok(one, ", ") == NULL, 20); /* No tokens. */ (void) strcpy(one, ""); check(strtok(one, ", ") == NULL, 21); /* Empty string. */ (void) strcpy(one, "abc"); equal(strtok(one, ", "), "abc", 22); /* No delimiters. */ check(strtok((char *)NULL, ", ") == NULL, 23); (void) strcpy(one, "abc"); equal(strtok(one, ""), "abc", 24); /* Empty delimiter list. */ check(strtok((char *)NULL, "") == NULL, 25); (void) strcpy(one, "abcdefgh"); (void) strcpy(one, "a,b,c"); equal(strtok(one, ","), "a", 26); /* Basics again... */ equal(strtok((char *)NULL, ","), "b", 27); equal(strtok((char *)NULL, ","), "c", 28); check(strtok((char *)NULL, ",") == NULL, 29); equal(one+6, "gh", 30); /* Stomped past end? */ equal(one, "a", 31); /* Stomped old tokens? */ equal(one+2, "b", 32); equal(one+4, "c", 33); } static void test_strtok_r (void) { it = "strtok_r"; (void) strcpy(one, "first, second, third"); cp = NULL; /* Always initialize cp to make sure it doesn't point to some old data. */ equal(strtok_r(one, ", ", &cp), "first", 1); /* Basic test. */ equal(one, "first", 2); equal(strtok_r((char *)NULL, ", ", &cp), "second", 3); equal(strtok_r((char *)NULL, ", ", &cp), "third", 4); check(strtok_r((char *)NULL, ", ", &cp) == NULL, 5); (void) strcpy(one, ", first, "); cp = NULL; equal(strtok_r(one, ", ", &cp), "first", 6); /* Extra delims, 1 tok. */ check(strtok_r((char *)NULL, ", ", &cp) == NULL, 7); (void) strcpy(one, "1a, 1b; 2a, 2b"); cp = NULL; equal(strtok_r(one, ", ", &cp), "1a", 8); /* Changing delim lists. */ equal(strtok_r((char *)NULL, "; ", &cp), "1b", 9); equal(strtok_r((char *)NULL, ", ", &cp), "2a", 10); (void) strcpy(two, "x-y"); cp = NULL; equal(strtok_r(two, "-", &cp), "x", 11); /* New string before done. */ equal(strtok_r((char *)NULL, "-", &cp), "y", 12); check(strtok_r((char *)NULL, "-", &cp) == NULL, 13); (void) strcpy(one, "a,b, c,, ,d"); cp = NULL; equal(strtok_r(one, ", ", &cp), "a", 14); /* Different separators. */ equal(strtok_r((char *)NULL, ", ", &cp), "b", 15); equal(strtok_r((char *)NULL, " ,", &cp), "c", 16); /* Permute list too. */ equal(strtok_r((char *)NULL, " ,", &cp), "d", 17); check(strtok_r((char *)NULL, ", ", &cp) == NULL, 18); check(strtok_r((char *)NULL, ", ", &cp) == NULL, 19); /* Persistence. */ (void) strcpy(one, ", "); cp = NULL; check(strtok_r(one, ", ", &cp) == NULL, 20); /* No tokens. */ (void) strcpy(one, ""); cp = NULL; check(strtok_r(one, ", ", &cp) == NULL, 21); /* Empty string. */ check(strtok_r((char *)NULL, ", ", &cp) == NULL, 22); /* Persistence. */ (void) strcpy(one, "abc"); cp = NULL; equal(strtok_r(one, ", ", &cp), "abc", 23); /* No delimiters. */ check(strtok_r((char *)NULL, ", ", &cp) == NULL, 24); (void) strcpy(one, "abc"); cp = NULL; equal(strtok_r(one, "", &cp), "abc", 25); /* Empty delimiter list. */ check(strtok_r((char *)NULL, "", &cp) == NULL, 26); (void) strcpy(one, "abcdefgh"); (void) strcpy(one, "a,b,c"); cp = NULL; equal(strtok_r(one, ",", &cp), "a", 27); /* Basics again... */ equal(strtok_r((char *)NULL, ",", &cp), "b", 28); equal(strtok_r((char *)NULL, ",", &cp), "c", 29); check(strtok_r((char *)NULL, ",", &cp) == NULL, 30); equal(one+6, "gh", 31); /* Stomped past end? */ equal(one, "a", 32); /* Stomped old tokens? */ equal(one+2, "b", 33); equal(one+4, "c", 34); } static void test_strsep (void) { char *ptr; it = "strsep"; cp = strcpy(one, "first, second, third"); equal(strsep(&cp, ", "), "first", 1); /* Basic test. */ equal(one, "first", 2); equal(strsep(&cp, ", "), "", 3); equal(strsep(&cp, ", "), "second", 4); equal(strsep(&cp, ", "), "", 5); equal(strsep(&cp, ", "), "third", 6); check(strsep(&cp, ", ") == NULL, 7); cp = strcpy(one, ", first, "); equal(strsep(&cp, ", "), "", 8); equal(strsep(&cp, ", "), "", 9); equal(strsep(&cp, ", "), "first", 10); /* Extra delims, 1 tok. */ equal(strsep(&cp, ", "), "", 11); equal(strsep(&cp, ", "), "", 12); check(strsep(&cp, ", ") == NULL, 13); cp = strcpy(one, "1a, 1b; 2a, 2b"); equal(strsep(&cp, ", "), "1a", 14); /* Changing delim lists. */ equal(strsep(&cp, ", "), "", 15); equal(strsep(&cp, "; "), "1b", 16); equal(strsep(&cp, ", "), "", 17); equal(strsep(&cp, ", "), "2a", 18); cp = strcpy(two, "x-y"); equal(strsep(&cp, "-"), "x", 19); /* New string before done. */ equal(strsep(&cp, "-"), "y", 20); check(strsep(&cp, "-") == NULL, 21); cp = strcpy(one, "a,b, c,, ,d "); equal(strsep(&cp, ", "), "a", 22); /* Different separators. */ equal(strsep(&cp, ", "), "b", 23); equal(strsep(&cp, " ,"), "", 24); equal(strsep(&cp, " ,"), "c", 25); /* Permute list too. */ equal(strsep(&cp, " ,"), "", 26); equal(strsep(&cp, " ,"), "", 27); equal(strsep(&cp, " ,"), "", 28); equal(strsep(&cp, " ,"), "d", 29); equal(strsep(&cp, " ,"), "", 30); check(strsep(&cp, ", ") == NULL, 31); check(strsep(&cp, ", ") == NULL, 32); /* Persistence. */ cp = strcpy(one, ", "); equal(strsep(&cp, ", "), "", 33); equal(strsep(&cp, ", "), "", 34); equal(strsep(&cp, ", "), "", 35); check(strsep(&cp, ", ") == NULL, 36); /* No tokens. */ cp = strcpy(one, ""); equal(strsep(&cp, ", "), "", 37); check(strsep(&cp, ", ") == NULL, 38); /* Empty string. */ cp = strcpy(one, "abc"); equal(strsep(&cp, ", "), "abc", 39); /* No delimiters. */ check(strsep(&cp, ", ") == NULL, 40); cp = strcpy(one, "abc"); equal(strsep(&cp, ""), "abc", 41); /* Empty delimiter list. */ check(strsep(&cp, "") == NULL, 42); (void) strcpy(one, "abcdefgh"); cp = strcpy(one, "a,b,c"); equal(strsep(&cp, ","), "a", 43); /* Basics again... */ equal(strsep(&cp, ","), "b", 44); equal(strsep(&cp, ","), "c", 45); check(strsep(&cp, ",") == NULL, 46); equal(one+6, "gh", 47); /* Stomped past end? */ equal(one, "a", 48); /* Stomped old tokens? */ equal(one+2, "b", 49); equal(one+4, "c", 50); { char text[] = "This,is,a,test"; char *list = strdupa (text); equal (strsep (&list, ","), "This", 51); equal (strsep (&list, ","), "is", 52); equal (strsep (&list, ","), "a", 53); equal (strsep (&list, ","), "test", 54); check (strsep (&list, ",") == NULL, 55); } cp = strcpy(one, "a,b, c,, ,d,"); equal(strsep(&cp, ","), "a", 56); /* Different separators. */ equal(strsep(&cp, ","), "b", 57); equal(strsep(&cp, ","), " c", 58); /* Permute list too. */ equal(strsep(&cp, ","), "", 59); equal(strsep(&cp, ","), " ", 60); equal(strsep(&cp, ","), "d", 61); equal(strsep(&cp, ","), "", 62); check(strsep(&cp, ",") == NULL, 63); check(strsep(&cp, ",") == NULL, 64); /* Persistence. */ cp = strcpy(one, "a,b, c,, ,d,"); equal(strsep(&cp, "xy,"), "a", 65); /* Different separators. */ equal(strsep(&cp, "x,y"), "b", 66); equal(strsep(&cp, ",xy"), " c", 67); /* Permute list too. */ equal(strsep(&cp, "xy,"), "", 68); equal(strsep(&cp, "x,y"), " ", 69); equal(strsep(&cp, ",xy"), "d", 70); equal(strsep(&cp, "xy,"), "", 71); check(strsep(&cp, "x,y") == NULL, 72); check(strsep(&cp, ",xy") == NULL, 73); /* Persistence. */ cp = strcpy(one, "ABC"); one[4] = ':'; equal(strsep(&cp, "C"), "AB", 74); /* Access beyond NUL. */ ptr = strsep(&cp, ":"); equal(ptr, "", 75); check(ptr == one + 3, 76); check(cp == NULL, 77); cp = strcpy(one, "ABC"); one[4] = ':'; equal(strsep(&cp, "CD"), "AB", 78); /* Access beyond NUL. */ ptr = strsep(&cp, ":."); equal(ptr, "", 79); check(ptr == one + 3, 80); cp = strcpy(one, "ABC"); /* No token in string. */ equal(strsep(&cp, ","), "ABC", 81); check(cp == NULL, 82); *one = '\0'; /* Empty string. */ cp = one; ptr = strsep(&cp, ","); equal(ptr, "", 83); check(ptr == one, 84); check(cp == NULL, 85); *one = '\0'; /* Empty string and no token. */ cp = one; ptr = strsep(&cp, ""); equal(ptr, "", 86); check(ptr == one , 87); check(cp == NULL, 88); } static void test_memcmp (void) { it = "memcmp"; check(memcmp("a", "a", 1) == 0, 1); /* Identity. */ check(memcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */ check(memcmp("abcd", "abce", 4) < 0, 3); /* Honestly unequal. */ check(memcmp("abce", "abcd", 4) > 0, 4); check(memcmp("alph", "beta", 4) < 0, 5); check(memcmp("a\203", "a\003", 2) > 0, 6); check(memcmp("abce", "abcd", 3) == 0, 7); /* Count limited. */ check(memcmp("abc", "def", 0) == 0, 8); /* Zero count. */ } static void test_memchr (void) { it = "memchr"; check(memchr("abcd", 'z', 4) == NULL, 1); /* Not found. */ (void) strcpy(one, "abcd"); check(memchr(one, 'c', 4) == one+2, 2); /* Basic test. */ check(memchr(one, ~0xff|'c', 4) == one+2, 2); /* ignore highorder bits. */ check(memchr(one, 'd', 4) == one+3, 3); /* End of string. */ check(memchr(one, 'a', 4) == one, 4); /* Beginning. */ check(memchr(one, '\0', 5) == one+4, 5); /* Finding NUL. */ (void) strcpy(one, "ababa"); check(memchr(one, 'b', 5) == one+1, 6); /* Finding first. */ check(memchr(one, 'b', 0) == NULL, 7); /* Zero count. */ check(memchr(one, 'a', 1) == one, 8); /* Singleton case. */ (void) strcpy(one, "a\203b"); check(memchr(one, 0203, 3) == one+1, 9); /* Unsignedness. */ /* now test all possible alignment and length combinations to catch bugs due to unrolled loops (assuming unrolling is limited to no more than 128 byte chunks: */ { char buf[128 + sizeof(long)]; long align, len, i, pos; for (align = 0; align < (long) sizeof(long); ++align) { for (len = 0; len < (long) (sizeof(buf) - align); ++len) { for (i = 0; i < len; ++i) { buf[align + i] = 'x'; /* don't depend on memset... */ } for (pos = 0; pos < len; ++pos) { #if 0 printf("align %d, len %d, pos %d\n", align, len, pos); #endif check(memchr(buf + align, 'x', len) == buf + align + pos, 10); check(memchr(buf + align, 'x', pos) == NULL, 11); buf[align + pos] = '-'; } } } } } static void test_memcpy (void) { int i; it = "memcpy"; check(memcpy(one, "abc", 4) == one, 1); /* Returned value. */ equal(one, "abc", 2); /* Did the copy go right? */ (void) strcpy(one, "abcdefgh"); (void) memcpy(one+1, "xyz", 2); equal(one, "axydefgh", 3); /* Basic test. */ (void) strcpy(one, "abc"); (void) memcpy(one, "xyz", 0); equal(one, "abc", 4); /* Zero-length copy. */ (void) strcpy(one, "hi there"); (void) strcpy(two, "foo"); (void) memcpy(two, one, 9); equal(two, "hi there", 5); /* Just paranoia. */ equal(one, "hi there", 6); /* Stomped on source? */ for (i = 0; i < 16; i++) { const char *x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; strcpy (one, x); check (memcpy (one + i, "hi there", 9) == one + i, 7 + (i * 6)); /* Unaligned destination. */ check (memcmp (one, x, i) == 0, 8 + (i * 6)); /* Wrote under? */ equal (one + i, "hi there", 9 + (i * 6)); check (one[i + 9] == 'x', 10 + (i * 6)); /* Wrote over? */ check (memcpy (two, one + i, 9) == two, 11 + (i * 6)); /* Unaligned source. */ equal (two, "hi there", 12 + (i * 6)); } } static void test_mempcpy (void) { int i; it = "mempcpy"; check(mempcpy(one, "abc", 4) == one + 4, 1); /* Returned value. */ equal(one, "abc", 2); /* Did the copy go right? */ (void) strcpy(one, "abcdefgh"); (void) mempcpy(one+1, "xyz", 2); equal(one, "axydefgh", 3); /* Basic test. */ (void) strcpy(one, "abc"); (void) mempcpy(one, "xyz", 0); equal(one, "abc", 4); /* Zero-length copy. */ (void) strcpy(one, "hi there"); (void) strcpy(two, "foo"); (void) mempcpy(two, one, 9); equal(two, "hi there", 5); /* Just paranoia. */ equal(one, "hi there", 6); /* Stomped on source? */ for (i = 0; i < 16; i++) { const char *x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; strcpy (one, x); check (mempcpy (one + i, "hi there", 9) == one + i + 9, 7 + (i * 6)); /* Unaligned destination. */ check (memcmp (one, x, i) == 0, 8 + (i * 6)); /* Wrote under? */ equal (one + i, "hi there", 9 + (i * 6)); check (one[i + 9] == 'x', 10 + (i * 6)); /* Wrote over? */ check (mempcpy (two, one + i, 9) == two + 9, 11 + (i * 6)); /* Unaligned source. */ equal (two, "hi there", 12 + (i * 6)); } } static void test_memmove (void) { it = "memmove"; check(memmove(one, "abc", 4) == one, 1); /* Returned value. */ equal(one, "abc", 2); /* Did the copy go right? */ (void) strcpy(one, "abcdefgh"); (void) memmove(one+1, "xyz", 2); equal(one, "axydefgh", 3); /* Basic test. */ (void) strcpy(one, "abc"); (void) memmove(one, "xyz", 0); equal(one, "abc", 4); /* Zero-length copy. */ (void) strcpy(one, "hi there"); (void) strcpy(two, "foo"); (void) memmove(two, one, 9); equal(two, "hi there", 5); /* Just paranoia. */ equal(one, "hi there", 6); /* Stomped on source? */ (void) strcpy(one, "abcdefgh"); (void) memmove(one+1, one, 9); equal(one, "aabcdefgh", 7); /* Overlap, right-to-left. */ (void) strcpy(one, "abcdefgh"); (void) memmove(one+1, one+2, 7); equal(one, "acdefgh", 8); /* Overlap, left-to-right. */ (void) strcpy(one, "abcdefgh"); (void) memmove(one, one, 9); equal(one, "abcdefgh", 9); /* 100% overlap. */ } static void test_memccpy (void) { /* First test like memcpy, then the search part The SVID, the only place where memccpy is mentioned, says overlap might fail, so we don't try it. Besides, it's hard to see the rationale for a non-left-to-right memccpy. */ it = "memccpy"; check(memccpy(one, "abc", 'q', 4) == NULL, 1); /* Returned value. */ equal(one, "abc", 2); /* Did the copy go right? */ (void) strcpy(one, "abcdefgh"); (void) memccpy(one+1, "xyz", 'q', 2); equal(one, "axydefgh", 3); /* Basic test. */ (void) strcpy(one, "abc"); (void) memccpy(one, "xyz", 'q', 0); equal(one, "abc", 4); /* Zero-length copy. */ (void) strcpy(one, "hi there"); (void) strcpy(two, "foo"); (void) memccpy(two, one, 'q', 9); equal(two, "hi there", 5); /* Just paranoia. */ equal(one, "hi there", 6); /* Stomped on source? */ (void) strcpy(one, "abcdefgh"); (void) strcpy(two, "horsefeathers"); check(memccpy(two, one, 'f', 9) == two+6, 7); /* Returned value. */ equal(one, "abcdefgh", 8); /* Source intact? */ equal(two, "abcdefeathers", 9); /* Copy correct? */ (void) strcpy(one, "abcd"); (void) strcpy(two, "bumblebee"); check(memccpy(two, one, 'a', 4) == two+1, 10); /* First char. */ equal(two, "aumblebee", 11); check(memccpy(two, one, 'd', 4) == two+4, 12); /* Last char. */ equal(two, "abcdlebee", 13); (void) strcpy(one, "xyz"); check(memccpy(two, one, 'x', 1) == two+1, 14); /* Singleton. */ equal(two, "xbcdlebee", 15); } static void test_memset (void) { int i; it = "memset"; (void) strcpy(one, "abcdefgh"); check(memset(one+1, 'x', 3) == one+1, 1); /* Return value. */ equal(one, "axxxefgh", 2); /* Basic test. */ (void) memset(one+2, 'y', 0); equal(one, "axxxefgh", 3); /* Zero-length set. */ (void) memset(one+5, 0, 1); equal(one, "axxxe", 4); /* Zero fill. */ equal(one+6, "gh", 5); /* And the leftover. */ (void) memset(one+2, 010045, 1); equal(one, "ax\045xe", 6); /* Unsigned char convert. */ /* Non-8bit fill character. */ memset (one, 0x101, sizeof (one)); for (i = 0; i < (int) sizeof (one); ++i) check (one[i] == '\01', 7); /* Test for more complex versions of memset, for all alignments and lengths up to 256. This test takes a little while, perhaps it should be made weaker? */ { char data[512]; int j; int k; int c; for (i = 0; i < 512; i++) data[i] = 'x'; for (c = 0; c <= 'y'; c += 'y') /* check for memset(,0,) and memset(,'y',) */ for (j = 0; j < 256; j++) for (i = 0; i < 256; i++) { memset (data + i, c, j); for (k = 0; k < i; k++) if (data[k] != 'x') goto fail; for (k = i; k < i+j; k++) { if (data[k] != c) goto fail; data[k] = 'x'; } for (k = i+j; k < 512; k++) if (data[k] != 'x') goto fail; continue; fail: check (0, 8 + i + j * 256 + (c != 0) * 256 * 256); } } } static void test_bcopy (void) { #ifdef __TEST_SUSV3_LEGACY__ /* Much like memcpy. Berklix manual is silent about overlap, so don't test it. */ it = "bcopy"; (void) bcopy("abc", one, 4); equal(one, "abc", 1); /* Simple copy. */ (void) strcpy(one, "abcdefgh"); (void) bcopy("xyz", one+1, 2); equal(one, "axydefgh", 2); /* Basic test. */ (void) strcpy(one, "abc"); (void) bcopy("xyz", one, 0); equal(one, "abc", 3); /* Zero-length copy. */ (void) strcpy(one, "hi there"); (void) strcpy(two, "foo"); (void) bcopy(one, two, 9); equal(two, "hi there", 4); /* Just paranoia. */ equal(one, "hi there", 5); /* Stomped on source? */ #endif } static void test_bzero (void) { #ifdef __TEST_SUSV3_LEGACY__ it = "bzero"; (void) strcpy(one, "abcdef"); bzero(one+2, 2); equal(one, "ab", 1); /* Basic test. */ equal(one+3, "", 2); equal(one+4, "ef", 3); (void) strcpy(one, "abcdef"); bzero(one+2, 0); equal(one, "abcdef", 4); /* Zero-length copy. */ #endif } static void test_strndup (void) { char *p, *q; it = "strndup"; p = strndup("abcdef", 12); check(p != NULL, 1); if (p != NULL) { equal(p, "abcdef", 2); q = strndup(p + 1, 2); check(q != NULL, 3); if (q != NULL) equal(q, "bc", 4); free (q); } free (p); p = strndup("abc def", 3); check(p != NULL, 5); if (p != NULL) equal(p, "abc", 6); free (p); } static void test_bcmp (void) { #ifdef __TEST_SUSV3_LEGACY__ it = "bcmp"; check(bcmp("a", "a", 1) == 0, 1); /* Identity. */ check(bcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */ check(bcmp("abcd", "abce", 4) != 0, 3); /* Honestly unequal. */ check(bcmp("abce", "abcd", 4) != 0, 4); check(bcmp("alph", "beta", 4) != 0, 5); check(bcmp("abce", "abcd", 3) == 0, 6); /* Count limited. */ check(bcmp("abc", "def", 0) == 0, 8); /* Zero count. */ #endif } static void test_strerror (void) { it = "strerror"; check(strerror(EDOM) != 0, 1); check(strerror(ERANGE) != 0, 2); check(strerror(ENOENT) != 0, 3); } static void test_strcasecmp (void) { it = "strcasecmp"; /* Note that the locale is "C". */ check(strcasecmp("a", "a") == 0, 1); check(strcasecmp("a", "A") == 0, 2); check(strcasecmp("A", "a") == 0, 3); check(strcasecmp("a", "b") < 0, 4); check(strcasecmp("c", "b") > 0, 5); check(strcasecmp("abc", "AbC") == 0, 6); check(strcasecmp("0123456789", "0123456789") == 0, 7); check(strcasecmp("", "0123456789") < 0, 8); check(strcasecmp("AbC", "") > 0, 9); check(strcasecmp("AbC", "A") > 0, 10); check(strcasecmp("AbC", "Ab") > 0, 11); check(strcasecmp("AbC", "ab") > 0, 12); } static void test_strncasecmp (void) { it = "strncasecmp"; /* Note that the locale is "C". */ check(strncasecmp("a", "a", 5) == 0, 1); check(strncasecmp("a", "A", 5) == 0, 2); check(strncasecmp("A", "a", 5) == 0, 3); check(strncasecmp("a", "b", 5) < 0, 4); check(strncasecmp("c", "b", 5) > 0, 5); check(strncasecmp("abc", "AbC", 5) == 0, 6); check(strncasecmp("0123456789", "0123456789", 10) == 0, 7); check(strncasecmp("", "0123456789", 10) < 0, 8); check(strncasecmp("AbC", "", 5) > 0, 9); check(strncasecmp("AbC", "A", 5) > 0, 10); check(strncasecmp("AbC", "Ab", 5) > 0, 11); check(strncasecmp("AbC", "ab", 5) > 0, 12); check(strncasecmp("0123456789", "AbC", 0) == 0, 13); check(strncasecmp("AbC", "abc", 1) == 0, 14); check(strncasecmp("AbC", "abc", 2) == 0, 15); check(strncasecmp("AbC", "abc", 3) == 0, 16); check(strncasecmp("AbC", "abcd", 3) == 0, 17); check(strncasecmp("AbC", "abcd", 4) < 0, 18); check(strncasecmp("ADC", "abcd", 1) == 0, 19); check(strncasecmp("ADC", "abcd", 2) > 0, 20); } int main (void) { int status; /* Test strcmp first because we use it to test other things. */ test_strcmp (); /* Test strcpy next because we need it to set up other tests. */ test_strcpy (); /* A closely related function is stpcpy. */ test_stpcpy (); /* stpncpy. */ test_stpncpy (); /* strcat. */ test_strcat (); /* strncat. */ test_strncat (); /* strlcat. */ test_strlcat (); /* strncmp. */ test_strncmp (); /* strncpy. */ test_strncpy (); /* strlcpy. */ test_strlcpy (); /* strlen. */ test_strlen (); /* strnlen. */ test_strnlen (); /* strchr. */ test_strchr (); /* strchrnul. */ test_strchrnul (); /* rawmemchr. */ test_rawmemchr (); /* index - just like strchr. */ test_index (); /* strrchr. */ test_strrchr (); /* memrchr. */ test_memrchr (); /* rindex - just like strrchr. */ test_rindex (); /* strpbrk - somewhat like strchr. */ test_strpbrk (); /* strstr - somewhat like strchr. */ test_strstr (); /* strspn. */ test_strspn (); /* strcspn. */ test_strcspn (); /* strtok - the hard one. */ test_strtok (); /* strtok_r. */ test_strtok_r (); /* strsep. */ test_strsep (); /* memcmp. */ test_memcmp (); /* memchr. */ test_memchr (); /* memcpy - need not work for overlap. */ test_memcpy (); /* memmove - must work on overlap. */ test_memmove (); /* mempcpy */ test_mempcpy (); /* memccpy. */ test_memccpy (); /* memset. */ test_memset (); /* bcopy. */ test_bcopy (); /* bzero. */ test_bzero (); /* bcmp - somewhat like memcmp. */ test_bcmp (); /* strndup. */ test_strndup (); /* strerror - VERY system-dependent. */ test_strerror (); /* strcasecmp. Without locale dependencies. */ test_strcasecmp (); /* strncasecmp. Without locale dependencies. */ test_strncasecmp (); if (errors == 0) { status = EXIT_SUCCESS; puts("No errors."); } else { status = EXIT_FAILURE; printf("%Zd errors.\n", errors); } return status; }
the_stack_data/40761759.c
#include <stdlib.h> int* sortedSquares(int* nums, int numsSize, int* returnSize) { int *res = malloc(sizeof(nums[0]) * numsSize); int start = 0; int end = numsSize - 1; for (int i = numsSize - 1; start <= end; i--) { int a = nums[start] * nums[start]; int b = nums[end] * nums[end]; if (a > b) { res[i] = a; start++; } else { res[i] = b; end--; } } return res; }
the_stack_data/150141133.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* l_numlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jecaudal <jecaudal@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/27 14:06:11 by jecaudal #+# #+# */ /* Updated: 2020/01/27 14:06:13 by jecaudal ### ########.fr */ /* */ /* ************************************************************************** */ int l_numlen(int n) { int count; count = 0; if (n == 0) return (1); while (n > 0) { n /= 10; count++; } return (count); }
the_stack_data/132953519.c
#include <stdio.h> #include <stdlib.h> struct Object { int *nums; int len; int k; }; struct ListNode { int val; struct ListNode *next; }; struct ListNode *make_list(int *nums, int size) { struct ListNode dummy, *prev = NULL; int i; dummy.next = NULL; prev = &dummy; for (i = 0; i < size; i++) { struct ListNode *node = malloc(sizeof(struct ListNode)); node->next = NULL; node->val = nums[i]; prev->next = node; prev = node; } return dummy.next; } void print_list(struct ListNode *list) { struct ListNode *p = list; while (p != NULL) { if (p == list) { printf("%d", p->val); } else { printf(" -> %d", p->val); } p = p->next; } } struct ListNode *rotate_right(struct ListNode *head, int k) { if (head == NULL || k <= 0) { return head; } int count = k; struct ListNode dummy; struct ListNode *prev = &dummy; // prev is the last node of the old list. struct ListNode *last = &dummy; // last is the last node of the new list. struct ListNode *p = head; dummy.next = head; while (k > 0) { if (p == NULL) { int length = count - k; prev = &dummy; p = head; k = count % length; // quick forward. if (k == 0) break; } prev = p; p = p->next; k--; } while (p != NULL) { last = last->next; prev = p; p = p->next; } if (last != &dummy) { prev->next = head; dummy.next = last->next; last->next = NULL; } return dummy.next; } int main(int argc, char **argv) { int nums1[] = {1, 2, 3, 4, 5}, len1 = sizeof(nums1) / sizeof(int); int nums2[] = {0, 1, 2}, len2 = sizeof(nums2) / sizeof(int); struct Object inputs[] = { {.nums = nums1, .len = len1, .k = 2}, {.nums = nums2, .len = len2, .k = 4}, }; int i, len = sizeof(inputs) / sizeof(struct Object); for (i = 0; i < len; i++) { int *nums = inputs[i].nums; int size = inputs[i].len; int k = inputs[i].k; struct ListNode *list = make_list(nums, size); printf("\n Input: "); print_list(list); printf(", k = %d\n", k); list = rotate_right(list, k); printf(" Output: "); print_list(list); putchar('\n'); } return EXIT_SUCCESS; }
the_stack_data/43887972.c
/*--------------------------------------------------------------* TableCurve C Code Output To modify generated output, edit C.TCL *--------------------------------------------------------------*/ #include <math.h> #include <stdio.h> #include <stdlib.h> double eqn7909(double x); /*--------------------------------------------------------------*/ double eqn7909(double x) /*--------------------------------------------------------------* TableCurve Function: C:\\BACKUP\\Documents\\!SCHOOL\\Masters\\plots for curve fitting\\equation_SFH.c Apr 24, 2009 8:04:07 AM H:\\Program Files\\TableCurve2Dv5.01\\CLIPBRD.PRN X= Area Y= SFH Eqn# 7909 y=(a+cx+ex^2+gx^3+ix^4+kx^5)/(1+bx+dx^2+fx^3+hx^4+jx^5) [NL] r2=0.9999995896280252 r2adj=0.999999288688577 StdErr=0.003053880889046886 Fstat=3898900.12378589 a= -0.0001404096113424695 b= 1.358427229137855 c= 7.977893021854755 d= 0.745893622383768 e= 7.797126079694334 f= -7.500711784387533 g= 5.679318820478323 h= 4.316659015381748 i= -47.3348203683902 j= 0.1002326782840694 k= 26.15186102077307 *--------------------------------------------------------------*/ { double y; y=(-0.0001404096113424695+x*(7.977893021854755+ x*(7.797126079694334+x*(5.679318820478323+ x*(-47.33482036839020+x*26.15186102077307)))))/ (1.0+x*(1.358427229137855+x*(0.7458936223837680+ x*(-7.500711784387533+x*(4.316659015381748+ x*0.1002326782840694))))); return(y); }
the_stack_data/179831858.c
#include <stdio.h> #include <stdlib.h> void foo(FILE *p) { p = fopen("bar.txt", "w+"); } int main() { FILE *f; foo(f); fclose(f); return 0; }
the_stack_data/114566.c
/* * @XMHF_LICENSE_HEADER_START@ * * eXtensible, Modular Hypervisor Framework (XMHF) * Copyright (c) 2009-2012 Carnegie Mellon University * Copyright (c) 2010-2012 VDG Inc. * All Rights Reserved. * * Developed by: XMHF Team * Carnegie Mellon University / CyLab * VDG Inc. * http://xmhf.org * * 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 names of Carnegie Mellon or VDG Inc, 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. * * @XMHF_LICENSE_HEADER_END@ */ /*++ Copyright (c) Microsoft Corporation. All rights reserved. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. Module Name: IOCTL.C Abstract: This modules contains functions to register/deregsiter a control- deviceobject for ioctl purposes and dispatch routine for handling ioctl requests from usermode. Revision History: Notes: --*/ #if defined(IOCTL_INTERFACE) #include "miniport.h" #include "public.h" #include "txrxfifo.h" // // Simple Mutual Exclusion constructs used in preference to // using KeXXX calls since we don't have Mutex calls in NDIS. // These can only be called at passive IRQL. // typedef struct _NIC_MUTEX { ULONG Counter; ULONG ModuleAndLine; // useful for debugging } NIC_MUTEX, *PNIC_MUTEX; #define NIC_INIT_MUTEX(_pMutex) \ { \ (_pMutex)->Counter = 0; \ (_pMutex)->ModuleAndLine = 0; \ } #define NIC_ACQUIRE_MUTEX(_pMutex) \ { \ while (NdisInterlockedIncrement((PLONG)&((_pMutex)->Counter)) != 1)\ { \ NdisInterlockedDecrement((PLONG)&((_pMutex)->Counter)); \ NdisMSleep(10000); \ } \ (_pMutex)->ModuleAndLine = ('I' << 16) | __LINE__;\ } #define NIC_RELEASE_MUTEX(_pMutex) \ { \ (_pMutex)->ModuleAndLine = 0; \ NdisInterlockedDecrement((PLONG)&(_pMutex)->Counter); \ } #define LINKNAME_STRING L"\\DosDevices\\LDNVNET" #define NTDEVICE_STRING L"\\Device\\LDNVNET" // // Global variables // NDIS_HANDLE NdisDeviceHandle = NULL; // From NdisMRegisterDevice LONG MiniportCount = 0; // Total number of miniports in existance PDEVICE_OBJECT ControlDeviceObject = NULL; // Device for IOCTLs NIC_MUTEX ControlDeviceMutex; extern NDIS_HANDLE NdisWrapperHandle; #pragma NDIS_PAGEABLE_FUNCTION(NICRegisterDevice) #pragma NDIS_PAGEABLE_FUNCTION(NICDeregisterDevice) #pragma NDIS_PAGEABLE_FUNCTION(NICDispatch) NDIS_STATUS NICRegisterDevice( VOID ) /*++ Routine Description: Register an ioctl interface - a device object to be used for this purpose is created by NDIS when we call NdisMRegisterDevice. This routine is called whenever a new miniport instance is initialized. However, we only create one global device object, when the first miniport instance is initialized. This routine handles potential race conditions with NICDeregisterDevice via the ControlDeviceMutex. NOTE: do not call this from DriverEntry; it will prevent the driver from being unloaded (e.g. on uninstall). Arguments: None Return Value: NDIS_STATUS_SUCCESS if we successfully register a device object. --*/ { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; UNICODE_STRING DeviceName; UNICODE_STRING DeviceLinkUnicodeString; PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION+1]; DEBUGP(MP_TRACE, ("==>NICRegisterDevice\n")); PAGED_CODE(); NIC_ACQUIRE_MUTEX(&ControlDeviceMutex); ++MiniportCount; if (1 == MiniportCount) { NdisZeroMemory(DispatchTable, (IRP_MJ_MAXIMUM_FUNCTION+1) * sizeof(PDRIVER_DISPATCH)); DispatchTable[IRP_MJ_CREATE] = NICDispatch; DispatchTable[IRP_MJ_CLEANUP] = NICDispatch; DispatchTable[IRP_MJ_CLOSE] = NICDispatch; DispatchTable[IRP_MJ_DEVICE_CONTROL] = NICDispatch; NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING); NdisInitUnicodeString(&DeviceLinkUnicodeString, LINKNAME_STRING); // // Create a device object and register our dispatch handlers // Status = NdisMRegisterDevice( NdisWrapperHandle, &DeviceName, &DeviceLinkUnicodeString, &DispatchTable[0], &ControlDeviceObject, &NdisDeviceHandle ); } NIC_RELEASE_MUTEX(&ControlDeviceMutex); DEBUGP(MP_TRACE, ("<==NICRegisterDevice: %x\n", Status)); return (Status); } NTSTATUS NICDispatch( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) /*++ Routine Description: Process IRPs sent to this device. Arguments: DeviceObject - pointer to a device object Irp - pointer to an I/O Request Packet Return Value: NTSTATUS - STATUS_SUCCESS always - change this when adding real code to handle ioctls. --*/ { PIO_STACK_LOCATION irpStack; NTSTATUS status = STATUS_SUCCESS; ULONG inlen; PVOID buffer; PAGED_CODE(); irpStack = IoGetCurrentIrpStackLocation(Irp); DEBUGP(MP_TRACE, ("==>NICDispatch %d\n", irpStack->MajorFunction)); switch (irpStack->MajorFunction) { case IRP_MJ_CREATE: Irp->IoStatus.Information = 0; break; case IRP_MJ_CLEANUP: Irp->IoStatus.Information = 0; break; case IRP_MJ_CLOSE: Irp->IoStatus.Information = 0; break; case IRP_MJ_DEVICE_CONTROL: { buffer = Irp->AssociatedIrp.SystemBuffer; inlen = irpStack->Parameters.DeviceIoControl.InputBufferLength; switch (irpStack->Parameters.DeviceIoControl.IoControlCode) { // // Add code here to handle ioctl commands. // case IOCTL_LDNVNET_READ_DATA:{ PCHAR buffer; ULONG length; NTSTATUS opStatus = STATUS_SUCCESS; buffer = Irp->AssociatedIrp.SystemBuffer; opStatus = txrxfifo_txfifo_remove(buffer, &length); if(opStatus == STATUS_SUCCESS) Irp->IoStatus.Information = length; else Irp->IoStatus.Information = 0; if(Irp->IoStatus.Information) DEBUGP(MP_ERROR, ("IOCTL(READ): returned %u bytes\n", Irp->IoStatus.Information)); } break; case IOCTL_LDNVNET_WRITE_DATA:{ PCHAR buffer; ULONG length; NTSTATUS opStatus = STATUS_SUCCESS; buffer = Irp->AssociatedIrp.SystemBuffer; length = irpStack->Parameters.DeviceIoControl.InputBufferLength; opStatus = txrxfifo_rxfifo_add(buffer, length); if(opStatus == STATUS_SUCCESS) Irp->IoStatus.Information = length; else Irp->IoStatus.Information = 0; if(Irp->IoStatus.Information) DEBUGP(MP_ERROR, ("IOCTL(WRITE): returned %u bytes\n", Irp->IoStatus.Information)); } break; default: Irp->IoStatus.Information = 0; status = STATUS_UNSUCCESSFUL; break; } break; } default: break; } Irp->IoStatus.Status = status; IoCompleteRequest(Irp, IO_NO_INCREMENT); DEBUGP(MP_TRACE, ("<== NIC Dispatch\n")); return status; } NDIS_STATUS NICDeregisterDevice( VOID ) /*++ Routine Description: Deregister the ioctl interface. This is called whenever a miniport instance is halted. When the last miniport instance is halted, we request NDIS to delete the device object Arguments: NdisDeviceHandle - Handle returned by NdisMRegisterDevice Return Value: NDIS_STATUS_SUCCESS if everything worked ok --*/ { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; DEBUGP(MP_TRACE, ("==>NICDeregisterDevice\n")); PAGED_CODE(); NIC_ACQUIRE_MUTEX(&ControlDeviceMutex); HALT_ON_ERRORCOND(MiniportCount > 0); --MiniportCount; if (0 == MiniportCount) { // // All miniport instances have been halted. // Deregister the control device. // if (NdisDeviceHandle != NULL) { Status = NdisMDeregisterDevice(NdisDeviceHandle); NdisDeviceHandle = NULL; } } NIC_RELEASE_MUTEX(&ControlDeviceMutex); DEBUGP(MP_TRACE, ("<== NICDeregisterDevice: %x\n", Status)); return Status; } #endif
the_stack_data/133220.c
#include <stdio.h> #include <stdlib.h> void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void q1() { void sort(int a[], int n) { for (int i = 0; i < n; i++) { int min_index = i; for (int j = i + 1; j < n; j++) { if (a[j] < a[min_index]) { min_index = j; } } swap(&a[i], &a[min_index]); } } int p; printf("Enter the size of the array\n"); scanf("%d", &p); int b[p]; printf("Enter the elements of the array\n"); for (int k = 0; k < p; k++) { scanf("%d", &b[k]); } sort(b, p); printf("The elements after sorting is\n"); for (int k = 0; k < p; k++) { printf("%d ", b[k]); } printf("\n"); } void q2a() { printf("Enter the total number of user who are using any site\n"); int n, z = 0; scanf("%d", &n); int arrival_time[n], leaving_time[n]; printf("Enter the arrival & leaving time of each user in format (arrival & leaving time)\n"); for (int i = 0; i < n; i++) { scanf("%d %d", &arrival_time[i], &leaving_time[i]); } printf("The Number of the pairs of users who are using the site at the same time are: \n"); for (int j = 0; j < n; j++) { for (int k = j + 1; k < n; k++) { if ((arrival_time[k] >= arrival_time[j] && arrival_time[k] <= leaving_time[j]) || (arrival_time[j] >= arrival_time[k] && arrival_time[j] <= leaving_time[k])) { printf("(%d,%d) \n", j + 1, k + 1); z++; } } } printf("The Total number of distinct pair of user which are possible is equal to %d\n", z); } void q2b() { void heapify(int arr[], int n, int i) { int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < n && arr[l] > arr[largest]) largest = l; if (r < n && arr[r] > arr[largest]) largest = r; if (largest != i) { swap(&arr[i], &arr[largest]); heapify(arr, n, largest); } } void heapsort(int arr[], int n) { for (int i = n / 2 - 1; i >= 0; i--) heapify(arr, n, i); for (int i = n - 1; i > 0; i--) { swap(&arr[0], &arr[i]); heapify(arr, i, 0); } } printf("Enter the total number of user who are using any site\n"); int n, z = 0; scanf("%d", &n); int arrival_time[n], leaving_time[n]; printf("Enter the arrival & leaving time of each user in format (arrival & leaving time)\n"); for (int i = 0; i < n; i++) { scanf("%d %d", &arrival_time[i], &leaving_time[i]); } heapsort(arrival_time, n); heapsort(leaving_time, n); printf("The Number of the pairs of users who are using the site at the same time are: \n"); for (int j = 0; j < n; j++) { for (int k = j + 1; k < n; k++) { if (leaving_time[j] > arrival_time[k]) { printf("(%d,%d) \n", j + 1, k + 1); z++; } } } printf("The Total number of distinct pair of user which are possible is equal to %d\n", z); } void q3c() { printf("Enter the size of the array\n"); int n; scanf("%d", &n); int a[n]; printf("Enter the elements of the array\n"); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int minimum_element = a[0]; for (int j = 0; j < n; j++) { if (a[j] <= minimum_element) { minimum_element = a[j]; } } printf("The Minimum element of the array is %d\n", minimum_element); } void q3f() { int min_array(int a[], int n) { if (n == 1) { return a[0]; } int min_element = a[0]; int x = min_array(a + 1, n - 1); if (min_element > x) { min_element = x; } return min_element; } printf("Enter the size of the array\n"); int n; scanf("%d", &n); int a[n]; printf("Enter the elements of the array\n"); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } printf("The Minimum element of the array is %d\n", min_array(a, n)); } void q4aiv() { int local_minima(int a[], int low, int high, int n) { int middle = low + (high - low) / 2; if ((middle == 0 || a[middle - 1] > a[middle]) && (middle == n - 1 || a[middle + 1] > a[middle])) { return middle; } else if ((middle > 0) && (a[middle - 1] < a[middle])) { return local_minima(a, low, (middle - 1), n); } return local_minima(a, (middle + 1), high, n); } printf("Enter the size of the array\n"); int n; scanf("%d", &n); int a[n]; printf("Enter the elements of the array\n"); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int ans = local_minima(a, 0, n - 1, n); printf("The value of the Local Minima at index %d is %d (if indexing starts from 1)\n", ans + 1, a[ans]); } void q4biv() { int local_minima(int n, int arr[n][n], int low, int high) { if ((high == 0 || arr[low][high - 1] > arr[low][high]) && (high == n - 1 || arr[low][high + 1] > arr[low][high]) && (low == 0 || arr[low - 1][high] > arr[low][high]) && (low == n - 1 || arr[low + 1][high] > arr[low][high])) { return arr[low][high]; } else if (high > 0 && arr[low][high - 1] < arr[low][high]) { return local_minima(n, arr, low, high - 1); } else if (high < n - 1 && arr[low][high + 1] < arr[low][high]) { return local_minima(n, arr, low, high + 1); } else if (low > 0 && arr[low - 1][high] < arr[low][high]) { return local_minima(n, arr, low - 1, high); } else { return local_minima(n, arr, low + 1, high); } } printf("Enter the size of the array\n"); int n; scanf("%d", &n); int a[n][n]; printf("Enter the elements of the array\n"); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &a[i][j]); } } int ans = local_minima(n, a, n / 2, n); printf("The value of the Local Minima at index %d is %d (if indexing starts from 1)\n", ans + 1, a[ans][ans]); } int main() { while (1) { printf("C Code Implementation of ADSA HW Assignment-2\n"); printf("-----------------------------------------------\n\n\n"); printf("1=> Q(1)\t2=>Q(2a)\t3=>Q(2b)\t4=>Q(3c)\t5=>Q(3f)\t6=>Q(4a(iv))\t7=>Q(4b(iv))\t8=> For Exit\n\n"); int op; printf("Enter your choice number\n"); scanf("%d", &op); switch (op) { case 1: q1(); break; case 2: q2a(); break; case 3: q2b(); break; case 4: q3c(); break; case 5: q3f(); break; case 6: q4aiv(); break; case 7: q4biv(); break; case 8: printf("Thanks for Joining. Happy Coding! :)\n"); exit(0); break; default: printf("Please enter a valid input number\n"); } } return 0; }
the_stack_data/170452765.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_memcpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jgigault <jgigault@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/06/01 14:59:17 by jgigault #+# #+# */ /* Updated: 2015/06/01 15:06:34 by jgigault ### ########.fr */ /* */ /* ************************************************************************** */ #include <strings.h> #include <stdlib.h> #include <stdio.h> void ft_memcpy(void *restrict dst, const void *restrict src, size_t n); int main(int argc, char **argv) { int i; char *str; if (argc == 4) { i = atoi(argv[1]); str = (char *)malloc(sizeof(char) * 100); str[0] = 0; if (i == 0) { ft_memcpy(str, argv[2], atoi(argv[3])); printf("%s", str); } } return (0); }
the_stack_data/51080.c
/* http://www.scriptol.org/sieve.php */ /* Sieve Of Erathosthenes by Denis Sureau */ #include <stdlib.h> #include <stdio.h> void eratosthenes(int top) { int all[1000000]; int idx = 0; int prime = 3; int x, j; printf("1 "); while (prime <= top) { for(x = 0; x < top; x++) { if(all[x] == prime) goto skip; } printf("%d ", prime); j = prime; while(j <= (top / prime)) { all[idx++] = prime * j; j += 1; } skip: prime+=2; } puts(""); return; } int main(int argc, char **argv) { if (argc == 2) { eratosthenes(atoi(argv[1])); } else { eratosthenes(1000000); } return 0; }
the_stack_data/9187.c
#include <stdio.h> int main() { int length = 10; for (int i = 0; i <= length; i++) { for (int j = 0; j < length; j++) { char out[] = "Y"; if (j < length - i) out[0] = 'X'; printf("%s", out); } printf("\n"); } return 0; }
the_stack_data/97108.c
#include <stdlib.h> #include <pthread.h> struct foo { int f_count; pthread_mutex_t f_lock; /* ... more stuff here ... */ }; struct foo * foo_alloc(void) /* allocate the object */ { struct foo *fp; if ((fp = malloc(sizeof(struct foo))) != NULL) { fp->f_count = 1; if (pthread_mutex_init(&fp->f_lock, NULL) != 0) { free(fp); return(NULL); } /* ... continue initialization ... */ } return(fp); } void foo_hold(struct foo *fp) /* add a reference to the object */ { pthread_mutex_lock(&fp->f_lock); fp->f_count++; pthread_mutex_unlock(&fp->f_lock); } void foo_rele(struct foo *fp) /* release a reference to the object */ { pthread_mutex_lock(&fp->f_lock); if (--fp->f_count == 0) { /* last reference */ pthread_mutex_unlock(&fp->f_lock); pthread_mutex_destroy(&fp->f_lock); free(fp); } else { pthread_mutex_unlock(&fp->f_lock); } }
the_stack_data/40762982.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define FILE_SIZE 1000 struct Submarine { int horizontal; int depth; int aim; }; struct Commands { char cmd[8]; int dist; }; struct Commands data[FILE_SIZE]; struct Submarine sub; void read_file (char *path) { FILE *fp = fopen(path, "r"); for (int i = 0; i < FILE_SIZE; i++) { fscanf(fp, "%s %d", data[i].cmd, &data[i].dist); /* printf("%s %d\n", data[i].cmd, data[i].dist); */ }; fclose(fp); } void compute () { int x = 0; for (int i = 0; i < FILE_SIZE; i++) { x = data[i].dist; if (strcmp("forward", data[i].cmd) == 0) { sub.horizontal += x; sub.depth += sub.aim * x; } else if (strcmp("down", data[i].cmd) == 0) sub.aim += x; else if (strcmp("up", data[i].cmd) == 0) sub.aim -= x; } } int main () { char *path = "./input"; read_file(path); compute(); printf("Depth: %d, Horizontal: %d\n", sub.depth, sub.horizontal); printf("Total: %d\n", (sub.horizontal*sub.depth)); }
the_stack_data/982798.c
/** * Title : echo server * Name : Aditya Pratap Singh Rajput * Subject : Network Protocols And Programming using C * * */ #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<unistd.h> // time #define MAXLINE 1024 #define PORT 5035 int main(){ int socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0); int number; socklen_t addressLength; char message[MAXLINE]; struct sockaddr_in serverAddress,clientAddress; serverAddress.sin_family = AF_INET; serverAddress.sin_addr.s_addr=INADDR_ANY; serverAddress.sin_port=htons(PORT); bind(socketDescriptor,(struct sockaddr*)&serverAddress,sizeof(serverAddress)); printf("\nServer Started ...\n"); while(1){ printf("\n"); addressLength = sizeof(clientAddress); number = recvfrom(socketDescriptor,message,MAXLINE,0,(struct sockaddr*)&clientAddress,&addressLength); printf("\n Client's Message: %s ",message); if(number<6) perror("send error"); sendto(socketDescriptor,message,number,0,(struct sockaddr*)&clientAddress,addressLength); } return 0; }
the_stack_data/96280.c
/* { dg-do run } */ /* { dg-require-effective-target nonlocal_goto } */ extern void exit (int); #if !defined (NO_LABEL_VALUES) && !defined (NO_TRAMPOLINES) extern void abort (void); int s(int i){if(i>0){__label__ l1;int f(int i){if(i==2)goto l1;return 0;}return f(i);l1:;}return 1;} int x(){return s(0)==1&&s(1)==0&&s(2)==1;} int main(){if(x()!=1)abort();exit(0);} #else int main(){ exit (0); } #endif
the_stack_data/116835.c
/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * 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. * * The Original Code is Global Alignment Kernel, (C) 2010, Marco Cuturi * * The Initial Developers of the Original Code is * * Marco Cuturi mcuturi@i.kyoto-u.ac.jp * * Portions created by the Initial Developers are * Copyright (C) 2011 the Initial Developers. All Rights Reserved. * * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * ***** END LICENSE BLOCK ***** * * REVISIONS: * This is v1.02 of Global Alignment Kernel, June 8th 2011. * Changed some C syntax that was not compiled properly on Windows platforms * * Previous versions: * v1.02 (Adrien Gaidon): removed Mex part + minor changes for Python wrapper * v1.01 of Global Alignment Kernel, May 12th 2011 (updated comments fields) * v1.0 of Global Alignment Kernel, March 25th 2011. * */ #include <stdlib.h> #include <math.h> /* Useful constants */ #define LOG0 -10000 /* log(0) */ #define LOGP(x, y) (((x)>(y))?(x)+log1p(exp((y)-(x))):(y)+log1p(exp((x)-(y)))) /* Implementation of the (Triangular) global alignment kernel. * * seq1 is a first sequence represented as a matrix of real elements. Each line i corresponds to the vector of observations at time i. * seq2 is the second sequence formatted in the same way. * nX, nY and dimvect provide the number of lines of seq1 and seq2. * sigma stands for the bandwidth of the \phi_\sigma distance used kernel * lambda is an additional factor that can be used with the Geometrically divisible Gaussian Kernel * triangular is a parameter which parameterizes the triangular kernel * kerneltype selects either the Gaussian Kernel or its geometrically divisible equivalent */ double logGAK(double *seq1 , double *seq2, int nX, int nY, int dimvect, double sigma, int triangular) { int i, j, ii, cur, old, curpos, frompos1, frompos2, frompos3; double aux; int cl = nY+1; /* length of a column for the dynamic programming */ double sum=0; double gram, Sig; /* logM is the array that will stores two successive columns of the (nX+1) x (nY+1) table used to compute the final kernel value*/ double * logM = malloc(2*cl * sizeof(double)); int trimax = (nX>nY) ? nX-1 : nY-1; /* Maximum of abs(i-j) when 1<=i<=nX and 1<=j<=nY */ double *logTriangularCoefficients = malloc((trimax+1) * sizeof(double)); if (triangular>0) { /* initialize */ for (i=0;i<=trimax;i++){ logTriangularCoefficients[i]=LOG0; /* Set all to zero */ } for (i=0;i<((trimax<triangular) ? trimax+1 : triangular);i++) { logTriangularCoefficients[i]=log(1-i/triangular); } } else for (i=0;i<=trimax;i++){ logTriangularCoefficients[i]=0; /* 1 for all if triangular==0, that is a log value of 0 */ } Sig=-1/(2*sigma*sigma); /****************************************************/ /* First iteration : initialization of columns to 0 */ /****************************************************/ /* The left most column is all zeros... */ for (j=1;j<cl;j++) { logM[j]=LOG0; } /* ... except for the lower-left cell which is initialized with a value of 1, i.e. a log value of 0. */ logM[0]=0; /* Cur and Old keep track of which column is the current one and which one is the already computed one.*/ cur = 1; /* Indexes [0..cl-1] are used to process the next column */ old = 0; /* Indexes [cl..2*cl-1] were used for column 0 */ /************************************************/ /* Next iterations : processing columns 1 .. nX */ /************************************************/ /* Main loop to vary the position for i=1..nX */ curpos = 0; for (i=1;i<=nX;i++) { /* Special update for positions (i=1..nX,j=0) */ curpos = cur*cl; /* index of the state (i,0) */ logM[curpos] = LOG0; /* Secondary loop to vary the position for j=1..nY */ for (j=1;j<=nY;j++) { curpos = cur*cl + j; /* index of the state (i,j) */ if (logTriangularCoefficients[abs(i-j)]>LOG0) { frompos1 = old*cl + j; /* index of the state (i-1,j) */ frompos2 = cur*cl + j-1; /* index of the state (i,j-1) */ frompos3 = old*cl + j-1; /* index of the state (i-1,j-1) */ /* We first compute the kernel value */ sum=0; for (ii=0;ii<dimvect;ii++) { sum+=(seq1[i-1+ii*nX]-seq2[j-1+ii*nY])*(seq1[i-1+ii*nX]-seq2[j-1+ii*nY]); } gram= logTriangularCoefficients[abs(i-j)] + sum*Sig ; gram -=log(2-exp(gram)); /* Doing the updates now, in two steps. */ aux= LOGP(logM[frompos1], logM[frompos2] ); logM[curpos] = LOGP( aux , logM[frompos3] ) + gram; } else { logM[curpos]=LOG0; } } /* Update the culumn order */ cur = 1-cur; old = 1-old; } aux = logM[curpos]; free(logM); free(logTriangularCoefficients); /* Return the logarithm of the Global Alignment Kernel */ return aux; }
the_stack_data/50308.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern float strtof(char const *str , char const *endptr ) ; extern void signal(int sig , void *func ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned long input[1] , unsigned long output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; int main(int argc , char *argv[] ) { unsigned long input[1] ; unsigned long output[1] ; int randomFuns_i5 ; unsigned long randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 6488003331680296674UL) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%lu\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned long input[1] , unsigned long output[1] ) { unsigned long state[1] ; unsigned long local2 ; unsigned long local1 ; unsigned int copy11 ; unsigned int copy12 ; char copy13 ; unsigned int copy14 ; { state[0UL] = (input[0UL] + 914778474UL) * 67330564296145686UL; local1 = 0UL; while (local1 < 0UL) { local2 = 0UL; while (local2 < 0UL) { if (state[0UL] < local2 + local1) { copy11 = *((unsigned int *)(& state[local2]) + 0); *((unsigned int *)(& state[local2]) + 0) = *((unsigned int *)(& state[local2]) + 1); *((unsigned int *)(& state[local2]) + 1) = copy11; copy12 = *((unsigned int *)(& state[0UL]) + 0); *((unsigned int *)(& state[0UL]) + 0) = *((unsigned int *)(& state[0UL]) + 1); *((unsigned int *)(& state[0UL]) + 1) = copy12; } else { copy13 = *((char *)(& state[local1]) + 3); *((char *)(& state[local1]) + 3) = *((char *)(& state[local1]) + 7); *((char *)(& state[local1]) + 7) = copy13; copy14 = *((unsigned int *)(& state[local1]) + 0); *((unsigned int *)(& state[local1]) + 0) = *((unsigned int *)(& state[local1]) + 1); *((unsigned int *)(& state[local1]) + 1) = copy14; } local2 ++; } local1 ++; } output[0UL] = state[0UL] * 168932551UL - 1042640300UL; } } void megaInit(void) { { } }
the_stack_data/62637473.c
// RUN: test.sh -p -t %t %s #include <unistd.h> #include <stdlib.h> // Ensure that a correct use of realpath() is not flagged as an error. int main() { char * buffer = malloc (24); realpath ("/etc/passwd", buffer); return 0; }
the_stack_data/167331397.c
/////////////////////////////////////////////////// // fmdebug.c // // September.4,1997 H.Ishida (FPL) // // COPYRIGHT(C) FUJITSU LIMITED 1997 #if DBG #include <minidrv.h> #include "fmlbp.h" void dbgPrintf(LPSTR pszMsg, ...) { va_list arg; va_start(arg, pszMsg); // DbgPrint("[fmblpres]", pszMsg, arg); va_end(arg); } #endif // DBG // end of fmdebug.c
the_stack_data/154827712.c
/* * uart.c - tiva-c launchpad uart interface implementation * * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ * * * 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 Texas Instruments Incorporated 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 * 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. * */ #ifdef SL_IF_TYPE_UART #include "simplelink.h" #include "board.h" #include "inc/hw_memmap.h" #include "inc/hw_ints.h" #include "driverlib/pin_map.h" #include "driverlib/gpio.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/uart.h" #include "uart.h" extern unsigned char IntIsMasked; int uart_Close(Fd_t fd) { /* Disable WLAN Interrupt ... */ CC3100_InterruptDisable(); return NONOS_RET_OK; } Fd_t uart_Open(char *ifName, unsigned long flags) { /* Configure CS (PE0) and nHIB (PE4) lines */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4); ROM_GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_4, PIN_LOW); /* configuring UART interface */ SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinConfigure(GPIO_PC4_U1RTS); GPIOPinConfigure(GPIO_PC5_U1CTS); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* configure with baud rate 115200 */ ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTFlowControlSet(UART1_BASE, UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX); UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8); ROM_UARTEnable(UART1_BASE); ROM_UARTFIFOEnable(UART1_BASE); ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX); ROM_UARTIntDisable(UART1_BASE, UART_INT_TX | UART_INT_RT); /* configure host IRQ line */ GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_RISING_EDGE); GPIOIntClear(GPIO_PORTB_BASE,GPIO_PIN_2); GPIOIntDisable(GPIO_PORTB_BASE,GPIO_PIN_2); ROM_IntEnable(INT_GPIOB); ROM_IntMasterEnable(); IntIsMasked = FALSE; /* Enable WLAN interrupt */ CC3100_InterruptEnable(); /* 50 ms delay */ ROM_SysCtlDelay((ROM_SysCtlClockGet()/(3*1000))*50 ); return NONOS_RET_OK; } int uart_Read(Fd_t fd, unsigned char *pBuff, int len) { int i = 0; ROM_UARTIntDisable(UART1_BASE, UART_INT_RX); for(i=0; i< len; i++) { pBuff[i] = (unsigned char)UARTCharGet(UART1_BASE); } ROM_UARTIntEnable(UART1_BASE, UART_INT_RX); return len; } int uart_Write(Fd_t fd, unsigned char *pBuff, int len) { int len_to_return = len; while(len) { /* Wait until UART channel is busy or CTS line from NWP is high */ UARTCharPut(UART1_BASE, *pBuff); len--; pBuff++; } return len_to_return; } #endif /* SL_IF_TYPE_UART */
the_stack_data/1139424.c
extern int test(int argc, char**argv); int main(int argc, char** argv) { return test(argc,argv); }
the_stack_data/61075002.c
#include <stdio.h> #include <stdlib.h> int main(void) { int i, n; printf("\n%s\n%s", "Some randomly distributed integers will be printed.", "How many do you want to see? "); scanf("%d", &n); for (i = 0; i < n; ++i) { if (i % 10 == 0) putchar('\n'); printf("%7d", rand()); } printf("\n\n"); return 0; }
the_stack_data/27806.c
extern int kkk(); int main() { return kkk(); }
the_stack_data/88044.c
/* * @Author: HuangYuhui * @Date: 2019-01-19 14:37:24 * @Last Modified by: HuangYuhui * @Last Modified time: 2019-01-19 14:38:41 */ #include<stdio.h> int main(int argc, char const *argv[]) { printf("Hi NCRE-C !\n"); getchar(); return 0; }
the_stack_data/20451478.c
/** Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. **/ #include <stdio.h> #include <stdlib.h> int main() { int predprejsna = 1, prejsna = 2; int trenutno = 0; int vsota = 2; //printf("%d\n%d\n", predprejsna, prejsna); while(trenutno <= 4000000){ trenutno = prejsna + predprejsna; predprejsna = prejsna; prejsna = trenutno; //printf("%d\n", trenutno); if (trenutno % 2 == 0) { vsota += trenutno; } } printf("%d\n",vsota); return 0; }
the_stack_data/237642300.c
/* ** bases.c for bases.c in /home/simon_w/System_unix/printf/PSU_2015_my_printf ** ** Made by Erwan Simon ** Login <simon_w@epitech.net> ** ** Started on Fri Nov 13 15:37:46 2015 Erwan Simon ** Last update Fri Nov 13 15:37:47 2015 Erwan Simon */ void my_putchar(char); int my_strlen(char *); int bases(int nb, char *base) { int result; int div; int len_base; div = 1; len_base = my_strlen(base); if (nb < 0) { my_putchar('-'); nb = nb * -1; } while ((nb / div) >= len_base) { div = div * len_base; } while (div > 0) { result = (nb / div) % len_base; my_putchar(base[result]); div = div / len_base; } }
the_stack_data/67326399.c
void something_f(float); int foo(void) { union { float f; double d; } u, *pu = &u; u.f = 1.0; something_f(u.f); }
the_stack_data/175142307.c
#include <stdio.h> #include <string.h> #include <stdbool.h> #define MAX_REMIND 50 #define MSG_LEN 60 int read_line(char *str, int n) { int ch, i; i = 0; while ((ch = getchar()) != '\n') { if (i < n) str[i++] = ch; } str[i] = '\0'; return i; } bool remaind_hour(char *time_str, int *minutes) { int hour, minute; printf("Enter 24-hour time: "); scanf("%d :%d", &hour, &minute); sprintf(time_str, "%d:%d", hour, minute); *minutes = hour * 60 + minute; return true; } bool remaind_day(char *day_str, int *day) { printf("Enter day and reminder: "); scanf("%2d", day); if (*day < 0 || *day > 31) { printf("day is error\n"); return false; } sprintf(day_str, "%2d", *day); return true; } bool remaind_date(char *time_str, int *days) { int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int month, day; printf("Enter an date(xx-xx): "); scanf("%2d -%2d", &month, &day); sprintf(time_str, "%d-%d", month, day); *days = 0; for (int i = 0; i < month - 1; i++) { *days += months[i]; } *days += day; return true; } int main(void) { char reminders[MAX_REMIND][MSG_LEN + 3]; char day_str[3], msg_str[MSG_LEN + 1]; int day, i, j, num_remind = 0; for (;;) { if (num_remind == MAX_REMIND) { printf("-- No space left --\n"); break; } remaind_date(day_str, &day); if (day == 0) { break; } read_line(msg_str, MSG_LEN); for (i = 0; i < num_remind; i++) { if (strcmp(day_str, reminders[i]) < 0) break; } for (j = num_remind; j > i; j--) { strcpy(reminders[j], reminders[j - 1]); } strcpy(reminders[i], day_str); strcat(reminders[i], msg_str); num_remind++; } printf("\nDay Reminder\n"); for (i = 0; i < num_remind; i++) { printf(" %s\n", reminders[i]); } return 0; }
the_stack_data/1270603.c
#include <stdio.h> #include <math.h> #define TRUTH_VALUE ((double)0.5) int main() { const double PI = acos(-1); double prev = 0, sum = 0; double numerator = 1, denom = 1; for (int i = 0; ; ++i) { prev = sum; sum += numerator / denom; numerator *= -(PI * PI) / 9; denom *= (2 * i + 1) * (2 * i + 2); printf("iter %d approx %lf err_a ", i, sum); if (i > 0) printf("%lf ", (prev - sum) / sum * 100.); else printf("na "); printf("err_r %lf\n", (TRUTH_VALUE - sum) / TRUTH_VALUE * 100.); } }
the_stack_data/109979.c
//Implementation of Bubble sort in C #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define swap(t, x, y) t z = x; x = y; y = z; typedef int TYPE; void bubble_sort(TYPE [], int); void print_array(TYPE [], int); TYPE* init_array(int size){ TYPE* v = (TYPE *) malloc(size * sizeof(TYPE)); for(int i = 0; i < size; i++){ v[i] = rand(); } return v; } int main(int argc, char **argv){ if(argc != 2) { printf("Usage: %s <sortingSize>\n", argv[0]); return -1; } int n = atoi(argv[1]); TYPE *A = init_array(n); struct timeval start, end; gettimeofday(&start, NULL); bubble_sort(A, n); gettimeofday(&end, NULL); float elapsed = ((end.tv_sec - start.tv_sec)*1000000.0f + end.tv_usec - start.tv_usec)/1000000.0f; printf("%12f \n", elapsed); return EXIT_SUCCESS; } void bubble_sort(TYPE A[], int n) { int i, j, sorted; for(i = 0; i < n; i++) { sorted = 1; for(j = 0; j < n - 1; j++) { if(A[j] > A[j + 1]) { swap(TYPE, A[j], A[j+1]); sorted = 0; } } if(sorted) break; /*if array is sorted break. This way we have O(n) in best case, instead of always O(n^2)*/ } } void print_array(TYPE A[], int n) { int i = 0; putchar('['); while(i < n) { if(i > 0) printf(", "); printf("%d", A[i++]); //first A[i] is done then i = i + 1 } puts("]"); }
the_stack_data/111079283.c
/** ****************************************************************************** * @file stm32wbxx_ll_pwr.c * @author MCD Application Team * @brief PWR LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32wbxx_ll_pwr.h" #include "stm32wbxx_ll_bus.h" /** @addtogroup STM32WBxx_LL_Driver * @{ */ #if defined(PWR) /** @defgroup PWR_LL PWR * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /** @defgroup PWR_LL_Private_Constants PWR Private Constants * @{ */ /* Definitions of PWR registers reset value */ #define PWR_CR1_RESET_VALUE (0x00000200) #define PWR_CR2_RESET_VALUE (0x00000000) #define PWR_CR3_RESET_VALUE (0x00008000) #define PWR_CR4_RESET_VALUE (0x00000000) #define PWR_CR5_RESET_VALUE (0x00004272) #define PWR_PUCRA_RESET_VALUE (0x00000000) #define PWR_PDCRA_RESET_VALUE (0x00000000) #define PWR_PUCRB_RESET_VALUE (0x00000000) #define PWR_PDCRB_RESET_VALUE (0x00000000) #define PWR_PUCRC_RESET_VALUE (0x00000000) #define PWR_PDCRC_RESET_VALUE (0x00000000) #define PWR_PUCRD_RESET_VALUE (0x00000000) #define PWR_PDCRD_RESET_VALUE (0x00000000) #define PWR_PUCRE_RESET_VALUE (0x00000000) #define PWR_PDCRE_RESET_VALUE (0x00000000) #define PWR_PUCRH_RESET_VALUE (0x00000000) #define PWR_PDCRH_RESET_VALUE (0x00000000) #define PWR_C2CR1_RESET_VALUE (0x00000000) #define PWR_C2CR3_RESET_VALUE (0x00008000) /** * @} */ /* Private macros ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup PWR_LL_Exported_Functions * @{ */ /** @addtogroup PWR_LL_EF_Init * @{ */ /** * @brief De-initialize the PWR registers to their default reset values. * @retval An ErrorStatus enumeration value: * - SUCCESS: PWR registers are de-initialized * - ERROR: not applicable */ ErrorStatus LL_PWR_DeInit(void) { /* Apply reset values to all PWR registers */ LL_PWR_WriteReg(CR1, PWR_CR1_RESET_VALUE); LL_PWR_WriteReg(CR2, PWR_CR2_RESET_VALUE); LL_PWR_WriteReg(CR3, PWR_CR3_RESET_VALUE); LL_PWR_WriteReg(CR4, PWR_CR4_RESET_VALUE); LL_PWR_WriteReg(CR5, PWR_CR5_RESET_VALUE); LL_PWR_WriteReg(PUCRA, PWR_PUCRA_RESET_VALUE); LL_PWR_WriteReg(PDCRA, PWR_PDCRA_RESET_VALUE); LL_PWR_WriteReg(PUCRB, PWR_PUCRB_RESET_VALUE); LL_PWR_WriteReg(PDCRB, PWR_PDCRB_RESET_VALUE); LL_PWR_WriteReg(PUCRC, PWR_PUCRC_RESET_VALUE); LL_PWR_WriteReg(PDCRC, PWR_PDCRC_RESET_VALUE); LL_PWR_WriteReg(PUCRD, PWR_PUCRD_RESET_VALUE); LL_PWR_WriteReg(PDCRD, PWR_PDCRD_RESET_VALUE); LL_PWR_WriteReg(PUCRE, PWR_PUCRE_RESET_VALUE); LL_PWR_WriteReg(PDCRE, PWR_PDCRE_RESET_VALUE); LL_PWR_WriteReg(PUCRH, PWR_PUCRH_RESET_VALUE); LL_PWR_WriteReg(PDCRH, PWR_PDCRH_RESET_VALUE); LL_PWR_WriteReg(C2CR1, PWR_C2CR1_RESET_VALUE); LL_PWR_WriteReg(C2CR3, PWR_C2CR3_RESET_VALUE); /* Clear all flags */ LL_PWR_WriteReg(SCR, LL_PWR_SCR_CC2HF | LL_PWR_SCR_C802AF | LL_PWR_SCR_CBLEAF | LL_PWR_SCR_CCRPEF | LL_PWR_SCR_C802WUF | LL_PWR_SCR_CBLEWUF | LL_PWR_SCR_CBORHF | LL_PWR_SCR_CSMPSFBF | LL_PWR_SCR_CWUF ); LL_PWR_WriteReg(EXTSCR, LL_PWR_EXTSCR_CCRPF | LL_PWR_EXTSCR_C2CSSF | LL_PWR_EXTSCR_C1CSSF ); return SUCCESS; } /** * @} */ /** * @} */ /** * @} */ #endif /* defined(PWR) */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/31387974.c
extern int __VERIFIER_nondet_int(); extern void abort(void); void reach_error(){} int fibo(int n) { if (n < 1) { return 0; } else if (n == 1) { return 1; } else { return fibo(n-1) + fibo(n-2); } } // fibo 1-30 // 1, 1, 2, 3, 5, // 8, 13, 21, 34, 55, // 89, 144, 233, 377, 610, // 987, 1597, 2584, 4181, 6765, // 10946, 17711, 28657, 46368, 75025, // 121393, 196418, 317811, 514229, 832040 int main(void) { int x = 10; int result = fibo(x); if (result == 55) { ERROR: {reach_error();abort();} } return 0; }
the_stack_data/621934.c
#include <stdio.h> #include <omp.h> int main(){ printf("I am master thread!\n"); #pragma omp parallel { printf("I am multithread!\n"); } return 0; }
the_stack_data/1176920.c
#include <wchar.h> #define STR(x) L ## x // typedef wchar_t Char; typedef wchar_t Char; typedef int EditLine; int map_bind(EditLine *, int, const Char **); int terminal_echotc(EditLine *, int, const Char **); int el_editmode(EditLine *, int, const Char **); int hist_command(EditLine *, int, const Char **); int terminal_telltc(EditLine *, int, const Char **); int terminal_settc(EditLine *, int, const Char **); int tty_stty(EditLine *, int, const Char **); // int (*func)(EditLine *, int, const Char **); const struct { const Char *name; int (*func)(EditLine *, int, const Char **); } cmds[] = { { STR("bind"), map_bind }, { STR("echotc"), terminal_echotc }, { STR("edit"), el_editmode }, { STR("history"), hist_command }, { STR("telltc"), terminal_telltc }, { STR("settc"), terminal_settc }, { STR("setty"), tty_stty }, { NULL, NULL } };
the_stack_data/68502.c
/* * sigmisc.c - used to get a signal mask */ /* $Id$ */ #if defined(_POSIX_SOURCE) /* This can't be done in setjmp.e, since SIG_SETMASK is defined in * <signal.h>. This is a C-file, which can't be included. */ #include <sys/types.h> #include <signal.h> #include <stddef.h> int _sigprocmask(int, sigset_t*, sigset_t*); static void __testsigset(void) { /* This switch compiles when a sigset_t has the right size. */ switch (0) { case 0: case sizeof(sigset_t) <= sizeof(long): break; } } void __newsigset(sigset_t* p) { /* The SIG_SETMASK is not significant */ _sigprocmask(SIG_SETMASK, NULL, p); } void __oldsigset(sigset_t* p) { _sigprocmask(SIG_SETMASK, p, NULL); } #endif /* _POSIX_SOURCE */
the_stack_data/153268986.c
#include <omp.h> #include <assert.h> int main() { int sum=7; int known_sum; int i; int j; int k = 111; #pragma omp parallel { #pragma omp sections reduction(+:sum) private(i) lastprivate(j) firstprivate(k) { #pragma omp section { assert (k == 111); for (i=1;i<400;i++){ sum += i; } } #pragma omp section { assert (k == 111); for(i=400;i<700;i++) sum += i; } #pragma omp section { assert (k == 111); j = 888; for(i=700;i<1000;i++) sum += i; } }/* end of section reduction.*/ } /* end of parallel */ known_sum=(999*1000)/2+7; assert (known_sum==sum); assert (j == 888); return 0; }
the_stack_data/237643088.c
/* Check statements that are eliminated by inlining. */ /* { dg-do compile } */ /* { dg-options "-O2 -fdump-ipa-inline-details -fno-early-inlining -fno-partial-inlining -fno-ipa-cp" } */ void foo (void); void bar (void); void bagr (void); static int t(int a) { if (a==1) { foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); } else if (a==2) { bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); bar(); } else { bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); bagr(); } } int main() { t(1); t(2); } /* Even if function is huge, inlining it will save code. */ /* { dg-final { scan-ipa-dump-times "Inlined into" 2 "inline" } } */
the_stack_data/22014104.c
/* Description A Simple Table demo for How To Declare a Variable in C The use of Type Names for Un/signed Integer Types (U, L, UL, LL, ULL) ******************************************************** Output: DEMO DECLARING BIG NUMBERS: ----------------------------------------------------- Type (Variable name) Value Bytes -------------------- ----- ----- integer (salary) 100 4 long (Big_Number) 1287600 4 long (below_sea_level) -100000 4 unsigned long (uvalue) 999999999 4 long long (really_big_number) 123456789 8 unsigned long long (LightYear) 429496700 8 ----------------------------------------------------- ********************************************************* Author: j3 Date: Jun, 22/2020 */ #include <stdio.h> // Include the header file for input and output int main(void) { printf("DEMO DECLARING BIG NUMBERS:\n"); printf("-----------------------------------------------------\n"); printf("Type (Variable name)\t\tValue\t\tBytes\n"); printf("--------------------\t\t-----\t\t-----\n"); int salary = 100; printf("integer (salary)%\t\t"); printf("%d\t\t", salary); printf("%d\t\t\n", sizeof(salary)); long Big_Number = 1287600L; printf("long (Big_Number)\t\t"); printf("%d\t\t", Big_Number); printf("%d\t\t\n", sizeof(Big_Number)); long below_sea_level = -100000L; printf("long (below_sea_level)\t\t"); printf("%d\t\t", below_sea_level); printf("%d\t\t\n", sizeof(below_sea_level)); unsigned long uvalue = 999999999UL; printf("unsigned long (uvalue)\t\t"); printf("%d\t", uvalue); printf("%d\t\t\n", sizeof(uvalue)); long long really_big_number = 123456789LL; printf("long long (really_big_number)\t"); printf("%d\t", really_big_number); printf("%d\t\t\n", sizeof(really_big_number)); unsigned long long LightYear = 429496700ULL; printf("unsigned long long (LightYear)\t"); printf("%d\t", LightYear); printf("%d\t\t\n", sizeof(LightYear)); printf("-----------------------------------------------------\n"); return 0; }
the_stack_data/67514.c
/* vim: set ts=4 sw=4: */ /* Filename : omp_pi_num_integration2.c * Description : calculate pi * Author : SunYoung Kim <sunyzero@gmail.com> * Notes : numerical integration method */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <omp.h> const int num_steps=800000000; /* integration 횟수: 8억번 (너무 많으면 줄이자.) */ int main() { double step, sum = 0.0; step = 1.0/(double) num_steps; printf("%d, %d\n", num_steps<<1, num_steps>>1); #pragma omp parallel sections reduction(+:sum) { #pragma omp section { double x1; int num_steps1=num_steps>>1; for (int i=0; i<num_steps1; i++) { x1 = (i+0.5) * step; sum += 4.0/(1.0 + x1*x1); } } #pragma omp section { double x2; for (int i = num_steps>>1; i<num_steps; i++) { x2 = (i+0.5) * step; sum += 4.0/(1.0 + x2*x2); } } } printf("pi = %.8f (sum = %.8f), 4*atan(1) = %.8f\n", step*sum, sum, atan(1)*4); return EXIT_SUCCESS; }
the_stack_data/40252.c
#include<math.h> #include<stdio.h> #define N 1000000 int main() { int i; double x, area = 0; #pragma omp parallel for private(x) reduction(+:area) for (i = 0; i < N; i++) { x = (i + .5) / N; x = 4 / (1 + x*x); //#pragma omp critical area += x; } printf("%.10lf\n", area/N); return 0; }
the_stack_data/31388962.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <math.h> int main (int argc, char *argv[]) { float valor_expoente; float valor_lido; if (argc==2) { valor_expoente = atoi(argv[1]); scanf("%f",&valor_lido); printf("%f\n",powf(valor_lido, valor_expoente)); return 0; } if (argc==3) if (strcmp(argv[1],"-c")==0) { valor_expoente = atoi(argv[2]); for(;;) { scanf("%f",&valor_lido); printf("%f\n",powf(valor_lido,valor_expoente)); fflush(stdout); } } return -1; }
the_stack_data/168892414.c
// Check issue with boolean variables used as integer variables // Subset of boolean12.c #include <stdbool.h> #include <stdio.h> int main(void) { bool stabilize = 1; int j, k; j = stabilize+stabilize; k = 3*stabilize; printf("j=%d, k=%d\n", j, k); return j+k; }
the_stack_data/153267990.c
// Subject total, average and percentages
the_stack_data/165765439.c
/*Exercise 4 - Functions Implement the three functions minimum(), maximum() and multiply() below the main() function. Do not change the code given in the main() function when you are implementing your solution.*/ #include <stdio.h> int minimum( int no1 , int no2); int maximum( int no1, int no2); int multiply( int no1, int no2); int main() { int no1, no2; printf("Enter a value for no 1 : "); scanf("%d", &no1); printf("Enter a value for no 2 : "); scanf("%d", &no2); printf("%d ", minimum(no1, no2)); printf("%d ", maximum(no1, no2)); printf("%d ", multiply(no1, no2)); return 0; } int minimum( int no1 , int no2) { if( no1 < no2) return no1; else if ( no1 > no2 ) return no2; else printf("Both are equal"); return 0; } int maximum( int no1 , int no2) { if( no1 < no2) return no2; else if ( no1 > no2 ) return no1; else printf("Both are equal"); return 0; } int multiply( int no1 , int no2) { int mul; mul = no1 * no2; return mul; }
the_stack_data/87052.c
/* Fig. 10.18: fig10_18.c Using an enumeration type */ #include <stdio.h> /* enumeration constants represent months of the year */ enum months { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; int main( void ) { enum months month; /* can contain any of the 12 months */ /* initialize array of pointers */ const char *monthName[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /* loop through months */ for ( month = JAN; month <= DEC; month++ ) { printf( "%2d%11s\n", month, monthName[ month ] ); } /* end for */ return 0; /* indicates successful termination */ } /* end main */ /************************************************************************** * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/
the_stack_data/28810.c
#include <stdio.h> int main(void){ printf("To C, or not to C: that is the question.\n"); return 0; }
the_stack_data/661426.c
// // //计算 1 + 2 +3 + 。。+5 // #include <stdio.h> int main(void){ int x,y; int sum=0; printf("input x:");scanf("%d", &x); printf("input y:");scanf("%d", &y); int b,s; b = (x>y)?x:y; s = (x<y)?x:y; printf("%d和%d之间的整数和是:", s,b); do{ sum = sum + s; s = s + 1; }while(s <= b); printf("%d \n", sum); return 0; }
the_stack_data/32949852.c
const unsigned short TILE_I_data[64] = { 11456, 19776, 19776, 19776, 19776, 19776, 19776, 11456, 19776, 32648, 32648, 32648, 32648, 32648, 32648, 19776, 19776, 29312, 30368, 30368, 30368, 30368, 29312, 19776, 19776, 29280, 30368, 30368, 30368, 30368, 29280, 19776, 19776, 29280, 29312, 30368, 30368, 29312, 29280, 19776, 19776, 29216, 29280, 29280, 29280, 29280, 29216, 19776, 19776, 29184, 29216, 29216, 29216, 29216, 29184, 19776, 11456, 19776, 19776, 19776, 19776, 19776, 19776, 11456, };
the_stack_data/1018301.c
/////////////////////////////////////////////////////////// // // Function Name : strcpyX() // Description : Accept String From User And Ask How Many Numbers To Copy // Input : Integer,String // Output : Integer,String // Author : Prasad Dangare // Date : 25 Mar 2021 // /////////////////////////////////////////////////////////// #include<stdio.h> void strncpyX(const char src[], char dest[], int value) { if((src == NULL) || (dest == NULL) || (value <= 0)) { return; } while((value>0) && (*src != '\0')) // if we give no as 25 and string is Marvellous so it will handle it { *dest = *src; dest++; src++; value--; } *dest = '\0'; } int main() { char arr[20]; char brr[20]; int iNo = 0; printf("Enter String\n"); scanf("%[^'\n']s",arr); printf("Enter number of elements to copy\n"); scanf(" %d",&iNo); strncpyX(arr,brr,iNo); printf("String after copy is : %s\n",brr); return 0; }
the_stack_data/62638465.c
/******************************************************************************* * Copyright 2016, 2017 ARM Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ #include <stdio.h> #include <stdint.h> #include <stdbool.h> #include <stddef.h> #include <inttypes.h> #ifndef PAL_LINUX_ETH #define PAL_LINUX_ETH "eth0" #endif bool dhcpDone = true; void* palTestGetNetWorkInterfaceContext(void){ static const char interface[] = PAL_LINUX_ETH; return (void *)&interface[0]; }
the_stack_data/78458.c
/* $Id: strspn.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ /* * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) * * 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. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Opsycon AB. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. * */ /* return length of initial segment of p that consists entirely of * characters from s */ int strspn(const char *p, const char *s) { int i, j; for (i = 0; p[i]; i++) { for (j = 0; s[j]; j++) { if (s[j] == p[i]) break; } if (!s[j]) break; } return (i); }
the_stack_data/191727.c
#include <stdio.h> int max(const int *poczatek, const int *koniec); int main(void) { int tab[] = {1, 2, 5, 6, 4, 8, 10, 23, 50, 11, 80}; printf("Max: %d\n", max(tab, tab + (sizeof(tab) / sizeof(int)))); return 0; } int max(const int *poczatek, const int *koniec) { int maksimum = *poczatek; int indeks, i = 0; while (poczatek < koniec) { if (maksimum < *poczatek) { maksimum = *poczatek; indeks = i; } i++; poczatek++; } printf("Indeks maxa: %d\n", indeks); return maksimum; }
the_stack_data/97013999.c
/* * Author: Oscar De La Rosa * Date: 09/26/15 * * Purpose: This program display the 'Oneness' property for two numbers in seven column in the format * 'x:y', where 'x' is the initial number and 'y' is the number of step that took from x->1 * */ #include <stdio.h> void clrKeyboardBuffer(); void oneness(int startPoint, int endPoint); void clrKeyboardBuffer() { char ch; scanf("%c", &ch); // It takes the last character of the string, \n while(ch != '\n') // Until \n is found it will stay inside this while loop scanf("%c", &ch); } void oneness(int startPoint, int endPoint) { int stepsTo1 = 0; // How many steps to startPoint -> 1 int newLnCounter = 0; // To help produce the seven columns int updatedStartPoint = startPoint; // Copy startPoint to be used throughout the function while(startPoint <= endPoint) { if(updatedStartPoint % 2 == 0) // Even number { updatedStartPoint = updatedStartPoint / 2; stepsTo1++; // Update steps if(updatedStartPoint == 1) { printf("%5d:%-5d", startPoint, stepsTo1); newLnCounter++; // Control of how many relationship have we printed if(newLnCounter == 7) // After the 6th relationship, the counter will be seven, therefore we move to a new line. { printf("\n"); newLnCounter = 0; // Set line counter back to zero, to print 7 new columns } startPoint++; // Move on to the next number stepsTo1 = 0; // Reset control updatedStartPoint = startPoint; // Update startPoint copy } } else // Odd number { updatedStartPoint = 3 * updatedStartPoint + 1; stepsTo1++; // Update control } } printf("\n"); } int main(int argc, char **argv) { int firstGivenNumber, secondGivenNumber; printf("__--Oneness Property--__\n"); printf("Enter a starting point (a number between 1-1,000): "); scanf("%d", &firstGivenNumber); while(firstGivenNumber <= 1 || firstGivenNumber >= 1000) { clrKeyboardBuffer(); printf("I'm sorry. The first number should be between 1 and 1000. Try again: "); scanf("%d", &firstGivenNumber); } printf("Enter an ending point (a number between previous number-10,000): "); scanf("%d", &secondGivenNumber); while(secondGivenNumber <= firstGivenNumber || secondGivenNumber >= 10000) { clrKeyboardBuffer(); printf("Sorry, but the second number must be higher than the first number and less than 10,000. Please, try again: "); scanf("%d", &secondGivenNumber); } oneness(firstGivenNumber, secondGivenNumber); return 0; }
the_stack_data/3263709.c
//area of various shapes using function and a menu driven program #include <stdio.h> #include <stdlib.h> float triangle(); int square(); float circle(); int rectangle(); int main() { int num; printf("\n------MENU------\n\n"); printf("1. Triangle \n"); printf("2. Square\n"); printf("3. Circle \n"); printf("4. Rectangle \n"); printf("\nEnter a choice : "); scanf("%d",&num); switch(num) { case 1: printf("\nArea of Triangle = %f \n",triangle()); break; case 2: printf("\nArea of Square = %d \n",square()); break; case 3: printf("\nArea of Circle = %f \n",circle()); break; case 4: printf("\nArea of Rectangle = %d \n",rectangle()); break; default: printf("\nInvalid input \n"); break; } return 0; } float triangle() //area of triangle { int h,b; float a; printf("\nEnter height and base of triangle : "); scanf("%d %d",&h,&b); a = 0.5*h*b; return a; } int square() //area of square { int s; printf("\nEnter side of square : "); scanf("%d",&s); return s*s; } float circle () //area of circle { int r; float ar; printf("\nEnter radius of circle : "); scanf("%d",&r); ar = r*(float)r*3.14; return ar; } int rectangle() //area of rectangle { int l,b; printf("\nEnter length and breath of rectangle : "); scanf("%d %d",&l,&b); return l*b; }
the_stack_data/7219.c
#include <stdlib.h> #include <stdio.h> int buscaBinaria (int x, int n, int v[]) { int e, m, d; e = -1; d = n; while (e < d-1) { m = (e + d)/2; if (v[m] < x) e = m; else d = m; } return d; } int main (void) { int tam=10,x=10,R=-1; int vet[10] = {1,2,3,6,7,8,9,10,10,12}; R = buscaBinaria(x,tam,vet); printf("%d\n",R); }
the_stack_data/119823.c
// Copyright 2013 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> //#include <malloc.h> const long long max_size = 2000; // max length of strings const long long N = 40; // number of closest words that will be shown const long long max_w = 50; // max length of vocabulary entries int main(int argc, char **argv) { FILE *f; char st1[max_size]; char bestw[N][max_size]; char file_name[max_size], st[100][max_size]; float dist, len, bestd[N], vec[max_size]; long long words, size, a, b, c, d, cn, bi[100]; char ch; float *M; char *vocab; if (argc < 2) { printf("Usage: ./word-analogy <FILE>\nwhere FILE contains word projections in the BINARY FORMAT\n"); return 0; } strcpy(file_name, argv[1]); f = fopen(file_name, "rb"); if (f == NULL) { printf("Input file not found\n"); return -1; } fscanf(f, "%lld", &words); fscanf(f, "%lld", &size); vocab = (char *)malloc((long long)words * max_w * sizeof(char)); M = (float *)malloc((long long)words * (long long)size * sizeof(float)); if (M == NULL) { printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size); return -1; } for (b = 0; b < words; b++) { a = 0; while (1) { vocab[b * max_w + a] = fgetc(f); if (feof(f) || (vocab[b * max_w + a] == ' ')) break; if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++; } vocab[b * max_w + a] = 0; for (a = 0; a < size; a++) fread(&M[a + b * size], sizeof(float), 1, f); len = 0; for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size]; len = sqrt(len); for (a = 0; a < size; a++) M[a + b * size] /= len; } fclose(f); while (1) { for (a = 0; a < N; a++) bestd[a] = 0; for (a = 0; a < N; a++) bestw[a][0] = 0; printf("Enter three words (EXIT to break): "); a = 0; while (1) { st1[a] = fgetc(stdin); if ((st1[a] == '\n') || (a >= max_size - 1)) { st1[a] = 0; break; } a++; } if (!strcmp(st1, "EXIT")) break; cn = 0; b = 0; c = 0; while (1) { st[cn][b] = st1[c]; b++; c++; st[cn][b] = 0; if (st1[c] == 0) break; if (st1[c] == ' ') { cn++; b = 0; c++; } } cn++; if (cn < 3) { printf("Only %lld words were entered.. three words are needed at the input to perform the calculation\n", cn); continue; } for (a = 0; a < cn; a++) { for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break; if (b == words) b = 0; bi[a] = b; printf("\nWord: %s Position in vocabulary: %lld\n", st[a], bi[a]); if (b == 0) { printf("Out of dictionary word!\n"); break; } } if (b == 0) continue; printf("\n Word Distance\n------------------------------------------------------------------------\n"); for (a = 0; a < size; a++) vec[a] = M[a + bi[1] * size] - M[a + bi[0] * size] + M[a + bi[2] * size]; len = 0; for (a = 0; a < size; a++) len += vec[a] * vec[a]; len = sqrt(len); for (a = 0; a < size; a++) vec[a] /= len; for (a = 0; a < N; a++) bestd[a] = 0; for (a = 0; a < N; a++) bestw[a][0] = 0; for (c = 0; c < words; c++) { if (c == bi[0]) continue; if (c == bi[1]) continue; if (c == bi[2]) continue; a = 0; for (b = 0; b < cn; b++) if (bi[b] == c) a = 1; if (a == 1) continue; dist = 0; for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size]; for (a = 0; a < N; a++) { if (dist > bestd[a]) { for (d = N - 1; d > a; d--) { bestd[d] = bestd[d - 1]; strcpy(bestw[d], bestw[d - 1]); } bestd[a] = dist; strcpy(bestw[a], &vocab[c * max_w]); break; } } } for (a = 0; a < N; a++) printf("%50s\t\t%f\n", bestw[a], bestd[a]); } return 0; }
the_stack_data/99296.c
/* * $Source$ * $State$ */ #define THREE_PASS /* branch and offset optimization */ #define BYTES_REVERSED /* high order byte has lowest address */ #define WORDS_REVERSED /* high order word has lowest address */ #define LISTING /* enable listing facilities */ #define RELOCATION /* generate relocatable code */ #define DEBUG 0 #undef valu_t #define valu_t int32_t #undef ADDR_T #define ADDR_T uint32_t #undef word_t #define word_t uint32_t #undef ALIGNWORD #define ALIGNWORD 4 #undef ALIGNSECT #define ALIGNSECT 4 #undef VALWIDTH #define VALWIDTH 8 #define FIXUPFLAGS (RELBR | RELWR) /* 6-bit mb (mask begin) or me (mask end) field */ #define MB6(v) (((v) & 0x1F)<<6 | ((v) & 0x20)>>0) /* 6-bit sh (shift) field */ #define SH6(v) (((v) & 0x1F)<<11 | ((v) & 0x20)>>4)
the_stack_data/154828704.c
/* Verify that 387 fsincos instruction is generated. */ /* { dg-do compile { target i?86-*-* x86_64-*-* } } */ /* { dg-require-effective-target ilp32 } */ /* { dg-options "-O -funsafe-math-optimizations -march=i686" } */ extern double sin (double); extern double cos (double); extern void sincos (double, double *, double *); double f1(double x) { double s, c; sincos (x, &s, &c); return s + c; } double f2(double x) { double s, c, tmp; sincos (x, &s, &tmp); c = cos (x); return s + c; } double f3(double x) { double s, c, tmp; sincos (x, &tmp, &c); s = sin (x); return s + c; } /* { dg-final { scan-assembler "fsincos" } } */ /* { dg-final { scan-assembler-not "fsin " } } */ /* { dg-final { scan-assembler-not "fcos" } } */ /* { dg-final { scan-assembler-not "call" } } */
the_stack_data/6191.c
/*Required Headers*/ #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <stdio.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main() { char str[100]; int listen_fd, comm_fd; struct sockaddr_in servaddr; listen_fd = socket(AF_INET, SOCK_STREAM, 0); bzero( &servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htons(INADDR_ANY); servaddr.sin_port = htons(22000); bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)); listen(listen_fd, 10); comm_fd = accept(listen_fd, (struct sockaddr*) NULL, NULL); while(1) { bzero( str, 100); read(comm_fd,str,100); printf("Echoing back - %s",str); write(comm_fd, str, strlen(str)+1); } }
the_stack_data/316775.c
// barbecue - a simple processor based on RISC-V // Copyright © 2017 Team Barbecue // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // 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 AUTHORS OR COPYRIGHT HOLDERS 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. #include <errno.h> #include <unistd.h> #define __BBQ_CONSOLE_ADDR 0x10000000 #define __BBQ_EXIT_STATUS_ADDR 0x20000000 ssize_t write(int fd, const void* buf, size_t len) { if (fd != STDOUT_FILENO && fd != STDERR_FILENO) { errno = EBADF; return -1; } for (const char* p = buf; p < (const char*)buf + len; p++) { *(volatile int*)__BBQ_CONSOLE_ADDR = *p; } return len; } void _exit(int status) { if (status == 0) { *(volatile int*)__BBQ_EXIT_STATUS_ADDR = 123456789; } asm volatile("ebreak"); __builtin_unreachable(); }
the_stack_data/3262481.c
/* */ /* A new `perfect' anti-aliasing renderer (body). */ /* */ /* Copyright 2000-2003, 2005-2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */
the_stack_data/171261.c
#include<stdio.h> int main() { int n, i; scanf("%d",&n); for(i=1; i<=n; i++) { if(i%2==0) printf("I love "); else printf("I hate "); if(i<n) printf("that "); else printf("it\n"); } }
the_stack_data/156527.c
#include <unistd.h> #include <ctype.h> #include <string.h> #include <stdio.h> int ft_tolower(int c); _Bool fail = 0; static void test1() { for (int c = -1000; c <= 1000; ++c) if (tolower(c) != ft_tolower(c)) { if (!fail) fprintf(stderr, "FAIL: ft_tolower\n"); fprintf(stderr, "\tChar code %d should return %d, not %d.\n", c, tolower(c), ft_tolower(c)); fail = 1; } } int main() { test1(); if (!fail) printf("PASS: ft_tolower\n"); return 0; }
the_stack_data/238046.c
#include <stdio.h> #include <string.h> #include <ctype.h> //printing a pattern of upright isosceles triangle with '*' int main (void) { printf("Enter Height: "); int n; scanf("%d", &n); for (int i = 0; i < n; i++)//for the height of triangle { for (int sp = 0; sp < n-1-i; sp++)//for the required spacing { printf(" "); } for (int st = 0; st < 2*i+1; st++)//for the required number of '*' in each line { printf("*"); } printf("\n");//mandatory for going to the next line } }
the_stack_data/34787.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define WORDS_QTY 31 #define ROWS 30 #define COLUMNS 30 typedef enum {RIGHT, LEFT, UP, DOWN, UP_RIGHT, UP_LEFT, DOWN_RIGHT, DOWN_LEFT} orientation; typedef struct{ char * word; int row; int column; orientation orientation; } wordPosition; char * orientationString(orientation orientation); void solve(char game[ROWS][COLUMNS], char * words[WORDS_QTY], wordPosition wordPositions[WORDS_QTY]); int checkOrientation(char game[ROWS][COLUMNS], char * word, int wordLength, int startRow, int startColumn, orientation orientation); int getRowIncrement(orientation orientation); int getColumnIncrement(orientation orientation); int main(){ char * words [WORDS_QTY] = {"ALMONDS", "APPLES", "BANANAS", "BEANS", "BLUEBERRIES", "BROCCOLI", "BROWNRICE", "CARROTS", "CASHEWS", "CELERY", "CHEESE", "CHICKEN", "CORN", "CRANBERRIES", "CUCUMBERS", "EGGS", "LEMONS", "LETTUCE", "OATMEAL", "ORANGES", "POTATOES", "SALMON", "SPINACH", "TOFU", "TOMATOES", "WALNUTS", "WATER", "WATERMELON", "WHOLEGRAINS", "YOGURT", "ZUCCHINI"}; char game[ROWS][COLUMNS] = { "SXXDLLQTSBWNOQBQOECSBZCIBXPMSW", "ZRDYQKOCTRPBASNICJEGRIRUQXCEQC", "UBEHPMCBUOSKVVYUIIITOEAAMVLROV", "VKHBAHWLNWWQYCTORUZWCZNWBPWRXT", "NLLTMANMLNSPYTSRBKCVCIBFPYTLNM", "TROBHUMJARVPEREGKXOEOWEAMZELKN", "XENQXTCKWIELIBBLZMRDLCRKCQXMYN", "SKSFWAHUQCOQENTMHQAHIMRXDXKWIJ", "GAGVNPSCCEVUMPAZUVNDAAIQUFJXAE", "BITYSETLGULREGUCNXGQQFEFRXUTMG", "EJUTAPRLZBYSONWXHUEOTXSIQPBVQG", "APKNGHAEWTEYQDLUSCSXJKCFAYHLCS", "NPACOLRLBEVLQBFBQQVLBEGMIIHEZS", "SMNAALOBHULLPZQVSWMDQWNFBVAVYN", "CSMFLSECYSGZYYXRZAOQEKTNQYQORI", "TTWGAMHMICPBIGEDPDMQOBMOQPCVRA", "RKGEAXOERIOBXTKKXXVCGEQDXOOBPR", "VHOKQOGNWEHJAIFTDQLPGANAHTRXEG", "NSFQFOIWDSTWDFEAMNVSNZRKXANUWE", "OATMEALGFSSALIXROYESWYKLYTTPNL", "XCSVLPEVLAWEWXMMOFZTRVTRVOYTYO", "OJPXIQPENFEQCHLGQUNOCVDZWETUCH", "SBQKERZABLLJDAUWCLORCEPSQSQDAW", "EQIEBMNOEBPGSRECACORAILXHRFABL", "UXXSAALEMONSTLHUSDVASWCEWWYPLA", "WYLIBNNMGXGNQIQQBKUCKNDARYSGRF", "CHICKENLQGUDNRYKOFXXXFUELYREYV", "TPYCHHGMQZBINFICONHIXBBCQZAXZO", "PNKUVONBMJVCOZUTAPMUXSJUDNMYOR", "VPOFDLHMZZOHYGOCITBSQTSAXNXEPG"}; wordPosition wordPositions[WORDS_QTY]; solve(game, words, wordPositions); for(int i = 0; i<WORDS_QTY; i++){ printf("%s:\n\tRow: %d\n\tColumn: %d\n\tOrientation: %s\n", wordPositions[i].word, wordPositions[i].row, wordPositions[i].column, orientationString(wordPositions[i].orientation)); } } char * orientationString(orientation orientation){ switch(orientation){ case RIGHT: return "Right"; case LEFT: return "Left"; case UP: return "Up"; case DOWN: return "Down"; case UP_RIGHT: return "Up & Right"; case UP_LEFT: return "Up & Left"; case DOWN_RIGHT: return "Down & Right"; case DOWN_LEFT: return "Down & Left"; default: return NULL; } } void solve(char game[ROWS][COLUMNS], char * words[WORDS_QTY], wordPosition wordPositions[WORDS_QTY]){ int wordPositionsIndex = 0; for(int wordIndex = 0; wordIndex<WORDS_QTY; wordIndex++){ int wordFound = 0; for(int row = 0; row<ROWS && !wordFound; row++){ for(int column = 0; column<COLUMNS && !wordFound; column++){ if(game[row][column] == words[wordIndex][0]){ for(orientation orientation = RIGHT; orientation<=DOWN_LEFT && !wordFound; orientation++){ if(checkOrientation(game, words[wordIndex], strlen(words[wordIndex]), row, column, orientation)){ wordFound = 1; wordPositions[wordPositionsIndex].word = words[wordIndex]; wordPositions[wordPositionsIndex].row = row; wordPositions[wordPositionsIndex].column = column; wordPositions[wordPositionsIndex].orientation = orientation; wordPositionsIndex++; } } } } } } } int checkOrientation(char game[ROWS][COLUMNS], char * word, int wordLength, int startRow, int startColumn, orientation orientation){ int rowIncrement = getRowIncrement(orientation); int columnIncrement = getColumnIncrement(orientation); for(int wordIndex = 0; wordIndex < wordLength; wordIndex++){ if(wordIndex * rowIncrement + startRow >= 0 && wordIndex * rowIncrement + startRow < ROWS && wordIndex * columnIncrement + startColumn >= 0 && wordIndex * columnIncrement + startColumn < COLUMNS){ if(word[wordIndex] != game[wordIndex * rowIncrement + startRow][wordIndex * columnIncrement + startColumn]){ return 0; } } else { return 0; } } return 1; } int getRowIncrement(orientation orientation){ switch(orientation){ case RIGHT: return 0; case LEFT: return 0; case UP: return -1; case DOWN: return 1; case UP_RIGHT: return -1; case UP_LEFT: return -1; case DOWN_RIGHT: return 1; case DOWN_LEFT: return 1; default: return 0; } } int getColumnIncrement(orientation orientation){ switch(orientation){ case RIGHT: return 1; case LEFT: return -1; case UP: return 0; case DOWN: return 0; case UP_RIGHT: return 1; case UP_LEFT: return -1; case DOWN_RIGHT: return 1; case DOWN_LEFT: return -1; default: return 0; } }
the_stack_data/43888964.c
int main(int argc, char **argv) { return 0; }
the_stack_data/828162.c
#if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA) || defined(MANDRIVA) || defined(MAGEIA)) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include "pool.h" #include "repo.h" #include "repo_rpmdb.h" #if defined(ENABLE_SUSEREPO) && defined(SUSE) #include "repo_products.h" #endif #if defined(ENABLE_APPDATA) #include "repo_appdata.h" #endif #include "transaction.h" #include "repoinfo.h" #include "repoinfo_cache.h" #include "repoinfo_system_rpm.h" #ifdef SUSE # define PRODUCTS_PATH "/etc/products.d" #endif #ifdef ENABLE_APPDATA # define APPDATA_PATH "/usr/share/appdata" #endif static void runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir) { pid_t pid; int status; if ((pid = fork()) == (pid_t)-1) { perror("fork"); exit(1); } if (pid == 0) { if (!rootdir) rootdir = "/"; if (dupfd3 != -1 && dupfd3 != 3) { dup2(dupfd3, 3); close(dupfd3); } if (dupfd3 != -1) fcntl(3, F_SETFD, 0); /* clear CLOEXEC */ if (strcmp(arg, "-e") == 0) execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0); else execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0); perror("rpm"); _exit(0); } while (waitpid(pid, &status, 0) != pid) ; if (status) { printf("rpm failed\n"); exit(1); } } int read_installed_rpm(struct repoinfo *cinfo) { Repo *repo = cinfo->repo; Pool *pool = repo->pool; FILE *ofp = 0; struct stat stb; memset(&stb, 0, sizeof(stb)); printf("rpm database:"); if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb)) memset(&stb, 0, sizeof(stb)); calc_cookie_stat(&stb, REPOKEY_TYPE_SHA256, 0, cinfo->cookie); cinfo->cookieset = 1; if (usecachedrepo(cinfo, 0, 0)) { printf(" cached\n"); return 1; } printf(" reading\n"); #if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH) if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR)) { fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool)); return 0; } #endif #if defined(ENABLE_APPDATA) && defined(APPDATA_PATH) if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR)) { fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool)); return 0; } #endif ofp = fopen(calc_cachepath(repo, 0, 0), "r"); if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR)) { fprintf(stderr, "installed db: %s\n", pool_errstr(pool)); return 0; } if (ofp) fclose(ofp); repo_internalize(repo); writecachedrepo(cinfo, 0, 0); return 1; } void commit_transactionelement_rpm(Pool *pool, Id type, Id p, FILE *fp) { Solvable *s = pool_id2solvable(pool, p); const char *rootdir = pool_get_rootdir(pool); const char *evr, *evrp, *nvra; switch(type) { case SOLVER_TRANSACTION_ERASE: if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start]) break; /* strip epoch from evr */ evr = evrp = pool_id2str(pool, s->evr); while (*evrp >= '0' && *evrp <= '9') evrp++; if (evrp > evr && evrp[0] == ':' && evrp[1]) evr = evrp + 1; nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr); nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch)); runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */ break; case SOLVER_TRANSACTION_INSTALL: case SOLVER_TRANSACTION_MULTIINSTALL: rewind(fp); lseek(fileno(fp), 0, SEEK_SET); runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir); break; default: break; } } #endif
the_stack_data/29823997.c
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <ctype.h> //문자관련 함수들. 레퍼런스 더 참고해보기 int main(void) { char ch; while ((ch = getchar()) != '\n') { if (islower(ch)) { ch = toupper(ch); } else if (isupper(ch)) { ch = tolower(ch); }; putchar(ch); }; }
the_stack_data/68887949.c
void fence() { asm("sync"); } void lwfence() { asm("lwsync"); } void isync() { asm("isync"); } int __unbuffered_cnt=0; int __unbuffered_p0_EAX=0; int __unbuffered_p1_EAX=0; int __unbuffered_p3_EAX=0; int __unbuffered_p3_EBX=0; int a=0; int x=0; int y=0; int z=0; void * P0(void * arg) { a = 1; __unbuffered_p0_EAX = x; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void * P1(void * arg) { x = 1; __unbuffered_p1_EAX = y; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void * P2(void * arg) { y = 1; z = 1; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void * P3(void * arg) { z = 2; __unbuffered_p3_EAX = z; __unbuffered_p3_EBX = a; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } int main() { __CPROVER_ASYNC_0: P0(0); __CPROVER_ASYNC_1: P1(0); __CPROVER_ASYNC_2: P2(0); __CPROVER_ASYNC_3: P3(0); __CPROVER_assume(__unbuffered_cnt==4); fence(); // EXPECT:exists __CPROVER_assert(!(z==2 && __unbuffered_p0_EAX==0 && __unbuffered_p1_EAX==0 && __unbuffered_p3_EAX==2 && __unbuffered_p3_EBX==0), "Program proven to be relaxed for X86, model checker says YES."); return 0; }
the_stack_data/1022858.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. */ int b = 8; int *test() { static int a = 3; a++; return &a; } int main() { int c = 4; return *test() + 8 + c; }
the_stack_data/154874.c
#include <stdio.h> main() { #define N 10 int a[N]; /* The length of the array can be specified by any (integer) constant expressions. Since array lengths may need to be adjusted when the program is later changed, using a macro to define the length of an array is an excellent practice. */ for (int i = 0; i < N; i++) { a[i] = 0; // initailize a } for (int i = 0; i < N; i++) { scanf("%d", &a[i]); // reads data into a } for (int i = 0, sum = 0; i < N; i++) { sum += a[i]; // sums the elements of a } }
the_stack_data/34514074.c
// This function is called from assembly code in callCFunc.s: int cFunc(int input){ return input * 2; // Must do something, to ensure function call worked } // For Cross platform compatibility Linux <-> Mac OSX : int _cFunc(int input){ return cFunc(input); }
the_stack_data/12349.c
#include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <limits.h> typedef struct stack_t stack_t; typedef struct list_t list_t; typedef struct node_t node_t; stack_t* newStack(); list_t* newList(); node_t* newNode(int value); //Stack bool isStackEmpty(stack_t *stack); bool isFull(stack_t *stack); int cap(stack_t *stack); int size(stack_t *stack); list_t* peek(stack_t *stack); void push(stack_t *stack, list_t *list); void pop(stack_t *stack); void destroyStack(stack_t *stack); //List void printarLista(list_t *list); bool isListEmpty(list_t *list); void insertBack(list_t *list, int value); void remov(list_t *list); void destroyList(list_t *list); int main() { char comando[30]; stack_t *stack = newStack(); while (scanf("%[^\n]", comando) != EOF) { getchar(); if (strcmp(comando, "PUSH") == 0) { list_t *temp = newList(); //Lê a lista push(stack, temp); } else { if (isStackEmpty(stack)) { printf("EMPTY STACK\n"); } else { list_t *temp = peek(stack); printarLista(temp); pop(stack); } } strcpy(comando, ""); } destroyStack(stack); return(0); } struct stack_t { int cap; int size; list_t *top; }; struct node_t { int value; node_t *next; }; struct list_t { int size; node_t *head; node_t *tail; list_t *bot; }; stack_t* newStack() { stack_t *temp = malloc(1 * sizeof(stack_t)); temp->cap = INT_MAX; temp->size = 0; return(temp); } node_t* newNode(int value) { node_t *temp = malloc(1 * sizeof(node_t)); temp->value = value; temp->next = NULL; return(temp); } bool isStackEmpty(stack_t *stack) { return(!stack->size); } bool isFull(stack_t *stack) { return(stack->size == stack->cap); } int cap(stack_t *stack) { return(stack->cap); } int size(stack_t *stack) { return(stack->size); } list_t* peek(stack_t *stack) { return(stack->top); } void push(stack_t *stack, list_t *list) { if (isFull(stack)) return; if (isStackEmpty(stack)) { stack->top = list; } else { list->bot = stack->top; stack->top = list; } stack->size ++; } void pop(stack_t *stack) { if (isStackEmpty(stack)) return; list_t *temp = stack->top; stack->top = stack->top->bot; destroyList(temp); stack->size --; } void destroyStack(stack_t *stack) { while (!isStackEmpty(stack)) pop(stack); free(stack); } //List list_t* newList() //Lê e cria uma nova lista { list_t *temp = malloc(1 * sizeof(list_t)); temp->size = 0; int value; char end; while (scanf("%d%c", &value, &end) != EOF && end != '\n') { insertBack(temp, value); } insertBack(temp, value); return(temp); } void printarLista(list_t *list) { int i; node_t *curr = list->head; for (i = 0; i < list->size - 1; i ++) { printf("%d ", curr->value); curr = curr->next; } printf("%d\n", curr->value); } bool isListEmpty(list_t *list) { return(!list->size); } void insertBack(list_t *list, int value) { node_t *temp = newNode(value); if (isListEmpty(list)) { list->head = temp; list->tail = temp; } else { list->tail->next = temp; list->tail = temp; } list->size ++; } void remov(list_t *list) { if (isListEmpty(list)) return; node_t *temp = list->head; list->head = list->head->next; free(temp); list->size --; } void destroyList(list_t *list) { while (!isListEmpty(list)) remov(list); free(list); }
the_stack_data/565656.c
// RUN: %clang -target armv8a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A %s // CHECK-V8A: #define __ARMEL__ 1 // CHECK-V8A: #define __ARM_ARCH 8 // CHECK-V8A: #define __ARM_ARCH_8A__ 1 // CHECK-V8A: #define __ARM_FEATURE_CRC32 1 // CHECK-V8A: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8A: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8A: #define __ARM_FP 0xe // CHECK-V8A: #define __ARM_FP16_ARGS 1 // CHECK-V8A: #define __ARM_FP16_FORMAT_IEEE 1 // RUN: %clang -target armv8r-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R %s // CHECK-V8R: #define __ARMEL__ 1 // CHECK-V8R: #define __ARM_ARCH 8 // CHECK-V8R: #define __ARM_ARCH_8R__ 1 // CHECK-V8R: #define __ARM_FEATURE_CRC32 1 // CHECK-V8R: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8R: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8R: #define __ARM_FP 0xe // RUN: %clang -target armv7a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7 %s // CHECK-V7: #define __ARMEL__ 1 // CHECK-V7: #define __ARM_ARCH 7 // CHECK-V7: #define __ARM_ARCH_7A__ 1 // CHECK-V7-NOT: __ARM_FEATURE_CRC32 // CHECK-V7-NOT: __ARM_FEATURE_NUMERIC_MAXMIN // CHECK-V7-NOT: __ARM_FEATURE_DIRECTED_ROUNDING // CHECK-V7: #define __ARM_FP 0xc // RUN: %clang -target armv7ve-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE %s // CHECK-V7VE: #define __ARMEL__ 1 // CHECK-V7VE: #define __ARM_ARCH 7 // CHECK-V7VE: #define __ARM_ARCH_7VE__ 1 // CHECK-V7VE: #define __ARM_ARCH_EXT_IDIV__ 1 // CHECK-V7VE: #define __ARM_FP 0xc // RUN: %clang -target x86_64-apple-macosx10.10 -arch armv7s -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7S %s // CHECK-V7S: #define __ARMEL__ 1 // CHECK-V7S: #define __ARM_ARCH 7 // CHECK-V7S: #define __ARM_ARCH_7S__ 1 // CHECK-V7S-NOT: __ARM_FEATURE_CRC32 // CHECK-V7S-NOT: __ARM_FEATURE_NUMERIC_MAXMIN // CHECK-V7S-NOT: __ARM_FEATURE_DIRECTED_ROUNDING // CHECK-V7S: #define __ARM_FP 0xe // RUN: %clang -target armv8a -mfloat-abi=hard -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF %s // CHECK-V8-BAREHF: #define __ARMEL__ 1 // CHECK-V8-BAREHF: #define __ARM_ARCH 8 // CHECK-V8-BAREHF: #define __ARM_ARCH_8A__ 1 // CHECK-V8-BAREHF: #define __ARM_FEATURE_CRC32 1 // CHECK-V8-BAREHF: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8-BAREHF: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8-BAREHP: #define __ARM_FP 0xe // CHECK-V8-BAREHF: #define __ARM_NEON__ 1 // CHECK-V8-BAREHF: #define __ARM_PCS_VFP 1 // CHECK-V8-BAREHF: #define __VFP_FP__ 1 // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-FP %s // CHECK-V8-BAREHF-FP-NOT: __ARM_NEON__ 1 // CHECK-V8-BAREHP-FP: #define __ARM_FP 0xe // CHECK-V8-BAREHF-FP: #define __VFP_FP__ 1 // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=neon-fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-NEON-FP %s // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=crypto-neon-fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-NEON-FP %s // CHECK-V8-BAREHP-NEON-FP: #define __ARM_FP 0xe // CHECK-V8-BAREHF-NEON-FP: #define __ARM_NEON__ 1 // CHECK-V8-BAREHF-NEON-FP: #define __VFP_FP__ 1 // RUN: %clang -target armv8a -mnocrc -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-NOCRC %s // CHECK-V8-NOCRC-NOT: __ARM_FEATURE_CRC32 1 // Check that -mhwdiv works properly for armv8/thumbv8 (enabled by default). // RUN: %clang -target armv8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // RUN: %clang -target armv8 -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // RUN: %clang -target armv8-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // RUN: %clang -target armv8-eabi -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // V8:#define __ARM_ARCH_EXT_IDIV__ 1 // RUN: %clang -target armv8 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // RUN: %clang -target armv8 -mthumb -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // RUN: %clang -target armv8 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // RUN: %clang -target armv8 -mthumb -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // NOHWDIV-V8-NOT:#define __ARM_ARCH_EXT_IDIV__ // RUN: %clang -target armv8a -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s // RUN: %clang -target armv8a -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s // RUN: %clang -target armv8a-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s // RUN: %clang -target armv8a-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s // V8A:#define __ARM_ARCH_EXT_IDIV__ 1 // V8A:#define __ARM_FP 0xe // RUN: %clang -target armv8m.base-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_BASELINE %s // V8M_BASELINE: #define __ARM_ARCH 8 // V8M_BASELINE: #define __ARM_ARCH_8M_BASE__ 1 // V8M_BASELINE: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M_BASELINE-NOT: __ARM_ARCH_ISA_ARM // V8M_BASELINE: #define __ARM_ARCH_ISA_THUMB 1 // V8M_BASELINE: #define __ARM_ARCH_PROFILE 'M' // V8M_BASELINE-NOT: __ARM_FEATURE_CRC32 // V8M_BASELINE-NOT: __ARM_FEATURE_DSP // V8M_BASELINE-NOT: __ARM_FP 0x{{.*}} // V8M_BASELINE-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 // RUN: %clang -target armv8m.main-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_MAINLINE %s // V8M_MAINLINE: #define __ARM_ARCH 8 // V8M_MAINLINE: #define __ARM_ARCH_8M_MAIN__ 1 // V8M_MAINLINE: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M_MAINLINE-NOT: __ARM_ARCH_ISA_ARM // V8M_MAINLINE: #define __ARM_ARCH_ISA_THUMB 2 // V8M_MAINLINE: #define __ARM_ARCH_PROFILE 'M' // V8M_MAINLINE-NOT: __ARM_FEATURE_CRC32 // V8M_MAINLINE-NOT: __ARM_FEATURE_DSP // V8M_MAINLINE: #define __ARM_FP 0xe // V8M_MAINLINE: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // RUN: %clang -target arm-none-linux-gnu -march=armv8-m.main+dsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_MAINLINE_DSP %s // V8M_MAINLINE_DSP: #define __ARM_ARCH 8 // V8M_MAINLINE_DSP: #define __ARM_ARCH_8M_MAIN__ 1 // V8M_MAINLINE_DSP: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M_MAINLINE_DSP-NOT: __ARM_ARCH_ISA_ARM // V8M_MAINLINE_DSP: #define __ARM_ARCH_ISA_THUMB 2 // V8M_MAINLINE_DSP: #define __ARM_ARCH_PROFILE 'M' // V8M_MAINLINE_DSP-NOT: __ARM_FEATURE_CRC32 // V8M_MAINLINE_DSP: #define __ARM_FEATURE_DSP 1 // V8M_MAINLINE_DSP: #define __ARM_FP 0xe // V8M_MAINLINE_DSP: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // RUN: %clang -target arm-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DEFS %s // CHECK-DEFS:#define __ARM_PCS 1 // CHECK-DEFS:#define __ARM_SIZEOF_MINIMAL_ENUM 4 // CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4 // RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\ // RUN: -fno-trapping-math -fassociative-math -freciprocal-math\ // RUN: -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s // RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\ // RUN: | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s // CHECK-FASTMATH: #define __ARM_FP_FAST 1 // RUN: %clang -target arm-none-linux-gnu -fshort-wchar -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-SHORTWCHAR %s // CHECK-SHORTWCHAR:#define __ARM_SIZEOF_WCHAR_T 2 // RUN: %clang -target arm-none-linux-gnu -fshort-enums -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-SHORTENUMS %s // CHECK-SHORTENUMS:#define __ARM_SIZEOF_MINIMAL_ENUM 1 // Test that -mhwdiv has the right effect for a target CPU which has hwdiv enabled by default. // RUN: %clang -target armv7 -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // RUN: %clang -target armv7 -mcpu=cortex-a15 -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // HWDIV:#define __ARM_ARCH_EXT_IDIV__ 1 // RUN: %clang -target arm -mcpu=cortex-a15 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // RUN: %clang -target arm -mthumb -mcpu=cortex-a15 -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // RUN: %clang -target arm -mcpu=cortex-a15 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // RUN: %clang -target arm -mthumb -mcpu=cortex-a15 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // NOHWDIV-NOT:#define __ARM_ARCH_EXT_IDIV__ // Check that -mfpu works properly for Cortex-A7 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s // DEFAULTFPU-A7:#define __ARM_FP 0xe // DEFAULTFPU-A7:#define __ARM_NEON__ 1 // DEFAULTFPU-A7:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A7 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A7 %s // FPUNONE-A7-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A7-NOT:#define __ARM_NEON__ 1 // FPUNONE-A7-NOT:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A7 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A7 %s // NONEON-A7:#define __ARM_FP 0xe // NONEON-A7-NOT:#define __ARM_NEON__ 1 // NONEON-A7:#define __ARM_VFPV4__ 1 // Check that -mfpu works properly for Cortex-A5 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A5 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A5 %s // DEFAULTFPU-A5:#define __ARM_FP 0xe // DEFAULTFPU-A5:#define __ARM_NEON__ 1 // DEFAULTFPU-A5:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A5 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A5 %s // FPUNONE-A5-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A5-NOT:#define __ARM_NEON__ 1 // FPUNONE-A5-NOT:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -mfpu=vfp4-d16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A5 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -mfpu=vfp4-d16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A5 %s // NONEON-A5:#define __ARM_FP 0xe // NONEON-A5-NOT:#define __ARM_NEON__ 1 // NONEON-A5:#define __ARM_VFPV4__ 1 // FIXME: add check for further predefines // Test whether predefines are as expected when targeting ep9312. // RUN: %clang -target armv4t -mcpu=ep9312 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A4T %s // A4T-NOT:#define __ARM_FEATURE_DSP // A4T-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting arm10tdmi. // RUN: %clang -target armv5 -mcpu=arm10tdmi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5T %s // A5T-NOT:#define __ARM_FEATURE_DSP // A5T-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-a5. // RUN: %clang -target armv7 -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5 %s // A5:#define __ARM_ARCH 7 // A5:#define __ARM_ARCH_7A__ 1 // A5-NOT:#define __ARM_ARCH_EXT_IDIV__ // A5:#define __ARM_ARCH_PROFILE 'A' // A5-NOT:#define __ARM_DWARF_EH__ 1 // A5-NOT: #define __ARM_FEATURE_DIRECTED_ROUNDING // A5:#define __ARM_FEATURE_DSP 1 // A5-NOT: #define __ARM_FEATURE_NUMERIC_MAXMIN // A5:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-a7. // RUN: %clang -target armv7k -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7 %s // RUN: %clang -target armv7k -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7 %s // A7:#define __ARM_ARCH 7 // A7:#define __ARM_ARCH_EXT_IDIV__ 1 // A7:#define __ARM_ARCH_PROFILE 'A' // A7-NOT:#define __ARM_DWARF_EH__ 1 // A7:#define __ARM_FEATURE_DSP 1 // A7:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-a7. // RUN: %clang -target x86_64-apple-darwin -arch armv7k -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV7K %s // ARMV7K:#define __ARM_ARCH 7 // ARMV7K:#define __ARM_ARCH_EXT_IDIV__ 1 // ARMV7K:#define __ARM_ARCH_PROFILE 'A' // ARMV7K:#define __ARM_DWARF_EH__ 1 // ARMV7K:#define __ARM_FEATURE_DSP 1 // ARMV7K:#define __ARM_FP 0xe // ARMV7K:#define __ARM_PCS_VFP 1 // Test whether predefines are as expected when targeting cortex-a8. // RUN: %clang -target armv7 -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8 %s // A8-NOT:#define __ARM_ARCH_EXT_IDIV__ // A8:#define __ARM_FEATURE_DSP 1 // A8:#define __ARM_FP 0xc // Test whether predefines are as expected when targeting cortex-a9. // RUN: %clang -target armv7 -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9 %s // A9-NOT:#define __ARM_ARCH_EXT_IDIV__ // A9:#define __ARM_FEATURE_DSP 1 // A9:#define __ARM_FP 0xe // Check that -mfpu works properly for Cortex-A12 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A12 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A12 %s // DEFAULTFPU-A12:#define __ARM_FP 0xe // DEFAULTFPU-A12:#define __ARM_NEON__ 1 // DEFAULTFPU-A12:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a12 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A12 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a12 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A12 %s // FPUNONE-A12-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A12-NOT:#define __ARM_NEON__ 1 // FPUNONE-A12-NOT:#define __ARM_VFPV4__ 1 // Test whether predefines are as expected when targeting cortex-a12. // RUN: %clang -target armv7 -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12 %s // A12:#define __ARM_ARCH 7 // A12:#define __ARM_ARCH_7A__ 1 // A12:#define __ARM_ARCH_EXT_IDIV__ 1 // A12:#define __ARM_ARCH_PROFILE 'A' // A12:#define __ARM_FEATURE_DSP 1 // A12:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-a15. // RUN: %clang -target armv7 -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15 %s // A15:#define __ARM_ARCH_EXT_IDIV__ 1 // A15:#define __ARM_FEATURE_DSP 1 // A15:#define __ARM_FP 0xe // Check that -mfpu works properly for Cortex-A17 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A17 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A17 %s // DEFAULTFPU-A17:#define __ARM_FP 0xe // DEFAULTFPU-A17:#define __ARM_NEON__ 1 // DEFAULTFPU-A17:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a17 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A17 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a17 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A17 %s // FPUNONE-A17-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A17-NOT:#define __ARM_NEON__ 1 // FPUNONE-A17-NOT:#define __ARM_VFPV4__ 1 // Test whether predefines are as expected when targeting cortex-a17. // RUN: %clang -target armv7 -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17 %s // A17:#define __ARM_ARCH 7 // A17:#define __ARM_ARCH_7A__ 1 // A17:#define __ARM_ARCH_EXT_IDIV__ 1 // A17:#define __ARM_ARCH_PROFILE 'A' // A17:#define __ARM_FEATURE_DSP 1 // A17:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting swift. // RUN: %clang -target armv7s -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT %s // RUN: %clang -target armv7s -mthumb -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT %s // SWIFT:#define __ARM_ARCH_EXT_IDIV__ 1 // SWIFT:#define __ARM_FEATURE_DSP 1 // SWIFT:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting ARMv8-A Cortex implementations // RUN: %clang -target armv8 -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // ARMV8:#define __ARM_ARCH_EXT_IDIV__ 1 // ARMV8:#define __ARM_FEATURE_DSP 1 // ARMV8:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-r4. // RUN: %clang -target armv7 -mcpu=cortex-r4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4-ARM %s // R4-ARM-NOT:#define __ARM_ARCH_EXT_IDIV__ // R4-ARM:#define __ARM_FEATURE_DSP 1 // R4-ARM-NOT:#define __ARM_FP 0x{{.*}} // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4-THUMB %s // R4-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // R4-THUMB:#define __ARM_FEATURE_DSP 1 // R4-THUMB-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-r4f. // RUN: %clang -target armv7 -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-ARM %s // R4F-ARM-NOT:#define __ARM_ARCH_EXT_IDIV__ // R4F-ARM:#define __ARM_FEATURE_DSP 1 // R4F-ARM:#define __ARM_FP 0xc // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-THUMB %s // R4F-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // R4F-THUMB:#define __ARM_FEATURE_DSP 1 // R4F-THUMB:#define __ARM_FP 0xc // Test whether predefines are as expected when targeting cortex-r5. // RUN: %clang -target armv7 -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5 %s // R5:#define __ARM_ARCH_EXT_IDIV__ 1 // R5:#define __ARM_FEATURE_DSP 1 // R5:#define __ARM_FP 0xc // Test whether predefines are as expected when targeting cortex-r7 and cortex-r8. // RUN: %clang -target armv7 -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // RUN: %clang -target armv7 -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // R7-R8:#define __ARM_ARCH_EXT_IDIV__ 1 // R7-R8:#define __ARM_FEATURE_DSP 1 // R7-R8:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-m0. // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m0 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m0plus -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=sc000 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // M0-THUMB-NOT:#define __ARM_ARCH_EXT_IDIV__ // M0-THUMB-NOT:#define __ARM_FEATURE_DSP // M0-THUMB-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-m3. // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M3-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=sc300 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M3-THUMB %s // M3-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // M3-THUMB-NOT:#define __ARM_FEATURE_DSP // M3-THUMB-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-m4. // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M4-THUMB %s // M4-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // M4-THUMB:#define __ARM_FEATURE_DSP 1 // M4-THUMB:#define __ARM_FP 0x6 // Test whether predefines are as expected when targeting cortex-m7. // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M7-THUMB %s // M7-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // M7-THUMB:#define __ARM_FEATURE_DSP 1 // M7-THUMB:#define __ARM_FP 0xe // M7-THUMB:#define __ARM_FPV5__ 1 // Test whether predefines are as expected when targeting v8m cores // RUN: %clang -target arm -mcpu=cortex-m23 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M23 %s // M23: #define __ARM_ARCH 8 // M23: #define __ARM_ARCH_8M_BASE__ 1 // M23: #define __ARM_ARCH_EXT_IDIV__ 1 // M23-NOT: __ARM_ARCH_ISA_ARM // M23: #define __ARM_ARCH_ISA_THUMB 1 // M23: #define __ARM_ARCH_PROFILE 'M' // M23-NOT: __ARM_FEATURE_CRC32 // M23-NOT: __ARM_FEATURE_DSP // M23-NOT: __ARM_FP 0x{{.*}} // M23-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 // RUN: %clang -target arm -mcpu=cortex-m33 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M33 %s // M33: #define __ARM_ARCH 8 // M33: #define __ARM_ARCH_8M_MAIN__ 1 // M33: #define __ARM_ARCH_EXT_IDIV__ 1 // M33-NOT: __ARM_ARCH_ISA_ARM // M33: #define __ARM_ARCH_ISA_THUMB 2 // M33: #define __ARM_ARCH_PROFILE 'M' // M33-NOT: __ARM_FEATURE_CRC32 // M33: #define __ARM_FEATURE_DSP 1 // M33: #define __ARM_FP 0x6 // M33: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // Test whether predefines are as expected when targeting krait. // RUN: %clang -target armv7 -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT %s // RUN: %clang -target armv7 -mthumb -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT %s // KRAIT:#define __ARM_ARCH_EXT_IDIV__ 1 // KRAIT:#define __ARM_FEATURE_DSP 1 // KRAIT:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81A %s // CHECK-V81A: #define __ARM_ARCH 8 // CHECK-V81A: #define __ARM_ARCH_8_1A__ 1 // CHECK-V81A: #define __ARM_ARCH_PROFILE 'A' // CHECK-V81A: #define __ARM_FEATURE_QRDMX 1 // CHECK-V81A: #define __ARM_FP 0xe // RUN: %clang -target armv8.2a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V82A %s // CHECK-V82A: #define __ARM_ARCH 8 // CHECK-V82A: #define __ARM_ARCH_8_2A__ 1 // CHECK-V82A: #define __ARM_ARCH_PROFILE 'A' // CHECK-V82A: #define __ARM_FEATURE_QRDMX 1 // CHECK-V82A: #define __ARM_FP 0xe
the_stack_data/203897.c
#include<stdio.h> #include<string.h> int digit(char); int main(){ char num[1000]; int i=0; long int number =0; printf("s="); scanf("%s",num); while(num[i]){ if(digit(num[i]) >= digit(num[i+1])) number = number + digit(num[i]); else{ number = number + (digit(num[i+1]) - digit(num[i])); i++; } i++; } printf("%ld",number); return 0; } int digit(char c){ int value=0; switch(c){ case 'I': value = 1; break; case 'V': value = 5; break; case 'X': value = 10; break; case 'L': value = 50; break; case 'C': value = 100; break; case 'D': value = 500; break; case 'M': value = 1000; break; default: value = -1; } return value; }
the_stack_data/48574567.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern void signal(int sig , void *func ) ; extern float strtof(char const *str , char const *endptr ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned int input[1] , unsigned int output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; int main(int argc , char *argv[] ) { unsigned int input[1] ; unsigned int output[1] ; int randomFuns_i5 ; unsigned int randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned int )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 968801766U) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned int input[1] , unsigned int output[1] ) { unsigned int state[1] ; char copy11 ; { state[0UL] = input[0UL] ^ 700325083U; if ((state[0UL] >> 4U) & 1U) { copy11 = *((char *)(& state[0UL]) + 1); *((char *)(& state[0UL]) + 1) = *((char *)(& state[0UL]) + 0); *((char *)(& state[0UL]) + 0) = copy11; copy11 = *((char *)(& state[0UL]) + 0); *((char *)(& state[0UL]) + 0) = *((char *)(& state[0UL]) + 1); *((char *)(& state[0UL]) + 1) = copy11; } output[0UL] = state[0UL] | 293908934UL; } } void megaInit(void) { { } }