file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/154831176.c
/* cdiff - context diff Author: Larry Wall */ /* Cdiff - turns a regular diff into a new-style context diff * * Usage: cdiff file1 file2 */ #define PATCHLEVEL 2 #include <sys/types.h> #include <sys/stat.h> #include <ctype.h> #include <stdio.h> char buff[512]; FILE *inputfp, *oldfp, *newfp; char *ctime(); int oldmin, oldmax, newmin, newmax; int oldbeg, oldend, newbeg, newend; int preoldmax, prenewmax; int preoldbeg, preoldend, prenewbeg, prenewend; int oldwanted, newwanted; char *oldhunk, *newhunk; unsigned oldsize, oldalloc, newsize, newalloc; void dumphunk(); char *getold(); char *getnew(); char *malloc(); char *realloc(); char *fgets(); FILE *popen(); #define Nullfp (FILE*)0 #define Nullch (char*)0 main(argc, argv) int argc; char **argv; { char *old, *new; int context = 3; struct stat statbuf; register char *s; char op; char *newmark, *oldmark; int len; char *line; int i; oldalloc = 512; oldhunk = malloc(oldalloc); newalloc = 512; newhunk = malloc(newalloc); for (argc--, argv++; argc; argc--, argv++) { if (argv[0][0] != '-') break; if (argv[0][1] == 'c') context = atoi(argv[0] + 2); } if (argc != 2) { fprintf(stderr, "Usage: cdiff old new\n"); exit(1); } old = argv[0]; new = argv[1]; sprintf(buff, "diff %s %s", old, new); inputfp = popen(buff, "r"); if (!inputfp) { fprintf(stderr, "Can't execute diff %s %s\n", old, new); exit(1); } oldfp = fopen(old, "r"); if (!oldfp) { fprintf(stderr, "Can't open %s\n", old); exit(1); } newfp = fopen(new, "r"); if (!newfp) { fprintf(stderr, "Can't open %s\n", new); exit(1); } fstat(fileno(oldfp), &statbuf); printf("*** %s\t%s", old, ctime(&statbuf.st_mtime)); fstat(fileno(newfp), &statbuf); printf("--- %s\t%s", new, ctime(&statbuf.st_mtime)); preoldend = -1000; while (fgets(buff, sizeof buff, inputfp) != Nullch) { if (isdigit(*buff)) { oldmin = atoi(buff); for (s = buff; isdigit(*s); s++); if (*s == ',') { s++; oldmax = atoi(s); for (; isdigit(*s); s++); } else { oldmax = oldmin; } if (*s != 'a' && *s != 'd' && *s != 'c') { fprintf(stderr, "Unparseable input: %s", s); exit(1); } op = *s; s++; newmin = atoi(s); for (; isdigit(*s); s++); if (*s == ',') { s++; newmax = atoi(s); for (; isdigit(*s); s++); } else { newmax = newmin; } if (*s != '\n' && *s != ' ') { fprintf(stderr, "Unparseable input: %s", s); exit(1); } newmark = oldmark = "! "; if (op == 'a') { oldmin++; newmark = "+ "; } if (op == 'd') { newmin++; oldmark = "- "; } oldbeg = oldmin - context; oldend = oldmax + context; if (oldbeg < 1) oldbeg = 1; newbeg = newmin - context; newend = newmax + context; if (newbeg < 1) newbeg = 1; if (preoldend < oldbeg - 1) { if (preoldend >= 0) { dumphunk(); } preoldbeg = oldbeg; prenewbeg = newbeg; oldwanted = newwanted = 0; oldsize = newsize = 0; } else { /* we want to append to previous hunk */ oldbeg = preoldmax + 1; newbeg = prenewmax + 1; } for (i = oldbeg; i <= oldmax; i++) { line = getold(i); if (!*line) { oldend = oldmax = i - 1; break; } len = strlen(line) + 2; if (oldsize + len + 1 >= oldalloc) { oldalloc *= 2; oldhunk = realloc(oldhunk, oldalloc); } if (i >= oldmin) { strcpy(oldhunk + oldsize, oldmark); oldwanted++; } else { strcpy(oldhunk + oldsize, " "); } strcpy(oldhunk + oldsize + 2, line); oldsize += len; } preoldmax = oldmax; preoldend = oldend; for (i = newbeg; i <= newmax; i++) { line = getnew(i); if (!*line) { newend = newmax = i - 1; break; } len = strlen(line) + 2; if (newsize + len + 1 >= newalloc) { newalloc *= 2; newhunk = realloc(newhunk, newalloc); } if (i >= newmin) { strcpy(newhunk + newsize, newmark); newwanted++; } else { strcpy(newhunk + newsize, " "); } strcpy(newhunk + newsize + 2, line); newsize += len; } prenewmax = newmax; prenewend = newend; } } if (preoldend >= 0) { dumphunk(); } } void dumphunk() { int i; char *line; int len; for (i = preoldmax + 1; i <= preoldend; i++) { line = getold(i); if (!line) { preoldend = i - 1; break; } len = strlen(line) + 2; if (oldsize + len + 1 >= oldalloc) { oldalloc *= 2; oldhunk = realloc(oldhunk, oldalloc); } strcpy(oldhunk + oldsize, " "); strcpy(oldhunk + oldsize + 2, line); oldsize += len; } for (i = prenewmax + 1; i <= prenewend; i++) { line = getnew(i); if (!line) { prenewend = i - 1; break; } len = strlen(line) + 2; if (newsize + len + 1 >= newalloc) { newalloc *= 2; newhunk = realloc(newhunk, newalloc); } strcpy(newhunk + newsize, " "); strcpy(newhunk + newsize + 2, line); newsize += len; } fputs("***************\n", stdout); if (preoldbeg >= preoldend) { printf("*** %d ****\n", preoldend); } else { printf("*** %d,%d ****\n", preoldbeg, preoldend); } if (oldwanted) { fputs(oldhunk, stdout); } oldsize = 0; *oldhunk = '\0'; if (prenewbeg >= prenewend) { printf("--- %d ----\n", prenewend); } else { printf("--- %d,%d ----\n", prenewbeg, prenewend); } if (newwanted) { fputs(newhunk, stdout); } newsize = 0; *newhunk = '\0'; } char * getold(targ) int targ; { static int oldline = 0; while (fgets(buff, sizeof buff, oldfp) != Nullch) { oldline++; if (oldline == targ) return buff; } return Nullch; } char * getnew(targ) int targ; { static int newline = 0; while (fgets(buff, sizeof buff, newfp) != Nullch) { newline++; if (newline == targ) return buff; } return Nullch; }
the_stack_data/126703189.c
/* ****************************************************************** ** ** OpenSees - Open System for Earthquake Engineering Simulation ** ** Pacific Earthquake Engineering Research Center ** ** ** ** ** ** (C) Copyright 1999, The Regents of the University of California ** ** All Rights Reserved. ** ** ** ** Commercial use of this program without express permission of the ** ** University of California, Berkeley, is strictly prohibited. See ** ** file 'COPYRIGHT' in main directory for information on usage and ** ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. ** ** ** ** Developed by: ** ** Frank McKenna ([email protected]) ** ** Gregory L. Fenves ([email protected]) ** ** Filip C. Filippou ([email protected]) ** ** ** ** ****************************************************************** */ // $Revision: 1.1.1.1 $ // $Date: 2000-09-15 08:23:25 $ // $Source: /usr/local/cvs/OpenSees/SRC/remote/remote.c,v $ /* File: ~/bin/remote.c ** ** Written: fmk 10/96 ** Rev: ** ** Purpose: To start a process running on a remote machine ** ** usage: remote machine program host_Inet_Address ** ** machine and program being character strings. */ #include <stdio.h> #include <string.h> char remotecmd[400]; main(int argv, char **argc) { int chilpid,i,j; /* now get remote program running */ strcpy(remotecmd,"ssh "); for (i =1; i <argv; i++) { strcat(remotecmd,argc[i]); strcat(remotecmd," "); } fprintf(stderr,"%s\n",remotecmd); /* This is an expensive hack to make this work */ if ( (chilpid = fork()) < 0) { /* FORK !! - hopefully done */ fprintf(stderr,"REMOTE: could not fork"); exit(-1); } if (chilpid == 0) { system(remotecmd); exit(0); } exit(0); }
the_stack_data/127917.c
#include <math.h> void kendl1(float data1[], float data2[], unsigned long n, float *tau, float *z, float *prob) { float erfcc(float x); unsigned long n2=0,n1=0,k,j; long is=0; float svar,aa,a2,a1; for (j=1;j<n;j++) { for (k=(j+1);k<=n;k++) { a1=data1[j]-data1[k]; a2=data2[j]-data2[k]; aa=a1*a2; if (aa) { ++n1; ++n2; aa > 0.0 ? ++is : --is; } else { if (a1) ++n1; if (a2) ++n2; } } } *tau=is/(sqrt((double) n1)*sqrt((double) n2)); svar=(4.0*n+10.0)/(9.0*n*(n-1.0)); *z=(*tau)/sqrt(svar); *prob=erfcc(fabs(*z)/1.4142136); }
the_stack_data/162641917.c
#include <stdio.h> void merge(int a[], int i1, int j1, int i2, int j2) { int tmp[50]; int i,j,k; i=i1, j=i2, k=0; while(i <= j1 && j <= j2) { if(a[i] < a[j]) tmp[k++] = a[i++]; else tmp[k++] = a[j++]; } while(i <= j1) tmp[k++] = a[i++]; while(j <= j2) tmp[k++] = a[j++]; for(i=i1, j=0; i <= j2; i++, j++) { a[i] = tmp[j]; } } void mergesort(int a[], int low, int high) { int mid; if(low < high) { mid=(low+high)/2; mergesort(a, low, mid); mergesort(a, mid+1, high); merge(a, low, mid, mid+1, high); } } int main() { int a[100], n, i; printf("Enter element number:"); scanf("%d", &n); printf("Enter array elements:"); for(i=0; i < n; i++) scanf("%d", &a[i]); mergesort(a, 0, n-1); for(i=0; i < n; i++) printf("%d ", a[i]); return 0; }
the_stack_data/54826178.c
// RUN: %clang -target x86_64-unknown-unknown -ccc-print-phases -extract-api %s 2> %t // RUN: echo 'END' >> %t // RUN: FileCheck -check-prefix EXTRACT-API-PHASES -input-file %t %s // EXTRACT-API-PHASES: 0: input, // EXTRACT-API-PHASES: , c // EXTRACT-API-PHASES: 1: preprocessor, {0}, cpp-output // EXTRACT-API-PHASES: 2: compiler, {1}, api-information // EXTRACT-API-PHASES-NOT: 3: // EXTRACT-API-PHASES: END // FIXME: Check for the dummy output now to verify that the custom action was executed. // RUN: %clang -extract-api %s | FileCheck -check-prefix DUMMY-OUTPUT %s void dummy_function(void); // DUMMY-OUTPUT: dummy_function
the_stack_data/16924.c
#include <stdio.h> int main() { int a = 0; int b = 0; int c = 0; int perimeter = 0; printf("Enter side a: "); scanf("%d", &a); printf("Enter side b: "); scanf("%d", &b); printf("Enter side c: "); scanf("%d", &c); perimeter = a + b + c; printf("The perimeter is: %d", perimeter); return 0; }
the_stack_data/150219.c
#include<stdio.h> void main() { printf("Printing Numbers 1 to 100\n"); print(100); } void print(int a) { if(a == -1) { return; } else{ printf("%d\n",a); a--; print(a); } }
the_stack_data/29826072.c
/* { dg-do compile } */ /* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */ typedef float real; typedef struct { int ngtc; real *ref_t; real *tau_t; } t_grpopts; typedef struct { real T; real xi; } t_grp_tcstat; typedef struct { t_grp_tcstat *tcstat; } t_groups; extern real *save_calloc (); void nosehoover_tcoupl (t_grpopts * opts, t_groups * grps, real dt, real SAfactor) { static real *Qinv = ((void *) 0); int i; real reft = 0, xit, oldxi; if (Qinv == ((void *) 0)) { (Qinv) = save_calloc ("Qinv", "coupling.c", 372, (opts->ngtc), sizeof (*(Qinv))); for (i = 0; i < opts->ngtc; i++) if ((opts->tau_t[i] > 0)) Qinv[i] = 1.0 / opts->tau_t[i]; } for (i = 0; (i < opts->ngtc); i++) { reft = (((0.0) > (opts->ref_t[i] * SAfactor)) ? (0.0) : (opts->ref_t[i] * SAfactor)); grps->tcstat[i].xi += dt * Qinv[i] * (grps->tcstat[i].T - reft); } }
the_stack_data/76700294.c
/* Autogenerated */ /* curve description: p521 */ /* requested operations: (all) */ /* n = 9 (from "9") */ /* s-c = 2^521 - [(1, 1)] (from "2^521 - 1") */ /* machine_wordsize = 64 (from "64") */ /* Computed values: */ /* carry_chain = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1] */ #include <stdint.h> typedef unsigned char fiat_p521_uint1; typedef signed char fiat_p521_int1; typedef signed __int128 fiat_p521_int128; typedef unsigned __int128 fiat_p521_uint128; #if (-1 & 3) != 3 #error "This code only works on a two's complement system" #endif /* * The function fiat_p521_addcarryx_u58 is an addition with carry. * Postconditions: * out1 = (arg1 + arg2 + arg3) mod 2^58 * out2 = ⌊(arg1 + arg2 + arg3) / 2^58⌋ * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0x3ffffffffffffff] * arg3: [0x0 ~> 0x3ffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0x3ffffffffffffff] * out2: [0x0 ~> 0x1] */ static void fiat_p521_addcarryx_u58(uint64_t* out1, fiat_p521_uint1* out2, fiat_p521_uint1 arg1, uint64_t arg2, uint64_t arg3) { uint64_t x1 = ((arg1 + arg2) + arg3); uint64_t x2 = (x1 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint1 x3 = (fiat_p521_uint1)(x1 >> 58); *out1 = x2; *out2 = x3; } /* * The function fiat_p521_subborrowx_u58 is a subtraction with borrow. * Postconditions: * out1 = (-arg1 + arg2 + -arg3) mod 2^58 * out2 = -⌊(-arg1 + arg2 + -arg3) / 2^58⌋ * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0x3ffffffffffffff] * arg3: [0x0 ~> 0x3ffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0x3ffffffffffffff] * out2: [0x0 ~> 0x1] */ static void fiat_p521_subborrowx_u58(uint64_t* out1, fiat_p521_uint1* out2, fiat_p521_uint1 arg1, uint64_t arg2, uint64_t arg3) { int64_t x1 = ((int64_t)(arg2 - (int64_t)arg1) - (int64_t)arg3); fiat_p521_int1 x2 = (fiat_p521_int1)(x1 >> 58); uint64_t x3 = (x1 & UINT64_C(0x3ffffffffffffff)); *out1 = x3; *out2 = (fiat_p521_uint1)(0x0 - x2); } /* * The function fiat_p521_addcarryx_u57 is an addition with carry. * Postconditions: * out1 = (arg1 + arg2 + arg3) mod 2^57 * out2 = ⌊(arg1 + arg2 + arg3) / 2^57⌋ * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0x1ffffffffffffff] * arg3: [0x0 ~> 0x1ffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0x1ffffffffffffff] * out2: [0x0 ~> 0x1] */ static void fiat_p521_addcarryx_u57(uint64_t* out1, fiat_p521_uint1* out2, fiat_p521_uint1 arg1, uint64_t arg2, uint64_t arg3) { uint64_t x1 = ((arg1 + arg2) + arg3); uint64_t x2 = (x1 & UINT64_C(0x1ffffffffffffff)); fiat_p521_uint1 x3 = (fiat_p521_uint1)(x1 >> 57); *out1 = x2; *out2 = x3; } /* * The function fiat_p521_subborrowx_u57 is a subtraction with borrow. * Postconditions: * out1 = (-arg1 + arg2 + -arg3) mod 2^57 * out2 = -⌊(-arg1 + arg2 + -arg3) / 2^57⌋ * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0x1ffffffffffffff] * arg3: [0x0 ~> 0x1ffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0x1ffffffffffffff] * out2: [0x0 ~> 0x1] */ static void fiat_p521_subborrowx_u57(uint64_t* out1, fiat_p521_uint1* out2, fiat_p521_uint1 arg1, uint64_t arg2, uint64_t arg3) { int64_t x1 = ((int64_t)(arg2 - (int64_t)arg1) - (int64_t)arg3); fiat_p521_int1 x2 = (fiat_p521_int1)(x1 >> 57); uint64_t x3 = (x1 & UINT64_C(0x1ffffffffffffff)); *out1 = x3; *out2 = (fiat_p521_uint1)(0x0 - x2); } /* * The function fiat_p521_cmovznz_u64 is a single-word conditional move. * Postconditions: * out1 = (if arg1 = 0 then arg2 else arg3) * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0xffffffffffffffff] * arg3: [0x0 ~> 0xffffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0xffffffffffffffff] */ static void fiat_p521_cmovznz_u64(uint64_t* out1, fiat_p521_uint1 arg1, uint64_t arg2, uint64_t arg3) { fiat_p521_uint1 x1 = (!(!arg1)); uint64_t x2 = ((fiat_p521_int1)(0x0 - x1) & UINT64_C(0xffffffffffffffff)); uint64_t x3 = ((x2 & arg3) | ((~x2) & arg2)); *out1 = x3; } /* * The function fiat_p521_carry_mul multiplies two field elements and reduces the result. * Postconditions: * eval out1 mod m = (eval arg1 * eval arg2) mod m * * Input Bounds: * arg1: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] * arg2: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] * Output Bounds: * out1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] */ static void fiat_p521_carry_mul(uint64_t out1[9], const uint64_t arg1[9], const uint64_t arg2[9]) { fiat_p521_uint128 x1 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x2 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x3 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[6]) * (uint64_t)0x2)); fiat_p521_uint128 x4 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[5]) * (uint64_t)0x2)); fiat_p521_uint128 x5 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[4]) * (uint64_t)0x2)); fiat_p521_uint128 x6 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[3]) * (uint64_t)0x2)); fiat_p521_uint128 x7 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[2]) * (uint64_t)0x2)); fiat_p521_uint128 x8 = ((fiat_p521_uint128)(arg1[8]) * ((arg2[1]) * (uint64_t)0x2)); fiat_p521_uint128 x9 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x10 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x11 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[6]) * (uint64_t)0x2)); fiat_p521_uint128 x12 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[5]) * (uint64_t)0x2)); fiat_p521_uint128 x13 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[4]) * (uint64_t)0x2)); fiat_p521_uint128 x14 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[3]) * (uint64_t)0x2)); fiat_p521_uint128 x15 = ((fiat_p521_uint128)(arg1[7]) * ((arg2[2]) * (uint64_t)0x2)); fiat_p521_uint128 x16 = ((fiat_p521_uint128)(arg1[6]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x17 = ((fiat_p521_uint128)(arg1[6]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x18 = ((fiat_p521_uint128)(arg1[6]) * ((arg2[6]) * (uint64_t)0x2)); fiat_p521_uint128 x19 = ((fiat_p521_uint128)(arg1[6]) * ((arg2[5]) * (uint64_t)0x2)); fiat_p521_uint128 x20 = ((fiat_p521_uint128)(arg1[6]) * ((arg2[4]) * (uint64_t)0x2)); fiat_p521_uint128 x21 = ((fiat_p521_uint128)(arg1[6]) * ((arg2[3]) * (uint64_t)0x2)); fiat_p521_uint128 x22 = ((fiat_p521_uint128)(arg1[5]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x23 = ((fiat_p521_uint128)(arg1[5]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x24 = ((fiat_p521_uint128)(arg1[5]) * ((arg2[6]) * (uint64_t)0x2)); fiat_p521_uint128 x25 = ((fiat_p521_uint128)(arg1[5]) * ((arg2[5]) * (uint64_t)0x2)); fiat_p521_uint128 x26 = ((fiat_p521_uint128)(arg1[5]) * ((arg2[4]) * (uint64_t)0x2)); fiat_p521_uint128 x27 = ((fiat_p521_uint128)(arg1[4]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x28 = ((fiat_p521_uint128)(arg1[4]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x29 = ((fiat_p521_uint128)(arg1[4]) * ((arg2[6]) * (uint64_t)0x2)); fiat_p521_uint128 x30 = ((fiat_p521_uint128)(arg1[4]) * ((arg2[5]) * (uint64_t)0x2)); fiat_p521_uint128 x31 = ((fiat_p521_uint128)(arg1[3]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x32 = ((fiat_p521_uint128)(arg1[3]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x33 = ((fiat_p521_uint128)(arg1[3]) * ((arg2[6]) * (uint64_t)0x2)); fiat_p521_uint128 x34 = ((fiat_p521_uint128)(arg1[2]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x35 = ((fiat_p521_uint128)(arg1[2]) * ((arg2[7]) * (uint64_t)0x2)); fiat_p521_uint128 x36 = ((fiat_p521_uint128)(arg1[1]) * ((arg2[8]) * (uint64_t)0x2)); fiat_p521_uint128 x37 = ((fiat_p521_uint128)(arg1[8]) * (arg2[0])); fiat_p521_uint128 x38 = ((fiat_p521_uint128)(arg1[7]) * (arg2[1])); fiat_p521_uint128 x39 = ((fiat_p521_uint128)(arg1[7]) * (arg2[0])); fiat_p521_uint128 x40 = ((fiat_p521_uint128)(arg1[6]) * (arg2[2])); fiat_p521_uint128 x41 = ((fiat_p521_uint128)(arg1[6]) * (arg2[1])); fiat_p521_uint128 x42 = ((fiat_p521_uint128)(arg1[6]) * (arg2[0])); fiat_p521_uint128 x43 = ((fiat_p521_uint128)(arg1[5]) * (arg2[3])); fiat_p521_uint128 x44 = ((fiat_p521_uint128)(arg1[5]) * (arg2[2])); fiat_p521_uint128 x45 = ((fiat_p521_uint128)(arg1[5]) * (arg2[1])); fiat_p521_uint128 x46 = ((fiat_p521_uint128)(arg1[5]) * (arg2[0])); fiat_p521_uint128 x47 = ((fiat_p521_uint128)(arg1[4]) * (arg2[4])); fiat_p521_uint128 x48 = ((fiat_p521_uint128)(arg1[4]) * (arg2[3])); fiat_p521_uint128 x49 = ((fiat_p521_uint128)(arg1[4]) * (arg2[2])); fiat_p521_uint128 x50 = ((fiat_p521_uint128)(arg1[4]) * (arg2[1])); fiat_p521_uint128 x51 = ((fiat_p521_uint128)(arg1[4]) * (arg2[0])); fiat_p521_uint128 x52 = ((fiat_p521_uint128)(arg1[3]) * (arg2[5])); fiat_p521_uint128 x53 = ((fiat_p521_uint128)(arg1[3]) * (arg2[4])); fiat_p521_uint128 x54 = ((fiat_p521_uint128)(arg1[3]) * (arg2[3])); fiat_p521_uint128 x55 = ((fiat_p521_uint128)(arg1[3]) * (arg2[2])); fiat_p521_uint128 x56 = ((fiat_p521_uint128)(arg1[3]) * (arg2[1])); fiat_p521_uint128 x57 = ((fiat_p521_uint128)(arg1[3]) * (arg2[0])); fiat_p521_uint128 x58 = ((fiat_p521_uint128)(arg1[2]) * (arg2[6])); fiat_p521_uint128 x59 = ((fiat_p521_uint128)(arg1[2]) * (arg2[5])); fiat_p521_uint128 x60 = ((fiat_p521_uint128)(arg1[2]) * (arg2[4])); fiat_p521_uint128 x61 = ((fiat_p521_uint128)(arg1[2]) * (arg2[3])); fiat_p521_uint128 x62 = ((fiat_p521_uint128)(arg1[2]) * (arg2[2])); fiat_p521_uint128 x63 = ((fiat_p521_uint128)(arg1[2]) * (arg2[1])); fiat_p521_uint128 x64 = ((fiat_p521_uint128)(arg1[2]) * (arg2[0])); fiat_p521_uint128 x65 = ((fiat_p521_uint128)(arg1[1]) * (arg2[7])); fiat_p521_uint128 x66 = ((fiat_p521_uint128)(arg1[1]) * (arg2[6])); fiat_p521_uint128 x67 = ((fiat_p521_uint128)(arg1[1]) * (arg2[5])); fiat_p521_uint128 x68 = ((fiat_p521_uint128)(arg1[1]) * (arg2[4])); fiat_p521_uint128 x69 = ((fiat_p521_uint128)(arg1[1]) * (arg2[3])); fiat_p521_uint128 x70 = ((fiat_p521_uint128)(arg1[1]) * (arg2[2])); fiat_p521_uint128 x71 = ((fiat_p521_uint128)(arg1[1]) * (arg2[1])); fiat_p521_uint128 x72 = ((fiat_p521_uint128)(arg1[1]) * (arg2[0])); fiat_p521_uint128 x73 = ((fiat_p521_uint128)(arg1[0]) * (arg2[8])); fiat_p521_uint128 x74 = ((fiat_p521_uint128)(arg1[0]) * (arg2[7])); fiat_p521_uint128 x75 = ((fiat_p521_uint128)(arg1[0]) * (arg2[6])); fiat_p521_uint128 x76 = ((fiat_p521_uint128)(arg1[0]) * (arg2[5])); fiat_p521_uint128 x77 = ((fiat_p521_uint128)(arg1[0]) * (arg2[4])); fiat_p521_uint128 x78 = ((fiat_p521_uint128)(arg1[0]) * (arg2[3])); fiat_p521_uint128 x79 = ((fiat_p521_uint128)(arg1[0]) * (arg2[2])); fiat_p521_uint128 x80 = ((fiat_p521_uint128)(arg1[0]) * (arg2[1])); fiat_p521_uint128 x81 = ((fiat_p521_uint128)(arg1[0]) * (arg2[0])); fiat_p521_uint128 x82 = (x81 + (x36 + (x35 + (x33 + (x30 + (x26 + (x21 + (x15 + x8)))))))); fiat_p521_uint128 x83 = (x82 >> 58); uint64_t x84 = (uint64_t)(x82 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x85 = (x73 + (x65 + (x58 + (x52 + (x47 + (x43 + (x40 + (x38 + x37)))))))); fiat_p521_uint128 x86 = (x74 + (x66 + (x59 + (x53 + (x48 + (x44 + (x41 + (x39 + x1)))))))); fiat_p521_uint128 x87 = (x75 + (x67 + (x60 + (x54 + (x49 + (x45 + (x42 + (x9 + x2)))))))); fiat_p521_uint128 x88 = (x76 + (x68 + (x61 + (x55 + (x50 + (x46 + (x16 + (x10 + x3)))))))); fiat_p521_uint128 x89 = (x77 + (x69 + (x62 + (x56 + (x51 + (x22 + (x17 + (x11 + x4)))))))); fiat_p521_uint128 x90 = (x78 + (x70 + (x63 + (x57 + (x27 + (x23 + (x18 + (x12 + x5)))))))); fiat_p521_uint128 x91 = (x79 + (x71 + (x64 + (x31 + (x28 + (x24 + (x19 + (x13 + x6)))))))); fiat_p521_uint128 x92 = (x80 + (x72 + (x34 + (x32 + (x29 + (x25 + (x20 + (x14 + x7)))))))); fiat_p521_uint128 x93 = (x83 + x92); fiat_p521_uint128 x94 = (x93 >> 58); uint64_t x95 = (uint64_t)(x93 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x96 = (x94 + x91); fiat_p521_uint128 x97 = (x96 >> 58); uint64_t x98 = (uint64_t)(x96 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x99 = (x97 + x90); fiat_p521_uint128 x100 = (x99 >> 58); uint64_t x101 = (uint64_t)(x99 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x102 = (x100 + x89); fiat_p521_uint128 x103 = (x102 >> 58); uint64_t x104 = (uint64_t)(x102 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x105 = (x103 + x88); fiat_p521_uint128 x106 = (x105 >> 58); uint64_t x107 = (uint64_t)(x105 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x108 = (x106 + x87); fiat_p521_uint128 x109 = (x108 >> 58); uint64_t x110 = (uint64_t)(x108 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x111 = (x109 + x86); fiat_p521_uint128 x112 = (x111 >> 58); uint64_t x113 = (uint64_t)(x111 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x114 = (x112 + x85); fiat_p521_uint128 x115 = (x114 >> 57); uint64_t x116 = (uint64_t)(x114 & UINT64_C(0x1ffffffffffffff)); fiat_p521_uint128 x117 = (x84 + x115); uint64_t x118 = (uint64_t)(x117 >> 58); uint64_t x119 = (uint64_t)(x117 & UINT64_C(0x3ffffffffffffff)); uint64_t x120 = (x118 + x95); uint64_t x121 = (x120 >> 58); uint64_t x122 = (x120 & UINT64_C(0x3ffffffffffffff)); uint64_t x123 = (x121 + x98); out1[0] = x119; out1[1] = x122; out1[2] = x123; out1[3] = x101; out1[4] = x104; out1[5] = x107; out1[6] = x110; out1[7] = x113; out1[8] = x116; } /* * The function fiat_p521_carry_square squares a field element and reduces the result. * Postconditions: * eval out1 mod m = (eval arg1 * eval arg1) mod m * * Input Bounds: * arg1: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] * Output Bounds: * out1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] */ static void fiat_p521_carry_square(uint64_t out1[9], const uint64_t arg1[9]) { uint64_t x1 = (arg1[8]); uint64_t x2 = (x1 * (uint64_t)0x2); uint64_t x3 = ((arg1[8]) * (uint64_t)0x2); uint64_t x4 = (arg1[7]); uint64_t x5 = (x4 * (uint64_t)0x2); uint64_t x6 = ((arg1[7]) * (uint64_t)0x2); uint64_t x7 = (arg1[6]); uint64_t x8 = (x7 * (uint64_t)0x2); uint64_t x9 = ((arg1[6]) * (uint64_t)0x2); uint64_t x10 = (arg1[5]); uint64_t x11 = (x10 * (uint64_t)0x2); uint64_t x12 = ((arg1[5]) * (uint64_t)0x2); uint64_t x13 = ((arg1[4]) * (uint64_t)0x2); uint64_t x14 = ((arg1[3]) * (uint64_t)0x2); uint64_t x15 = ((arg1[2]) * (uint64_t)0x2); uint64_t x16 = ((arg1[1]) * (uint64_t)0x2); fiat_p521_uint128 x17 = ((fiat_p521_uint128)(arg1[8]) * (x1 * (uint64_t)0x2)); fiat_p521_uint128 x18 = ((fiat_p521_uint128)(arg1[7]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x19 = ((fiat_p521_uint128)(arg1[7]) * (x4 * (uint64_t)0x2)); fiat_p521_uint128 x20 = ((fiat_p521_uint128)(arg1[6]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x21 = ((fiat_p521_uint128)(arg1[6]) * (x5 * (uint64_t)0x2)); fiat_p521_uint128 x22 = ((fiat_p521_uint128)(arg1[6]) * (x7 * (uint64_t)0x2)); fiat_p521_uint128 x23 = ((fiat_p521_uint128)(arg1[5]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x24 = ((fiat_p521_uint128)(arg1[5]) * (x5 * (uint64_t)0x2)); fiat_p521_uint128 x25 = ((fiat_p521_uint128)(arg1[5]) * (x8 * (uint64_t)0x2)); fiat_p521_uint128 x26 = ((fiat_p521_uint128)(arg1[5]) * (x10 * (uint64_t)0x2)); fiat_p521_uint128 x27 = ((fiat_p521_uint128)(arg1[4]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x28 = ((fiat_p521_uint128)(arg1[4]) * (x5 * (uint64_t)0x2)); fiat_p521_uint128 x29 = ((fiat_p521_uint128)(arg1[4]) * (x8 * (uint64_t)0x2)); fiat_p521_uint128 x30 = ((fiat_p521_uint128)(arg1[4]) * (x11 * (uint64_t)0x2)); fiat_p521_uint128 x31 = ((fiat_p521_uint128)(arg1[4]) * (arg1[4])); fiat_p521_uint128 x32 = ((fiat_p521_uint128)(arg1[3]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x33 = ((fiat_p521_uint128)(arg1[3]) * (x5 * (uint64_t)0x2)); fiat_p521_uint128 x34 = ((fiat_p521_uint128)(arg1[3]) * (x8 * (uint64_t)0x2)); fiat_p521_uint128 x35 = ((fiat_p521_uint128)(arg1[3]) * x12); fiat_p521_uint128 x36 = ((fiat_p521_uint128)(arg1[3]) * x13); fiat_p521_uint128 x37 = ((fiat_p521_uint128)(arg1[3]) * (arg1[3])); fiat_p521_uint128 x38 = ((fiat_p521_uint128)(arg1[2]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x39 = ((fiat_p521_uint128)(arg1[2]) * (x5 * (uint64_t)0x2)); fiat_p521_uint128 x40 = ((fiat_p521_uint128)(arg1[2]) * x9); fiat_p521_uint128 x41 = ((fiat_p521_uint128)(arg1[2]) * x12); fiat_p521_uint128 x42 = ((fiat_p521_uint128)(arg1[2]) * x13); fiat_p521_uint128 x43 = ((fiat_p521_uint128)(arg1[2]) * x14); fiat_p521_uint128 x44 = ((fiat_p521_uint128)(arg1[2]) * (arg1[2])); fiat_p521_uint128 x45 = ((fiat_p521_uint128)(arg1[1]) * (x2 * (uint64_t)0x2)); fiat_p521_uint128 x46 = ((fiat_p521_uint128)(arg1[1]) * x6); fiat_p521_uint128 x47 = ((fiat_p521_uint128)(arg1[1]) * x9); fiat_p521_uint128 x48 = ((fiat_p521_uint128)(arg1[1]) * x12); fiat_p521_uint128 x49 = ((fiat_p521_uint128)(arg1[1]) * x13); fiat_p521_uint128 x50 = ((fiat_p521_uint128)(arg1[1]) * x14); fiat_p521_uint128 x51 = ((fiat_p521_uint128)(arg1[1]) * x15); fiat_p521_uint128 x52 = ((fiat_p521_uint128)(arg1[1]) * (arg1[1])); fiat_p521_uint128 x53 = ((fiat_p521_uint128)(arg1[0]) * x3); fiat_p521_uint128 x54 = ((fiat_p521_uint128)(arg1[0]) * x6); fiat_p521_uint128 x55 = ((fiat_p521_uint128)(arg1[0]) * x9); fiat_p521_uint128 x56 = ((fiat_p521_uint128)(arg1[0]) * x12); fiat_p521_uint128 x57 = ((fiat_p521_uint128)(arg1[0]) * x13); fiat_p521_uint128 x58 = ((fiat_p521_uint128)(arg1[0]) * x14); fiat_p521_uint128 x59 = ((fiat_p521_uint128)(arg1[0]) * x15); fiat_p521_uint128 x60 = ((fiat_p521_uint128)(arg1[0]) * x16); fiat_p521_uint128 x61 = ((fiat_p521_uint128)(arg1[0]) * (arg1[0])); fiat_p521_uint128 x62 = (x61 + (x45 + (x39 + (x34 + x30)))); fiat_p521_uint128 x63 = (x62 >> 58); uint64_t x64 = (uint64_t)(x62 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x65 = (x53 + (x46 + (x40 + (x35 + x31)))); fiat_p521_uint128 x66 = (x54 + (x47 + (x41 + (x36 + x17)))); fiat_p521_uint128 x67 = (x55 + (x48 + (x42 + (x37 + x18)))); fiat_p521_uint128 x68 = (x56 + (x49 + (x43 + (x20 + x19)))); fiat_p521_uint128 x69 = (x57 + (x50 + (x44 + (x23 + x21)))); fiat_p521_uint128 x70 = (x58 + (x51 + (x27 + (x24 + x22)))); fiat_p521_uint128 x71 = (x59 + (x52 + (x32 + (x28 + x25)))); fiat_p521_uint128 x72 = (x60 + (x38 + (x33 + (x29 + x26)))); fiat_p521_uint128 x73 = (x63 + x72); fiat_p521_uint128 x74 = (x73 >> 58); uint64_t x75 = (uint64_t)(x73 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x76 = (x74 + x71); fiat_p521_uint128 x77 = (x76 >> 58); uint64_t x78 = (uint64_t)(x76 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x79 = (x77 + x70); fiat_p521_uint128 x80 = (x79 >> 58); uint64_t x81 = (uint64_t)(x79 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x82 = (x80 + x69); fiat_p521_uint128 x83 = (x82 >> 58); uint64_t x84 = (uint64_t)(x82 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x85 = (x83 + x68); fiat_p521_uint128 x86 = (x85 >> 58); uint64_t x87 = (uint64_t)(x85 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x88 = (x86 + x67); fiat_p521_uint128 x89 = (x88 >> 58); uint64_t x90 = (uint64_t)(x88 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x91 = (x89 + x66); fiat_p521_uint128 x92 = (x91 >> 58); uint64_t x93 = (uint64_t)(x91 & UINT64_C(0x3ffffffffffffff)); fiat_p521_uint128 x94 = (x92 + x65); fiat_p521_uint128 x95 = (x94 >> 57); uint64_t x96 = (uint64_t)(x94 & UINT64_C(0x1ffffffffffffff)); fiat_p521_uint128 x97 = (x64 + x95); uint64_t x98 = (uint64_t)(x97 >> 58); uint64_t x99 = (uint64_t)(x97 & UINT64_C(0x3ffffffffffffff)); uint64_t x100 = (x98 + x75); uint64_t x101 = (x100 >> 58); uint64_t x102 = (x100 & UINT64_C(0x3ffffffffffffff)); uint64_t x103 = (x101 + x78); out1[0] = x99; out1[1] = x102; out1[2] = x103; out1[3] = x81; out1[4] = x84; out1[5] = x87; out1[6] = x90; out1[7] = x93; out1[8] = x96; } /* * The function fiat_p521_carry reduces a field element. * Postconditions: * eval out1 mod m = eval arg1 mod m * * Input Bounds: * arg1: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] * Output Bounds: * out1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] */ static void fiat_p521_carry(uint64_t out1[9], const uint64_t arg1[9]) { uint64_t x1 = (arg1[0]); uint64_t x2 = ((x1 >> 58) + (arg1[1])); uint64_t x3 = ((x2 >> 58) + (arg1[2])); uint64_t x4 = ((x3 >> 58) + (arg1[3])); uint64_t x5 = ((x4 >> 58) + (arg1[4])); uint64_t x6 = ((x5 >> 58) + (arg1[5])); uint64_t x7 = ((x6 >> 58) + (arg1[6])); uint64_t x8 = ((x7 >> 58) + (arg1[7])); uint64_t x9 = ((x8 >> 58) + (arg1[8])); uint64_t x10 = ((x1 & UINT64_C(0x3ffffffffffffff)) + (x9 >> 57)); uint64_t x11 = ((x10 >> 58) + (x2 & UINT64_C(0x3ffffffffffffff))); uint64_t x12 = (x10 & UINT64_C(0x3ffffffffffffff)); uint64_t x13 = (x11 & UINT64_C(0x3ffffffffffffff)); uint64_t x14 = ((x11 >> 58) + (x3 & UINT64_C(0x3ffffffffffffff))); uint64_t x15 = (x4 & UINT64_C(0x3ffffffffffffff)); uint64_t x16 = (x5 & UINT64_C(0x3ffffffffffffff)); uint64_t x17 = (x6 & UINT64_C(0x3ffffffffffffff)); uint64_t x18 = (x7 & UINT64_C(0x3ffffffffffffff)); uint64_t x19 = (x8 & UINT64_C(0x3ffffffffffffff)); uint64_t x20 = (x9 & UINT64_C(0x1ffffffffffffff)); out1[0] = x12; out1[1] = x13; out1[2] = x14; out1[3] = x15; out1[4] = x16; out1[5] = x17; out1[6] = x18; out1[7] = x19; out1[8] = x20; } /* * The function fiat_p521_add adds two field elements. * Postconditions: * eval out1 mod m = (eval arg1 + eval arg2) mod m * * Input Bounds: * arg1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] * arg2: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] * Output Bounds: * out1: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] */ static void fiat_p521_add(uint64_t out1[9], const uint64_t arg1[9], const uint64_t arg2[9]) { uint64_t x1 = ((arg1[0]) + (arg2[0])); uint64_t x2 = ((arg1[1]) + (arg2[1])); uint64_t x3 = ((arg1[2]) + (arg2[2])); uint64_t x4 = ((arg1[3]) + (arg2[3])); uint64_t x5 = ((arg1[4]) + (arg2[4])); uint64_t x6 = ((arg1[5]) + (arg2[5])); uint64_t x7 = ((arg1[6]) + (arg2[6])); uint64_t x8 = ((arg1[7]) + (arg2[7])); uint64_t x9 = ((arg1[8]) + (arg2[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /* * The function fiat_p521_sub subtracts two field elements. * Postconditions: * eval out1 mod m = (eval arg1 - eval arg2) mod m * * Input Bounds: * arg1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] * arg2: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] * Output Bounds: * out1: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] */ static void fiat_p521_sub(uint64_t out1[9], const uint64_t arg1[9], const uint64_t arg2[9]) { uint64_t x1 = ((UINT64_C(0x7fffffffffffffe) + (arg1[0])) - (arg2[0])); uint64_t x2 = ((UINT64_C(0x7fffffffffffffe) + (arg1[1])) - (arg2[1])); uint64_t x3 = ((UINT64_C(0x7fffffffffffffe) + (arg1[2])) - (arg2[2])); uint64_t x4 = ((UINT64_C(0x7fffffffffffffe) + (arg1[3])) - (arg2[3])); uint64_t x5 = ((UINT64_C(0x7fffffffffffffe) + (arg1[4])) - (arg2[4])); uint64_t x6 = ((UINT64_C(0x7fffffffffffffe) + (arg1[5])) - (arg2[5])); uint64_t x7 = ((UINT64_C(0x7fffffffffffffe) + (arg1[6])) - (arg2[6])); uint64_t x8 = ((UINT64_C(0x7fffffffffffffe) + (arg1[7])) - (arg2[7])); uint64_t x9 = ((UINT64_C(0x3fffffffffffffe) + (arg1[8])) - (arg2[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /* * The function fiat_p521_opp negates a field element. * Postconditions: * eval out1 mod m = -eval arg1 mod m * * Input Bounds: * arg1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] * Output Bounds: * out1: [[0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0xd33333333333332], [0x0 ~> 0x699999999999999]] */ static void fiat_p521_opp(uint64_t out1[9], const uint64_t arg1[9]) { uint64_t x1 = (UINT64_C(0x7fffffffffffffe) - (arg1[0])); uint64_t x2 = (UINT64_C(0x7fffffffffffffe) - (arg1[1])); uint64_t x3 = (UINT64_C(0x7fffffffffffffe) - (arg1[2])); uint64_t x4 = (UINT64_C(0x7fffffffffffffe) - (arg1[3])); uint64_t x5 = (UINT64_C(0x7fffffffffffffe) - (arg1[4])); uint64_t x6 = (UINT64_C(0x7fffffffffffffe) - (arg1[5])); uint64_t x7 = (UINT64_C(0x7fffffffffffffe) - (arg1[6])); uint64_t x8 = (UINT64_C(0x7fffffffffffffe) - (arg1[7])); uint64_t x9 = (UINT64_C(0x3fffffffffffffe) - (arg1[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /* * The function fiat_p521_selectznz is a multi-limb conditional select. * Postconditions: * eval out1 = (if arg1 = 0 then eval arg2 else eval arg3) * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * arg3: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_p521_selectznz(uint64_t out1[9], fiat_p521_uint1 arg1, const uint64_t arg2[9], const uint64_t arg3[9]) { uint64_t x1; fiat_p521_cmovznz_u64(&x1, arg1, (arg2[0]), (arg3[0])); uint64_t x2; fiat_p521_cmovznz_u64(&x2, arg1, (arg2[1]), (arg3[1])); uint64_t x3; fiat_p521_cmovznz_u64(&x3, arg1, (arg2[2]), (arg3[2])); uint64_t x4; fiat_p521_cmovznz_u64(&x4, arg1, (arg2[3]), (arg3[3])); uint64_t x5; fiat_p521_cmovznz_u64(&x5, arg1, (arg2[4]), (arg3[4])); uint64_t x6; fiat_p521_cmovznz_u64(&x6, arg1, (arg2[5]), (arg3[5])); uint64_t x7; fiat_p521_cmovznz_u64(&x7, arg1, (arg2[6]), (arg3[6])); uint64_t x8; fiat_p521_cmovznz_u64(&x8, arg1, (arg2[7]), (arg3[7])); uint64_t x9; fiat_p521_cmovznz_u64(&x9, arg1, (arg2[8]), (arg3[8])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; out1[4] = x5; out1[5] = x6; out1[6] = x7; out1[7] = x8; out1[8] = x9; } /* * The function fiat_p521_to_bytes serializes a field element to bytes in little-endian order. * Postconditions: * out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..65] * * Input Bounds: * arg1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] * Output Bounds: * out1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1]] */ static void fiat_p521_to_bytes(uint8_t out1[66], const uint64_t arg1[9]) { uint64_t x1; fiat_p521_uint1 x2; fiat_p521_subborrowx_u58(&x1, &x2, 0x0, (arg1[0]), UINT64_C(0x3ffffffffffffff)); uint64_t x3; fiat_p521_uint1 x4; fiat_p521_subborrowx_u58(&x3, &x4, x2, (arg1[1]), UINT64_C(0x3ffffffffffffff)); uint64_t x5; fiat_p521_uint1 x6; fiat_p521_subborrowx_u58(&x5, &x6, x4, (arg1[2]), UINT64_C(0x3ffffffffffffff)); uint64_t x7; fiat_p521_uint1 x8; fiat_p521_subborrowx_u58(&x7, &x8, x6, (arg1[3]), UINT64_C(0x3ffffffffffffff)); uint64_t x9; fiat_p521_uint1 x10; fiat_p521_subborrowx_u58(&x9, &x10, x8, (arg1[4]), UINT64_C(0x3ffffffffffffff)); uint64_t x11; fiat_p521_uint1 x12; fiat_p521_subborrowx_u58(&x11, &x12, x10, (arg1[5]), UINT64_C(0x3ffffffffffffff)); uint64_t x13; fiat_p521_uint1 x14; fiat_p521_subborrowx_u58(&x13, &x14, x12, (arg1[6]), UINT64_C(0x3ffffffffffffff)); uint64_t x15; fiat_p521_uint1 x16; fiat_p521_subborrowx_u58(&x15, &x16, x14, (arg1[7]), UINT64_C(0x3ffffffffffffff)); uint64_t x17; fiat_p521_uint1 x18; fiat_p521_subborrowx_u57(&x17, &x18, x16, (arg1[8]), UINT64_C(0x1ffffffffffffff)); uint64_t x19; fiat_p521_cmovznz_u64(&x19, x18, 0x0, UINT64_C(0xffffffffffffffff)); uint64_t x20; fiat_p521_uint1 x21; fiat_p521_addcarryx_u58(&x20, &x21, 0x0, x1, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x22; fiat_p521_uint1 x23; fiat_p521_addcarryx_u58(&x22, &x23, x21, x3, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x24; fiat_p521_uint1 x25; fiat_p521_addcarryx_u58(&x24, &x25, x23, x5, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x26; fiat_p521_uint1 x27; fiat_p521_addcarryx_u58(&x26, &x27, x25, x7, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x28; fiat_p521_uint1 x29; fiat_p521_addcarryx_u58(&x28, &x29, x27, x9, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x30; fiat_p521_uint1 x31; fiat_p521_addcarryx_u58(&x30, &x31, x29, x11, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x32; fiat_p521_uint1 x33; fiat_p521_addcarryx_u58(&x32, &x33, x31, x13, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x34; fiat_p521_uint1 x35; fiat_p521_addcarryx_u58(&x34, &x35, x33, x15, (x19 & UINT64_C(0x3ffffffffffffff))); uint64_t x36; fiat_p521_uint1 x37; fiat_p521_addcarryx_u57(&x36, &x37, x35, x17, (x19 & UINT64_C(0x1ffffffffffffff))); uint64_t x38 = (x34 << 6); uint64_t x39 = (x32 << 4); uint64_t x40 = (x30 << 2); uint64_t x41 = (x26 << 6); uint64_t x42 = (x24 << 4); uint64_t x43 = (x22 << 2); uint64_t x44 = (x20 >> 8); uint8_t x45 = (uint8_t)(x20 & UINT8_C(0xff)); uint64_t x46 = (x44 >> 8); uint8_t x47 = (uint8_t)(x44 & UINT8_C(0xff)); uint64_t x48 = (x46 >> 8); uint8_t x49 = (uint8_t)(x46 & UINT8_C(0xff)); uint64_t x50 = (x48 >> 8); uint8_t x51 = (uint8_t)(x48 & UINT8_C(0xff)); uint64_t x52 = (x50 >> 8); uint8_t x53 = (uint8_t)(x50 & UINT8_C(0xff)); uint64_t x54 = (x52 >> 8); uint8_t x55 = (uint8_t)(x52 & UINT8_C(0xff)); uint8_t x56 = (uint8_t)(x54 >> 8); uint8_t x57 = (uint8_t)(x54 & UINT8_C(0xff)); uint64_t x58 = (x56 + x43); uint64_t x59 = (x58 >> 8); uint8_t x60 = (uint8_t)(x58 & UINT8_C(0xff)); uint64_t x61 = (x59 >> 8); uint8_t x62 = (uint8_t)(x59 & UINT8_C(0xff)); uint64_t x63 = (x61 >> 8); uint8_t x64 = (uint8_t)(x61 & UINT8_C(0xff)); uint64_t x65 = (x63 >> 8); uint8_t x66 = (uint8_t)(x63 & UINT8_C(0xff)); uint64_t x67 = (x65 >> 8); uint8_t x68 = (uint8_t)(x65 & UINT8_C(0xff)); uint64_t x69 = (x67 >> 8); uint8_t x70 = (uint8_t)(x67 & UINT8_C(0xff)); uint8_t x71 = (uint8_t)(x69 >> 8); uint8_t x72 = (uint8_t)(x69 & UINT8_C(0xff)); uint64_t x73 = (x71 + x42); uint64_t x74 = (x73 >> 8); uint8_t x75 = (uint8_t)(x73 & UINT8_C(0xff)); uint64_t x76 = (x74 >> 8); uint8_t x77 = (uint8_t)(x74 & UINT8_C(0xff)); uint64_t x78 = (x76 >> 8); uint8_t x79 = (uint8_t)(x76 & UINT8_C(0xff)); uint64_t x80 = (x78 >> 8); uint8_t x81 = (uint8_t)(x78 & UINT8_C(0xff)); uint64_t x82 = (x80 >> 8); uint8_t x83 = (uint8_t)(x80 & UINT8_C(0xff)); uint64_t x84 = (x82 >> 8); uint8_t x85 = (uint8_t)(x82 & UINT8_C(0xff)); uint8_t x86 = (uint8_t)(x84 >> 8); uint8_t x87 = (uint8_t)(x84 & UINT8_C(0xff)); uint64_t x88 = (x86 + x41); uint64_t x89 = (x88 >> 8); uint8_t x90 = (uint8_t)(x88 & UINT8_C(0xff)); uint64_t x91 = (x89 >> 8); uint8_t x92 = (uint8_t)(x89 & UINT8_C(0xff)); uint64_t x93 = (x91 >> 8); uint8_t x94 = (uint8_t)(x91 & UINT8_C(0xff)); uint64_t x95 = (x93 >> 8); uint8_t x96 = (uint8_t)(x93 & UINT8_C(0xff)); uint64_t x97 = (x95 >> 8); uint8_t x98 = (uint8_t)(x95 & UINT8_C(0xff)); uint64_t x99 = (x97 >> 8); uint8_t x100 = (uint8_t)(x97 & UINT8_C(0xff)); uint8_t x101 = (uint8_t)(x99 >> 8); uint8_t x102 = (uint8_t)(x99 & UINT8_C(0xff)); uint8_t x103 = (uint8_t)(x101 & UINT8_C(0xff)); uint64_t x104 = (x28 >> 8); uint8_t x105 = (uint8_t)(x28 & UINT8_C(0xff)); uint64_t x106 = (x104 >> 8); uint8_t x107 = (uint8_t)(x104 & UINT8_C(0xff)); uint64_t x108 = (x106 >> 8); uint8_t x109 = (uint8_t)(x106 & UINT8_C(0xff)); uint64_t x110 = (x108 >> 8); uint8_t x111 = (uint8_t)(x108 & UINT8_C(0xff)); uint64_t x112 = (x110 >> 8); uint8_t x113 = (uint8_t)(x110 & UINT8_C(0xff)); uint64_t x114 = (x112 >> 8); uint8_t x115 = (uint8_t)(x112 & UINT8_C(0xff)); uint8_t x116 = (uint8_t)(x114 >> 8); uint8_t x117 = (uint8_t)(x114 & UINT8_C(0xff)); uint64_t x118 = (x116 + x40); uint64_t x119 = (x118 >> 8); uint8_t x120 = (uint8_t)(x118 & UINT8_C(0xff)); uint64_t x121 = (x119 >> 8); uint8_t x122 = (uint8_t)(x119 & UINT8_C(0xff)); uint64_t x123 = (x121 >> 8); uint8_t x124 = (uint8_t)(x121 & UINT8_C(0xff)); uint64_t x125 = (x123 >> 8); uint8_t x126 = (uint8_t)(x123 & UINT8_C(0xff)); uint64_t x127 = (x125 >> 8); uint8_t x128 = (uint8_t)(x125 & UINT8_C(0xff)); uint64_t x129 = (x127 >> 8); uint8_t x130 = (uint8_t)(x127 & UINT8_C(0xff)); uint8_t x131 = (uint8_t)(x129 >> 8); uint8_t x132 = (uint8_t)(x129 & UINT8_C(0xff)); uint64_t x133 = (x131 + x39); uint64_t x134 = (x133 >> 8); uint8_t x135 = (uint8_t)(x133 & UINT8_C(0xff)); uint64_t x136 = (x134 >> 8); uint8_t x137 = (uint8_t)(x134 & UINT8_C(0xff)); uint64_t x138 = (x136 >> 8); uint8_t x139 = (uint8_t)(x136 & UINT8_C(0xff)); uint64_t x140 = (x138 >> 8); uint8_t x141 = (uint8_t)(x138 & UINT8_C(0xff)); uint64_t x142 = (x140 >> 8); uint8_t x143 = (uint8_t)(x140 & UINT8_C(0xff)); uint64_t x144 = (x142 >> 8); uint8_t x145 = (uint8_t)(x142 & UINT8_C(0xff)); uint8_t x146 = (uint8_t)(x144 >> 8); uint8_t x147 = (uint8_t)(x144 & UINT8_C(0xff)); uint64_t x148 = (x146 + x38); uint64_t x149 = (x148 >> 8); uint8_t x150 = (uint8_t)(x148 & UINT8_C(0xff)); uint64_t x151 = (x149 >> 8); uint8_t x152 = (uint8_t)(x149 & UINT8_C(0xff)); uint64_t x153 = (x151 >> 8); uint8_t x154 = (uint8_t)(x151 & UINT8_C(0xff)); uint64_t x155 = (x153 >> 8); uint8_t x156 = (uint8_t)(x153 & UINT8_C(0xff)); uint64_t x157 = (x155 >> 8); uint8_t x158 = (uint8_t)(x155 & UINT8_C(0xff)); uint64_t x159 = (x157 >> 8); uint8_t x160 = (uint8_t)(x157 & UINT8_C(0xff)); uint8_t x161 = (uint8_t)(x159 >> 8); uint8_t x162 = (uint8_t)(x159 & UINT8_C(0xff)); uint8_t x163 = (uint8_t)(x161 & UINT8_C(0xff)); uint64_t x164 = (x36 >> 8); uint8_t x165 = (uint8_t)(x36 & UINT8_C(0xff)); uint64_t x166 = (x164 >> 8); uint8_t x167 = (uint8_t)(x164 & UINT8_C(0xff)); uint64_t x168 = (x166 >> 8); uint8_t x169 = (uint8_t)(x166 & UINT8_C(0xff)); uint64_t x170 = (x168 >> 8); uint8_t x171 = (uint8_t)(x168 & UINT8_C(0xff)); uint64_t x172 = (x170 >> 8); uint8_t x173 = (uint8_t)(x170 & UINT8_C(0xff)); uint64_t x174 = (x172 >> 8); uint8_t x175 = (uint8_t)(x172 & UINT8_C(0xff)); fiat_p521_uint1 x176 = (fiat_p521_uint1)(x174 >> 8); uint8_t x177 = (uint8_t)(x174 & UINT8_C(0xff)); out1[0] = x45; out1[1] = x47; out1[2] = x49; out1[3] = x51; out1[4] = x53; out1[5] = x55; out1[6] = x57; out1[7] = x60; out1[8] = x62; out1[9] = x64; out1[10] = x66; out1[11] = x68; out1[12] = x70; out1[13] = x72; out1[14] = x75; out1[15] = x77; out1[16] = x79; out1[17] = x81; out1[18] = x83; out1[19] = x85; out1[20] = x87; out1[21] = x90; out1[22] = x92; out1[23] = x94; out1[24] = x96; out1[25] = x98; out1[26] = x100; out1[27] = x102; out1[28] = x103; out1[29] = x105; out1[30] = x107; out1[31] = x109; out1[32] = x111; out1[33] = x113; out1[34] = x115; out1[35] = x117; out1[36] = x120; out1[37] = x122; out1[38] = x124; out1[39] = x126; out1[40] = x128; out1[41] = x130; out1[42] = x132; out1[43] = x135; out1[44] = x137; out1[45] = x139; out1[46] = x141; out1[47] = x143; out1[48] = x145; out1[49] = x147; out1[50] = x150; out1[51] = x152; out1[52] = x154; out1[53] = x156; out1[54] = x158; out1[55] = x160; out1[56] = x162; out1[57] = x163; out1[58] = x165; out1[59] = x167; out1[60] = x169; out1[61] = x171; out1[62] = x173; out1[63] = x175; out1[64] = x177; out1[65] = x176; } /* * The function fiat_p521_from_bytes deserializes a field element from bytes in little-endian order. * Postconditions: * eval out1 mod m = bytes_eval arg1 mod m * * Input Bounds: * arg1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1]] * Output Bounds: * out1: [[0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x466666666666666], [0x0 ~> 0x233333333333333]] */ static void fiat_p521_from_bytes(uint64_t out1[9], const uint8_t arg1[66]) { uint64_t x1 = ((uint64_t)(fiat_p521_uint1)(arg1[65]) << 56); uint64_t x2 = ((uint64_t)(arg1[64]) << 48); uint64_t x3 = ((uint64_t)(arg1[63]) << 40); uint64_t x4 = ((uint64_t)(arg1[62]) << 32); uint64_t x5 = ((uint64_t)(arg1[61]) << 24); uint64_t x6 = ((uint64_t)(arg1[60]) << 16); uint64_t x7 = ((uint64_t)(arg1[59]) << 8); uint8_t x8 = (arg1[58]); uint64_t x9 = ((uint64_t)(arg1[57]) << 50); uint64_t x10 = ((uint64_t)(arg1[56]) << 42); uint64_t x11 = ((uint64_t)(arg1[55]) << 34); uint64_t x12 = ((uint64_t)(arg1[54]) << 26); uint64_t x13 = ((uint64_t)(arg1[53]) << 18); uint64_t x14 = ((uint64_t)(arg1[52]) << 10); uint64_t x15 = ((uint64_t)(arg1[51]) << 2); uint64_t x16 = ((uint64_t)(arg1[50]) << 52); uint64_t x17 = ((uint64_t)(arg1[49]) << 44); uint64_t x18 = ((uint64_t)(arg1[48]) << 36); uint64_t x19 = ((uint64_t)(arg1[47]) << 28); uint64_t x20 = ((uint64_t)(arg1[46]) << 20); uint64_t x21 = ((uint64_t)(arg1[45]) << 12); uint64_t x22 = ((uint64_t)(arg1[44]) << 4); uint64_t x23 = ((uint64_t)(arg1[43]) << 54); uint64_t x24 = ((uint64_t)(arg1[42]) << 46); uint64_t x25 = ((uint64_t)(arg1[41]) << 38); uint64_t x26 = ((uint64_t)(arg1[40]) << 30); uint64_t x27 = ((uint64_t)(arg1[39]) << 22); uint64_t x28 = ((uint64_t)(arg1[38]) << 14); uint64_t x29 = ((uint64_t)(arg1[37]) << 6); uint64_t x30 = ((uint64_t)(arg1[36]) << 56); uint64_t x31 = ((uint64_t)(arg1[35]) << 48); uint64_t x32 = ((uint64_t)(arg1[34]) << 40); uint64_t x33 = ((uint64_t)(arg1[33]) << 32); uint64_t x34 = ((uint64_t)(arg1[32]) << 24); uint64_t x35 = ((uint64_t)(arg1[31]) << 16); uint64_t x36 = ((uint64_t)(arg1[30]) << 8); uint8_t x37 = (arg1[29]); uint64_t x38 = ((uint64_t)(arg1[28]) << 50); uint64_t x39 = ((uint64_t)(arg1[27]) << 42); uint64_t x40 = ((uint64_t)(arg1[26]) << 34); uint64_t x41 = ((uint64_t)(arg1[25]) << 26); uint64_t x42 = ((uint64_t)(arg1[24]) << 18); uint64_t x43 = ((uint64_t)(arg1[23]) << 10); uint64_t x44 = ((uint64_t)(arg1[22]) << 2); uint64_t x45 = ((uint64_t)(arg1[21]) << 52); uint64_t x46 = ((uint64_t)(arg1[20]) << 44); uint64_t x47 = ((uint64_t)(arg1[19]) << 36); uint64_t x48 = ((uint64_t)(arg1[18]) << 28); uint64_t x49 = ((uint64_t)(arg1[17]) << 20); uint64_t x50 = ((uint64_t)(arg1[16]) << 12); uint64_t x51 = ((uint64_t)(arg1[15]) << 4); uint64_t x52 = ((uint64_t)(arg1[14]) << 54); uint64_t x53 = ((uint64_t)(arg1[13]) << 46); uint64_t x54 = ((uint64_t)(arg1[12]) << 38); uint64_t x55 = ((uint64_t)(arg1[11]) << 30); uint64_t x56 = ((uint64_t)(arg1[10]) << 22); uint64_t x57 = ((uint64_t)(arg1[9]) << 14); uint64_t x58 = ((uint64_t)(arg1[8]) << 6); uint64_t x59 = ((uint64_t)(arg1[7]) << 56); uint64_t x60 = ((uint64_t)(arg1[6]) << 48); uint64_t x61 = ((uint64_t)(arg1[5]) << 40); uint64_t x62 = ((uint64_t)(arg1[4]) << 32); uint64_t x63 = ((uint64_t)(arg1[3]) << 24); uint64_t x64 = ((uint64_t)(arg1[2]) << 16); uint64_t x65 = ((uint64_t)(arg1[1]) << 8); uint8_t x66 = (arg1[0]); uint64_t x67 = (x66 + (x65 + (x64 + (x63 + (x62 + (x61 + (x60 + x59))))))); uint8_t x68 = (uint8_t)(x67 >> 58); uint64_t x69 = (x67 & UINT64_C(0x3ffffffffffffff)); uint64_t x70 = (x8 + (x7 + (x6 + (x5 + (x4 + (x3 + (x2 + x1))))))); uint64_t x71 = (x15 + (x14 + (x13 + (x12 + (x11 + (x10 + x9)))))); uint64_t x72 = (x22 + (x21 + (x20 + (x19 + (x18 + (x17 + x16)))))); uint64_t x73 = (x29 + (x28 + (x27 + (x26 + (x25 + (x24 + x23)))))); uint64_t x74 = (x37 + (x36 + (x35 + (x34 + (x33 + (x32 + (x31 + x30))))))); uint64_t x75 = (x44 + (x43 + (x42 + (x41 + (x40 + (x39 + x38)))))); uint64_t x76 = (x51 + (x50 + (x49 + (x48 + (x47 + (x46 + x45)))))); uint64_t x77 = (x58 + (x57 + (x56 + (x55 + (x54 + (x53 + x52)))))); uint64_t x78 = (x68 + x77); uint8_t x79 = (uint8_t)(x78 >> 58); uint64_t x80 = (x78 & UINT64_C(0x3ffffffffffffff)); uint64_t x81 = (x79 + x76); uint8_t x82 = (uint8_t)(x81 >> 58); uint64_t x83 = (x81 & UINT64_C(0x3ffffffffffffff)); uint64_t x84 = (x82 + x75); uint64_t x85 = (x84 & UINT64_C(0x3ffffffffffffff)); uint8_t x86 = (uint8_t)(x74 >> 58); uint64_t x87 = (x74 & UINT64_C(0x3ffffffffffffff)); uint64_t x88 = (x86 + x73); uint8_t x89 = (uint8_t)(x88 >> 58); uint64_t x90 = (x88 & UINT64_C(0x3ffffffffffffff)); uint64_t x91 = (x89 + x72); uint8_t x92 = (uint8_t)(x91 >> 58); uint64_t x93 = (x91 & UINT64_C(0x3ffffffffffffff)); uint64_t x94 = (x92 + x71); uint64_t x95 = (x94 & UINT64_C(0x3ffffffffffffff)); out1[0] = x69; out1[1] = x80; out1[2] = x83; out1[3] = x85; out1[4] = x87; out1[5] = x90; out1[6] = x93; out1[7] = x95; out1[8] = x70; }
the_stack_data/151191.c
/* You have been given a positive integer N. You need to find and print the Factorial of this number. The Factorial of a positive integer N refers to the product of all number in the range from 1 to N. You can read more about the factorial of a number here. Input Format: The first and only line of the input contains a single integer N denoting the number whose factorial you need to find. Output Format Output a single line denoting the factorial of the number N. Constraints 1 <= N <= 10 SAMPLE INPUT 2 SAMPLE OUTPUT 2 */ #include<stdio.h> int factorial(int n){ if(n==0) return 1; if(n==1) return n; return factorial(n-1) * n; } int main() { int N; scanf("%d", &N); printf("%d", factorial(N)); return 0; }
the_stack_data/1147802.c
/* * POK header * * The following file is a part of the POK project. Any modification should * be made according to the POK licence. You CANNOT use this file or a part * of a file for your own project. * * For more information on the POK licence, please see our LICENCE FILE * * Please follow the coding guidelines described in doc/CODING_GUIDELINES * * Copyright (c) 2007-2022 POK team */ /* @(#)w_scalb.c 5.1 93/09/24 */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #ifdef POK_NEEDS_LIBMATH /* * wrapper scalb(double x, double fn) is provide for * passing various standard test suite. One * should use scalbn() instead. */ #include "math_private.h" #include <libm.h> #include <errno.h> #ifdef _SCALB_INT double scalb(double x, int fn) /* wrapper scalb */ #else double scalb(double x, double fn) /* wrapper scalb */ #endif { #ifdef _IEEE_LIBM return __ieee754_scalb(x, fn); #else double z; z = __ieee754_scalb(x, fn); if (_LIB_VERSION == _IEEE_) return z; if (!(finite(z) || isnan(z)) && finite(x)) { return __kernel_standard(x, (double)fn, 32); /* scalb overflow */ } if (z == 0.0 && z != x) { return __kernel_standard(x, (double)fn, 33); /* scalb underflow */ } #ifndef _SCALB_INT if (!finite(fn)) errno = POK_ERRNO_ERANGE; #endif return z; #endif } #endif
the_stack_data/59420.c
/* Generated by CIL v. 1.3.7 */ /* print_CIL_Input is true */ #line 31 "/usr/include/bits/types.h" typedef unsigned char __u_char; #line 35 "/usr/include/sys/types.h" typedef __u_char u_char; #line 339 "/usr/include/stdio.h" extern int printf(char const * __restrict __format , ...) ; #line 81 "/usr/include/ctype.h" extern __attribute__((__nothrow__)) unsigned short const **__ctype_b_loc(void) __attribute__((__const__)) ; #line 67 "./sendmail.h" void tTflag(char *s ) ; #line 68 void tTsetup(u_char *vect , int size , char *defflags ) ; #line 88 "tTflag-bad.c" static u_char *tTvect ; #line 89 "tTflag-bad.c" static int tTsize ; #line 90 "tTflag-bad.c" static char *DefFlags ; #line 94 "tTflag-bad.c" void tTsetup(u_char *vect , int size , char *defflags ) { { #line 100 tTvect = vect; #line 101 tTsize = size; #line 102 DefFlags = defflags; #line 103 return; } } #line 118 "tTflag-bad.c" void tTflag(char *s ) { int first ; int last ; register unsigned int i ; char *tmp ; unsigned short const **tmp___0 ; unsigned short const **tmp___1 ; unsigned short const **tmp___2 ; int tmp___3 ; char *tmp___4 ; char __cil_tmp11 ; int __cil_tmp12 ; char __cil_tmp13 ; int __cil_tmp14 ; int __cil_tmp15 ; char __cil_tmp16 ; int __cil_tmp17 ; unsigned short const *__cil_tmp18 ; unsigned short const *__cil_tmp19 ; unsigned short __cil_tmp20 ; int __cil_tmp21 ; char __cil_tmp22 ; int __cil_tmp23 ; int __cil_tmp24 ; unsigned int __cil_tmp25 ; unsigned int __cil_tmp26 ; char __cil_tmp27 ; int __cil_tmp28 ; char __cil_tmp29 ; int __cil_tmp30 ; int __cil_tmp31 ; char __cil_tmp32 ; int __cil_tmp33 ; unsigned short const *__cil_tmp34 ; unsigned short const *__cil_tmp35 ; unsigned short __cil_tmp36 ; int __cil_tmp37 ; char __cil_tmp38 ; int __cil_tmp39 ; int __cil_tmp40 ; unsigned int __cil_tmp41 ; unsigned int __cil_tmp42 ; char __cil_tmp43 ; int __cil_tmp44 ; char __cil_tmp45 ; int __cil_tmp46 ; int __cil_tmp47 ; char __cil_tmp48 ; int __cil_tmp49 ; unsigned short const *__cil_tmp50 ; unsigned short const *__cil_tmp51 ; unsigned short __cil_tmp52 ; int __cil_tmp53 ; char __cil_tmp54 ; int __cil_tmp55 ; int __cil_tmp56 ; unsigned int __cil_tmp57 ; unsigned int __cil_tmp58 ; char const * __restrict __cil_tmp59 ; u_char *__cil_tmp60 ; char __cil_tmp61 ; int __cil_tmp62 ; { { #line 125 __cil_tmp11 = *s; #line 125 __cil_tmp12 = (int )__cil_tmp11; #line 125 if (__cil_tmp12 == 0) { #line 126 s = DefFlags; } else { } } { #line 128 while (1) { while_continue: /* CIL Label */ ; #line 131 i = 0U; { #line 133 while (1) { while_continue___0: /* CIL Label */ ; { #line 133 __cil_tmp13 = *s; #line 133 __cil_tmp14 = (int )__cil_tmp13; #line 133 __cil_tmp15 = __cil_tmp14 & -128; #line 133 if (__cil_tmp15 == 0) { { #line 133 tmp___0 = __ctype_b_loc(); } { #line 133 __cil_tmp16 = *s; #line 133 __cil_tmp17 = (int )__cil_tmp16; #line 133 __cil_tmp18 = *tmp___0; #line 133 __cil_tmp19 = __cil_tmp18 + __cil_tmp17; #line 133 __cil_tmp20 = *__cil_tmp19; #line 133 __cil_tmp21 = (int const )__cil_tmp20; #line 133 if (__cil_tmp21 & 2048) { } else { #line 133 goto while_break___0; } } } else { #line 133 goto while_break___0; } } #line 134 tmp = s; #line 134 s = s + 1; #line 134 __cil_tmp22 = *tmp; #line 134 __cil_tmp23 = (int )__cil_tmp22; #line 134 __cil_tmp24 = __cil_tmp23 - 48; #line 134 __cil_tmp25 = (unsigned int )__cil_tmp24; #line 134 __cil_tmp26 = i * 10U; #line 134 i = __cil_tmp26 + __cil_tmp25; } while_break___0: /* CIL Label */ ; } #line 138 first = (int )i; { #line 141 __cil_tmp27 = *s; #line 141 __cil_tmp28 = (int )__cil_tmp27; #line 141 if (__cil_tmp28 == 45) { #line 143 i = 0U; { #line 144 while (1) { while_continue___1: /* CIL Label */ ; #line 144 s = s + 1; { #line 144 __cil_tmp29 = *s; #line 144 __cil_tmp30 = (int )__cil_tmp29; #line 144 __cil_tmp31 = __cil_tmp30 & -128; #line 144 if (__cil_tmp31 == 0) { { #line 144 tmp___1 = __ctype_b_loc(); } { #line 144 __cil_tmp32 = *s; #line 144 __cil_tmp33 = (int )__cil_tmp32; #line 144 __cil_tmp34 = *tmp___1; #line 144 __cil_tmp35 = __cil_tmp34 + __cil_tmp33; #line 144 __cil_tmp36 = *__cil_tmp35; #line 144 __cil_tmp37 = (int const )__cil_tmp36; #line 144 if (__cil_tmp37 & 2048) { } else { #line 144 goto while_break___1; } } } else { #line 144 goto while_break___1; } } #line 145 __cil_tmp38 = *s; #line 145 __cil_tmp39 = (int )__cil_tmp38; #line 145 __cil_tmp40 = __cil_tmp39 - 48; #line 145 __cil_tmp41 = (unsigned int )__cil_tmp40; #line 145 __cil_tmp42 = i * 10U; #line 145 i = __cil_tmp42 + __cil_tmp41; } while_break___1: /* CIL Label */ ; } } else { } } #line 147 last = (int )i; #line 150 i = 1U; { #line 151 __cil_tmp43 = *s; #line 151 __cil_tmp44 = (int )__cil_tmp43; #line 151 if (__cil_tmp44 == 46) { #line 153 i = 0U; { #line 154 while (1) { while_continue___2: /* CIL Label */ ; #line 154 s = s + 1; { #line 154 __cil_tmp45 = *s; #line 154 __cil_tmp46 = (int )__cil_tmp45; #line 154 __cil_tmp47 = __cil_tmp46 & -128; #line 154 if (__cil_tmp47 == 0) { { #line 154 tmp___2 = __ctype_b_loc(); } { #line 154 __cil_tmp48 = *s; #line 154 __cil_tmp49 = (int )__cil_tmp48; #line 154 __cil_tmp50 = *tmp___2; #line 154 __cil_tmp51 = __cil_tmp50 + __cil_tmp49; #line 154 __cil_tmp52 = *__cil_tmp51; #line 154 __cil_tmp53 = (int const )__cil_tmp52; #line 154 if (__cil_tmp53 & 2048) { } else { #line 154 goto while_break___2; } } } else { #line 154 goto while_break___2; } } #line 155 __cil_tmp54 = *s; #line 155 __cil_tmp55 = (int )__cil_tmp54; #line 155 __cil_tmp56 = __cil_tmp55 - 48; #line 155 __cil_tmp57 = (unsigned int )__cil_tmp56; #line 155 __cil_tmp58 = i * 10U; #line 155 i = __cil_tmp58 + __cil_tmp57; } while_break___2: /* CIL Label */ ; } } else { } } #line 160 if (first >= tTsize) { #line 161 first = tTsize - 1; } else { } #line 162 if (last >= tTsize) { #line 163 last = tTsize - 1; } else { } { #line 166 while (1) { while_continue___3: /* CIL Label */ ; #line 166 if (first <= last) { } else { #line 166 goto while_break___3; } { #line 168 __cil_tmp59 = (char const * __restrict )"index = %d\n"; #line 168 printf(__cil_tmp59, first); } #line 171 tmp___3 = first; #line 171 first = first + 1; #line 171 __cil_tmp60 = tTvect + tmp___3; #line 171 *__cil_tmp60 = (u_char )i; } while_break___3: /* CIL Label */ ; } #line 177 tmp___4 = s; #line 177 s = s + 1; { #line 177 __cil_tmp61 = *tmp___4; #line 177 __cil_tmp62 = (int )__cil_tmp61; #line 177 if (__cil_tmp62 == 0) { #line 178 return; } else { } } } while_break: /* CIL Label */ ; } } }
the_stack_data/125140670.c
int a[10] = {1,4,7,2,3,0,8,5,9,6}; // BitMINICC灏氭湭瀹炵幇鎸囬拡锛岄噰鐢ㄥ叏灞�鏁扮粍 void quick(int start,int end); int partion(int low,int high); void quickSort(int len){ quick(0,len-1); return; } void quick(int start,int end){ int par = partion(start,end); if(par > start + 1){ quick(start, par-1); } if(par < end - 1){ quick(par+1, end); } return; } int partion(int low, int high){ int tmp = a[low]; for(; low < high; ){ for(; low < high && a[high] > tmp;){ high --; } if(low >= high){ break; }else{ a[low] = a[high]; } for(; low < high && a[low] < tmp;){ low ++; } if(low >= high){ break; }else{ a[high] = a[low]; } } a[low] = tmp; return low; } int main(){ Mars_PrintStr("Before quicksort:\n"); for(int i = 0; i<10; i++){ Mars_PrintInt(a[i]); } quickSort(10); Mars_PrintStr("\nAfter quicksort:\n"); for(int i = 0; i<10; i++){ Mars_PrintInt(a[i]); } return 0; }
the_stack_data/336485.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 short input[1] , unsigned short 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 short input[1] ; unsigned short output[1] ; int randomFuns_i5 ; unsigned short 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 short )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 5875) { 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 megaInit(void) { { } } void RandomFunc(unsigned short input[1] , unsigned short output[1] ) { unsigned short state[1] ; unsigned short local2 ; unsigned short local1 ; { state[0UL] = input[0UL] + (unsigned short)2885; local1 = 0UL; while (local1 < input[1UL]) { local2 = 0UL; while (local2 < input[1UL]) { local2 += 2UL; } local1 += 2UL; } output[0UL] = (state[0UL] - 146565199UL) + (unsigned short)17348; } }
the_stack_data/1527.c
/* PR target/59644 */ /* { dg-do run { target lp64 } } */ /* { dg-options "-O2 -ffreestanding -mno-sse -mpreferred-stack-boundary=3 -maccumulate-outgoing-args -mno-red-zone" } */ /* This test uses __builtin_trap () instead of e.g. abort, because due to -mpreferred-stack-boundary=3 it should not call any library function from within main (). */ #include <stdarg.h> __attribute__((noinline, noclone)) int bar (int x, int y, int z, int w, const char *fmt, va_list ap) { if (x != 1 || y != 2 || z != 3 || w != 4) __builtin_trap (); if (fmt[0] != 'f' || fmt[1] != 'o' || fmt[2] != 'o' || fmt[3]) __builtin_trap (); if (va_arg (ap, int) != 5 || va_arg (ap, int) != 6 || va_arg (ap, long long) != 7LL) __builtin_trap (); return 9; } __attribute__((noinline, noclone, optimize ("Os"))) int foo (const char *fmt, ...) { va_list ap; va_start (ap, fmt); int r = bar (1, 2, 3, 4, fmt, ap); va_end (ap); return r; } int main () { if (foo ("foo", 5, 6, 7LL) != 9) __builtin_trap (); return 0; }
the_stack_data/34511991.c
#include <stdio.h> #include <stdlib.h> typedef struct tuple_int_int { int tuple_int_int_field_0; int tuple_int_int_field_1; } tuple_int_int; typedef struct toto { struct tuple_int_int * foo; int bar; } toto; int main(void) { int d, c, bar_; scanf("%d %d %d ", &bar_, &c, &d); struct tuple_int_int * e = malloc(sizeof(tuple_int_int)); e->tuple_int_int_field_0 = c; e->tuple_int_int_field_1 = d; struct toto * t = malloc(sizeof(toto)); t->foo = e; t->bar = bar_; struct tuple_int_int * f = t->foo; int a = f->tuple_int_int_field_0; int b = f->tuple_int_int_field_1; printf("%d %d %d\n", a, b, t->bar); return 0; }
the_stack_data/610816.c
#include <ctype.h> #include <errno.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #define READ 0 #define WRITE 1 static void get_cpuid(char buffer[13]) { memset(buffer, 0, 1024); int eax = 0; /* Get vendor ID */ int ebx, ecx, edx; /* ecx is often an input as well as an output. */ asm volatile("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "0" (eax), "2" (ecx)); ((int*)buffer)[0] = ebx; ((int*)buffer)[1] = edx; ((int*)buffer)[2] = ecx; buffer[12] = 0; } static void get_name(char *buffer) { int pipe_stdout[2]; int status; int n; memset(buffer, 0, 1024); pipe(pipe_stdout); pid_t pid = fork(); if(!pid) { /* Copy the pipes. */ if(dup2(pipe_stdout[WRITE], STDOUT_FILENO) == -1) { perror("exec: couldn't duplicate STDOUT handle"); exit(1); } /* Execute the new process. */ execlp("uname", "uname", "-n", (char*) NULL); /* If execlp returns, bad stuff happened. */ printf("exec: execlp failed (%d)", errno); exit(1); } waitpid(pid, &status, 0); n = read(pipe_stdout[READ], buffer, 1024); buffer[n-1] = '\0'; } static void get_os(char *buffer) { int i, n, m; memset(buffer, 0, 1024); FILE *f = fopen("/proc/version", "r"); n = fread(buffer, 1, 1024, f); m = strchr(strchr(buffer, ' ') + 1, ' ') - buffer + 1; memmove(buffer, buffer + m, n - m); for(i = 0; ; i++) { if(!isdigit(buffer[i]) && buffer[i] != '.') { buffer[i] = '\0'; return; } } } #define SWAP(n,s,i,j) tmp=s[(i)%n];s[(i)%n]=s[(j)%n];s[(j)%n]=tmp; #define A(n,s,i) SWAP(n,s,i*3, i*11) #define B(n,s,i) SWAP(n,s,i|12,i<<3) #define C(n,s,i) SWAP(n,s,i*7, i*17) #define D(n,s,i) SWAP(n,s,i^3, i*i) #define E(n,s,i) A(n,s,i+buffer2[0]);B(n,s,i+buffer2[ 8]);C(n,s,i+buffer2[16]);D(n,s,i+buffer2[24]) #define F(n,s,i) B(n,s,i+buffer2[1]);C(n,s,i+buffer2[ 9]);D(n,s,i+buffer2[17]);A(n,s,i+buffer2[25]) #define G(n,s,i) C(n,s,i+buffer2[2]);D(n,s,i+buffer2[10]);A(n,s,i+buffer2[18]);B(n,s,i+buffer2[26]) #define H(n,s,i) D(n,s,i+buffer2[3]);A(n,s,i+buffer2[11]);B(n,s,i+buffer2[19]);C(n,s,i+buffer2[27]) #define I(n,s,i) E(n,s,i+buffer2[4]);F(n,s,i+buffer2[12]);G(n,s,i+buffer2[20]);H(n,s,i+buffer2[28]) #define J(n,s,i) H(n,s,i+buffer2[5]);G(n,s,i+buffer2[13]);F(n,s,i+buffer2[21]);E(n,s,i+buffer2[29]) #define K(n,s,i) F(n,s,i+buffer2[6]);F(n,s,i+buffer2[14]);G(n,s,i+buffer2[22]);G(n,s,i+buffer2[30]) #define L(n,s,i) E(n,s,i+buffer2[7]);E(n,s,i+buffer2[15]);H(n,s,i+buffer2[23]);H(n,s,i+buffer2[31]) static void finish(char *buffer2) { char key[] = "8988317ff468a390eb1d163cd46e7b182d6dbedb3c63290174300fdab69c584f"; /*char buffer[] = "FLAG:18ee7c71d2794f546ca23e6858de0bc6";*/ char buffer[] = "\x12\x56\x27\x70\x2c\x07\x5a\x67\x44\x0f\x07\x00\x63\x06\x4a\x3c\x0f\x04\x57\x01\x0d\x55\x65\x05\x34\x0b\x6d\x05\x73\x20\x7a\x06\x57\x04\x54\x24\x03\x31"; int i, j, k, l; int tmp; int n = sizeof(key)-1; for(i = 0; i < sizeof(key); i++) key[i] ^= buffer2[i]; for(i = 0; i < n*100; i++) { I(n, key, i); J(n, key, i); K(n, key, i); L(n, key, i); } for(i = 0; i < sizeof(buffer); i++) buffer[i] ^= key[i]; printf("\n\n"); printf("The key is: %s\n", buffer); } int main(int argc, char **argv) { int i; char buffer[1024]; char buffer2[1024]; memset(buffer2, 0, 1024); get_name(buffer); #ifdef TEST1 strcpy(buffer, "hax0rz!~"); #endif printf("Computer name: %s\n", buffer); if(strcmp(buffer, "hax0rz!~")) { printf("Sorry, your computer's name - %s - is not correct!\n", buffer); raise(SIGKILL); } strcat(buffer2, buffer); get_os(buffer); printf("OS version: %s\n", buffer); #ifdef TEST2 strcpy(buffer, "2.4.31"); #endif if(strcmp(buffer, "2.4.31")) { printf("Sorry, your OS version - %s - is not supported!\n", buffer); raise(SIGKILL); } strcat(buffer2, buffer); get_cpuid(buffer); #ifdef TEST3 strcpy(buffer, "AMDisbetter!"); #endif printf("%s\n", buffer); if(strcmp(buffer, "AMDisbetter!")) { printf("Sorry, your CPU - %s - is not supported!\n", buffer); raise(SIGKILL); } strcat(buffer2, buffer); finish(buffer2); }
the_stack_data/927629.c
/* stbi-1.29 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c when you control the images you're loading no warranty implied; use at your own risk QUICK NOTES: Primarily of interest to game developers and other people who can avoid problematic images and only need the trivial interface JPEG baseline (no JPEG progressive) PNG 8-bit only TGA (not sure what subset, if a subset) BMP non-1bpp, non-RLE PSD (composited view only, no extra channels) GIF (*comp always reports as 4-channel) HDR (radiance rgbE format) PIC (Softimage PIC) - decoded from memory or through stdio FILE (define STBI_NO_STDIO to remove code) - supports installable dequantizing-IDCT, YCbCr-to-RGB conversion (define STBI_SIMD) Latest revisions: 1.29 (2010-08-16) various warning fixes from Aurelien Pocheville 1.28 (2010-08-01) fix bug in GIF palette transparency (SpartanJ) 1.27 (2010-08-01) cast-to-uint8 to fix warnings (Laurent Gomila) allow trailing 0s at end of image data (Laurent Gomila) 1.26 (2010-07-24) fix bug in file buffering for PNG reported by SpartanJ 1.25 (2010-07-17) refix trans_data warning (Won Chun) 1.24 (2010-07-12) perf improvements reading from files minor perf improvements for jpeg deprecated type-specific functions in hope of feedback attempt to fix trans_data warning (Won Chun) 1.23 fixed bug in iPhone support 1.22 (2010-07-10) removed image *writing* support to stb_image_write.h stbi_info support from Jetro Lauha GIF support from Jean-Marc Lienher iPhone PNG-extensions from James Brown warning-fixes from Nicolas Schulz and Janez Zemva 1.21 fix use of 'uint8' in header (reported by jon blow) 1.20 added support for Softimage PIC, by Tom Seddon See end of file for full revision history. TODO: stbi_info support for BMP,PSD,HDR,PIC rewrite stbi_info and load_file variations to share file handling code (current system allows individual functions to be called directly, since each does all the work, but I doubt anyone uses this in practice) ============================ Contributors ========================= Image formats Optimizations & bugfixes Sean Barrett (jpeg, png, bmp) Fabian "ryg" Giesen Nicolas Schulz (hdr, psd) Jonathan Dummer (tga) Bug fixes & warning fixes Jean-Marc Lienher (gif) Marc LeBlanc Tom Seddon (pic) Christpher Lloyd Thatcher Ulrich (psd) Dave Moore Won Chun the Horde3D community Extensions, features Janez Zemva Jetro Lauha (stbi_info) Jonathan Blow James "moose2000" Brown (iPhone PNG) Laurent Gomila Aruelien Pocheville If your name should be here but isn't, let Sean know. */ #ifndef STBI_INCLUDE_STB_IMAGE_H #define STBI_INCLUDE_STB_IMAGE_H // To get a header file for this, either cut and paste the header, // or create stb_image.h, #define STBI_HEADER_FILE_ONLY, and // then include stb_image.c from it. //// begin header file //////////////////////////////////////////////////// // // Limitations: // - no jpeg progressive support // - non-HDR formats support 8-bit samples only (jpeg, png) // - no delayed line count (jpeg) -- IJG doesn't support either // - no 1-bit BMP // - GIF always returns *comp=4 // // Basic usage (see HDR discussion below): // int x,y,n; // unsigned char *data = stbi_load(filename, &x, &y, &n, 0); // // ... process data if not NULL ... // // ... x = width, y = height, n = # 8-bit components per pixel ... // // ... replace '0' with '1'..'4' to force that many components per pixel // stbi_image_free(data) // // Standard parameters: // int *x -- outputs image width in pixels // int *y -- outputs image height in pixels // int *comp -- outputs # of image components in image file // int req_comp -- if non-zero, # of image components requested in result // // The return value from an image loader is an 'unsigned char *' which points // to the pixel data. The pixel data consists of *y scanlines of *x pixels, // with each pixel consisting of N interleaved 8-bit components; the first // pixel pointed to is top-left-most in the image. There is no padding between // image scanlines or between pixels, regardless of format. The number of // components N is 'req_comp' if req_comp is non-zero, or *comp otherwise. // If req_comp is non-zero, *comp has the number of components that _would_ // have been output otherwise. E.g. if you set req_comp to 4, you will always // get RGBA output, but you can check *comp to easily see if it's opaque. // // An output image with N components has the following components interleaved // in this order in each pixel: // // N=#comp components // 1 grey // 2 grey, alpha // 3 red, green, blue // 4 red, green, blue, alpha // // If image loading fails for any reason, the return value will be NULL, // and *x, *y, *comp will be unchanged. The function stbi_failure_reason() // can be queried for an extremely brief, end-user unfriendly explanation // of why the load failed. Define STBI_NO_FAILURE_STRINGS to avoid // compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly // more user-friendly ones. // // Paletted PNG, BMP, GIF, and PIC images are automatically depalettized. // // =========================================================================== // // iPhone PNG support: // // By default we convert iphone-formatted PNGs back to RGB; nominally they // would silently load as BGR, except the existing code should have just // failed on such iPhone PNGs. But you can disable this conversion by // by calling stbi_convert_iphone_png_to_rgb(0), in which case // you will always just get the native iphone "format" through. // // Call stbi_set_unpremultiply_on_load(1) as well to force a divide per // pixel to remove any premultiplied alpha *only* if the image file explicitly // says there's premultiplied data (currently only happens in iPhone images, // and only if iPhone convert-to-rgb processing is on). // // =========================================================================== // // HDR image support (disable by defining STBI_NO_HDR) // // stb_image now supports loading HDR images in general, and currently // the Radiance .HDR file format, although the support is provided // generically. You can still load any file through the existing interface; // if you attempt to load an HDR file, it will be automatically remapped to // LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1; // both of these constants can be reconfigured through this interface: // // stbi_hdr_to_ldr_gamma(2.2f); // stbi_hdr_to_ldr_scale(1.0f); // // (note, do not use _inverse_ constants; stbi_image will invert them // appropriately). // // Additionally, there is a new, parallel interface for loading files as // (linear) floats to preserve the full dynamic range: // // float *data = stbi_loadf(filename, &x, &y, &n, 0); // // If you load LDR images through this interface, those images will // be promoted to floating point values, run through the inverse of // constants corresponding to the above: // // stbi_ldr_to_hdr_scale(1.0f); // stbi_ldr_to_hdr_gamma(2.2f); // // Finally, given a filename (or an open file or memory block--see header // file for details) containing image data, you can query for the "most // appropriate" interface to use (that is, whether the image is HDR or // not), using: // // stbi_is_hdr(char *filename); #ifndef STBI_NO_STDIO #include <stdio.h> #endif #define STBI_VERSION 1 enum { STBI_default = 0, // only used for req_comp STBI_grey = 1, STBI_grey_alpha = 2, STBI_rgb = 3, STBI_rgb_alpha = 4 }; typedef unsigned char stbi_uc; #ifdef __cplusplus extern "C" { #endif // PRIMARY API - works on images of any type // load image by filename, open file, or memory buffer extern stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern stbi_uc *stbi_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); // for stbi_load_from_file, file pointer is left pointing immediately after image #endif #ifndef STBI_NO_HDR extern float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern float *stbi_loadf (char const *filename, int *x, int *y, int *comp, int req_comp); extern float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif extern void stbi_hdr_to_ldr_gamma(float gamma); extern void stbi_hdr_to_ldr_scale(float scale); extern void stbi_ldr_to_hdr_gamma(float gamma); extern void stbi_ldr_to_hdr_scale(float scale); #endif // STBI_NO_HDR // get a VERY brief reason for failure // NOT THREADSAFE extern const char *stbi_failure_reason (void); // free the loaded image -- this is just free() extern void stbi_image_free (void *retval_from_stbi_load); // get image dimensions & components without fully decoding extern int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); extern int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len); #ifndef STBI_NO_STDIO extern int stbi_info (char const *filename, int *x, int *y, int *comp); extern int stbi_info_from_file (FILE *f, int *x, int *y, int *comp); extern int stbi_is_hdr (char const *filename); extern int stbi_is_hdr_from_file(FILE *f); #endif // for image formats that explicitly notate that they have premultiplied alpha, // we just return the colors as stored in the file. set this flag to force // unpremultiplication. results are undefined if the unpremultiply overflow. extern void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); // indicate whether we should process iphone images back to canonical format, // or just pass them through "as-is" extern void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert); // ZLIB client - used by PNG, available for other purposes extern char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen); extern char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen); extern int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); extern char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen); extern int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); // define new loaders typedef struct { int (*test_memory)(stbi_uc const *buffer, int len); stbi_uc * (*load_from_memory)(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO int (*test_file)(FILE *f); stbi_uc * (*load_from_file)(FILE *f, int *x, int *y, int *comp, int req_comp); #endif } stbi_loader; // register a loader by filling out the above structure (you must define ALL functions) // returns 1 if added or already added, 0 if not added (too many loaders) // NOT THREADSAFE extern int stbi_register_loader(stbi_loader *loader); // define faster low-level operations (typically SIMD support) #ifdef STBI_SIMD typedef void (*stbi_idct_8x8)(stbi_uc *out, int out_stride, short data[64], unsigned short *dequantize); // compute an integer IDCT on "input" // input[x] = data[x] * dequantize[x] // write results to 'out': 64 samples, each run of 8 spaced by 'out_stride' // CLAMP results to 0..255 typedef void (*stbi_YCbCr_to_RGB_run)(stbi_uc *output, stbi_uc const *y, stbi_uc const *cb, stbi_uc const *cr, int count, int step); // compute a conversion from YCbCr to RGB // 'count' pixels // write pixels to 'output'; each pixel is 'step' bytes (either 3 or 4; if 4, write '255' as 4th), order R,G,B // y: Y input channel // cb: Cb input channel; scale/biased to be 0..255 // cr: Cr input channel; scale/biased to be 0..255 extern void stbi_install_idct(stbi_idct_8x8 func); extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func); #endif // STBI_SIMD // TYPE-SPECIFIC ACCESS #ifdef STBI_TYPE_SPECIFIC_FUNCTIONS // is it a jpeg? extern int stbi_jpeg_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_jpeg_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); extern int stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern stbi_uc *stbi_jpeg_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern int stbi_jpeg_test_file (FILE *f); extern stbi_uc *stbi_jpeg_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); extern int stbi_jpeg_info (char const *filename, int *x, int *y, int *comp); extern int stbi_jpeg_info_from_file (FILE *f, int *x, int *y, int *comp); #endif // is it a png? extern int stbi_png_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_png_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); extern int stbi_png_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern stbi_uc *stbi_png_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern int stbi_png_info (char const *filename, int *x, int *y, int *comp); extern int stbi_png_test_file (FILE *f); extern stbi_uc *stbi_png_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); extern int stbi_png_info_from_file (FILE *f, int *x, int *y, int *comp); #endif // is it a bmp? extern int stbi_bmp_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_bmp_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_bmp_test_file (FILE *f); extern stbi_uc *stbi_bmp_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a tga? extern int stbi_tga_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_tga_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_tga_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_tga_test_file (FILE *f); extern stbi_uc *stbi_tga_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a psd? extern int stbi_psd_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_psd_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_psd_test_file (FILE *f); extern stbi_uc *stbi_psd_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it an hdr? extern int stbi_hdr_test_memory (stbi_uc const *buffer, int len); extern float * stbi_hdr_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern float * stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_hdr_test_file (FILE *f); extern float * stbi_hdr_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a pic? extern int stbi_pic_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_pic_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_pic_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_pic_test_file (FILE *f); extern stbi_uc *stbi_pic_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a gif? extern int stbi_gif_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_gif_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_gif_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); extern int stbi_gif_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern int stbi_gif_test_file (FILE *f); extern stbi_uc *stbi_gif_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); extern int stbi_gif_info (char const *filename, int *x, int *y, int *comp); extern int stbi_gif_info_from_file (FILE *f, int *x, int *y, int *comp); #endif #endif//STBI_TYPE_SPECIFIC_FUNCTIONS #ifdef __cplusplus } #endif // // //// end header file ///////////////////////////////////////////////////// #endif // STBI_INCLUDE_STB_IMAGE_H #ifndef STBI_HEADER_FILE_ONLY #ifndef STBI_NO_HDR #include <math.h> // ldexp #include <string.h> // strcmp #endif #ifndef STBI_NO_STDIO #include <stdio.h> #endif #include <stdlib.h> #include <memory.h> #include <assert.h> #include <stdarg.h> #ifndef _MSC_VER #ifdef __cplusplus #define __forceinline inline #else #define __forceinline #endif #endif // implementation: typedef unsigned char uint8; typedef unsigned short uint16; typedef signed short int16; typedef unsigned int uint32; typedef signed int int32; typedef unsigned int uint; // should produce compiler error if size is wrong typedef unsigned char validate_uint32[sizeof(uint32)==4 ? 1 : -1]; #if defined(STBI_NO_STDIO) && !defined(STBI_NO_WRITE) #define STBI_NO_WRITE #endif #define STBI_NOTUSED(v) v=v #ifdef _MSC_VER #define STBI_HAS_LRTOL #endif #ifdef STBI_HAS_LRTOL #define stbi_lrot(x,y) _lrotl(x,y) #else #define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) #endif ////////////////////////////////////////////////////////////////////////////// // // Generic API that works on all image types // // deprecated functions // is it a jpeg? extern int stbi_jpeg_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_jpeg_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); extern int stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern stbi_uc *stbi_jpeg_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern int stbi_jpeg_test_file (FILE *f); extern stbi_uc *stbi_jpeg_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); extern int stbi_jpeg_info (char const *filename, int *x, int *y, int *comp); extern int stbi_jpeg_info_from_file (FILE *f, int *x, int *y, int *comp); #endif // is it a png? extern int stbi_png_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_png_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); extern int stbi_png_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern stbi_uc *stbi_png_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern int stbi_png_info (char const *filename, int *x, int *y, int *comp); extern int stbi_png_test_file (FILE *f); extern stbi_uc *stbi_png_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); extern int stbi_png_info_from_file (FILE *f, int *x, int *y, int *comp); #endif // is it a bmp? extern int stbi_bmp_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_bmp_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_bmp_test_file (FILE *f); extern stbi_uc *stbi_bmp_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a tga? extern int stbi_tga_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_tga_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_tga_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_tga_test_file (FILE *f); extern stbi_uc *stbi_tga_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a psd? extern int stbi_psd_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_psd_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_psd_test_file (FILE *f); extern stbi_uc *stbi_psd_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it an hdr? extern int stbi_hdr_test_memory (stbi_uc const *buffer, int len); extern float * stbi_hdr_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern float * stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_hdr_test_file (FILE *f); extern float * stbi_hdr_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a pic? extern int stbi_pic_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_pic_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_pic_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); #ifndef STBI_NO_STDIO extern int stbi_pic_test_file (FILE *f); extern stbi_uc *stbi_pic_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); #endif // is it a gif? extern int stbi_gif_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_gif_load (char const *filename, int *x, int *y, int *comp, int req_comp); extern stbi_uc *stbi_gif_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); extern int stbi_gif_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern int stbi_gif_test_file (FILE *f); extern stbi_uc *stbi_gif_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); extern int stbi_gif_info (char const *filename, int *x, int *y, int *comp); extern int stbi_gif_info_from_file (FILE *f, int *x, int *y, int *comp); #endif // this is not threadsafe static const char *failure_reason; const char *stbi_failure_reason(void) { return failure_reason; } static int e(const char *str) { failure_reason = str; return 0; } #ifdef STBI_NO_FAILURE_STRINGS #define e(x,y) 0 #elif defined(STBI_FAILURE_USERMSG) #define e(x,y) e(y) #else #define e(x,y) e(x) #endif #define epf(x,y) ((float *) (e(x,y)?NULL:NULL)) #define epuc(x,y) ((unsigned char *) (e(x,y)?NULL:NULL)) void stbi_image_free(void *retval_from_stbi_load) { free(retval_from_stbi_load); } #define MAX_LOADERS 32 stbi_loader *loaders[MAX_LOADERS]; static int max_loaders = 0; int stbi_register_loader(stbi_loader *loader) { int i; for (i=0; i < MAX_LOADERS; ++i) { // already present? if (loaders[i] == loader) return 1; // end of the list? if (loaders[i] == NULL) { loaders[i] = loader; max_loaders = i+1; return 1; } } // no room for it return 0; } #ifndef STBI_NO_HDR static float *ldr_to_hdr(stbi_uc *data, int x, int y, int comp); static stbi_uc *hdr_to_ldr(float *data, int x, int y, int comp); #endif #ifndef STBI_NO_STDIO unsigned char *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp) { FILE *f = fopen(filename, "rb"); unsigned char *result; if (!f) return epuc("can't fopen", "Unable to open file"); result = stbi_load_from_file(f,x,y,comp,req_comp); fclose(f); return result; } unsigned char *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { int i; if (stbi_jpeg_test_file(f)) return stbi_jpeg_load_from_file(f,x,y,comp,req_comp); if (stbi_png_test_file(f)) return stbi_png_load_from_file(f,x,y,comp,req_comp); if (stbi_bmp_test_file(f)) return stbi_bmp_load_from_file(f,x,y,comp,req_comp); if (stbi_gif_test_file(f)) return stbi_gif_load_from_file(f,x,y,comp,req_comp); if (stbi_psd_test_file(f)) return stbi_psd_load_from_file(f,x,y,comp,req_comp); if (stbi_pic_test_file(f)) return stbi_pic_load_from_file(f,x,y,comp,req_comp); #ifndef STBI_NO_HDR if (stbi_hdr_test_file(f)) { float *hdr = stbi_hdr_load_from_file(f, x,y,comp,req_comp); return hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp); } #endif for (i=0; i < max_loaders; ++i) if (loaders[i]->test_file(f)) return loaders[i]->load_from_file(f,x,y,comp,req_comp); // test tga last because it's a crappy test! if (stbi_tga_test_file(f)) return stbi_tga_load_from_file(f,x,y,comp,req_comp); return epuc("unknown image type", "Image not of any known type, or corrupt"); } #endif unsigned char *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { int i; if (stbi_jpeg_test_memory(buffer,len)) return stbi_jpeg_load_from_memory(buffer,len,x,y,comp,req_comp); if (stbi_png_test_memory(buffer,len)) return stbi_png_load_from_memory(buffer,len,x,y,comp,req_comp); if (stbi_bmp_test_memory(buffer,len)) return stbi_bmp_load_from_memory(buffer,len,x,y,comp,req_comp); if (stbi_gif_test_memory(buffer,len)) return stbi_gif_load_from_memory(buffer,len,x,y,comp,req_comp); if (stbi_psd_test_memory(buffer,len)) return stbi_psd_load_from_memory(buffer,len,x,y,comp,req_comp); if (stbi_pic_test_memory(buffer,len)) return stbi_pic_load_from_memory(buffer,len,x,y,comp,req_comp); #ifndef STBI_NO_HDR if (stbi_hdr_test_memory(buffer, len)) { float *hdr = stbi_hdr_load_from_memory(buffer, len,x,y,comp,req_comp); return hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp); } #endif for (i=0; i < max_loaders; ++i) if (loaders[i]->test_memory(buffer,len)) return loaders[i]->load_from_memory(buffer,len,x,y,comp,req_comp); // test tga last because it's a crappy test! if (stbi_tga_test_memory(buffer,len)) return stbi_tga_load_from_memory(buffer,len,x,y,comp,req_comp); return epuc("unknown image type", "Image not of any known type, or corrupt"); } #ifndef STBI_NO_HDR #ifndef STBI_NO_STDIO float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp) { FILE *f = fopen(filename, "rb"); float *result; if (!f) return epf("can't fopen", "Unable to open file"); result = stbi_loadf_from_file(f,x,y,comp,req_comp); fclose(f); return result; } float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { unsigned char *data; #ifndef STBI_NO_HDR if (stbi_hdr_test_file(f)) return stbi_hdr_load_from_file(f,x,y,comp,req_comp); #endif data = stbi_load_from_file(f, x, y, comp, req_comp); if (data) return ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp); return epf("unknown image type", "Image not of any known type, or corrupt"); } #endif float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { stbi_uc *data; #ifndef STBI_NO_HDR if (stbi_hdr_test_memory(buffer, len)) return stbi_hdr_load_from_memory(buffer, len,x,y,comp,req_comp); #endif data = stbi_load_from_memory(buffer, len, x, y, comp, req_comp); if (data) return ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp); return epf("unknown image type", "Image not of any known type, or corrupt"); } #endif // these is-hdr-or-not is defined independent of whether STBI_NO_HDR is // defined, for API simplicity; if STBI_NO_HDR is defined, it always // reports false! int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len) { #ifndef STBI_NO_HDR return stbi_hdr_test_memory(buffer, len); #else STBI_NOTUSED(buffer); STBI_NOTUSED(len); return 0; #endif } #ifndef STBI_NO_STDIO extern int stbi_is_hdr (char const *filename) { FILE *f = fopen(filename, "rb"); int result=0; if (f) { result = stbi_is_hdr_from_file(f); fclose(f); } return result; } extern int stbi_is_hdr_from_file(FILE *f) { #ifndef STBI_NO_HDR return stbi_hdr_test_file(f); #else return 0; #endif } #endif #ifndef STBI_NO_HDR static float h2l_gamma_i=1.0f/2.2f, h2l_scale_i=1.0f; static float l2h_gamma=2.2f, l2h_scale=1.0f; void stbi_hdr_to_ldr_gamma(float gamma) { h2l_gamma_i = 1/gamma; } void stbi_hdr_to_ldr_scale(float scale) { h2l_scale_i = 1/scale; } void stbi_ldr_to_hdr_gamma(float gamma) { l2h_gamma = gamma; } void stbi_ldr_to_hdr_scale(float scale) { l2h_scale = scale; } #endif ////////////////////////////////////////////////////////////////////////////// // // Common code used by all image loaders // enum { SCAN_load=0, SCAN_type, SCAN_header }; typedef struct { uint32 img_x, img_y; int img_n, img_out_n; #ifndef STBI_NO_STDIO FILE *img_file; int buflen; uint8 buffer_start[128]; int from_file; #endif uint8 *img_buffer, *img_buffer_end; } stbi; #ifndef STBI_NO_STDIO static void start_file(stbi *s, FILE *f) { s->img_file = f; s->buflen = sizeof(s->buffer_start); s->img_buffer_end = s->buffer_start + s->buflen; s->img_buffer = s->img_buffer_end; s->from_file = 1; } #endif static void start_mem(stbi *s, uint8 const *buffer, int len) { #ifndef STBI_NO_STDIO s->img_file = NULL; s->from_file = 0; #endif s->img_buffer = (uint8 *) buffer; s->img_buffer_end = (uint8 *) buffer+len; } #ifndef STBI_NO_STDIO static void refill_buffer(stbi *s) { int n = fread(s->buffer_start, 1, s->buflen, s->img_file); if (n == 0) { s->from_file = 0; s->img_buffer = s->img_buffer_end-1; *s->img_buffer = 0; } else { s->img_buffer = s->buffer_start; s->img_buffer_end = s->buffer_start + n; } } #endif __forceinline static int get8(stbi *s) { if (s->img_buffer < s->img_buffer_end) return *s->img_buffer++; #ifndef STBI_NO_STDIO if (s->from_file) { refill_buffer(s); return *s->img_buffer++; } #endif return 0; } __forceinline static int at_eof(stbi *s) { #ifndef STBI_NO_STDIO if (s->img_file) { if (!feof(s->img_file)) return 0; // if feof() is true, check if buffer = end // special case: we've only got the special 0 character at the end if (s->from_file == 0) return 1; } #endif return s->img_buffer >= s->img_buffer_end; } __forceinline static uint8 get8u(stbi *s) { return (uint8) get8(s); } static void skip(stbi *s, int n) { #ifndef STBI_NO_STDIO if (s->img_file) { int blen = s->img_buffer_end - s->img_buffer; if (blen < n) { s->img_buffer = s->img_buffer_end; fseek(s->img_file, n - blen, SEEK_CUR); return; } } #endif s->img_buffer += n; } static int getn(stbi *s, stbi_uc *buffer, int n) { #ifndef STBI_NO_STDIO if (s->img_file) { int blen = s->img_buffer_end - s->img_buffer; if (blen < n) { int res; memcpy(buffer, s->img_buffer, blen); res = ((int) fread(buffer + blen, 1, n - blen, s->img_file) == (n-blen)); s->img_buffer = s->img_buffer_end; return res; } } #endif if (s->img_buffer+n <= s->img_buffer_end) { memcpy(buffer, s->img_buffer, n); s->img_buffer += n; return 1; } else return 0; } static int get16(stbi *s) { int z = get8(s); return (z << 8) + get8(s); } static uint32 get32(stbi *s) { uint32 z = get16(s); return (z << 16) + get16(s); } static int get16le(stbi *s) { int z = get8(s); return z + (get8(s) << 8); } static uint32 get32le(stbi *s) { uint32 z = get16le(s); return z + (get16le(s) << 16); } ////////////////////////////////////////////////////////////////////////////// // // generic converter from built-in img_n to req_comp // individual types do this automatically as much as possible (e.g. jpeg // does all cases internally since it needs to colorspace convert anyway, // and it never has alpha, so very few cases ). png can automatically // interleave an alpha=255 channel, but falls back to this for other cases // // assume data buffer is malloced, so malloc a new one and free that one // only failure mode is malloc failing static uint8 compute_y(int r, int g, int b) { return (uint8) (((r*77) + (g*150) + (29*b)) >> 8); } static unsigned char *convert_format(unsigned char *data, int img_n, int req_comp, uint x, uint y) { int i,j; unsigned char *good; if (req_comp == img_n) return data; assert(req_comp >= 1 && req_comp <= 4); good = (unsigned char *) malloc(req_comp * x * y); if (good == NULL) { free(data); return epuc("outofmem", "Out of memory"); } for (j=0; j < (int) y; ++j) { unsigned char *src = data + j * x * img_n ; unsigned char *dest = good + j * x * req_comp; #define COMBO(a,b) ((a)*8+(b)) #define CASE(a,b) case COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) // convert source image with img_n components to one with req_comp components; // avoid switch per pixel, so use switch per scanline and massive macros switch (COMBO(img_n, req_comp)) { CASE(1,2) dest[0]=src[0], dest[1]=255; break; CASE(1,3) dest[0]=dest[1]=dest[2]=src[0]; break; CASE(1,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; break; CASE(2,1) dest[0]=src[0]; break; CASE(2,3) dest[0]=dest[1]=dest[2]=src[0]; break; CASE(2,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; break; CASE(3,4) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; break; CASE(3,1) dest[0]=compute_y(src[0],src[1],src[2]); break; CASE(3,2) dest[0]=compute_y(src[0],src[1],src[2]), dest[1] = 255; break; CASE(4,1) dest[0]=compute_y(src[0],src[1],src[2]); break; CASE(4,2) dest[0]=compute_y(src[0],src[1],src[2]), dest[1] = src[3]; break; CASE(4,3) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; break; default: assert(0); } #undef CASE } free(data); return good; } #ifndef STBI_NO_HDR static float *ldr_to_hdr(stbi_uc *data, int x, int y, int comp) { int i,k,n; float *output = (float *) malloc(x * y * comp * sizeof(float)); if (output == NULL) { free(data); return epf("outofmem", "Out of memory"); } // compute number of non-alpha components if (comp & 1) n = comp; else n = comp-1; for (i=0; i < x*y; ++i) { for (k=0; k < n; ++k) { output[i*comp + k] = (float) pow(data[i*comp+k]/255.0f, l2h_gamma) * l2h_scale; } if (k < comp) output[i*comp + k] = data[i*comp+k]/255.0f; } free(data); return output; } #define float2int(x) ((int) (x)) static stbi_uc *hdr_to_ldr(float *data, int x, int y, int comp) { int i,k,n; stbi_uc *output = (stbi_uc *) malloc(x * y * comp); if (output == NULL) { free(data); return epuc("outofmem", "Out of memory"); } // compute number of non-alpha components if (comp & 1) n = comp; else n = comp-1; for (i=0; i < x*y; ++i) { for (k=0; k < n; ++k) { float z = (float) pow(data[i*comp+k]*h2l_scale_i, h2l_gamma_i) * 255 + 0.5f; if (z < 0) z = 0; if (z > 255) z = 255; output[i*comp + k] = (uint8) float2int(z); } if (k < comp) { float z = data[i*comp+k] * 255 + 0.5f; if (z < 0) z = 0; if (z > 255) z = 255; output[i*comp + k] = (uint8) float2int(z); } } free(data); return output; } #endif ////////////////////////////////////////////////////////////////////////////// // // "baseline" JPEG/JFIF decoder (not actually fully baseline implementation) // // simple implementation // - channel subsampling of at most 2 in each dimension // - doesn't support delayed output of y-dimension // - simple interface (only one output format: 8-bit interleaved RGB) // - doesn't try to recover corrupt jpegs // - doesn't allow partial loading, loading multiple at once // - still fast on x86 (copying globals into locals doesn't help x86) // - allocates lots of intermediate memory (full size of all components) // - non-interleaved case requires this anyway // - allows good upsampling (see next) // high-quality // - upsampled channels are bilinearly interpolated, even across blocks // - quality integer IDCT derived from IJG's 'slow' // performance // - fast huffman; reasonable integer IDCT // - uses a lot of intermediate memory, could cache poorly // - load http://nothings.org/remote/anemones.jpg 3 times on 2.8Ghz P4 // stb_jpeg: 1.34 seconds (MSVC6, default release build) // stb_jpeg: 1.06 seconds (MSVC6, processor = Pentium Pro) // IJL11.dll: 1.08 seconds (compiled by intel) // IJG 1998: 0.98 seconds (MSVC6, makefile provided by IJG) // IJG 1998: 0.95 seconds (MSVC6, makefile + proc=PPro) // huffman decoding acceleration #define FAST_BITS 9 // larger handles more cases; smaller stomps less cache typedef struct { uint8 fast[1 << FAST_BITS]; // weirdly, repacking this into AoS is a 10% speed loss, instead of a win uint16 code[256]; uint8 values[256]; uint8 size[257]; unsigned int maxcode[18]; int delta[17]; // old 'firstsymbol' - old 'firstcode' } huffman; typedef struct { #ifdef STBI_SIMD unsigned short dequant2[4][64]; #endif stbi s; huffman huff_dc[4]; huffman huff_ac[4]; uint8 dequant[4][64]; // sizes for components, interleaved MCUs int img_h_max, img_v_max; int img_mcu_x, img_mcu_y; int img_mcu_w, img_mcu_h; // definition of jpeg image component struct { int id; int h,v; int tq; int hd,ha; int dc_pred; int x,y,w2,h2; uint8 *data; void *raw_data; uint8 *linebuf; } img_comp[4]; uint32 code_buffer; // jpeg entropy-coded buffer int code_bits; // number of valid bits unsigned char marker; // marker seen while filling entropy buffer int nomore; // flag if we saw a marker so must stop int scan_n, order[4]; int restart_interval, todo; } jpeg; static int build_huffman(huffman *h, int *count) { int i,j,k=0,code; // build size list for each symbol (from JPEG spec) for (i=0; i < 16; ++i) for (j=0; j < count[i]; ++j) h->size[k++] = (uint8) (i+1); h->size[k] = 0; // compute actual symbols (from jpeg spec) code = 0; k = 0; for(j=1; j <= 16; ++j) { // compute delta to add to code to compute symbol id h->delta[j] = k - code; if (h->size[k] == j) { while (h->size[k] == j) h->code[k++] = (uint16) (code++); if (code-1 >= (1 << j)) return e("bad code lengths","Corrupt JPEG"); } // compute largest code + 1 for this size, preshifted as needed later h->maxcode[j] = code << (16-j); code <<= 1; } h->maxcode[j] = 0xffffffff; // build non-spec acceleration table; 255 is flag for not-accelerated memset(h->fast, 255, 1 << FAST_BITS); for (i=0; i < k; ++i) { int s = h->size[i]; if (s <= FAST_BITS) { int c = h->code[i] << (FAST_BITS-s); int m = 1 << (FAST_BITS-s); for (j=0; j < m; ++j) { h->fast[c+j] = (uint8) i; } } } return 1; } static void grow_buffer_unsafe(jpeg *j) { do { int b = j->nomore ? 0 : get8(&j->s); if (b == 0xff) { int c = get8(&j->s); if (c != 0) { j->marker = (unsigned char) c; j->nomore = 1; return; } } j->code_buffer |= b << (24 - j->code_bits); j->code_bits += 8; } while (j->code_bits <= 24); } // (1 << n) - 1 static uint32 bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; // decode a jpeg huffman value from the bitstream __forceinline static int decode(jpeg *j, huffman *h) { unsigned int temp; int c,k; if (j->code_bits < 16) grow_buffer_unsafe(j); // look at the top FAST_BITS and determine what symbol ID it is, // if the code is <= FAST_BITS c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); k = h->fast[c]; if (k < 255) { int s = h->size[k]; if (s > j->code_bits) return -1; j->code_buffer <<= s; j->code_bits -= s; return h->values[k]; } // naive test is to shift the code_buffer down so k bits are // valid, then test against maxcode. To speed this up, we've // preshifted maxcode left so that it has (16-k) 0s at the // end; in other words, regardless of the number of bits, it // wants to be compared against something shifted to have 16; // that way we don't need to shift inside the loop. temp = j->code_buffer >> 16; for (k=FAST_BITS+1 ; ; ++k) if (temp < h->maxcode[k]) break; if (k == 17) { // error! code not found j->code_bits -= 16; return -1; } if (k > j->code_bits) return -1; // convert the huffman code to the symbol id c = ((j->code_buffer >> (32 - k)) & bmask[k]) + h->delta[k]; assert((((j->code_buffer) >> (32 - h->size[c])) & bmask[h->size[c]]) == h->code[c]); // convert the id to a symbol j->code_bits -= k; j->code_buffer <<= k; return h->values[c]; } // combined JPEG 'receive' and JPEG 'extend', since baseline // always extends everything it receives. __forceinline static int extend_receive(jpeg *j, int n) { unsigned int m = 1 << (n-1); unsigned int k; if (j->code_bits < n) grow_buffer_unsafe(j); #if 1 k = stbi_lrot(j->code_buffer, n); j->code_buffer = k & ~bmask[n]; k &= bmask[n]; j->code_bits -= n; #else k = (j->code_buffer >> (32 - n)) & bmask[n]; j->code_bits -= n; j->code_buffer <<= n; #endif // the following test is probably a random branch that won't // predict well. I tried to table accelerate it but failed. // maybe it's compiling as a conditional move? if (k < m) return (-1 << n) + k + 1; else return k; } // given a value that's at position X in the zigzag stream, // where does it appear in the 8x8 matrix coded as row-major? static uint8 dezigzag[64+15] = { 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63, // let corrupt input sample past end 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 }; // decode one 64-entry block-- static int decode_block(jpeg *j, short data[64], huffman *hdc, huffman *hac, int b) { int diff,dc,k; int t = decode(j, hdc); if (t < 0) return e("bad huffman code","Corrupt JPEG"); // 0 all the ac values now so we can do it 32-bits at a time memset(data,0,64*sizeof(data[0])); diff = t ? extend_receive(j, t) : 0; dc = j->img_comp[b].dc_pred + diff; j->img_comp[b].dc_pred = dc; data[0] = (short) dc; // decode AC components, see JPEG spec k = 1; do { int r,s; int rs = decode(j, hac); if (rs < 0) return e("bad huffman code","Corrupt JPEG"); s = rs & 15; r = rs >> 4; if (s == 0) { if (rs != 0xf0) break; // end block k += 16; } else { k += r; // decode into unzigzag'd location data[dezigzag[k++]] = (short) extend_receive(j,s); } } while (k < 64); return 1; } // take a -128..127 value and clamp it and convert to 0..255 __forceinline static uint8 clamp(int x) { // trick to use a single test to catch both cases if ((unsigned int) x > 255) { if (x < 0) return 0; if (x > 255) return 255; } return (uint8) x; } #define f2f(x) (int) (((x) * 4096 + 0.5)) #define fsh(x) ((x) << 12) // derived from jidctint -- DCT_ISLOW #define IDCT_1D(s0,s1,s2,s3,s4,s5,s6,s7) \ int t0,t1,t2,t3,p1,p2,p3,p4,p5,x0,x1,x2,x3; \ p2 = s2; \ p3 = s6; \ p1 = (p2+p3) * f2f(0.5411961f); \ t2 = p1 + p3*f2f(-1.847759065f); \ t3 = p1 + p2*f2f( 0.765366865f); \ p2 = s0; \ p3 = s4; \ t0 = fsh(p2+p3); \ t1 = fsh(p2-p3); \ x0 = t0+t3; \ x3 = t0-t3; \ x1 = t1+t2; \ x2 = t1-t2; \ t0 = s7; \ t1 = s5; \ t2 = s3; \ t3 = s1; \ p3 = t0+t2; \ p4 = t1+t3; \ p1 = t0+t3; \ p2 = t1+t2; \ p5 = (p3+p4)*f2f( 1.175875602f); \ t0 = t0*f2f( 0.298631336f); \ t1 = t1*f2f( 2.053119869f); \ t2 = t2*f2f( 3.072711026f); \ t3 = t3*f2f( 1.501321110f); \ p1 = p5 + p1*f2f(-0.899976223f); \ p2 = p5 + p2*f2f(-2.562915447f); \ p3 = p3*f2f(-1.961570560f); \ p4 = p4*f2f(-0.390180644f); \ t3 += p1+p4; \ t2 += p2+p3; \ t1 += p2+p4; \ t0 += p1+p3; #ifdef STBI_SIMD typedef unsigned short stbi_dequantize_t; #else typedef uint8 stbi_dequantize_t; #endif // .344 seconds on 3*anemones.jpg static void idct_block(uint8 *out, int out_stride, short data[64], stbi_dequantize_t *dequantize) { int i,val[64],*v=val; stbi_dequantize_t *dq = dequantize; uint8 *o; short *d = data; // columns for (i=0; i < 8; ++i,++d,++dq, ++v) { // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing if (d[ 8]==0 && d[16]==0 && d[24]==0 && d[32]==0 && d[40]==0 && d[48]==0 && d[56]==0) { // no shortcut 0 seconds // (1|2|3|4|5|6|7)==0 0 seconds // all separate -0.047 seconds // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds int dcterm = d[0] * dq[0] << 2; v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm; } else { IDCT_1D(d[ 0]*dq[ 0],d[ 8]*dq[ 8],d[16]*dq[16],d[24]*dq[24], d[32]*dq[32],d[40]*dq[40],d[48]*dq[48],d[56]*dq[56]) // constants scaled things up by 1<<12; let's bring them back // down, but keep 2 extra bits of precision x0 += 512; x1 += 512; x2 += 512; x3 += 512; v[ 0] = (x0+t3) >> 10; v[56] = (x0-t3) >> 10; v[ 8] = (x1+t2) >> 10; v[48] = (x1-t2) >> 10; v[16] = (x2+t1) >> 10; v[40] = (x2-t1) >> 10; v[24] = (x3+t0) >> 10; v[32] = (x3-t0) >> 10; } } for (i=0, v=val, o=out; i < 8; ++i,v+=8,o+=out_stride) { // no fast case since the first 1D IDCT spread components out IDCT_1D(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]) // constants scaled things up by 1<<12, plus we had 1<<2 from first // loop, plus horizontal and vertical each scale by sqrt(8) so together // we've got an extra 1<<3, so 1<<17 total we need to remove. // so we want to round that, which means adding 0.5 * 1<<17, // aka 65536. Also, we'll end up with -128 to 127 that we want // to encode as 0..255 by adding 128, so we'll add that before the shift x0 += 65536 + (128<<17); x1 += 65536 + (128<<17); x2 += 65536 + (128<<17); x3 += 65536 + (128<<17); // tried computing the shifts into temps, or'ing the temps to see // if any were out of range, but that was slower o[0] = clamp((x0+t3) >> 17); o[7] = clamp((x0-t3) >> 17); o[1] = clamp((x1+t2) >> 17); o[6] = clamp((x1-t2) >> 17); o[2] = clamp((x2+t1) >> 17); o[5] = clamp((x2-t1) >> 17); o[3] = clamp((x3+t0) >> 17); o[4] = clamp((x3-t0) >> 17); } } #ifdef STBI_SIMD static stbi_idct_8x8 stbi_idct_installed = idct_block; extern void stbi_install_idct(stbi_idct_8x8 func) { stbi_idct_installed = func; } #endif #define MARKER_none 0xff // if there's a pending marker from the entropy stream, return that // otherwise, fetch from the stream and get a marker. if there's no // marker, return 0xff, which is never a valid marker value static uint8 get_marker(jpeg *j) { uint8 x; if (j->marker != MARKER_none) { x = j->marker; j->marker = MARKER_none; return x; } x = get8u(&j->s); if (x != 0xff) return MARKER_none; while (x == 0xff) x = get8u(&j->s); return x; } // in each scan, we'll have scan_n components, and the order // of the components is specified by order[] #define RESTART(x) ((x) >= 0xd0 && (x) <= 0xd7) // after a restart interval, reset the entropy decoder and // the dc prediction static void reset(jpeg *j) { j->code_bits = 0; j->code_buffer = 0; j->nomore = 0; j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = 0; j->marker = MARKER_none; j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff; // no more than 1<<31 MCUs if no restart_interal? that's plenty safe, // since we don't even allow 1<<30 pixels } static int parse_entropy_coded_data(jpeg *z) { reset(z); if (z->scan_n == 1) { int i,j; #ifdef STBI_SIMD __declspec(align(16)) #endif short data[64]; int n = z->order[0]; // non-interleaved data, we just need to process one block at a time, // in trivial scanline order // number of blocks to do just depends on how many actual "pixels" this // component has, independent of interleaved MCU blocking and such int w = (z->img_comp[n].x+7) >> 3; int h = (z->img_comp[n].y+7) >> 3; for (j=0; j < h; ++j) { for (i=0; i < w; ++i) { if (!decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+z->img_comp[n].ha, n)) return 0; #ifdef STBI_SIMD stbi_idct_installed(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data, z->dequant2[z->img_comp[n].tq]); #else idct_block(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data, z->dequant[z->img_comp[n].tq]); #endif // every data block is an MCU, so countdown the restart interval if (--z->todo <= 0) { if (z->code_bits < 24) grow_buffer_unsafe(z); // if it's NOT a restart, then just bail, so we get corrupt data // rather than no data if (!RESTART(z->marker)) return 1; reset(z); } } } } else { // interleaved! int i,j,k,x,y; short data[64]; for (j=0; j < z->img_mcu_y; ++j) { for (i=0; i < z->img_mcu_x; ++i) { // scan an interleaved mcu... process scan_n components in order for (k=0; k < z->scan_n; ++k) { int n = z->order[k]; // scan out an mcu's worth of this component; that's just determined // by the basic H and V specified for the component for (y=0; y < z->img_comp[n].v; ++y) { for (x=0; x < z->img_comp[n].h; ++x) { int x2 = (i*z->img_comp[n].h + x)*8; int y2 = (j*z->img_comp[n].v + y)*8; if (!decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+z->img_comp[n].ha, n)) return 0; #ifdef STBI_SIMD stbi_idct_installed(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data, z->dequant2[z->img_comp[n].tq]); #else idct_block(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data, z->dequant[z->img_comp[n].tq]); #endif } } } // after all interleaved components, that's an interleaved MCU, // so now count down the restart interval if (--z->todo <= 0) { if (z->code_bits < 24) grow_buffer_unsafe(z); // if it's NOT a restart, then just bail, so we get corrupt data // rather than no data if (!RESTART(z->marker)) return 1; reset(z); } } } } return 1; } static int process_marker(jpeg *z, int m) { int L; switch (m) { case MARKER_none: // no marker found return e("expected marker","Corrupt JPEG"); case 0xC2: // SOF - progressive return e("progressive jpeg","JPEG format not supported (progressive)"); case 0xDD: // DRI - specify restart interval if (get16(&z->s) != 4) return e("bad DRI len","Corrupt JPEG"); z->restart_interval = get16(&z->s); return 1; case 0xDB: // DQT - define quantization table L = get16(&z->s)-2; while (L > 0) { int q = get8(&z->s); int p = q >> 4; int t = q & 15,i; if (p != 0) return e("bad DQT type","Corrupt JPEG"); if (t > 3) return e("bad DQT table","Corrupt JPEG"); for (i=0; i < 64; ++i) z->dequant[t][dezigzag[i]] = get8u(&z->s); #ifdef STBI_SIMD for (i=0; i < 64; ++i) z->dequant2[t][i] = z->dequant[t][i]; #endif L -= 65; } return L==0; case 0xC4: // DHT - define huffman table L = get16(&z->s)-2; while (L > 0) { uint8 *v; int sizes[16],i,m=0; int q = get8(&z->s); int tc = q >> 4; int th = q & 15; if (tc > 1 || th > 3) return e("bad DHT header","Corrupt JPEG"); for (i=0; i < 16; ++i) { sizes[i] = get8(&z->s); m += sizes[i]; } L -= 17; if (tc == 0) { if (!build_huffman(z->huff_dc+th, sizes)) return 0; v = z->huff_dc[th].values; } else { if (!build_huffman(z->huff_ac+th, sizes)) return 0; v = z->huff_ac[th].values; } for (i=0; i < m; ++i) v[i] = get8u(&z->s); L -= m; } return L==0; } // check for comment block or APP blocks if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) { skip(&z->s, get16(&z->s)-2); return 1; } return 0; } // after we see SOS static int process_scan_header(jpeg *z) { int i; int Ls = get16(&z->s); z->scan_n = get8(&z->s); if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s.img_n) return e("bad SOS component count","Corrupt JPEG"); if (Ls != 6+2*z->scan_n) return e("bad SOS len","Corrupt JPEG"); for (i=0; i < z->scan_n; ++i) { int id = get8(&z->s), which; int q = get8(&z->s); for (which = 0; which < z->s.img_n; ++which) if (z->img_comp[which].id == id) break; if (which == z->s.img_n) return 0; z->img_comp[which].hd = q >> 4; if (z->img_comp[which].hd > 3) return e("bad DC huff","Corrupt JPEG"); z->img_comp[which].ha = q & 15; if (z->img_comp[which].ha > 3) return e("bad AC huff","Corrupt JPEG"); z->order[i] = which; } if (get8(&z->s) != 0) return e("bad SOS","Corrupt JPEG"); get8(&z->s); // should be 63, but might be 0 if (get8(&z->s) != 0) return e("bad SOS","Corrupt JPEG"); return 1; } static int process_frame_header(jpeg *z, int scan) { stbi *s = &z->s; int Lf,p,i,q, h_max=1,v_max=1,c; Lf = get16(s); if (Lf < 11) return e("bad SOF len","Corrupt JPEG"); // JPEG p = get8(s); if (p != 8) return e("only 8-bit","JPEG format not supported: 8-bit only"); // JPEG baseline s->img_y = get16(s); if (s->img_y == 0) return e("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG s->img_x = get16(s); if (s->img_x == 0) return e("0 width","Corrupt JPEG"); // JPEG requires c = get8(s); if (c != 3 && c != 1) return e("bad component count","Corrupt JPEG"); // JFIF requires s->img_n = c; for (i=0; i < c; ++i) { z->img_comp[i].data = NULL; z->img_comp[i].linebuf = NULL; } if (Lf != 8+3*s->img_n) return e("bad SOF len","Corrupt JPEG"); for (i=0; i < s->img_n; ++i) { z->img_comp[i].id = get8(s); if (z->img_comp[i].id != i+1) // JFIF requires if (z->img_comp[i].id != i) // some version of jpegtran outputs non-JFIF-compliant files! return e("bad component ID","Corrupt JPEG"); q = get8(s); z->img_comp[i].h = (q >> 4); if (!z->img_comp[i].h || z->img_comp[i].h > 4) return e("bad H","Corrupt JPEG"); z->img_comp[i].v = q & 15; if (!z->img_comp[i].v || z->img_comp[i].v > 4) return e("bad V","Corrupt JPEG"); z->img_comp[i].tq = get8(s); if (z->img_comp[i].tq > 3) return e("bad TQ","Corrupt JPEG"); } if (scan != SCAN_load) return 1; if ((1 << 30) / s->img_x / s->img_n < s->img_y) return e("too large", "Image too large to decode"); for (i=0; i < s->img_n; ++i) { if (z->img_comp[i].h > h_max) h_max = z->img_comp[i].h; if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v; } // compute interleaved mcu info z->img_h_max = h_max; z->img_v_max = v_max; z->img_mcu_w = h_max * 8; z->img_mcu_h = v_max * 8; z->img_mcu_x = (s->img_x + z->img_mcu_w-1) / z->img_mcu_w; z->img_mcu_y = (s->img_y + z->img_mcu_h-1) / z->img_mcu_h; for (i=0; i < s->img_n; ++i) { // number of effective pixels (e.g. for non-interleaved MCU) z->img_comp[i].x = (s->img_x * z->img_comp[i].h + h_max-1) / h_max; z->img_comp[i].y = (s->img_y * z->img_comp[i].v + v_max-1) / v_max; // to simplify generation, we'll allocate enough memory to decode // the bogus oversized data from using interleaved MCUs and their // big blocks (e.g. a 16x16 iMCU on an image of width 33); we won't // discard the extra data until colorspace conversion z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8; z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8; z->img_comp[i].raw_data = malloc(z->img_comp[i].w2 * z->img_comp[i].h2+15); if (z->img_comp[i].raw_data == NULL) { for(--i; i >= 0; --i) { free(z->img_comp[i].raw_data); z->img_comp[i].data = NULL; } return e("outofmem", "Out of memory"); } // align blocks for installable-idct using mmx/sse z->img_comp[i].data = (uint8*) (((size_t) z->img_comp[i].raw_data + 15) & ~15); z->img_comp[i].linebuf = NULL; } return 1; } // use comparisons since in some cases we handle more than one case (e.g. SOF) #define DNL(x) ((x) == 0xdc) #define SOI(x) ((x) == 0xd8) #define EOI(x) ((x) == 0xd9) #define SOF(x) ((x) == 0xc0 || (x) == 0xc1) #define SOS(x) ((x) == 0xda) static int decode_jpeg_header(jpeg *z, int scan) { int m; z->marker = MARKER_none; // initialize cached marker to empty m = get_marker(z); if (!SOI(m)) return e("no SOI","Corrupt JPEG"); if (scan == SCAN_type) return 1; m = get_marker(z); while (!SOF(m)) { if (!process_marker(z,m)) return 0; m = get_marker(z); while (m == MARKER_none) { // some files have extra padding after their blocks, so ok, we'll scan if (at_eof(&z->s)) return e("no SOF", "Corrupt JPEG"); m = get_marker(z); } } if (!process_frame_header(z, scan)) return 0; return 1; } static int decode_jpeg_image(jpeg *j) { int m; j->restart_interval = 0; if (!decode_jpeg_header(j, SCAN_load)) return 0; m = get_marker(j); while (!EOI(m)) { if (SOS(m)) { if (!process_scan_header(j)) return 0; if (!parse_entropy_coded_data(j)) return 0; if (j->marker == MARKER_none ) { // handle 0s at the end of image data from IP Kamera 9060 while (!at_eof(&j->s)) { int x = get8(&j->s); if (x == 255) { j->marker = get8u(&j->s); break; } else if (x != 0) { return 0; } } // if we reach eof without hitting a marker, get_marker() below will fail and we'll eventually return 0 } } else { if (!process_marker(j, m)) return 0; } m = get_marker(j); } return 1; } // static jfif-centered resampling (across block boundaries) typedef uint8 *(*resample_row_func)(uint8 *out, uint8 *in0, uint8 *in1, int w, int hs); #define div4(x) ((uint8) ((x) >> 2)) static uint8 *resample_row_1(uint8 *out, uint8 *in_near, uint8 *in_far, int w, int hs) { STBI_NOTUSED(out); STBI_NOTUSED(in_far); STBI_NOTUSED(w); STBI_NOTUSED(hs); return in_near; } static uint8* resample_row_v_2(uint8 *out, uint8 *in_near, uint8 *in_far, int w, int hs) { // need to generate two samples vertically for every one in input int i; STBI_NOTUSED(hs); for (i=0; i < w; ++i) out[i] = div4(3*in_near[i] + in_far[i] + 2); return out; } static uint8* resample_row_h_2(uint8 *out, uint8 *in_near, uint8 *in_far, int w, int hs) { // need to generate two samples horizontally for every one in input int i; uint8 *input = in_near; if (w == 1) { // if only one sample, can't do any interpolation out[0] = out[1] = input[0]; return out; } out[0] = input[0]; out[1] = div4(input[0]*3 + input[1] + 2); for (i=1; i < w-1; ++i) { int n = 3*input[i]+2; out[i*2+0] = div4(n+input[i-1]); out[i*2+1] = div4(n+input[i+1]); } out[i*2+0] = div4(input[w-2]*3 + input[w-1] + 2); out[i*2+1] = input[w-1]; STBI_NOTUSED(in_far); STBI_NOTUSED(hs); return out; } #define div16(x) ((uint8) ((x) >> 4)) static uint8 *resample_row_hv_2(uint8 *out, uint8 *in_near, uint8 *in_far, int w, int hs) { // need to generate 2x2 samples for every one in input int i,t0,t1; if (w == 1) { out[0] = out[1] = div4(3*in_near[0] + in_far[0] + 2); return out; } t1 = 3*in_near[0] + in_far[0]; out[0] = div4(t1+2); for (i=1; i < w; ++i) { t0 = t1; t1 = 3*in_near[i]+in_far[i]; out[i*2-1] = div16(3*t0 + t1 + 8); out[i*2 ] = div16(3*t1 + t0 + 8); } out[w*2-1] = div4(t1+2); STBI_NOTUSED(hs); return out; } static uint8 *resample_row_generic(uint8 *out, uint8 *in_near, uint8 *in_far, int w, int hs) { // resample with nearest-neighbor int i,j; in_far = in_far; for (i=0; i < w; ++i) for (j=0; j < hs; ++j) out[i*hs+j] = in_near[i]; return out; } #define float2fixed(x) ((int) ((x) * 65536 + 0.5)) // 0.38 seconds on 3*anemones.jpg (0.25 with processor = Pro) // VC6 without processor=Pro is generating multiple LEAs per multiply! static void YCbCr_to_RGB_row(uint8 *out, const uint8 *y, const uint8 *pcb, const uint8 *pcr, int count, int step) { int i; for (i=0; i < count; ++i) { int y_fixed = (y[i] << 16) + 32768; // rounding int r,g,b; int cr = pcr[i] - 128; int cb = pcb[i] - 128; r = y_fixed + cr*float2fixed(1.40200f); g = y_fixed - cr*float2fixed(0.71414f) - cb*float2fixed(0.34414f); b = y_fixed + cb*float2fixed(1.77200f); r >>= 16; g >>= 16; b >>= 16; if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } out[0] = (uint8)r; out[1] = (uint8)g; out[2] = (uint8)b; out[3] = 255; out += step; } } #ifdef STBI_SIMD static stbi_YCbCr_to_RGB_run stbi_YCbCr_installed = YCbCr_to_RGB_row; void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func) { stbi_YCbCr_installed = func; } #endif // clean up the temporary component buffers static void cleanup_jpeg(jpeg *j) { int i; for (i=0; i < j->s.img_n; ++i) { if (j->img_comp[i].data) { free(j->img_comp[i].raw_data); j->img_comp[i].data = NULL; } if (j->img_comp[i].linebuf) { free(j->img_comp[i].linebuf); j->img_comp[i].linebuf = NULL; } } } typedef struct { resample_row_func resample; uint8 *line0,*line1; int hs,vs; // expansion factor in each axis int w_lores; // horizontal pixels pre-expansion int ystep; // how far through vertical expansion we are int ypos; // which pre-expansion row we're on } stbi_resample; static uint8 *load_jpeg_image(jpeg *z, int *out_x, int *out_y, int *comp, int req_comp) { int n, decode_n; // validate req_comp if (req_comp < 0 || req_comp > 4) return epuc("bad req_comp", "Internal error"); z->s.img_n = 0; // load a jpeg image from whichever source if (!decode_jpeg_image(z)) { cleanup_jpeg(z); return NULL; } // determine actual number of components to generate n = req_comp ? req_comp : z->s.img_n; if (z->s.img_n == 3 && n < 3) decode_n = 1; else decode_n = z->s.img_n; // resample and color-convert { int k; uint i,j; uint8 *output; uint8 *coutput[4]; stbi_resample res_comp[4]; for (k=0; k < decode_n; ++k) { stbi_resample *r = &res_comp[k]; // allocate line buffer big enough for upsampling off the edges // with upsample factor of 4 z->img_comp[k].linebuf = (uint8 *) malloc(z->s.img_x + 3); if (!z->img_comp[k].linebuf) { cleanup_jpeg(z); return epuc("outofmem", "Out of memory"); } r->hs = z->img_h_max / z->img_comp[k].h; r->vs = z->img_v_max / z->img_comp[k].v; r->ystep = r->vs >> 1; r->w_lores = (z->s.img_x + r->hs-1) / r->hs; r->ypos = 0; r->line0 = r->line1 = z->img_comp[k].data; if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1; else if (r->hs == 1 && r->vs == 2) r->resample = resample_row_v_2; else if (r->hs == 2 && r->vs == 1) r->resample = resample_row_h_2; else if (r->hs == 2 && r->vs == 2) r->resample = resample_row_hv_2; else r->resample = resample_row_generic; } // can't error after this so, this is safe output = (uint8 *) malloc(n * z->s.img_x * z->s.img_y + 1); if (!output) { cleanup_jpeg(z); return epuc("outofmem", "Out of memory"); } // now go ahead and resample for (j=0; j < z->s.img_y; ++j) { uint8 *out = output + n * z->s.img_x * j; for (k=0; k < decode_n; ++k) { stbi_resample *r = &res_comp[k]; int y_bot = r->ystep >= (r->vs >> 1); coutput[k] = r->resample(z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, y_bot ? r->line0 : r->line1, r->w_lores, r->hs); if (++r->ystep >= r->vs) { r->ystep = 0; r->line0 = r->line1; if (++r->ypos < z->img_comp[k].y) r->line1 += z->img_comp[k].w2; } } if (n >= 3) { uint8 *y = coutput[0]; if (z->s.img_n == 3) { #ifdef STBI_SIMD stbi_YCbCr_installed(out, y, coutput[1], coutput[2], z->s.img_x, n); #else YCbCr_to_RGB_row(out, y, coutput[1], coutput[2], z->s.img_x, n); #endif } else for (i=0; i < z->s.img_x; ++i) { out[0] = out[1] = out[2] = y[i]; out[3] = 255; // not used if n==3 out += n; } } else { uint8 *y = coutput[0]; if (n == 1) for (i=0; i < z->s.img_x; ++i) out[i] = y[i]; else for (i=0; i < z->s.img_x; ++i) *out++ = y[i], *out++ = 255; } } cleanup_jpeg(z); *out_x = z->s.img_x; *out_y = z->s.img_y; if (comp) *comp = z->s.img_n; // report original components, not output return output; } } #ifndef STBI_NO_STDIO unsigned char *stbi_jpeg_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { jpeg j; start_file(&j.s, f); return load_jpeg_image(&j, x,y,comp,req_comp); } unsigned char *stbi_jpeg_load(char const *filename, int *x, int *y, int *comp, int req_comp) { unsigned char *data; FILE *f = fopen(filename, "rb"); if (!f) return NULL; data = stbi_jpeg_load_from_file(f,x,y,comp,req_comp); fclose(f); return data; } #endif unsigned char *stbi_jpeg_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { #ifdef STBI_SMALL_STACK unsigned char *result; jpeg *j = (jpeg *) malloc(sizeof(*j)); start_mem(&j->s, buffer, len); result = load_jpeg_image(j,x,y,comp,req_comp); free(j); return result; #else jpeg j; start_mem(&j.s, buffer,len); return load_jpeg_image(&j, x,y,comp,req_comp); #endif } static int stbi_jpeg_info_raw(jpeg *j, int *x, int *y, int *comp) { if (!decode_jpeg_header(j, SCAN_header)) return 0; if (x) *x = j->s.img_x; if (y) *y = j->s.img_y; if (comp) *comp = j->s.img_n; return 1; } #ifndef STBI_NO_STDIO int stbi_jpeg_test_file(FILE *f) { int n,r; jpeg j; n = ftell(f); start_file(&j.s, f); r = decode_jpeg_header(&j, SCAN_type); fseek(f,n,SEEK_SET); return r; } int stbi_jpeg_info_from_file(FILE *f, int *x, int *y, int *comp) { jpeg j; long n = ftell(f); int res; start_file(&j.s, f); res = stbi_jpeg_info_raw(&j, x, y, comp); fseek(f, n, SEEK_SET); return res; } int stbi_jpeg_info(char const *filename, int *x, int *y, int *comp) { FILE *f = fopen(filename, "rb"); int result; if (!f) return e("can't fopen", "Unable to open file"); result = stbi_jpeg_info_from_file(f, x, y, comp); fclose(f); return result; } #endif int stbi_jpeg_test_memory(stbi_uc const *buffer, int len) { jpeg j; start_mem(&j.s, buffer,len); return decode_jpeg_header(&j, SCAN_type); } int stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) { jpeg j; start_mem(&j.s, buffer, len); return stbi_jpeg_info_raw(&j, x, y, comp); } #ifndef STBI_NO_STDIO extern int stbi_jpeg_info (char const *filename, int *x, int *y, int *comp); extern int stbi_jpeg_info_from_file (FILE *f, int *x, int *y, int *comp); #endif extern int stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); // public domain zlib decode v0.2 Sean Barrett 2006-11-18 // simple implementation // - all input must be provided in an upfront buffer // - all output is written to a single output buffer (can malloc/realloc) // performance // - fast huffman // fast-way is faster to check than jpeg huffman, but slow way is slower #define ZFAST_BITS 9 // accelerate all cases in default tables #define ZFAST_MASK ((1 << ZFAST_BITS) - 1) // zlib-style huffman encoding // (jpegs packs from left, zlib from right, so can't share code) typedef struct { uint16 fast[1 << ZFAST_BITS]; uint16 firstcode[16]; int maxcode[17]; uint16 firstsymbol[16]; uint8 size[288]; uint16 value[288]; } zhuffman; __forceinline static int bitreverse16(int n) { n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2); n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4); n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8); return n; } __forceinline static int bit_reverse(int v, int bits) { assert(bits <= 16); // to bit reverse n bits, reverse 16 and shift // e.g. 11 bits, bit reverse and shift away 5 return bitreverse16(v) >> (16-bits); } static int zbuild_huffman(zhuffman *z, uint8 *sizelist, int num) { int i,k=0; int code, next_code[16], sizes[17]; // DEFLATE spec for generating codes memset(sizes, 0, sizeof(sizes)); memset(z->fast, 255, sizeof(z->fast)); for (i=0; i < num; ++i) ++sizes[sizelist[i]]; sizes[0] = 0; for (i=1; i < 16; ++i) assert(sizes[i] <= (1 << i)); code = 0; for (i=1; i < 16; ++i) { next_code[i] = code; z->firstcode[i] = (uint16) code; z->firstsymbol[i] = (uint16) k; code = (code + sizes[i]); if (sizes[i]) if (code-1 >= (1 << i)) return e("bad codelengths","Corrupt JPEG"); z->maxcode[i] = code << (16-i); // preshift for inner loop code <<= 1; k += sizes[i]; } z->maxcode[16] = 0x10000; // sentinel for (i=0; i < num; ++i) { int s = sizelist[i]; if (s) { int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s]; z->size[c] = (uint8)s; z->value[c] = (uint16)i; if (s <= ZFAST_BITS) { int k = bit_reverse(next_code[s],s); while (k < (1 << ZFAST_BITS)) { z->fast[k] = (uint16) c; k += (1 << s); } } ++next_code[s]; } } return 1; } // zlib-from-memory implementation for PNG reading // because PNG allows splitting the zlib stream arbitrarily, // and it's annoying structurally to have PNG call ZLIB call PNG, // we require PNG read all the IDATs and combine them into a single // memory buffer typedef struct { uint8 *zbuffer, *zbuffer_end; int num_bits; uint32 code_buffer; char *zout; char *zout_start; char *zout_end; int z_expandable; zhuffman z_length, z_distance; } zbuf; __forceinline static int zget8(zbuf *z) { if (z->zbuffer >= z->zbuffer_end) return 0; return *z->zbuffer++; } static void fill_bits(zbuf *z) { do { assert(z->code_buffer < (1U << z->num_bits)); z->code_buffer |= zget8(z) << z->num_bits; z->num_bits += 8; } while (z->num_bits <= 24); } __forceinline static unsigned int zreceive(zbuf *z, int n) { unsigned int k; if (z->num_bits < n) fill_bits(z); k = z->code_buffer & ((1 << n) - 1); z->code_buffer >>= n; z->num_bits -= n; return k; } __forceinline static int zhuffman_decode(zbuf *a, zhuffman *z) { int b,s,k; if (a->num_bits < 16) fill_bits(a); b = z->fast[a->code_buffer & ZFAST_MASK]; if (b < 0xffff) { s = z->size[b]; a->code_buffer >>= s; a->num_bits -= s; return z->value[b]; } // not resolved by fast table, so compute it the slow way // use jpeg approach, which requires MSbits at top k = bit_reverse(a->code_buffer, 16); for (s=ZFAST_BITS+1; ; ++s) if (k < z->maxcode[s]) break; if (s == 16) return -1; // invalid code! // code size is s, so: b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; assert(z->size[b] == s); a->code_buffer >>= s; a->num_bits -= s; return z->value[b]; } static int expand(zbuf *z, int n) // need to make room for n bytes { char *q; int cur, limit; if (!z->z_expandable) return e("output buffer limit","Corrupt PNG"); cur = (int) (z->zout - z->zout_start); limit = (int) (z->zout_end - z->zout_start); while (cur + n > limit) limit *= 2; q = (char *) realloc(z->zout_start, limit); if (q == NULL) return e("outofmem", "Out of memory"); z->zout_start = q; z->zout = q + cur; z->zout_end = q + limit; return 1; } static int length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 }; static int length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; static int dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; static int dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; static int parse_huffman_block(zbuf *a) { for(;;) { int z = zhuffman_decode(a, &a->z_length); if (z < 256) { if (z < 0) return e("bad huffman code","Corrupt PNG"); // error in huffman codes if (a->zout >= a->zout_end) if (!expand(a, 1)) return 0; *a->zout++ = (char) z; } else { uint8 *p; int len,dist; if (z == 256) return 1; z -= 257; len = length_base[z]; if (length_extra[z]) len += zreceive(a, length_extra[z]); z = zhuffman_decode(a, &a->z_distance); if (z < 0) return e("bad huffman code","Corrupt PNG"); dist = dist_base[z]; if (dist_extra[z]) dist += zreceive(a, dist_extra[z]); if (a->zout - a->zout_start < dist) return e("bad dist","Corrupt PNG"); if (a->zout + len > a->zout_end) if (!expand(a, len)) return 0; p = (uint8 *) (a->zout - dist); while (len--) *a->zout++ = *p++; } } } static int compute_huffman_codes(zbuf *a) { static uint8 length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; zhuffman z_codelength; uint8 lencodes[286+32+137];//padding for maximum single op uint8 codelength_sizes[19]; int i,n; int hlit = zreceive(a,5) + 257; int hdist = zreceive(a,5) + 1; int hclen = zreceive(a,4) + 4; memset(codelength_sizes, 0, sizeof(codelength_sizes)); for (i=0; i < hclen; ++i) { int s = zreceive(a,3); codelength_sizes[length_dezigzag[i]] = (uint8) s; } if (!zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0; n = 0; while (n < hlit + hdist) { int c = zhuffman_decode(a, &z_codelength); assert(c >= 0 && c < 19); if (c < 16) lencodes[n++] = (uint8) c; else if (c == 16) { c = zreceive(a,2)+3; memset(lencodes+n, lencodes[n-1], c); n += c; } else if (c == 17) { c = zreceive(a,3)+3; memset(lencodes+n, 0, c); n += c; } else { assert(c == 18); c = zreceive(a,7)+11; memset(lencodes+n, 0, c); n += c; } } if (n != hlit+hdist) return e("bad codelengths","Corrupt PNG"); if (!zbuild_huffman(&a->z_length, lencodes, hlit)) return 0; if (!zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0; return 1; } static int parse_uncompressed_block(zbuf *a) { uint8 header[4]; int len,nlen,k; if (a->num_bits & 7) zreceive(a, a->num_bits & 7); // discard // drain the bit-packed data into header k = 0; while (a->num_bits > 0) { header[k++] = (uint8) (a->code_buffer & 255); // wtf this warns? a->code_buffer >>= 8; a->num_bits -= 8; } assert(a->num_bits == 0); // now fill header the normal way while (k < 4) header[k++] = (uint8) zget8(a); len = header[1] * 256 + header[0]; nlen = header[3] * 256 + header[2]; if (nlen != (len ^ 0xffff)) return e("zlib corrupt","Corrupt PNG"); if (a->zbuffer + len > a->zbuffer_end) return e("read past buffer","Corrupt PNG"); if (a->zout + len > a->zout_end) if (!expand(a, len)) return 0; memcpy(a->zout, a->zbuffer, len); a->zbuffer += len; a->zout += len; return 1; } static int parse_zlib_header(zbuf *a) { int cmf = zget8(a); int cm = cmf & 15; /* int cinfo = cmf >> 4; */ int flg = zget8(a); if ((cmf*256+flg) % 31 != 0) return e("bad zlib header","Corrupt PNG"); // zlib spec if (flg & 32) return e("no preset dict","Corrupt PNG"); // preset dictionary not allowed in png if (cm != 8) return e("bad compression","Corrupt PNG"); // DEFLATE required for png // window = 1 << (8 + cinfo)... but who cares, we fully buffer output return 1; } // @TODO: should statically initialize these for optimal thread safety static uint8 default_length[288], default_distance[32]; static void init_defaults(void) { int i; // use <= to match clearly with spec for (i=0; i <= 143; ++i) default_length[i] = 8; for ( ; i <= 255; ++i) default_length[i] = 9; for ( ; i <= 279; ++i) default_length[i] = 7; for ( ; i <= 287; ++i) default_length[i] = 8; for (i=0; i <= 31; ++i) default_distance[i] = 5; } int stbi_png_partial; // a quick hack to only allow decoding some of a PNG... I should implement real streaming support instead static int parse_zlib(zbuf *a, int parse_header) { int final, type; if (parse_header) if (!parse_zlib_header(a)) return 0; a->num_bits = 0; a->code_buffer = 0; do { final = zreceive(a,1); type = zreceive(a,2); if (type == 0) { if (!parse_uncompressed_block(a)) return 0; } else if (type == 3) { return 0; } else { if (type == 1) { // use fixed code lengths if (!default_distance[31]) init_defaults(); if (!zbuild_huffman(&a->z_length , default_length , 288)) return 0; if (!zbuild_huffman(&a->z_distance, default_distance, 32)) return 0; } else { if (!compute_huffman_codes(a)) return 0; } if (!parse_huffman_block(a)) return 0; } if (stbi_png_partial && a->zout - a->zout_start > 65536) break; } while (!final); return 1; } static int do_zlib(zbuf *a, char *obuf, int olen, int exp, int parse_header) { a->zout_start = obuf; a->zout = obuf; a->zout_end = obuf + olen; a->z_expandable = exp; return parse_zlib(a, parse_header); } char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen) { zbuf a; char *p = (char *) malloc(initial_size); if (p == NULL) return NULL; a.zbuffer = (uint8 *) buffer; a.zbuffer_end = (uint8 *) buffer + len; if (do_zlib(&a, p, initial_size, 1, 1)) { if (outlen) *outlen = (int) (a.zout - a.zout_start); return a.zout_start; } else { free(a.zout_start); return NULL; } } char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen) { return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); } char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header) { zbuf a; char *p = (char *) malloc(initial_size); if (p == NULL) return NULL; a.zbuffer = (uint8 *) buffer; a.zbuffer_end = (uint8 *) buffer + len; if (do_zlib(&a, p, initial_size, 1, parse_header)) { if (outlen) *outlen = (int) (a.zout - a.zout_start); return a.zout_start; } else { free(a.zout_start); return NULL; } } int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen) { zbuf a; a.zbuffer = (uint8 *) ibuffer; a.zbuffer_end = (uint8 *) ibuffer + ilen; if (do_zlib(&a, obuffer, olen, 0, 1)) return (int) (a.zout - a.zout_start); else return -1; } char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen) { zbuf a; char *p = (char *) malloc(16384); if (p == NULL) return NULL; a.zbuffer = (uint8 *) buffer; a.zbuffer_end = (uint8 *) buffer+len; if (do_zlib(&a, p, 16384, 1, 0)) { if (outlen) *outlen = (int) (a.zout - a.zout_start); return a.zout_start; } else { free(a.zout_start); return NULL; } } int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen) { zbuf a; a.zbuffer = (uint8 *) ibuffer; a.zbuffer_end = (uint8 *) ibuffer + ilen; if (do_zlib(&a, obuffer, olen, 0, 0)) return (int) (a.zout - a.zout_start); else return -1; } // public domain "baseline" PNG decoder v0.10 Sean Barrett 2006-11-18 // simple implementation // - only 8-bit samples // - no CRC checking // - allocates lots of intermediate memory // - avoids problem of streaming data between subsystems // - avoids explicit window management // performance // - uses stb_zlib, a PD zlib implementation with fast huffman decoding typedef struct { uint32 length; uint32 type; } chunk; #define PNG_TYPE(a,b,c,d) (((a) << 24) + ((b) << 16) + ((c) << 8) + (d)) static chunk get_chunk_header(stbi *s) { chunk c; c.length = get32(s); c.type = get32(s); return c; } static int check_png_header(stbi *s) { static uint8 png_sig[8] = { 137,80,78,71,13,10,26,10 }; int i; for (i=0; i < 8; ++i) if (get8(s) != png_sig[i]) return e("bad png sig","Not a PNG"); return 1; } typedef struct { stbi s; uint8 *idata, *expanded, *out; } png; enum { F_none=0, F_sub=1, F_up=2, F_avg=3, F_paeth=4, F_avg_first, F_paeth_first }; static uint8 first_row_filter[5] = { F_none, F_sub, F_none, F_avg_first, F_paeth_first }; static int paeth(int a, int b, int c) { int p = a + b - c; int pa = abs(p-a); int pb = abs(p-b); int pc = abs(p-c); if (pa <= pb && pa <= pc) return a; if (pb <= pc) return b; return c; } // create the png data from post-deflated data static int create_png_image_raw(png *a, uint8 *raw, uint32 raw_len, int out_n, uint32 x, uint32 y) { stbi *s = &a->s; uint32 i,j,stride = x*out_n; int k; int img_n = s->img_n; // copy it into a local for later assert(out_n == s->img_n || out_n == s->img_n+1); if (stbi_png_partial) y = 1; a->out = (uint8 *) malloc(x * y * out_n); if (!a->out) return e("outofmem", "Out of memory"); if (!stbi_png_partial) { if (s->img_x == x && s->img_y == y) { if (raw_len != (img_n * x + 1) * y) return e("not enough pixels","Corrupt PNG"); } else { // interlaced: if (raw_len < (img_n * x + 1) * y) return e("not enough pixels","Corrupt PNG"); } } for (j=0; j < y; ++j) { uint8 *cur = a->out + stride*j; uint8 *prior = cur - stride; int filter = *raw++; if (filter > 4) return e("invalid filter","Corrupt PNG"); // if first row, use special filter that doesn't sample previous row if (j == 0) filter = first_row_filter[filter]; // handle first pixel explicitly for (k=0; k < img_n; ++k) { switch (filter) { case F_none : cur[k] = raw[k]; break; case F_sub : cur[k] = raw[k]; break; case F_up : cur[k] = raw[k] + prior[k]; break; case F_avg : cur[k] = raw[k] + (prior[k]>>1); break; case F_paeth : cur[k] = (uint8) (raw[k] + paeth(0,prior[k],0)); break; case F_avg_first : cur[k] = raw[k]; break; case F_paeth_first: cur[k] = raw[k]; break; } } if (img_n != out_n) cur[img_n] = 255; raw += img_n; cur += out_n; prior += out_n; // this is a little gross, so that we don't switch per-pixel or per-component if (img_n == out_n) { #define CASE(f) \ case f: \ for (i=x-1; i >= 1; --i, raw+=img_n,cur+=img_n,prior+=img_n) \ for (k=0; k < img_n; ++k) switch (filter) { CASE(F_none) cur[k] = raw[k]; break; CASE(F_sub) cur[k] = raw[k] + cur[k-img_n]; break; CASE(F_up) cur[k] = raw[k] + prior[k]; break; CASE(F_avg) cur[k] = raw[k] + ((prior[k] + cur[k-img_n])>>1); break; CASE(F_paeth) cur[k] = (uint8) (raw[k] + paeth(cur[k-img_n],prior[k],prior[k-img_n])); break; CASE(F_avg_first) cur[k] = raw[k] + (cur[k-img_n] >> 1); break; CASE(F_paeth_first) cur[k] = (uint8) (raw[k] + paeth(cur[k-img_n],0,0)); break; } #undef CASE } else { assert(img_n+1 == out_n); #define CASE(f) \ case f: \ for (i=x-1; i >= 1; --i, cur[img_n]=255,raw+=img_n,cur+=out_n,prior+=out_n) \ for (k=0; k < img_n; ++k) switch (filter) { CASE(F_none) cur[k] = raw[k]; break; CASE(F_sub) cur[k] = raw[k] + cur[k-out_n]; break; CASE(F_up) cur[k] = raw[k] + prior[k]; break; CASE(F_avg) cur[k] = raw[k] + ((prior[k] + cur[k-out_n])>>1); break; CASE(F_paeth) cur[k] = (uint8) (raw[k] + paeth(cur[k-out_n],prior[k],prior[k-out_n])); break; CASE(F_avg_first) cur[k] = raw[k] + (cur[k-out_n] >> 1); break; CASE(F_paeth_first) cur[k] = (uint8) (raw[k] + paeth(cur[k-out_n],0,0)); break; } #undef CASE } } return 1; } static int create_png_image(png *a, uint8 *raw, uint32 raw_len, int out_n, int interlaced) { uint8 *final; int p; int save; if (!interlaced) return create_png_image_raw(a, raw, raw_len, out_n, a->s.img_x, a->s.img_y); save = stbi_png_partial; stbi_png_partial = 0; // de-interlacing final = (uint8 *) malloc(a->s.img_x * a->s.img_y * out_n); for (p=0; p < 7; ++p) { int xorig[] = { 0,4,0,2,0,1,0 }; int yorig[] = { 0,0,4,0,2,0,1 }; int xspc[] = { 8,8,4,4,2,2,1 }; int yspc[] = { 8,8,8,4,4,2,2 }; int i,j,x,y; // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1 x = (a->s.img_x - xorig[p] + xspc[p]-1) / xspc[p]; y = (a->s.img_y - yorig[p] + yspc[p]-1) / yspc[p]; if (x && y) { if (!create_png_image_raw(a, raw, raw_len, out_n, x, y)) { free(final); return 0; } for (j=0; j < y; ++j) for (i=0; i < x; ++i) memcpy(final + (j*yspc[p]+yorig[p])*a->s.img_x*out_n + (i*xspc[p]+xorig[p])*out_n, a->out + (j*x+i)*out_n, out_n); free(a->out); raw += (x*out_n+1)*y; raw_len -= (x*out_n+1)*y; } } a->out = final; stbi_png_partial = save; return 1; } static int compute_transparency(png *z, uint8 tc[3], int out_n) { stbi *s = &z->s; uint32 i, pixel_count = s->img_x * s->img_y; uint8 *p = z->out; // compute color-based transparency, assuming we've // already got 255 as the alpha value in the output assert(out_n == 2 || out_n == 4); if (out_n == 2) { for (i=0; i < pixel_count; ++i) { p[1] = (p[0] == tc[0] ? 0 : 255); p += 2; } } else { for (i=0; i < pixel_count; ++i) { if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) p[3] = 0; p += 4; } } return 1; } static int expand_palette(png *a, uint8 *palette, int len, int pal_img_n) { uint32 i, pixel_count = a->s.img_x * a->s.img_y; uint8 *p, *temp_out, *orig = a->out; p = (uint8 *) malloc(pixel_count * pal_img_n); if (p == NULL) return e("outofmem", "Out of memory"); // between here and free(out) below, exitting would leak temp_out = p; if (pal_img_n == 3) { for (i=0; i < pixel_count; ++i) { int n = orig[i]*4; p[0] = palette[n ]; p[1] = palette[n+1]; p[2] = palette[n+2]; p += 3; } } else { for (i=0; i < pixel_count; ++i) { int n = orig[i]*4; p[0] = palette[n ]; p[1] = palette[n+1]; p[2] = palette[n+2]; p[3] = palette[n+3]; p += 4; } } free(a->out); a->out = temp_out; STBI_NOTUSED(len); return 1; } static int stbi_unpremultiply_on_load = 0; static int stbi_de_iphone_flag = 0; void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply) { stbi_unpremultiply_on_load = flag_true_if_should_unpremultiply; } void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert) { stbi_de_iphone_flag = flag_true_if_should_convert; } static void stbi_de_iphone(png *z) { stbi *s = &z->s; uint32 i, pixel_count = s->img_x * s->img_y; uint8 *p = z->out; if (s->img_out_n == 3) { // convert bgr to rgb for (i=0; i < pixel_count; ++i) { uint8 t = p[0]; p[0] = p[2]; p[2] = t; p += 3; } } else { assert(s->img_out_n == 4); if (stbi_unpremultiply_on_load) { // convert bgr to rgb and unpremultiply for (i=0; i < pixel_count; ++i) { uint8 a = p[3]; uint8 t = p[0]; if (a) { p[0] = p[2] * 255 / a; p[1] = p[1] * 255 / a; p[2] = t * 255 / a; } else { p[0] = p[2]; p[2] = t; } p += 4; } } else { // convert bgr to rgb for (i=0; i < pixel_count; ++i) { uint8 t = p[0]; p[0] = p[2]; p[2] = t; p += 4; } } } } static int parse_png_file(png *z, int scan, int req_comp) { uint8 palette[1024], pal_img_n=0; uint8 has_trans=0, tc[3]; uint32 ioff=0, idata_limit=0, i, pal_len=0; int first=1,k,interlace=0, iphone=0; stbi *s = &z->s; if (!check_png_header(s)) return 0; if (scan == SCAN_type) return 1; for (;;) { chunk c = get_chunk_header(s); switch (c.type) { case PNG_TYPE('C','g','B','I'): iphone = stbi_de_iphone_flag; skip(s, c.length); break; case PNG_TYPE('I','H','D','R'): { int depth,color,comp,filter; if (!first) return e("multiple IHDR","Corrupt PNG"); first = 0; if (c.length != 13) return e("bad IHDR len","Corrupt PNG"); s->img_x = get32(s); if (s->img_x > (1 << 24)) return e("too large","Very large image (corrupt?)"); s->img_y = get32(s); if (s->img_y > (1 << 24)) return e("too large","Very large image (corrupt?)"); depth = get8(s); if (depth != 8) return e("8bit only","PNG not supported: 8-bit only"); color = get8(s); if (color > 6) return e("bad ctype","Corrupt PNG"); if (color == 3) pal_img_n = 3; else if (color & 1) return e("bad ctype","Corrupt PNG"); comp = get8(s); if (comp) return e("bad comp method","Corrupt PNG"); filter= get8(s); if (filter) return e("bad filter method","Corrupt PNG"); interlace = get8(s); if (interlace>1) return e("bad interlace method","Corrupt PNG"); if (!s->img_x || !s->img_y) return e("0-pixel image","Corrupt PNG"); if (!pal_img_n) { s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); if ((1 << 30) / s->img_x / s->img_n < s->img_y) return e("too large", "Image too large to decode"); if (scan == SCAN_header) return 1; } else { // if paletted, then pal_n is our final components, and // img_n is # components to decompress/filter. s->img_n = 1; if ((1 << 30) / s->img_x / 4 < s->img_y) return e("too large","Corrupt PNG"); // if SCAN_header, have to scan to see if we have a tRNS } break; } case PNG_TYPE('P','L','T','E'): { if (first) return e("first not IHDR", "Corrupt PNG"); if (c.length > 256*3) return e("invalid PLTE","Corrupt PNG"); pal_len = c.length / 3; if (pal_len * 3 != c.length) return e("invalid PLTE","Corrupt PNG"); for (i=0; i < pal_len; ++i) { palette[i*4+0] = get8u(s); palette[i*4+1] = get8u(s); palette[i*4+2] = get8u(s); palette[i*4+3] = 255; } break; } case PNG_TYPE('t','R','N','S'): { if (first) return e("first not IHDR", "Corrupt PNG"); if (z->idata) return e("tRNS after IDAT","Corrupt PNG"); if (pal_img_n) { if (scan == SCAN_header) { s->img_n = 4; return 1; } if (pal_len == 0) return e("tRNS before PLTE","Corrupt PNG"); if (c.length > pal_len) return e("bad tRNS len","Corrupt PNG"); pal_img_n = 4; for (i=0; i < c.length; ++i) palette[i*4+3] = get8u(s); } else { if (!(s->img_n & 1)) return e("tRNS with alpha","Corrupt PNG"); if (c.length != (uint32) s->img_n*2) return e("bad tRNS len","Corrupt PNG"); has_trans = 1; for (k=0; k < s->img_n; ++k) tc[k] = (uint8) get16(s); // non 8-bit images will be larger } break; } case PNG_TYPE('I','D','A','T'): { if (first) return e("first not IHDR", "Corrupt PNG"); if (pal_img_n && !pal_len) return e("no PLTE","Corrupt PNG"); if (scan == SCAN_header) { s->img_n = pal_img_n; return 1; } if (ioff + c.length > idata_limit) { uint8 *p; if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; while (ioff + c.length > idata_limit) idata_limit *= 2; p = (uint8 *) realloc(z->idata, idata_limit); if (p == NULL) return e("outofmem", "Out of memory"); z->idata = p; } if (!getn(s, z->idata+ioff,c.length)) return e("outofdata","Corrupt PNG"); ioff += c.length; break; } case PNG_TYPE('I','E','N','D'): { uint32 raw_len; if (first) return e("first not IHDR", "Corrupt PNG"); if (scan != SCAN_load) return 1; if (z->idata == NULL) return e("no IDAT","Corrupt PNG"); z->expanded = (uint8 *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, 16384, (int *) &raw_len, !iphone); if (z->expanded == NULL) return 0; // zlib should set error free(z->idata); z->idata = NULL; if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) s->img_out_n = s->img_n+1; else s->img_out_n = s->img_n; if (!create_png_image(z, z->expanded, raw_len, s->img_out_n, interlace)) return 0; if (has_trans) if (!compute_transparency(z, tc, s->img_out_n)) return 0; if (iphone && s->img_out_n > 2) stbi_de_iphone(z); if (pal_img_n) { // pal_img_n == 3 or 4 s->img_n = pal_img_n; // record the actual colors we had s->img_out_n = pal_img_n; if (req_comp >= 3) s->img_out_n = req_comp; if (!expand_palette(z, palette, pal_len, s->img_out_n)) return 0; } free(z->expanded); z->expanded = NULL; return 1; } default: // if critical, fail if (first) return e("first not IHDR", "Corrupt PNG"); if ((c.type & (1 << 29)) == 0) { #ifndef STBI_NO_FAILURE_STRINGS // not threadsafe static char invalid_chunk[] = "XXXX chunk not known"; invalid_chunk[0] = (uint8) (c.type >> 24); invalid_chunk[1] = (uint8) (c.type >> 16); invalid_chunk[2] = (uint8) (c.type >> 8); invalid_chunk[3] = (uint8) (c.type >> 0); #endif return e(invalid_chunk, "PNG not supported: unknown chunk type"); } skip(s, c.length); break; } // end of chunk, read and skip CRC get32(s); } } static unsigned char *do_png(png *p, int *x, int *y, int *n, int req_comp) { unsigned char *result=NULL; p->expanded = NULL; p->idata = NULL; p->out = NULL; if (req_comp < 0 || req_comp > 4) return epuc("bad req_comp", "Internal error"); if (parse_png_file(p, SCAN_load, req_comp)) { result = p->out; p->out = NULL; if (req_comp && req_comp != p->s.img_out_n) { result = convert_format(result, p->s.img_out_n, req_comp, p->s.img_x, p->s.img_y); p->s.img_out_n = req_comp; if (result == NULL) return result; } *x = p->s.img_x; *y = p->s.img_y; if (n) *n = p->s.img_n; } free(p->out); p->out = NULL; free(p->expanded); p->expanded = NULL; free(p->idata); p->idata = NULL; return result; } #ifndef STBI_NO_STDIO unsigned char *stbi_png_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { png p; start_file(&p.s, f); return do_png(&p, x,y,comp,req_comp); } unsigned char *stbi_png_load(char const *filename, int *x, int *y, int *comp, int req_comp) { unsigned char *data; FILE *f = fopen(filename, "rb"); if (!f) return NULL; data = stbi_png_load_from_file(f,x,y,comp,req_comp); fclose(f); return data; } #endif unsigned char *stbi_png_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { png p; start_mem(&p.s, buffer,len); return do_png(&p, x,y,comp,req_comp); } #ifndef STBI_NO_STDIO int stbi_png_test_file(FILE *f) { png p; int n,r; n = ftell(f); start_file(&p.s, f); r = parse_png_file(&p, SCAN_type,STBI_default); fseek(f,n,SEEK_SET); return r; } #endif int stbi_png_test_memory(stbi_uc const *buffer, int len) { png p; start_mem(&p.s, buffer, len); return parse_png_file(&p, SCAN_type,STBI_default); } static int stbi_png_info_raw(png *p, int *x, int *y, int *comp) { if (!parse_png_file(p, SCAN_header, 0)) return 0; if (x) *x = p->s.img_x; if (y) *y = p->s.img_y; if (comp) *comp = p->s.img_n; return 1; } #ifndef STBI_NO_STDIO int stbi_png_info (char const *filename, int *x, int *y, int *comp) { int res; FILE *f = fopen(filename, "rb"); if (!f) return 0; res = stbi_png_info_from_file(f, x, y, comp); fclose(f); return res; } int stbi_png_info_from_file(FILE *f, int *x, int *y, int *comp) { png p; int res; long n = ftell(f); start_file(&p.s, f); res = stbi_png_info_raw(&p, x, y, comp); fseek(f, n, SEEK_SET); return res; } #endif // !STBI_NO_STDIO int stbi_png_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) { png p; start_mem(&p.s, buffer, len); return stbi_png_info_raw(&p, x, y, comp); } // Microsoft/Windows BMP image static int bmp_test(stbi *s) { int sz; if (get8(s) != 'B') return 0; if (get8(s) != 'M') return 0; get32le(s); // discard filesize get16le(s); // discard reserved get16le(s); // discard reserved get32le(s); // discard data offset sz = get32le(s); if (sz == 12 || sz == 40 || sz == 56 || sz == 108) return 1; return 0; } #ifndef STBI_NO_STDIO int stbi_bmp_test_file (FILE *f) { stbi s; int r,n = ftell(f); start_file(&s,f); r = bmp_test(&s); fseek(f,n,SEEK_SET); return r; } #endif int stbi_bmp_test_memory (stbi_uc const *buffer, int len) { stbi s; start_mem(&s, buffer, len); return bmp_test(&s); } // returns 0..31 for the highest set bit static int high_bit(unsigned int z) { int n=0; if (z == 0) return -1; if (z >= 0x10000) n += 16, z >>= 16; if (z >= 0x00100) n += 8, z >>= 8; if (z >= 0x00010) n += 4, z >>= 4; if (z >= 0x00004) n += 2, z >>= 2; if (z >= 0x00002) n += 1, z >>= 1; return n; } static int bitcount(unsigned int a) { a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2 a = (a & 0x33333333) + ((a >> 2) & 0x33333333); // max 4 a = (a + (a >> 4)) & 0x0f0f0f0f; // max 8 per 4, now 8 bits a = (a + (a >> 8)); // max 16 per 8 bits a = (a + (a >> 16)); // max 32 per 8 bits return a & 0xff; } static int shiftsigned(int v, int shift, int bits) { int result; int z=0; if (shift < 0) v <<= -shift; else v >>= shift; result = v; z = bits; while (z < 8) { result += v >> z; z += bits; } return result; } static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp) { uint8 *out; unsigned int mr=0,mg=0,mb=0,ma=0, fake_a=0; stbi_uc pal[256][4]; int psize=0,i,j,compress=0,width; int bpp, flip_vertically, pad, target, offset, hsz; if (get8(s) != 'B' || get8(s) != 'M') return epuc("not BMP", "Corrupt BMP"); get32le(s); // discard filesize get16le(s); // discard reserved get16le(s); // discard reserved offset = get32le(s); hsz = get32le(s); if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108) return epuc("unknown BMP", "BMP type not supported: unknown"); if (hsz == 12) { s->img_x = get16le(s); s->img_y = get16le(s); } else { s->img_x = get32le(s); s->img_y = get32le(s); } if (get16le(s) != 1) return epuc("bad BMP", "bad BMP"); bpp = get16le(s); if (bpp == 1) return epuc("monochrome", "BMP type not supported: 1-bit"); flip_vertically = ((int) s->img_y) > 0; s->img_y = abs((int) s->img_y); if (hsz == 12) { if (bpp < 24) psize = (offset - 14 - 24) / 3; } else { compress = get32le(s); if (compress == 1 || compress == 2) return epuc("BMP RLE", "BMP type not supported: RLE"); get32le(s); // discard sizeof get32le(s); // discard hres get32le(s); // discard vres get32le(s); // discard colorsused get32le(s); // discard max important if (hsz == 40 || hsz == 56) { if (hsz == 56) { get32le(s); get32le(s); get32le(s); get32le(s); } if (bpp == 16 || bpp == 32) { mr = mg = mb = 0; if (compress == 0) { if (bpp == 32) { mr = 0xffu << 16; mg = 0xffu << 8; mb = 0xffu << 0; ma = 0xffu << 24; fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255 } else { mr = 31u << 10; mg = 31u << 5; mb = 31u << 0; } } else if (compress == 3) { mr = get32le(s); mg = get32le(s); mb = get32le(s); // not documented, but generated by photoshop and handled by mspaint if (mr == mg && mg == mb) { // ?!?!? return epuc("bad BMP", "bad BMP"); } } else return epuc("bad BMP", "bad BMP"); } } else { assert(hsz == 108); mr = get32le(s); mg = get32le(s); mb = get32le(s); ma = get32le(s); get32le(s); // discard color space for (i=0; i < 12; ++i) get32le(s); // discard color space parameters } if (bpp < 16) psize = (offset - 14 - hsz) >> 2; } s->img_n = ma ? 4 : 3; if (req_comp && req_comp >= 3) // we can directly decode 3 or 4 target = req_comp; else target = s->img_n; // if they want monochrome, we'll post-convert out = (stbi_uc *) malloc(target * s->img_x * s->img_y); if (!out) return epuc("outofmem", "Out of memory"); if (bpp < 16) { int z=0; if (psize == 0 || psize > 256) { free(out); return epuc("invalid", "Corrupt BMP"); } for (i=0; i < psize; ++i) { pal[i][2] = get8u(s); pal[i][1] = get8u(s); pal[i][0] = get8u(s); if (hsz != 12) get8(s); pal[i][3] = 255; } skip(s, offset - 14 - hsz - psize * (hsz == 12 ? 3 : 4)); if (bpp == 4) width = (s->img_x + 1) >> 1; else if (bpp == 8) width = s->img_x; else { free(out); return epuc("bad bpp", "Corrupt BMP"); } pad = (-width)&3; for (j=0; j < (int) s->img_y; ++j) { for (i=0; i < (int) s->img_x; i += 2) { int v=get8(s),v2=0; if (bpp == 4) { v2 = v & 15; v >>= 4; } out[z++] = pal[v][0]; out[z++] = pal[v][1]; out[z++] = pal[v][2]; if (target == 4) out[z++] = 255; if (i+1 == (int) s->img_x) break; v = (bpp == 8) ? get8(s) : v2; out[z++] = pal[v][0]; out[z++] = pal[v][1]; out[z++] = pal[v][2]; if (target == 4) out[z++] = 255; } skip(s, pad); } } else { int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0; int z = 0; int easy=0; skip(s, offset - 14 - hsz); if (bpp == 24) width = 3 * s->img_x; else if (bpp == 16) width = 2*s->img_x; else /* bpp = 32 and pad = 0 */ width=0; pad = (-width) & 3; if (bpp == 24) { easy = 1; } else if (bpp == 32) { if (mb == 0xff && mg == 0xff00 && mr == 0xff000000 && ma == 0xff000000) easy = 2; } if (!easy) { if (!mr || !mg || !mb) return epuc("bad masks", "Corrupt BMP"); // right shift amt to put high bit in position #7 rshift = high_bit(mr)-7; rcount = bitcount(mr); gshift = high_bit(mg)-7; gcount = bitcount(mr); bshift = high_bit(mb)-7; bcount = bitcount(mr); ashift = high_bit(ma)-7; acount = bitcount(mr); } for (j=0; j < (int) s->img_y; ++j) { if (easy) { for (i=0; i < (int) s->img_x; ++i) { int a; out[z+2] = get8u(s); out[z+1] = get8u(s); out[z+0] = get8u(s); z += 3; a = (easy == 2 ? get8(s) : 255); if (target == 4) out[z++] = (uint8) a; } } else { for (i=0; i < (int) s->img_x; ++i) { uint32 v = (bpp == 16 ? get16le(s) : get32le(s)); int a; out[z++] = (uint8) shiftsigned(v & mr, rshift, rcount); out[z++] = (uint8) shiftsigned(v & mg, gshift, gcount); out[z++] = (uint8) shiftsigned(v & mb, bshift, bcount); a = (ma ? shiftsigned(v & ma, ashift, acount) : 255); if (target == 4) out[z++] = (uint8) a; } } skip(s, pad); } } if (flip_vertically) { stbi_uc t; for (j=0; j < (int) s->img_y>>1; ++j) { stbi_uc *p1 = out + j *s->img_x*target; stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target; for (i=0; i < (int) s->img_x*target; ++i) { t = p1[i], p1[i] = p2[i], p2[i] = t; } } } if (req_comp && req_comp != target) { out = convert_format(out, target, req_comp, s->img_x, s->img_y); if (out == NULL) return out; // convert_format frees input on failure } *x = s->img_x; *y = s->img_y; if (comp) *comp = target; return out; } #ifndef STBI_NO_STDIO stbi_uc *stbi_bmp_load (char const *filename, int *x, int *y, int *comp, int req_comp) { stbi_uc *data; FILE *f = fopen(filename, "rb"); if (!f) return NULL; data = stbi_bmp_load_from_file(f, x,y,comp,req_comp); fclose(f); return data; } stbi_uc *stbi_bmp_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp) { stbi s; start_file(&s, f); return bmp_load(&s, x,y,comp,req_comp); } #endif stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { stbi s; start_mem(&s, buffer, len); return bmp_load(&s, x,y,comp,req_comp); } // Targa Truevision - TGA // by Jonathan Dummer static int tga_info(stbi *s, int *x, int *y, int *comp) { int tga_w, tga_h, tga_comp; int sz; get8u(s); // discard Offset sz = get8u(s); // color type if( sz > 1 ) return 0; // only RGB or indexed allowed sz = get8u(s); // image type // only RGB or grey allowed, +/- RLE if ((sz != 1) && (sz != 2) && (sz != 3) && (sz != 9) && (sz != 10) && (sz != 11)) return 0; get16le(s); // discard palette start get16le(s); // discard palette length get8(s); // discard bits per palette color entry get16le(s); // discard x origin get16le(s); // discard y origin tga_w = get16le(s); if( tga_w < 1 ) return 0; // test width tga_h = get16le(s); if( tga_h < 1 ) return 0; // test height sz = get8(s); // bits per pixel // only RGB or RGBA or grey allowed if ((sz != 8) && (sz != 16) && (sz != 24) && (sz != 32)) return 0; tga_comp = sz; if (x) *x = tga_w; if (y) *y = tga_h; if (comp) *comp = tga_comp / 8; return 1; // seems to have passed everything } #ifndef STBI_NO_STDIO int stbi_tga_info_from_file(FILE *f, int *x, int *y, int *comp) { stbi s; int r; long n = ftell(f); start_file(&s, f); r = tga_info(&s, x, y, comp); fseek(f, n, SEEK_SET); return r; } #endif int stbi_tga_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) { stbi s; start_mem(&s, buffer, len); return tga_info(&s, x, y, comp); } static int tga_test(stbi *s) { int sz; get8u(s); // discard Offset sz = get8u(s); // color type if ( sz > 1 ) return 0; // only RGB or indexed allowed sz = get8u(s); // image type if ( (sz != 1) && (sz != 2) && (sz != 3) && (sz != 9) && (sz != 10) && (sz != 11) ) return 0; // only RGB or grey allowed, +/- RLE get16(s); // discard palette start get16(s); // discard palette length get8(s); // discard bits per palette color entry get16(s); // discard x origin get16(s); // discard y origin if ( get16(s) < 1 ) return 0; // test width if ( get16(s) < 1 ) return 0; // test height sz = get8(s); // bits per pixel if ( (sz != 8) && (sz != 16) && (sz != 24) && (sz != 32) ) return 0; // only RGB or RGBA or grey allowed return 1; // seems to have passed everything } #ifndef STBI_NO_STDIO int stbi_tga_test_file (FILE *f) { stbi s; int r,n = ftell(f); start_file(&s, f); r = tga_test(&s); fseek(f,n,SEEK_SET); return r; } #endif int stbi_tga_test_memory (stbi_uc const *buffer, int len) { stbi s; start_mem(&s, buffer, len); return tga_test(&s); } static stbi_uc *tga_load(stbi *s, int *x, int *y, int *comp, int req_comp) { // read in the TGA header stuff int tga_offset = get8u(s); int tga_indexed = get8u(s); int tga_image_type = get8u(s); int tga_is_RLE = 0; int tga_palette_start = get16le(s); int tga_palette_len = get16le(s); int tga_palette_bits = get8u(s); int tga_x_origin = get16le(s); int tga_y_origin = get16le(s); int tga_width = get16le(s); int tga_height = get16le(s); int tga_bits_per_pixel = get8u(s); int tga_inverted = get8u(s); // image data unsigned char *tga_data; unsigned char *tga_palette = NULL; int i, j; unsigned char raw_data[4]; unsigned char trans_data[4]; int RLE_count = 0; int RLE_repeating = 0; int read_next_pixel = 1; // do a tiny bit of precessing if ( tga_image_type >= 8 ) { tga_image_type -= 8; tga_is_RLE = 1; } /* int tga_alpha_bits = tga_inverted & 15; */ tga_inverted = 1 - ((tga_inverted >> 5) & 1); // error check if ( //(tga_indexed) || (tga_width < 1) || (tga_height < 1) || (tga_image_type < 1) || (tga_image_type > 3) || ((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16) && (tga_bits_per_pixel != 24) && (tga_bits_per_pixel != 32)) ) { return NULL; } // If I'm paletted, then I'll use the number of bits from the palette if ( tga_indexed ) { tga_bits_per_pixel = tga_palette_bits; } // tga info *x = tga_width; *y = tga_height; if ( (req_comp < 1) || (req_comp > 4) ) { // just use whatever the file was req_comp = tga_bits_per_pixel / 8; *comp = req_comp; } else { // force a new number of components *comp = tga_bits_per_pixel/8; } tga_data = (unsigned char*)malloc( tga_width * tga_height * req_comp ); // skip to the data's starting position (offset usually = 0) skip(s, tga_offset ); // do I need to load a palette? if ( tga_indexed ) { // any data to skip? (offset usually = 0) skip(s, tga_palette_start ); // load the palette tga_palette = (unsigned char*)malloc( tga_palette_len * tga_palette_bits / 8 ); if (!getn(s, tga_palette, tga_palette_len * tga_palette_bits / 8 )) { free(tga_data); return NULL; } } // load the data trans_data[0] = trans_data[1] = trans_data[2] = trans_data[3] = 0; for (i=0; i < tga_width * tga_height; ++i) { // if I'm in RLE mode, do I need to get a RLE chunk? if ( tga_is_RLE ) { if ( RLE_count == 0 ) { // yep, get the next byte as a RLE command int RLE_cmd = get8u(s); RLE_count = 1 + (RLE_cmd & 127); RLE_repeating = RLE_cmd >> 7; read_next_pixel = 1; } else if ( !RLE_repeating ) { read_next_pixel = 1; } } else { read_next_pixel = 1; } // OK, if I need to read a pixel, do it now if ( read_next_pixel ) { // load however much data we did have if ( tga_indexed ) { // read in 1 byte, then perform the lookup int pal_idx = get8u(s); if ( pal_idx >= tga_palette_len ) { // invalid index pal_idx = 0; } pal_idx *= tga_bits_per_pixel / 8; for (j = 0; j*8 < tga_bits_per_pixel; ++j) { raw_data[j] = tga_palette[pal_idx+j]; } } else { // read in the data raw for (j = 0; j*8 < tga_bits_per_pixel; ++j) { raw_data[j] = get8u(s); } } // convert raw to the intermediate format switch (tga_bits_per_pixel) { case 8: // Luminous => RGBA trans_data[0] = raw_data[0]; trans_data[1] = raw_data[0]; trans_data[2] = raw_data[0]; trans_data[3] = 255; break; case 16: // Luminous,Alpha => RGBA trans_data[0] = raw_data[0]; trans_data[1] = raw_data[0]; trans_data[2] = raw_data[0]; trans_data[3] = raw_data[1]; break; case 24: // BGR => RGBA trans_data[0] = raw_data[2]; trans_data[1] = raw_data[1]; trans_data[2] = raw_data[0]; trans_data[3] = 255; break; case 32: // BGRA => RGBA trans_data[0] = raw_data[2]; trans_data[1] = raw_data[1]; trans_data[2] = raw_data[0]; trans_data[3] = raw_data[3]; break; } // clear the reading flag for the next pixel read_next_pixel = 0; } // end of reading a pixel // convert to final format switch (req_comp) { case 1: // RGBA => Luminance tga_data[i*req_comp+0] = compute_y(trans_data[0],trans_data[1],trans_data[2]); break; case 2: // RGBA => Luminance,Alpha tga_data[i*req_comp+0] = compute_y(trans_data[0],trans_data[1],trans_data[2]); tga_data[i*req_comp+1] = trans_data[3]; break; case 3: // RGBA => RGB tga_data[i*req_comp+0] = trans_data[0]; tga_data[i*req_comp+1] = trans_data[1]; tga_data[i*req_comp+2] = trans_data[2]; break; case 4: // RGBA => RGBA tga_data[i*req_comp+0] = trans_data[0]; tga_data[i*req_comp+1] = trans_data[1]; tga_data[i*req_comp+2] = trans_data[2]; tga_data[i*req_comp+3] = trans_data[3]; break; } // in case we're in RLE mode, keep counting down --RLE_count; } // do I need to invert the image? if ( tga_inverted ) { for (j = 0; j*2 < tga_height; ++j) { int index1 = j * tga_width * req_comp; int index2 = (tga_height - 1 - j) * tga_width * req_comp; for (i = tga_width * req_comp; i > 0; --i) { unsigned char temp = tga_data[index1]; tga_data[index1] = tga_data[index2]; tga_data[index2] = temp; ++index1; ++index2; } } } // clear my palette, if I had one if ( tga_palette != NULL ) { free( tga_palette ); } // the things I do to get rid of an error message, and yet keep // Microsoft's C compilers happy... [8^( tga_palette_start = tga_palette_len = tga_palette_bits = tga_x_origin = tga_y_origin = 0; // OK, done return tga_data; } #ifndef STBI_NO_STDIO stbi_uc *stbi_tga_load (char const *filename, int *x, int *y, int *comp, int req_comp) { stbi_uc *data; FILE *f = fopen(filename, "rb"); if (!f) return NULL; data = stbi_tga_load_from_file(f, x,y,comp,req_comp); fclose(f); return data; } stbi_uc *stbi_tga_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp) { stbi s; start_file(&s, f); return tga_load(&s, x,y,comp,req_comp); } #endif stbi_uc *stbi_tga_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { stbi s; start_mem(&s, buffer, len); return tga_load(&s, x,y,comp,req_comp); } // ************************************************************************************************* // Photoshop PSD loader -- PD by Thatcher Ulrich, integration by Nicolas Schulz, tweaked by STB static int psd_test(stbi *s) { if (get32(s) != 0x38425053) return 0; // "8BPS" else return 1; } #ifndef STBI_NO_STDIO int stbi_psd_test_file(FILE *f) { stbi s; int r,n = ftell(f); start_file(&s, f); r = psd_test(&s); fseek(f,n,SEEK_SET); return r; } #endif int stbi_psd_test_memory(stbi_uc const *buffer, int len) { stbi s; start_mem(&s, buffer, len); return psd_test(&s); } static stbi_uc *psd_load(stbi *s, int *x, int *y, int *comp, int req_comp) { int pixelCount; int channelCount, compression; int channel, i, count, len; int w,h; uint8 *out; // Check identifier if (get32(s) != 0x38425053) // "8BPS" return epuc("not PSD", "Corrupt PSD image"); // Check file type version. if (get16(s) != 1) return epuc("wrong version", "Unsupported version of PSD image"); // Skip 6 reserved bytes. skip(s, 6 ); // Read the number of channels (R, G, B, A, etc). channelCount = get16(s); if (channelCount < 0 || channelCount > 16) return epuc("wrong channel count", "Unsupported number of channels in PSD image"); // Read the rows and columns of the image. h = get32(s); w = get32(s); // Make sure the depth is 8 bits. if (get16(s) != 8) return epuc("unsupported bit depth", "PSD bit depth is not 8 bit"); // Make sure the color mode is RGB. // Valid options are: // 0: Bitmap // 1: Grayscale // 2: Indexed color // 3: RGB color // 4: CMYK color // 7: Multichannel // 8: Duotone // 9: Lab color if (get16(s) != 3) return epuc("wrong color format", "PSD is not in RGB color format"); // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.) skip(s,get32(s) ); // Skip the image resources. (resolution, pen tool paths, etc) skip(s, get32(s) ); // Skip the reserved data. skip(s, get32(s) ); // Find out if the data is compressed. // Known values: // 0: no compression // 1: RLE compressed compression = get16(s); if (compression > 1) return epuc("bad compression", "PSD has an unknown compression format"); // Create the destination image. out = (stbi_uc *) malloc(4 * w*h); if (!out) return epuc("outofmem", "Out of memory"); pixelCount = w*h; // Initialize the data to zero. //memset( out, 0, pixelCount * 4 ); // Finally, the image data. if (compression) { // RLE as used by .PSD and .TIFF // Loop until you get the number of unpacked bytes you are expecting: // Read the next source byte into n. // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally. // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times. // Else if n is 128, noop. // Endloop // The RLE-compressed data is preceeded by a 2-byte data count for each row in the data, // which we're going to just skip. skip(s, h * channelCount * 2 ); // Read the RLE data by channel. for (channel = 0; channel < 4; channel++) { uint8 *p; p = out+channel; if (channel >= channelCount) { // Fill this channel with default data. for (i = 0; i < pixelCount; i++) *p = (channel == 3 ? 255 : 0), p += 4; } else { // Read the RLE data. count = 0; while (count < pixelCount) { len = get8(s); if (len == 128) { // No-op. } else if (len < 128) { // Copy next len+1 bytes literally. len++; count += len; while (len) { *p = get8u(s); p += 4; len--; } } else if (len > 128) { uint8 val; // Next -len+1 bytes in the dest are replicated from next source byte. // (Interpret len as a negative 8-bit int.) len ^= 0x0FF; len += 2; val = get8u(s); count += len; while (len) { *p = val; p += 4; len--; } } } } } } else { // We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...) // where each channel consists of an 8-bit value for each pixel in the image. // Read the data by channel. for (channel = 0; channel < 4; channel++) { uint8 *p; p = out + channel; if (channel > channelCount) { // Fill this channel with default data. for (i = 0; i < pixelCount; i++) *p = channel == 3 ? 255 : 0, p += 4; } else { // Read the data. for (i = 0; i < pixelCount; i++) *p = get8u(s), p += 4; } } } if (req_comp && req_comp != 4) { out = convert_format(out, 4, req_comp, w, h); if (out == NULL) return out; // convert_format frees input on failure } if (comp) *comp = channelCount; *y = h; *x = w; return out; } #ifndef STBI_NO_STDIO stbi_uc *stbi_psd_load(char const *filename, int *x, int *y, int *comp, int req_comp) { stbi_uc *data; FILE *f = fopen(filename, "rb"); if (!f) return NULL; data = stbi_psd_load_from_file(f, x,y,comp,req_comp); fclose(f); return data; } stbi_uc *stbi_psd_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { stbi s; start_file(&s, f); return psd_load(&s, x,y,comp,req_comp); } #endif stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { stbi s; start_mem(&s, buffer, len); return psd_load(&s, x,y,comp,req_comp); } // ************************************************************************************************* // Softimage PIC loader // by Tom Seddon // // See http://softimage.wiki.softimage.com/index.php/INFO:_PIC_file_format // See http://ozviz.wasp.uwa.edu.au/~pbourke/dataformats/softimagepic/ static int pic_is4(stbi *s,const char *str) { int i; for (i=0; i<4; ++i) if (get8(s) != (stbi_uc)str[i]) return 0; return 1; } static int pic_test(stbi *s) { int i; if (!pic_is4(s,"\x53\x80\xF6\x34")) return 0; for(i=0;i<84;++i) get8(s); if (!pic_is4(s,"PICT")) return 0; return 1; } typedef struct { stbi_uc size,type,channel; } pic_packet_t; static stbi_uc *pic_readval(stbi *s, int channel, stbi_uc *dest) { int mask=0x80, i; for (i=0; i<4; ++i, mask>>=1) { if (channel & mask) { if (at_eof(s)) return epuc("bad file","PIC file too short"); dest[i]=get8u(s); } } return dest; } static void pic_copyval(int channel,stbi_uc *dest,const stbi_uc *src) { int mask=0x80,i; for (i=0;i<4; ++i, mask>>=1) if (channel&mask) dest[i]=src[i]; } static stbi_uc *pic_load2(stbi *s,int width,int height,int *comp, stbi_uc *result) { int act_comp=0,num_packets=0,y,chained; pic_packet_t packets[10]; // this will (should...) cater for even some bizarre stuff like having data // for the same channel in multiple packets. do { pic_packet_t *packet; if (num_packets==sizeof(packets)/sizeof(packets[0])) return epuc("bad format","too many packets"); packet = &packets[num_packets++]; chained = get8(s); packet->size = get8u(s); packet->type = get8u(s); packet->channel = get8u(s); act_comp |= packet->channel; if (at_eof(s)) return epuc("bad file","file too short (reading packets)"); if (packet->size != 8) return epuc("bad format","packet isn't 8bpp"); } while (chained); *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel? for(y=0; y<height; ++y) { int packet_idx; for(packet_idx=0; packet_idx < num_packets; ++packet_idx) { pic_packet_t *packet = &packets[packet_idx]; stbi_uc *dest = result+y*width*4; switch (packet->type) { default: return epuc("bad format","packet has bad compression type"); case 0: {//uncompressed int x; for(x=0;x<width;++x, dest+=4) if (!pic_readval(s,packet->channel,dest)) return 0; break; } case 1://Pure RLE { int left=width, i; while (left>0) { stbi_uc count,value[4]; count=get8u(s); if (at_eof(s)) return epuc("bad file","file too short (pure read count)"); if (count > left) count = (uint8) left; if (!pic_readval(s,packet->channel,value)) return 0; for(i=0; i<count; ++i,dest+=4) pic_copyval(packet->channel,dest,value); left -= count; } } break; case 2: {//Mixed RLE int left=width; while (left>0) { int count = get8(s), i; if (at_eof(s)) return epuc("bad file","file too short (mixed read count)"); if (count >= 128) { // Repeated stbi_uc value[4]; int i; if (count==128) count = get16(s); else count -= 127; if (count > left) return epuc("bad file","scanline overrun"); if (!pic_readval(s,packet->channel,value)) return 0; for(i=0;i<count;++i, dest += 4) pic_copyval(packet->channel,dest,value); } else { // Raw ++count; if (count>left) return epuc("bad file","scanline overrun"); for(i=0;i<count;++i, dest+=4) if (!pic_readval(s,packet->channel,dest)) return 0; } left-=count; } break; } } } } return result; } static stbi_uc *pic_load(stbi *s,int *px,int *py,int *comp,int req_comp) { stbi_uc *result; int i, x,y; for (i=0; i<92; ++i) get8(s); x = get16(s); y = get16(s); if (at_eof(s)) return epuc("bad file","file too short (pic header)"); if ((1 << 28) / x < y) return epuc("too large", "Image too large to decode"); get32(s); //skip `ratio' get16(s); //skip `fields' get16(s); //skip `pad' // intermediate buffer is RGBA result = (stbi_uc *) malloc(x*y*4); memset(result, 0xff, x*y*4); if (!pic_load2(s,x,y,comp, result)) { free(result); result=0; } *px = x; *py = y; if (req_comp == 0) req_comp = *comp; result=convert_format(result,4,req_comp,x,y); return result; } int stbi_pic_test_memory(stbi_uc const *buffer, int len) { stbi s; start_mem(&s,buffer,len); return pic_test(&s); } stbi_uc *stbi_pic_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { stbi s; start_mem(&s,buffer,len); return pic_load(&s,x,y,comp,req_comp); } #ifndef STBI_NO_STDIO int stbi_pic_test_file(FILE *f) { int result; long l = ftell(f); stbi s; start_file(&s,f); result = pic_test(&s); fseek(f,l,SEEK_SET); return result; } stbi_uc *stbi_pic_load(char const *filename,int *x, int *y, int *comp, int req_comp) { stbi_uc *result; FILE *f=fopen(filename,"rb"); if (!f) return 0; result = stbi_pic_load_from_file(f,x,y,comp,req_comp); fclose(f); return result; } stbi_uc *stbi_pic_load_from_file(FILE *f,int *x, int *y, int *comp, int req_comp) { stbi s; start_file(&s,f); return pic_load(&s,x,y,comp,req_comp); } #endif // ************************************************************************************************* // GIF loader -- public domain by Jean-Marc Lienher -- simplified/shrunk by stb typedef struct stbi_gif_lzw_struct { int16 prefix; uint8 first; uint8 suffix; } stbi_gif_lzw; typedef struct stbi_gif_struct { int w,h; stbi_uc *out; // output buffer (always 4 components) int flags, bgindex, ratio, transparent, eflags; uint8 pal[256][4]; uint8 lpal[256][4]; stbi_gif_lzw codes[4096]; uint8 *color_table; int parse, step; int lflags; int start_x, start_y; int max_x, max_y; int cur_x, cur_y; int line_size; } stbi_gif; static int gif_test(stbi *s) { int sz; if (get8(s) != 'G' || get8(s) != 'I' || get8(s) != 'F' || get8(s) != '8') return 0; sz = get8(s); if (sz != '9' && sz != '7') return 0; if (get8(s) != 'a') return 0; return 1; } #ifndef STBI_NO_STDIO int stbi_gif_test_file (FILE *f) { stbi s; int r,n = ftell(f); start_file(&s,f); r = gif_test(&s); fseek(f,n,SEEK_SET); return r; } #endif int stbi_gif_test_memory (stbi_uc const *buffer, int len) { stbi s; start_mem(&s, buffer, len); return gif_test(&s); } static void stbi_gif_parse_colortable(stbi *s, uint8 pal[256][4], int num_entries, int transp) { int i; for (i=0; i < num_entries; ++i) { pal[i][2] = get8u(s); pal[i][1] = get8u(s); pal[i][0] = get8u(s); pal[i][3] = transp ? 0 : 255; } } static int stbi_gif_header(stbi *s, stbi_gif *g, int *comp, int is_info) { uint8 version; if (get8(s) != 'G' || get8(s) != 'I' || get8(s) != 'F' || get8(s) != '8') return e("not GIF", "Corrupt GIF"); version = get8u(s); if (version != '7' && version != '9') return e("not GIF", "Corrupt GIF"); if (get8(s) != 'a') return e("not GIF", "Corrupt GIF"); failure_reason = ""; g->w = get16le(s); g->h = get16le(s); g->flags = get8(s); g->bgindex = get8(s); g->ratio = get8(s); g->transparent = -1; if (comp != 0) *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments if (is_info) return 1; if (g->flags & 0x80) stbi_gif_parse_colortable(s,g->pal, 2 << (g->flags & 7), -1); return 1; } static int stbi_gif_info_raw(stbi *s, int *x, int *y, int *comp) { stbi_gif g; if (!stbi_gif_header(s, &g, comp, 1)) return 0; if (x) *x = g.w; if (y) *y = g.h; return 1; } static void stbi_out_gif_code(stbi_gif *g, uint16 code) { uint8 *p, *c; // recurse to decode the prefixes, since the linked-list is backwards, // and working backwards through an interleaved image would be nasty if (g->codes[code].prefix >= 0) stbi_out_gif_code(g, g->codes[code].prefix); if (g->cur_y >= g->max_y) return; p = &g->out[g->cur_x + g->cur_y]; c = &g->color_table[g->codes[code].suffix * 4]; if (c[3] >= 128) { p[0] = c[2]; p[1] = c[1]; p[2] = c[0]; p[3] = c[3]; } g->cur_x += 4; if (g->cur_x >= g->max_x) { g->cur_x = g->start_x; g->cur_y += g->step; while (g->cur_y >= g->max_y && g->parse > 0) { g->step = (1 << g->parse) * g->line_size; g->cur_y = g->start_y + (g->step >> 1); --g->parse; } } } static uint8 *stbi_process_gif_raster(stbi *s, stbi_gif *g) { uint8 lzw_cs; int32 len, code; uint32 first; int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear; stbi_gif_lzw *p; lzw_cs = get8u(s); clear = 1 << lzw_cs; first = 1; codesize = lzw_cs + 1; codemask = (1 << codesize) - 1; bits = 0; valid_bits = 0; for (code = 0; code < clear; code++) { g->codes[code].prefix = -1; g->codes[code].first = (uint8) code; g->codes[code].suffix = (uint8) code; } // support no starting clear code avail = clear+2; oldcode = -1; len = 0; for(;;) { if (valid_bits < codesize) { if (len == 0) { len = get8(s); // start new block if (len == 0) return g->out; } --len; bits |= (int32) get8(s) << valid_bits; valid_bits += 8; } else { int32 code = bits & codemask; bits >>= codesize; valid_bits -= codesize; // @OPTIMIZE: is there some way we can accelerate the non-clear path? if (code == clear) { // clear code codesize = lzw_cs + 1; codemask = (1 << codesize) - 1; avail = clear + 2; oldcode = -1; first = 0; } else if (code == clear + 1) { // end of stream code skip(s, len); while ((len = get8(s)) > 0) skip(s,len); return g->out; } else if (code <= avail) { if (first) return epuc("no clear code", "Corrupt GIF"); if (oldcode >= 0) { p = &g->codes[avail++]; if (avail > 4096) return epuc("too many codes", "Corrupt GIF"); p->prefix = (int16) oldcode; p->first = g->codes[oldcode].first; p->suffix = (code == avail) ? p->first : g->codes[code].first; } else if (code == avail) return epuc("illegal code in raster", "Corrupt GIF"); stbi_out_gif_code(g, (uint16) code); if ((avail & codemask) == 0 && avail <= 0x0FFF) { codesize++; codemask = (1 << codesize) - 1; } oldcode = code; } else { return epuc("illegal code in raster", "Corrupt GIF"); } } } } static void stbi_fill_gif_background(stbi_gif *g) { int i; uint8 *c = g->pal[g->bgindex]; // @OPTIMIZE: write a dword at a time for (i = 0; i < g->w * g->h * 4; i += 4) { uint8 *p = &g->out[i]; p[0] = c[2]; p[1] = c[1]; p[2] = c[0]; p[3] = c[3]; } } // this function is designed to support animated gifs, although stb_image doesn't support it static uint8 *stbi_gif_load_next(stbi *s, stbi_gif *g, int *comp, int req_comp) { int i; uint8 *old_out = 0; if (g->out == 0) { if (!stbi_gif_header(s, g, comp,0)) return 0; // failure_reason set by stbi_gif_header g->out = (uint8 *) malloc(4 * g->w * g->h); if (g->out == 0) return epuc("outofmem", "Out of memory"); stbi_fill_gif_background(g); } else { // animated-gif-only path if (((g->eflags & 0x1C) >> 2) == 3) { old_out = g->out; g->out = (uint8 *) malloc(4 * g->w * g->h); if (g->out == 0) return epuc("outofmem", "Out of memory"); memcpy(g->out, old_out, g->w*g->h*4); } } for (;;) { switch (get8(s)) { case 0x2C: /* Image Descriptor */ { int32 x, y, w, h; uint8 *o; x = get16le(s); y = get16le(s); w = get16le(s); h = get16le(s); if (((x + w) > (g->w)) || ((y + h) > (g->h))) return epuc("bad Image Descriptor", "Corrupt GIF"); g->line_size = g->w * 4; g->start_x = x * 4; g->start_y = y * g->line_size; g->max_x = g->start_x + w * 4; g->max_y = g->start_y + h * g->line_size; g->cur_x = g->start_x; g->cur_y = g->start_y; g->lflags = get8(s); if (g->lflags & 0x40) { g->step = 8 * g->line_size; // first interlaced spacing g->parse = 3; } else { g->step = g->line_size; g->parse = 0; } if (g->lflags & 0x80) { stbi_gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1); g->color_table = (uint8 *) g->lpal; } else if (g->flags & 0x80) { for (i=0; i < 256; ++i) // @OPTIMIZE: reset only the previous transparent g->pal[i][3] = 255; if (g->transparent >= 0 && (g->eflags & 0x01)) g->pal[g->transparent][3] = 0; g->color_table = (uint8 *) g->pal; } else return epuc("missing color table", "Corrupt GIF"); o = stbi_process_gif_raster(s, g); if (o == NULL) return NULL; if (req_comp && req_comp != 4) o = convert_format(o, 4, req_comp, g->w, g->h); return o; } case 0x21: // Comment Extension. { int len; if (get8(s) == 0xF9) { // Graphic Control Extension. len = get8(s); if (len == 4) { g->eflags = get8(s); get16le(s); // delay g->transparent = get8(s); } else { skip(s, len); break; } } while ((len = get8(s)) != 0) skip(s, len); break; } case 0x3B: // gif stream termination code return (uint8 *) 1; default: return epuc("unknown code", "Corrupt GIF"); } } } #ifndef STBI_NO_STDIO stbi_uc *stbi_gif_load (char const *filename, int *x, int *y, int *comp, int req_comp) { uint8 *data; FILE *f = fopen(filename, "rb"); if (!f) return NULL; data = stbi_gif_load_from_file(f, x,y,comp,req_comp); fclose(f); return data; } stbi_uc *stbi_gif_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp) { uint8 *u = 0; stbi s; stbi_gif g={0}; start_file(&s, f); u = stbi_gif_load_next(&s, &g, comp, req_comp); if (u == (void *) 1) u = 0; // end of animated gif marker if (u) { *x = g.w; *y = g.h; } return u; } #endif stbi_uc *stbi_gif_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { uint8 *u = 0; stbi s; stbi_gif g={0}; start_mem(&s, buffer, len); u = stbi_gif_load_next(&s, &g, comp, req_comp); if (u == (void *) 1) u = 0; // end of animated gif marker if (u) { *x = g.w; *y = g.h; } return u; } #ifndef STBI_NO_STDIO int stbi_gif_info (char const *filename, int *x, int *y, int *comp) { int res; FILE *f = fopen(filename, "rb"); if (!f) return 0; res = stbi_gif_info_from_file(f, x, y, comp); fclose(f); return res; } int stbi_gif_info_from_file(FILE *f, int *x, int *y, int *comp) { stbi s; int res; long n = ftell(f); start_file(&s, f); res = stbi_gif_info_raw(&s, x, y, comp); fseek(f, n, SEEK_SET); return res; } #endif // !STBI_NO_STDIO int stbi_gif_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) { stbi s; start_mem(&s, buffer, len); return stbi_gif_info_raw(&s, x, y, comp); } // ************************************************************************************************* // Radiance RGBE HDR loader // originally by Nicolas Schulz #ifndef STBI_NO_HDR static int hdr_test(stbi *s) { const char *signature = "#?RADIANCE\n"; int i; for (i=0; signature[i]; ++i) if (get8(s) != signature[i]) return 0; return 1; } int stbi_hdr_test_memory(stbi_uc const *buffer, int len) { stbi s; start_mem(&s, buffer, len); return hdr_test(&s); } #ifndef STBI_NO_STDIO int stbi_hdr_test_file(FILE *f) { stbi s; int r,n = ftell(f); start_file(&s, f); r = hdr_test(&s); fseek(f,n,SEEK_SET); return r; } #endif #define HDR_BUFLEN 1024 static char *hdr_gettoken(stbi *z, char *buffer) { int len=0; char c = '\0'; c = (char) get8(z); while (!at_eof(z) && c != '\n') { buffer[len++] = c; if (len == HDR_BUFLEN-1) { // flush to end of line while (!at_eof(z) && get8(z) != '\n') ; break; } c = (char) get8(z); } buffer[len] = 0; return buffer; } static void hdr_convert(float *output, stbi_uc *input, int req_comp) { if ( input[3] != 0 ) { float f1; // Exponent f1 = (float) ldexp(1.0f, input[3] - (int)(128 + 8)); if (req_comp <= 2) output[0] = (input[0] + input[1] + input[2]) * f1 / 3; else { output[0] = input[0] * f1; output[1] = input[1] * f1; output[2] = input[2] * f1; } if (req_comp == 2) output[1] = 1; if (req_comp == 4) output[3] = 1; } else { switch (req_comp) { case 4: output[3] = 1; /* fallthrough */ case 3: output[0] = output[1] = output[2] = 0; break; case 2: output[1] = 1; /* fallthrough */ case 1: output[0] = 0; break; } } } static float *hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp) { char buffer[HDR_BUFLEN]; char *token; int valid = 0; int width, height; stbi_uc *scanline; float *hdr_data; int len; unsigned char count, value; int i, j, k, c1,c2, z; // Check identifier if (strcmp(hdr_gettoken(s,buffer), "#?RADIANCE") != 0) return epf("not HDR", "Corrupt HDR image"); // Parse header for(;;) { token = hdr_gettoken(s,buffer); if (token[0] == 0) break; if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; } if (!valid) return epf("unsupported format", "Unsupported HDR format"); // Parse width and height // can't use sscanf() if we're not using stdio! token = hdr_gettoken(s,buffer); if (strncmp(token, "-Y ", 3)) return epf("unsupported data layout", "Unsupported HDR format"); token += 3; height = strtol(token, &token, 10); while (*token == ' ') ++token; if (strncmp(token, "+X ", 3)) return epf("unsupported data layout", "Unsupported HDR format"); token += 3; width = strtol(token, NULL, 10); *x = width; *y = height; *comp = 3; if (req_comp == 0) req_comp = 3; // Read data hdr_data = (float *) malloc(height * width * req_comp * sizeof(float)); // Load image data // image data is stored as some number of sca if ( width < 8 || width >= 32768) { // Read flat data for (j=0; j < height; ++j) { for (i=0; i < width; ++i) { stbi_uc rgbe[4]; main_decode_loop: getn(s, rgbe, 4); hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp); } } } else { // Read RLE-encoded data scanline = NULL; for (j = 0; j < height; ++j) { c1 = get8(s); c2 = get8(s); len = get8(s); if (c1 != 2 || c2 != 2 || (len & 0x80)) { // not run-length encoded, so we have to actually use THIS data as a decoded // pixel (note this can't be a valid pixel--one of RGB must be >= 128) uint8 rgbe[4]; rgbe[0] = (uint8) c1; rgbe[1] = (uint8) c2; rgbe[2] = (uint8) len; rgbe[3] = (uint8) get8u(s); hdr_convert(hdr_data, rgbe, req_comp); i = 1; j = 0; free(scanline); goto main_decode_loop; // yes, this makes no sense } len <<= 8; len |= get8(s); if (len != width) { free(hdr_data); free(scanline); return epf("invalid decoded scanline length", "corrupt HDR"); } if (scanline == NULL) scanline = (stbi_uc *) malloc(width * 4); for (k = 0; k < 4; ++k) { i = 0; while (i < width) { count = get8u(s); if (count > 128) { // Run value = get8u(s); count -= 128; for (z = 0; z < count; ++z) scanline[i++ * 4 + k] = value; } else { // Dump for (z = 0; z < count; ++z) scanline[i++ * 4 + k] = get8u(s); } } } for (i=0; i < width; ++i) hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp); } free(scanline); } return hdr_data; } #ifndef STBI_NO_STDIO float *stbi_hdr_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { stbi s; start_file(&s,f); return hdr_load(&s,x,y,comp,req_comp); } #endif float *stbi_hdr_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) { stbi s; start_mem(&s,buffer, len); return hdr_load(&s,x,y,comp,req_comp); } #endif // STBI_NO_HDR #ifndef STBI_NO_STDIO int stbi_info(char const *filename, int *x, int *y, int *comp) { FILE *f = fopen(filename, "rb"); int result; if (!f) return e("can't fopen", "Unable to open file"); result = stbi_info_from_file(f, x, y, comp); fclose(f); return result; } int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) { if (stbi_jpeg_info_from_file(f, x, y, comp)) return 1; if (stbi_png_info_from_file(f, x, y, comp)) return 1; if (stbi_gif_info_from_file(f, x, y, comp)) return 1; // @TODO: stbi_bmp_info_from_file // @TODO: stbi_psd_info_from_file #ifndef STBI_NO_HDR // @TODO: stbi_hdr_info_from_file #endif // test tga last because it's a crappy test! if (stbi_tga_info_from_file(f, x, y, comp)) return 1; return e("unknown image type", "Image not of any known type, or corrupt"); } #endif // !STBI_NO_STDIO int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) { if (stbi_jpeg_info_from_memory(buffer, len, x, y, comp)) return 1; if (stbi_png_info_from_memory(buffer, len, x, y, comp)) return 1; if (stbi_gif_info_from_memory(buffer, len, x, y, comp)) return 1; // @TODO: stbi_bmp_info_from_memory // @TODO: stbi_psd_info_from_memory #ifndef STBI_NO_HDR // @TODO: stbi_hdr_info_from_memory #endif // test tga last because it's a crappy test! if (stbi_tga_info_from_memory(buffer, len, x, y, comp)) return 1; return e("unknown image type", "Image not of any known type, or corrupt"); } #endif // STBI_HEADER_FILE_ONLY /* revision history: 1.29 (2010-08-16) various warning fixes from Aurelien Pocheville 1.28 (2010-08-01) fix bug in GIF palette transparency (SpartanJ) 1.27 (2010-08-01) cast-to-uint8 to fix warnings 1.26 (2010-07-24) fix bug in file buffering for PNG reported by SpartanJ 1.25 (2010-07-17) refix trans_data warning (Won Chun) 1.24 (2010-07-12) perf improvements reading from files on platforms with lock-heavy fgetc() minor perf improvements for jpeg deprecated type-specific functions so we'll get feedback if they're needed attempt to fix trans_data warning (Won Chun) 1.23 fixed bug in iPhone support 1.22 (2010-07-10) removed image *writing* support removed image *writing* support stbi_info support from Jetro Lauha GIF support from Jean-Marc Lienher iPhone PNG-extensions from James Brown warning-fixes from Nicolas Schulz and Janez Zemva (i.e. Janez (U+017D)emva) 1.21 fix use of 'uint8' in header (reported by jon blow) 1.20 added support for Softimage PIC, by Tom Seddon 1.19 bug in interlaced PNG corruption check (found by ryg) 1.18 2008-08-02 fix a threading bug (local mutable static) 1.17 support interlaced PNG 1.16 major bugfix - convert_format converted one too many pixels 1.15 initialize some fields for thread safety 1.14 fix threadsafe conversion bug header-file-only version (#define STBI_HEADER_FILE_ONLY before including) 1.13 threadsafe 1.12 const qualifiers in the API 1.11 Support installable IDCT, colorspace conversion routines 1.10 Fixes for 64-bit (don't use "unsigned long") optimized upsampling by Fabian "ryg" Giesen 1.09 Fix format-conversion for PSD code (bad global variables!) 1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz 1.07 attempt to fix C++ warning/errors again 1.06 attempt to fix C++ warning/errors again 1.05 fix TGA loading to return correct *comp and use good luminance calc 1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free 1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR 1.02 support for (subset of) HDR files, float interface for preferred access to them 1.01 fix bug: possible bug in handling right-side up bmps... not sure fix bug: the stbi_bmp_load() and stbi_tga_load() functions didn't work at all 1.00 interface to zlib that skips zlib header 0.99 correct handling of alpha in palette 0.98 TGA loader by lonesock; dynamically add loaders (untested) 0.97 jpeg errors on too large a file; also catch another malloc failure 0.96 fix detection of invalid v value - particleman@mollyrocket forum 0.95 during header scan, seek to markers in case of padding 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same 0.93 handle jpegtran output; verbose errors 0.92 read 4,8,16,24,32-bit BMP files of several formats 0.91 output 24-bit Windows 3.0 BMP files 0.90 fix a few more warnings; bump version number to approach 1.0 0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd 0.60 fix compiling as c++ 0.59 fix warnings: merge Dave Moore's -Wall fixes 0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian 0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less than 16 available 0.56 fix bug: zlib uncompressed mode len vs. nlen 0.55 fix bug: restart_interval not initialized to 0 0.54 allow NULL for 'int *comp' 0.53 fix bug in png 3->4; speedup png decoding 0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments 0.51 obey req_comp requests, 1-component jpegs return as 1-component, on 'test' only check type, not whether we support this variant */
the_stack_data/33331.c
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> #include <sys/stat.h> int main(int argc, char const *argv[]) { int pid; pid = fork(); if (pid == 0) { pid = fork(); if (pid == 0) { printf("I am the daemon!\n"); fclose(stdin); fclose(stdout); fclose(stderr); umask(0); chdir("/tmp"); while (1) { } } wait(NULL); } return 0; }
the_stack_data/14477.c
#include <stdio.h> #include <time.h> #include <stdlib.h> /*int main(void) { //srand(time(NULL)); //난수 초기화 //int num = rand() % 3 +1; //1~3 printf("난수 초기화 이전\n"); for(int i=0; i<10;i++){ printf("%d ",rand()%10); } srand(time(NULL)); printf("\n\n난수 초기화 이후\n"); for(int i=0; i<10;i++){ printf("%d ",rand()%10); } printf("\n"); return 0; }*/ /*int main(void) { srand(time(NULL)); int i = rand()%3; switch(i) { case 0:printf("가위\n"); break; case 1:printf("바위\n"); break; case 2:printf("보\n"); break; default:printf("몰라요\n"); break; } }*/
the_stack_data/3874.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #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; 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;} #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)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #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) = conj(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) (cimag(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; } 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; } 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; } 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; _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; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _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; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _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; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c__1 = 1; /* > \brief <b> CHPEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for OTHER m atrices</b> */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download CHPEV + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chpev.f "> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chpev.f "> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chpev.f "> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE CHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK, */ /* INFO ) */ /* CHARACTER JOBZ, UPLO */ /* INTEGER INFO, LDZ, N */ /* REAL RWORK( * ), W( * ) */ /* COMPLEX AP( * ), WORK( * ), Z( LDZ, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > CHPEV computes all the eigenvalues and, optionally, eigenvectors of a */ /* > complex Hermitian matrix in packed storage. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] JOBZ */ /* > \verbatim */ /* > JOBZ is CHARACTER*1 */ /* > = 'N': Compute eigenvalues only; */ /* > = 'V': Compute eigenvalues and eigenvectors. */ /* > \endverbatim */ /* > */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': Upper triangle of A is stored; */ /* > = 'L': Lower triangle of A is stored. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] AP */ /* > \verbatim */ /* > AP is COMPLEX array, dimension (N*(N+1)/2) */ /* > On entry, the upper or lower triangle of the Hermitian matrix */ /* > A, packed columnwise in a linear array. The j-th column of A */ /* > is stored in the array AP as follows: */ /* > if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* > if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ /* > */ /* > On exit, AP is overwritten by values generated during the */ /* > reduction to tridiagonal form. If UPLO = 'U', the diagonal */ /* > and first superdiagonal of the tridiagonal matrix T overwrite */ /* > the corresponding elements of A, and if UPLO = 'L', the */ /* > diagonal and first subdiagonal of T overwrite the */ /* > corresponding elements of A. */ /* > \endverbatim */ /* > */ /* > \param[out] W */ /* > \verbatim */ /* > W is REAL array, dimension (N) */ /* > If INFO = 0, the eigenvalues in ascending order. */ /* > \endverbatim */ /* > */ /* > \param[out] Z */ /* > \verbatim */ /* > Z is COMPLEX array, dimension (LDZ, N) */ /* > If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ /* > eigenvectors of the matrix A, with the i-th column of Z */ /* > holding the eigenvector associated with W(i). */ /* > If JOBZ = 'N', then Z is not referenced. */ /* > \endverbatim */ /* > */ /* > \param[in] LDZ */ /* > \verbatim */ /* > LDZ is INTEGER */ /* > The leading dimension of the array Z. LDZ >= 1, and if */ /* > JOBZ = 'V', LDZ >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is COMPLEX array, dimension (f2cmax(1, 2*N-1)) */ /* > \endverbatim */ /* > */ /* > \param[out] RWORK */ /* > \verbatim */ /* > RWORK is REAL array, dimension (f2cmax(1, 3*N-2)) */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit. */ /* > < 0: if INFO = -i, the i-th argument had an illegal value. */ /* > > 0: if INFO = i, the algorithm failed to converge; i */ /* > off-diagonal elements of an intermediate tridiagonal */ /* > form did not converge to zero. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complexOTHEReigen */ /* ===================================================================== */ /* Subroutine */ int chpev_(char *jobz, char *uplo, integer *n, complex *ap, real *w, complex *z__, integer *ldz, complex *work, real *rwork, integer *info) { /* System generated locals */ integer z_dim1, z_offset, i__1; real r__1; /* Local variables */ integer inde; real anrm; integer imax; real rmin, rmax, sigma; extern logical lsame_(char *, char *); integer iinfo; extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); logical wantz; integer iscale; extern real clanhp_(char *, char *, integer *, complex *, real *), slamch_(char *); extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer *); real safmin; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); real bignum; integer indtau; extern /* Subroutine */ int chptrd_(char *, integer *, complex *, real *, real *, complex *, integer *); integer indrwk, indwrk; extern /* Subroutine */ int csteqr_(char *, integer *, real *, real *, complex *, integer *, real *, integer *), cupgtr_(char *, integer *, complex *, complex *, complex *, integer *, complex *, integer *), ssterf_(integer *, real *, real *, integer *); real smlnum, eps; /* -- LAPACK driver 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..-- */ /* December 2016 */ /* ===================================================================== */ /* Test the input parameters. */ /* Parameter adjustments */ --ap; --w; z_dim1 = *ldz; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; --work; --rwork; /* Function Body */ wantz = lsame_(jobz, "V"); *info = 0; if (! (wantz || lsame_(jobz, "N"))) { *info = -1; } else if (! (lsame_(uplo, "L") || lsame_(uplo, "U"))) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*ldz < 1 || wantz && *ldz < *n) { *info = -7; } if (*info != 0) { i__1 = -(*info); xerbla_("CHPEV ", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } if (*n == 1) { w[1] = ap[1].r; rwork[1] = 1.f; if (wantz) { i__1 = z_dim1 + 1; z__[i__1].r = 1.f, z__[i__1].i = 0.f; } return 0; } /* Get machine constants. */ safmin = slamch_("Safe minimum"); eps = slamch_("Precision"); smlnum = safmin / eps; bignum = 1.f / smlnum; rmin = sqrt(smlnum); rmax = sqrt(bignum); /* Scale matrix to allowable range, if necessary. */ anrm = clanhp_("M", uplo, n, &ap[1], &rwork[1]); iscale = 0; if (anrm > 0.f && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { i__1 = *n * (*n + 1) / 2; csscal_(&i__1, &sigma, &ap[1], &c__1); } /* Call CHPTRD to reduce Hermitian packed matrix to tridiagonal form. */ inde = 1; indtau = 1; chptrd_(uplo, n, &ap[1], &w[1], &rwork[inde], &work[indtau], &iinfo); /* For eigenvalues only, call SSTERF. For eigenvectors, first call */ /* CUPGTR to generate the orthogonal matrix, then call CSTEQR. */ if (! wantz) { ssterf_(n, &w[1], &rwork[inde], info); } else { indwrk = indtau + *n; cupgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, &work[ indwrk], &iinfo); indrwk = inde + *n; csteqr_(jobz, n, &w[1], &rwork[inde], &z__[z_offset], ldz, &rwork[ indrwk], info); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ if (iscale == 1) { if (*info == 0) { imax = *n; } else { imax = *info - 1; } r__1 = 1.f / sigma; sscal_(&imax, &r__1, &w[1], &c__1); } return 0; /* End of CHPEV */ } /* chpev_ */
the_stack_data/192330428.c
#include <stdio.h> #include <stdlib.h> #include <string.h> char* getenv(const char* name); int main(int args, char* argv[]){ printf("Set-Cookie: fredrik=roos\n"); printf("Content-Type: text/html\r\n\r\n"); printf("<h2>Hello from C CGI - where the rubber hits the road</h2>"); return 0; }
the_stack_data/452717.c
#include <stdio.h> int main () { FILE* fp; size_t n; char buf[200]; fp = fopen ("file.txt", "rb"); n = fread (buf,8, 50, fp); if (n == -1) printf("fread failed"); fclose (fp); return 0; }
the_stack_data/808292.c
#ifdef STM32F0xx #include "stm32f0xx_hal.c" #endif #ifdef STM32F1xx #include "stm32f1xx_hal.c" #endif #ifdef STM32F2xx #include "stm32f2xx_hal.c" #endif #ifdef STM32F3xx #include "stm32f3xx_hal.c" #endif #ifdef STM32F4xx #include "stm32f4xx_hal.c" #endif #ifdef STM32F7xx #include "stm32f7xx_hal.c" #endif #ifdef STM32L0xx #include "stm32l0xx_hal.c" #endif #ifdef STM32L1xx #include "stm32l1xx_hal.c" #endif #ifdef STM32L4xx #include "stm32l4xx_hal.c" #endif
the_stack_data/51701378.c
/***************************************************************** * samplec.c version 1.0 sun/unix, 5-8-86 ***************************************************************** * Contains sample code for external routines defined in C. The * file "starlink.c" is initialized to link these three * routines into the STAR environment as external functions * under the class "c_function". *****************************************************************/ typedef int unit; unit reverse(lis1) unit lis1; /************************************************************ * See Example 33, STAR Tutorial Guide. ************************************************************/ { extern int get_list_size(); extern unit get_list_element(); extern unit make_list(); extern unit insert_list_at_head(); extern unit insert_list_at_tail(); unit result; result = make_list(); if(get_unit_type(lis1) != 4) return(result); if(get_list_size(lis1) != 2) return(result); result = insert_list_at_head( result, get_list_element(lis1,2) ); result = insert_list_at_tail( result, get_list_element(lis1,1) ); return(result); } float array_1[10] = {10.1,20.1,30.1,40.1,50.1,60.1,70.1,80.1,90.1,100.1}; /************************************************************ * Global definition for the array used by "return_array_1". ************************************************************/ unit return_array_1() /************************************************************ * Forms a CONNECTION to "array_1" and returns this to STAR. ************************************************************/ { extern float array_1[10]; extern unit make_connection(); return(make_connection(array_1,"ARRAY_@")); } unit subscript_array(con1,num1) unit con1,num1; /************************************************************ * Given a CONNECTION to a C array of real values (for * example, the CONNECTION returned by "return_array_1"), * extracts the "num1"'th element and returns as a STAR * NUMBER. ************************************************************/ { extern int get_connection_contents(); extern double get_number(); extern unit make_number(); float *array; array = (float *) get_connection_contents(con1); return(make_number(array[((int) get_number(num1)) - 1])); }
the_stack_data/92327426.c
/* * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ int arith_divide_by_zero() { int x = 0; int y = 5; return y / x; }
the_stack_data/125444.c
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { float z; int y,x; printf("Digite o numero de dias trabalhados:"); scanf("%d \n",&x); y = x*30; z =y*8/100; printf("O salario em valores liquidos e: %f",z); return 0; }
the_stack_data/37638124.c
/* * Copyright (c) 2015, Freescale Semiconductor, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, this list * of conditions and the following disclaimer. * * o 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. * * o Neither the name of Freescale Semiconductor, 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. */ #include <stdint.h> #include <stdlib.h> #include <stdio.h> /*! * @addtogroup qspi_driver * @{ */ //////////////////////////////////////////////////////////////////////////////// // Definitions //////////////////////////////////////////////////////////////////////////////// #define QSPI_LUT_MAX_ENTRIES 64 #define QSPI_PRE_CMD_CNT 4 //!< the max number of pre commands #define QSPI_FEATURE_ENABLE 1 #define QSPI_VERSION_NAME 'Q' //! @brief Build a 32-bit code from four character values. //! //! The resulting value is built with a byte order such that the string //! being readable in expected order when viewed in a hex editor, if the value //! is treated as a 32-bit little endian value. #define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a))) enum __qspi_config_block_tags { //! @brief Tag value used to validate the qspi config block. kQspiConfigTag = FOUR_CHAR_CODE('k', 'q', 'c', 'f'), kQspiVersionTag = FOUR_CHAR_CODE(0, 1, 1, 'Q'), }; //! @brief QSPI Flash mode options typedef enum _qspiflash_mode_option { kQspiFlashMode_Serial = 0, //!< Serial mode kQspiFlashMode_Parallel = 1 //!< Parallel mode } qspiflash_mode_option_t; //! @brief External spi flash pad definition typedef enum _qspiflash_pad { kQspiFlashPad_Single = 0, //!< Single-pad spi flash kQspiFlashPad_Dual = 1, //!< Dual-pad spi flash kQspiFlashPad_Quad = 2, //!< Quad-pad spi flash kQspiFlashPad_Octal = 3 //!< Octal-pad spi flash } qspiflash_pad_t; //! @brief QSPI Serial Clock Frequency options typedef enum _qspi_serial_clock_freq { kQspiSerialClockFreq_Low = 0, //!< QuadSPI module works at low frequency kQspiSerialClockFreq_Mid = 1, //!< QuadSPI module works at mid frequency kQspiSerialClockFreq_High = 2 //!< QuadSPI module works at high frequency } qspi_serial_clock_freq_t; //! @brief Port Enablement Option typedef enum _qspi_port_enable { kQspiPort_EnablePortA = 0U, //!< Only PORTA is enabled kQspiPort_EnableBothPorts = 1, //!< Enable Both PoartA and PortB } qspi_port_enable_t; //! @brief Definition for AHB data tranfer size typedef enum _qspi_ahb_data_transfer_size { kQspiAHBDataTransferSize_64Bytes = 8U, //!< AHB data transfer size is 64bytes kQspiAHBDataTransferSize_256Bytes = 32U, //!< AHB data transfer size is 256bytes } qspi_ahb_data_transfer_size_t; typedef union BootloaderVersion { struct { uint32_t bugfix : 8; //!< bugfix version [7:0] uint32_t minor : 8; //!< minor version [15:8] uint32_t major : 8; //!< major version [23:16] uint32_t name : 8; //!< name [31:24] } B; uint32_t version; //!< combined version numbers } standard_version_t; //! @brief QuadSPI Config block structure #pragma pack(1) typedef struct __sflash_configuration_parameter { uint32_t tag; //!< Set to magic number of 'kqcf' standard_version_t version; //!< version of config struct uint32_t lengthInBytes; //!< Total length of strcut in bytes uint32_t dqs_loopback; //!< Sets DQS LoopBack Mode to enable Dummy Pad MCR[24] uint32_t data_hold_time; //!< Serial Flash data hold time, valid value: 0/1/2 uint32_t reserved0[2]; //!< Reserved for K80 uint32_t device_mode_config_en; //!< Determine if it is required to config working mode of external spi flash. uint32_t device_cmd; //!< Command to be tranferred to device uint32_t write_cmd_ipcr; //!< IPCR value of Write command uint32_t word_addressable; //!< Determine if the serial flash is word addressable uint32_t cs_hold_time; //!< CS hold time in terms of serial clock.(for example 1 serial clock cyle) uint32_t cs_setup_time; //!< CS setup time in terms of serial clock.(for example 1 serial clock cyle) uint32_t sflash_A1_size; //!< Size of flash connected on QSPI0A Ports and QSPI0A_SS0, in terms of Bytes uint32_t sflash_A2_size; //!< Size of flash connected on QSPI0A Ports and QSPI0A_SS1, in terms of Bytes uint32_t sflash_B1_size; //!< Size of flash connected on QSPI0B Ports and QSPI0B_SS0, in terms of Bytes uint32_t sflash_B2_size; //!< Size of flash connected on QSPI0B Ports and QSPI0B_SS1, in terms of Bytes uint32_t sclk_freq; //!< In 00 - 24MHz, 01 - 48MHz, 10 - 96MHz,(only for SDR Mode) uint32_t busy_bit_offset; //!< Flash device busy bit offset in status register uint32_t sflash_type; //!< SPI flash type: 0-Single,1--Dual 2--Quad, 3-- Octal uint32_t sflash_port; //!< 0--Only Port-A, 1--Both PortA and PortB uint32_t ddr_mode_enable; //!< Enable DDR mode if set to TRUE uint32_t dqs_enable; //!< Enable DQS mode if set to TRUE. uint32_t parallel_mode_enable; //!< Enable Individual or parrallel mode. uint32_t portA_cs1; //!< Enable PORTA CS1 uint32_t portB_cs1; //!< Enable PORTB CS1 uint32_t fsphs; //!< Full speed delay selection for SDR instructions uint32_t fsdly; //!< Full speed phase selection for SDR instructions uint32_t ddrsmp; //!< Select the sampling point for incomming data when serial flash is in DDR mdoe uint32_t look_up_table[QSPI_LUT_MAX_ENTRIES]; //!< Set of seq to perform optimum read on SFLASH as as per vendor SFLASH uint32_t column_address_space; //!< The width of the column address uint32_t config_cmd_en; //!< Enable config commands uint32_t config_cmds[QSPI_PRE_CMD_CNT]; //!< Config comands, used to configure nor flash uint32_t config_cmds_args[QSPI_PRE_CMD_CNT]; //!< Config commands arguments uint32_t differential_clock_pin_enable; //!< Differential flash clock pins enable uint32_t flash_CK2_clock_pin_enable; //!< Flash CK2 clock pin enable uint32_t dqs_inverse_sel; //!< Select clock source for internal DQS generation uint32_t dqs_latency_enable; //!< DQS Latency Enable uint32_t dqs_loopback_internal; //!< 0: dqs loopback from pad, 1: dqs loopback internally uint32_t dqs_phase_sel; //!< dqs phase sel uint32_t dqs_fa_delay_chain_sel; //!< dqs fa delay chain selection uint32_t dqs_fb_delay_chain_sel; //!< dqs fb delay chain selection uint32_t reserved1[2]; //!< reserved uint32_t pagesize; //!< page Size of Serial Flash uint32_t sectorsize; //!< sector Size of Serial Flash uint32_t timeout_milliseconds; //!< timeout in terms of millisecond in case of infinite loop in qspi driver //!< 0 represents disabling timeout check. This value is valid since version 1.1.0 uint32_t ips_command_second_divider; //!< second devider for all IPS commands. uint32_t need_multi_phases; //!< Determine if multiple hases command are needed. uint32_t is_spansion_hyperflash; //!< Determine if connected spi flash device belongs to Hyperflash family uint32_t pre_read_status_cmd_address_offset; //!< Address for PreReadStatus command uint32_t pre_unlock_cmd_address_offset; //!< Address for PreWriteEnable command uint32_t unlock_cmd_address_offset; //!< Address for WriteEnable command uint32_t pre_program_cmd_address_offset; //!< Address for PreProgram command uint32_t pre_erase_cmd_address_offset; //!< Address for PreErase command uint32_t erase_all_cmd_address_offset; //!< Address for EraseAll command uint32_t reserved2[3]; //!< Reserved words to make sure qspi config block is page-aligend. } qspi_config_t, *SFLASH_CONFIGURATION_PARAM_PTR; #pragma pack() int main(void) { const qspi_config_t qspi_config_block = { .tag = kQspiConfigTag, // Fixed value, do not change .version = {.version = kQspiVersionTag }, // Fixed value, do not change .lengthInBytes = 512, // Fixed value, do not change .sflash_A1_size = 0x400000, // 4MB .sflash_B1_size = 0x400000, // 4MB .sclk_freq = kQspiSerialClockFreq_High, // High frequency, in K82-256, it means 96MHz/1 = 96MHz .sflash_type = kQspiFlashPad_Quad, // SPI Flash devices work under quad-pad mode .sflash_port = kQspiPort_EnableBothPorts, // Both QSPI0A and QSPI0B are enabled. .busy_bit_offset = 0, // Busy offset is 0 .ddr_mode_enable = 0, // disable DDR mode .dqs_enable = 0, // Disable DQS feature .parallel_mode_enable = 0, // QuadSPI module work under serial mode .pagesize = 256, // Page Size : 256 bytes .sectorsize = 0x1000, // Sector Size: 4KB .device_mode_config_en = 1, // Enable quad mode for SPI flash .device_cmd = 0x40, // Enable quad mode via set bit 6 in status register to 1 .write_cmd_ipcr = 0x05000000U, // IPCR indicating seq id for Quad Mode Enable (5<<24) .ips_command_second_divider = 3, // Set second divider for QSPI serial clock to 3 .look_up_table = { // Seq0 : Quad Read (maximum supported freq: 104MHz) /* CMD: 0xEB - Quad Read, Single pad ADDR: 0x18 - 24bit address, Quad pads DUMMY: 0x06 - 6 clock cycles, Quad pads READ: 0x80 - Read 128 bytes, Quad pads JUMP_ON_CS: 0 */ [0] = 0x0A1804EB, [1] = 0x1E800E06, [2] = 0x2400, // Seq1: Write Enable (maximum supported freq: 104MHz) /* CMD: 0x06 - Write Enable, Single pad */ [4] = 0x406, // Seq2: Erase All (maximum supported freq: 104MHz) /* CMD: 0x60 - Erase All chip, Single pad */ [8] = 0x460, // Seq3: Read Status (maximum supported freq: 104MHz) /* CMD: 0x05 - Read Status, single pad READ: 0x01 - Read 1 byte */ [12] = 0x1c010405, // Seq4: 4 I/O Page Program (maximum supported freq: 104MHz) /* CMD: 0x38 - 4 I/O Page Program, Single pad ADDR: 0x18 - 24bit address, Quad pad WRITE: 0x40 - Write 64 bytes at one pass, Quad pad */ [16] = 0x0A180438, [17] = 0x2240, // Seq5: Write status register to enable quad mode /* CMD: 0x01 - Write Status Register, single pad WRITE: 0x01 - Write 1 byte of data, single pad */ [20] = 0x20010401, // Seq7: Erase Sector /* CMD: 0x20 - Sector Erase, single pad ADDR: 0x18 - 24 bit address, single pad */ [28] = 0x08180420, // Seq8: Dummy /* CMD: 0 - Dummy command, used to force SPI flash to exit continuous read mode. unnecessary here because the continuous read mode is not enabled. */ [32] = 0, }, }; // Generate QSPI config block const char *filePath = "qspi_config_block.bin"; FILE *fp = fopen(filePath, "wb+"); if (fp == NULL) { printf("Cannot open/create %s\n", filePath); } else { size_t write_size = sizeof(qspi_config_block); size_t actual_write_size; actual_write_size = fwrite(&qspi_config_block, 1, write_size, fp); fclose(fp); if (actual_write_size == write_size) { printf("Generated %s successfully.\n\n", filePath); } else { printf("Failed to generate %s \n\n", filePath); } } system("pause"); return 0; }
the_stack_data/162643444.c
#include<stdio.h> #include<string.h> int main() { int i,T,j, len,count = 1; char word[100], r_word[100]; scanf("%d", &T); while(T--){ scanf("%s", word); len = strlen(word); for(i=0, j=len -1; i<len; i++, j--) { r_word[i] = word[j]; } r_word[i] = '\0'; if(0 == strcmp(word, r_word)) { printf("Case %d: Yes\n", count); count++; } else { printf("Case %d: No\n", count); count++; } } return 0; }
the_stack_data/102302.c
#include <stdio.h> #include <math.h> #include <stdbool.h> double snippet(double xx) { int j=0; double x = 0.0; double y= 0.0; double tmp= 0.0; double ser= 0; double cof[6]={76.18009172947146,-86.50532032941677, 24.01409824083091,-1.231739572450155,0.1208650973866179e-2, -0.5395239384953e-5}; x = xx; y = x; tmp=x+5.5; tmp -= (x+0.5)*log(tmp); ser=1.000000000190015; for (j=0;j<6;j++) ser += cof[j]/++y; return -tmp+log(2.5066282746310005*ser/x); }
the_stack_data/73574564.c
/* * Copyright (C) 2002-2005 Novell/SUSE * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2 of the * License. */ #include <stdio.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> int main(int argc, char *argv[]) { int retval; if (argc != 3){ fprintf(stderr, "usage: %s oldfile newfile\n", argv[0]); return 1; } retval=rename(argv[1], argv[2]); if (retval == -1){ fprintf(stderr, "FAIL: rename from %s to %s failed - %s\n", argv[1], argv[2], strerror(errno)); return errno; } printf("PASS\n"); return 0; }
the_stack_data/365616.c
#include<stdio.h> int main (void) { int number,result=0,scraped,decoy; printf("Enter a nunber: "); //Taking input from the user scanf("%d",&number); decoy = number; //Decoy value to perform calculations in the loop without disturbing the original number for (;decoy != 0; decoy/=10) //Loop cuts the last digit of the number every time and stops when the number becomes zero { scraped = decoy%10; //Cutting the last digit of the number and using it result = result*10 + scraped; //Creating a number in reverse order of the original number } if (number==result) //Checking the result if it matches the original input printf("It's a palindrome"); else printf("It's not a palindrome"); return 0; }
the_stack_data/37637132.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_swap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: anicusan <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/07/13 15:52:44 by anicusan #+# #+# */ /* Updated: 2016/07/13 15:53:32 by anicusan ### ########.fr */ /* */ /* ************************************************************************** */ void ft_swap(int *a, int *b) { int aux; aux = *a; *a = *b; *b = aux; }
the_stack_data/182953457.c
long long strlen(const char *s) { long long n = 0; while (s[n] != 0) n++; return n; }
the_stack_data/92328430.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <stdio.h> int shrfunc1 (int x) { return x + 4; /* unloadshr break */ }
the_stack_data/181392567.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2010-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ volatile int var; int return_1 (void) { return 1; } int main(void) { var++; var++; /* watchpoint-stop */ return 0; /* break-at-exit */ }
the_stack_data/225143926.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <stdint.h> #include <errno.h> #include <unistd.h> #include <stdbool.h> #include <assert.h> // TODO: consider using: getprogname() #define PROGRAM_NAME "cfd" #ifndef unlikely #define unlikely(x) __builtin_expect(!!(x), 0) #endif static void __attribute__((__noreturn__)) *xalloc_die(); static void __attribute__((__malloc__)) *xmalloc(size_t n); static void __attribute__((__malloc__)) *xrealloc(void *p, size_t n); static void *xalloc_die() { fflush(stdout); fprintf(stderr, "memory exhausted\n"); abort(); } static void *xmalloc(size_t n) { void *p = malloc(n); if (!p && n != 0) { xalloc_die(); } return p; } static void *xrealloc(void *p, size_t n) { if (!n && p) { free(p); return NULL; } p = realloc(p, n); if (!p && n) { xalloc_die(); } return p; } #ifndef powerof2 #define powerof2(x) ((((x)-1)&(x))==0) #endif #if !defined(SIZE_T_MAX) && !defined(SIZE_MAX) #error "missing SIZE_T_MAX and SIZE_MAX" #endif static inline size_t p2roundup(size_t n) { if (!powerof2(n)) { n--; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; #if SIZE_T_MAX > 0xffffffffU || SIZE_MAX > 0xffffffffU n |= n >> 32; #endif n++; } return (n); } #ifndef SSIZE_MAX #define SSIZE_MAX PTRDIFF_MAX #endif static inline int expand_buffer(char **buf, size_t *cap, size_t len) { if (unlikely(len > (size_t)SSIZE_MAX + 1)) { errno = EOVERFLOW; return -1; } if (unlikely(*cap <= len)) { // avoid overflow size_t newcap; if (len >= (size_t)SSIZE_MAX + 1) { newcap = (size_t)SSIZE_MAX + 1; } else { newcap = p2roundup(len + *cap); } char *newline = xrealloc(*buf, newcap); *cap = newcap; *buf = newline; } return 0; } static ssize_t trim_prefix(char **dst, size_t *dst_cap, const char *buf, const size_t buf_len) { if (unlikely(expand_buffer(dst, dst_cap, buf_len) != 0)) { return -1; } char *d = *dst; if (buf_len > 2) { if (memcmp(buf, "./", 2) == 0) { size_t n = buf_len - 2; memcpy(d, &buf[2], n); return n; } // TODO: remove and write ANSII prefix then use the // above logic to strip the prefix. if (memcmp(buf, "\x1b[", 2) == 0) { const char *p = memchr(buf, 'm', buf_len); if (p) { ssize_t i = p - buf; memcpy(d, buf, i + 1); memcpy(&d[i + 1], &buf[i + 2 + 1], buf_len - i - 2); return buf_len - 2;; } } } memcpy(d, buf, buf_len); return buf_len; } static int consume_stdin(const unsigned char delim) { size_t buf_cap = 256; size_t dst_cap = 256; char *buf = xmalloc(256); char *dst = xmalloc(256); ssize_t i; while ((i = getdelim(&buf, &buf_cap, delim, stdin)) != -1) { ssize_t n = trim_prefix(&dst, &dst_cap, buf, i); if (unlikely(n < 0)) { goto fatal_error; } if (unlikely((ssize_t)fwrite(dst, 1, n, stdout) < n)) { perror("fwrite"); goto fatal_error; } } if (ferror(stdin)) { if (errno != 0) { perror("getdelim"); } goto fatal_error; } free(buf); free(dst); fflush(stdout); return 0; fatal_error: fprintf(stderr, "fatal error"); return 1; } static void print_usage(bool print_error) { if (print_error) { fprintf(stderr, "Usage: %s [OPTION]...\n", PROGRAM_NAME); fprintf(stderr, "Try '%s --help' for more information.\n", PROGRAM_NAME); } else { printf("Usage: %s [OPTION]... [FILE]...\n", PROGRAM_NAME); fputs("\n\ Strip './' filename prefixes from the output of fd (fd-find).\n\ \n\ Options:\n\ -0, --print0 Line delimiter is NUL, not newline\n\ -h, --help Print this help message and exit.\n", stdout); } } int main(int argc, char const *argv[]) { bool null_terminate = false; bool invalid_flag = false; bool print_help = false; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-0") == 0 || strcmp(argv[i], "--print0") == 0) { if (null_terminate) { fprintf(stderr,"%s: null terminate flag ['-0', '--print0'] specified twice\n", PROGRAM_NAME); invalid_flag = true; } null_terminate = true; } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { print_help = true; break; } else { fprintf(stderr, "%s: unrecognized option: '%s'\n", PROGRAM_NAME, argv[i]); invalid_flag = true; } } if (invalid_flag) { print_usage(true); return 2; } if (print_help) { print_usage(false); return 0; } const unsigned char delim = null_terminate ? 0 : '\n'; return consume_stdin(delim); }
the_stack_data/54965.c
#include <stdio.h> int main(){ printf("hello world"); return 0; }
the_stack_data/112258.c
// WAP to solve given expression. // ans=a + b - (c*d) / f + g void main() { int a, b, c, d, f, g, ans; printf("Enter the value of a & b\n"); scanf("%d,%d", &a, &b); printf("\nEnter the value of c & d\n"); scanf("%d,%d", &c, &d); printf("\nEnter the value of f & g\n"); scanf("%d,%d", &f, &g); ans == a + b - (c*d) / f + g; printf("\n The answer to a + b - (c*d) / f + g = %d", ans); }
the_stack_data/45449571.c
int main(void) { int x = (int)'a' + (char)"abc"; return 0; }
the_stack_data/36076513.c
/* * Stack-less Just-In-Time compiler * * Copyright Zoltan Herczeg ([email protected]). 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. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) 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(S) 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. */ /* ------------------------------------------------------------------------ */ /* Locks */ /* ------------------------------------------------------------------------ */ #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) || (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) #if (defined SLJIT_SINGLE_THREADED && SLJIT_SINGLE_THREADED) #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) static SLJIT_INLINE void allocator_grab_lock(void) { /* Always successful. */ } static SLJIT_INLINE void allocator_release_lock(void) { /* Always successful. */ } #endif /* SLJIT_EXECUTABLE_ALLOCATOR */ #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_grab_lock(void) { /* Always successful. */ } SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_release_lock(void) { /* Always successful. */ } #endif /* SLJIT_UTIL_GLOBAL_LOCK */ #elif defined(_WIN32) /* SLJIT_SINGLE_THREADED */ #include "windows.h" #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) static HANDLE allocator_mutex = 0; static SLJIT_INLINE void allocator_grab_lock(void) { /* No idea what to do if an error occurs. Static mutexes should never fail... */ if (!allocator_mutex) allocator_mutex = CreateMutex(NULL, TRUE, NULL); else WaitForSingleObject(allocator_mutex, INFINITE); } static SLJIT_INLINE void allocator_release_lock(void) { ReleaseMutex(allocator_mutex); } #endif /* SLJIT_EXECUTABLE_ALLOCATOR */ #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) static HANDLE global_mutex = 0; SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_grab_lock(void) { /* No idea what to do if an error occurs. Static mutexes should never fail... */ if (!global_mutex) global_mutex = CreateMutex(NULL, TRUE, NULL); else WaitForSingleObject(global_mutex, INFINITE); } SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_release_lock(void) { ReleaseMutex(global_mutex); } #endif /* SLJIT_UTIL_GLOBAL_LOCK */ #else /* _WIN32 */ #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) #include <pthread.h> static pthread_mutex_t allocator_mutex = PTHREAD_MUTEX_INITIALIZER; static SLJIT_INLINE void allocator_grab_lock(void) { pthread_mutex_lock(&allocator_mutex); } static SLJIT_INLINE void allocator_release_lock(void) { pthread_mutex_unlock(&allocator_mutex); } #endif /* SLJIT_EXECUTABLE_ALLOCATOR */ #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) #include <pthread.h> static pthread_mutex_t global_mutex = PTHREAD_MUTEX_INITIALIZER; SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_grab_lock(void) { pthread_mutex_lock(&global_mutex); } SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_release_lock(void) { pthread_mutex_unlock(&global_mutex); } #endif /* SLJIT_UTIL_GLOBAL_LOCK */ #endif /* _WIN32 */ /* ------------------------------------------------------------------------ */ /* Stack */ /* ------------------------------------------------------------------------ */ #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) || (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) #ifdef _WIN32 #include "windows.h" #else /* Provides mmap function. */ #include <sys/mman.h> /* For detecting the page size. */ #include <unistd.h> #ifndef MAP_ANON #include <fcntl.h> /* Some old systems does not have MAP_ANON. */ static sljit_s32 dev_zero = -1; #if (defined SLJIT_SINGLE_THREADED && SLJIT_SINGLE_THREADED) static SLJIT_INLINE sljit_s32 open_dev_zero(void) { dev_zero = open("/dev/zero", O_RDWR); return dev_zero < 0; } #else /* SLJIT_SINGLE_THREADED */ #include <pthread.h> static pthread_mutex_t dev_zero_mutex = PTHREAD_MUTEX_INITIALIZER; static SLJIT_INLINE sljit_s32 open_dev_zero(void) { pthread_mutex_lock(&dev_zero_mutex); /* The dev_zero might be initialized by another thread during the waiting. */ if (dev_zero < 0) { dev_zero = open("/dev/zero", O_RDWR); } pthread_mutex_unlock(&dev_zero_mutex); return dev_zero < 0; } #endif /* SLJIT_SINGLE_THREADED */ #endif #endif #endif /* SLJIT_UTIL_STACK || SLJIT_EXECUTABLE_ALLOCATOR */ #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) /* Planning to make it even more clever in the future. */ static sljit_sw sljit_page_align = 0; SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_FUNC sljit_allocate_stack(sljit_uw start_size, sljit_uw max_size, void *allocator_data) { struct sljit_stack *stack; void *ptr; #ifdef _WIN32 SYSTEM_INFO si; #endif SLJIT_UNUSED_ARG(allocator_data); if (start_size > max_size || start_size < 1) return NULL; #ifdef _WIN32 if (!sljit_page_align) { GetSystemInfo(&si); sljit_page_align = si.dwPageSize - 1; } #else if (!sljit_page_align) { sljit_page_align = sysconf(_SC_PAGESIZE); /* Should never happen. */ if (sljit_page_align < 0) sljit_page_align = 4096; sljit_page_align--; } #endif stack = (struct sljit_stack*)SLJIT_MALLOC(sizeof(struct sljit_stack), allocator_data); if (!stack) return NULL; /* Align max_size. */ max_size = (max_size + sljit_page_align) & ~sljit_page_align; #ifdef _WIN32 ptr = VirtualAlloc(NULL, max_size, MEM_RESERVE, PAGE_READWRITE); if (!ptr) { SLJIT_FREE(stack, allocator_data); return NULL; } stack->min_start = (sljit_u8 *)ptr; stack->end = stack->min_start + max_size; stack->start = stack->end; if (sljit_stack_resize(stack, stack->end - start_size) == NULL) { sljit_free_stack(stack, allocator_data); return NULL; } #else #ifdef MAP_ANON ptr = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); #else if (dev_zero < 0) { if (open_dev_zero()) { SLJIT_FREE(stack, allocator_data); return NULL; } } ptr = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero, 0); #endif if (ptr == MAP_FAILED) { SLJIT_FREE(stack, allocator_data); return NULL; } stack->min_start = (sljit_u8 *)ptr; stack->end = stack->min_start + max_size; stack->start = stack->end - start_size; #endif stack->top = stack->end; return stack; } #undef PAGE_ALIGN SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_free_stack(struct sljit_stack *stack, void *allocator_data) { SLJIT_UNUSED_ARG(allocator_data); #ifdef _WIN32 VirtualFree((void*)stack->min_start, 0, MEM_RELEASE); #else munmap((void*)stack->min_start, stack->end - stack->min_start); #endif SLJIT_FREE(stack, allocator_data); } SLJIT_API_FUNC_ATTRIBUTE sljit_u8 *SLJIT_FUNC sljit_stack_resize(struct sljit_stack *stack, sljit_u8 *new_start) { sljit_uw aligned_old_start; sljit_uw aligned_new_start; if ((new_start < stack->min_start) || (new_start >= stack->end)) return NULL; #ifdef _WIN32 aligned_new_start = (sljit_uw)new_start & ~sljit_page_align; aligned_old_start = ((sljit_uw)stack->start) & ~sljit_page_align; if (aligned_new_start != aligned_old_start) { if (aligned_new_start < aligned_old_start) { if (!VirtualAlloc((void*)aligned_new_start, aligned_old_start - aligned_new_start, MEM_COMMIT, PAGE_READWRITE)) return NULL; } else { if (!VirtualFree((void*)aligned_old_start, aligned_new_start - aligned_old_start, MEM_DECOMMIT)) return NULL; } } #else if (stack->start < new_start) { aligned_new_start = (sljit_uw)new_start & ~sljit_page_align; aligned_old_start = ((sljit_uw)stack->start) & ~sljit_page_align; /* If madvise is available, we release the unnecessary space. */ #if defined(MADV_DONTNEED) if (aligned_new_start > aligned_old_start) madvise((void*)aligned_old_start, aligned_new_start - aligned_old_start, MADV_DONTNEED); #elif defined(POSIX_MADV_DONTNEED) if (aligned_new_start > aligned_old_start) posix_madvise((void*)aligned_old_start, aligned_new_start - aligned_old_start, POSIX_MADV_DONTNEED); #endif } #endif stack->start = new_start; return new_start; } #endif /* SLJIT_UTIL_STACK */ #endif
the_stack_data/200142641.c
#include <stdio.h> void scilab_rt_contour_i2i2d2d0d0d0s0i2_(int in00, int in01, int matrixin0[in00][in01], int in10, int in11, int matrixin1[in10][in11], int in20, int in21, double matrixin2[in20][in21], double scalarin0, double scalarin1, double scalarin2, char* scalarin3, int in30, int in31, int matrixin3[in30][in31]) { int i; int j; int val0 = 0; int val1 = 0; double val2 = 0; int val3 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { val0 += matrixin0[i][j]; } } printf("%d", val0); for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%d", val1); for (i = 0; i < in20; ++i) { for (j = 0; j < in21; ++j) { val2 += matrixin2[i][j]; } } printf("%f", val2); printf("%f", scalarin0); printf("%f", scalarin1); printf("%f", scalarin2); printf("%s", scalarin3); for (i = 0; i < in30; ++i) { for (j = 0; j < in31; ++j) { val3 += matrixin3[i][j]; } } printf("%d", val3); }
the_stack_data/1224026.c
#include <stdio.h> int main(void) { float dist, speed; int num; printf("Enter number of drive time computation: "); scanf("%d", &num); while (num) { printf("\nEnter distance: "); scanf("%f", &dist); printf("Enter average speed: "); scanf("%f", &speed); printf("Drive time is %f\n", dist/speed); } return 0; }
the_stack_data/134696.c
// Program 58: Program to find the length of each string in a 2-dimensional array #include <stdio.h> #include <strings.h> int main() { int i,x,y,a,b,ans; printf("Enter the number of columns"); scanf("%d", &x); printf("Enter the number of rows"); scanf("%d", &y); // Initialise 2d Array int arr[x][y]; for (a=0; a<x; a++) { for (b=0; b<y; b++) { scanf("%d",& arr[a][b]); } } for (int i = 0; i < a; ++i) { ans = strlen(*(arr+i)); printff("%d", &ans); } return 0; }
the_stack_data/353382.c
/* * PowerPC signal handling routines * * Copyright 2002 Marcus Meissner, SuSE Linux AG * * This 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. * * This 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 this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef __powerpc__ #include "config.h" #include "wine/port.h" #include <assert.h> #include <signal.h> #include <stdlib.h> #include <stdarg.h> #include <stdio.h> #include <sys/types.h> #ifdef HAVE_UNISTD_H # include <unistd.h> #endif #ifdef HAVE_SYS_PARAM_H # include <sys/param.h> #endif #ifdef HAVE_SYSCALL_H # include <syscall.h> #else # ifdef HAVE_SYS_SYSCALL_H # include <sys/syscall.h> # endif #endif #ifdef HAVE_SYS_SIGNAL_H # include <sys/signal.h> #endif #ifdef HAVE_SYS_UCONTEXT_H # include <sys/ucontext.h> #endif #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" #include "winternl.h" #include "wine/library.h" #include "wine/exception.h" #include "ntdll_misc.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(seh); static pthread_key_t teb_key; /*********************************************************************** * signal context platform-specific definitions */ #ifdef linux /* All Registers access - only for local access */ # define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name) /* Gpr Registers access */ # define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context) # define IAR_sig(context) REG_sig(nip, context) /* Program counter */ # define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */ # define CTR_sig(context) REG_sig(ctr, context) /* Count register */ # define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */ # define LR_sig(context) REG_sig(link, context) /* Link register */ # define CR_sig(context) REG_sig(ccr, context) /* Condition register */ /* Float Registers access */ # define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num]) # define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4))) /* Exception Registers access */ # define DAR_sig(context) REG_sig(dar, context) # define DSISR_sig(context) REG_sig(dsisr, context) # define TRAP_sig(context) REG_sig(trap, context) #endif /* linux */ #ifdef __APPLE__ /* All Registers access - only for local access */ # define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name) # define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name) # define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name) # define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name) /* Gpr Registers access */ # define GPR_sig(reg_num, context) REG_sig(r##reg_num, context) # define IAR_sig(context) REG_sig(srr0, context) /* Program counter */ # define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */ # define CTR_sig(context) REG_sig(ctr, context) # define XER_sig(context) REG_sig(xer, context) /* Link register */ # define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */ # define CR_sig(context) REG_sig(cr, context) /* Condition register */ /* Float Registers access */ # define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context) # define FPSCR_sig(context) FLOATREG_sig(fpscr, context) /* Exception Registers access */ # define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */ # define DSISR_sig(context) EXCEPREG_sig(dsisr, context) # define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */ /* Signal defs : Those are undefined on darwin SIGBUS #undef BUS_ADRERR #undef BUS_OBJERR SIGILL #undef ILL_ILLOPN #undef ILL_ILLTRP #undef ILL_ILLADR #undef ILL_COPROC #undef ILL_PRVREG #undef ILL_BADSTK SIGTRAP #undef TRAP_BRKPT #undef TRAP_TRACE SIGFPE */ #endif /* __APPLE__ */ typedef int (*wine_signal_handler)(unsigned int sig); static wine_signal_handler handlers[256]; /*********************************************************************** * dispatch_signal */ static inline int dispatch_signal(unsigned int sig) { if (handlers[sig] == NULL) return 0; return handlers[sig](sig); } /*********************************************************************** * save_context * * Set the register values from a sigcontext. */ static void save_context( CONTEXT *context, const ucontext_t *sigcontext ) { #define C(x) context->Gpr##x = GPR_sig(x,sigcontext) /* Save Gpr registers */ C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); C(31); #undef C context->Iar = IAR_sig(sigcontext); /* Program Counter */ context->Msr = MSR_sig(sigcontext); /* Machine State Register (Supervisor) */ context->Ctr = CTR_sig(sigcontext); context->Xer = XER_sig(sigcontext); context->Lr = LR_sig(sigcontext); context->Cr = CR_sig(sigcontext); /* Saving Exception regs */ context->Dar = DAR_sig(sigcontext); context->Dsisr = DSISR_sig(sigcontext); context->Trap = TRAP_sig(sigcontext); } /*********************************************************************** * restore_context * * Build a sigcontext from the register values. */ static void restore_context( const CONTEXT *context, ucontext_t *sigcontext ) { #define C(x) GPR_sig(x,sigcontext) = context->Gpr##x C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); C(31); #undef C IAR_sig(sigcontext) = context->Iar; /* Program Counter */ MSR_sig(sigcontext) = context->Msr; /* Machine State Register (Supervisor) */ CTR_sig(sigcontext) = context->Ctr; XER_sig(sigcontext) = context->Xer; LR_sig(sigcontext) = context->Lr; CR_sig(sigcontext) = context->Cr; /* Setting Exception regs */ DAR_sig(sigcontext) = context->Dar; DSISR_sig(sigcontext) = context->Dsisr; TRAP_sig(sigcontext) = context->Trap; } /*********************************************************************** * save_fpu * * Set the FPU context from a sigcontext. */ static inline void save_fpu( CONTEXT *context, const ucontext_t *sigcontext ) { #define C(x) context->Fpr##x = FLOAT_sig(x,sigcontext) C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); C(31); #undef C context->Fpscr = FPSCR_sig(sigcontext); } /*********************************************************************** * restore_fpu * * Restore the FPU context to a sigcontext. */ static inline void restore_fpu( CONTEXT *context, const ucontext_t *sigcontext ) { #define C(x) FLOAT_sig(x,sigcontext) = context->Fpr##x C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); C(31); #undef C FPSCR_sig(sigcontext) = context->Fpscr; } /*********************************************************************** * RtlCaptureContext (NTDLL.@) */ void WINAPI RtlCaptureContext( CONTEXT *context ) { FIXME("not implemented\n"); memset( context, 0, sizeof(*context) ); } /*********************************************************************** * set_cpu_context * * Set the new CPU context. */ void set_cpu_context( const CONTEXT *context ) { FIXME("not implemented\n"); } /*********************************************************************** * copy_context * * Copy a register context according to the flags. */ void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags ) { if (flags & CONTEXT_CONTROL) { to->Msr = from->Msr; to->Ctr = from->Ctr; to->Iar = from->Iar; to->Lr = from->Lr; to->Dar = from->Dar; to->Dsisr = from->Dsisr; to->Trap = from->Trap; } if (flags & CONTEXT_INTEGER) { to->Gpr0 = from->Gpr0; to->Gpr1 = from->Gpr1; to->Gpr2 = from->Gpr2; to->Gpr3 = from->Gpr3; to->Gpr4 = from->Gpr4; to->Gpr5 = from->Gpr5; to->Gpr6 = from->Gpr6; to->Gpr7 = from->Gpr7; to->Gpr8 = from->Gpr8; to->Gpr9 = from->Gpr9; to->Gpr10 = from->Gpr10; to->Gpr11 = from->Gpr11; to->Gpr12 = from->Gpr12; to->Gpr13 = from->Gpr13; to->Gpr14 = from->Gpr14; to->Gpr15 = from->Gpr15; to->Gpr16 = from->Gpr16; to->Gpr17 = from->Gpr17; to->Gpr18 = from->Gpr18; to->Gpr19 = from->Gpr19; to->Gpr20 = from->Gpr20; to->Gpr21 = from->Gpr21; to->Gpr22 = from->Gpr22; to->Gpr23 = from->Gpr23; to->Gpr24 = from->Gpr24; to->Gpr25 = from->Gpr25; to->Gpr26 = from->Gpr26; to->Gpr27 = from->Gpr27; to->Gpr28 = from->Gpr28; to->Gpr29 = from->Gpr29; to->Gpr30 = from->Gpr30; to->Gpr31 = from->Gpr31; to->Xer = from->Xer; to->Cr = from->Cr; } if (flags & CONTEXT_FLOATING_POINT) { to->Fpr0 = from->Fpr0; to->Fpr1 = from->Fpr1; to->Fpr2 = from->Fpr2; to->Fpr3 = from->Fpr3; to->Fpr4 = from->Fpr4; to->Fpr5 = from->Fpr5; to->Fpr6 = from->Fpr6; to->Fpr7 = from->Fpr7; to->Fpr8 = from->Fpr8; to->Fpr9 = from->Fpr9; to->Fpr10 = from->Fpr10; to->Fpr11 = from->Fpr11; to->Fpr12 = from->Fpr12; to->Fpr13 = from->Fpr13; to->Fpr14 = from->Fpr14; to->Fpr15 = from->Fpr15; to->Fpr16 = from->Fpr16; to->Fpr17 = from->Fpr17; to->Fpr18 = from->Fpr18; to->Fpr19 = from->Fpr19; to->Fpr20 = from->Fpr20; to->Fpr21 = from->Fpr21; to->Fpr22 = from->Fpr22; to->Fpr23 = from->Fpr23; to->Fpr24 = from->Fpr24; to->Fpr25 = from->Fpr25; to->Fpr26 = from->Fpr26; to->Fpr27 = from->Fpr27; to->Fpr28 = from->Fpr28; to->Fpr29 = from->Fpr29; to->Fpr30 = from->Fpr30; to->Fpr31 = from->Fpr31; to->Fpscr = from->Fpscr; } } /*********************************************************************** * context_to_server * * Convert a register context to the server format. */ NTSTATUS context_to_server( context_t *to, const CONTEXT *from ) { DWORD flags = from->ContextFlags; /* no CPU id? */ memset( to, 0, sizeof(*to) ); to->cpu = CPU_POWERPC; if (flags & CONTEXT_CONTROL) { to->flags |= SERVER_CTX_CONTROL; to->ctl.powerpc_regs.iar = from->Iar; to->ctl.powerpc_regs.msr = from->Msr; to->ctl.powerpc_regs.ctr = from->Ctr; to->ctl.powerpc_regs.lr = from->Lr; to->ctl.powerpc_regs.dar = from->Dar; to->ctl.powerpc_regs.dsisr = from->Dsisr; to->ctl.powerpc_regs.trap = from->Trap; } if (flags & CONTEXT_INTEGER) { to->flags |= SERVER_CTX_INTEGER; to->integer.powerpc_regs.gpr[0] = from->Gpr0; to->integer.powerpc_regs.gpr[1] = from->Gpr1; to->integer.powerpc_regs.gpr[2] = from->Gpr2; to->integer.powerpc_regs.gpr[3] = from->Gpr3; to->integer.powerpc_regs.gpr[4] = from->Gpr4; to->integer.powerpc_regs.gpr[5] = from->Gpr5; to->integer.powerpc_regs.gpr[6] = from->Gpr6; to->integer.powerpc_regs.gpr[7] = from->Gpr7; to->integer.powerpc_regs.gpr[8] = from->Gpr8; to->integer.powerpc_regs.gpr[9] = from->Gpr9; to->integer.powerpc_regs.gpr[10] = from->Gpr10; to->integer.powerpc_regs.gpr[11] = from->Gpr11; to->integer.powerpc_regs.gpr[12] = from->Gpr12; to->integer.powerpc_regs.gpr[13] = from->Gpr13; to->integer.powerpc_regs.gpr[14] = from->Gpr14; to->integer.powerpc_regs.gpr[15] = from->Gpr15; to->integer.powerpc_regs.gpr[16] = from->Gpr16; to->integer.powerpc_regs.gpr[17] = from->Gpr17; to->integer.powerpc_regs.gpr[18] = from->Gpr18; to->integer.powerpc_regs.gpr[19] = from->Gpr19; to->integer.powerpc_regs.gpr[20] = from->Gpr20; to->integer.powerpc_regs.gpr[21] = from->Gpr21; to->integer.powerpc_regs.gpr[22] = from->Gpr22; to->integer.powerpc_regs.gpr[23] = from->Gpr23; to->integer.powerpc_regs.gpr[24] = from->Gpr24; to->integer.powerpc_regs.gpr[25] = from->Gpr25; to->integer.powerpc_regs.gpr[26] = from->Gpr26; to->integer.powerpc_regs.gpr[27] = from->Gpr27; to->integer.powerpc_regs.gpr[28] = from->Gpr28; to->integer.powerpc_regs.gpr[29] = from->Gpr29; to->integer.powerpc_regs.gpr[30] = from->Gpr30; to->integer.powerpc_regs.gpr[31] = from->Gpr31; to->integer.powerpc_regs.xer = from->Xer; to->integer.powerpc_regs.cr = from->Cr; } if (flags & CONTEXT_FLOATING_POINT) { to->flags |= SERVER_CTX_FLOATING_POINT; to->fp.powerpc_regs.fpr[0] = from->Fpr0; to->fp.powerpc_regs.fpr[1] = from->Fpr1; to->fp.powerpc_regs.fpr[2] = from->Fpr2; to->fp.powerpc_regs.fpr[3] = from->Fpr3; to->fp.powerpc_regs.fpr[4] = from->Fpr4; to->fp.powerpc_regs.fpr[5] = from->Fpr5; to->fp.powerpc_regs.fpr[6] = from->Fpr6; to->fp.powerpc_regs.fpr[7] = from->Fpr7; to->fp.powerpc_regs.fpr[8] = from->Fpr8; to->fp.powerpc_regs.fpr[9] = from->Fpr9; to->fp.powerpc_regs.fpr[10] = from->Fpr10; to->fp.powerpc_regs.fpr[11] = from->Fpr11; to->fp.powerpc_regs.fpr[12] = from->Fpr12; to->fp.powerpc_regs.fpr[13] = from->Fpr13; to->fp.powerpc_regs.fpr[14] = from->Fpr14; to->fp.powerpc_regs.fpr[15] = from->Fpr15; to->fp.powerpc_regs.fpr[16] = from->Fpr16; to->fp.powerpc_regs.fpr[17] = from->Fpr17; to->fp.powerpc_regs.fpr[18] = from->Fpr18; to->fp.powerpc_regs.fpr[19] = from->Fpr19; to->fp.powerpc_regs.fpr[20] = from->Fpr20; to->fp.powerpc_regs.fpr[21] = from->Fpr21; to->fp.powerpc_regs.fpr[22] = from->Fpr22; to->fp.powerpc_regs.fpr[23] = from->Fpr23; to->fp.powerpc_regs.fpr[24] = from->Fpr24; to->fp.powerpc_regs.fpr[25] = from->Fpr25; to->fp.powerpc_regs.fpr[26] = from->Fpr26; to->fp.powerpc_regs.fpr[27] = from->Fpr27; to->fp.powerpc_regs.fpr[28] = from->Fpr28; to->fp.powerpc_regs.fpr[29] = from->Fpr29; to->fp.powerpc_regs.fpr[30] = from->Fpr30; to->fp.powerpc_regs.fpr[31] = from->Fpr31; to->fp.powerpc_regs.fpscr = from->Fpscr; } return STATUS_SUCCESS; } /*********************************************************************** * context_from_server * * Convert a register context from the server format. */ NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) { if (from->cpu != CPU_POWERPC) return STATUS_INVALID_PARAMETER; to->ContextFlags = 0; /* no CPU id? */ if (from->flags & SERVER_CTX_CONTROL) { to->ContextFlags |= CONTEXT_CONTROL; to->Msr = from->ctl.powerpc_regs.msr; to->Ctr = from->ctl.powerpc_regs.ctr; to->Iar = from->ctl.powerpc_regs.iar; to->Lr = from->ctl.powerpc_regs.lr; to->Dar = from->ctl.powerpc_regs.dar; to->Dsisr = from->ctl.powerpc_regs.dsisr; to->Trap = from->ctl.powerpc_regs.trap; } if (from->flags & SERVER_CTX_INTEGER) { to->ContextFlags |= CONTEXT_INTEGER; to->Gpr0 = from->integer.powerpc_regs.gpr[0]; to->Gpr1 = from->integer.powerpc_regs.gpr[1]; to->Gpr2 = from->integer.powerpc_regs.gpr[2]; to->Gpr3 = from->integer.powerpc_regs.gpr[3]; to->Gpr4 = from->integer.powerpc_regs.gpr[4]; to->Gpr5 = from->integer.powerpc_regs.gpr[5]; to->Gpr6 = from->integer.powerpc_regs.gpr[6]; to->Gpr7 = from->integer.powerpc_regs.gpr[7]; to->Gpr8 = from->integer.powerpc_regs.gpr[8]; to->Gpr9 = from->integer.powerpc_regs.gpr[9]; to->Gpr10 = from->integer.powerpc_regs.gpr[10]; to->Gpr11 = from->integer.powerpc_regs.gpr[11]; to->Gpr12 = from->integer.powerpc_regs.gpr[12]; to->Gpr13 = from->integer.powerpc_regs.gpr[13]; to->Gpr14 = from->integer.powerpc_regs.gpr[14]; to->Gpr15 = from->integer.powerpc_regs.gpr[15]; to->Gpr16 = from->integer.powerpc_regs.gpr[16]; to->Gpr17 = from->integer.powerpc_regs.gpr[17]; to->Gpr18 = from->integer.powerpc_regs.gpr[18]; to->Gpr19 = from->integer.powerpc_regs.gpr[19]; to->Gpr20 = from->integer.powerpc_regs.gpr[20]; to->Gpr21 = from->integer.powerpc_regs.gpr[21]; to->Gpr22 = from->integer.powerpc_regs.gpr[22]; to->Gpr23 = from->integer.powerpc_regs.gpr[23]; to->Gpr24 = from->integer.powerpc_regs.gpr[24]; to->Gpr25 = from->integer.powerpc_regs.gpr[25]; to->Gpr26 = from->integer.powerpc_regs.gpr[26]; to->Gpr27 = from->integer.powerpc_regs.gpr[27]; to->Gpr28 = from->integer.powerpc_regs.gpr[28]; to->Gpr29 = from->integer.powerpc_regs.gpr[29]; to->Gpr30 = from->integer.powerpc_regs.gpr[30]; to->Gpr31 = from->integer.powerpc_regs.gpr[31]; to->Xer = from->integer.powerpc_regs.xer; to->Cr = from->integer.powerpc_regs.cr; } if (from->flags & SERVER_CTX_FLOATING_POINT) { to->ContextFlags |= CONTEXT_FLOATING_POINT; to->Fpr0 = from->fp.powerpc_regs.fpr[0]; to->Fpr1 = from->fp.powerpc_regs.fpr[1]; to->Fpr2 = from->fp.powerpc_regs.fpr[2]; to->Fpr3 = from->fp.powerpc_regs.fpr[3]; to->Fpr4 = from->fp.powerpc_regs.fpr[4]; to->Fpr5 = from->fp.powerpc_regs.fpr[5]; to->Fpr6 = from->fp.powerpc_regs.fpr[6]; to->Fpr7 = from->fp.powerpc_regs.fpr[7]; to->Fpr8 = from->fp.powerpc_regs.fpr[8]; to->Fpr9 = from->fp.powerpc_regs.fpr[9]; to->Fpr10 = from->fp.powerpc_regs.fpr[10]; to->Fpr11 = from->fp.powerpc_regs.fpr[11]; to->Fpr12 = from->fp.powerpc_regs.fpr[12]; to->Fpr13 = from->fp.powerpc_regs.fpr[13]; to->Fpr14 = from->fp.powerpc_regs.fpr[14]; to->Fpr15 = from->fp.powerpc_regs.fpr[15]; to->Fpr16 = from->fp.powerpc_regs.fpr[16]; to->Fpr17 = from->fp.powerpc_regs.fpr[17]; to->Fpr18 = from->fp.powerpc_regs.fpr[18]; to->Fpr19 = from->fp.powerpc_regs.fpr[19]; to->Fpr20 = from->fp.powerpc_regs.fpr[20]; to->Fpr21 = from->fp.powerpc_regs.fpr[21]; to->Fpr22 = from->fp.powerpc_regs.fpr[22]; to->Fpr23 = from->fp.powerpc_regs.fpr[23]; to->Fpr24 = from->fp.powerpc_regs.fpr[24]; to->Fpr25 = from->fp.powerpc_regs.fpr[25]; to->Fpr26 = from->fp.powerpc_regs.fpr[26]; to->Fpr27 = from->fp.powerpc_regs.fpr[27]; to->Fpr28 = from->fp.powerpc_regs.fpr[28]; to->Fpr29 = from->fp.powerpc_regs.fpr[29]; to->Fpr30 = from->fp.powerpc_regs.fpr[30]; to->Fpr31 = from->fp.powerpc_regs.fpr[31]; to->Fpscr = from->fp.powerpc_regs.fpscr; } return STATUS_SUCCESS; } /********************************************************************** * call_stack_handlers * * Call the stack handlers chain. */ static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) { EXCEPTION_POINTERS ptrs; FIXME( "not implemented on PowerPC\n" ); /* hack: call unhandled exception filter directly */ ptrs.ExceptionRecord = rec; ptrs.ContextRecord = context; unhandled_exception_filter( &ptrs ); return STATUS_UNHANDLED_EXCEPTION; } /******************************************************************* * raise_exception * * Implementation of NtRaiseException. */ static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance ) { NTSTATUS status; if (first_chance) { DWORD c; TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n", rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, context->Iar, GetCurrentThreadId() ); for (c = 0; c < rec->NumberParameters; c++) TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] ); if (rec->ExceptionCode == EXCEPTION_WINE_STUB) { if (rec->ExceptionInformation[1] >> 16) MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n", rec->ExceptionAddress, (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] ); else MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n", rec->ExceptionAddress, (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] ); } else { /* FIXME: dump context */ } status = send_debug_event( rec, TRUE, context ); if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED) return STATUS_SUCCESS; if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION) return STATUS_SUCCESS; if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION) return status; } /* last chance exception */ status = send_debug_event( rec, FALSE, context ); if (status != DBG_CONTINUE) { if (rec->ExceptionFlags & EH_STACK_INVALID) ERR("Exception frame is not in stack limits => unable to dispatch exception.\n"); else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION) ERR("Process attempted to continue execution after noncontinuable exception.\n"); else ERR("Unhandled exception code %x flags %x addr %p\n", rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress ); NtTerminateProcess( NtCurrentProcess(), rec->ExceptionCode ); } return STATUS_SUCCESS; } /********************************************************************** * segv_handler * * Handler for SIGSEGV and related errors. */ static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { EXCEPTION_RECORD rec; CONTEXT context; NTSTATUS status; save_context( &context, sigcontext ); rec.ExceptionRecord = NULL; rec.ExceptionFlags = EXCEPTION_CONTINUABLE; rec.ExceptionAddress = (LPVOID)context.Iar; rec.NumberParameters = 0; switch (signal) { case SIGSEGV: switch (siginfo->si_code & 0xffff) { case SEGV_MAPERR: case SEGV_ACCERR: rec.NumberParameters = 2; rec.ExceptionInformation[0] = 0; /* FIXME ? */ rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr; if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0]))) goto done; break; default: FIXME("Unhandled SIGSEGV/%x\n",siginfo->si_code); break; } break; case SIGBUS: switch (siginfo->si_code & 0xffff) { case BUS_ADRALN: rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT; break; #ifdef BUS_ADRERR case BUS_ADRERR: #endif #ifdef BUS_OBJERR case BUS_OBJERR: /* FIXME: correct for all cases ? */ rec.NumberParameters = 2; rec.ExceptionInformation[0] = 0; /* FIXME ? */ rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr; if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0]))) goto done; break; #endif default: FIXME("Unhandled SIGBUS/%x\n",siginfo->si_code); break; } break; case SIGILL: switch (siginfo->si_code & 0xffff) { case ILL_ILLOPC: /* illegal opcode */ #ifdef ILL_ILLOPN case ILL_ILLOPN: /* illegal operand */ #endif #ifdef ILL_ILLADR case ILL_ILLADR: /* illegal addressing mode */ #endif #ifdef ILL_ILLTRP case ILL_ILLTRP: /* illegal trap */ #endif #ifdef ILL_COPROC case ILL_COPROC: /* coprocessor error */ #endif rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION; break; case ILL_PRVOPC: /* privileged opcode */ #ifdef ILL_PRVREG case ILL_PRVREG: /* privileged register */ #endif rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION; break; #ifdef ILL_BADSTK case ILL_BADSTK: /* internal stack error */ rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW; break; #endif default: FIXME("Unhandled SIGILL/%x\n", siginfo->si_code); break; } break; } status = raise_exception( &rec, &context, TRUE ); if (status) raise_status( status, &rec ); done: restore_context( &context, sigcontext ); } /********************************************************************** * trap_handler * * Handler for SIGTRAP. */ static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { EXCEPTION_RECORD rec; CONTEXT context; NTSTATUS status; save_context( &context, sigcontext ); rec.ExceptionFlags = EXCEPTION_CONTINUABLE; rec.ExceptionRecord = NULL; rec.ExceptionAddress = (LPVOID)context.Iar; rec.NumberParameters = 0; /* FIXME: check if we might need to modify PC */ switch (siginfo->si_code & 0xffff) { #ifdef TRAP_BRKPT case TRAP_BRKPT: rec.ExceptionCode = EXCEPTION_BREAKPOINT; break; #endif #ifdef TRAP_TRACE case TRAP_TRACE: rec.ExceptionCode = EXCEPTION_SINGLE_STEP; break; #endif default: FIXME("Unhandled SIGTRAP/%x\n", siginfo->si_code); break; } status = raise_exception( &rec, &context, TRUE ); if (status) raise_status( status, &rec ); restore_context( &context, sigcontext ); } /********************************************************************** * fpe_handler * * Handler for SIGFPE. */ static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { EXCEPTION_RECORD rec; CONTEXT context; NTSTATUS status; save_fpu( &context, sigcontext ); save_context( &context, sigcontext ); switch (siginfo->si_code & 0xffff ) { #ifdef FPE_FLTSUB case FPE_FLTSUB: rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED; break; #endif #ifdef FPE_INTDIV case FPE_INTDIV: rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO; break; #endif #ifdef FPE_INTOVF case FPE_INTOVF: rec.ExceptionCode = EXCEPTION_INT_OVERFLOW; break; #endif #ifdef FPE_FLTDIV case FPE_FLTDIV: rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO; break; #endif #ifdef FPE_FLTOVF case FPE_FLTOVF: rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW; break; #endif #ifdef FPE_FLTUND case FPE_FLTUND: rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW; break; #endif #ifdef FPE_FLTRES case FPE_FLTRES: rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT; break; #endif #ifdef FPE_FLTINV case FPE_FLTINV: #endif default: rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION; break; } rec.ExceptionFlags = EXCEPTION_CONTINUABLE; rec.ExceptionRecord = NULL; rec.ExceptionAddress = (LPVOID)context.Iar; rec.NumberParameters = 0; status = raise_exception( &rec, &context, TRUE ); if (status) raise_status( status, &rec ); restore_context( &context, sigcontext ); restore_fpu( &context, sigcontext ); } /********************************************************************** * int_handler * * Handler for SIGINT. */ static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { if (!dispatch_signal(SIGINT)) { EXCEPTION_RECORD rec; CONTEXT context; NTSTATUS status; save_context( &context, sigcontext ); rec.ExceptionCode = CONTROL_C_EXIT; rec.ExceptionFlags = EXCEPTION_CONTINUABLE; rec.ExceptionRecord = NULL; rec.ExceptionAddress = (LPVOID)context.Iar; rec.NumberParameters = 0; status = raise_exception( &rec, &context, TRUE ); if (status) raise_status( status, &rec ); restore_context( &context, sigcontext ); } } /********************************************************************** * abrt_handler * * Handler for SIGABRT. */ static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { EXCEPTION_RECORD rec; CONTEXT context; NTSTATUS status; save_context( &context, sigcontext ); rec.ExceptionCode = EXCEPTION_WINE_ASSERTION; rec.ExceptionFlags = EH_NONCONTINUABLE; rec.ExceptionRecord = NULL; rec.ExceptionAddress = (LPVOID)context.Iar; rec.NumberParameters = 0; status = raise_exception( &rec, &context, TRUE ); if (status) raise_status( status, &rec ); restore_context( &context, sigcontext ); } /********************************************************************** * quit_handler * * Handler for SIGQUIT. */ static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { abort_thread(0); } /********************************************************************** * usr1_handler * * Handler for SIGUSR1, used to signal a thread that it got suspended. */ static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext ) { CONTEXT context; save_context( &context, sigcontext ); wait_suspend( &context ); restore_context( &context, sigcontext ); } /*********************************************************************** * __wine_set_signal_handler (NTDLL.@) */ int CDECL __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh) { if (sig > sizeof(handlers) / sizeof(handlers[0])) return -1; if (handlers[sig] != NULL) return -2; handlers[sig] = wsh; return 0; } /********************************************************************** * signal_alloc_thread */ NTSTATUS signal_alloc_thread( TEB **teb ) { static size_t sigstack_zero_bits; SIZE_T size; NTSTATUS status; if (!sigstack_zero_bits) { size_t min_size = page_size; /* this is just for the TEB, we don't use a signal stack yet */ /* find the first power of two not smaller than min_size */ while ((1u << sigstack_zero_bits) < min_size) sigstack_zero_bits++; assert( sizeof(TEB) <= min_size ); } size = 1 << sigstack_zero_bits; *teb = NULL; if (!(status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)teb, sigstack_zero_bits, &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE ))) { (*teb)->Tib.Self = &(*teb)->Tib; (*teb)->Tib.ExceptionList = (void *)~0UL; } return status; } /********************************************************************** * signal_free_thread */ void signal_free_thread( TEB *teb ) { SIZE_T size; if (teb->DeallocationStack) { size = 0; NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); } size = 0; NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); } /********************************************************************** * signal_init_thread */ void signal_init_thread( TEB *teb ) { static BOOL init_done; if (!init_done) { pthread_key_create( &teb_key, NULL ); init_done = TRUE; } pthread_setspecific( teb_key, teb ); } /********************************************************************** * signal_init_process */ void signal_init_process(void) { struct sigaction sig_act; sig_act.sa_mask = server_block_set; sig_act.sa_flags = SA_RESTART | SA_SIGINFO; sig_act.sa_sigaction = int_handler; if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error; sig_act.sa_sigaction = fpe_handler; if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error; sig_act.sa_sigaction = abrt_handler; if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error; sig_act.sa_sigaction = quit_handler; if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error; sig_act.sa_sigaction = usr1_handler; if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error; sig_act.sa_sigaction = segv_handler; if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error; #ifdef SIGBUS if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error; #endif #ifdef SIGTRAP sig_act.sa_sigaction = trap_handler; if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error; #endif return; error: perror("sigaction"); exit(1); } /********************************************************************** * __wine_enter_vm86 (NTDLL.@) */ void __wine_enter_vm86( CONTEXT *context ) { MESSAGE("vm86 mode not supported on this platform\n"); } /*********************************************************************** * RtlUnwind (NTDLL.@) */ void WINAPI RtlUnwind( PVOID pEndFrame, PVOID targetIp, PEXCEPTION_RECORD pRecord, PVOID retval ) { FIXME( "Not implemented on PowerPC\n" ); } /******************************************************************* * NtRaiseException (NTDLL.@) */ NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance ) { NTSTATUS status = raise_exception( rec, context, first_chance ); if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context ); return status; } /*********************************************************************** * RtlRaiseException (NTDLL.@) */ void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec ) { CONTEXT context; NTSTATUS status; RtlCaptureContext( &context ); rec->ExceptionAddress = (void *)context.Iar; status = raise_exception( rec, &context, TRUE ); if (status) raise_status( status, rec ); } /************************************************************************* * RtlCaptureStackBackTrace (NTDLL.@) */ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash ) { FIXME( "(%d, %d, %p, %p) stub!\n", skip, count, buffer, hash ); return 0; } /*********************************************************************** * call_thread_entry_point */ void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) { __TRY { exit_thread( entry( arg )); } __EXCEPT(unhandled_exception_filter) { NtTerminateThread( GetCurrentThread(), GetExceptionCode() ); } __ENDTRY abort(); /* should not be reached */ } /*********************************************************************** * RtlExitUserThread (NTDLL.@) */ void WINAPI RtlExitUserThread( ULONG status ) { exit_thread( status ); } /*********************************************************************** * abort_thread */ void abort_thread( int status ) { terminate_thread( status ); } /********************************************************************** * DbgBreakPoint (NTDLL.@) */ void WINAPI DbgBreakPoint(void) { kill(getpid(), SIGTRAP); } /********************************************************************** * DbgUserBreakPoint (NTDLL.@) */ void WINAPI DbgUserBreakPoint(void) { kill(getpid(), SIGTRAP); } /********************************************************************** * NtCurrentTeb (NTDLL.@) */ TEB * WINAPI NtCurrentTeb(void) { return pthread_getspecific( teb_key ); } #endif /* __powerpc__ */
the_stack_data/206391923.c
/* * Write a function that takes three arguments: a character and two integers. * The character is to be printed. The first integer specifies the number of * times that the character is to be printed on a line, and the second integer * specifies the number of lines that are to be printed. Write a program that * makes use of this function. */ #include <stdio.h> void draw_grid(char c, int n, int nrows); int main (void) { char c; int n, nrows; printf("Enter a character, and two integers: \n"); while (scanf("%c %d %d", &c, &n, &nrows) != 3) { while (getchar() != '\n') {} printf("Error reading input.\nEnter a character and two integers: \n"); } draw_grid(c, n, nrows); return 0; } void draw_grid(char c, int n, int nrows) { for (int i = 0; i < nrows; i++) { for (int j = 0; j < n; j++) { printf("%c", c); } printf("\n"); } return; }
the_stack_data/59514146.c
/** ******************************************************************************* * Copyright (C) 2017 - 2018 Accumulate Team * * * * 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. * ******************************************************************************* * @file bootload.c * * @author yearnext * * @version 1.0.0 * * @date 2018-04-16 * * @brief bootload component source file * * @par work platform * * Windows * * @par compiler * * GCC * ******************************************************************************* * @note * * 1.XXXXX * ******************************************************************************* */ /** * @defgroup bootload component * @{ */ /* Includes ------------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Exported variables --------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @}*/ /** bootload component */ /**********************************END OF FILE*********************************/
the_stack_data/36074840.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_alphabet.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: llima-ce <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/07/15 15:02:52 by llima-ce #+# #+# */ /* Updated: 2021/07/17 13:43:29 by llima-ce ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> void ft_print_alphabet(void) { char c; c = 'a'; while (c <= 'z') { write(1, &c, 1); c++; } }
the_stack_data/20449182.c
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define BUF_SIZE 1024 bool is_vowel(char c) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ){ return true; } return false; } int copy_non_vowels(int num_char, char* in_buff, char* out_buff){ int index =0; for(int i = 0; i< num_char-1; i++){ if( is_vowel(in_buff[i]) == false ){ out_buff[index] = in_buff[i]; index++; } } return index; } void disemvowel(FILE* inputFile, FILE* outputFile) { /* * Copy all the non-vowels from inputFile to outputFile. * Create input and output buffers, and use fread() to repeatedly read * in a buffer of data, copy the non-vowels to the output buffer, and * use fwrite to write that out. */ char inBuff[BUF_SIZE]; char outBuff[BUF_SIZE]; int nChars = 0; nChars = (int) fread(inBuff, sizeof(char), BUF_SIZE, inputFile); if(nChars != 0){ int Consts = copy_non_vowels(nChars, inBuff, outBuff); fwrite(outBuff, sizeof(char), Consts, outputFile); } } int main(int argc, char *argv[]) { FILE *inputFile = stdin; FILE *outputFile = stdout; if (argc >= 2) { inputFile = fopen(argv[1], "r"); if (inputFile == NULL) { perror("fopen()"); exit(1); } } if (argc == 3) { outputFile = fopen(argv[2], "w"); if (outputFile == NULL) { perror("fopen()"); exit(1); } } disemvowel(inputFile, outputFile); fclose(inputFile); fclose(outputFile); return 0; }
the_stack_data/176706048.c
int func(int a) { int b = 100; int c = a + b; return c; } int main() { int v = func(5) + func(10); return v; }
the_stack_data/215767149.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_negative.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: evgenkarlson <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 12:33:14 by evgenkarlson #+# #+# */ /* Updated: 2020/09/28 17:53:18 by evgenkarlson ### ########.fr */ /* */ /* ************************************************************************** */ /* ************************************************************************** */ /* ************************************************************************** ** ** ** - Создайте функцию, которая отображает символы «N» или «P» в зависимости от ** целочисленного знака, введенного в качестве параметра. Если n отрицательно, ** выведите символ «N». Если 'n' является положительным или нулевым, выведите ** символ «P». ** ** - Функция должна быть обьялена следующим образом: ** ** void ft_is_negative(int n); ** ** ************************************************************************** ** ** ** Скомпилируй файл тест. В нем можно увидеть как работает эта функция вживую ** ** ************************************************************************** */ /* ************************************************************************** */ void ft_putchar(char c); void ft_is_negative(int n) { if (n < 0) ft_putchar('N'); else ft_putchar('P'); } /* ************************************************************************** */
the_stack_data/56436.c
#include <stdio.h> #include <stdlib.h> typedef struct { int num; int min_idx; int stack[]; } MinStack; /** initialize your data structure here. */ static MinStack* minStackCreate(const int maxSize) { MinStack* obj = malloc(sizeof(MinStack) + sizeof(int) * maxSize); obj->num = 0; obj->min_idx = 0; return obj; } static void minStackPush(MinStack* const obj, const int x) { if (obj->num > 0 && x < obj->stack[obj->min_idx]) { obj->min_idx = obj->num; } obj->stack[obj->num++] = x; } static void minStackPop(MinStack* const obj) { int i; /* We records min index but not min value to save unnecessary operation */ if (--obj->num == obj->min_idx) { int min_idx = 0; for (i = 1; i < obj->num; i++) { if (obj->stack[i] < obj->stack[min_idx]) { min_idx = i; } } obj->min_idx = min_idx; } } static int minStackTop(MinStack* const obj) { return obj->stack[obj->num - 1]; } static int minStackGetMin(MinStack* const obj) { return obj->stack[obj->min_idx]; } static void minStackFree(MinStack* const obj) { free(obj); } int main(void) { MinStack *obj = minStackCreate(5); minStackPush(obj, 2); minStackPush(obj, 0); minStackPush(obj, 3); minStackPush(obj, 0); printf("Min:%d\n", minStackGetMin(obj)); minStackPop(obj); //printf("Top:%d\n", minStackTop(obj)); printf("Min:%d\n", minStackGetMin(obj)); minStackPop(obj); printf("Min:%d\n", minStackGetMin(obj)); minStackPop(obj); printf("Min:%d\n", minStackGetMin(obj)); minStackFree(obj); return 0; }
the_stack_data/71370.c
#include<sys/stat.h> #include<sys/types.h> int main(int argc, char *argv[]) { mkdir("foobar",'644'); }
the_stack_data/591827.c
#include <stdio.h> #pragma warning(disable:4996) int main() { int num,j,k; scanf("%d", &num); for (int i = 0; i < num; i++) { for (j = 0; j < num - i - 1; j++) { printf(" "); } for (k = 0; k <= i; k++) { printf("*"); } printf("\n"); } }
the_stack_data/206393470.c
// SKIP PARAM: --set ana.activated[-] mutex --set solver "'new'" --set ana.ctx_insens[+] base --set ana.ctx_insens[+] escape --set ana.base.privatization none void write(int **p){ *p=1; } int *P = 0; void f(){ int *a; write(&a); return; } int main(void){ write(&P); f(); return 0; // NOWARN }
the_stack_data/677242.c
#include <assert.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> uint8_t subnetgen_random_uint8() { uint8_t n; assert(!getentropy(&n, sizeof(n))); return n; } #define SUBNETGEN_IPV4_MASK "10.%u.%u.0/24" #define SUBNETGEN_IPV6_MASK "fd%x:%x%x:%x%x::/48" int main(int argc, char *argv[]) { for (;;) switch (getopt(argc, argv, "46")) { case '4': printf(SUBNETGEN_IPV4_MASK "\n", subnetgen_random_uint8(), subnetgen_random_uint8()); break; case '6': printf(SUBNETGEN_IPV6_MASK "\n", subnetgen_random_uint8(), subnetgen_random_uint8(), subnetgen_random_uint8(), subnetgen_random_uint8(), subnetgen_random_uint8()); break; case -1: return EXIT_SUCCESS; default: return EXIT_FAILURE; } }
the_stack_data/19932.c
void caller() { my_func(0xdede); } int my_func(int arg) { return arg; }
the_stack_data/91636.c
/* Normally compiler builtins are used, but sometimes the compiler calls out of line code. Based on asm-i386/string.h. */ #define _STRING_C #include <linux/string.h> #include <linux/module.h> #undef memmove void *memmove(void * dest,const void *src,size_t count) { if (dest < src) { return memcpy(dest,src,count); } else { char *p = (char *) dest + count; char *s = (char *) src + count; while (count--) *--p = *--s; } return dest; } EXPORT_SYMBOL(memmove);
the_stack_data/182951904.c
#include <stdio.h> #define MAX 5 struct CQ { int size, front, rear, queue[MAX]; }; void enqueue(struct CQ*,int); int dequeue(struct CQ*); int main() { struct CQ q={0, 0, -1}; int choice,data; do { printf("\n"); printf("Select an option. \n"); printf("1. ENQUEUE\n"); printf("2. DEQUEUE\n"); printf("3. EXIT.\n"); printf(">"); scanf("%d",&choice); switch (choice) { case 1: if(q.size == MAX) printf("QUEUUE IS FULL\n"); else { printf("Enter data : "); scanf("%d",&data); enqueue(&q, data); printf("%d Enqueued\n",data); } break; case 2: if(q.size == 0) printf("QUEUE IS EMPTY\n"); else printf("Removed element is : %d \n",dequeue(&q)); break; case 3: printf("BYE\n"); break; } }while (choice!= 3); return 0; } void enqueue(struct CQ *Q, int a) { Q->rear = (Q->rear+1)%MAX; Q->queue[Q->rear]=a; Q->size += 1; } int dequeue(struct CQ *Q) { int ret = Q->queue[Q->front]; Q->front=(Q->front+1)%MAX; Q->size -= 1; return ret; }
the_stack_data/187143.c
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> struct TreeNode_; typedef struct TreeNode_ TreeNode; typedef int Data; struct TreeNode_{ TreeNode *left; TreeNode *right; Data data; }; typedef TreeNode TreeNode; typedef TreeNode* Tree; void preOrder(Tree root) { if (root==NULL)return ; printf("%d \n",root->data); preOrder(root->left); preOrder(root->right); } void inOrder(Tree root){ if (root==NULL)return ; inOrder(root->left); printf("%d \n",root->data); inOrder(root->right); } void postOrder(Tree root){ if (root==NULL)return; postOrder(root->left); postOrder(root->right); printf("%d \n",root->data); } TreeNode* newTreeNode(Data data) { Tree tree =0; do { tree = (Tree) malloc(sizeof(TreeNode)); }while(tree==0); memset(tree,0,sizeof(TreeNode)); tree->data = data; return tree; } void Add2Left(Tree root,TreeNode *n){ if (root==NULL) return ; root->left =n; } void Add2Right(Tree root,TreeNode *n){ if (root==NULL) return; root->right=n; } void DeleteByPostOrder(Tree root){ if (root==NULL)return; DeleteByPostOrder(root->left); DeleteByPostOrder(root->right); printf("%d will delete ..\n",root->data); free(root); } int main(int argc,const char *argvs[]){ Tree tree = newTreeNode(10); TreeNode *layer1_left = newTreeNode(1); TreeNode *layer1_right = newTreeNode(2); Add2Left(tree,layer1_left); Add2Right(tree,layer1_right); TreeNode *layer1_left_left = newTreeNode(11); TreeNode *layer1_left_right= newTreeNode(12); Add2Left(layer1_left,layer1_left_left); Add2Right(layer1_left,layer1_left_right); TreeNode *layer1_right_left = newTreeNode(22); TreeNode *layer1_right_right = newTreeNode(23); Add2Left(layer1_right,layer1_right_left); Add2Right(layer1_right,layer1_right_right); printf("preOder...\n"); preOrder(tree); printf("inOder...\n"); inOrder(tree); printf("postOder...\n"); postOrder(tree); DeleteByPostOrder(tree); return 0; }
the_stack_data/128901.c
/* * Copyright 2018 Google LLC * * 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 <unistd.h> int main(int argc, char** argv) { for(int i = 3; i < 1024; i++) close(i); return execvp(argv[1], &argv[1]); }
the_stack_data/175144439.c
int x = 9; int z; int main() { z = 8; return z+x; }
the_stack_data/140343.c
#include <stdio.h> struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; typedef struct TreeNode TreeNode; #define max(x, y) (((x)<(y))?(y):(x)) void rob_node(struct TreeNode *root, int *f, int *g) { *f = *g = 0; if (!root) return; int lf, lg, rf, rg; rob_node(root->left, &lf, &lg); rob_node(root->right, &rf, &rg); *f = root->val + lg + rg; *g = max(lf, lg) + max(rf, rg); return; } int rob(struct TreeNode* root) { int f, g; rob_node(root, &f, &g); if (f > g) return f; else return g; } int main(int argc, char *argv[]) { TreeNode n1, n2, n3, n4, n5; n1.val = 3; n2.val = 2; n3.val = 3; n4.val = 3; n5.val = 1; n1.left = &n2; n1.right = &n3; n2.left = NULL; n2.right = &n4; n3.left = NULL; n3.right = &n5; n4.left = n4.right = n5.left = n5.right = NULL; int v = rob(&n1); printf("value = %d\n", v); return 0; }
the_stack_data/167405.c
# include <stdio.h> # include <stdlib.h> # include <locale.h> main(){ setlocale(LC_ALL,""); int cont = 0, ra; float nota; do{ printf("Digite o RA do aluno: "); scanf("%d", &ra); if (ra == 0){ break; } printf("Digite a nota do aluno: "); scanf("%f", &nota); cont++; } while (cont < 100); system("pause"); }
the_stack_data/300111.c
#include <stdio.h> #define IN 1 /* inside a word */ #define OUT 0 /* outside a word */ #define MAX_LENGTH 100 int main() { char c; int i, j, k, status, length, max_wl, show_times; int word[MAX_LENGTH]; i = j = k = show_times = length = max_wl = 0; status = OUT; for(i = 1; i <= MAX_LENGTH; i++) word[i] = 0; while((c = getchar()) != EOF) { if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) if(status == OUT) { status = IN; ++ word[length]; length = 1; } else { ++ length; } else { status = OUT; } } ++ word[length]; printf("\n"); for(i = 1; i < MAX_LENGTH; i++) { if (word[i] > max_wl) max_wl = word[i]; if (word[i] && i > show_times) show_times = i; } for(i = 0; i < 60; i++) printf("="); printf("\n"); /* horizontal histogram */ printf("\nhorizontal histogram\n\n"); printf("length | times\n"); for(i = 1; i <= show_times; i++) { printf("%6d | ", i); for(j = 1; j <= word[i]; j++) printf("*"); printf("\n"); } printf("\n"); /* vertical histogram */ printf("\nhorizontal histogram\n"); printf("\ntimes|\n"); for(k = max_wl; k > 0; k--) { printf("%4d | ", k); for(i = 1; i <= show_times; i++) { if(word[i] < k) printf(" "); else printf("* "); } printf("\n"); } printf(" "); for(i = 1; i <= show_times; i++) printf("-----"); printf("\n "); for(i = 1; i <= show_times; i++) printf("%4d", i); printf(" length\n"); printf("\n"); return 0; }
the_stack_data/32948943.c
#include <assert.h> #include <limits.h> #include <stdbool.h> void test_char() { volatile char a = 1; volatile char b = 5; volatile char result; bool overflow = __builtin_add_overflow(a, b, &result); assert(!overflow); assert(result == 6); b = CHAR_MAX; overflow = __builtin_add_overflow(a, b, &result); assert(overflow); assert(result == CHAR_MIN); } void test_short() { volatile short a = 1; volatile short b = 5; volatile short result; bool overflow = __builtin_add_overflow(a, b, &result); assert(!overflow); assert(result == 6); b = SHRT_MAX; overflow = __builtin_add_overflow(a, b, &result); assert(overflow); assert(result == SHRT_MIN); } void test_int() { volatile int a = 1; volatile int b = 5; volatile int result; bool overflow = __builtin_add_overflow(a, b, &result); assert(!overflow); assert(result == 6); b = INT_MAX; overflow = __builtin_add_overflow(a, b, &result); assert(overflow); assert(result == INT_MIN); } void test_long() { volatile long a = 1; volatile long b = 5; volatile long result; bool overflow = __builtin_add_overflow(a, b, &result); assert(!overflow); assert(result == 6); b = LONG_MAX; overflow = __builtin_add_overflow(a, b, &result); assert(overflow); assert(result == LONG_MIN); } void test_longlong() { volatile long long a = 1; volatile long long b = 5; volatile long long result; bool overflow = __builtin_add_overflow(a, b, &result); assert(!overflow); assert(result == 6); b = LLONG_MAX; overflow = __builtin_add_overflow(a, b, &result); assert(overflow); assert(result == LLONG_MIN); } int main() { test_char(); test_short(); test_int(); test_long(); test_longlong(); return 0; }
the_stack_data/1230988.c
/** * \file */ #if defined(HAVE_KQUEUE) #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> #if defined(HOST_WIN32) /* We assume that kqueue is not available on windows */ #error #endif #define KQUEUE_NEVENTS 128 static gint kqueue_fd; static struct kevent *kqueue_events; static gint KQUEUE_INIT_FD (gint fd, gint events, gint flags) { struct kevent event; EV_SET (&event, fd, events, flags, 0, 0, 0); return kevent (kqueue_fd, &event, 1, NULL, 0, NULL); } static gboolean kqueue_init (gint wakeup_pipe_fd) { kqueue_fd = kqueue (); if (kqueue_fd == -1) { g_error ("kqueue_init: kqueue () failed, error (%d) %s", errno, g_strerror (errno)); return FALSE; } if (KQUEUE_INIT_FD (wakeup_pipe_fd, EVFILT_READ, EV_ADD | EV_ENABLE) == -1) { g_error ("kqueue_init: kevent () failed, error (%d) %s", errno, g_strerror (errno)); close (kqueue_fd); return FALSE; } kqueue_events = g_new0 (struct kevent, KQUEUE_NEVENTS); return TRUE; } static void kqueue_register_fd (gint fd, gint events, gboolean is_new) { if (events & EVENT_IN) { if (KQUEUE_INIT_FD (fd, EVFILT_READ, EV_ADD | EV_ENABLE) == -1) g_error ("kqueue_register_fd: kevent(read,enable) failed, error (%d) %s", errno, g_strerror (errno)); } else { if (KQUEUE_INIT_FD (fd, EVFILT_READ, EV_ADD | EV_DISABLE) == -1) g_error ("kqueue_register_fd: kevent(read,disable) failed, error (%d) %s", errno, g_strerror (errno)); } if (events & EVENT_OUT) { if (KQUEUE_INIT_FD (fd, EVFILT_WRITE, EV_ADD | EV_ENABLE) == -1) g_error ("kqueue_register_fd: kevent(write,enable) failed, error (%d) %s", errno, g_strerror (errno)); } else { if (KQUEUE_INIT_FD (fd, EVFILT_WRITE, EV_ADD | EV_DISABLE) == -1) g_error ("kqueue_register_fd: kevent(write,disable) failed, error (%d) %s", errno, g_strerror (errno)); } } static void kqueue_remove_fd (gint fd) { /* FIXME: a race between closing and adding operation in the Socket managed code trigger a ENOENT error */ if (KQUEUE_INIT_FD (fd, EVFILT_READ, EV_DELETE) == -1) g_error ("kqueue_register_fd: kevent(read,delete) failed, error (%d) %s", errno, g_strerror (errno)); if (KQUEUE_INIT_FD (fd, EVFILT_WRITE, EV_DELETE) == -1) g_error ("kqueue_register_fd: kevent(write,delete) failed, error (%d) %s", errno, g_strerror (errno)); } static gint kqueue_event_wait (void (*callback) (gint fd, gint events, gpointer user_data), gpointer user_data) { gint i, ready; memset (kqueue_events, 0, sizeof (struct kevent) * KQUEUE_NEVENTS); mono_gc_set_skip_thread (TRUE); MONO_ENTER_GC_SAFE; ready = kevent (kqueue_fd, NULL, 0, kqueue_events, KQUEUE_NEVENTS, NULL); MONO_EXIT_GC_SAFE; mono_gc_set_skip_thread (FALSE); if (ready == -1) { switch (errno) { case EINTR: ready = 0; break; default: g_error ("kqueue_event_wait: kevent () failed, error (%d) %s", errno, g_strerror (errno)); break; } } if (ready == -1) return -1; for (i = 0; i < ready; ++i) { gint fd, events = 0; fd = kqueue_events [i].ident; if (kqueue_events [i].filter == EVFILT_READ || (kqueue_events [i].flags & EV_ERROR) != 0) events |= EVENT_IN; if (kqueue_events [i].filter == EVFILT_WRITE || (kqueue_events [i].flags & EV_ERROR) != 0) events |= EVENT_OUT; callback (fd, events, user_data); } return 0; } static ThreadPoolIOBackend backend_kqueue = { .init = kqueue_init, .register_fd = kqueue_register_fd, .remove_fd = kqueue_remove_fd, .event_wait = kqueue_event_wait, }; #endif
the_stack_data/29901.c
extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); typedef enum {false, true} bool; bool __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } int main() { float x_31, _x_x_31; bool _J3102, _x__J3102; bool _J3096, _x__J3096; bool _EL_U_3075, _x__EL_U_3075; float x_28, _x_x_28; float x_12, _x_x_12; float x_20, _x_x_20; float x_9, _x_x_9; float x_3, _x_x_3; float x_18, _x_x_18; float x_0, _x_x_0; bool _EL_U_3077, _x__EL_U_3077; float x_25, _x_x_25; float x_2, _x_x_2; float x_4, _x_x_4; float x_1, _x_x_1; float x_6, _x_x_6; float x_5, _x_x_5; float x_8, _x_x_8; float x_10, _x_x_10; float x_19, _x_x_19; float x_21, _x_x_21; float x_11, _x_x_11; float x_22, _x_x_22; float x_13, _x_x_13; float x_14, _x_x_14; float x_26, _x_x_26; float x_15, _x_x_15; float x_17, _x_x_17; float x_7, _x_x_7; float x_23, _x_x_23; float x_24, _x_x_24; float x_16, _x_x_16; float x_29, _x_x_29; float x_30, _x_x_30; float x_27, _x_x_27; int __steps_to_fair = __VERIFIER_nondet_int(); x_31 = __VERIFIER_nondet_float(); _J3102 = __VERIFIER_nondet_bool(); _J3096 = __VERIFIER_nondet_bool(); _EL_U_3075 = __VERIFIER_nondet_bool(); x_28 = __VERIFIER_nondet_float(); x_12 = __VERIFIER_nondet_float(); x_20 = __VERIFIER_nondet_float(); x_9 = __VERIFIER_nondet_float(); x_3 = __VERIFIER_nondet_float(); x_18 = __VERIFIER_nondet_float(); x_0 = __VERIFIER_nondet_float(); _EL_U_3077 = __VERIFIER_nondet_bool(); x_25 = __VERIFIER_nondet_float(); x_2 = __VERIFIER_nondet_float(); x_4 = __VERIFIER_nondet_float(); x_1 = __VERIFIER_nondet_float(); x_6 = __VERIFIER_nondet_float(); x_5 = __VERIFIER_nondet_float(); x_8 = __VERIFIER_nondet_float(); x_10 = __VERIFIER_nondet_float(); x_19 = __VERIFIER_nondet_float(); x_21 = __VERIFIER_nondet_float(); x_11 = __VERIFIER_nondet_float(); x_22 = __VERIFIER_nondet_float(); x_13 = __VERIFIER_nondet_float(); x_14 = __VERIFIER_nondet_float(); x_26 = __VERIFIER_nondet_float(); x_15 = __VERIFIER_nondet_float(); x_17 = __VERIFIER_nondet_float(); x_7 = __VERIFIER_nondet_float(); x_23 = __VERIFIER_nondet_float(); x_24 = __VERIFIER_nondet_float(); x_16 = __VERIFIER_nondet_float(); x_29 = __VERIFIER_nondet_float(); x_30 = __VERIFIER_nondet_float(); x_27 = __VERIFIER_nondet_float(); bool __ok = (1 && ((( !(_EL_U_3077 || ( !(( !(( !(-18.0 <= (x_3 + (-1.0 * x_9)))) && ((x_20 + (-1.0 * x_28)) <= 10.0))) || _EL_U_3075)))) && ( !_J3096)) && ( !_J3102))); while (__steps_to_fair >= 0 && __ok) { if ((_J3096 && _J3102)) { __steps_to_fair = __VERIFIER_nondet_int(); } else { __steps_to_fair--; } _x_x_31 = __VERIFIER_nondet_float(); _x__J3102 = __VERIFIER_nondet_bool(); _x__J3096 = __VERIFIER_nondet_bool(); _x__EL_U_3075 = __VERIFIER_nondet_bool(); _x_x_28 = __VERIFIER_nondet_float(); _x_x_12 = __VERIFIER_nondet_float(); _x_x_20 = __VERIFIER_nondet_float(); _x_x_9 = __VERIFIER_nondet_float(); _x_x_3 = __VERIFIER_nondet_float(); _x_x_18 = __VERIFIER_nondet_float(); _x_x_0 = __VERIFIER_nondet_float(); _x__EL_U_3077 = __VERIFIER_nondet_bool(); _x_x_25 = __VERIFIER_nondet_float(); _x_x_2 = __VERIFIER_nondet_float(); _x_x_4 = __VERIFIER_nondet_float(); _x_x_1 = __VERIFIER_nondet_float(); _x_x_6 = __VERIFIER_nondet_float(); _x_x_5 = __VERIFIER_nondet_float(); _x_x_8 = __VERIFIER_nondet_float(); _x_x_10 = __VERIFIER_nondet_float(); _x_x_19 = __VERIFIER_nondet_float(); _x_x_21 = __VERIFIER_nondet_float(); _x_x_11 = __VERIFIER_nondet_float(); _x_x_22 = __VERIFIER_nondet_float(); _x_x_13 = __VERIFIER_nondet_float(); _x_x_14 = __VERIFIER_nondet_float(); _x_x_26 = __VERIFIER_nondet_float(); _x_x_15 = __VERIFIER_nondet_float(); _x_x_17 = __VERIFIER_nondet_float(); _x_x_7 = __VERIFIER_nondet_float(); _x_x_23 = __VERIFIER_nondet_float(); _x_x_24 = __VERIFIER_nondet_float(); _x_x_16 = __VERIFIER_nondet_float(); _x_x_29 = __VERIFIER_nondet_float(); _x_x_30 = __VERIFIER_nondet_float(); _x_x_27 = __VERIFIER_nondet_float(); __ok = ((((((((((((((((((((((((((((((((((((x_31 + (-1.0 * _x_x_0)) <= -15.0) && (((x_30 + (-1.0 * _x_x_0)) <= -9.0) && (((x_29 + (-1.0 * _x_x_0)) <= -16.0) && (((x_26 + (-1.0 * _x_x_0)) <= -17.0) && (((x_25 + (-1.0 * _x_x_0)) <= -9.0) && (((x_24 + (-1.0 * _x_x_0)) <= -20.0) && (((x_23 + (-1.0 * _x_x_0)) <= -10.0) && (((x_22 + (-1.0 * _x_x_0)) <= -11.0) && (((x_20 + (-1.0 * _x_x_0)) <= -4.0) && (((x_19 + (-1.0 * _x_x_0)) <= -9.0) && (((x_17 + (-1.0 * _x_x_0)) <= -7.0) && (((x_14 + (-1.0 * _x_x_0)) <= -9.0) && (((x_12 + (-1.0 * _x_x_0)) <= -16.0) && (((x_11 + (-1.0 * _x_x_0)) <= -10.0) && (((x_8 + (-1.0 * _x_x_0)) <= -14.0) && ((x_10 + (-1.0 * _x_x_0)) <= -7.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_0)) == -15.0) || (((x_30 + (-1.0 * _x_x_0)) == -9.0) || (((x_29 + (-1.0 * _x_x_0)) == -16.0) || (((x_26 + (-1.0 * _x_x_0)) == -17.0) || (((x_25 + (-1.0 * _x_x_0)) == -9.0) || (((x_24 + (-1.0 * _x_x_0)) == -20.0) || (((x_23 + (-1.0 * _x_x_0)) == -10.0) || (((x_22 + (-1.0 * _x_x_0)) == -11.0) || (((x_20 + (-1.0 * _x_x_0)) == -4.0) || (((x_19 + (-1.0 * _x_x_0)) == -9.0) || (((x_17 + (-1.0 * _x_x_0)) == -7.0) || (((x_14 + (-1.0 * _x_x_0)) == -9.0) || (((x_12 + (-1.0 * _x_x_0)) == -16.0) || (((x_11 + (-1.0 * _x_x_0)) == -10.0) || (((x_8 + (-1.0 * _x_x_0)) == -14.0) || ((x_10 + (-1.0 * _x_x_0)) == -7.0))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_1)) <= -12.0) && (((x_27 + (-1.0 * _x_x_1)) <= -17.0) && (((x_26 + (-1.0 * _x_x_1)) <= -17.0) && (((x_24 + (-1.0 * _x_x_1)) <= -15.0) && (((x_22 + (-1.0 * _x_x_1)) <= -10.0) && (((x_21 + (-1.0 * _x_x_1)) <= -19.0) && (((x_19 + (-1.0 * _x_x_1)) <= -3.0) && (((x_18 + (-1.0 * _x_x_1)) <= -7.0) && (((x_16 + (-1.0 * _x_x_1)) <= -3.0) && (((x_14 + (-1.0 * _x_x_1)) <= -20.0) && (((x_13 + (-1.0 * _x_x_1)) <= -20.0) && (((x_11 + (-1.0 * _x_x_1)) <= -4.0) && (((x_8 + (-1.0 * _x_x_1)) <= -1.0) && (((x_6 + (-1.0 * _x_x_1)) <= -2.0) && (((x_0 + (-1.0 * _x_x_1)) <= -3.0) && ((x_2 + (-1.0 * _x_x_1)) <= -19.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_1)) == -12.0) || (((x_27 + (-1.0 * _x_x_1)) == -17.0) || (((x_26 + (-1.0 * _x_x_1)) == -17.0) || (((x_24 + (-1.0 * _x_x_1)) == -15.0) || (((x_22 + (-1.0 * _x_x_1)) == -10.0) || (((x_21 + (-1.0 * _x_x_1)) == -19.0) || (((x_19 + (-1.0 * _x_x_1)) == -3.0) || (((x_18 + (-1.0 * _x_x_1)) == -7.0) || (((x_16 + (-1.0 * _x_x_1)) == -3.0) || (((x_14 + (-1.0 * _x_x_1)) == -20.0) || (((x_13 + (-1.0 * _x_x_1)) == -20.0) || (((x_11 + (-1.0 * _x_x_1)) == -4.0) || (((x_8 + (-1.0 * _x_x_1)) == -1.0) || (((x_6 + (-1.0 * _x_x_1)) == -2.0) || (((x_0 + (-1.0 * _x_x_1)) == -3.0) || ((x_2 + (-1.0 * _x_x_1)) == -19.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_2)) <= -3.0) && (((x_29 + (-1.0 * _x_x_2)) <= -7.0) && (((x_25 + (-1.0 * _x_x_2)) <= -15.0) && (((x_24 + (-1.0 * _x_x_2)) <= -19.0) && (((x_20 + (-1.0 * _x_x_2)) <= -9.0) && (((x_19 + (-1.0 * _x_x_2)) <= -16.0) && (((x_18 + (-1.0 * _x_x_2)) <= -3.0) && (((x_17 + (-1.0 * _x_x_2)) <= -12.0) && (((x_14 + (-1.0 * _x_x_2)) <= -11.0) && (((x_13 + (-1.0 * _x_x_2)) <= -17.0) && (((x_12 + (-1.0 * _x_x_2)) <= -18.0) && (((x_11 + (-1.0 * _x_x_2)) <= -18.0) && (((x_10 + (-1.0 * _x_x_2)) <= -16.0) && (((x_9 + (-1.0 * _x_x_2)) <= -16.0) && (((x_3 + (-1.0 * _x_x_2)) <= -12.0) && ((x_4 + (-1.0 * _x_x_2)) <= -6.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_2)) == -3.0) || (((x_29 + (-1.0 * _x_x_2)) == -7.0) || (((x_25 + (-1.0 * _x_x_2)) == -15.0) || (((x_24 + (-1.0 * _x_x_2)) == -19.0) || (((x_20 + (-1.0 * _x_x_2)) == -9.0) || (((x_19 + (-1.0 * _x_x_2)) == -16.0) || (((x_18 + (-1.0 * _x_x_2)) == -3.0) || (((x_17 + (-1.0 * _x_x_2)) == -12.0) || (((x_14 + (-1.0 * _x_x_2)) == -11.0) || (((x_13 + (-1.0 * _x_x_2)) == -17.0) || (((x_12 + (-1.0 * _x_x_2)) == -18.0) || (((x_11 + (-1.0 * _x_x_2)) == -18.0) || (((x_10 + (-1.0 * _x_x_2)) == -16.0) || (((x_9 + (-1.0 * _x_x_2)) == -16.0) || (((x_3 + (-1.0 * _x_x_2)) == -12.0) || ((x_4 + (-1.0 * _x_x_2)) == -6.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_3)) <= -9.0) && (((x_30 + (-1.0 * _x_x_3)) <= -5.0) && (((x_28 + (-1.0 * _x_x_3)) <= -16.0) && (((x_27 + (-1.0 * _x_x_3)) <= -17.0) && (((x_25 + (-1.0 * _x_x_3)) <= -16.0) && (((x_24 + (-1.0 * _x_x_3)) <= -9.0) && (((x_21 + (-1.0 * _x_x_3)) <= -3.0) && (((x_18 + (-1.0 * _x_x_3)) <= -3.0) && (((x_17 + (-1.0 * _x_x_3)) <= -18.0) && (((x_15 + (-1.0 * _x_x_3)) <= -7.0) && (((x_7 + (-1.0 * _x_x_3)) <= -15.0) && (((x_6 + (-1.0 * _x_x_3)) <= -11.0) && (((x_5 + (-1.0 * _x_x_3)) <= -16.0) && (((x_4 + (-1.0 * _x_x_3)) <= -7.0) && (((x_0 + (-1.0 * _x_x_3)) <= -7.0) && ((x_2 + (-1.0 * _x_x_3)) <= -9.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_3)) == -9.0) || (((x_30 + (-1.0 * _x_x_3)) == -5.0) || (((x_28 + (-1.0 * _x_x_3)) == -16.0) || (((x_27 + (-1.0 * _x_x_3)) == -17.0) || (((x_25 + (-1.0 * _x_x_3)) == -16.0) || (((x_24 + (-1.0 * _x_x_3)) == -9.0) || (((x_21 + (-1.0 * _x_x_3)) == -3.0) || (((x_18 + (-1.0 * _x_x_3)) == -3.0) || (((x_17 + (-1.0 * _x_x_3)) == -18.0) || (((x_15 + (-1.0 * _x_x_3)) == -7.0) || (((x_7 + (-1.0 * _x_x_3)) == -15.0) || (((x_6 + (-1.0 * _x_x_3)) == -11.0) || (((x_5 + (-1.0 * _x_x_3)) == -16.0) || (((x_4 + (-1.0 * _x_x_3)) == -7.0) || (((x_0 + (-1.0 * _x_x_3)) == -7.0) || ((x_2 + (-1.0 * _x_x_3)) == -9.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_4)) <= -12.0) && (((x_28 + (-1.0 * _x_x_4)) <= -16.0) && (((x_27 + (-1.0 * _x_x_4)) <= -8.0) && (((x_25 + (-1.0 * _x_x_4)) <= -13.0) && (((x_23 + (-1.0 * _x_x_4)) <= -13.0) && (((x_21 + (-1.0 * _x_x_4)) <= -6.0) && (((x_20 + (-1.0 * _x_x_4)) <= -7.0) && (((x_19 + (-1.0 * _x_x_4)) <= -4.0) && (((x_18 + (-1.0 * _x_x_4)) <= -1.0) && (((x_13 + (-1.0 * _x_x_4)) <= -4.0) && (((x_12 + (-1.0 * _x_x_4)) <= -16.0) && (((x_11 + (-1.0 * _x_x_4)) <= -14.0) && (((x_10 + (-1.0 * _x_x_4)) <= -4.0) && (((x_6 + (-1.0 * _x_x_4)) <= -6.0) && (((x_0 + (-1.0 * _x_x_4)) <= -15.0) && ((x_5 + (-1.0 * _x_x_4)) <= -7.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_4)) == -12.0) || (((x_28 + (-1.0 * _x_x_4)) == -16.0) || (((x_27 + (-1.0 * _x_x_4)) == -8.0) || (((x_25 + (-1.0 * _x_x_4)) == -13.0) || (((x_23 + (-1.0 * _x_x_4)) == -13.0) || (((x_21 + (-1.0 * _x_x_4)) == -6.0) || (((x_20 + (-1.0 * _x_x_4)) == -7.0) || (((x_19 + (-1.0 * _x_x_4)) == -4.0) || (((x_18 + (-1.0 * _x_x_4)) == -1.0) || (((x_13 + (-1.0 * _x_x_4)) == -4.0) || (((x_12 + (-1.0 * _x_x_4)) == -16.0) || (((x_11 + (-1.0 * _x_x_4)) == -14.0) || (((x_10 + (-1.0 * _x_x_4)) == -4.0) || (((x_6 + (-1.0 * _x_x_4)) == -6.0) || (((x_0 + (-1.0 * _x_x_4)) == -15.0) || ((x_5 + (-1.0 * _x_x_4)) == -7.0)))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_5)) <= -7.0) && (((x_27 + (-1.0 * _x_x_5)) <= -15.0) && (((x_26 + (-1.0 * _x_x_5)) <= -18.0) && (((x_25 + (-1.0 * _x_x_5)) <= -10.0) && (((x_22 + (-1.0 * _x_x_5)) <= -11.0) && (((x_19 + (-1.0 * _x_x_5)) <= -7.0) && (((x_17 + (-1.0 * _x_x_5)) <= -2.0) && (((x_16 + (-1.0 * _x_x_5)) <= -7.0) && (((x_15 + (-1.0 * _x_x_5)) <= -2.0) && (((x_12 + (-1.0 * _x_x_5)) <= -2.0) && (((x_11 + (-1.0 * _x_x_5)) <= -19.0) && (((x_10 + (-1.0 * _x_x_5)) <= -1.0) && (((x_8 + (-1.0 * _x_x_5)) <= -12.0) && (((x_7 + (-1.0 * _x_x_5)) <= -15.0) && (((x_3 + (-1.0 * _x_x_5)) <= -15.0) && ((x_6 + (-1.0 * _x_x_5)) <= -6.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_5)) == -7.0) || (((x_27 + (-1.0 * _x_x_5)) == -15.0) || (((x_26 + (-1.0 * _x_x_5)) == -18.0) || (((x_25 + (-1.0 * _x_x_5)) == -10.0) || (((x_22 + (-1.0 * _x_x_5)) == -11.0) || (((x_19 + (-1.0 * _x_x_5)) == -7.0) || (((x_17 + (-1.0 * _x_x_5)) == -2.0) || (((x_16 + (-1.0 * _x_x_5)) == -7.0) || (((x_15 + (-1.0 * _x_x_5)) == -2.0) || (((x_12 + (-1.0 * _x_x_5)) == -2.0) || (((x_11 + (-1.0 * _x_x_5)) == -19.0) || (((x_10 + (-1.0 * _x_x_5)) == -1.0) || (((x_8 + (-1.0 * _x_x_5)) == -12.0) || (((x_7 + (-1.0 * _x_x_5)) == -15.0) || (((x_3 + (-1.0 * _x_x_5)) == -15.0) || ((x_6 + (-1.0 * _x_x_5)) == -6.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_6)) <= -11.0) && (((x_26 + (-1.0 * _x_x_6)) <= -5.0) && (((x_23 + (-1.0 * _x_x_6)) <= -9.0) && (((x_20 + (-1.0 * _x_x_6)) <= -17.0) && (((x_19 + (-1.0 * _x_x_6)) <= -5.0) && (((x_18 + (-1.0 * _x_x_6)) <= -20.0) && (((x_16 + (-1.0 * _x_x_6)) <= -4.0) && (((x_15 + (-1.0 * _x_x_6)) <= -17.0) && (((x_14 + (-1.0 * _x_x_6)) <= -11.0) && (((x_9 + (-1.0 * _x_x_6)) <= -9.0) && (((x_8 + (-1.0 * _x_x_6)) <= -7.0) && (((x_5 + (-1.0 * _x_x_6)) <= -4.0) && (((x_3 + (-1.0 * _x_x_6)) <= -13.0) && (((x_2 + (-1.0 * _x_x_6)) <= -3.0) && (((x_0 + (-1.0 * _x_x_6)) <= -5.0) && ((x_1 + (-1.0 * _x_x_6)) <= -20.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_6)) == -11.0) || (((x_26 + (-1.0 * _x_x_6)) == -5.0) || (((x_23 + (-1.0 * _x_x_6)) == -9.0) || (((x_20 + (-1.0 * _x_x_6)) == -17.0) || (((x_19 + (-1.0 * _x_x_6)) == -5.0) || (((x_18 + (-1.0 * _x_x_6)) == -20.0) || (((x_16 + (-1.0 * _x_x_6)) == -4.0) || (((x_15 + (-1.0 * _x_x_6)) == -17.0) || (((x_14 + (-1.0 * _x_x_6)) == -11.0) || (((x_9 + (-1.0 * _x_x_6)) == -9.0) || (((x_8 + (-1.0 * _x_x_6)) == -7.0) || (((x_5 + (-1.0 * _x_x_6)) == -4.0) || (((x_3 + (-1.0 * _x_x_6)) == -13.0) || (((x_2 + (-1.0 * _x_x_6)) == -3.0) || (((x_0 + (-1.0 * _x_x_6)) == -5.0) || ((x_1 + (-1.0 * _x_x_6)) == -20.0)))))))))))))))))) && ((((x_26 + (-1.0 * _x_x_7)) <= -12.0) && (((x_25 + (-1.0 * _x_x_7)) <= -18.0) && (((x_24 + (-1.0 * _x_x_7)) <= -3.0) && (((x_19 + (-1.0 * _x_x_7)) <= -12.0) && (((x_18 + (-1.0 * _x_x_7)) <= -14.0) && (((x_17 + (-1.0 * _x_x_7)) <= -19.0) && (((x_14 + (-1.0 * _x_x_7)) <= -2.0) && (((x_11 + (-1.0 * _x_x_7)) <= -16.0) && (((x_10 + (-1.0 * _x_x_7)) <= -19.0) && (((x_8 + (-1.0 * _x_x_7)) <= -7.0) && (((x_7 + (-1.0 * _x_x_7)) <= -19.0) && (((x_6 + (-1.0 * _x_x_7)) <= -9.0) && (((x_4 + (-1.0 * _x_x_7)) <= -18.0) && (((x_3 + (-1.0 * _x_x_7)) <= -9.0) && (((x_1 + (-1.0 * _x_x_7)) <= -4.0) && ((x_2 + (-1.0 * _x_x_7)) <= -14.0)))))))))))))))) && (((x_26 + (-1.0 * _x_x_7)) == -12.0) || (((x_25 + (-1.0 * _x_x_7)) == -18.0) || (((x_24 + (-1.0 * _x_x_7)) == -3.0) || (((x_19 + (-1.0 * _x_x_7)) == -12.0) || (((x_18 + (-1.0 * _x_x_7)) == -14.0) || (((x_17 + (-1.0 * _x_x_7)) == -19.0) || (((x_14 + (-1.0 * _x_x_7)) == -2.0) || (((x_11 + (-1.0 * _x_x_7)) == -16.0) || (((x_10 + (-1.0 * _x_x_7)) == -19.0) || (((x_8 + (-1.0 * _x_x_7)) == -7.0) || (((x_7 + (-1.0 * _x_x_7)) == -19.0) || (((x_6 + (-1.0 * _x_x_7)) == -9.0) || (((x_4 + (-1.0 * _x_x_7)) == -18.0) || (((x_3 + (-1.0 * _x_x_7)) == -9.0) || (((x_1 + (-1.0 * _x_x_7)) == -4.0) || ((x_2 + (-1.0 * _x_x_7)) == -14.0)))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_8)) <= -14.0) && (((x_28 + (-1.0 * _x_x_8)) <= -11.0) && (((x_26 + (-1.0 * _x_x_8)) <= -20.0) && (((x_21 + (-1.0 * _x_x_8)) <= -17.0) && (((x_20 + (-1.0 * _x_x_8)) <= -1.0) && (((x_19 + (-1.0 * _x_x_8)) <= -11.0) && (((x_18 + (-1.0 * _x_x_8)) <= -3.0) && (((x_17 + (-1.0 * _x_x_8)) <= -1.0) && (((x_16 + (-1.0 * _x_x_8)) <= -10.0) && (((x_12 + (-1.0 * _x_x_8)) <= -18.0) && (((x_10 + (-1.0 * _x_x_8)) <= -1.0) && (((x_9 + (-1.0 * _x_x_8)) <= -4.0) && (((x_5 + (-1.0 * _x_x_8)) <= -17.0) && (((x_4 + (-1.0 * _x_x_8)) <= -13.0) && (((x_0 + (-1.0 * _x_x_8)) <= -16.0) && ((x_1 + (-1.0 * _x_x_8)) <= -10.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_8)) == -14.0) || (((x_28 + (-1.0 * _x_x_8)) == -11.0) || (((x_26 + (-1.0 * _x_x_8)) == -20.0) || (((x_21 + (-1.0 * _x_x_8)) == -17.0) || (((x_20 + (-1.0 * _x_x_8)) == -1.0) || (((x_19 + (-1.0 * _x_x_8)) == -11.0) || (((x_18 + (-1.0 * _x_x_8)) == -3.0) || (((x_17 + (-1.0 * _x_x_8)) == -1.0) || (((x_16 + (-1.0 * _x_x_8)) == -10.0) || (((x_12 + (-1.0 * _x_x_8)) == -18.0) || (((x_10 + (-1.0 * _x_x_8)) == -1.0) || (((x_9 + (-1.0 * _x_x_8)) == -4.0) || (((x_5 + (-1.0 * _x_x_8)) == -17.0) || (((x_4 + (-1.0 * _x_x_8)) == -13.0) || (((x_0 + (-1.0 * _x_x_8)) == -16.0) || ((x_1 + (-1.0 * _x_x_8)) == -10.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_9)) <= -1.0) && (((x_30 + (-1.0 * _x_x_9)) <= -17.0) && (((x_28 + (-1.0 * _x_x_9)) <= -8.0) && (((x_26 + (-1.0 * _x_x_9)) <= -12.0) && (((x_25 + (-1.0 * _x_x_9)) <= -14.0) && (((x_23 + (-1.0 * _x_x_9)) <= -19.0) && (((x_22 + (-1.0 * _x_x_9)) <= -7.0) && (((x_20 + (-1.0 * _x_x_9)) <= -10.0) && (((x_17 + (-1.0 * _x_x_9)) <= -15.0) && (((x_16 + (-1.0 * _x_x_9)) <= -13.0) && (((x_12 + (-1.0 * _x_x_9)) <= -19.0) && (((x_9 + (-1.0 * _x_x_9)) <= -1.0) && (((x_8 + (-1.0 * _x_x_9)) <= -12.0) && (((x_5 + (-1.0 * _x_x_9)) <= -6.0) && (((x_1 + (-1.0 * _x_x_9)) <= -4.0) && ((x_3 + (-1.0 * _x_x_9)) <= -7.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_9)) == -1.0) || (((x_30 + (-1.0 * _x_x_9)) == -17.0) || (((x_28 + (-1.0 * _x_x_9)) == -8.0) || (((x_26 + (-1.0 * _x_x_9)) == -12.0) || (((x_25 + (-1.0 * _x_x_9)) == -14.0) || (((x_23 + (-1.0 * _x_x_9)) == -19.0) || (((x_22 + (-1.0 * _x_x_9)) == -7.0) || (((x_20 + (-1.0 * _x_x_9)) == -10.0) || (((x_17 + (-1.0 * _x_x_9)) == -15.0) || (((x_16 + (-1.0 * _x_x_9)) == -13.0) || (((x_12 + (-1.0 * _x_x_9)) == -19.0) || (((x_9 + (-1.0 * _x_x_9)) == -1.0) || (((x_8 + (-1.0 * _x_x_9)) == -12.0) || (((x_5 + (-1.0 * _x_x_9)) == -6.0) || (((x_1 + (-1.0 * _x_x_9)) == -4.0) || ((x_3 + (-1.0 * _x_x_9)) == -7.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_10)) <= -16.0) && (((x_27 + (-1.0 * _x_x_10)) <= -19.0) && (((x_25 + (-1.0 * _x_x_10)) <= -5.0) && (((x_24 + (-1.0 * _x_x_10)) <= -1.0) && (((x_19 + (-1.0 * _x_x_10)) <= -15.0) && (((x_18 + (-1.0 * _x_x_10)) <= -15.0) && (((x_16 + (-1.0 * _x_x_10)) <= -17.0) && (((x_13 + (-1.0 * _x_x_10)) <= -19.0) && (((x_11 + (-1.0 * _x_x_10)) <= -5.0) && (((x_9 + (-1.0 * _x_x_10)) <= -14.0) && (((x_7 + (-1.0 * _x_x_10)) <= -20.0) && (((x_5 + (-1.0 * _x_x_10)) <= -10.0) && (((x_4 + (-1.0 * _x_x_10)) <= -6.0) && (((x_3 + (-1.0 * _x_x_10)) <= -18.0) && (((x_1 + (-1.0 * _x_x_10)) <= -2.0) && ((x_2 + (-1.0 * _x_x_10)) <= -18.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_10)) == -16.0) || (((x_27 + (-1.0 * _x_x_10)) == -19.0) || (((x_25 + (-1.0 * _x_x_10)) == -5.0) || (((x_24 + (-1.0 * _x_x_10)) == -1.0) || (((x_19 + (-1.0 * _x_x_10)) == -15.0) || (((x_18 + (-1.0 * _x_x_10)) == -15.0) || (((x_16 + (-1.0 * _x_x_10)) == -17.0) || (((x_13 + (-1.0 * _x_x_10)) == -19.0) || (((x_11 + (-1.0 * _x_x_10)) == -5.0) || (((x_9 + (-1.0 * _x_x_10)) == -14.0) || (((x_7 + (-1.0 * _x_x_10)) == -20.0) || (((x_5 + (-1.0 * _x_x_10)) == -10.0) || (((x_4 + (-1.0 * _x_x_10)) == -6.0) || (((x_3 + (-1.0 * _x_x_10)) == -18.0) || (((x_1 + (-1.0 * _x_x_10)) == -2.0) || ((x_2 + (-1.0 * _x_x_10)) == -18.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_11)) <= -20.0) && (((x_28 + (-1.0 * _x_x_11)) <= -13.0) && (((x_26 + (-1.0 * _x_x_11)) <= -15.0) && (((x_25 + (-1.0 * _x_x_11)) <= -12.0) && (((x_23 + (-1.0 * _x_x_11)) <= -1.0) && (((x_22 + (-1.0 * _x_x_11)) <= -11.0) && (((x_20 + (-1.0 * _x_x_11)) <= -18.0) && (((x_19 + (-1.0 * _x_x_11)) <= -17.0) && (((x_17 + (-1.0 * _x_x_11)) <= -6.0) && (((x_15 + (-1.0 * _x_x_11)) <= -9.0) && (((x_12 + (-1.0 * _x_x_11)) <= -2.0) && (((x_11 + (-1.0 * _x_x_11)) <= -7.0) && (((x_9 + (-1.0 * _x_x_11)) <= -12.0) && (((x_8 + (-1.0 * _x_x_11)) <= -10.0) && (((x_2 + (-1.0 * _x_x_11)) <= -12.0) && ((x_5 + (-1.0 * _x_x_11)) <= -19.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_11)) == -20.0) || (((x_28 + (-1.0 * _x_x_11)) == -13.0) || (((x_26 + (-1.0 * _x_x_11)) == -15.0) || (((x_25 + (-1.0 * _x_x_11)) == -12.0) || (((x_23 + (-1.0 * _x_x_11)) == -1.0) || (((x_22 + (-1.0 * _x_x_11)) == -11.0) || (((x_20 + (-1.0 * _x_x_11)) == -18.0) || (((x_19 + (-1.0 * _x_x_11)) == -17.0) || (((x_17 + (-1.0 * _x_x_11)) == -6.0) || (((x_15 + (-1.0 * _x_x_11)) == -9.0) || (((x_12 + (-1.0 * _x_x_11)) == -2.0) || (((x_11 + (-1.0 * _x_x_11)) == -7.0) || (((x_9 + (-1.0 * _x_x_11)) == -12.0) || (((x_8 + (-1.0 * _x_x_11)) == -10.0) || (((x_2 + (-1.0 * _x_x_11)) == -12.0) || ((x_5 + (-1.0 * _x_x_11)) == -19.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_12)) <= -13.0) && (((x_26 + (-1.0 * _x_x_12)) <= -15.0) && (((x_22 + (-1.0 * _x_x_12)) <= -15.0) && (((x_20 + (-1.0 * _x_x_12)) <= -6.0) && (((x_19 + (-1.0 * _x_x_12)) <= -13.0) && (((x_18 + (-1.0 * _x_x_12)) <= -10.0) && (((x_17 + (-1.0 * _x_x_12)) <= -17.0) && (((x_16 + (-1.0 * _x_x_12)) <= -13.0) && (((x_12 + (-1.0 * _x_x_12)) <= -12.0) && (((x_11 + (-1.0 * _x_x_12)) <= -11.0) && (((x_9 + (-1.0 * _x_x_12)) <= -6.0) && (((x_7 + (-1.0 * _x_x_12)) <= -8.0) && (((x_6 + (-1.0 * _x_x_12)) <= -4.0) && (((x_4 + (-1.0 * _x_x_12)) <= -8.0) && (((x_0 + (-1.0 * _x_x_12)) <= -6.0) && ((x_1 + (-1.0 * _x_x_12)) <= -15.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_12)) == -13.0) || (((x_26 + (-1.0 * _x_x_12)) == -15.0) || (((x_22 + (-1.0 * _x_x_12)) == -15.0) || (((x_20 + (-1.0 * _x_x_12)) == -6.0) || (((x_19 + (-1.0 * _x_x_12)) == -13.0) || (((x_18 + (-1.0 * _x_x_12)) == -10.0) || (((x_17 + (-1.0 * _x_x_12)) == -17.0) || (((x_16 + (-1.0 * _x_x_12)) == -13.0) || (((x_12 + (-1.0 * _x_x_12)) == -12.0) || (((x_11 + (-1.0 * _x_x_12)) == -11.0) || (((x_9 + (-1.0 * _x_x_12)) == -6.0) || (((x_7 + (-1.0 * _x_x_12)) == -8.0) || (((x_6 + (-1.0 * _x_x_12)) == -4.0) || (((x_4 + (-1.0 * _x_x_12)) == -8.0) || (((x_0 + (-1.0 * _x_x_12)) == -6.0) || ((x_1 + (-1.0 * _x_x_12)) == -15.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_13)) <= -18.0) && (((x_28 + (-1.0 * _x_x_13)) <= -19.0) && (((x_27 + (-1.0 * _x_x_13)) <= -10.0) && (((x_26 + (-1.0 * _x_x_13)) <= -10.0) && (((x_25 + (-1.0 * _x_x_13)) <= -9.0) && (((x_23 + (-1.0 * _x_x_13)) <= -3.0) && (((x_19 + (-1.0 * _x_x_13)) <= -7.0) && (((x_16 + (-1.0 * _x_x_13)) <= -2.0) && (((x_14 + (-1.0 * _x_x_13)) <= -10.0) && (((x_12 + (-1.0 * _x_x_13)) <= -4.0) && (((x_9 + (-1.0 * _x_x_13)) <= -15.0) && (((x_8 + (-1.0 * _x_x_13)) <= -20.0) && (((x_7 + (-1.0 * _x_x_13)) <= -13.0) && (((x_5 + (-1.0 * _x_x_13)) <= -1.0) && (((x_0 + (-1.0 * _x_x_13)) <= -14.0) && ((x_3 + (-1.0 * _x_x_13)) <= -18.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_13)) == -18.0) || (((x_28 + (-1.0 * _x_x_13)) == -19.0) || (((x_27 + (-1.0 * _x_x_13)) == -10.0) || (((x_26 + (-1.0 * _x_x_13)) == -10.0) || (((x_25 + (-1.0 * _x_x_13)) == -9.0) || (((x_23 + (-1.0 * _x_x_13)) == -3.0) || (((x_19 + (-1.0 * _x_x_13)) == -7.0) || (((x_16 + (-1.0 * _x_x_13)) == -2.0) || (((x_14 + (-1.0 * _x_x_13)) == -10.0) || (((x_12 + (-1.0 * _x_x_13)) == -4.0) || (((x_9 + (-1.0 * _x_x_13)) == -15.0) || (((x_8 + (-1.0 * _x_x_13)) == -20.0) || (((x_7 + (-1.0 * _x_x_13)) == -13.0) || (((x_5 + (-1.0 * _x_x_13)) == -1.0) || (((x_0 + (-1.0 * _x_x_13)) == -14.0) || ((x_3 + (-1.0 * _x_x_13)) == -18.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_14)) <= -12.0) && (((x_30 + (-1.0 * _x_x_14)) <= -6.0) && (((x_29 + (-1.0 * _x_x_14)) <= -7.0) && (((x_28 + (-1.0 * _x_x_14)) <= -19.0) && (((x_27 + (-1.0 * _x_x_14)) <= -10.0) && (((x_21 + (-1.0 * _x_x_14)) <= -19.0) && (((x_20 + (-1.0 * _x_x_14)) <= -6.0) && (((x_18 + (-1.0 * _x_x_14)) <= -12.0) && (((x_13 + (-1.0 * _x_x_14)) <= -11.0) && (((x_12 + (-1.0 * _x_x_14)) <= -5.0) && (((x_11 + (-1.0 * _x_x_14)) <= -11.0) && (((x_10 + (-1.0 * _x_x_14)) <= -9.0) && (((x_7 + (-1.0 * _x_x_14)) <= -4.0) && (((x_6 + (-1.0 * _x_x_14)) <= -12.0) && (((x_3 + (-1.0 * _x_x_14)) <= -14.0) && ((x_4 + (-1.0 * _x_x_14)) <= -3.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_14)) == -12.0) || (((x_30 + (-1.0 * _x_x_14)) == -6.0) || (((x_29 + (-1.0 * _x_x_14)) == -7.0) || (((x_28 + (-1.0 * _x_x_14)) == -19.0) || (((x_27 + (-1.0 * _x_x_14)) == -10.0) || (((x_21 + (-1.0 * _x_x_14)) == -19.0) || (((x_20 + (-1.0 * _x_x_14)) == -6.0) || (((x_18 + (-1.0 * _x_x_14)) == -12.0) || (((x_13 + (-1.0 * _x_x_14)) == -11.0) || (((x_12 + (-1.0 * _x_x_14)) == -5.0) || (((x_11 + (-1.0 * _x_x_14)) == -11.0) || (((x_10 + (-1.0 * _x_x_14)) == -9.0) || (((x_7 + (-1.0 * _x_x_14)) == -4.0) || (((x_6 + (-1.0 * _x_x_14)) == -12.0) || (((x_3 + (-1.0 * _x_x_14)) == -14.0) || ((x_4 + (-1.0 * _x_x_14)) == -3.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_15)) <= -12.0) && (((x_30 + (-1.0 * _x_x_15)) <= -13.0) && (((x_29 + (-1.0 * _x_x_15)) <= -9.0) && (((x_25 + (-1.0 * _x_x_15)) <= -7.0) && (((x_24 + (-1.0 * _x_x_15)) <= -10.0) && (((x_20 + (-1.0 * _x_x_15)) <= -1.0) && (((x_19 + (-1.0 * _x_x_15)) <= -9.0) && (((x_16 + (-1.0 * _x_x_15)) <= -3.0) && (((x_15 + (-1.0 * _x_x_15)) <= -2.0) && (((x_13 + (-1.0 * _x_x_15)) <= -19.0) && (((x_11 + (-1.0 * _x_x_15)) <= -4.0) && (((x_9 + (-1.0 * _x_x_15)) <= -4.0) && (((x_6 + (-1.0 * _x_x_15)) <= -13.0) && (((x_5 + (-1.0 * _x_x_15)) <= -10.0) && (((x_2 + (-1.0 * _x_x_15)) <= -12.0) && ((x_4 + (-1.0 * _x_x_15)) <= -13.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_15)) == -12.0) || (((x_30 + (-1.0 * _x_x_15)) == -13.0) || (((x_29 + (-1.0 * _x_x_15)) == -9.0) || (((x_25 + (-1.0 * _x_x_15)) == -7.0) || (((x_24 + (-1.0 * _x_x_15)) == -10.0) || (((x_20 + (-1.0 * _x_x_15)) == -1.0) || (((x_19 + (-1.0 * _x_x_15)) == -9.0) || (((x_16 + (-1.0 * _x_x_15)) == -3.0) || (((x_15 + (-1.0 * _x_x_15)) == -2.0) || (((x_13 + (-1.0 * _x_x_15)) == -19.0) || (((x_11 + (-1.0 * _x_x_15)) == -4.0) || (((x_9 + (-1.0 * _x_x_15)) == -4.0) || (((x_6 + (-1.0 * _x_x_15)) == -13.0) || (((x_5 + (-1.0 * _x_x_15)) == -10.0) || (((x_2 + (-1.0 * _x_x_15)) == -12.0) || ((x_4 + (-1.0 * _x_x_15)) == -13.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_16)) <= -20.0) && (((x_27 + (-1.0 * _x_x_16)) <= -13.0) && (((x_26 + (-1.0 * _x_x_16)) <= -18.0) && (((x_25 + (-1.0 * _x_x_16)) <= -2.0) && (((x_24 + (-1.0 * _x_x_16)) <= -14.0) && (((x_23 + (-1.0 * _x_x_16)) <= -19.0) && (((x_22 + (-1.0 * _x_x_16)) <= -9.0) && (((x_19 + (-1.0 * _x_x_16)) <= -18.0) && (((x_18 + (-1.0 * _x_x_16)) <= -6.0) && (((x_17 + (-1.0 * _x_x_16)) <= -14.0) && (((x_12 + (-1.0 * _x_x_16)) <= -13.0) && (((x_11 + (-1.0 * _x_x_16)) <= -4.0) && (((x_10 + (-1.0 * _x_x_16)) <= -1.0) && (((x_7 + (-1.0 * _x_x_16)) <= -16.0) && (((x_1 + (-1.0 * _x_x_16)) <= -5.0) && ((x_2 + (-1.0 * _x_x_16)) <= -4.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_16)) == -20.0) || (((x_27 + (-1.0 * _x_x_16)) == -13.0) || (((x_26 + (-1.0 * _x_x_16)) == -18.0) || (((x_25 + (-1.0 * _x_x_16)) == -2.0) || (((x_24 + (-1.0 * _x_x_16)) == -14.0) || (((x_23 + (-1.0 * _x_x_16)) == -19.0) || (((x_22 + (-1.0 * _x_x_16)) == -9.0) || (((x_19 + (-1.0 * _x_x_16)) == -18.0) || (((x_18 + (-1.0 * _x_x_16)) == -6.0) || (((x_17 + (-1.0 * _x_x_16)) == -14.0) || (((x_12 + (-1.0 * _x_x_16)) == -13.0) || (((x_11 + (-1.0 * _x_x_16)) == -4.0) || (((x_10 + (-1.0 * _x_x_16)) == -1.0) || (((x_7 + (-1.0 * _x_x_16)) == -16.0) || (((x_1 + (-1.0 * _x_x_16)) == -5.0) || ((x_2 + (-1.0 * _x_x_16)) == -4.0)))))))))))))))))) && ((((x_28 + (-1.0 * _x_x_17)) <= -6.0) && (((x_27 + (-1.0 * _x_x_17)) <= -14.0) && (((x_26 + (-1.0 * _x_x_17)) <= -14.0) && (((x_25 + (-1.0 * _x_x_17)) <= -5.0) && (((x_23 + (-1.0 * _x_x_17)) <= -6.0) && (((x_21 + (-1.0 * _x_x_17)) <= -4.0) && (((x_18 + (-1.0 * _x_x_17)) <= -12.0) && (((x_17 + (-1.0 * _x_x_17)) <= -13.0) && (((x_16 + (-1.0 * _x_x_17)) <= -16.0) && (((x_15 + (-1.0 * _x_x_17)) <= -10.0) && (((x_11 + (-1.0 * _x_x_17)) <= -15.0) && (((x_10 + (-1.0 * _x_x_17)) <= -18.0) && (((x_9 + (-1.0 * _x_x_17)) <= -15.0) && (((x_6 + (-1.0 * _x_x_17)) <= -13.0) && (((x_0 + (-1.0 * _x_x_17)) <= -18.0) && ((x_2 + (-1.0 * _x_x_17)) <= -17.0)))))))))))))))) && (((x_28 + (-1.0 * _x_x_17)) == -6.0) || (((x_27 + (-1.0 * _x_x_17)) == -14.0) || (((x_26 + (-1.0 * _x_x_17)) == -14.0) || (((x_25 + (-1.0 * _x_x_17)) == -5.0) || (((x_23 + (-1.0 * _x_x_17)) == -6.0) || (((x_21 + (-1.0 * _x_x_17)) == -4.0) || (((x_18 + (-1.0 * _x_x_17)) == -12.0) || (((x_17 + (-1.0 * _x_x_17)) == -13.0) || (((x_16 + (-1.0 * _x_x_17)) == -16.0) || (((x_15 + (-1.0 * _x_x_17)) == -10.0) || (((x_11 + (-1.0 * _x_x_17)) == -15.0) || (((x_10 + (-1.0 * _x_x_17)) == -18.0) || (((x_9 + (-1.0 * _x_x_17)) == -15.0) || (((x_6 + (-1.0 * _x_x_17)) == -13.0) || (((x_0 + (-1.0 * _x_x_17)) == -18.0) || ((x_2 + (-1.0 * _x_x_17)) == -17.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_18)) <= -7.0) && (((x_30 + (-1.0 * _x_x_18)) <= -19.0) && (((x_27 + (-1.0 * _x_x_18)) <= -15.0) && (((x_26 + (-1.0 * _x_x_18)) <= -7.0) && (((x_21 + (-1.0 * _x_x_18)) <= -4.0) && (((x_20 + (-1.0 * _x_x_18)) <= -8.0) && (((x_19 + (-1.0 * _x_x_18)) <= -6.0) && (((x_16 + (-1.0 * _x_x_18)) <= -13.0) && (((x_14 + (-1.0 * _x_x_18)) <= -12.0) && (((x_12 + (-1.0 * _x_x_18)) <= -18.0) && (((x_11 + (-1.0 * _x_x_18)) <= -12.0) && (((x_10 + (-1.0 * _x_x_18)) <= -6.0) && (((x_9 + (-1.0 * _x_x_18)) <= -2.0) && (((x_5 + (-1.0 * _x_x_18)) <= -15.0) && (((x_2 + (-1.0 * _x_x_18)) <= -1.0) && ((x_3 + (-1.0 * _x_x_18)) <= -8.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_18)) == -7.0) || (((x_30 + (-1.0 * _x_x_18)) == -19.0) || (((x_27 + (-1.0 * _x_x_18)) == -15.0) || (((x_26 + (-1.0 * _x_x_18)) == -7.0) || (((x_21 + (-1.0 * _x_x_18)) == -4.0) || (((x_20 + (-1.0 * _x_x_18)) == -8.0) || (((x_19 + (-1.0 * _x_x_18)) == -6.0) || (((x_16 + (-1.0 * _x_x_18)) == -13.0) || (((x_14 + (-1.0 * _x_x_18)) == -12.0) || (((x_12 + (-1.0 * _x_x_18)) == -18.0) || (((x_11 + (-1.0 * _x_x_18)) == -12.0) || (((x_10 + (-1.0 * _x_x_18)) == -6.0) || (((x_9 + (-1.0 * _x_x_18)) == -2.0) || (((x_5 + (-1.0 * _x_x_18)) == -15.0) || (((x_2 + (-1.0 * _x_x_18)) == -1.0) || ((x_3 + (-1.0 * _x_x_18)) == -8.0)))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_19)) <= -3.0) && (((x_28 + (-1.0 * _x_x_19)) <= -19.0) && (((x_27 + (-1.0 * _x_x_19)) <= -15.0) && (((x_26 + (-1.0 * _x_x_19)) <= -13.0) && (((x_24 + (-1.0 * _x_x_19)) <= -16.0) && (((x_21 + (-1.0 * _x_x_19)) <= -3.0) && (((x_20 + (-1.0 * _x_x_19)) <= -18.0) && (((x_19 + (-1.0 * _x_x_19)) <= -5.0) && (((x_18 + (-1.0 * _x_x_19)) <= -16.0) && (((x_17 + (-1.0 * _x_x_19)) <= -17.0) && (((x_8 + (-1.0 * _x_x_19)) <= -12.0) && (((x_7 + (-1.0 * _x_x_19)) <= -19.0) && (((x_6 + (-1.0 * _x_x_19)) <= -8.0) && (((x_3 + (-1.0 * _x_x_19)) <= -17.0) && (((x_1 + (-1.0 * _x_x_19)) <= -2.0) && ((x_2 + (-1.0 * _x_x_19)) <= -16.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_19)) == -3.0) || (((x_28 + (-1.0 * _x_x_19)) == -19.0) || (((x_27 + (-1.0 * _x_x_19)) == -15.0) || (((x_26 + (-1.0 * _x_x_19)) == -13.0) || (((x_24 + (-1.0 * _x_x_19)) == -16.0) || (((x_21 + (-1.0 * _x_x_19)) == -3.0) || (((x_20 + (-1.0 * _x_x_19)) == -18.0) || (((x_19 + (-1.0 * _x_x_19)) == -5.0) || (((x_18 + (-1.0 * _x_x_19)) == -16.0) || (((x_17 + (-1.0 * _x_x_19)) == -17.0) || (((x_8 + (-1.0 * _x_x_19)) == -12.0) || (((x_7 + (-1.0 * _x_x_19)) == -19.0) || (((x_6 + (-1.0 * _x_x_19)) == -8.0) || (((x_3 + (-1.0 * _x_x_19)) == -17.0) || (((x_1 + (-1.0 * _x_x_19)) == -2.0) || ((x_2 + (-1.0 * _x_x_19)) == -16.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_20)) <= -20.0) && (((x_29 + (-1.0 * _x_x_20)) <= -17.0) && (((x_28 + (-1.0 * _x_x_20)) <= -10.0) && (((x_24 + (-1.0 * _x_x_20)) <= -3.0) && (((x_22 + (-1.0 * _x_x_20)) <= -12.0) && (((x_20 + (-1.0 * _x_x_20)) <= -1.0) && (((x_17 + (-1.0 * _x_x_20)) <= -14.0) && (((x_16 + (-1.0 * _x_x_20)) <= -17.0) && (((x_14 + (-1.0 * _x_x_20)) <= -16.0) && (((x_13 + (-1.0 * _x_x_20)) <= -10.0) && (((x_9 + (-1.0 * _x_x_20)) <= -3.0) && (((x_8 + (-1.0 * _x_x_20)) <= -15.0) && (((x_5 + (-1.0 * _x_x_20)) <= -12.0) && (((x_4 + (-1.0 * _x_x_20)) <= -11.0) && (((x_0 + (-1.0 * _x_x_20)) <= -19.0) && ((x_3 + (-1.0 * _x_x_20)) <= -1.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_20)) == -20.0) || (((x_29 + (-1.0 * _x_x_20)) == -17.0) || (((x_28 + (-1.0 * _x_x_20)) == -10.0) || (((x_24 + (-1.0 * _x_x_20)) == -3.0) || (((x_22 + (-1.0 * _x_x_20)) == -12.0) || (((x_20 + (-1.0 * _x_x_20)) == -1.0) || (((x_17 + (-1.0 * _x_x_20)) == -14.0) || (((x_16 + (-1.0 * _x_x_20)) == -17.0) || (((x_14 + (-1.0 * _x_x_20)) == -16.0) || (((x_13 + (-1.0 * _x_x_20)) == -10.0) || (((x_9 + (-1.0 * _x_x_20)) == -3.0) || (((x_8 + (-1.0 * _x_x_20)) == -15.0) || (((x_5 + (-1.0 * _x_x_20)) == -12.0) || (((x_4 + (-1.0 * _x_x_20)) == -11.0) || (((x_0 + (-1.0 * _x_x_20)) == -19.0) || ((x_3 + (-1.0 * _x_x_20)) == -1.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_21)) <= -5.0) && (((x_28 + (-1.0 * _x_x_21)) <= -20.0) && (((x_27 + (-1.0 * _x_x_21)) <= -10.0) && (((x_26 + (-1.0 * _x_x_21)) <= -6.0) && (((x_25 + (-1.0 * _x_x_21)) <= -15.0) && (((x_24 + (-1.0 * _x_x_21)) <= -1.0) && (((x_23 + (-1.0 * _x_x_21)) <= -9.0) && (((x_22 + (-1.0 * _x_x_21)) <= -12.0) && (((x_17 + (-1.0 * _x_x_21)) <= -12.0) && (((x_16 + (-1.0 * _x_x_21)) <= -10.0) && (((x_14 + (-1.0 * _x_x_21)) <= -7.0) && (((x_13 + (-1.0 * _x_x_21)) <= -4.0) && (((x_10 + (-1.0 * _x_x_21)) <= -3.0) && (((x_9 + (-1.0 * _x_x_21)) <= -13.0) && (((x_3 + (-1.0 * _x_x_21)) <= -15.0) && ((x_4 + (-1.0 * _x_x_21)) <= -5.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_21)) == -5.0) || (((x_28 + (-1.0 * _x_x_21)) == -20.0) || (((x_27 + (-1.0 * _x_x_21)) == -10.0) || (((x_26 + (-1.0 * _x_x_21)) == -6.0) || (((x_25 + (-1.0 * _x_x_21)) == -15.0) || (((x_24 + (-1.0 * _x_x_21)) == -1.0) || (((x_23 + (-1.0 * _x_x_21)) == -9.0) || (((x_22 + (-1.0 * _x_x_21)) == -12.0) || (((x_17 + (-1.0 * _x_x_21)) == -12.0) || (((x_16 + (-1.0 * _x_x_21)) == -10.0) || (((x_14 + (-1.0 * _x_x_21)) == -7.0) || (((x_13 + (-1.0 * _x_x_21)) == -4.0) || (((x_10 + (-1.0 * _x_x_21)) == -3.0) || (((x_9 + (-1.0 * _x_x_21)) == -13.0) || (((x_3 + (-1.0 * _x_x_21)) == -15.0) || ((x_4 + (-1.0 * _x_x_21)) == -5.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_22)) <= -3.0) && (((x_30 + (-1.0 * _x_x_22)) <= -18.0) && (((x_29 + (-1.0 * _x_x_22)) <= -4.0) && (((x_28 + (-1.0 * _x_x_22)) <= -5.0) && (((x_27 + (-1.0 * _x_x_22)) <= -18.0) && (((x_26 + (-1.0 * _x_x_22)) <= -12.0) && (((x_19 + (-1.0 * _x_x_22)) <= -13.0) && (((x_17 + (-1.0 * _x_x_22)) <= -8.0) && (((x_16 + (-1.0 * _x_x_22)) <= -18.0) && (((x_14 + (-1.0 * _x_x_22)) <= -4.0) && (((x_13 + (-1.0 * _x_x_22)) <= -12.0) && (((x_12 + (-1.0 * _x_x_22)) <= -14.0) && (((x_8 + (-1.0 * _x_x_22)) <= -4.0) && (((x_5 + (-1.0 * _x_x_22)) <= -8.0) && (((x_0 + (-1.0 * _x_x_22)) <= -8.0) && ((x_3 + (-1.0 * _x_x_22)) <= -6.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_22)) == -3.0) || (((x_30 + (-1.0 * _x_x_22)) == -18.0) || (((x_29 + (-1.0 * _x_x_22)) == -4.0) || (((x_28 + (-1.0 * _x_x_22)) == -5.0) || (((x_27 + (-1.0 * _x_x_22)) == -18.0) || (((x_26 + (-1.0 * _x_x_22)) == -12.0) || (((x_19 + (-1.0 * _x_x_22)) == -13.0) || (((x_17 + (-1.0 * _x_x_22)) == -8.0) || (((x_16 + (-1.0 * _x_x_22)) == -18.0) || (((x_14 + (-1.0 * _x_x_22)) == -4.0) || (((x_13 + (-1.0 * _x_x_22)) == -12.0) || (((x_12 + (-1.0 * _x_x_22)) == -14.0) || (((x_8 + (-1.0 * _x_x_22)) == -4.0) || (((x_5 + (-1.0 * _x_x_22)) == -8.0) || (((x_0 + (-1.0 * _x_x_22)) == -8.0) || ((x_3 + (-1.0 * _x_x_22)) == -6.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_23)) <= -12.0) && (((x_28 + (-1.0 * _x_x_23)) <= -9.0) && (((x_25 + (-1.0 * _x_x_23)) <= -6.0) && (((x_24 + (-1.0 * _x_x_23)) <= -10.0) && (((x_21 + (-1.0 * _x_x_23)) <= -19.0) && (((x_20 + (-1.0 * _x_x_23)) <= -10.0) && (((x_19 + (-1.0 * _x_x_23)) <= -3.0) && (((x_17 + (-1.0 * _x_x_23)) <= -15.0) && (((x_15 + (-1.0 * _x_x_23)) <= -4.0) && (((x_14 + (-1.0 * _x_x_23)) <= -15.0) && (((x_11 + (-1.0 * _x_x_23)) <= -16.0) && (((x_10 + (-1.0 * _x_x_23)) <= -18.0) && (((x_8 + (-1.0 * _x_x_23)) <= -13.0) && (((x_7 + (-1.0 * _x_x_23)) <= -8.0) && (((x_1 + (-1.0 * _x_x_23)) <= -3.0) && ((x_2 + (-1.0 * _x_x_23)) <= -5.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_23)) == -12.0) || (((x_28 + (-1.0 * _x_x_23)) == -9.0) || (((x_25 + (-1.0 * _x_x_23)) == -6.0) || (((x_24 + (-1.0 * _x_x_23)) == -10.0) || (((x_21 + (-1.0 * _x_x_23)) == -19.0) || (((x_20 + (-1.0 * _x_x_23)) == -10.0) || (((x_19 + (-1.0 * _x_x_23)) == -3.0) || (((x_17 + (-1.0 * _x_x_23)) == -15.0) || (((x_15 + (-1.0 * _x_x_23)) == -4.0) || (((x_14 + (-1.0 * _x_x_23)) == -15.0) || (((x_11 + (-1.0 * _x_x_23)) == -16.0) || (((x_10 + (-1.0 * _x_x_23)) == -18.0) || (((x_8 + (-1.0 * _x_x_23)) == -13.0) || (((x_7 + (-1.0 * _x_x_23)) == -8.0) || (((x_1 + (-1.0 * _x_x_23)) == -3.0) || ((x_2 + (-1.0 * _x_x_23)) == -5.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_24)) <= -18.0) && (((x_30 + (-1.0 * _x_x_24)) <= -16.0) && (((x_26 + (-1.0 * _x_x_24)) <= -3.0) && (((x_24 + (-1.0 * _x_x_24)) <= -9.0) && (((x_23 + (-1.0 * _x_x_24)) <= -4.0) && (((x_19 + (-1.0 * _x_x_24)) <= -7.0) && (((x_17 + (-1.0 * _x_x_24)) <= -11.0) && (((x_15 + (-1.0 * _x_x_24)) <= -6.0) && (((x_14 + (-1.0 * _x_x_24)) <= -6.0) && (((x_13 + (-1.0 * _x_x_24)) <= -4.0) && (((x_10 + (-1.0 * _x_x_24)) <= -15.0) && (((x_9 + (-1.0 * _x_x_24)) <= -2.0) && (((x_7 + (-1.0 * _x_x_24)) <= -6.0) && (((x_6 + (-1.0 * _x_x_24)) <= -9.0) && (((x_0 + (-1.0 * _x_x_24)) <= -6.0) && ((x_3 + (-1.0 * _x_x_24)) <= -20.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_24)) == -18.0) || (((x_30 + (-1.0 * _x_x_24)) == -16.0) || (((x_26 + (-1.0 * _x_x_24)) == -3.0) || (((x_24 + (-1.0 * _x_x_24)) == -9.0) || (((x_23 + (-1.0 * _x_x_24)) == -4.0) || (((x_19 + (-1.0 * _x_x_24)) == -7.0) || (((x_17 + (-1.0 * _x_x_24)) == -11.0) || (((x_15 + (-1.0 * _x_x_24)) == -6.0) || (((x_14 + (-1.0 * _x_x_24)) == -6.0) || (((x_13 + (-1.0 * _x_x_24)) == -4.0) || (((x_10 + (-1.0 * _x_x_24)) == -15.0) || (((x_9 + (-1.0 * _x_x_24)) == -2.0) || (((x_7 + (-1.0 * _x_x_24)) == -6.0) || (((x_6 + (-1.0 * _x_x_24)) == -9.0) || (((x_0 + (-1.0 * _x_x_24)) == -6.0) || ((x_3 + (-1.0 * _x_x_24)) == -20.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_25)) <= -13.0) && (((x_27 + (-1.0 * _x_x_25)) <= -9.0) && (((x_26 + (-1.0 * _x_x_25)) <= -8.0) && (((x_25 + (-1.0 * _x_x_25)) <= -15.0) && (((x_23 + (-1.0 * _x_x_25)) <= -11.0) && (((x_22 + (-1.0 * _x_x_25)) <= -14.0) && (((x_21 + (-1.0 * _x_x_25)) <= -8.0) && (((x_18 + (-1.0 * _x_x_25)) <= -19.0) && (((x_17 + (-1.0 * _x_x_25)) <= -20.0) && (((x_15 + (-1.0 * _x_x_25)) <= -4.0) && (((x_12 + (-1.0 * _x_x_25)) <= -8.0) && (((x_11 + (-1.0 * _x_x_25)) <= -8.0) && (((x_10 + (-1.0 * _x_x_25)) <= -19.0) && (((x_9 + (-1.0 * _x_x_25)) <= -18.0) && (((x_2 + (-1.0 * _x_x_25)) <= -10.0) && ((x_7 + (-1.0 * _x_x_25)) <= -2.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_25)) == -13.0) || (((x_27 + (-1.0 * _x_x_25)) == -9.0) || (((x_26 + (-1.0 * _x_x_25)) == -8.0) || (((x_25 + (-1.0 * _x_x_25)) == -15.0) || (((x_23 + (-1.0 * _x_x_25)) == -11.0) || (((x_22 + (-1.0 * _x_x_25)) == -14.0) || (((x_21 + (-1.0 * _x_x_25)) == -8.0) || (((x_18 + (-1.0 * _x_x_25)) == -19.0) || (((x_17 + (-1.0 * _x_x_25)) == -20.0) || (((x_15 + (-1.0 * _x_x_25)) == -4.0) || (((x_12 + (-1.0 * _x_x_25)) == -8.0) || (((x_11 + (-1.0 * _x_x_25)) == -8.0) || (((x_10 + (-1.0 * _x_x_25)) == -19.0) || (((x_9 + (-1.0 * _x_x_25)) == -18.0) || (((x_2 + (-1.0 * _x_x_25)) == -10.0) || ((x_7 + (-1.0 * _x_x_25)) == -2.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_26)) <= -11.0) && (((x_28 + (-1.0 * _x_x_26)) <= -9.0) && (((x_25 + (-1.0 * _x_x_26)) <= -9.0) && (((x_24 + (-1.0 * _x_x_26)) <= -10.0) && (((x_23 + (-1.0 * _x_x_26)) <= -20.0) && (((x_22 + (-1.0 * _x_x_26)) <= -11.0) && (((x_20 + (-1.0 * _x_x_26)) <= -10.0) && (((x_18 + (-1.0 * _x_x_26)) <= -18.0) && (((x_15 + (-1.0 * _x_x_26)) <= -11.0) && (((x_14 + (-1.0 * _x_x_26)) <= -2.0) && (((x_13 + (-1.0 * _x_x_26)) <= -10.0) && (((x_9 + (-1.0 * _x_x_26)) <= -8.0) && (((x_7 + (-1.0 * _x_x_26)) <= -11.0) && (((x_3 + (-1.0 * _x_x_26)) <= -11.0) && (((x_0 + (-1.0 * _x_x_26)) <= -3.0) && ((x_2 + (-1.0 * _x_x_26)) <= -10.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_26)) == -11.0) || (((x_28 + (-1.0 * _x_x_26)) == -9.0) || (((x_25 + (-1.0 * _x_x_26)) == -9.0) || (((x_24 + (-1.0 * _x_x_26)) == -10.0) || (((x_23 + (-1.0 * _x_x_26)) == -20.0) || (((x_22 + (-1.0 * _x_x_26)) == -11.0) || (((x_20 + (-1.0 * _x_x_26)) == -10.0) || (((x_18 + (-1.0 * _x_x_26)) == -18.0) || (((x_15 + (-1.0 * _x_x_26)) == -11.0) || (((x_14 + (-1.0 * _x_x_26)) == -2.0) || (((x_13 + (-1.0 * _x_x_26)) == -10.0) || (((x_9 + (-1.0 * _x_x_26)) == -8.0) || (((x_7 + (-1.0 * _x_x_26)) == -11.0) || (((x_3 + (-1.0 * _x_x_26)) == -11.0) || (((x_0 + (-1.0 * _x_x_26)) == -3.0) || ((x_2 + (-1.0 * _x_x_26)) == -10.0)))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_27)) <= -17.0) && (((x_29 + (-1.0 * _x_x_27)) <= -17.0) && (((x_26 + (-1.0 * _x_x_27)) <= -16.0) && (((x_24 + (-1.0 * _x_x_27)) <= -7.0) && (((x_23 + (-1.0 * _x_x_27)) <= -13.0) && (((x_21 + (-1.0 * _x_x_27)) <= -8.0) && (((x_20 + (-1.0 * _x_x_27)) <= -16.0) && (((x_19 + (-1.0 * _x_x_27)) <= -11.0) && (((x_18 + (-1.0 * _x_x_27)) <= -12.0) && (((x_16 + (-1.0 * _x_x_27)) <= -12.0) && (((x_15 + (-1.0 * _x_x_27)) <= -5.0) && (((x_14 + (-1.0 * _x_x_27)) <= -15.0) && (((x_13 + (-1.0 * _x_x_27)) <= -17.0) && (((x_5 + (-1.0 * _x_x_27)) <= -8.0) && (((x_1 + (-1.0 * _x_x_27)) <= -20.0) && ((x_4 + (-1.0 * _x_x_27)) <= -5.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_27)) == -17.0) || (((x_29 + (-1.0 * _x_x_27)) == -17.0) || (((x_26 + (-1.0 * _x_x_27)) == -16.0) || (((x_24 + (-1.0 * _x_x_27)) == -7.0) || (((x_23 + (-1.0 * _x_x_27)) == -13.0) || (((x_21 + (-1.0 * _x_x_27)) == -8.0) || (((x_20 + (-1.0 * _x_x_27)) == -16.0) || (((x_19 + (-1.0 * _x_x_27)) == -11.0) || (((x_18 + (-1.0 * _x_x_27)) == -12.0) || (((x_16 + (-1.0 * _x_x_27)) == -12.0) || (((x_15 + (-1.0 * _x_x_27)) == -5.0) || (((x_14 + (-1.0 * _x_x_27)) == -15.0) || (((x_13 + (-1.0 * _x_x_27)) == -17.0) || (((x_5 + (-1.0 * _x_x_27)) == -8.0) || (((x_1 + (-1.0 * _x_x_27)) == -20.0) || ((x_4 + (-1.0 * _x_x_27)) == -5.0)))))))))))))))))) && ((((x_31 + (-1.0 * _x_x_28)) <= -5.0) && (((x_30 + (-1.0 * _x_x_28)) <= -10.0) && (((x_27 + (-1.0 * _x_x_28)) <= -8.0) && (((x_26 + (-1.0 * _x_x_28)) <= -19.0) && (((x_25 + (-1.0 * _x_x_28)) <= -18.0) && (((x_20 + (-1.0 * _x_x_28)) <= -20.0) && (((x_18 + (-1.0 * _x_x_28)) <= -12.0) && (((x_17 + (-1.0 * _x_x_28)) <= -19.0) && (((x_16 + (-1.0 * _x_x_28)) <= -9.0) && (((x_14 + (-1.0 * _x_x_28)) <= -15.0) && (((x_13 + (-1.0 * _x_x_28)) <= -2.0) && (((x_12 + (-1.0 * _x_x_28)) <= -2.0) && (((x_11 + (-1.0 * _x_x_28)) <= -18.0) && (((x_7 + (-1.0 * _x_x_28)) <= -5.0) && (((x_3 + (-1.0 * _x_x_28)) <= -17.0) && ((x_4 + (-1.0 * _x_x_28)) <= -3.0)))))))))))))))) && (((x_31 + (-1.0 * _x_x_28)) == -5.0) || (((x_30 + (-1.0 * _x_x_28)) == -10.0) || (((x_27 + (-1.0 * _x_x_28)) == -8.0) || (((x_26 + (-1.0 * _x_x_28)) == -19.0) || (((x_25 + (-1.0 * _x_x_28)) == -18.0) || (((x_20 + (-1.0 * _x_x_28)) == -20.0) || (((x_18 + (-1.0 * _x_x_28)) == -12.0) || (((x_17 + (-1.0 * _x_x_28)) == -19.0) || (((x_16 + (-1.0 * _x_x_28)) == -9.0) || (((x_14 + (-1.0 * _x_x_28)) == -15.0) || (((x_13 + (-1.0 * _x_x_28)) == -2.0) || (((x_12 + (-1.0 * _x_x_28)) == -2.0) || (((x_11 + (-1.0 * _x_x_28)) == -18.0) || (((x_7 + (-1.0 * _x_x_28)) == -5.0) || (((x_3 + (-1.0 * _x_x_28)) == -17.0) || ((x_4 + (-1.0 * _x_x_28)) == -3.0)))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_29)) <= -16.0) && (((x_28 + (-1.0 * _x_x_29)) <= -16.0) && (((x_25 + (-1.0 * _x_x_29)) <= -12.0) && (((x_24 + (-1.0 * _x_x_29)) <= -1.0) && (((x_23 + (-1.0 * _x_x_29)) <= -1.0) && (((x_22 + (-1.0 * _x_x_29)) <= -13.0) && (((x_18 + (-1.0 * _x_x_29)) <= -7.0) && (((x_17 + (-1.0 * _x_x_29)) <= -19.0) && (((x_14 + (-1.0 * _x_x_29)) <= -1.0) && (((x_12 + (-1.0 * _x_x_29)) <= -9.0) && (((x_10 + (-1.0 * _x_x_29)) <= -16.0) && (((x_6 + (-1.0 * _x_x_29)) <= -1.0) && (((x_5 + (-1.0 * _x_x_29)) <= -12.0) && (((x_3 + (-1.0 * _x_x_29)) <= -8.0) && (((x_0 + (-1.0 * _x_x_29)) <= -13.0) && ((x_1 + (-1.0 * _x_x_29)) <= -5.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_29)) == -16.0) || (((x_28 + (-1.0 * _x_x_29)) == -16.0) || (((x_25 + (-1.0 * _x_x_29)) == -12.0) || (((x_24 + (-1.0 * _x_x_29)) == -1.0) || (((x_23 + (-1.0 * _x_x_29)) == -1.0) || (((x_22 + (-1.0 * _x_x_29)) == -13.0) || (((x_18 + (-1.0 * _x_x_29)) == -7.0) || (((x_17 + (-1.0 * _x_x_29)) == -19.0) || (((x_14 + (-1.0 * _x_x_29)) == -1.0) || (((x_12 + (-1.0 * _x_x_29)) == -9.0) || (((x_10 + (-1.0 * _x_x_29)) == -16.0) || (((x_6 + (-1.0 * _x_x_29)) == -1.0) || (((x_5 + (-1.0 * _x_x_29)) == -12.0) || (((x_3 + (-1.0 * _x_x_29)) == -8.0) || (((x_0 + (-1.0 * _x_x_29)) == -13.0) || ((x_1 + (-1.0 * _x_x_29)) == -5.0)))))))))))))))))) && ((((x_29 + (-1.0 * _x_x_30)) <= -12.0) && (((x_28 + (-1.0 * _x_x_30)) <= -5.0) && (((x_26 + (-1.0 * _x_x_30)) <= -10.0) && (((x_24 + (-1.0 * _x_x_30)) <= -10.0) && (((x_22 + (-1.0 * _x_x_30)) <= -17.0) && (((x_21 + (-1.0 * _x_x_30)) <= -13.0) && (((x_20 + (-1.0 * _x_x_30)) <= -1.0) && (((x_15 + (-1.0 * _x_x_30)) <= -5.0) && (((x_11 + (-1.0 * _x_x_30)) <= -2.0) && (((x_9 + (-1.0 * _x_x_30)) <= -15.0) && (((x_8 + (-1.0 * _x_x_30)) <= -18.0) && (((x_6 + (-1.0 * _x_x_30)) <= -19.0) && (((x_4 + (-1.0 * _x_x_30)) <= -13.0) && (((x_2 + (-1.0 * _x_x_30)) <= -5.0) && (((x_0 + (-1.0 * _x_x_30)) <= -14.0) && ((x_1 + (-1.0 * _x_x_30)) <= -11.0)))))))))))))))) && (((x_29 + (-1.0 * _x_x_30)) == -12.0) || (((x_28 + (-1.0 * _x_x_30)) == -5.0) || (((x_26 + (-1.0 * _x_x_30)) == -10.0) || (((x_24 + (-1.0 * _x_x_30)) == -10.0) || (((x_22 + (-1.0 * _x_x_30)) == -17.0) || (((x_21 + (-1.0 * _x_x_30)) == -13.0) || (((x_20 + (-1.0 * _x_x_30)) == -1.0) || (((x_15 + (-1.0 * _x_x_30)) == -5.0) || (((x_11 + (-1.0 * _x_x_30)) == -2.0) || (((x_9 + (-1.0 * _x_x_30)) == -15.0) || (((x_8 + (-1.0 * _x_x_30)) == -18.0) || (((x_6 + (-1.0 * _x_x_30)) == -19.0) || (((x_4 + (-1.0 * _x_x_30)) == -13.0) || (((x_2 + (-1.0 * _x_x_30)) == -5.0) || (((x_0 + (-1.0 * _x_x_30)) == -14.0) || ((x_1 + (-1.0 * _x_x_30)) == -11.0)))))))))))))))))) && ((((x_30 + (-1.0 * _x_x_31)) <= -3.0) && (((x_29 + (-1.0 * _x_x_31)) <= -11.0) && (((x_28 + (-1.0 * _x_x_31)) <= -4.0) && (((x_24 + (-1.0 * _x_x_31)) <= -19.0) && (((x_23 + (-1.0 * _x_x_31)) <= -2.0) && (((x_20 + (-1.0 * _x_x_31)) <= -3.0) && (((x_17 + (-1.0 * _x_x_31)) <= -9.0) && (((x_15 + (-1.0 * _x_x_31)) <= -14.0) && (((x_14 + (-1.0 * _x_x_31)) <= -17.0) && (((x_13 + (-1.0 * _x_x_31)) <= -17.0) && (((x_11 + (-1.0 * _x_x_31)) <= -19.0) && (((x_10 + (-1.0 * _x_x_31)) <= -14.0) && (((x_8 + (-1.0 * _x_x_31)) <= -20.0) && (((x_5 + (-1.0 * _x_x_31)) <= -14.0) && (((x_1 + (-1.0 * _x_x_31)) <= -8.0) && ((x_2 + (-1.0 * _x_x_31)) <= -12.0)))))))))))))))) && (((x_30 + (-1.0 * _x_x_31)) == -3.0) || (((x_29 + (-1.0 * _x_x_31)) == -11.0) || (((x_28 + (-1.0 * _x_x_31)) == -4.0) || (((x_24 + (-1.0 * _x_x_31)) == -19.0) || (((x_23 + (-1.0 * _x_x_31)) == -2.0) || (((x_20 + (-1.0 * _x_x_31)) == -3.0) || (((x_17 + (-1.0 * _x_x_31)) == -9.0) || (((x_15 + (-1.0 * _x_x_31)) == -14.0) || (((x_14 + (-1.0 * _x_x_31)) == -17.0) || (((x_13 + (-1.0 * _x_x_31)) == -17.0) || (((x_11 + (-1.0 * _x_x_31)) == -19.0) || (((x_10 + (-1.0 * _x_x_31)) == -14.0) || (((x_8 + (-1.0 * _x_x_31)) == -20.0) || (((x_5 + (-1.0 * _x_x_31)) == -14.0) || (((x_1 + (-1.0 * _x_x_31)) == -8.0) || ((x_2 + (-1.0 * _x_x_31)) == -12.0)))))))))))))))))) && ((((_EL_U_3075 == (_x__EL_U_3075 || ( !(((_x_x_20 + (-1.0 * _x_x_28)) <= 10.0) && ( !(-18.0 <= (_x_x_3 + (-1.0 * _x_x_9)))))))) && (_EL_U_3077 == (_x__EL_U_3077 || ( !(_x__EL_U_3075 || ( !(((_x_x_20 + (-1.0 * _x_x_28)) <= 10.0) && ( !(-18.0 <= (_x_x_3 + (-1.0 * _x_x_9))))))))))) && (_x__J3096 == (( !(_J3096 && _J3102)) && ((_J3096 && _J3102) || ((( !(( !(-18.0 <= (x_3 + (-1.0 * x_9)))) && ((x_20 + (-1.0 * x_28)) <= 10.0))) || ( !(( !(( !(-18.0 <= (x_3 + (-1.0 * x_9)))) && ((x_20 + (-1.0 * x_28)) <= 10.0))) || _EL_U_3075))) || _J3096))))) && (_x__J3102 == (( !(_J3096 && _J3102)) && ((_J3096 && _J3102) || ((( !(( !(( !(-18.0 <= (x_3 + (-1.0 * x_9)))) && ((x_20 + (-1.0 * x_28)) <= 10.0))) || _EL_U_3075)) || ( !(_EL_U_3077 || ( !(( !(( !(-18.0 <= (x_3 + (-1.0 * x_9)))) && ((x_20 + (-1.0 * x_28)) <= 10.0))) || _EL_U_3075))))) || _J3102)))))); x_31 = _x_x_31; _J3102 = _x__J3102; _J3096 = _x__J3096; _EL_U_3075 = _x__EL_U_3075; x_28 = _x_x_28; x_12 = _x_x_12; x_20 = _x_x_20; x_9 = _x_x_9; x_3 = _x_x_3; x_18 = _x_x_18; x_0 = _x_x_0; _EL_U_3077 = _x__EL_U_3077; x_25 = _x_x_25; x_2 = _x_x_2; x_4 = _x_x_4; x_1 = _x_x_1; x_6 = _x_x_6; x_5 = _x_x_5; x_8 = _x_x_8; x_10 = _x_x_10; x_19 = _x_x_19; x_21 = _x_x_21; x_11 = _x_x_11; x_22 = _x_x_22; x_13 = _x_x_13; x_14 = _x_x_14; x_26 = _x_x_26; x_15 = _x_x_15; x_17 = _x_x_17; x_7 = _x_x_7; x_23 = _x_x_23; x_24 = _x_x_24; x_16 = _x_x_16; x_29 = _x_x_29; x_30 = _x_x_30; x_27 = _x_x_27; } }
the_stack_data/86143.c
void foo() { // if ( ( ( union { int v; } ) {} ).v || ( ( union { int v; } ) {} ).v ); if ( ( ( union { int v; } ) {} ).v || ( ( union { int v; } ) {} ).v ) { } }
the_stack_data/660537.c
/* ** EPITECH PROJECT, 2021 ** Libmy ** File description: ** check if a string contains only uppercase */ int my_strlen(char const *); int my_str_isupper(char const *str) { int ok = 1; int i = 0; for (; ok && i < my_strlen(str); i++) { if ('A' <= str[i] && str[i] <= 'Z') ok = 1; else ok = 0; } return ok; }
the_stack_data/647271.c
#include <string.h> #include <zlib.h> #include <stdio.h> #include <inttypes.h> #include <stdlib.h> #include <assert.h> #define PACKAGE_VERSION "r439" //#define MAQ_LONGREADS #ifdef MAQ_LONGREADS # define MAX_READLEN 128 #else # define MAX_READLEN 64 #endif #define MAX_NAMELEN 36 #define MAQMAP_FORMAT_OLD 0 #define MAQMAP_FORMAT_NEW -1 #define PAIRFLAG_FF 0x01 #define PAIRFLAG_FR 0x02 #define PAIRFLAG_RF 0x04 #define PAIRFLAG_RR 0x08 #define PAIRFLAG_PAIRED 0x10 #define PAIRFLAG_DIFFCHR 0x20 #define PAIRFLAG_NOMATCH 0x40 #define PAIRFLAG_SW 0x80 typedef struct { uint8_t seq[MAX_READLEN]; /* the last base is the single-end mapping quality. */ uint8_t size, map_qual, info1, info2, c[2], flag, alt_qual; uint32_t seqid, pos; int dist; char name[MAX_NAMELEN]; } maqmap1_t; typedef struct { int format, n_ref; char **ref_name; uint64_t n_mapped_reads; maqmap1_t *mapped_reads; } maqmap_t; maqmap_t *maq_new_maqmap(void) { maqmap_t *mm = (maqmap_t*)calloc(1, sizeof(maqmap_t)); mm->format = MAQMAP_FORMAT_NEW; return mm; } void maq_delete_maqmap(maqmap_t *mm) { int i; if (mm == 0) return; for (i = 0; i < mm->n_ref; ++i) free(mm->ref_name[i]); free(mm->ref_name); free(mm->mapped_reads); free(mm); } maqmap_t *maqmap_read_header(gzFile fp) { maqmap_t *mm; int k, len; mm = maq_new_maqmap(); gzread(fp, &mm->format, sizeof(int)); if (mm->format != MAQMAP_FORMAT_NEW) { if (mm->format > 0) { fprintf(stderr, "** Obsolete map format is detected. Please use 'mapass2maq' command to convert the format.\n"); exit(3); } assert(mm->format == MAQMAP_FORMAT_NEW); } gzread(fp, &mm->n_ref, sizeof(int)); mm->ref_name = (char**)calloc(mm->n_ref, sizeof(char*)); for (k = 0; k != mm->n_ref; ++k) { gzread(fp, &len, sizeof(int)); mm->ref_name[k] = (char*)malloc(len * sizeof(char)); gzread(fp, mm->ref_name[k], len); } /* read number of mapped reads */ gzread(fp, &mm->n_mapped_reads, sizeof(uint64_t)); return mm; } void maq2tam_core(gzFile fp, const char *rg) { maqmap_t *mm; maqmap1_t mm1, *m1; int ret; m1 = &mm1; mm = maqmap_read_header(fp); while ((ret = gzread(fp, m1, sizeof(maqmap1_t))) == sizeof(maqmap1_t)) { int j, flag = 0, se_mapq = m1->seq[MAX_READLEN-1]; if (m1->flag) flag |= 1; if ((m1->flag&PAIRFLAG_PAIRED) || ((m1->flag&PAIRFLAG_SW) && m1->flag != 192)) flag |= 2; if (m1->flag == 192) flag |= 4; if (m1->flag == 64) flag |= 8; if (m1->pos&1) flag |= 0x10; if ((flag&1) && m1->dist != 0) { int c; if (m1->dist > 0) { if (m1->flag&(PAIRFLAG_FF|PAIRFLAG_RF)) c = 0; else if (m1->flag&(PAIRFLAG_FR|PAIRFLAG_RR)) c = 1; else c = m1->pos&1; } else { if (m1->flag&(PAIRFLAG_FF|PAIRFLAG_FR)) c = 0; else if (m1->flag&(PAIRFLAG_RF|PAIRFLAG_RR)) c = 1; else c = m1->pos&1; } if (c) flag |= 0x20; } if (m1->flag) { int l = strlen(m1->name); if (m1->name[l-2] == '/') { flag |= (m1->name[l-1] == '1')? 0x40 : 0x80; m1->name[l-2] = '\0'; } } printf("%s\t%d\t", m1->name, flag); printf("%s\t%d\t", mm->ref_name[m1->seqid], (m1->pos>>1)+1); if (m1->flag == 130) { int c = (int8_t)m1->seq[MAX_READLEN-1]; printf("%d\t", m1->alt_qual); if (c == 0) printf("%dM\t", m1->size); else { if (c > 0) printf("%dM%dI%dM\t", m1->map_qual, c, m1->size - m1->map_qual - c); else printf("%dM%dD%dM\t", m1->map_qual, -c, m1->size - m1->map_qual); } se_mapq = 0; // zero SE mapQ for reads aligned by SW } else { if (flag&4) printf("0\t*\t"); else printf("%d\t%dM\t", m1->map_qual, m1->size); } printf("*\t0\t%d\t", m1->dist); for (j = 0; j != m1->size; ++j) { if (m1->seq[j] == 0) putchar('N'); else putchar("ACGT"[m1->seq[j]>>6&3]); } putchar('\t'); for (j = 0; j != m1->size; ++j) putchar((m1->seq[j]&0x3f) + 33); putchar('\t'); if (rg) printf("RG:Z:%s\t", rg); if (flag&4) { // unmapped printf("MF:i:%d\n", m1->flag); } else { printf("MF:i:%d\t", m1->flag); if (m1->flag) printf("AM:i:%d\tSM:i:%d\t", m1->alt_qual, se_mapq); printf("NM:i:%d\tUQ:i:%d\tH0:i:%d\tH1:i:%d\n", m1->info1&0xf, m1->info2, m1->c[0], m1->c[1]); } } if (ret > 0) fprintf(stderr, "Truncated! Continue anyway.\n"); maq_delete_maqmap(mm); } int main(int argc, char *argv[]) { gzFile fp; if (argc == 1) { fprintf(stderr, "Version: %s\n", PACKAGE_VERSION); fprintf(stderr, "Usage: maq2sam <in.map> [<readGroup>]\n"); return 1; } fp = strcmp(argv[1], "-")? gzopen(argv[1], "r") : gzdopen(fileno(stdin), "r"); maq2tam_core(fp, argc > 2? argv[2] : 0); gzclose(fp); return 0; }
the_stack_data/153266881.c
/* $begin shp-proto */ int signed_high_prod(int x, int y); /* $end shp-proto */ /* $begin uhp-proto */ unsigned unsigned_high_prod(unsigned x, unsigned y); /* $end uhp-proto */ unsigned unsigned_high_prod(unsigned x, unsigned y) { unsigned p = (unsigned) signed_high_prod((int) x, (int) y); /* Solution omitted */ return p; }
the_stack_data/168893505.c
#include <stdio.h> #define MAXTITL 41 #define MAXAUTL 31 struct book { char title[MAXTITL]; char author[MAXAUTL]; float value; }; int main(void) { struct book readfirst; int score; printf("Enter test score: "); scanf("%d", &score); if (score >= 84) readfirst = (struct book) {"C", "F", 11.25}; else readfirst = (struct book) {"M", "F", 5.99}; return 0; }
the_stack_data/165764528.c
/* ASCII font from Steph's Mini DevKit */ const unsigned int font_data[] = { // 20 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x00000000, 0x000FF000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0FF00FF0, 0xFFFFFFFF, 0x0FF00FF0, 0x0FF00FF0, 0xFFFFFFFF, 0x0FF00FF0, 0x00000000, 0x000FF000, 0x00FFFFF0, 0x0FF00000, 0x00FFFF00, 0x00000FF0, 0x0FFFFF00, 0x000FF000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF0FF00, 0x000FF000, 0x00FF0000, 0x0FF00FF0, 0x0F000FF0, 0x00000000, 0x000FFF00, 0x00FF0FF0, 0x000FFF00, 0x00FFF000, 0x0FF0FFFF, 0x0FF00FF0, 0x00FFF0FF, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FFF0, 0x000FFF00, 0x000FF000, 0x000FF000, 0x000FFF00, 0x0000FFF0, 0x00000000, 0x00000000, 0x0FFF0000, 0x00FFF000, 0x000FF000, 0x000FF000, 0x00FFF000, 0x0FFF0000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x00FFFF00, 0xFFFFFFFF, 0x00FFFF00, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x0FFFFFF0, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x00000FF0, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x0FF00000, 0x0F000000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FF0FFF0, 0x0FFF0FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x000FF000, 0x00FFF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x0000FF00, 0x000FF000, 0x0000FF00, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x0000FF00, 0x000FFF00, 0x00FFFF00, 0x0FF0FF00, 0x0FFFFFF0, 0x0000FF00, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x0FF00000, 0x0FFFFF00, 0x00000FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x00000FF0, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x00FF0000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x00FFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x00FFFFF0, 0x00000FF0, 0x0000FF00, 0x00FFF000, 0x00000000, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x00000000, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x00000000, 0x000FF000, 0x000FF000, 0x00000000, 0x000FF000, 0x000FF000, 0x00FF0000, 0x00000FF0, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x000FF000, 0x0000FF00, 0x00000FF0, 0x00000000, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x0FF00000, 0x00FF0000, 0x000FF000, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x0FF00000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0000FF00, 0x000FF000, 0x00000000, 0x000FF000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FF0FFF0, 0x0FF0FFF0, 0x0FF00000, 0x00FFFFF0, 0x00000000, 0x00000000, 0x000FF000, 0x00FFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFFF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x0FFFFF00, 0x0FF00FF0, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFF00, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FF00000, 0x0FF00000, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x0FFFF000, 0x0FF0FF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FF0FF00, 0x0FFFF000, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x0FF00000, 0x0FFFFF00, 0x0FF00000, 0x0FF00000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x0FF00000, 0x0FFFFF00, 0x0FF00000, 0x0FF00000, 0x0FF00000, 0x00000000, 0x00000000, 0x00FFFFF0, 0x0FF00000, 0x0FF00000, 0x0FF0FFF0, 0x0FF00FF0, 0x00FFFFF0, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFFF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x00000FF0, 0x00000FF0, 0x00000FF0, 0x00000FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF0FF00, 0x0FFFF000, 0x0FFFF000, 0x0FF0FF00, 0x0FF00FF0, 0x00000000, 0x00000000, 0x0FF00000, 0x0FF00000, 0x0FF00000, 0x0FF00000, 0x0FF00000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x0FF000FF, 0x0FFF0FFF, 0x0FFFFFFF, 0x0FF0F0FF, 0x0FF000FF, 0x0FF000FF, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FFF0FF0, 0x0FFFFFF0, 0x0FFFFFF0, 0x0FF0FFF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFF00, 0x0FF00000, 0x0FF00000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF0FF00, 0x00FF0FF0, 0x00000000, 0x00000000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFF00, 0x0FF0FF00, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00000, 0x00FFFF00, 0x00000FF0, 0x00000FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x000FF000, 0x00000000, 0x00000000, 0x0FF000FF, 0x0FF000FF, 0x0FF0F0FF, 0x0FFFFFFF, 0x0FFF0FFF, 0x0FF000FF, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x00FFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x000FF000, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x0FF00000, 0x0FFFFFF0, 0x00000000, 0x00000000, 0x000FFFF0, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FFFF0, 0x00000000, 0x00000000, 0x0F000000, 0x0FF00000, 0x00FF0000, 0x000FF000, 0x0000FF00, 0x00000FF0, 0x00000000, 0x00000000, 0x0FFFF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x0FFFF000, 0x00000000, 0x00000000, 0x0000F000, 0x000FFF00, 0x00FF0FF0, 0x0FF000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x000FF000, 0x00FFFF00, 0x0FFFFFF0, 0x0FFFFFF0, 0x00FFFF00, 0x000FF000, 0x00000000, 0x00000000, 0x00000000, 0x00FFFF00, 0x00000FF0, 0x00FFFFF0, 0x0FF00FF0, 0x00FFFFF0, 0x00000000, 0x00000000, 0x0FF00000, 0x0FF00000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFF00, 0x00000000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00000, 0x0FF00000, 0x0FF00000, 0x00FFFF00, 0x00000000, 0x00000000, 0x00000FF0, 0x00000FF0, 0x00FFFFF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFFF0, 0x00000000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FFFFFF0, 0x0FF00000, 0x00FFFF00, 0x00000000, 0x00000000, 0x0000FFF0, 0x000FF000, 0x00FFFFF0, 0x000FF000, 0x000FF000, 0x000FF000, 0x00000000, 0x00000000, 0x00000000, 0x00FFFFF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFFF0, 0x00000FF0, 0x0FFFFF00, 0x00000000, 0x0FF00000, 0x0FF00000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x000FF000, 0x00000000, 0x00FFF000, 0x000FF000, 0x000FF000, 0x00FFFF00, 0x00000000, 0x00000000, 0x00000FF0, 0x00000000, 0x00000FF0, 0x00000FF0, 0x00000FF0, 0x00000FF0, 0x00FFFF00, 0x00000000, 0x0FF00000, 0x0FF00000, 0x0FF0FF00, 0x0FFFF000, 0x0FF0FF00, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00FFF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x00FFFF00, 0x00000000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FFFFFFF, 0x0FFFFFFF, 0x0FF0F0FF, 0x0FF000FF, 0x00000000, 0x00000000, 0x00000000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00000000, 0x00FFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x00000000, 0x00000000, 0x00000000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00FF0, 0x0FFFFF00, 0x0FF00000, 0x0FF00000, 0x00000000, 0x00000000, 0x00FFFFF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFFF0, 0x00000FF0, 0x00000FF0, 0x00000000, 0x00000000, 0x0FFFFF00, 0x0FF00FF0, 0x0FF00000, 0x0FF00000, 0x0FF00000, 0x00000000, 0x00000000, 0x00000000, 0x00FFFFF0, 0x0FF00000, 0x00FFFF00, 0x00000FF0, 0x0FFFFF00, 0x00000000, 0x00000000, 0x000FF000, 0x0FFFFFF0, 0x000FF000, 0x000FF000, 0x000FF000, 0x0000FFF0, 0x00000000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFFF0, 0x00000000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFF00, 0x000FF000, 0x00000000, 0x00000000, 0x00000000, 0x0FF000FF, 0x0FF0F0FF, 0x0FFFFFFF, 0x00FFFFF0, 0x00FF0FF0, 0x00000000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x00FFFF00, 0x000FF000, 0x00FFFF00, 0x0FF00FF0, 0x00000000, 0x00000000, 0x00000000, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x00FFFFF0, 0x0000FF00, 0x0FFFF000, 0x00000000, 0x00000000, 0x0FFFFFF0, 0x0000FF00, 0x000FF000, 0x00FF0000, 0x0FFFFFF0, 0x00000000, // 7B 0x00000000, 0x0000FFF0, 0x000FF000, 0x000FF000, 0x00FFF000, 0x000FF000, 0x0000FFF0, 0x00000000, // 7C 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, 0x000FF000, // 7D 0x00000000, 0x0FFF0000, 0x000FF000, 0x000FF000, 0x000FFF00, 0x000FF000, 0x0FFF0000, 0x00000000, // 7E 0x00000000, 0x00FFF0FF, 0x0FF0FFF0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 7F 0x0000F000, 0x000FF000, 0x00FFF000, 0x0FFFF000, 0x00FFF000, 0x000FF000, 0x0000F000, 0x00000000, // 80 0x00000000, 0x00000000, 0x00000000, 0x000FFFFF, 0x000FFFFF, 0x000FF000, 0x000FF000, 0x000FF000, // 81 0x000FF000, 0x000FF000, 0x000FF000, 0x000FFFFF, 0x000FFFFF, 0x000FF000, 0x000FF000, 0x000FF000, // 82 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, // 83 0x000FF000, 0x000FF000, 0x000FF000, 0xFFFFF000, 0xFFFFF000, 0x00000000, 0x00000000, 0x00000000, // 84 0x000FF000, 0x000FF000, 0x000FF000, 0xFFFFF000, 0xFFFFF000, 0x000FF000, 0x000FF000, 0x000FF000, // 85 0x00000000, 0x00000000, 0x00000000, 0xFFFFF000, 0xFFFFF000, 0x000FF000, 0x000FF000, 0x000FF000, // 86 0x000FF000, 0x000FF000, 0x000FF000, 0x000FFFFF, 0x000FFFFF, 0x00000000, 0x00000000, 0x00000000, // 87 0x000FF000, 0x000FF000, 0x000FF000, 0xFFFFFFFF, 0xFFFFFFFF, 0x000FF000, 0x000FF000, 0x000FF000, // 88 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x000FF000, 0x000FF000, 0x000FF000, // 89 0x000FF000, 0x000FF000, 0x000FF000, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, // 8A 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, };
the_stack_data/66405.c
/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 2016 - 2017, Steve Holme, <[email protected]>. * Copyright (C) 2017, Expat development team * * All rights reserved. * Licensed under the MIT license: * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * 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 OF * THIRD PARTY RIGHTS. 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. * * Except as contained in this notice, the name of a copyright holder shall * not be used in advertising or otherwise to promote the sale, use or other * dealings in this Software without prior written authorization of the * copyright holder. * ***************************************************************************/ #if defined(_WIN32) #include <windows.h> #include <tchar.h> #include <stdlib.h> HMODULE _Expat_LoadLibrary(LPCTSTR filename); #if !defined(LOAD_WITH_ALTERED_SEARCH_PATH) #define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008 #endif #if !defined(LOAD_LIBRARY_SEARCH_SYSTEM32) #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 #endif /* We use our own typedef here since some headers might lack these */ typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD); /* See function definitions in winbase.h */ #ifdef UNICODE # ifdef _WIN32_WCE # define LOADLIBARYEX L"LoadLibraryExW" # else # define LOADLIBARYEX "LoadLibraryExW" # endif #else # define LOADLIBARYEX "LoadLibraryExA" #endif /* * _Expat_LoadLibrary() * * This is used to dynamically load DLLs using the most secure method available * for the version of Windows that we are running on. * * Parameters: * * filename [in] - The filename or full path of the DLL to load. If only the * filename is passed then the DLL will be loaded from the * Windows system directory. * * Returns the handle of the module on success; otherwise NULL. */ HMODULE _Expat_LoadLibrary(LPCTSTR filename) { HMODULE hModule = NULL; LOADLIBRARYEX_FN pLoadLibraryEx = NULL; /* Get a handle to kernel32 so we can access it's functions at runtime */ HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32")); if(!hKernel32) return NULL; /* LCOV_EXCL_LINE */ /* Attempt to find LoadLibraryEx() which is only available on Windows 2000 and above */ pLoadLibraryEx = (LOADLIBRARYEX_FN) GetProcAddress(hKernel32, LOADLIBARYEX); /* Detect if there's already a path in the filename and load the library if there is. Note: Both back slashes and forward slashes have been supported since the earlier days of DOS at an API level although they are not supported by command prompt */ if(_tcspbrk(filename, TEXT("\\/"))) { /** !checksrc! disable BANNEDFUNC 1 **/ hModule = pLoadLibraryEx ? pLoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(filename); } /* Detect if KB2533623 is installed, as LOAD_LIBARY_SEARCH_SYSTEM32 is only supported on Windows Vista, Windows Server 2008, Windows 7 and Windows Server 2008 R2 with this patch or natively on Windows 8 and above */ else if(pLoadLibraryEx && GetProcAddress(hKernel32, "AddDllDirectory")) { /* Load the DLL from the Windows system directory */ hModule = pLoadLibraryEx(filename, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); } else { /* Attempt to get the Windows system path */ UINT systemdirlen = GetSystemDirectory(NULL, 0); if(systemdirlen) { /* Allocate space for the full DLL path (Room for the null terminator is included in systemdirlen) */ size_t filenamelen = _tcslen(filename); TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen)); if(path && GetSystemDirectory(path, systemdirlen)) { /* Calculate the full DLL path */ _tcscpy(path + _tcslen(path), TEXT("\\")); _tcscpy(path + _tcslen(path), filename); /* Load the DLL from the Windows system directory */ /** !checksrc! disable BANNEDFUNC 1 **/ hModule = pLoadLibraryEx ? pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(path); } free(path); } } return hModule; } #else /* defined(_WIN32) */ /* ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit] */ typedef int _TRANSLATION_UNIT_LOAD_LIBRARY_C_NOT_EMTPY; #endif /* defined(_WIN32) */
the_stack_data/41343.c
/* * Copyright (c) 2012 The Native Client Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include <stdio.h> #if defined(__GLIBC__) #include <unistd.h> #else /* * TODO(bsy): remove when newlib toolchain catches up * http://code.google.com/p/nativeclient/issues/detail?id=2714 */ #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" #endif int main(void) { #if defined(__GLIBC__) long rv = sysconf(_SC_PAGESIZE); #else long rv = sysconf(NACL_ABI__SC_PAGESIZE); #endif printf("%ld\n", rv); return rv != (1<<16); }
the_stack_data/111077384.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2009-2019 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Contributed by Markus Deuling <[email protected]> */ #include <stdio.h> #include <sys/syscall.h> int main (unsigned long long speid, unsigned long long argp, unsigned long long envp) { __send_to_ppe (0x2112, 0, NULL); return 0; }
the_stack_data/296915.c
// SPDX-License-Identifier: GPL-2.0 extern void prom_putchar(unsigned char ch); void putc(char c) { prom_putchar(c); }
the_stack_data/3263590.c
#include <stdio.h> /* replaces strings of blanks by the minimum number of tabs and blanks to * achieve the same spacing */ int main() { int c, i, j; int num_spaces, num_tabs, remaining_spaces; const int TAB_WIDTH = 3; /* number of spaces per tab in my terminal */ num_spaces = num_tabs = remaining_spaces = 0; while ((c = getchar()) != EOF) { if (c == ' ') { num_spaces++; } else { num_tabs = num_spaces / TAB_WIDTH; remaining_spaces = num_spaces % TAB_WIDTH; for (i = 0; i < num_tabs; i++) { printf("\t"); } for (j = 0; j < remaining_spaces; j++) { putchar(' '); } putchar(c); num_spaces = num_tabs = remaining_spaces = 0; } } return 0; }
the_stack_data/7080.c
/* * Copyright (C) 2003,2007 Wolfgang Hommel * * This file is part of the FakeTime Preload Library. * * The FakeTime Preload Library 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 of the * License, or (at your option) any later version. * * The FakeTime Preload 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with the FakeTime Preload Library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <sys/timeb.h> #ifdef FAKE_STAT #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #endif int main (int argc, char **argv) { time_t now; struct timeb tb; struct timeval tv; struct timespec ts; #ifdef FAKE_STAT struct stat buf; #endif time(&now); printf("time() : Current date and time: %s", ctime(&now)); printf("time(NULL) : Seconds since Epoch : %u\n", (unsigned int)time(NULL)); ftime(&tb); printf("ftime() : Current date and time: %s", ctime(&tb.time)); printf("(Intentionally sleeping 2 seconds...)\n"); fflush(stdout); sleep(2); gettimeofday(&tv, NULL); printf("gettimeofday() : Current date and time: %s", ctime(&tv.tv_sec)); clock_gettime(CLOCK_REALTIME, &ts); printf("clock_gettime(): Current date and time: %s", ctime(&ts.tv_sec)); #ifdef FAKE_STAT lstat(argv[0], &buf); printf("stat(): mod. time of file '%s': %s", argv[0], ctime(&buf.st_mtime)); #endif return 0; }
the_stack_data/1020792.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define L 23 #define C 30 #define LL 21 #define LC 28 #define UP 1 #define RIGHT 2 #define DOWN 3 #define LEFT 4 #define LINHA 0 #define COLUNA 1 //tirei essa função, usei o proprio vetor pacman[3] p variar linhas e coluna /*void *operacao_dist(int pacman[3] , int dir[2], int x, int y) { int linha, coluna; linha = pacman[0]; coluna = pacman[1] + 2; dir[0] = linha; dir[1] = coluna; printf("%d %d \n\n", dir[0], dir[1]); } */ //usei o vetor pacman[3] p variar aqui void dist (int pacman[3]) { int posicao_pacman; posicao_pacman = pacman[2]; //dir = malloc(sizeof(int) * 2); if (posicao_pacman == UP) { pacman[0] = pacman[0]-2; } //operacao_dist(pacman, dir, -2, 0); if (posicao_pacman == RIGHT) //operacao_dist(pacman, dir, 0, 2); { pacman[1] = pacman[1]+2; } if (posicao_pacman == DOWN) //operacao_dist(pacman, dir, 2, 0); { pacman[0] = pacman[0]+2; } if (posicao_pacman == LEFT) //operacao_dist(pacman, dir, 0, -2); { pacman[1] = pacman[1]-2; } //return dir; } //não usei essa tbm, acho que tem que colocar as excessoes de quando cai numa posicao invalida aqui, p depois usar ela em casos mais dificeis void verifica_target(int target[2], char maze[23][30]) { if (target[LINHA]>22) { target[LINHA]=22; } if (target[COLUNA]>29) { target[COLUNA]=29; } if (target[LINHA]<1) { target[LINHA]=1; } if (target[COLUNA]<1) { target[COLUNA]=1; } } void print_maze(char maze[23][30]) { int i, j; for (i=0; i<23; i++) { for (j=0; j<30; j++) { printf("%c", maze[i][j]); } printf("\n"); } printf("\n"); } void marca_target(char maze[23][30], int target[2]) { maze[target[LINHA]][target[COLUNA]]='T'; } void marca_ghost(char maze[23][30], int ghost[3]) { maze[ghost[LINHA]][ghost[COLUNA]]='B'; } void marca_red(char maze[23][30], int red[3]) { maze[red[LINHA]][red[COLUNA]]='R'; } //acrescentei o marca_pacman void marca_pacman(char maze[23][30], int pacman[3]) { maze[pacman[LINHA]][pacman[COLUNA]]='P'; } void zera_vetor(int vet[4]) { int i; for (i=0;i<4;i++) { vet[i]=1000; } } //nos if's de dentro da funcao acrescentei que a posicao deve ser != de 0 e != de B void anda(int ghost[3], char maze[23][30], int target[2]) { int dist[4], i=0, j=0, menor=0, vet[8]; while(maze[ghost[LINHA]][ghost[COLUNA]+1]!='T' || maze[ghost[LINHA]][ghost[COLUNA]-1]!='T' || maze[ghost[LINHA]+1][ghost[COLUNA]]!='T' || maze[ghost[LINHA]-1][ghost[COLUNA]]!='T') { if (maze[ghost[LINHA]][ghost[COLUNA]+1]!='7' || maze[ghost[LINHA]][ghost[COLUNA]-1]!='7' || maze[ghost[LINHA]+1][ghost[COLUNA]]!='7' || maze[ghost[LINHA]-1][ghost[COLUNA]]!='7') { if (maze[ghost[LINHA]-1][ghost[COLUNA]]!='0' && maze[ghost[LINHA]-1][ghost[COLUNA]]!='B') { ghost[LINHA]--; marca_ghost(maze, ghost); print_maze(maze); } else if (maze[ghost[LINHA]][ghost[COLUNA]-1]!='0' && maze[ghost[LINHA]][ghost[COLUNA]-1]!='B') { ghost[COLUNA]--; marca_ghost(maze, ghost); print_maze(maze); } else if (maze[ghost[LINHA]+1][ghost[COLUNA]]!='0' && maze[ghost[LINHA]+1][ghost[COLUNA]]!='B') { ghost[LINHA]++; marca_ghost(maze, ghost); print_maze(maze); } else if (maze[ghost[LINHA]][ghost[COLUNA]+1]!='0' && maze[ghost[LINHA]][ghost[COLUNA]+1]!='B') { ghost[COLUNA]++; marca_ghost(maze, ghost); print_maze(maze); } }else if (maze[ghost[LINHA]][ghost[COLUNA]+1]=='7' || (maze[ghost[LINHA]][ghost[COLUNA]-1]=='7') || (maze[ghost[LINHA]+1][ghost[COLUNA]]=='7') || (maze[ghost[LINHA]-1][ghost[COLUNA]]=='7')) { vet[0]=ghost[LINHA]; vet[1]=ghost[COLUNA]+2; vet[2]=ghost[LINHA]; vet[3]=ghost[COLUNA]-2; vet[4]=ghost[LINHA]+2; vet[5]=ghost[COLUNA]; vet[6]=ghost[LINHA]-2; vet[7]=ghost[COLUNA]; zera_vetor(dist); if (maze[vet[0]][vet[1]]!='0') { dist[0]=sqrt(pow((vet[LINHA]-target[LINHA]), 2)+pow((vet[COLUNA]-target[COLUNA]), 2)); } else if (maze[vet[2]][vet[3]]!='0') { dist[1]=sqrt(pow((vet[2]-target[LINHA]),2)+pow((vet[3]-target[COLUNA]),2)); } else if (maze[vet[4]][vet[5]]!='0') { dist[2]=sqrt(pow((vet[4]-target[LINHA]),2) + pow((vet[5]-target[COLUNA]),2)); } else if (maze[vet[6]][vet[7]]!='0') { dist[3]=sqrt(pow((vet[6]-target[LINHA]),2) + pow((vet[7]-target[COLUNA]),2)); } for(i=0;i<4;i++) { for (j=0;j<4;j++) { if (dist[i]<dist[j]) { menor=dist[i]; } else if (dist[j]<dist[i]) { menor=dist[j]; } } } if (menor==dist[0]) { maze[ghost[LINHA]][ghost[COLUNA]+2]='B'; print_maze(maze); } else if (menor==dist[1]) { maze[ghost[LINHA]][ghost[COLUNA]-2]='B'; print_maze(maze); } else if (menor==dist[2]) { maze[ghost[LINHA]+2][ghost[COLUNA]]='B'; print_maze(maze); } else if (menor==dist[3]) { maze[ghost[LINHA]-2][ghost[COLUNA]]='B'; print_maze(maze); } } } } void clean_matrix(char v[23][30], int m) { int i; for ( i = 0; i < m; i++ ) { free(v[i]); } free (v); } void inky(int pacman[3], int red[3], char maze[23][30], int ghost[3]) { int target[2]; target[LINHA]=(pacman[LINHA]-red[LINHA])+pacman[LINHA]; target[COLUNA]=(pacman[COLUNA]-red[COLUNA])+pacman[COLUNA]; printf("%d %d\n\n", target[LINHA], target[COLUNA]); //printf("%d", target[0]); //printf("%d", target[1]); //verifica_target(target, maze); marca_red(maze, red); marca_ghost(maze, ghost); marca_target(maze, target); print_maze(maze); anda(ghost, maze, target); } int main (int argc, const char *argv[]) { char maze[L][C]={{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}, {'0',' ',' ',' ',' ',' ','7',' ',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ',' ','7',' ',' ',' ',' ',' ',' ','0'}, {'0',' ','0','0','0','0',' ','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0','0',' ','0','0','0','0','0',' ','0'}, {'0','7',' ',' ',' ',' ','7',' ',' ',' ',' ',' ',' ','7',' ','7',' ',' ',' ',' ',' ',' ','7',' ',' ',' ',' ',' ','7','0'}, {'0',' ','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0',' ','0'}, {'0',' ',' ',' ',' ',' ','7','0',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ','0','7',' ',' ',' ',' ',' ',' ','0'}, {'0',' ','0','0','0','0',' ','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0',' ',' ',' ',' ',' ','6',' ','6',' ',' ',' ',' ',' ','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ',' ','7','0','0','0','0','0','0','0','0','0','0','0','7',' ',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0','7',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','7','0',' ','0','0','0','0','0',' ','0'}, {'0',' ','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0',' ','0'}, {'0',' ',' ',' ',' ',' ','7',' ','7',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ','7',' ','7',' ',' ',' ',' ',' ',' ','0'}, {'0',' ','0','0','0','0',' ','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0','0',' ','0','0','0','0','0',' ','0'}, {'0','7',' ',' ',' ',' ','7',' ','7',' ',' ',' ',' ','6',' ','6',' ',' ',' ',' ','7',' ','7','0',' ',' ',' ',' ','7','0'}, {'0',' ','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0',' ','0','0','0',' ','0'}, {'0','7',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ','0',' ',' ',' ',' ',' ',' ','0',' ',' ','7',' ',' ',' ','7','0'}, {'0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','0',' ','0','0','0','0','0','0','0','0','0','0','0','0',' ','0'}, {'0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','7',' ','7',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0'}, {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}}; int red[3], pacman[3], ghost[3]; //dis=malloc(sizeof(int) * 2); red[0]=2; red[1]=6; red[2]=RIGHT; pacman[0]=4; pacman[1]=7; pacman[2]=RIGHT; ghost[0]=1; ghost[1]=1; ghost[2]=RIGHT; marca_pacman(maze, pacman); dist(pacman); inky(pacman, red, maze, ghost); //clean_matrix(maze, 23); return 0; }
the_stack_data/154829615.c
#include <stdio.h> int main() { int n,x,t=0,maxct=0,i=0,j=0; printf("Enter the number of processes : "); scanf("%d",&n); int pid[n],at[n],bt[n],ct[n],tat[n],wt[n],mark[n],done[n]; float avgtat=0,avgwt=0,tput=0; printf("\tENTER THE DETAILS OF PROCESSES\n"); for( i=0;i<n;i++) { printf("Enter Process ID , Arival Time and Burst Time of process no.: %d \n",i+1); scanf("%d",&pid[i]); scanf("%d",&at[i]); scanf("%d",&bt[i]); ct[i]=0; tat[i]=0; wt[i]=0; mark[i]=0; done[i]=0; } //arranging the processes in order of incrasing at for( i=0;i<n;i++) { for( j=0;j<n-i-1;j++) { if(at[j]>at[j+1]) { int temp=at[j]; at[j]=at[j+1]; at[j+1]=temp; temp=bt[j]; bt[j]=bt[j+1]; bt[j+1]=temp; temp=pid[j]; pid[j]=pid[j+1]; pid[j+1]=temp; } } } //Calculation int c=0; for( i=0;c!=n;i++) { t=0;//found //unmarking all previous marks for( j=0;j<n;j++) { mark[j]=0; } //marking the processes with at less than or equal to clock for( j=0;j<n;j++) { if((at[j]<=i)&&(done[j]==0)) { t++; mark[j]=1; } } if(t>0) //inner conditions will run iff any process whose at is less than clk is found { //finding the process with shortest burst time amongst the checked ones int sbt=9999; int k=0; for( j=n-1;j>=0;j--) { if((bt[j]<=sbt)&&(mark[j]==1)) { k=j; sbt=bt[j]; } } done[k]=1; //calculating compile time of the marked process ct[k]=i+bt[k]; i+=bt[k]-1; c++; //calculating other details tat[k]=ct[k]-at[k]; wt[k]=tat[k]-bt[k]; avgtat+=tat[k]; avgwt+=wt[k]; //finding max CT if(maxct<ct[k]) maxct=ct[k]; } } avgtat=(float)avgtat/n; avgwt=(float)avgwt/n; tput=(float)n/(maxct-at[0]); //arranging the processess in order of pid for( i=0;i<n;i++) { for( j=0;j<n-i-1;j++) { if(pid[j]>pid[j+1]) { int temp=at[j]; at[j]=at[j+1]; at[j+1]=temp; temp=bt[j]; bt[j]=bt[j+1]; bt[j+1]=temp; temp=pid[j]; pid[j]=pid[j+1]; pid[j+1]=temp; temp=ct[j]; ct[j]=ct[j+1]; ct[j+1]=temp; temp=wt[j]; wt[j]=wt[j+1]; wt[j+1]=temp; temp=tat[j]; tat[j]=tat[j+1]; tat[j+1]=temp; } } } //printing the processed details printf("\n\n"); printf("\tCalculated Data after (SJFS) Shortest Job First Scheduling "); printf("\n\n"); printf("PID.\t\t A.T.\t\t B.T.\t\t C.T.\t\t T.A.T\t\t W.T.\n"); for( i=0;i<n;i++) { printf("%d\t\t %d\t\t %d\t\t %d\t\t %d\t\t %d\n",pid[i],at[i],bt[i],ct[i],tat[i],wt[i]); } printf("\n\n"); printf("Average Turn Around Time : %.2f\n",avgtat); printf("Average Waiting Time : %.2f\n",avgwt); printf("Through Put : %.2f",tput); }
the_stack_data/510292.c
/* Test that the function: int sigqueue(pid_t, int, const union sigval); is declared. */ #include <signal.h> #include <sys/types.h> typedef int (*sigqueue_test) (pid_t, int, const union sigval); int dummyfcn(void) { sigqueue_test dummyvar; dummyvar = sigqueue; return 0; }
the_stack_data/864024.c
#include <stdio.h> #include <string.h> #include <stdlib.h> int wcount(char *s) { int dlina=0,i=0, count=0; dlina = strnlen(s,100); for (i=0;i<dlina;i++) if(*(s+i)!=' '){ count++; for(;*(s+i)!=' ';i++); }else if (*(s+i-1)!=' ') i--; return count; } int main() { char s[100]={ 0 }; gets(s); printf("%d", wcount(s)); return 0 ; }
the_stack_data/79549.c
//#include <stdio.h> //int main() { // int suma = 0, limite; // // printf("Ingrese el limite de la sumatoria: "); // scanf("%d", &limite); // // for(int i = 0; i <= limite; i += 2) { // suma += i; // printf("%d \n", i); // } // // printf("La sumatoria es igual a: %d \n", suma); // return 0; //}
the_stack_data/97012888.c
#include <stdio.h> #include <string.h> int main() { int tc, i, l, j, result; char line[101], dump; scanf("%d%c", &tc, &dump); for(i=1 ; i<=tc ; i++) { gets(line); l = strlen(line); result=0; for(j=0 ; j<l ; j++) { if( line[j]=='a' || line[j]=='d' || line[j]=='g' || line[j]=='j' || line[j]=='m' || line[j]=='p' || line[j]=='t' || line[j]=='w' || line[j]==' ' ) result += 1; else if( line[j]=='b' || line[j]=='e' || line[j]=='h' || line[j]=='k' || line[j]=='n' || line[j]=='q' || line[j]=='u' || line[j]=='x' ) result += 2; else if( line[j]=='c' || line[j]=='f' || line[j]=='i' || line[j]=='l' || line[j]=='o' || line[j]=='r' || line[j]=='v' || line[j]=='y' ) result += 3; else if( line[j]=='s' || line[j]=='z' ) result += 4; } printf("Case #%d: %d\n", i, result); } return 0; }
the_stack_data/118932.c
/* example.c -- usage example of the zlib compression library * Copyright (C) 1995-1996 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ /* $Id: example.c,v 1.1.1.1 2000/11/06 19:54:01 mguthaus Exp $ */ #include <stdio.h> #include "zlib.h" #ifdef STDC # include <string.h> # include <stdlib.h> #else extern void exit OF((int)); #endif #define CHECK_ERR(err, msg) { \ if (err != Z_OK) { \ fprintf(stderr, "%s error: %d\n", msg, err); \ exit(1); \ } \ } const char hello[] = "hello, hello!"; /* "hello world" would be more standard, but the repeated "hello" * stresses the compression code better, sorry... */ const char dictionary[] = "hello"; uLong dictId; /* Adler32 value of the dictionary */ void test_compress OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_gzio OF((const char *out, const char *in, Byte *uncompr, int uncomprLen)); void test_deflate OF((Byte *compr, uLong comprLen)); void test_inflate OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_large_deflate OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_large_inflate OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_flush OF((Byte *compr, uLong comprLen)); void test_sync OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_dict_deflate OF((Byte *compr, uLong comprLen)); void test_dict_inflate OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); int main OF((int argc, char *argv[])); /* =========================================================================== * Test compress() and uncompress() */ void test_compress(compr, comprLen, uncompr, uncomprLen) Byte *compr, *uncompr; uLong comprLen, uncomprLen; { int err; uLong len = strlen(hello)+1; err = compress(compr, &comprLen, (const Bytef*)hello, len); CHECK_ERR(err, "compress"); strcpy((char*)uncompr, "garbage"); err = uncompress(uncompr, &uncomprLen, compr, comprLen); CHECK_ERR(err, "uncompress"); if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad uncompress\n"); } else { printf("uncompress(): %s\n", uncompr); } } /* =========================================================================== * Test read/write of .gz files */ void test_gzio(out, in, uncompr, uncomprLen) const char *out; /* output file */ const char *in; /* input file */ Byte *uncompr; int uncomprLen; { int err; int len = strlen(hello)+1; gzFile file; file = gzopen(out, "wb"); if (file == NULL) { fprintf(stderr, "gzopen error\n"); exit(1); } if (gzwrite(file, (const voidp)hello, (unsigned)len) != len) { fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err)); } gzclose(file); file = gzopen(in, "rb"); if (file == NULL) { fprintf(stderr, "gzopen error\n"); } strcpy((char*)uncompr, "garbage"); uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); if (uncomprLen != len) { fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); } gzclose(file); if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad gzread\n"); } else { printf("gzread(): %s\n", uncompr); } } /* =========================================================================== * Test deflate() with small buffers */ void test_deflate(compr, comprLen) Byte *compr; uLong comprLen; { z_stream c_stream; /* compression stream */ int err; int len = strlen(hello)+1; c_stream.zalloc = (alloc_func)0; c_stream.zfree = (free_func)0; c_stream.opaque = (voidpf)0; err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); CHECK_ERR(err, "deflateInit"); c_stream.next_in = (Bytef*)hello; c_stream.next_out = compr; while (c_stream.total_in != (uLong)len && c_stream.total_out < comprLen) { c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ err = deflate(&c_stream, Z_NO_FLUSH); CHECK_ERR(err, "deflate"); } /* Finish the stream, still forcing small buffers: */ for (;;) { c_stream.avail_out = 1; err = deflate(&c_stream, Z_FINISH); if (err == Z_STREAM_END) break; CHECK_ERR(err, "deflate"); } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); } /* =========================================================================== * Test inflate() with small buffers */ void test_inflate(compr, comprLen, uncompr, uncomprLen) Byte *compr, *uncompr; uLong comprLen, uncomprLen; { int err; z_stream d_stream; /* decompression stream */ strcpy((char*)uncompr, "garbage"); d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; d_stream.opaque = (voidpf)0; err = inflateInit(&d_stream); CHECK_ERR(err, "inflateInit"); d_stream.next_in = compr; d_stream.next_out = uncompr; while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ err = inflate(&d_stream, Z_NO_FLUSH); if (err == Z_STREAM_END) break; CHECK_ERR(err, "inflate"); } err = inflateEnd(&d_stream); CHECK_ERR(err, "inflateEnd"); if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad inflate\n"); } else { printf("inflate(): %s\n", uncompr); } } /* =========================================================================== * Test deflate() with large buffers and dynamic change of compression level */ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) Byte *compr, *uncompr; uLong comprLen, uncomprLen; { z_stream c_stream; /* compression stream */ int err; c_stream.zalloc = (alloc_func)0; c_stream.zfree = (free_func)0; c_stream.opaque = (voidpf)0; err = deflateInit(&c_stream, Z_BEST_SPEED); CHECK_ERR(err, "deflateInit"); c_stream.next_out = compr; c_stream.avail_out = (uInt)comprLen; /* At this point, uncompr is still mostly zeroes, so it should compress * very well: */ c_stream.next_in = uncompr; c_stream.avail_in = (uInt)uncomprLen; err = deflate(&c_stream, Z_NO_FLUSH); CHECK_ERR(err, "deflate"); if (c_stream.avail_in != 0) { fprintf(stderr, "deflate not greedy\n"); } /* Feed in already compressed data and switch to no compression: */ deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); c_stream.next_in = compr; c_stream.avail_in = (uInt)comprLen/2; err = deflate(&c_stream, Z_NO_FLUSH); CHECK_ERR(err, "deflate"); /* Switch back to compressing mode: */ deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED); c_stream.next_in = uncompr; c_stream.avail_in = (uInt)uncomprLen; err = deflate(&c_stream, Z_NO_FLUSH); CHECK_ERR(err, "deflate"); err = deflate(&c_stream, Z_FINISH); if (err != Z_STREAM_END) { fprintf(stderr, "deflate should report Z_STREAM_END\n"); } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); } /* =========================================================================== * Test inflate() with large buffers */ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) Byte *compr, *uncompr; uLong comprLen, uncomprLen; { int err; z_stream d_stream; /* decompression stream */ strcpy((char*)uncompr, "garbage"); d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; d_stream.opaque = (voidpf)0; err = inflateInit(&d_stream); CHECK_ERR(err, "inflateInit"); d_stream.next_in = compr; d_stream.avail_in = (uInt)comprLen; for (;;) { d_stream.next_out = uncompr; /* discard the output */ d_stream.avail_out = (uInt)uncomprLen; err = inflate(&d_stream, Z_NO_FLUSH); if (err == Z_STREAM_END) break; CHECK_ERR(err, "large inflate"); } err = inflateEnd(&d_stream); CHECK_ERR(err, "inflateEnd"); if (d_stream.total_out != 2*uncomprLen + comprLen/2) { fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); } else { printf("large_inflate(): OK\n"); } } /* =========================================================================== * Test deflate() with full flush */ void test_flush(compr, comprLen) Byte *compr; uLong comprLen; { z_stream c_stream; /* compression stream */ int err; int len = strlen(hello)+1; c_stream.zalloc = (alloc_func)0; c_stream.zfree = (free_func)0; c_stream.opaque = (voidpf)0; err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); CHECK_ERR(err, "deflateInit"); c_stream.next_in = (Bytef*)hello; c_stream.next_out = compr; c_stream.avail_in = 3; c_stream.avail_out = (uInt)comprLen; err = deflate(&c_stream, Z_FULL_FLUSH); CHECK_ERR(err, "deflate"); compr[3]++; /* force an error in first compressed block */ c_stream.avail_in = len - 3; err = deflate(&c_stream, Z_FINISH); if (err != Z_STREAM_END) { CHECK_ERR(err, "deflate"); } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); } /* =========================================================================== * Test inflateSync() */ void test_sync(compr, comprLen, uncompr, uncomprLen) Byte *compr, *uncompr; uLong comprLen, uncomprLen; { int err; z_stream d_stream; /* decompression stream */ strcpy((char*)uncompr, "garbage"); d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; d_stream.opaque = (voidpf)0; err = inflateInit(&d_stream); CHECK_ERR(err, "inflateInit"); d_stream.next_in = compr; d_stream.next_out = uncompr; d_stream.avail_in = 2; /* just read the zlib header */ d_stream.avail_out = (uInt)uncomprLen; inflate(&d_stream, Z_NO_FLUSH); CHECK_ERR(err, "inflate"); d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */ err = inflateSync(&d_stream); /* but skip the damaged part */ CHECK_ERR(err, "inflateSync"); err = inflate(&d_stream, Z_FINISH); if (err != Z_DATA_ERROR) { fprintf(stderr, "inflate should report DATA_ERROR\n"); /* Because of incorrect adler32 */ } err = inflateEnd(&d_stream); CHECK_ERR(err, "inflateEnd"); printf("after inflateSync(): hel%s\n", uncompr); } /* =========================================================================== * Test deflate() with preset dictionary */ void test_dict_deflate(compr, comprLen) Byte *compr; uLong comprLen; { z_stream c_stream; /* compression stream */ int err; c_stream.zalloc = (alloc_func)0; c_stream.zfree = (free_func)0; c_stream.opaque = (voidpf)0; err = deflateInit(&c_stream, Z_BEST_COMPRESSION); CHECK_ERR(err, "deflateInit"); err = deflateSetDictionary(&c_stream, (const Bytef*)dictionary, sizeof(dictionary)); CHECK_ERR(err, "deflateSetDictionary"); dictId = c_stream.adler; c_stream.next_out = compr; c_stream.avail_out = (uInt)comprLen; c_stream.next_in = (Bytef*)hello; c_stream.avail_in = (uInt)strlen(hello)+1; err = deflate(&c_stream, Z_FINISH); if (err != Z_STREAM_END) { fprintf(stderr, "deflate should report Z_STREAM_END\n"); } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); } /* =========================================================================== * Test inflate() with a preset dictionary */ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) Byte *compr, *uncompr; uLong comprLen, uncomprLen; { int err; z_stream d_stream; /* decompression stream */ strcpy((char*)uncompr, "garbage"); d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; d_stream.opaque = (voidpf)0; err = inflateInit(&d_stream); CHECK_ERR(err, "inflateInit"); d_stream.next_in = compr; d_stream.avail_in = (uInt)comprLen; d_stream.next_out = uncompr; d_stream.avail_out = (uInt)uncomprLen; for (;;) { err = inflate(&d_stream, Z_NO_FLUSH); if (err == Z_STREAM_END) break; if (err == Z_NEED_DICT) { if (d_stream.adler != dictId) { fprintf(stderr, "unexpected dictionary"); exit(1); } err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, sizeof(dictionary)); } CHECK_ERR(err, "inflate with dict"); } err = inflateEnd(&d_stream); CHECK_ERR(err, "inflateEnd"); if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad inflate with dict\n"); } else { printf("inflate with dictionary: %s\n", uncompr); } } /* =========================================================================== * Usage: example [output.gz [input.gz]] */ int main(argc, argv) int argc; char *argv[]; { Byte *compr, *uncompr; uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ uLong uncomprLen = comprLen; if (zlibVersion()[0] != ZLIB_VERSION[0]) { fprintf(stderr, "incompatible zlib version\n"); exit(1); } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { fprintf(stderr, "warning: different zlib version\n"); } compr = (Byte*)calloc((uInt)comprLen, 1); uncompr = (Byte*)calloc((uInt)uncomprLen, 1); /* compr and uncompr are cleared to avoid reading uninitialized * data and to ensure that uncompr compresses well. */ if (compr == Z_NULL || uncompr == Z_NULL) { printf("out of memory\n"); exit(1); } test_compress(compr, comprLen, uncompr, uncomprLen); test_gzio((argc > 1 ? argv[1] : "foo.gz"), (argc > 2 ? argv[2] : "foo.gz"), uncompr, (int)uncomprLen); test_deflate(compr, comprLen); test_inflate(compr, comprLen, uncompr, uncomprLen); test_large_deflate(compr, comprLen, uncompr, uncomprLen); test_large_inflate(compr, comprLen, uncompr, uncomprLen); test_flush(compr, comprLen); test_sync(compr, comprLen, uncompr, uncomprLen); test_dict_deflate(compr, comprLen); test_dict_inflate(compr, comprLen, uncompr, uncomprLen); exit(0); return 0; /* to avoid warning */ }
the_stack_data/98387.c
#include<stdio.h> int main(){ int ns,i,n,cont; cont=0; scanf("%d\n",&ns); if((ns>=3)&&(ns<=1000)){ for(i=0;i<ns;i++){ scanf("%d\n",&n); if((n>(2*(n=i-1)))&&(n>(2*(n=i+1)))){ cont++; } } }else{ printf("ERROR\n"); } printf("%d\n",cont); }
the_stack_data/6308.c
/* * Copyright 2011 ArtForz * Copyright 2011-2013 pooler * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. See COPYING for more details. */ #include <string.h> #include <inttypes.h> #if defined(__arm__) && defined(__APCS_32__) #define EXTERN_SHA256 #endif static const uint32_t sha256_h[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; static const uint32_t sha256_k[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70718, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; void sha256_init(uint32_t *state) { memcpy(state, sha256_h, 32); } /* to quiet strict compiler warning */ uint32_t swab32(uint32_t i); uint32_t be32dec(uint32_t *i); uint32_t be32enc(uint32_t *j, uint32_t i); /* Elementary functions used by SHA256 */ #define Ch(x, y, z) ((x & (y ^ z)) ^ z) #define Maj(x, y, z) ((x & (y | z)) | (y & z)) #define ROTR(x, n) ((x >> n) | (x << (32 - n))) #define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) #define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) #define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ (x >> 3)) #define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ (x >> 10)) /* SHA256 round function */ #define RND(a, b, c, d, e, f, g, h, k) \ do { \ t0 = h + S1(e) + Ch(e, f, g) + k; \ t1 = S0(a) + Maj(a, b, c); \ d += t0; \ h = t0 + t1; \ } while (0) /* Adjusted round function for rotating state */ #define RNDr(S, W, i) \ RND(S[(64 - i) & 7], S[(65 - i) & 7], \ S[(66 - i) & 7], S[(67 - i) & 7], \ S[(68 - i) & 7], S[(69 - i) & 7], \ S[(70 - i) & 7], S[(71 - i) & 7], \ W[i] + sha256_k[i]) #ifndef EXTERN_SHA256 /* * SHA256 block compression function. The 256-bit state is transformed via * the 512-bit input block to produce a new state. */ void sha256_transform(uint32_t *state, const uint32_t *block, int swap) { uint32_t W[64]; uint32_t S[8]; uint32_t t0, t1; int i; /* 1. Prepare message schedule W. */ if (swap) { for (i = 0; i < 16; i++) W[i] = swab32(block[i]); } else memcpy(W, block, 64); for (i = 16; i < 64; i += 2) { W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15]; } /* 2. Initialize working variables. */ memcpy(S, state, 32); /* 3. Mix. */ RNDr(S, W, 0); RNDr(S, W, 1); RNDr(S, W, 2); RNDr(S, W, 3); RNDr(S, W, 4); RNDr(S, W, 5); RNDr(S, W, 6); RNDr(S, W, 7); RNDr(S, W, 8); RNDr(S, W, 9); RNDr(S, W, 10); RNDr(S, W, 11); RNDr(S, W, 12); RNDr(S, W, 13); RNDr(S, W, 14); RNDr(S, W, 15); RNDr(S, W, 16); RNDr(S, W, 17); RNDr(S, W, 18); RNDr(S, W, 19); RNDr(S, W, 20); RNDr(S, W, 21); RNDr(S, W, 22); RNDr(S, W, 23); RNDr(S, W, 24); RNDr(S, W, 25); RNDr(S, W, 26); RNDr(S, W, 27); RNDr(S, W, 28); RNDr(S, W, 29); RNDr(S, W, 30); RNDr(S, W, 31); RNDr(S, W, 32); RNDr(S, W, 33); RNDr(S, W, 34); RNDr(S, W, 35); RNDr(S, W, 36); RNDr(S, W, 37); RNDr(S, W, 38); RNDr(S, W, 39); RNDr(S, W, 40); RNDr(S, W, 41); RNDr(S, W, 42); RNDr(S, W, 43); RNDr(S, W, 44); RNDr(S, W, 45); RNDr(S, W, 46); RNDr(S, W, 47); RNDr(S, W, 48); RNDr(S, W, 49); RNDr(S, W, 50); RNDr(S, W, 51); RNDr(S, W, 52); RNDr(S, W, 53); RNDr(S, W, 54); RNDr(S, W, 55); RNDr(S, W, 56); RNDr(S, W, 57); RNDr(S, W, 58); RNDr(S, W, 59); RNDr(S, W, 60); RNDr(S, W, 61); RNDr(S, W, 62); RNDr(S, W, 63); /* 4. Mix local working variables into global state */ for (i = 0; i < 8; i++) state[i] += S[i]; } #endif /* EXTERN_SHA256 */ static const uint32_t sha256d_hash1[16] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100 }; /* static void sha256d_80_swap(uint32_t *hash, const uint32_t *data) { uint32_t S[16]; int i; sha256_init(S); sha256_transform(S, data, 0); sha256_transform(S, data + 16, 0); memcpy(S + 8, sha256d_hash1 + 8, 32); sha256_init(hash); sha256_transform(hash, S, 0); for (i = 0; i < 8; i++) hash[i] = swab32(hash[i]); } */ void sha256d(unsigned char *hash, const unsigned char *data, int len) { uint32_t S[16], T[16]; int i, r; sha256_init(S); for (r = len; r > -9; r -= 64) { if (r < 64) memset(T, 0, 64); memcpy(T, data + len - r, r > 64 ? 64 : (r < 0 ? 0 : r)); if (r >= 0 && r < 64) ((unsigned char *)T)[r] = 0x80; for (i = 0; i < 16; i++) T[i] = be32dec(T + i); if (r < 56) T[15] = 8 * len; sha256_transform(S, T, 0); } memcpy(S + 8, sha256d_hash1 + 8, 32); sha256_init(T); sha256_transform(T, S, 0); for (i = 0; i < 8; i++) be32enc((uint32_t *)hash + i, T[i]); } /* static inline void sha256d_preextend(uint32_t *W) { W[16] = s1(W[14]) + W[ 9] + s0(W[ 1]) + W[ 0]; W[17] = s1(W[15]) + W[10] + s0(W[ 2]) + W[ 1]; W[18] = s1(W[16]) + W[11] + W[ 2]; W[19] = s1(W[17]) + W[12] + s0(W[ 4]); W[20] = W[13] + s0(W[ 5]) + W[ 4]; W[21] = W[14] + s0(W[ 6]) + W[ 5]; W[22] = W[15] + s0(W[ 7]) + W[ 6]; W[23] = W[16] + s0(W[ 8]) + W[ 7]; W[24] = W[17] + s0(W[ 9]) + W[ 8]; W[25] = s0(W[10]) + W[ 9]; W[26] = s0(W[11]) + W[10]; W[27] = s0(W[12]) + W[11]; W[28] = s0(W[13]) + W[12]; W[29] = s0(W[14]) + W[13]; W[30] = s0(W[15]) + W[14]; W[31] = s0(W[16]) + W[15]; } */ /* static inline void sha256d_prehash(uint32_t *S, const uint32_t *W) { uint32_t t0, t1; RNDr(S, W, 0); RNDr(S, W, 1); RNDr(S, W, 2); } */ #ifdef EXTERN_SHA256 void sha256d_ms(uint32_t *hash, uint32_t *W, const uint32_t *midstate, const uint32_t *prehash); #else /* static inline void sha256d_ms(uint32_t *hash, uint32_t *W, const uint32_t *midstate, const uint32_t *prehash) { uint32_t S[64]; uint32_t t0, t1; int i; S[18] = W[18]; S[19] = W[19]; S[20] = W[20]; S[22] = W[22]; S[23] = W[23]; S[24] = W[24]; S[30] = W[30]; S[31] = W[31]; W[18] += s0(W[3]); W[19] += W[3]; W[20] += s1(W[18]); W[21] = s1(W[19]); W[22] += s1(W[20]); W[23] += s1(W[21]); W[24] += s1(W[22]); W[25] = s1(W[23]) + W[18]; W[26] = s1(W[24]) + W[19]; W[27] = s1(W[25]) + W[20]; W[28] = s1(W[26]) + W[21]; W[29] = s1(W[27]) + W[22]; W[30] += s1(W[28]) + W[23]; W[31] += s1(W[29]) + W[24]; for (i = 32; i < 64; i += 2) { W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15]; } memcpy(S, prehash, 32); RNDr(S, W, 3); RNDr(S, W, 4); RNDr(S, W, 5); RNDr(S, W, 6); RNDr(S, W, 7); RNDr(S, W, 8); RNDr(S, W, 9); RNDr(S, W, 10); RNDr(S, W, 11); RNDr(S, W, 12); RNDr(S, W, 13); RNDr(S, W, 14); RNDr(S, W, 15); RNDr(S, W, 16); RNDr(S, W, 17); RNDr(S, W, 18); RNDr(S, W, 19); RNDr(S, W, 20); RNDr(S, W, 21); RNDr(S, W, 22); RNDr(S, W, 23); RNDr(S, W, 24); RNDr(S, W, 25); RNDr(S, W, 26); RNDr(S, W, 27); RNDr(S, W, 28); RNDr(S, W, 29); RNDr(S, W, 30); RNDr(S, W, 31); RNDr(S, W, 32); RNDr(S, W, 33); RNDr(S, W, 34); RNDr(S, W, 35); RNDr(S, W, 36); RNDr(S, W, 37); RNDr(S, W, 38); RNDr(S, W, 39); RNDr(S, W, 40); RNDr(S, W, 41); RNDr(S, W, 42); RNDr(S, W, 43); RNDr(S, W, 44); RNDr(S, W, 45); RNDr(S, W, 46); RNDr(S, W, 47); RNDr(S, W, 48); RNDr(S, W, 49); RNDr(S, W, 50); RNDr(S, W, 51); RNDr(S, W, 52); RNDr(S, W, 53); RNDr(S, W, 54); RNDr(S, W, 55); RNDr(S, W, 56); RNDr(S, W, 57); RNDr(S, W, 58); RNDr(S, W, 59); RNDr(S, W, 60); RNDr(S, W, 61); RNDr(S, W, 62); RNDr(S, W, 63); for (i = 0; i < 8; i++) S[i] += midstate[i]; W[18] = S[18]; W[19] = S[19]; W[20] = S[20]; W[22] = S[22]; W[23] = S[23]; W[24] = S[24]; W[30] = S[30]; W[31] = S[31]; memcpy(S + 8, sha256d_hash1 + 8, 32); S[16] = s1(sha256d_hash1[14]) + sha256d_hash1[ 9] + s0(S[ 1]) + S[ 0]; S[17] = s1(sha256d_hash1[15]) + sha256d_hash1[10] + s0(S[ 2]) + S[ 1]; S[18] = s1(S[16]) + sha256d_hash1[11] + s0(S[ 3]) + S[ 2]; S[19] = s1(S[17]) + sha256d_hash1[12] + s0(S[ 4]) + S[ 3]; S[20] = s1(S[18]) + sha256d_hash1[13] + s0(S[ 5]) + S[ 4]; S[21] = s1(S[19]) + sha256d_hash1[14] + s0(S[ 6]) + S[ 5]; S[22] = s1(S[20]) + sha256d_hash1[15] + s0(S[ 7]) + S[ 6]; S[23] = s1(S[21]) + S[16] + s0(sha256d_hash1[ 8]) + S[ 7]; S[24] = s1(S[22]) + S[17] + s0(sha256d_hash1[ 9]) + sha256d_hash1[ 8]; S[25] = s1(S[23]) + S[18] + s0(sha256d_hash1[10]) + sha256d_hash1[ 9]; S[26] = s1(S[24]) + S[19] + s0(sha256d_hash1[11]) + sha256d_hash1[10]; S[27] = s1(S[25]) + S[20] + s0(sha256d_hash1[12]) + sha256d_hash1[11]; S[28] = s1(S[26]) + S[21] + s0(sha256d_hash1[13]) + sha256d_hash1[12]; S[29] = s1(S[27]) + S[22] + s0(sha256d_hash1[14]) + sha256d_hash1[13]; S[30] = s1(S[28]) + S[23] + s0(sha256d_hash1[15]) + sha256d_hash1[14]; S[31] = s1(S[29]) + S[24] + s0(S[16]) + sha256d_hash1[15]; for (i = 32; i < 60; i += 2) { S[i] = s1(S[i - 2]) + S[i - 7] + s0(S[i - 15]) + S[i - 16]; S[i+1] = s1(S[i - 1]) + S[i - 6] + s0(S[i - 14]) + S[i - 15]; } S[60] = s1(S[58]) + S[53] + s0(S[45]) + S[44]; sha256_init(hash); RNDr(hash, S, 0); RNDr(hash, S, 1); RNDr(hash, S, 2); RNDr(hash, S, 3); RNDr(hash, S, 4); RNDr(hash, S, 5); RNDr(hash, S, 6); RNDr(hash, S, 7); RNDr(hash, S, 8); RNDr(hash, S, 9); RNDr(hash, S, 10); RNDr(hash, S, 11); RNDr(hash, S, 12); RNDr(hash, S, 13); RNDr(hash, S, 14); RNDr(hash, S, 15); RNDr(hash, S, 16); RNDr(hash, S, 17); RNDr(hash, S, 18); RNDr(hash, S, 19); RNDr(hash, S, 20); RNDr(hash, S, 21); RNDr(hash, S, 22); RNDr(hash, S, 23); RNDr(hash, S, 24); RNDr(hash, S, 25); RNDr(hash, S, 26); RNDr(hash, S, 27); RNDr(hash, S, 28); RNDr(hash, S, 29); RNDr(hash, S, 30); RNDr(hash, S, 31); RNDr(hash, S, 32); RNDr(hash, S, 33); RNDr(hash, S, 34); RNDr(hash, S, 35); RNDr(hash, S, 36); RNDr(hash, S, 37); RNDr(hash, S, 38); RNDr(hash, S, 39); RNDr(hash, S, 40); RNDr(hash, S, 41); RNDr(hash, S, 42); RNDr(hash, S, 43); RNDr(hash, S, 44); RNDr(hash, S, 45); RNDr(hash, S, 46); RNDr(hash, S, 47); RNDr(hash, S, 48); RNDr(hash, S, 49); RNDr(hash, S, 50); RNDr(hash, S, 51); RNDr(hash, S, 52); RNDr(hash, S, 53); RNDr(hash, S, 54); RNDr(hash, S, 55); RNDr(hash, S, 56); hash[2] += hash[6] + S1(hash[3]) + Ch(hash[3], hash[4], hash[5]) + S[57] + sha256_k[57]; hash[1] += hash[5] + S1(hash[2]) + Ch(hash[2], hash[3], hash[4]) + S[58] + sha256_k[58]; hash[0] += hash[4] + S1(hash[1]) + Ch(hash[1], hash[2], hash[3]) + S[59] + sha256_k[59]; hash[7] += hash[3] + S1(hash[0]) + Ch(hash[0], hash[1], hash[2]) + S[60] + sha256_k[60] + sha256_h[7]; } */ #endif /* EXTERN_SHA256 */ #if HAVE_SHA256_4WAY void sha256d_ms_4way(uint32_t *hash, uint32_t *data, const uint32_t *midstate, const uint32_t *prehash); static inline int scanhash_sha256d_4way(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done) { uint32_t data[4 * 64] __attribute__((aligned(128))); uint32_t hash[4 * 8] __attribute__((aligned(32))); uint32_t midstate[4 * 8] __attribute__((aligned(32))); uint32_t prehash[4 * 8] __attribute__((aligned(32))); uint32_t n = pdata[19] - 1; const uint32_t first_nonce = pdata[19]; const uint32_t Htarg = ptarget[7]; int i, j; memcpy(data, pdata + 16, 64); sha256d_preextend(data); for (i = 31; i >= 0; i--) for (j = 0; j < 4; j++) data[i * 4 + j] = data[i]; sha256_init(midstate); sha256_transform(midstate, pdata, 0); memcpy(prehash, midstate, 32); sha256d_prehash(prehash, pdata + 16); for (i = 7; i >= 0; i--) { for (j = 0; j < 4; j++) { midstate[i * 4 + j] = midstate[i]; prehash[i * 4 + j] = prehash[i]; } } do { for (i = 0; i < 4; i++) data[4 * 3 + i] = ++n; sha256d_ms_4way(hash, data, midstate, prehash); for (i = 0; i < 4; i++) { if (swab32(hash[4 * 7 + i]) <= Htarg) { pdata[19] = data[4 * 3 + i]; sha256d_80_swap(hash, pdata); if (fulltest(hash, ptarget)) { *hashes_done = n - first_nonce + 1; return 1; } } } } while (n < max_nonce && !work_restart[thr_id].restart); *hashes_done = n - first_nonce + 1; pdata[19] = n; return 0; } #endif /* HAVE_SHA256_4WAY */ #if HAVE_SHA256_8WAY void sha256d_ms_8way(uint32_t *hash, uint32_t *data, const uint32_t *midstate, const uint32_t *prehash); #endif /* HAVE_SHA256_8WAY */
the_stack_data/3262618.c
/* C non-blocking keyboard input http://stackoverflow.com/questions/448944/c-non-blocking-keyboard-input */ #include <stdlib.h> #include <string.h> #include <sys/select.h> #include <termios.h> #include <unistd.h> struct termios orig_termios; void reset_terminal_mode() { tcsetattr(0, TCSANOW, &orig_termios); } void set_conio_terminal_mode() { struct termios new_termios; /* take two copies - one for now, one for later */ tcgetattr(0, &orig_termios); memcpy(&new_termios, &orig_termios, sizeof(new_termios)); /* register cleanup handler, and set the new terminal mode */ atexit(reset_terminal_mode); cfmakeraw(&new_termios); new_termios.c_oflag |= OPOST; tcsetattr(0, TCSANOW, &new_termios); } int kbhit() { struct timeval tv = { 0L, 0L }; fd_set fds; FD_ZERO(&fds); // not in original posting to stackoverflow FD_SET(0, &fds); return select(1, &fds, NULL, NULL, &tv); } int getch() { int r; unsigned char c; if ((r = read(0, &c, sizeof(c))) < 0) { return r; } else { return c; } } #if 0 int main(int argc, char *argv[]) { set_conio_terminal_mode(); while (!kbhit()) { /* do some work */ } (void)getch(); /* consume the character */ } #endif
the_stack_data/6387083.c
/*Given a positive integer denoting , do the following: If , then print the lowercase English word corresponding to the number (e.g., one for , two for , etc.). If , print Greater than 9. Input Format The first line contains a single integer denoting . Constraints Output Format If , then print the lowercase English word corresponding to the number (e.g., one for , two for , etc.); otherwise, print Greater than 9 instead. Sample Input 5 Sample Output five Sample Input #01 8 Sample Output #01 eight Sample Input #02 44 Sample Output #02 Greater than 9*/ #include <assert.h> #include <limits.h> #include <math.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> char* readline(); int main() { /*char* n_endptr; char* n_str = readline(); int n = strtol(n_str, &n_endptr, 10); if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); }*/ int a; scanf("%d",&a); char* str_nums[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; if(1<=a && a<=9){ printf("%s", str_nums[a - 1]); } else{ printf("Greater than 9"); } return 0; } char* readline() { size_t alloc_length = 1024; size_t data_length = 0; char* data = malloc(alloc_length); while (true) { char* cursor = data + data_length; char* line = fgets(cursor, alloc_length - data_length, stdin); if (!line) { break; } data_length += strlen(cursor); if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; } size_t new_length = alloc_length << 1; data = realloc(data, new_length); if (!data) { break; } alloc_length = new_length; } if (data[data_length - 1] == '\n') { data[data_length - 1] = '\0'; } data = realloc(data, data_length); return data; }
the_stack_data/920006.c
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define MAX 20 int main(void) { // determine random seed int seed = time(NULL) % 1000; srand(seed); // determine capacity with sum of 10 random int from 0~99999999 int rand_weights[MAX], rand_profits[MAX], rand_capacity = 0; for (int c = 0; c < MAX / 2; c++) { rand_capacity += (rand() % 10000) * 10000 + rand() % 10000; } // determine weight of 20 objects with random int from 0~99999999 // and count there profits with a random c/p ratio between 1.8~2.2 // just like the input from the website for (int c = 0; c < MAX; c++) { rand_weights[c] = (rand() % 10000) * 10000 + rand() % 10000; rand_profits[c] = rand_weights[c] * (1.8 + (double)rand() / (RAND_MAX * 2.5)); } // open files and write data in char filename[5]; sprintf(filename, "k%d", rand() % 1000); printf("%s", filename); char filename_c[strlen(filename) + 7]; char filename_w[strlen(filename) + 7]; char filename_p[strlen(filename) + 7]; strncpy(filename_c, filename, strlen(filename) + 1); strncpy(filename_w, filename, strlen(filename) + 1); strncpy(filename_p, filename, strlen(filename) + 1); strncat(filename_c, "_c.txt", 7); strncat(filename_w, "_w.txt", 7); strncat(filename_p, "_p.txt", 7); FILE *fptrc, *fptrw, *fptrp; fptrc = fopen(filename_c, "w"); fptrw = fopen(filename_w, "w"); fptrp = fopen(filename_p, "w"); fprintf(fptrc, "\n%d", rand_capacity); for (int c = 0; c < MAX; c++) { fprintf(fptrw, "\n%d", rand_weights[c]); fprintf(fptrp, "\n%d", rand_profits[c]); } return EXIT_SUCCESS; }
the_stack_data/97011653.c
/* nrfit.c ======= Numerical Recipes */ /* LICENSE AND DISCLAIMER Copyright (c) 2012 The Johns Hopkins University/Applied Physics Laboratory This file is part of the Radar Software Toolkit (RST). RST 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 3 of the License, or any later version. RST 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 RST. If not, see <http://www.gnu.org/licenses/>. */ #include <stdio.h> #include <stdlib.h> #include <math.h> void nrfit(float *x,float *y,int ndata,float *sig,int mwt, float *a,float *b,float *siga,float *sigb,float *chi2, float *q) { int i; float wt,t,sxoss,sx=0.0,sy=0.0,st2=0.0,ss,sigdat; *b=0.0; if (mwt) { ss=0.0; for (i=0;i<ndata;i++) { wt=1.0/(sig[i]*sig[i]); ss+=wt; sx+=x[i]*wt; sy+=y[i]*wt; } } else { for (i=0;i<ndata;i++) { sx+=x[i]; sy+=y[i]; } ss=ndata; } sxoss=sx/ss; if (mwt) { for (i=0;i<ndata;i++) { t=(x[i]-sxoss)/sig[i]; st2+=t*t; *b+=t*y[i]/sig[i]; } } else { for (i=0;i<ndata;i++) { t=x[i]-sxoss; st2+=t*t; *b+=t*y[i]; } } *b/=st2; *a=(sy-sx*(*b))/ss; *siga=sqrt((1.0+sx*sx/(ss*st2))/ss); *sigb=sqrt(1.0/st2); *chi2=0.0; if (mwt==0) { for (i=0;i<ndata;i++) *chi2+=(y[i]-(*a)-(*b)*x[i])*(y[i]-(*a)-(*b)*x[i]); *q=1.0; sigdat=sqrt((*chi2)/(ndata-2)); *siga *= sigdat; *sigb *= sigdat; } else { for (i=0;i<ndata;i++) *chi2+=((y[i]-(*a)-(*b)*x[i])/sig[i])*((y[i]-(*a)-(*b)*x[i])/sig[i]); /* *q=gammaq(0.5*(ndata-2),0.5*(*chi2)); */ *q=1.0; } }
the_stack_data/13258.c
/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */ /* { dg-options "-O2" } */ /* { dg-final { scan-assembler-not "cmpw" } } */ /* Origin:Pete Steinmetz <[email protected]> */ /* PR 16458: Extraneous compare. */ int foo (unsigned a, unsigned b) { if (a == b) return 1; if (a > b) return 2; if (a < b) return 3; return 0; }
the_stack_data/68886858.c
/* * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * This file uses the low level AES and engine functions (which are deprecated * for non-internal use) in order to implement the padlock engine AES ciphers. */ #define OPENSSL_SUPPRESS_DEPRECATED #include <stdio.h> #include <string.h> #include <openssl/opensslconf.h> #include <openssl/crypto.h> #include <openssl/engine.h> #include <openssl/evp.h> #include <openssl/aes.h> #include <openssl/rand.h> #include <openssl/err.h> #include <openssl/modes.h> #ifndef OPENSSL_NO_PADLOCKENG /* * VIA PadLock AES is available *ONLY* on some x86 CPUs. Not only that it * doesn't exist elsewhere, but it even can't be compiled on other platforms! */ # undef COMPILE_PADLOCKENG # if defined(PADLOCK_ASM) # define COMPILE_PADLOCKENG # ifdef OPENSSL_NO_DYNAMIC_ENGINE static ENGINE *ENGINE_padlock(void); # endif # endif # ifdef OPENSSL_NO_DYNAMIC_ENGINE void engine_load_padlock_int(void); void engine_load_padlock_int(void) { /* On non-x86 CPUs it just returns. */ # ifdef COMPILE_PADLOCKENG ENGINE *toadd = ENGINE_padlock(); if (!toadd) return; ERR_set_mark(); ENGINE_add(toadd); /* * If the "add" worked, it gets a structural reference. So either way, we * release our just-created reference. */ ENGINE_free(toadd); /* * If the "add" didn't work, it was probably a conflict because it was * already added (eg. someone calling ENGINE_load_blah then calling * ENGINE_load_builtin_engines() perhaps). */ ERR_pop_to_mark(); # endif } # endif # ifdef COMPILE_PADLOCKENG /* Function for ENGINE detection and control */ static int padlock_available(void); static int padlock_init(ENGINE *e); /* RNG Stuff */ static RAND_METHOD padlock_rand; /* Cipher Stuff */ static int padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid); /* Engine names */ static const char *padlock_id = "padlock"; static char padlock_name[100]; /* Available features */ static int padlock_use_ace = 0; /* Advanced Cryptography Engine */ static int padlock_use_rng = 0; /* Random Number Generator */ /* ===== Engine "management" functions ===== */ /* Prepare the ENGINE structure for registration */ static int padlock_bind_helper(ENGINE *e) { /* Check available features */ padlock_available(); /* * RNG is currently disabled for reasons discussed in commentary just * before padlock_rand_bytes function. */ padlock_use_rng = 0; /* Generate a nice engine name with available features */ BIO_snprintf(padlock_name, sizeof(padlock_name), "VIA PadLock (%s, %s)", padlock_use_rng ? "RNG" : "no-RNG", padlock_use_ace ? "ACE" : "no-ACE"); /* Register everything or return with an error */ if (!ENGINE_set_id(e, padlock_id) || !ENGINE_set_name(e, padlock_name) || !ENGINE_set_init_function(e, padlock_init) || (padlock_use_ace && !ENGINE_set_ciphers(e, padlock_ciphers)) || (padlock_use_rng && !ENGINE_set_RAND(e, &padlock_rand))) { return 0; } /* Everything looks good */ return 1; } # ifdef OPENSSL_NO_DYNAMIC_ENGINE /* Constructor */ static ENGINE *ENGINE_padlock(void) { ENGINE *eng = ENGINE_new(); if (eng == NULL) { return NULL; } if (!padlock_bind_helper(eng)) { ENGINE_free(eng); return NULL; } return eng; } # endif /* Check availability of the engine */ static int padlock_init(ENGINE *e) { return (padlock_use_rng || padlock_use_ace); } /* * This stuff is needed if this ENGINE is being compiled into a * self-contained shared-library. */ # ifndef OPENSSL_NO_DYNAMIC_ENGINE static int padlock_bind_fn(ENGINE *e, const char *id) { if (id && (strcmp(id, padlock_id) != 0)) { return 0; } if (!padlock_bind_helper(e)) { return 0; } return 1; } IMPLEMENT_DYNAMIC_CHECK_FN() IMPLEMENT_DYNAMIC_BIND_FN(padlock_bind_fn) # endif /* !OPENSSL_NO_DYNAMIC_ENGINE */ /* ===== Here comes the "real" engine ===== */ /* Some AES-related constants */ # define AES_BLOCK_SIZE 16 # define AES_KEY_SIZE_128 16 # define AES_KEY_SIZE_192 24 # define AES_KEY_SIZE_256 32 /* * Here we store the status information relevant to the current context. */ /* * BIG FAT WARNING: Inline assembler in PADLOCK_XCRYPT_ASM() depends on * the order of items in this structure. Don't blindly modify, reorder, * etc! */ struct padlock_cipher_data { unsigned char iv[AES_BLOCK_SIZE]; /* Initialization vector */ union { unsigned int pad[4]; struct { int rounds:4; int dgst:1; /* n/a in C3 */ int align:1; /* n/a in C3 */ int ciphr:1; /* n/a in C3 */ unsigned int keygen:1; int interm:1; unsigned int encdec:1; int ksize:2; } b; } cword; /* Control word */ AES_KEY ks; /* Encryption key */ }; /* Interface to assembler module */ unsigned int padlock_capability(void); void padlock_key_bswap(AES_KEY *key); void padlock_verify_context(struct padlock_cipher_data *ctx); void padlock_reload_key(void); void padlock_aes_block(void *out, const void *inp, struct padlock_cipher_data *ctx); int padlock_ecb_encrypt(void *out, const void *inp, struct padlock_cipher_data *ctx, size_t len); int padlock_cbc_encrypt(void *out, const void *inp, struct padlock_cipher_data *ctx, size_t len); int padlock_cfb_encrypt(void *out, const void *inp, struct padlock_cipher_data *ctx, size_t len); int padlock_ofb_encrypt(void *out, const void *inp, struct padlock_cipher_data *ctx, size_t len); int padlock_ctr32_encrypt(void *out, const void *inp, struct padlock_cipher_data *ctx, size_t len); int padlock_xstore(void *out, int edx); void padlock_sha1_oneshot(void *ctx, const void *inp, size_t len); void padlock_sha1(void *ctx, const void *inp, size_t len); void padlock_sha256_oneshot(void *ctx, const void *inp, size_t len); void padlock_sha256(void *ctx, const void *inp, size_t len); /* * Load supported features of the CPU to see if the PadLock is available. */ static int padlock_available(void) { unsigned int edx = padlock_capability(); /* Fill up some flags */ padlock_use_ace = ((edx & (0x3 << 6)) == (0x3 << 6)); padlock_use_rng = ((edx & (0x3 << 2)) == (0x3 << 2)); return padlock_use_ace + padlock_use_rng; } /* ===== AES encryption/decryption ===== */ # if defined(NID_aes_128_cfb128) && ! defined (NID_aes_128_cfb) # define NID_aes_128_cfb NID_aes_128_cfb128 # endif # if defined(NID_aes_128_ofb128) && ! defined (NID_aes_128_ofb) # define NID_aes_128_ofb NID_aes_128_ofb128 # endif # if defined(NID_aes_192_cfb128) && ! defined (NID_aes_192_cfb) # define NID_aes_192_cfb NID_aes_192_cfb128 # endif # if defined(NID_aes_192_ofb128) && ! defined (NID_aes_192_ofb) # define NID_aes_192_ofb NID_aes_192_ofb128 # endif # if defined(NID_aes_256_cfb128) && ! defined (NID_aes_256_cfb) # define NID_aes_256_cfb NID_aes_256_cfb128 # endif # if defined(NID_aes_256_ofb128) && ! defined (NID_aes_256_ofb) # define NID_aes_256_ofb NID_aes_256_ofb128 # endif /* List of supported ciphers. */ static const int padlock_cipher_nids[] = { NID_aes_128_ecb, NID_aes_128_cbc, NID_aes_128_cfb, NID_aes_128_ofb, NID_aes_128_ctr, NID_aes_192_ecb, NID_aes_192_cbc, NID_aes_192_cfb, NID_aes_192_ofb, NID_aes_192_ctr, NID_aes_256_ecb, NID_aes_256_cbc, NID_aes_256_cfb, NID_aes_256_ofb, NID_aes_256_ctr }; static int padlock_cipher_nids_num = (sizeof(padlock_cipher_nids) / sizeof(padlock_cipher_nids[0])); /* Function prototypes ... */ static int padlock_aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc); # define NEAREST_ALIGNED(ptr) ( (unsigned char *)(ptr) + \ ( (0x10 - ((size_t)(ptr) & 0x0F)) & 0x0F ) ) # define ALIGNED_CIPHER_DATA(ctx) ((struct padlock_cipher_data *)\ NEAREST_ALIGNED(EVP_CIPHER_CTX_get_cipher_data(ctx))) static int padlock_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, const unsigned char *in_arg, size_t nbytes) { return padlock_ecb_encrypt(out_arg, in_arg, ALIGNED_CIPHER_DATA(ctx), nbytes); } static int padlock_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); int ret; memcpy(cdata->iv, EVP_CIPHER_CTX_iv(ctx), AES_BLOCK_SIZE); if ((ret = padlock_cbc_encrypt(out_arg, in_arg, cdata, nbytes))) memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), cdata->iv, AES_BLOCK_SIZE); return ret; } static int padlock_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); size_t chunk; if ((chunk = EVP_CIPHER_CTX_num(ctx))) { /* borrow chunk variable */ unsigned char *ivp = EVP_CIPHER_CTX_iv_noconst(ctx); if (chunk >= AES_BLOCK_SIZE) return 0; /* bogus value */ if (EVP_CIPHER_CTX_encrypting(ctx)) while (chunk < AES_BLOCK_SIZE && nbytes != 0) { ivp[chunk] = *(out_arg++) = *(in_arg++) ^ ivp[chunk]; chunk++, nbytes--; } else while (chunk < AES_BLOCK_SIZE && nbytes != 0) { unsigned char c = *(in_arg++); *(out_arg++) = c ^ ivp[chunk]; ivp[chunk++] = c, nbytes--; } EVP_CIPHER_CTX_set_num(ctx, chunk % AES_BLOCK_SIZE); } if (nbytes == 0) return 1; memcpy(cdata->iv, EVP_CIPHER_CTX_iv(ctx), AES_BLOCK_SIZE); if ((chunk = nbytes & ~(AES_BLOCK_SIZE - 1))) { if (!padlock_cfb_encrypt(out_arg, in_arg, cdata, chunk)) return 0; nbytes -= chunk; } if (nbytes) { unsigned char *ivp = cdata->iv; out_arg += chunk; in_arg += chunk; EVP_CIPHER_CTX_set_num(ctx, nbytes); if (cdata->cword.b.encdec) { cdata->cword.b.encdec = 0; padlock_reload_key(); padlock_aes_block(ivp, ivp, cdata); cdata->cword.b.encdec = 1; padlock_reload_key(); while (nbytes) { unsigned char c = *(in_arg++); *(out_arg++) = c ^ *ivp; *(ivp++) = c, nbytes--; } } else { padlock_reload_key(); padlock_aes_block(ivp, ivp, cdata); padlock_reload_key(); while (nbytes) { *ivp = *(out_arg++) = *(in_arg++) ^ *ivp; ivp++, nbytes--; } } } memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), cdata->iv, AES_BLOCK_SIZE); return 1; } static int padlock_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); size_t chunk; /* * ctx->num is maintained in byte-oriented modes, such as CFB and OFB... */ if ((chunk = EVP_CIPHER_CTX_num(ctx))) { /* borrow chunk variable */ unsigned char *ivp = EVP_CIPHER_CTX_iv_noconst(ctx); if (chunk >= AES_BLOCK_SIZE) return 0; /* bogus value */ while (chunk < AES_BLOCK_SIZE && nbytes != 0) { *(out_arg++) = *(in_arg++) ^ ivp[chunk]; chunk++, nbytes--; } EVP_CIPHER_CTX_set_num(ctx, chunk % AES_BLOCK_SIZE); } if (nbytes == 0) return 1; memcpy(cdata->iv, EVP_CIPHER_CTX_iv(ctx), AES_BLOCK_SIZE); if ((chunk = nbytes & ~(AES_BLOCK_SIZE - 1))) { if (!padlock_ofb_encrypt(out_arg, in_arg, cdata, chunk)) return 0; nbytes -= chunk; } if (nbytes) { unsigned char *ivp = cdata->iv; out_arg += chunk; in_arg += chunk; EVP_CIPHER_CTX_set_num(ctx, nbytes); padlock_reload_key(); /* empirically found */ padlock_aes_block(ivp, ivp, cdata); padlock_reload_key(); /* empirically found */ while (nbytes) { *(out_arg++) = *(in_arg++) ^ *ivp; ivp++, nbytes--; } } memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), cdata->iv, AES_BLOCK_SIZE); return 1; } static void padlock_ctr32_encrypt_glue(const unsigned char *in, unsigned char *out, size_t blocks, struct padlock_cipher_data *ctx, const unsigned char *ivec) { memcpy(ctx->iv, ivec, AES_BLOCK_SIZE); padlock_ctr32_encrypt(out, in, ctx, AES_BLOCK_SIZE * blocks); } static int padlock_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); unsigned int num = EVP_CIPHER_CTX_num(ctx); CRYPTO_ctr128_encrypt_ctr32(in_arg, out_arg, nbytes, cdata, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_buf_noconst(ctx), &num, (ctr128_f) padlock_ctr32_encrypt_glue); EVP_CIPHER_CTX_set_num(ctx, (size_t)num); return 1; } # define EVP_CIPHER_block_size_ECB AES_BLOCK_SIZE # define EVP_CIPHER_block_size_CBC AES_BLOCK_SIZE # define EVP_CIPHER_block_size_OFB 1 # define EVP_CIPHER_block_size_CFB 1 # define EVP_CIPHER_block_size_CTR 1 /* * Declaring so many ciphers by hand would be a pain. Instead introduce a bit * of preprocessor magic :-) */ # define DECLARE_AES_EVP(ksize,lmode,umode) \ static EVP_CIPHER *_hidden_aes_##ksize##_##lmode = NULL; \ static const EVP_CIPHER *padlock_aes_##ksize##_##lmode(void) \ { \ if (_hidden_aes_##ksize##_##lmode == NULL \ && ((_hidden_aes_##ksize##_##lmode = \ EVP_CIPHER_meth_new(NID_aes_##ksize##_##lmode, \ EVP_CIPHER_block_size_##umode, \ AES_KEY_SIZE_##ksize)) == NULL \ || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_##ksize##_##lmode, \ AES_BLOCK_SIZE) \ || !EVP_CIPHER_meth_set_flags(_hidden_aes_##ksize##_##lmode, \ 0 | EVP_CIPH_##umode##_MODE) \ || !EVP_CIPHER_meth_set_init(_hidden_aes_##ksize##_##lmode, \ padlock_aes_init_key) \ || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_##ksize##_##lmode, \ padlock_##lmode##_cipher) \ || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_##ksize##_##lmode, \ sizeof(struct padlock_cipher_data) + 16) \ || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_aes_##ksize##_##lmode, \ EVP_CIPHER_set_asn1_iv) \ || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_aes_##ksize##_##lmode, \ EVP_CIPHER_get_asn1_iv))) { \ EVP_CIPHER_meth_free(_hidden_aes_##ksize##_##lmode); \ _hidden_aes_##ksize##_##lmode = NULL; \ } \ return _hidden_aes_##ksize##_##lmode; \ } DECLARE_AES_EVP(128, ecb, ECB) DECLARE_AES_EVP(128, cbc, CBC) DECLARE_AES_EVP(128, cfb, CFB) DECLARE_AES_EVP(128, ofb, OFB) DECLARE_AES_EVP(128, ctr, CTR) DECLARE_AES_EVP(192, ecb, ECB) DECLARE_AES_EVP(192, cbc, CBC) DECLARE_AES_EVP(192, cfb, CFB) DECLARE_AES_EVP(192, ofb, OFB) DECLARE_AES_EVP(192, ctr, CTR) DECLARE_AES_EVP(256, ecb, ECB) DECLARE_AES_EVP(256, cbc, CBC) DECLARE_AES_EVP(256, cfb, CFB) DECLARE_AES_EVP(256, ofb, OFB) DECLARE_AES_EVP(256, ctr, CTR) static int padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid) { /* No specific cipher => return a list of supported nids ... */ if (!cipher) { *nids = padlock_cipher_nids; return padlock_cipher_nids_num; } /* ... or the requested "cipher" otherwise */ switch (nid) { case NID_aes_128_ecb: *cipher = padlock_aes_128_ecb(); break; case NID_aes_128_cbc: *cipher = padlock_aes_128_cbc(); break; case NID_aes_128_cfb: *cipher = padlock_aes_128_cfb(); break; case NID_aes_128_ofb: *cipher = padlock_aes_128_ofb(); break; case NID_aes_128_ctr: *cipher = padlock_aes_128_ctr(); break; case NID_aes_192_ecb: *cipher = padlock_aes_192_ecb(); break; case NID_aes_192_cbc: *cipher = padlock_aes_192_cbc(); break; case NID_aes_192_cfb: *cipher = padlock_aes_192_cfb(); break; case NID_aes_192_ofb: *cipher = padlock_aes_192_ofb(); break; case NID_aes_192_ctr: *cipher = padlock_aes_192_ctr(); break; case NID_aes_256_ecb: *cipher = padlock_aes_256_ecb(); break; case NID_aes_256_cbc: *cipher = padlock_aes_256_cbc(); break; case NID_aes_256_cfb: *cipher = padlock_aes_256_cfb(); break; case NID_aes_256_ofb: *cipher = padlock_aes_256_ofb(); break; case NID_aes_256_ctr: *cipher = padlock_aes_256_ctr(); break; default: /* Sorry, we don't support this NID */ *cipher = NULL; return 0; } return 1; } /* Prepare the encryption key for PadLock usage */ static int padlock_aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { struct padlock_cipher_data *cdata; int key_len = EVP_CIPHER_CTX_key_length(ctx) * 8; unsigned long mode = EVP_CIPHER_CTX_mode(ctx); if (key == NULL) return 0; /* ERROR */ cdata = ALIGNED_CIPHER_DATA(ctx); memset(cdata, 0, sizeof(*cdata)); /* Prepare Control word. */ if (mode == EVP_CIPH_OFB_MODE || mode == EVP_CIPH_CTR_MODE) cdata->cword.b.encdec = 0; else cdata->cword.b.encdec = (EVP_CIPHER_CTX_encrypting(ctx) == 0); cdata->cword.b.rounds = 10 + (key_len - 128) / 32; cdata->cword.b.ksize = (key_len - 128) / 64; switch (key_len) { case 128: /* * PadLock can generate an extended key for AES128 in hardware */ memcpy(cdata->ks.rd_key, key, AES_KEY_SIZE_128); cdata->cword.b.keygen = 0; break; case 192: case 256: /* * Generate an extended AES key in software. Needed for AES192/AES256 */ /* * Well, the above applies to Stepping 8 CPUs and is listed as * hardware errata. They most likely will fix it at some point and * then a check for stepping would be due here. */ if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE) && !enc) AES_set_decrypt_key(key, key_len, &cdata->ks); else AES_set_encrypt_key(key, key_len, &cdata->ks); # ifndef AES_ASM /* * OpenSSL C functions use byte-swapped extended key. */ padlock_key_bswap(&cdata->ks); # endif cdata->cword.b.keygen = 1; break; default: /* ERROR */ return 0; } /* * This is done to cover for cases when user reuses the * context for new key. The catch is that if we don't do * this, padlock_eas_cipher might proceed with old key... */ padlock_reload_key(); return 1; } /* ===== Random Number Generator ===== */ /* * This code is not engaged. The reason is that it does not comply * with recommendations for VIA RNG usage for secure applications * (posted at http://www.via.com.tw/en/viac3/c3.jsp) nor does it * provide meaningful error control... */ /* * Wrapper that provides an interface between the API and the raw PadLock * RNG */ static int padlock_rand_bytes(unsigned char *output, int count) { unsigned int eax, buf; while (count >= 8) { eax = padlock_xstore(output, 0); if (!(eax & (1 << 6))) return 0; /* RNG disabled */ /* this ---vv--- covers DC bias, Raw Bits and String Filter */ if (eax & (0x1F << 10)) return 0; if ((eax & 0x1F) == 0) continue; /* no data, retry... */ if ((eax & 0x1F) != 8) return 0; /* fatal failure... */ output += 8; count -= 8; } while (count > 0) { eax = padlock_xstore(&buf, 3); if (!(eax & (1 << 6))) return 0; /* RNG disabled */ /* this ---vv--- covers DC bias, Raw Bits and String Filter */ if (eax & (0x1F << 10)) return 0; if ((eax & 0x1F) == 0) continue; /* no data, retry... */ if ((eax & 0x1F) != 1) return 0; /* fatal failure... */ *output++ = (unsigned char)buf; count--; } OPENSSL_cleanse(&buf, sizeof(buf)); return 1; } /* Dummy but necessary function */ static int padlock_rand_status(void) { return 1; } /* Prepare structure for registration */ static RAND_METHOD padlock_rand = { NULL, /* seed */ padlock_rand_bytes, /* bytes */ NULL, /* cleanup */ NULL, /* add */ padlock_rand_bytes, /* pseudorand */ padlock_rand_status, /* rand status */ }; # endif /* COMPILE_PADLOCKENG */ #endif /* !OPENSSL_NO_PADLOCKENG */ #if defined(OPENSSL_NO_PADLOCKENG) || !defined(COMPILE_PADLOCKENG) # ifndef OPENSSL_NO_DYNAMIC_ENGINE OPENSSL_EXPORT int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); OPENSSL_EXPORT int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; } IMPLEMENT_DYNAMIC_CHECK_FN() # endif #endif
the_stack_data/35696.c
extern void __VERIFIER_error(); #include <pthread.h> pthread_mutex_t ma, mb; int data1, data2; void * thread1(void * arg) { pthread_mutex_lock(&ma); data1++; pthread_mutex_unlock(&ma); pthread_mutex_lock(&ma); data2++; pthread_mutex_unlock(&ma); } void * thread2(void * arg) { pthread_mutex_lock(&ma); data1+=5; pthread_mutex_unlock(&ma); pthread_mutex_lock(&ma); data2-=6; pthread_mutex_unlock(&ma); } int main() { pthread_t t1, t2; pthread_mutex_init(&ma, 0); pthread_mutex_init(&mb, 0); data1 = 10; data2 = 10; pthread_create(&t1, 0, thread1, 0); pthread_create(&t2, 0, thread2, 0); pthread_join(t1, 0); pthread_join(t2, 0); if (data1==16 && data2==5) { ERROR: __VERIFIER_error(); ; } return 0; }
the_stack_data/140766494.c
#include <stdio.h> #include<stdlib.h> #include<string.h> void printArr(int *, int); int main() { char *p; int n, i; printf("# of elements in int array: "); scanf("%d", &n); int *my_array = (int*) malloc(n* sizeof(int)); *my_array = -10; for(i =1; i<n; i++) *(my_array+i) = i*100; printArr(my_array, n); p = malloc(6 * sizeof(char)); p = "hello"; printf("%s %d\n", p, strlen(p)); *(p+2) = 'X'; printf("%s\n", p); return 0; } /* print the first n elements of int array arr */ void printArr(int * arr, int n){ int i; for(i=0;i<n ;i++) printf("[%d]: %d\n", i, *(arr+i)); }
the_stack_data/956880.c
/* ------------------------------------------------------------------------------- lookup3.c, by Bob Jenkins, May 2006, Public Domain. These are functions for producing 32-bit hashes for hash table lookup. hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() are externally useful functions. Routines to test the hash are included if SELF_TEST is defined. You can use this free for any purpose. It's in the public domain. It has no warranty. You probably want to use hashlittle(). hashlittle() and hashbig() hash byte arrays. hashlittle() is is faster than hashbig() on little-endian machines. Intel and AMD are little-endian machines. On second thought, you probably want hashlittle2(), which is identical to hashlittle() except it returns two 32-bit hashes for the price of one. You could implement hashbig2() if you wanted but I haven't bothered here. If you want to find a hash of, say, exactly 7 integers, do a = i1; b = i2; c = i3; mix(a,b,c); a += i4; b += i5; c += i6; mix(a,b,c); a += i7; final(a,b,c); then use c as the hash value. If you have a variable length array of 4-byte integers to hash, use hashword(). If you have a byte array (like a character string), use hashlittle(). If you have several byte arrays, or a mix of things, see the comments above hashlittle(). Why is this so big? I read 12 bytes at a time into 3 4-byte integers, then mix those integers. This is fast (you can do a lot more thorough mixing with 12*3 instructions on 3 integers than you can with 3 instructions on 1 byte), but shoehorning those bytes into integers efficiently is messy. ------------------------------------------------------------------------------- */ #include <stdio.h> /* defines printf for tests */ #include <time.h> /* defines time_t for timings in the test */ #include <inttypes.h> /* defines uint32_t etc */ #include <sys/param.h> /* attempt to define endianness */ #ifdef linux # include <endian.h> /* attempt to define endianness */ #endif /* * My best guess at if you are big-endian or little-endian. This may * need adjustment. */ #if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ __BYTE_ORDER == __LITTLE_ENDIAN) || \ (defined(i386) || defined(__i386__) || defined(__i486__) || \ defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) # define HASH_LITTLE_ENDIAN 1 # define HASH_BIG_ENDIAN 0 #elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \ __BYTE_ORDER == __BIG_ENDIAN) || \ (defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel)) # define HASH_LITTLE_ENDIAN 0 # define HASH_BIG_ENDIAN 1 #else # define HASH_LITTLE_ENDIAN 0 # define HASH_BIG_ENDIAN 0 #endif #define hashsize(n) ((uint32_t)1<<(n)) #define hashmask(n) (hashsize(n)-1) #define rot(x,k) (((x)<<(k)) ^ ((x)>>(32-(k)))) /* ------------------------------------------------------------------------------- mix -- mix 3 32-bit values reversibly. This is reversible, so any information in (a,b,c) before mix() is still in (a,b,c) after mix(). If four pairs of (a,b,c) inputs are run through mix(), or through mix() in reverse, there are at least 32 bits of the output that are sometimes the same for one pair and different for another pair. This was tested for: * pairs that differed by one bit, by two bits, in any combination of top bits of (a,b,c), or in any combination of bottom bits of (a,b,c). * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed the output delta to a Gray code (a^(a>>1)) so a string of 1's (as is commonly produced by subtraction) look like a single 1-bit difference. * the base values were pseudorandom, all zero but one bit set, or all zero plus a counter that starts at zero. Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that satisfy this are 4 6 8 16 19 4 9 15 3 18 27 15 14 9 3 7 17 3 Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing for "differ" defined as + with a one-bit base and a two-bit delta. I used http://burtleburtle.net/bob/hash/avalanche.html to choose the operations, constants, and arrangements of the variables. This does not achieve avalanche. There are input bits of (a,b,c) that fail to affect some output bits of (a,b,c), especially of a. The most thoroughly mixed value is c, but it doesn't really even achieve avalanche in c. This allows some parallelism. Read-after-writes are good at doubling the number of bits affected, so the goal of mixing pulls in the opposite direction as the goal of parallelism. I did what I could. Rotates seem to cost as much as shifts on every machine I could lay my hands on, and rotates are much kinder to the top and bottom bits, so I used rotates. ------------------------------------------------------------------------------- */ #define mix(a,b,c) \ { \ a -= c; a ^= rot(c, 4); c += b; \ b -= a; b ^= rot(a, 6); a += c; \ c -= b; c ^= rot(b, 8); b += a; \ a -= c; a ^= rot(c,16); c += b; \ b -= a; b ^= rot(a,19); a += c; \ c -= b; c ^= rot(b, 4); b += a; \ } /* ------------------------------------------------------------------------------- final -- final mixing of 3 32-bit values (a,b,c) into c Pairs of (a,b,c) values differing in only a few bits will usually produce values of c that look totally different. This was tested for * pairs that differed by one bit, by two bits, in any combination of top bits of (a,b,c), or in any combination of bottom bits of (a,b,c). * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed the output delta to a Gray code (a^(a>>1)) so a string of 1's (as is commonly produced by subtraction) look like a single 1-bit difference. * the base values were pseudorandom, all zero but one bit set, or all zero plus a counter that starts at zero. These constants passed: 14 11 25 16 4 14 24 12 14 25 16 4 14 24 and these came close: 4 8 15 26 3 22 24 10 8 15 26 3 22 24 11 8 15 26 3 22 24 ------------------------------------------------------------------------------- */ #define final(a,b,c) \ { \ c ^= b; c -= rot(b,14); \ a ^= c; a -= rot(c,11); \ b ^= a; b -= rot(a,25); \ c ^= b; c -= rot(b,16); \ a ^= c; a -= rot(c,4); \ b ^= a; b -= rot(a,14); \ c ^= b; c -= rot(b,24); \ } /* -------------------------------------------------------------------- This works on all machines. To be useful, it requires -- that the key be an array of uint32_t's, and -- that the length be the number of uint32_t's in the key The function hashword() is identical to hashlittle() on little-endian machines, and identical to hashbig() on big-endian machines, except that the length has to be measured in uint32_ts rather than in bytes. hashlittle() is more complicated than hashword() only because hashlittle() has to dance around fitting the key bytes into registers. -------------------------------------------------------------------- */ uint32_t hashword( const uint32_t *k, /* the key, an array of uint32_t values */ size_t length, /* the length of the key, in uint32_ts */ uint32_t initval) /* the previous hash, or an arbitrary value */ { uint32_t a,b,c; /* Set up the internal state */ a = b = c = 0xdeadbeef + (((uint32_t)length)<<2) + initval; /*------------------------------------------------- handle most of the key */ while (length > 3) { a += k[0]; b += k[1]; c += k[2]; mix(a,b,c); length -= 3; k += 3; } /*------------------------------------------- handle the last 3 uint32_t's */ switch(length) /* all the case statements fall through */ { case 3 : c+=k[2]; case 2 : b+=k[1]; case 1 : a+=k[0]; final(a,b,c); case 0: /* case 0: nothing left to add */ break; } /*------------------------------------------------------ report the result */ return c; } void hashword2( const uint32_t *k, /* the key, an array of uint32_t values */ size_t length, /* the length of the key, in uint32_ts */ uint32_t *pc, uint32_t *pb) /* the previous hash, or an arbitrary value */ { uint32_t a,b,c; /* Set up the internal state */ a = b = c = 0xdeadbeef + (((uint32_t)length)<<2) + *pc; /*------------------------------------------------- handle most of the key */ while (length > 3) { a += k[0]; b += k[1]; c += k[2]; mix(a,b,c); length -= 3; k += 3; } /*------------------------------------------- handle the last 3 uint32_t's */ switch(length) /* all the case statements fall through */ { case 3 : c+=k[2]; case 2 : b+=k[1]; case 1 : a+=k[0]; final(a,b,c); case 0: /* case 0: nothing left to add */ break; } /*------------------------------------------------------ report the result */ *pc = c; *pb = b; } /* ------------------------------------------------------------------------------- hashlittle() -- hash a variable-length key into a 32-bit value k : the key (the unaligned variable-length array of bytes) length : the length of the key, counting by bytes initval : can be any 4-byte value Returns a 32-bit value. Every bit of the key affects every bit of the return value. Two keys differing by one or two bits will have totally different hash values. The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do h = (h & hashmask(10)); In which case, the hash table should have hashsize(10) elements. If you are hashing n strings (uint8_t **)k, do it like this: for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h); By Bob Jenkins, 2006. [email protected]. You may use this code any way you wish, private, educational, or commercial. It's free. Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes. ------------------------------------------------------------------------------- */ uint32_t hashlittle( const void *key, size_t length, uint32_t initval) { uint32_t a,b,c; /* internal state */ union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ /* Set up the internal state */ a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; u.ptr = key; if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ #ifdef VALGRIND const uint8_t *k8; #endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) { a += k[0]; b += k[1]; c += k[2]; mix(a,b,c); length -= 12; k += 3; } /*----------------------------- handle the last (probably partial) block */ /* * "k[2]&0xffffff" actually reads beyond the end of the string, but * then masks off the part it's not allowed to read. Because the * string is aligned, the masked-off tail is in the same word as the * rest of the string. Every machine with memory protection I've seen * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). */ #ifndef VALGRIND switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; case 8 : b+=k[1]; a+=k[0]; break; case 7 : b+=k[1]&0xffffff; a+=k[0]; break; case 6 : b+=k[1]&0xffff; a+=k[0]; break; case 5 : b+=k[1]&0xff; a+=k[0]; break; case 4 : a+=k[0]; break; case 3 : a+=k[0]&0xffffff; break; case 2 : a+=k[0]&0xffff; break; case 1 : a+=k[0]&0xff; break; case 0 : return c; /* zero length strings require no mixing */ } #else /* make valgrind happy */ k8 = (const uint8_t *)k; switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ case 9 : c+=k8[8]; /* fall through */ case 8 : b+=k[1]; a+=k[0]; break; case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ case 5 : b+=k8[4]; /* fall through */ case 4 : a+=k[0]; break; case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ case 1 : a+=k8[0]; break; case 0 : return c; } #endif /* !valgrind */ } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ const uint8_t *k8; /*--------------- all but last block: aligned reads and different mixing */ while (length > 12) { a += k[0] + (((uint32_t)k[1])<<16); b += k[2] + (((uint32_t)k[3])<<16); c += k[4] + (((uint32_t)k[5])<<16); mix(a,b,c); length -= 12; k += 6; } /*----------------------------- handle the last (probably partial) block */ k8 = (const uint8_t *)k; switch(length) { case 12: c+=k[4]+(((uint32_t)k[5])<<16); b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ case 10: c+=k[4]; b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; case 9 : c+=k8[8]; /* fall through */ case 8 : b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ case 6 : b+=k[2]; a+=k[0]+(((uint32_t)k[1])<<16); break; case 5 : b+=k8[4]; /* fall through */ case 4 : a+=k[0]+(((uint32_t)k[1])<<16); break; case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ case 2 : a+=k[0]; break; case 1 : a+=k8[0]; break; case 0 : return c; /* zero length requires no mixing */ } } else { /* need to read the key one byte at a time */ const uint8_t *k = (const uint8_t *)key; /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ while (length > 12) { a += k[0]; a += ((uint32_t)k[1])<<8; a += ((uint32_t)k[2])<<16; a += ((uint32_t)k[3])<<24; b += k[4]; b += ((uint32_t)k[5])<<8; b += ((uint32_t)k[6])<<16; b += ((uint32_t)k[7])<<24; c += k[8]; c += ((uint32_t)k[9])<<8; c += ((uint32_t)k[10])<<16; c += ((uint32_t)k[11])<<24; mix(a,b,c); length -= 12; k += 12; } /*-------------------------------- last block: affect all 32 bits of (c) */ switch(length) /* all the case statements fall through */ { case 12: c+=((uint32_t)k[11])<<24; case 11: c+=((uint32_t)k[10])<<16; case 10: c+=((uint32_t)k[9])<<8; case 9 : c+=k[8]; case 8 : b+=((uint32_t)k[7])<<24; case 7 : b+=((uint32_t)k[6])<<16; case 6 : b+=((uint32_t)k[5])<<8; case 5 : b+=k[4]; case 4 : a+=((uint32_t)k[3])<<24; case 3 : a+=((uint32_t)k[2])<<16; case 2 : a+=((uint32_t)k[1])<<8; case 1 : a+=k[0]; break; case 0 : return c; } } final(a,b,c); return c; } /* * hashlittle2: return 2 32-bit hash values * * This is identical to hashlittle(), except it returns two 32-bit hash * values instead of just one. This is good enough for hash table * lookup with 2^^64 buckets, or if you want a second hash if you're not * happy with the first, or if you want a probably-unique 64-bit ID for * the key. *pc is better mixed than *pb, so use *pc first. If you want * a 64-bit value do something like "*pc + (((uint64_t)*pb)<<32)". */ void hashlittle2( const void *key, /* the key to hash */ size_t length, /* length of the key */ uint32_t *pc, /* IN: primary initval, OUT: primary hash */ uint32_t *pb) /* IN: secondary initval, OUT: secondary hash */ { uint32_t a,b,c; /* internal state */ union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ /* Set up the internal state */ a = b = c = 0xdeadbeef + ((uint32_t)length) + *pc; c += *pb; u.ptr = key; if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ #ifdef VALGRIND const uint8_t *k8; #endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) { a += k[0]; b += k[1]; c += k[2]; mix(a,b,c); length -= 12; k += 3; } /*----------------------------- handle the last (probably partial) block */ /* * "k[2]&0xffffff" actually reads beyond the end of the string, but * then masks off the part it's not allowed to read. Because the * string is aligned, the masked-off tail is in the same word as the * rest of the string. Every machine with memory protection I've seen * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). */ #ifndef VALGRIND switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; case 8 : b+=k[1]; a+=k[0]; break; case 7 : b+=k[1]&0xffffff; a+=k[0]; break; case 6 : b+=k[1]&0xffff; a+=k[0]; break; case 5 : b+=k[1]&0xff; a+=k[0]; break; case 4 : a+=k[0]; break; case 3 : a+=k[0]&0xffffff; break; case 2 : a+=k[0]&0xffff; break; case 1 : a+=k[0]&0xff; break; case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ } #else /* make valgrind happy */ k8 = (const uint8_t *)k; switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ case 9 : c+=k8[8]; /* fall through */ case 8 : b+=k[1]; a+=k[0]; break; case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ case 5 : b+=k8[4]; /* fall through */ case 4 : a+=k[0]; break; case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ case 1 : a+=k8[0]; break; case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ } #endif /* !valgrind */ } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ const uint8_t *k8; /*--------------- all but last block: aligned reads and different mixing */ while (length > 12) { a += k[0] + (((uint32_t)k[1])<<16); b += k[2] + (((uint32_t)k[3])<<16); c += k[4] + (((uint32_t)k[5])<<16); mix(a,b,c); length -= 12; k += 6; } /*----------------------------- handle the last (probably partial) block */ k8 = (const uint8_t *)k; switch(length) { case 12: c+=k[4]+(((uint32_t)k[5])<<16); b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ case 10: c+=k[4]; b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; case 9 : c+=k8[8]; /* fall through */ case 8 : b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ case 6 : b+=k[2]; a+=k[0]+(((uint32_t)k[1])<<16); break; case 5 : b+=k8[4]; /* fall through */ case 4 : a+=k[0]+(((uint32_t)k[1])<<16); break; case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ case 2 : a+=k[0]; break; case 1 : a+=k8[0]; break; case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ } } else { /* need to read the key one byte at a time */ const uint8_t *k = (const uint8_t *)key; /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ while (length > 12) { a += k[0]; a += ((uint32_t)k[1])<<8; a += ((uint32_t)k[2])<<16; a += ((uint32_t)k[3])<<24; b += k[4]; b += ((uint32_t)k[5])<<8; b += ((uint32_t)k[6])<<16; b += ((uint32_t)k[7])<<24; c += k[8]; c += ((uint32_t)k[9])<<8; c += ((uint32_t)k[10])<<16; c += ((uint32_t)k[11])<<24; mix(a,b,c); length -= 12; k += 12; } /*-------------------------------- last block: affect all 32 bits of (c) */ switch(length) /* all the case statements fall through */ { case 12: c+=((uint32_t)k[11])<<24; case 11: c+=((uint32_t)k[10])<<16; case 10: c+=((uint32_t)k[9])<<8; case 9 : c+=k[8]; case 8 : b+=((uint32_t)k[7])<<24; case 7 : b+=((uint32_t)k[6])<<16; case 6 : b+=((uint32_t)k[5])<<8; case 5 : b+=k[4]; case 4 : a+=((uint32_t)k[3])<<24; case 3 : a+=((uint32_t)k[2])<<16; case 2 : a+=((uint32_t)k[1])<<8; case 1 : a+=k[0]; break; case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ } } final(a,b,c); *pc=c; *pb=b; return; /* zero length strings require no mixing */ } /* * hashbig(): * This is the same as hashword() on big-endian machines. It is different * from hashlittle() on all machines. hashbig() takes advantage of * big-endian byte ordering. */ uint32_t hashbig( const void *key, size_t length, uint32_t initval) { uint32_t a,b,c; union { const void *ptr; size_t i; } u; /* to cast key to (size_t) happily */ /* Set up the internal state */ a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; u.ptr = key; if (HASH_BIG_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ #ifdef VALGRIND const uint8_t *k8; #endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) { a += k[0]; b += k[1]; c += k[2]; mix(a,b,c); length -= 12; k += 3; } /*----------------------------- handle the last (probably partial) block */ /* * "k[2]<<8" actually reads beyond the end of the string, but * then shifts out the part it's not allowed to read. Because the * string is aligned, the illegal read is in the same word as the * rest of the string. Every machine with memory protection I've seen * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). */ #ifndef VALGRIND switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; case 11: c+=k[2]&0xffffff00; b+=k[1]; a+=k[0]; break; case 10: c+=k[2]&0xffff0000; b+=k[1]; a+=k[0]; break; case 9 : c+=k[2]&0xff000000; b+=k[1]; a+=k[0]; break; case 8 : b+=k[1]; a+=k[0]; break; case 7 : b+=k[1]&0xffffff00; a+=k[0]; break; case 6 : b+=k[1]&0xffff0000; a+=k[0]; break; case 5 : b+=k[1]&0xff000000; a+=k[0]; break; case 4 : a+=k[0]; break; case 3 : a+=k[0]&0xffffff00; break; case 2 : a+=k[0]&0xffff0000; break; case 1 : a+=k[0]&0xff000000; break; case 0 : return c; /* zero length strings require no mixing */ } #else /* make valgrind happy */ k8 = (const uint8_t *)k; switch(length) /* all the case statements fall through */ { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; case 11: c+=((uint32_t)k8[10])<<8; /* fall through */ case 10: c+=((uint32_t)k8[9])<<16; /* fall through */ case 9 : c+=((uint32_t)k8[8])<<24; /* fall through */ case 8 : b+=k[1]; a+=k[0]; break; case 7 : b+=((uint32_t)k8[6])<<8; /* fall through */ case 6 : b+=((uint32_t)k8[5])<<16; /* fall through */ case 5 : b+=((uint32_t)k8[4])<<24; /* fall through */ case 4 : a+=k[0]; break; case 3 : a+=((uint32_t)k8[2])<<8; /* fall through */ case 2 : a+=((uint32_t)k8[1])<<16; /* fall through */ case 1 : a+=((uint32_t)k8[0])<<24; break; case 0 : return c; } #endif /* !VALGRIND */ } else { /* need to read the key one byte at a time */ const uint8_t *k = (const uint8_t *)key; /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ while (length > 12) { a += ((uint32_t)k[0])<<24; a += ((uint32_t)k[1])<<16; a += ((uint32_t)k[2])<<8; a += ((uint32_t)k[3]); b += ((uint32_t)k[4])<<24; b += ((uint32_t)k[5])<<16; b += ((uint32_t)k[6])<<8; b += ((uint32_t)k[7]); c += ((uint32_t)k[8])<<24; c += ((uint32_t)k[9])<<16; c += ((uint32_t)k[10])<<8; c += ((uint32_t)k[11]); mix(a,b,c); length -= 12; k += 12; } /*-------------------------------- last block: affect all 32 bits of (c) */ switch(length) /* all the case statements fall through */ { case 12: c+=k[11]; case 11: c+=((uint32_t)k[10])<<8; case 10: c+=((uint32_t)k[9])<<16; case 9 : c+=((uint32_t)k[8])<<24; case 8 : b+=k[7]; case 7 : b+=((uint32_t)k[6])<<8; case 6 : b+=((uint32_t)k[5])<<16; case 5 : b+=((uint32_t)k[4])<<24; case 4 : a+=k[3]; case 3 : a+=((uint32_t)k[2])<<8; case 2 : a+=((uint32_t)k[1])<<16; case 1 : a+=((uint32_t)k[0])<<24; break; case 0 : return c; } } final(a,b,c); return c; } #ifdef SELF_TEST /* used for timings */ void driver1() { uint8_t buf[256]; uint32_t i; uint32_t h=0; time_t a,z; time(&a); for (i=0; i<256; ++i) buf[i] = 'x'; for (i=0; i<1; ++i) { h = hashlittle(&buf[0],1,h); } time(&z); if (z-a > 0) printf("time %d %.8x\n", z-a, h); } /* check that every input bit changes every output bit half the time */ #define HASHSTATE 1 #define HASHLEN 1 #define MAXPAIR 60 #define MAXLEN 70 void driver2() { uint8_t qa[MAXLEN+1], qb[MAXLEN+2], *a = &qa[0], *b = &qb[1]; uint32_t c[HASHSTATE], d[HASHSTATE], i=0, j=0, k, l, m=0, z; uint32_t e[HASHSTATE],f[HASHSTATE],g[HASHSTATE],h[HASHSTATE]; uint32_t x[HASHSTATE],y[HASHSTATE]; uint32_t hlen; printf("No more than %d trials should ever be needed \n",MAXPAIR/2); for (hlen=0; hlen < MAXLEN; ++hlen) { z=0; for (i=0; i<hlen; ++i) /*----------------------- for each input byte, */ { for (j=0; j<8; ++j) /*------------------------ for each input bit, */ { for (m=1; m<8; ++m) /*------------ for serveral possible initvals, */ { for (l=0; l<HASHSTATE; ++l) e[l]=f[l]=g[l]=h[l]=x[l]=y[l]=~((uint32_t)0); /*---- check that every output bit is affected by that input bit */ for (k=0; k<MAXPAIR; k+=2) { uint32_t finished=1; /* keys have one bit different */ for (l=0; l<hlen+1; ++l) {a[l] = b[l] = (uint8_t)0;} /* have a and b be two keys differing in only one bit */ a[i] ^= (k<<j); a[i] ^= (k>>(8-j)); c[0] = hashlittle(a, hlen, m); b[i] ^= ((k+1)<<j); b[i] ^= ((k+1)>>(8-j)); d[0] = hashlittle(b, hlen, m); /* check every bit is 1, 0, set, and not set at least once */ for (l=0; l<HASHSTATE; ++l) { e[l] &= (c[l]^d[l]); f[l] &= ~(c[l]^d[l]); g[l] &= c[l]; h[l] &= ~c[l]; x[l] &= d[l]; y[l] &= ~d[l]; if (e[l]|f[l]|g[l]|h[l]|x[l]|y[l]) finished=0; } if (finished) break; } if (k>z) z=k; if (k==MAXPAIR) { printf("Some bit didn't change: "); printf("%.8x %.8x %.8x %.8x %.8x %.8x ", e[0],f[0],g[0],h[0],x[0],y[0]); printf("i %d j %d m %d len %d\n", i, j, m, hlen); } if (z==MAXPAIR) goto done; } } } done: if (z < MAXPAIR) { printf("Mix success %2d bytes %2d initvals ",i,m); printf("required %d trials\n", z/2); } } printf("\n"); } /* Check for reading beyond the end of the buffer and alignment problems */ void driver3() { uint8_t buf[MAXLEN+20], *b; uint32_t len; uint32_t a; uint8_t q[] = "This is the time for all good men to come to the aid of their country..."; uint32_t h; uint8_t qq[] = "xThis is the time for all good men to come to the aid of their country..."; uint32_t i; uint8_t qqq[] = "xxThis is the time for all good men to come to the aid of their country..."; uint32_t j; uint8_t qqqq[] = "xxxThis is the time for all good men to come to the aid of their country..."; uint32_t ref,x,y; uint8_t *p; printf("Endianness. These lines should all be the same (for values filled in):\n"); printf("%.8x %.8x %.8x\n", hashword((const uint32_t *)q, (sizeof(q)-1)/4, 13), hashword((const uint32_t *)q, (sizeof(q)-5)/4, 13), hashword((const uint32_t *)q, (sizeof(q)-9)/4, 13)); p = q; printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); p = &qq[1]; printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); p = &qqq[2]; printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); p = &qqqq[3]; printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); printf("\n"); for (h=0, b=buf+1; h<8; ++h, ++b) { for (i=0; i<MAXLEN; ++i) { len = i; for (j=0; j<i; ++j) *(b+j)=0; /* these should all be equal */ ref = hashlittle(b, len, (uint32_t)1); *(b+i)=(uint8_t)~0; *(b-1)=(uint8_t)~0; x = hashlittle(b, len, (uint32_t)1); y = hashlittle(b, len, (uint32_t)1); if ((ref != x) || (ref != y)) { printf("alignment error: %.8x %.8x %.8x %d %d\n",ref,x,y, h, i); } } } } /* check for problems with nulls */ void driver4() { uint8_t buf[1]; uint32_t h,i,state[HASHSTATE]; buf[0] = ~0; for (i=0; i<HASHSTATE; ++i) state[i] = 1; printf("These should all be different\n"); for (i=0, h=0; i<8; ++i) { h = hashlittle(buf, 0, h); printf("%2ld 0-byte strings, hash is %.8x\n", i, h); } } int main() { driver1(); /* test that the key is hashed: used for timings */ driver2(); /* test that whole key is hashed thoroughly */ driver3(); /* test that nothing but the key is hashed */ driver4(); /* test hashing multiple buffers (all buffers are null) */ return 1; } #endif /* SELF_TEST */
the_stack_data/584201.c
// Copyright (c) 2015 Nuxi, https://nuxi.nl/ // // SPDX-License-Identifier: BSD-2-Clause #define _CLOUDLIBC_UNSAFE_STRING_FUNCTIONS #include <string.h> char *strcpy(char *restrict s1, const char *restrict s2) { char *s = s1; for (;;) { *s++ = *s2; if (*s2++ == '\0') return s1; } }
the_stack_data/48575476.c
#include<stdio.h> #include<stdlib.h> int cmpl(const void*a,const void*b){ return *(int *)b-*(int *)a; } int main() { int d,i=0,j=1,k,t=1,cnt=0,flag; scanf("%d",&d); int *a=(int*)malloc(d*sizeof(int)); int *b=(int*)malloc(d*sizeof(int)); int *sum=(int*)malloc(d*sizeof(int)); for(i=0;i<d;i++){ scanf("%d",&a[i]); b[i]=0; sum[i]=0; } scanf("%d",&k); qsort(a,d,sizeof(a[0]),cmpl); //快速排序函数 for(i=0;i<d-1;i+=t){ t=1; for(j=i+1;a[i]==a[j];j++) t++; b[cnt]=a[i]; sum[cnt]=t; cnt++; } printf("%d %d",b[k-1],sum[k-1]); free(a); free(b); free(sum); return 0; }